Clearing.cs 40 KB

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