MainForm.cs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using PTMedicalInsurance.Common;
  11. using PTMedicalInsurance.Helper;
  12. using Newtonsoft.Json.Linq;
  13. using PTMedicalInsurance.FormSetter;
  14. using System.IO;
  15. using System.IO.Compression;
  16. using PTMedicalInsurance.Business;
  17. using Sunny.UI;
  18. using Newtonsoft.Json;
  19. using System.Collections;
  20. using PTMedicalInsurance.Variables;
  21. namespace PTMedicalInsurance.Forms.Clearings
  22. {
  23. public partial class MainForm : Form
  24. {
  25. private string txtPath;
  26. private string txtName;
  27. private string finalAchPath;
  28. private string fileDir;
  29. private UIDataGridViewFooter dgvHisSettlRecFooter = new Sunny.UI.UIDataGridViewFooter();
  30. JObject jo9102Rtn = new JObject();
  31. #region 初始化
  32. public MainForm()
  33. {
  34. InitializeComponent();
  35. //初始化界面
  36. InitForm();
  37. //添加转院备案
  38. AddForm(this.tpOutOfAreaClearing, new OutOfAreaClearing(this));
  39. }
  40. private void InitForm()
  41. {
  42. this.StartPosition = FormStartPosition.CenterParent;
  43. ComboxSetter cbxSetter = new ComboxSetter();
  44. cbxSetter.setCbxInterfaceDataSource(cbxInterface);
  45. cbxSetter.setCbxDictionaryDataSource(Global.inf.interfaceDr.ToString(), "insutype", cbxInsuType);
  46. cbxSetter.setCbxDictionaryDataSource(Global.inf.interfaceDr.ToString(), "clr_type", cbxClrType);
  47. GridViewSetter grdSetter = new GridViewSetter();
  48. grdSetter.SetHeaderTextOfCheck(dgvSettlSummary);
  49. cbgGroupSet.SelectAll();
  50. cbgGroupSet.SetItemCheckState(4, false);
  51. cbxValid.SelectedIndex = 1;
  52. cbReservelFlag.SelectedIndex = 2;
  53. cbConfirmFlag.SelectedIndex = 1;
  54. dpST.Text = DateTime.Now.ToString("yyyy-MM-01");
  55. dpED.Value = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1);
  56. WindowState = FormWindowState.Maximized;
  57. fileDir = Global.currentDirectory + "\\Download";
  58. this.WindowState = FormWindowState.Maximized;
  59. this.uiTabControl1.SelectedIndex = 1;
  60. }
  61. private void AddForm(TabPage tabpage, Form frm)
  62. {
  63. tabpage.Controls.Add(frm);
  64. frm.Show();
  65. }
  66. #endregion
  67. #region 非按钮事件
  68. #region 查询HIS
  69. private int queryHisSettlementInfo(out string error)
  70. {
  71. GridViewSetter grdSetter = new GridViewSetter();
  72. grdSetter.SetHeaderTextOfHisSettlRec(dgvHisSettlRec);
  73. error = "";
  74. try
  75. {
  76. DataTable dtInteface = (DataTable)cbxInterface.DataSource;
  77. int i = cbxInterface.SelectedIndex;
  78. string sqlStr = "";
  79. string conditionStr = " ";
  80. DataTable dtSettlSummary = (DataTable)dgvSettlSummary.DataSource;
  81. int iCurRow = dgvSettlSummary.CurrentRow.Index;
  82. //DataTable dtInteface = (DataTable)cbxInterface.DataSource;
  83. if (cbgGroupSet.GetItemCheckState(0))
  84. {
  85. conditionStr = conditionStr + " and Interface_Dr ='" + dtSettlSummary.Rows[iCurRow]["Interface_dr"].ToString() + "'";
  86. }
  87. //if (cbgGroupSet.GetItemCheckState(1))
  88. //{
  89. // conditionStr = conditionStr + " and InsuranceType ='" + dtSettlSummary.Rows[iCurRow]["insutype"].ToString() + "'";
  90. //}
  91. if (cbgGroupSet.GetItemCheckState(2))
  92. {
  93. conditionStr = conditionStr + " and ClearingType ='" + dtSettlSummary.Rows[iCurRow]["clr_type"].ToString() + "'";
  94. }
  95. if (cbgGroupSet.GetItemCheckState(3))
  96. {
  97. conditionStr = conditionStr + " and ClearingOrgan ='" + dtSettlSummary.Rows[iCurRow]["setl_optins"].ToString() + "'";
  98. }
  99. if (cbgGroupSet.GetItemCheckState(4))
  100. {
  101. sqlStr = sqlStr + ",BillType";
  102. conditionStr = conditionStr + " and BillType ='" + dtSettlSummary.Rows[iCurRow]["BillType"].ToString() + "'";
  103. }
  104. sqlStr = "select * " + getWhereCondition();
  105. sqlStr = sqlStr + conditionStr;
  106. JObject joSqlstr = new JObject();
  107. joSqlstr.Add("sqlStr", sqlStr);
  108. JArray jaParam = new JArray();
  109. jaParam.Add(joSqlstr);
  110. JObject joSettlQuery = new JObject();
  111. joSettlQuery.Add("params", jaParam);
  112. joSettlQuery.Add("code", "09010059");
  113. InvokeHelper invoker = new InvokeHelper();
  114. JObject joRtn = invoker.invokeInsuService(joSettlQuery.ToString(), "查询结算信息");
  115. //DataTable dt = (DataTable)joRtn["result"]["data"].ToObject(typeof(DataTable));
  116. JArray ja = JArray.Parse(JsonHelper.getDestValue(joRtn, "result.data"));
  117. DataTable dt = (DataTable)JsonConvert.DeserializeObject(JsonHelper.getDestValue(joRtn, "result.data"), (typeof(DataTable)));
  118. dgvHisSettlRec.DataSource = dt;
  119. if (dt.Rows.Count == 0)
  120. {
  121. error = "未查询到数据";
  122. return -1;
  123. }
  124. //dt.Columns[7].DataType = typeof(float);//不允许
  125. //dgvHisSettlRecFooter.DataGridView = dgvHisSettlRec;
  126. //dgvHisSettlRecFooter.Dock = System.Windows.Forms.DockStyle.Bottom;
  127. //dgvHisSettlRecFooter.Clear();
  128. //dgvHisSettlRecFooter["AdmID"] = "合计";
  129. //dgvHisSettlRecFooter["OverLimitAmount"] = "测试";
  130. return 0;
  131. }
  132. catch (Exception ex)
  133. {
  134. error = "queryHisSettlementInfo:" + ex.Message;
  135. return -1;
  136. }
  137. }
  138. private string getWhereCondition()
  139. {
  140. string sqlStr = "";
  141. sqlStr = sqlStr + " FROM BS_MedInsuSettlement WHERE Hospital_Dr=" + Global.inf.hospitalDr;
  142. sqlStr = sqlStr + " and OccurTime>'" + dpST.Text + " 00:00:00'";
  143. sqlStr = sqlStr + " and OccurTime<'" + dpED.Text + " 23:59:59'";
  144. sqlStr = sqlStr + " and (left(InsuranceAreaCode,2)='44')";
  145. DataTable dtInteface = (DataTable)cbxInterface.DataSource;
  146. int i = cbxInterface.SelectedIndex;
  147. if (cbxInterface.Text != "")
  148. {
  149. sqlStr = sqlStr + " and Interface_Dr =" + dtInteface.Rows[i]["ID"].ToString();
  150. }
  151. if (cbxInsuType.Text != "")
  152. {
  153. sqlStr = sqlStr + " and InsuranceType ='" + cbxInsuType.SelectedValue + "'";
  154. }
  155. if (cbxClrType.Text != "")
  156. {
  157. sqlStr = sqlStr + " and ClearingType ='" + cbxClrType.SelectedValue + "'";
  158. }
  159. if (tbSettlOption.Text != "")
  160. {
  161. sqlStr = sqlStr + " and ClearingOrgan ='" + tbSettlOption.Text + "'";
  162. }
  163. //ValidFlag=1 and BillType=1 表示正常结算记录 ValidFlag=0 and BillType=-1 表示退费记录 ValidFlag=0表示无效记录
  164. if (cbxValid.SelectedIndex != 0)
  165. {
  166. if (cbxValid.SelectedIndex == 1)
  167. sqlStr = sqlStr + " and ValidFlag =1 and BillType=1";
  168. else
  169. sqlStr = sqlStr + " and ValidFlag =0 and BillType=-1";
  170. }
  171. //确认标志
  172. if (cbConfirmFlag.SelectedIndex != 0)
  173. {
  174. if (cbConfirmFlag.SelectedIndex == 1)
  175. sqlStr = sqlStr + " and ((ConfirmFlag = 1 and AdmType = 3) or (AdmType in ('1','2'))) ";
  176. else
  177. sqlStr = sqlStr + " and ConfirmFlag <> 1";
  178. }
  179. // ReversalFlag = 1 表示数据已冲正,ReversalFlag =0 表示 正常未冲正数据
  180. if (cbReservelFlag.SelectedIndex != 0)
  181. {
  182. if (cbReservelFlag.SelectedIndex == 1)
  183. sqlStr = sqlStr + " and ReversalFlag =1 ";
  184. else
  185. sqlStr = sqlStr + " and ReversalFlag <> 1 ";
  186. }
  187. return sqlStr;
  188. }
  189. #endregion
  190. #region 对明细账
  191. public static void writeToTxt(string content, string filePath, string fileName)
  192. {
  193. //创建文件夹,文件夹名称与TXT同名
  194. string finalPath = filePath + "\\" + fileName;
  195. if (!Directory.Exists(finalPath))
  196. {
  197. DirectoryInfo dirInfo = Directory.CreateDirectory(finalPath);
  198. }
  199. //判断文件夹中是否存在txt
  200. string finalFileName = finalPath + "\\" + fileName + ".txt";
  201. if (!File.Exists(finalFileName))
  202. {
  203. FileStream fs1 = File.Create(finalFileName);
  204. fs1.Close();
  205. }
  206. FileStream fs = new FileStream(finalFileName, FileMode.Append, FileAccess.Write);
  207. StreamWriter sw = new StreamWriter(fs);
  208. sw.WriteLine(content);
  209. sw.Close();
  210. fs.Close();
  211. }
  212. /// <summary>
  213. /// 读文件到byte[]
  214. /// </summary>
  215. /// <param name="fileName">硬盘文件路径</param>
  216. /// <returns></returns>
  217. public static byte[] ReadFileToByte(string fileName)
  218. {
  219. FileStream pFileStream = null;
  220. byte[] pReadByte = new byte[0];
  221. try
  222. {
  223. pFileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
  224. BinaryReader r = new BinaryReader(pFileStream);
  225. r.BaseStream.Seek(0, SeekOrigin.Begin); //将文件指针设置到文件开
  226. pReadByte = r.ReadBytes((int)r.BaseStream.Length);
  227. return pReadByte;
  228. }
  229. catch
  230. {
  231. return pReadByte;
  232. }
  233. finally
  234. {
  235. if (pFileStream != null)
  236. pFileStream.Close();
  237. }
  238. }
  239. /// <summary>
  240. ///单字节转有符号整数
  241. /// </summary>
  242. /// <param name="data"></param>
  243. /// <returns></returns>
  244. public string byteArrayToDecString(byte[] data)
  245. {
  246. StringBuilder builder = new StringBuilder();
  247. for (int i = 0; i < data.Length; i++)
  248. {
  249. builder.Append((sbyte)data[i] + ",");
  250. }
  251. return builder.ToString().Trim();
  252. }
  253. private int HISDetailDataExport(string filePath, string fileName)
  254. {
  255. try
  256. {
  257. DataTable dt = (DataTable)dgvHisSettlRec.DataSource;
  258. string content = "";
  259. for (int i = 0; i < dt.Rows.Count; i++)
  260. {
  261. string flag = "";
  262. if (dt.Rows[i]["ValidFlag"].ToString() == "-1")
  263. {
  264. flag = "1";
  265. }
  266. else
  267. {
  268. flag = "0";
  269. }
  270. content = "\r\n"
  271. + dt.Rows[i]["SettlementID"].ToString() + "\t"
  272. + dt.Rows[i]["MdtrtID"].ToString() + "\t"
  273. + dt.Rows[i]["PersonnelNO"].ToString() + "\t"
  274. + dt.Rows[i]["Sumamt"].ToString() + "\t"
  275. + dt.Rows[i]["FundPaySumamt"].ToString() + "\t"
  276. + dt.Rows[i]["AccountPaySumamt"].ToString() + "\t"
  277. + flag
  278. + content;
  279. }
  280. string finalContent = content.Remove(0, 2);
  281. writeToTxt(finalContent, filePath, fileName);
  282. return 0;
  283. }
  284. catch (Exception ex)
  285. {
  286. MessageBox.Show(ex.Message);
  287. return -1;
  288. }
  289. }
  290. private int exportAndCompress(out string zipPath)
  291. {
  292. zipPath = "";
  293. try
  294. {
  295. //导出TXT
  296. string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
  297. string filePath = Global.currentDirectory + "\\Download";
  298. HISDetailDataExport(filePath, fileName);
  299. //压缩
  300. string finalDirPath = filePath + "\\" + fileName;//同名文件夹
  301. zipPath = finalDirPath + ".zip";
  302. System.IO.Compression.ZipFile.CreateFromDirectory(finalDirPath, zipPath);
  303. return 0;
  304. }
  305. catch (Exception ex)
  306. {
  307. zipPath = "exportAndCompress:" + ex.Message;
  308. return -1;
  309. }
  310. }
  311. /// <summary>
  312. /// 上传ZIP文件转字节流再转换为有符号10进制数组后上传
  313. /// </summary>
  314. /// <param name="zipPath"></param>
  315. /// <param name="file_qury_no"></param>
  316. /// <returns></returns>
  317. private int uploadFileToCenter(string zipPath, out string file_qury_no)
  318. {
  319. string outParam = "";
  320. try
  321. {
  322. byte[] bArray = ReadFileToByte(zipPath);
  323. string str = "[" + byteArrayToDecString(bArray) + "]";
  324. JObject joTmp = new JObject();
  325. joTmp.Add("in", JArray.Parse(str));
  326. joTmp.Add("filename", txtName + ".zip");
  327. joTmp.Add("fixmedins_code", Global.inf.hospitalNO);
  328. JObject joFsUploadIn = new JObject();
  329. joFsUploadIn.Add("fsUploadIn", joTmp);
  330. InvokeHelper invoker = new InvokeHelper();
  331. JObject jo9101Rtn = invoker.invokeCenterService(TradeEnum.FileUpload, joFsUploadIn);
  332. if (JsonHelper.parseCenterReturnJson(jo9101Rtn, out outParam) != 0)
  333. {
  334. file_qury_no = outParam;
  335. return -1;
  336. }
  337. else
  338. {
  339. file_qury_no = JsonHelper.getDestValue(jo9101Rtn, "output.file_qury_no");
  340. return 0;
  341. }
  342. }
  343. catch (Exception ex)
  344. {
  345. file_qury_no = "uploadFileToCenter:" + ex.Message;
  346. return -1;
  347. }
  348. }
  349. private int checkDetail(string file_qury_no, out string outParam, out string fileName)
  350. {
  351. fileName = "";
  352. try
  353. {
  354. DataTable dt = (DataTable)dgvSettlSummary.DataSource;
  355. int i = dgvSettlSummary.CurrentRow.Index;
  356. dynamic joCheck = new JObject();
  357. joCheck.file_qury_no = file_qury_no.Replace(@"\\", @"\");
  358. joCheck.clr_type = dt.Rows[i]["clr_type"].ToString();
  359. joCheck.setl_optins = dt.Rows[i]["setl_optins"].ToString();
  360. joCheck.stmt_begndate = dpST.Value.ToString("yyyy-MM-dd HH:mm:ss");
  361. joCheck.stmt_enddate = dpED.Value.ToString("yyyy-MM-dd HH:mm:ss");
  362. joCheck.medfee_sumamt = dt.Rows[i]["medfee_sumamt"].ToString();
  363. joCheck.fund_pay_sumamt = dt.Rows[i]["fund_pay_sumamt"].ToString();
  364. joCheck.cash_payamt = dt.Rows[i]["cash_payamt"].ToString();
  365. joCheck.fixmedins_setl_cnt = dt.Rows[i]["fixmedins_setl_cnt"].ToString();
  366. JObject joData = new JObject();
  367. joData.Add("data", joCheck);
  368. InvokeHelper invoker = new InvokeHelper();
  369. JObject jo3202Rtn = invoker.invokeCenterService(TradeEnum.FeeDetailCheck, joData);
  370. if (JsonHelper.parseCenterReturnJson(jo3202Rtn, out outParam) != 0)
  371. {
  372. return -1;
  373. }
  374. else
  375. {
  376. outParam = JsonHelper.getDestValue(jo3202Rtn, "output.fileinfo.file_qury_no");
  377. fileName = JsonHelper.getDestValue(jo3202Rtn, "output.fileinfo.filename");
  378. return 0;
  379. }
  380. }
  381. catch (Exception ex)
  382. {
  383. outParam = "checkDetail:" + ex.Message;
  384. return -1;
  385. }
  386. }
  387. private int downloadZIP(string file_qury_no, string fileName, out string outParam)
  388. {
  389. outParam = "";
  390. try
  391. {
  392. JObject joTmp = new JObject();
  393. joTmp = new JObject();
  394. joTmp.Add("file_qury_no", file_qury_no.Replace(@"\\", @"\"));
  395. joTmp.Add("filename", fileName);
  396. joTmp.Add("fixmedins_code", Global.inf.hospitalNO);
  397. JObject joFsDownloadIn = new JObject();
  398. joFsDownloadIn.Add("fsDownloadIn", joTmp);
  399. InvokeHelper invoker = new InvokeHelper();
  400. JObject jo9102Rtn = invoker.DownloadCenterFile(JsonHelper.setCenterInpar("9102", joFsDownloadIn).ToString());
  401. string error = "";
  402. if (JsonHelper.parseIrisRtnValue(jo9102Rtn, out error) != 0)
  403. {
  404. outParam = error;
  405. return -1;
  406. }
  407. else
  408. {
  409. outParam = JsonHelper.getDestValue(jo9102Rtn, "filePath");
  410. return 0;
  411. }
  412. }
  413. catch (Exception ex)
  414. {
  415. outParam = "downloadZIP:" + ex.Message;
  416. return -1;
  417. }
  418. }
  419. private int importToDgvCenterSetlRec(string fileName, string zipFilePath, out string outParam)
  420. {
  421. outParam = "";
  422. try
  423. {
  424. string dir = fileName.Substring(1, fileName.Length - 4);
  425. //解压缩
  426. string txtFileDir = System.Environment.CurrentDirectory + "\\Download\\" + dir;
  427. string txtFilePath = zipFilePath.Substring(0, zipFilePath.Length - 4);
  428. if (File.Exists(txtFilePath))
  429. {
  430. File.Delete(txtFilePath);
  431. }
  432. if (!Directory.Exists(txtFileDir))
  433. {
  434. Directory.CreateDirectory(txtFileDir);
  435. }
  436. ZipFile.ExtractToDirectory(zipFilePath, txtFileDir);
  437. //导入文件
  438. GridViewSetter grd = new GridViewSetter();
  439. grd.SetHeaderTextOfDgvCenterSetlRec(dgvCenterSettlRec);
  440. //txtFileDir = txtFileDir;//E:\GHSF\SCYBDownLoad\result.txt
  441. string[] lines = System.IO.File.ReadAllLines(txtFileDir + "\\result.txt");
  442. DataTable dt = new DataTable();
  443. dt.Columns.Add("sn", typeof(int));
  444. dt.Columns.Add("psn_no", typeof(string));
  445. dt.Columns.Add("mdtrt_id", typeof(string));
  446. dt.Columns.Add("setl_id", typeof(string));
  447. dt.Columns.Add("msgid", typeof(string));
  448. dt.Columns.Add("stmt_rslt", typeof(string));
  449. dt.Columns.Add("refd_setl_flag", typeof(string));
  450. dt.Columns.Add("memo", typeof(string));
  451. dt.Columns.Add("medfee_sumamt", typeof(string));
  452. dt.Columns.Add("fund_pay_sumamt", typeof(string));
  453. dt.Columns.Add("acct_pay", typeof(string));
  454. //foreach (string line in lines)
  455. for (int i = 0; i < lines.Length; i++)
  456. {
  457. string[] strs = (lines[i] + "\t").Split('\t');
  458. DataRow dr = dt.NewRow();
  459. //Global.inf.writeLog(lines[i].ToString());
  460. //Global.inf.writeLog(strs.Length.ToString());
  461. dr["sn"] = i + 1;
  462. dr["psn_no"] = strs[0];
  463. dr["mdtrt_id"] = strs[1];
  464. dr["setl_id"] = strs[2];
  465. dr["msgid"] = strs[3];
  466. dr["stmt_rslt"] = strs[4];
  467. dr["refd_setl_flag"] = strs[5];
  468. dr["memo"] = strs[6];
  469. dr["medfee_sumamt"] = strs[7];
  470. dr["fund_pay_sumamt"] = strs[8];
  471. dr["acct_pay"] = strs[9];
  472. //dr["Field2"] = strs[2];
  473. dt.Rows.Add(dr);
  474. }
  475. dgvCenterSettlRec.DataSource = dt;
  476. return 0;
  477. }
  478. catch (Exception ex)
  479. {
  480. outParam = "importToDgvCenterSetlRec:" + ex.Message;
  481. return -1;
  482. }
  483. }
  484. private int CheckDetail_Single(out string outParam)
  485. {
  486. outParam = "";
  487. //先签到
  488. CenterBusiness cBus = new CenterBusiness();
  489. JObject jo9001Rtn = new JObject();
  490. cBus.signIn(out jo9001Rtn);
  491. try
  492. {
  493. //导出并压缩
  494. if (exportAndCompress(out outParam) != 0)
  495. {
  496. return -1;
  497. }
  498. string zipPath = outParam;
  499. //上传给中心,
  500. if (uploadFileToCenter(zipPath, out outParam) != 0)
  501. {
  502. return -1;
  503. }
  504. string file_query_no = outParam;
  505. string fileName = "";
  506. //3202明细对账 输出查询号和文件名
  507. if (checkDetail(file_query_no, out outParam, out fileName) != 0)
  508. {
  509. return -1;
  510. }
  511. file_query_no = outParam;
  512. Global.writeLog("checkDetail:" + outParam + "///" + fileName);
  513. //下载 获取 查询号和文件名后 下载
  514. if (downloadZIP(file_query_no, fileName, out outParam) != 0)
  515. {
  516. return -1;
  517. }
  518. zipPath = outParam;
  519. Global.writeLog("downloadZIP:" + outParam);
  520. //导入DGV
  521. if (importToDgvCenterSetlRec(fileName, zipPath, out outParam) != 0)
  522. {
  523. return -1;
  524. }
  525. Global.writeLog("importToDgvCenterSetlRec:" + outParam);
  526. return 0;
  527. }
  528. catch (Exception ex)
  529. {
  530. outParam = "CheckDetail_Single:" + ex.Message;
  531. return -1;
  532. }
  533. }
  534. #endregion
  535. #region 对账
  536. /// <summary>
  537. /// 单条对总账【本地】
  538. /// </summary>
  539. /// <param name="error"></param>
  540. /// <returns></returns>
  541. private int Check_Single(out string error)
  542. {
  543. error = ""; string setlOptins = "";
  544. DataTable dt = (DataTable)dgvSettlSummary.DataSource;
  545. int i = dgvSettlSummary.CurrentRow.Index;
  546. dynamic joCheck = new JObject();
  547. joCheck.insutype = dt.Rows[i]["insutype"].ToString(); //险种类型
  548. joCheck.clr_type = dt.Rows[i]["clr_type"].ToString(); //清算类别
  549. //if (tbSettlOption.Text != "")
  550. //{
  551. // joCheck.setl_optins = tbSettlOption.Text; //dt.Rows[i]["setl_optins"].ToString(); //结算经办机构
  552. // setlOptins = tbSettlOption.Text;
  553. //}
  554. //else
  555. //{
  556. joCheck.setl_optins = dt.Rows[i]["setl_optins"].ToString(); //结算经办机构
  557. setlOptins = dt.Rows[i]["setl_optins"].ToString();
  558. //}
  559. joCheck.medfee_sumamt = dt.Rows[i]["medfee_sumamt"].ToString(); //医疗费总额
  560. joCheck.fund_pay_sumamt = dt.Rows[i]["fund_pay_sumamt"].ToString(); //基金支付总额
  561. joCheck.acct_pay = dt.Rows[i]["acct_pay"].ToString(); //个人账户支付金额
  562. joCheck.fixmedins_setl_cnt = dt.Rows[i]["fixmedins_setl_cnt"].ToString(); //定点医药机构结算笔数
  563. joCheck.stmt_begndate = dpST.Value.ToString("yyyy-MM-dd 00:00:00"); //对账开始日期
  564. joCheck.stmt_enddate = dpED.Value.ToString("yyyy-MM-dd 23:59:59"); //对账结束日期
  565. JObject joData = new JObject();
  566. joData.Add("data", joCheck);
  567. //上传给中心
  568. //先签到
  569. CenterBusiness cBus = new CenterBusiness();
  570. JObject jo9001Rtn = new JObject();
  571. cBus.signIn(out jo9001Rtn);
  572. Global.pat.insuplc_admdvs = setlOptins;
  573. InvokeHelper invoker = new InvokeHelper();
  574. JObject joRtn = invoker.invokeCenterService(TradeEnum.FeeSummaryCheck, joData);
  575. if (JsonHelper.parseCenterReturnJson(joRtn, out error) != 0)
  576. {
  577. return -1;
  578. }
  579. else
  580. {
  581. if (JsonHelper.getDestValue(joRtn, "output.stmtinfo.stmt_rslt") != "0")
  582. {
  583. error = JsonHelper.getDestValue(joRtn, "output.stmtinfo.stmt_rslt_dscr");
  584. return -1;
  585. }
  586. else
  587. {
  588. return 0;
  589. }
  590. }
  591. }
  592. #endregion
  593. #region 智能比对
  594. private int compareDataGridView(string value, string colName, Sunny.UI.UIDataGridView dgv)
  595. {
  596. try
  597. {
  598. for (int i = 0; i < dgv.RowCount; i++)
  599. {
  600. if (dgv.Rows[i].Cells[colName].Value.ToString() == value)
  601. {
  602. return 0;
  603. }
  604. }
  605. return -1;
  606. }
  607. catch (Exception ex)
  608. {
  609. MessageBox.Show("compareDataGridView" + ex.Message);
  610. return -1;
  611. }
  612. }
  613. #endregion
  614. #endregion
  615. #region 按钮事件
  616. private void Btn_Query_Click(object sender, EventArgs e)
  617. {
  618. DataTable dtInteface = (DataTable)cbxInterface.DataSource;
  619. int i = cbxInterface.SelectedIndex;
  620. //乘以单据类型后,IRIS会返回整数,关键不知道SQL里咋转换为浮点数
  621. //string sqlStr = "SELECT SUM(BillType*Sumamt) AS medfee_sumamt,count(*) AS fixmedins_setl_cnt,SUM(BillType*PersonCashPay) AS cash_payamt, ";
  622. //sqlStr = sqlStr + " SUM(BillType*AccountPaySumamt) AS acct_pay,SUM(BillType*FundPaySumamt) AS fund_pay_sumamt ";
  623. //对账时个人账户=个人账户+共济账户
  624. string sqlStr = "SELECT SUM(BillType*Sumamt) AS medfee_sumamt,count(*) AS fixmedins_setl_cnt,SUM(BillType*PersonCashPay) AS cash_payamt, ";
  625. sqlStr = sqlStr + " SUM(billType*(AccountPaySumamt+AccountMutualAidAmount)) AS acct_pay,SUM(BillType*FundPaySumamt) AS fund_pay_sumamt ";
  626. //sqlStr = sqlStr + " Interface_dr,clearingWay AS clr_way,clearingType AS clr_type ";
  627. // 增加先行自付金额、医疗救助基金、公务员医疗补助、个人账户共济支付、企业补充、职工大额
  628. sqlStr += ",Sum(BillType*PreSelfPayAmount) as PreSelfPayAmount,sum(BillType*MedicalAssistPay) as MedicalAssistPay,sum(BillType*CivilserviceAllowancePay) as CivilserviceAllowancePay,"
  629. + "sum(BillType*AccountMutualAidAmount) as AccountMutualAidAmount ,sum(BillType*LargeExpensesSupplementPay) as LargeExpensesSupplementPay,"
  630. + "sum(BillType*EnterpriseSupplementPay) as EnterpriseSupplementPay ";
  631. string conditionStr = " Group By";
  632. if (cbgGroupSet.GetItemCheckState(0))
  633. {
  634. sqlStr = sqlStr + ",Interface_Dr";
  635. conditionStr = conditionStr + " Interface_Dr,";
  636. }
  637. if (cbgGroupSet.GetItemCheckState(1))
  638. {
  639. sqlStr = sqlStr + ",InsuranceType as insutype";
  640. conditionStr = conditionStr + " InsuranceType,";
  641. }
  642. if (cbgGroupSet.GetItemCheckState(2))
  643. {
  644. sqlStr = sqlStr + ",ClearingType as clr_type";
  645. conditionStr = conditionStr + " ClearingType,";
  646. }
  647. if (cbgGroupSet.GetItemCheckState(3))
  648. {
  649. sqlStr = sqlStr + ",ClearingOrgan as setl_optins";
  650. conditionStr = conditionStr + " ClearingOrgan,";
  651. }
  652. if (cbgGroupSet.GetItemCheckState(4))
  653. {
  654. sqlStr = sqlStr + ",BillType";
  655. conditionStr = conditionStr + " BillType,";
  656. }
  657. sqlStr = sqlStr + getWhereCondition();
  658. conditionStr = conditionStr.Remove(conditionStr.Length - 1, 1);
  659. sqlStr = sqlStr + conditionStr;
  660. JObject joSqlstr = new JObject();
  661. //MessageBox.Show(sqlStr);
  662. joSqlstr.Add("sqlStr", sqlStr);
  663. JArray jaParam = new JArray();
  664. jaParam.Add(joSqlstr);
  665. JObject joSettlQuery = new JObject();
  666. joSettlQuery.Add("params", jaParam);
  667. joSettlQuery.Add("code", "09010061");
  668. InvokeHelper invoker = new InvokeHelper();
  669. JObject joRtn = invoker.invokeInsuService(joSettlQuery.ToString(), "查询汇总结算信息");
  670. DataTable dt = (DataTable)joRtn["result"]["data"].ToObject(typeof(DataTable));
  671. dgvSettlSummary.DataSource = dt;
  672. //初始化HIS结算明细View数据
  673. dgvHisSettlRec.DataSource = null;
  674. }
  675. private void btBatchCheck_Click(object sender, EventArgs e)
  676. {
  677. string errMsg = "";
  678. bool success = true;
  679. for (int i = 0; i < dgvSettlSummary.RowCount; i++)
  680. {
  681. dgvSettlSummary.CurrentCell = dgvSettlSummary.Rows[i].Cells[0];
  682. if (Check_Single(out errMsg) != 0)
  683. {
  684. dgvSettlSummary.Rows[i].DefaultCellStyle.BackColor = Color.Red;
  685. rtbCheckLog.AppendText("第" + (i + 1).ToString() + "条对账失败!" + errMsg + "\r\n");
  686. success = false;
  687. }
  688. }
  689. if (success)
  690. {
  691. MessageBox.Show("批量对账全部成功!");
  692. }
  693. else
  694. {
  695. MessageBox.Show("部分对账失败,请查看对账结果!");
  696. }
  697. }
  698. private void tsmCheck_Single_Click(object sender, EventArgs e)
  699. {
  700. string error = "";
  701. if (Check_Single(out error) != 0)
  702. {
  703. MessageBox.Show("对总账失败:" + error);
  704. }
  705. else
  706. {
  707. if (dgvHisSettlRec.SelectedIndex != -1)
  708. {
  709. dgvHisSettlRec.Rows[dgvHisSettlRec.SelectedIndex].DefaultCellStyle.BackColor = Color.White;
  710. }
  711. MessageBox.Show("对总账成功");
  712. }
  713. }
  714. private void tsmCheckDetail_Single_Click(object sender, EventArgs e)
  715. {
  716. //HIS明细
  717. string error;
  718. if (queryHisSettlementInfo(out error) != 0)
  719. {
  720. MessageBox.Show(error);
  721. }
  722. //中心明细
  723. if (CheckDetail_Single(out error) != 0)
  724. {
  725. MessageBox.Show(error);
  726. }
  727. }
  728. private void tsmCheck_Batch_Click(object sender, EventArgs e)
  729. {
  730. btBatchCheck_Click(sender, e);
  731. }
  732. private void tsmCheckDetail_Batch_Click(object sender, EventArgs e)
  733. {
  734. }
  735. private void tsmHisRecord_Click(object sender, EventArgs e)
  736. {
  737. string error;
  738. if (queryHisSettlementInfo(out error) != 0)
  739. {
  740. MessageBox.Show(error);
  741. }
  742. }
  743. private void tsmAICheck_Click(object sender, EventArgs e)
  744. {
  745. for (int i = 0; i < dgvHisSettlRec.RowCount; i++)
  746. {
  747. string value = dgvHisSettlRec.Rows[i].Cells["SettlementID"].Value.ToString();
  748. string colName = "setl_id";
  749. if (compareDataGridView(value, colName, dgvCenterSettlRec) != 0)
  750. {
  751. dgvHisSettlRec.Rows[i].DefaultCellStyle.BackColor = Color.Red;
  752. rtbCheckDetailLog.AppendText("HIS结算ID:" + value + "在中心明细中未找到数据!" + "\r\n");
  753. }
  754. }
  755. for (int i = 0; i < dgvCenterSettlRec.RowCount; i++)
  756. {
  757. string value = dgvCenterSettlRec.Rows[i].Cells["setl_id"].Value.ToString();
  758. string colName = "SettlementID";
  759. if (compareDataGridView(value, colName, dgvHisSettlRec) != 0)
  760. {
  761. dgvCenterSettlRec.Rows[i].DefaultCellStyle.BackColor = Color.Red;
  762. rtbCheckDetailLog.AppendText("中心结算ID:" + value + "在HIS明细中未找到数据!" + "\r\n");
  763. }
  764. }
  765. }
  766. private void tsmExport_Click(object sender, EventArgs e)
  767. {
  768. txtName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
  769. txtPath = Global.currentDirectory + "\\Download";
  770. if (HISDetailDataExport(txtPath, txtName) != 0)
  771. {
  772. MessageBox.Show("导出TXT失败!");
  773. }
  774. else
  775. {
  776. MessageBox.Show("导出TXT成功!");
  777. }
  778. }
  779. private void tsmCompress_Click(object sender, EventArgs e)
  780. {
  781. string finalDirPath = txtPath + "\\" + txtName;
  782. finalAchPath = finalDirPath + ".zip";
  783. System.IO.Compression.ZipFile.CreateFromDirectory(finalDirPath, finalAchPath);
  784. MessageBox.Show("将TXT压缩为ZIP成功!");
  785. }
  786. private void tsmZIPToSDec_Click(object sender, EventArgs e)
  787. {
  788. byte[] bArray = ReadFileToByte(finalAchPath);
  789. string str = byteArrayToDecString(bArray);
  790. Global.writeLog(str);
  791. MessageBox.Show("ZIP转为有符号整数成功!");
  792. }
  793. private void tsmUploadZIP_Click(object sender, EventArgs e)
  794. {
  795. string outParam = "";
  796. byte[] bArray = ReadFileToByte(finalAchPath);
  797. string str = "[" + byteArrayToDecString(bArray) + "]";
  798. JObject joTmp = new JObject();
  799. joTmp.Add("in", JArray.Parse(str));
  800. joTmp.Add("filename", txtName + ".zip");
  801. Global.inf.fileName = txtName + ".zip";
  802. //joTmp.Add("filename", finalAchPath.Replace("\\",@"\"));
  803. joTmp.Add("fixmedins_code", Global.inf.hospitalNO);
  804. JObject joFsUploadIn = new JObject();
  805. joFsUploadIn.Add("fsUploadIn", joTmp);
  806. InvokeHelper invoker = new InvokeHelper();
  807. JObject jo9101Rtn = invoker.invokeCenterService(TradeEnum.FileUpload, joFsUploadIn);
  808. if (JsonHelper.parseCenterRtnValue(jo9101Rtn, out outParam) != 0)
  809. {
  810. outParam = JsonHelper.setExceptionJson(-1, "【9101】文件上传失败", outParam).ToString();
  811. return;
  812. }
  813. else
  814. {
  815. MessageBox.Show("【9101】文件上传成功");
  816. }
  817. }
  818. private void tsm3202_Click(object sender, EventArgs e)
  819. {
  820. if (string.IsNullOrEmpty(Global.inf.areaCode))
  821. {
  822. MessageBox.Show("请先签到!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  823. return;
  824. }
  825. string outParam = "";
  826. DataTable dt = (DataTable)dgvSettlSummary.DataSource;
  827. int i = dgvSettlSummary.CurrentRow.Index;
  828. dynamic joCheck = new JObject();
  829. joCheck.file_qury_no = JObject.Parse(fileDir);
  830. joCheck.clr_type = dt.Rows[i]["clr_type"].ToString();
  831. joCheck.setl_optins = dt.Rows[i]["setl_optins"].ToString();
  832. joCheck.stmt_begndate = dpST.Value.ToString("yyyy-MM-dd HH:mm:ss");
  833. joCheck.stmt_enddate = dpED.Value.ToString("yyyy-MM-dd HH:mm:ss");
  834. joCheck.medfee_sumamt = dt.Rows[i]["medfee_sumamt"].ToString();
  835. joCheck.fund_pay_sumamt = dt.Rows[i]["fund_pay_sumamt"].ToString();
  836. joCheck.cash_payamt = dt.Rows[i]["cash_payamt"].ToString();
  837. joCheck.fixmedins_setl_cnt = dt.Rows[i]["fixmedins_setl_cnt"].ToString();
  838. JObject joData = new JObject();
  839. joData.Add("data", joCheck);
  840. InvokeHelper invoker = new InvokeHelper();
  841. JObject jo3202Rtn = invoker.invokeCenterService(TradeEnum.FeeDetailCheck, joData);
  842. if (JsonHelper.parseCenterRtnValue(jo3202Rtn, out outParam) != 0)
  843. {
  844. outParam = JsonHelper.setExceptionJson(-1, "【3202】医保明细对账失败", outParam).ToString();
  845. MessageBox.Show(outParam);
  846. return;
  847. }
  848. else
  849. {
  850. MessageBox.Show("【3202】医保明细对账成功");
  851. }
  852. }
  853. private void tsmDownload_Click(object sender, EventArgs e)
  854. {
  855. string outParam = "";
  856. JObject joTmp = new JObject();
  857. joTmp.Add("file_qury_no", JObject.Parse(fileDir.Replace(@"\\", @"\")));
  858. joTmp.Add("filename", txtName + ".zip");
  859. joTmp.Add("fixmedins_code", Global.inf.hospitalNO);
  860. JObject joFsDownloadIn = new JObject();
  861. joFsDownloadIn.Add("fsDownloadIn", joTmp);
  862. InvokeHelper invoker = new InvokeHelper();
  863. jo9102Rtn = invoker.invokeCenterService(TradeEnum.FileDownload, joFsDownloadIn);
  864. if (JsonHelper.parseCenterRtnValue(jo9102Rtn, out outParam) != 0)
  865. {
  866. outParam = JsonHelper.setExceptionJson(-1, "【9102】文件下载失败", outParam).ToString();
  867. MessageBox.Show(outParam);
  868. return;
  869. }
  870. else
  871. {
  872. MessageBox.Show("【9102】文件下载成功");
  873. }
  874. }
  875. private void tsmUnCompress_Click(object sender, EventArgs e)
  876. {
  877. //解压缩
  878. string zipFilePath = jo9102Rtn["filePath"].ToString();
  879. string txtFileDir = System.Environment.CurrentDirectory + "\\Download";
  880. //string txtFilePath = txtFileDir + "\\" + filename.Substring(0, filename.Length - 4);
  881. string txtFilePath = txtFileDir;
  882. if (File.Exists(txtFilePath))
  883. {
  884. File.Delete(txtFilePath);
  885. }
  886. ZipFile.ExtractToDirectory(zipFilePath, txtFileDir);
  887. }
  888. private void tsmImport_Click(object sender, EventArgs e)
  889. {
  890. GridViewSetter grd = new GridViewSetter();
  891. grd.SetHeaderTextOfDgvCenterSetlRec(dgvCenterSettlRec);
  892. string txtFileDir = fileDir;//E:\GHSF\SCYBDownLoad\result.txt
  893. string[] lines = System.IO.File.ReadAllLines(txtFileDir);
  894. Global.writeLog(lines.ToString());
  895. DataTable dt = new DataTable();
  896. dt.Columns.Add("sn", typeof(int));
  897. dt.Columns.Add("psn_no", typeof(string));
  898. dt.Columns.Add("mdtrt_id", typeof(string));
  899. dt.Columns.Add("setl_id", typeof(string));
  900. dt.Columns.Add("msgid", typeof(string));
  901. dt.Columns.Add("stmt_rslt", typeof(string));
  902. dt.Columns.Add("refd_setl_flag", typeof(string));
  903. dt.Columns.Add("memo", typeof(string));
  904. dt.Columns.Add("medfee_sumamt", typeof(string));
  905. dt.Columns.Add("fund_pay_sumamt", typeof(string));
  906. dt.Columns.Add("acct_pay", typeof(string));
  907. //foreach (string line in lines)
  908. for (int i = 0; i < lines.Length; i++)
  909. {
  910. string[] strs = (lines[i] + "\t").Split('\t');
  911. DataRow dr = dt.NewRow();
  912. //Global.inf.writeLog(lines[i].ToString());
  913. //Global.inf.writeLog(strs.Length.ToString());
  914. dr["sn"] = i;
  915. dr["psn_no"] = strs[0];
  916. dr["mdtrt_id"] = strs[1];
  917. dr["setl_id"] = strs[2];
  918. dr["msgid"] = strs[3];
  919. dr["stmt_rslt"] = strs[4];
  920. dr["refd_setl_flag"] = strs[5];
  921. dr["memo"] = strs[6];
  922. dr["medfee_sumamt"] = strs[7];
  923. dr["fund_pay_sumamt"] = strs[8];
  924. dr["acct_pay"] = strs[9];
  925. //dr["Field2"] = strs[2];
  926. dt.Rows.Add(dr);
  927. }
  928. dgvCenterSettlRec.DataSource = dt;
  929. }
  930. private void tsmHandCheck_Click(object sender, EventArgs e)
  931. {
  932. JObject joData = JObject.Parse(rtbCheckDetailLog.Text);
  933. InvokeHelper invoker = new InvokeHelper();
  934. JObject joRtn = invoker.invokeCenterService(TradeEnum.FeeSummaryCheck, joData);
  935. }
  936. private void btClose_Click(object sender, EventArgs e)
  937. {
  938. Close();
  939. }
  940. #endregion
  941. }
  942. }