| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using PTMedicalInsurance.Common;
- using PTMedicalInsurance.Helper;
- using Newtonsoft.Json.Linq;
- using PTMedicalInsurance.FormSetter;
- using System.IO;
- using System.IO.Compression;
- using PTMedicalInsurance.Business;
- using Sunny.UI;
- using Newtonsoft.Json;
- using System.Collections;
- using PTMedicalInsurance.Variables;
- namespace PTMedicalInsurance.Forms
- {
- public partial class Clearing : Form
- {
- private string txtPath;
- private string txtName;
- private string finalAchPath;
- private UIDataGridViewFooter dgvHisSettlRecFooter = new Sunny.UI.UIDataGridViewFooter();
- JObject jo9102Rtn = new JObject();
- public Clearing()
- {
- InitializeComponent();
- }
- private void Clearing_Load(object sender, EventArgs e)
- {
- ComboxSetter cbxSetter = new ComboxSetter();
- cbxSetter.setCbxDictionaryDataSource(Global.inf.interfaceDr.ToString(), "insutype", cbxInsuType);
- cbxSetter.setCbxDictionaryDataSource(Global.inf.interfaceDr.ToString(), "clr_type", cbxClrType);
- GridViewSetter grdSetter = new GridViewSetter();
- grdSetter.SetHeaderTextOfCheck(dgvSettlSummary);
- cbgGroupSet.SelectAll();
- cbgGroupSet.SetItemCheckState(4, false);
- cbxValid.SelectedIndex = 0;
- cbIsHaveAccountPay.Checked = true;
- dpST.Text = DateTime.Now.ToString("yyyy-MM-01 00:00:00");
- dpED.Text = DateTime.Now.ToString("yyyy-MM-01 23:59:59");
- //dpED.Value = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1);
- WindowState = FormWindowState.Maximized;
- //tbTmp.Text= Global.curEvt.path + "\\Download";
- }
- /// <summary>
- /// 单条对总账事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsmCheck_Single_Click(object sender, EventArgs e)
- {
- string error = "";
- if (Check_Single(out error) != 0)
- {
- MessageBox.Show("对总账失败:" + error);
- }
- else
- {
- MessageBox.Show("对总账成功");
- }
- }
- /// <summary>
- /// 单条对总账【本地】
- /// </summary>
- /// <param name="error"></param>
- /// <returns></returns>
- private int Check_Single(out string error)
- {
- error = "";
- DataTable dt = (DataTable)dgvSettlSummary.DataSource;
- int i = dgvSettlSummary.CurrentRow.Index;
- dynamic joCheck = new JObject();
- joCheck.insutype = dt.Rows[i]["insutype"].ToString(); //险种类型
- joCheck.clr_type = dt.Rows[i]["clr_type"].ToString(); //清算类别
- joCheck.setl_optins = dt.Rows[i]["setl_optins"].ToString(); //结算经办机构
- joCheck.medfee_sumamt = dt.Rows[i]["medfee_sumamt"].ToString(); //医疗费总额
- joCheck.fund_pay_sumamt = dt.Rows[i]["fund_pay_sumamt"].ToString(); //基金支付总额
- joCheck.acct_pay = dt.Rows[i]["acct_pay"].ToString(); //个人账户支付金额
- joCheck.fixmedins_setl_cnt = dt.Rows[i]["fixmedins_setl_cnt"].ToString(); //定点医药机构结算笔数
- joCheck.stmt_begndate = dpST.Value.ToString("yyyy-MM-dd HH:mm:ss"); //对账开始日期
- joCheck.stmt_enddate = dpED.Value.ToString("yyyy-MM-dd HH:mm:ss"); //对账结束日期
- JObject joData = new JObject();
- joData.Add("data", joCheck);
- //上传给中心
- //先签到
- CenterBusiness cBus = new CenterBusiness();
- JObject jo9001Rtn = new JObject();
- cBus.signIn(out jo9001Rtn);
- InvokeHelper invoker = new InvokeHelper();
- JObject joRtn = invoker.invokeCenterService("3201", JsonHelper.setCenterInpar("3201",joData));
- if (JsonHelper.parseCenterRtnValue(joRtn, out error) != 0)
- {
- return -1;
- }
- else
- {
- if (JsonHelper.getDestValue(joRtn, "output.stmtinfo.stmt_rslt") != "0")
- {
- error = JsonHelper.getDestValue(joRtn, "output.stmtinfo.stmt_rslt_dscr");
- return -1;
- }
- else
- {
- return 0;
- }
- }
- }
-
- private int queryHisSettlementInfo(out string error)
- {
- GridViewSetter grdSetter = new GridViewSetter();
- grdSetter.SetHeaderTextOfHisSettlRec(dgvHisSettlRec);
- error = "";
- try
- {
-
- string sqlStr = "SELECT SUM(BillType*Sumamt) AS medfee_sumamt,count(*) AS fixmedins_setl_cnt, ";
- sqlStr = sqlStr + " SUM(BillType*AccountPaySumamt) AS acct_pay,SUM(BillType*HealthInsurancePay) AS fund_pay_sumamt ";
- //sqlStr = sqlStr + " Interface_dr,clearingWay AS clr_way,clearingType AS clr_type ";
- string conditionStr = " ";
- DataTable dtSettlSummary = (DataTable)dgvSettlSummary.DataSource;
- int iCurRow = dgvSettlSummary.CurrentRow.Index;
- //DataTable dtInteface = (DataTable)cbxInterface.DataSource;
- if (cbgGroupSet.GetItemCheckState(0))
- {
- conditionStr = conditionStr + " and Interface_Dr ='" + dtSettlSummary.Rows[iCurRow]["Interface_dr"].ToString() + "'";
- }
- if (cbgGroupSet.GetItemCheckState(1))
- {
- conditionStr = conditionStr + " and InsuranceType ='" + dtSettlSummary.Rows[iCurRow]["insutype"].ToString() + "'";
- }
- if (cbgGroupSet.GetItemCheckState(2))
- {
- conditionStr = conditionStr + " and ClearingType ='" + dtSettlSummary.Rows[iCurRow]["clr_type"].ToString() + "'";
- }
- if (cbgGroupSet.GetItemCheckState(3))
- {
- conditionStr = conditionStr + " and ClearingOrgan ='" + dtSettlSummary.Rows[iCurRow]["setl_optins"].ToString() + "'";
- }
- if (cbgGroupSet.GetItemCheckState(4))
- {
- sqlStr = sqlStr + ",BillType";
- conditionStr = conditionStr + " and BillType ='" + dtSettlSummary.Rows[iCurRow]["BillType"].ToString() + "'";
- }
- sqlStr = "select * FROM MedInsu_Tables.Settlement WHERE Hosp_Dr=" + Global.inf.hospitalDr;
- sqlStr = sqlStr + " and OccurTime>'" + dpST.Text + "'";
- sqlStr = sqlStr + " and OccurTime<'" + dpED.Text + "'";
- //ValidFlag=1 and BillType=1 表示正常结算记录 ValidFlag=0 and BillType=-1 表示退费记录 ValidFlag=0表示无效记录
- if (cbxValid.SelectedIndex != 0)
- {
- if (cbxValid.SelectedIndex == 1)
- sqlStr = sqlStr + " and ValidFlag =1 and BillType=1";
- else
- sqlStr = sqlStr + " and ValidFlag =0 and BillType=-1";
- }
- if (cbIsHaveAccountPay.Checked)
- {
- sqlStr = sqlStr + " and AccountPaySumamt>0 AND PersonPaySumamt = Sumamt";
- }
- ////省医保和市医保对账一样,异地对账需要用到另外的对账交易
- //if (Global.inf.interfaceDr == 1)
- //{
- // sqlStr = sqlStr + " and (InsuranceAreaCode='539900' or InsuranceAreaCode='530100')";
- //}
- //conditionStr = conditionStr.Substring(0,conditionStr.Length -1 );
- //conditionStr = conditionStr.Remove(conditionStr.Length - 1, 1);
- sqlStr = sqlStr + conditionStr;
- JObject joSqlstr = new JObject();
- joSqlstr.Add("sqlStr", sqlStr);
- JArray jaParam = new JArray();
- jaParam.Add(joSqlstr);
- JObject joSettlQuery = new JObject();
- joSettlQuery.Add("params", jaParam);
- joSettlQuery.Add("code", "09010059");
- InvokeHelper invoker = new InvokeHelper();
- JObject joRtn = invoker.invokeInsuService(joSettlQuery.ToString(), "查询结算信息");
- //DataTable dt = (DataTable)joRtn["result"]["data"].ToObject(typeof(DataTable));
- JArray ja = JArray.Parse(JsonHelper.getDestValue(joRtn, "result.data"));
- DataTable dt = (DataTable)JsonConvert.DeserializeObject(JsonHelper.getDestValue(joRtn, "result.data"), (typeof(DataTable)));
- dgvHisSettlRec.DataSource = dt;
- //dt.Columns[7].DataType = typeof(float);//不允许
- //dgvHisSettlRecFooter.DataGridView = dgvHisSettlRec;
- //dgvHisSettlRecFooter.Dock = System.Windows.Forms.DockStyle.Bottom;
- //dgvHisSettlRecFooter.Clear();
- //dgvHisSettlRecFooter["AdmID"] = "合计";
- //dgvHisSettlRecFooter["OverLimitAmount"] = "测试";
- return 0;
- }
- catch (Exception ex)
- {
- error = "queryHisSettlementInfo:" + ex.Message;
- return -1;
- }
- }
- private void tsmCheckDetail_Single_Click(object sender, EventArgs e)
- {
- //HIS明细
- string error;
- if (queryHisSettlementInfo(out error) != 0)
- {
- MessageBox.Show(error);
- }
- //中心明细
- if (CheckDetail_Single(out error) != 0)
- {
- MessageBox.Show(error);
- }
- }
- /// <summary>
- /// 查询HIS结算明细记录
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsmHisRecord_Click(object sender, EventArgs e)
- {
- string error;
- if (queryHisSettlementInfo(out error) != 0)
- {
- MessageBox.Show(error);
- }
- }
- public static void writeToTxt(string content, string filePath, string fileName)
- {
- //创建文件夹,文件夹名称与TXT同名
- string finalPath = filePath + "\\" + fileName;
- if (!Directory.Exists(finalPath))
- {
- DirectoryInfo dirInfo = Directory.CreateDirectory(finalPath);
- }
- //判断文件夹中是否存在txt
- string finalFileName = finalPath + "\\" + fileName + ".txt";
- if (!File.Exists(finalFileName))
- {
- FileStream fs1 = File.Create(finalFileName);
- fs1.Close();
- }
- FileStream fs = new FileStream(finalFileName, FileMode.Append, FileAccess.Write);
- StreamWriter sw = new StreamWriter(fs);
- sw.WriteLine(content);
- sw.Close();
- fs.Close();
- }
- /// <summary>
- /// 读文件到byte[]
- /// </summary>
- /// <param name="fileName">硬盘文件路径</param>
- /// <returns></returns>
- public static byte[] ReadFileToByte(string fileName)
- {
- FileStream pFileStream = null;
- byte[] pReadByte = new byte[0];
- try
- {
- pFileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
- BinaryReader r = new BinaryReader(pFileStream);
- r.BaseStream.Seek(0, SeekOrigin.Begin); //将文件指针设置到文件开
- pReadByte = r.ReadBytes((int)r.BaseStream.Length);
- return pReadByte;
- }
- catch
- {
- return pReadByte;
- }
- finally
- {
- if (pFileStream != null)
- pFileStream.Close();
- }
- }
- /// <summary>
- ///单字节转有符号整数
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public string byteArrayToDecString(byte[] data)
- {
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < data.Length; i++)
- {
- builder.Append((sbyte)data[i] + ",");
- }
- return builder.ToString().Trim();
- }
- private int HISDetailDataExport(string filePath, string fileName)
- {
- try
- {
- DataTable dt = (DataTable)dgvHisSettlRec.DataSource;
- string content = "";
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- string flag = "";
- if (dt.Rows[i]["ValidFlag"].ToString() == "-1")
- {
- flag = "1";
- }
- else
- {
- flag = "0";
- }
- content = "\r\n"
- + dt.Rows[i]["SettlementID"].ToString() + "\t"
- + dt.Rows[i]["MdtrtID"].ToString() + "\t"
- + dt.Rows[i]["PersonnelNO"].ToString() + "\t"
- + dt.Rows[i]["Sumamt"].ToString() + "\t"
- + dt.Rows[i]["FundPaySumamt"].ToString() + "\t"
- + dt.Rows[i]["AccountPaySumamt"].ToString() + "\t"
- + flag
- + content;
- }
- string finalContent = content.Remove(0, 2);
- writeToTxt(finalContent, filePath, fileName);
- return 0;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- return -1;
- }
- }
- private void tsmExport_Click(object sender, EventArgs e)
- {
- txtName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
- txtPath = Global.curEvt.path + "\\Download";
- HISDetailDataExport(txtPath, txtName);
- //System.IO.Compression.ZipFile.CreateFromDirectory(txtPath + "\\" + "2022ceshi", txtPath + "\\" + "111.zip");
- }
- private void tsmCompress_Click(object sender, EventArgs e)
- {
- string path = @"C:\ProgramData\prykNT\prBrowser\bin\service\plugins\INSUNew\DownLoad\111";
- string name = @"1121.zip";
- string finalDirPath = txtPath + "\\" + txtName;
- finalAchPath = finalDirPath + ".zip";
- System.IO.Compression.ZipFile.CreateFromDirectory(finalDirPath, finalAchPath);
- //System.IO.Compression.ZipFile.CreateFromDirectory(path, name);
- //System.IO.Compression.ZipFile.CreateFromDirectory(path, name, 0, true);
- }
- private void tsmZIPToSDec_Click(object sender, EventArgs e)
- {
- byte[] bArray = ReadFileToByte(finalAchPath);
- string str = byteArrayToDecString(bArray);
- Global.writeLog(str);
- }
- private void tsmUploadZIP_Click(object sender, EventArgs e)
- {
- byte[] bArray = ReadFileToByte(finalAchPath);
- string str = "[" + byteArrayToDecString(bArray) + "]";
- JObject joTmp = new JObject();
- joTmp.Add("in", JArray.Parse(str));
- joTmp.Add("filename", txtName + ".zip");
- joTmp.Add("fixmedins_code", Global.inf.hospitalNO);
- JObject joFsUploadIn = new JObject();
- joFsUploadIn.Add("fsUploadIn", joTmp);
- InvokeHelper invoker = new InvokeHelper();
- invoker.invokeCenterService("9101", joFsUploadIn.ToString());
- }
- private void tsm3202_Click(object sender, EventArgs e)
- {
- DataTable dt = (DataTable)dgvSettlSummary.DataSource;
- int i = dgvSettlSummary.CurrentRow.Index;
- dynamic joCheck = new JObject();
- joCheck.file_qury_no = tbTmp.Text;
- joCheck.clr_type = dt.Rows[i]["clr_type"].ToString();
- joCheck.setl_optins = dt.Rows[i]["setl_optins"].ToString();
- joCheck.stmt_begndate = dpST.Value.ToString("yyyy-MM-dd HH:mm:ss");
- joCheck.stmt_enddate = dpED.Value.ToString("yyyy-MM-dd HH:mm:ss");
- joCheck.medfee_sumamt = dt.Rows[i]["medfee_sumamt"].ToString();
- joCheck.fund_pay_sumamt = dt.Rows[i]["fund_pay_sumamt"].ToString();
- joCheck.cash_payamt = dt.Rows[i]["cash_payamt"].ToString();
- joCheck.fixmedins_setl_cnt = dt.Rows[i]["fixmedins_setl_cnt"].ToString();
- JObject joData = new JObject();
- joData.Add("data", joCheck);
- InvokeHelper invoker = new InvokeHelper();
- invoker.invokeCenterService("3202", joData.ToString());
- }
- private void tsmDownload_Click(object sender, EventArgs e)
- {
- JObject joTmp = new JObject();
- joTmp.Add("file_qury_no", tbTmp.Text);
- joTmp.Add("filename", txtName + ".zip");
- joTmp.Add("fixmedins_code", Global.inf.hospitalNO);
- JObject joFsDownloadIn = new JObject();
- joFsDownloadIn.Add("fsDownloadIn", joTmp);
- InvokeHelper invoker = new InvokeHelper();
- jo9102Rtn = invoker.invokeCenterService("9102", JsonHelper.setCenterInpar("9102", joFsDownloadIn).ToString());
- }
- private void tsmUnCompress_Click(object sender, EventArgs e)
- {
- //解压缩
- string zipFilePath = jo9102Rtn["filePath"].ToString();
- string txtFileDir = System.Environment.CurrentDirectory + "\\Download";
- //string txtFilePath = txtFileDir + "\\" + filename.Substring(0, filename.Length - 4);
- string txtFilePath = txtFileDir;
- if (File.Exists(txtFilePath))
- {
- File.Delete(txtFilePath);
- }
- ZipFile.ExtractToDirectory(zipFilePath, txtFileDir);
- }
- private void tsmImport_Click(object sender, EventArgs e)
- {
- GridViewSetter grd = new GridViewSetter();
- grd.SetHeaderTextOfDgvCenterSetlRec(dgvCenterSettlRec);
- string txtFileDir = tbTmp.Text;//E:\GHSF\SCYBDownLoad\result.txt
- string[] lines = System.IO.File.ReadAllLines(txtFileDir);
- Global.writeLog(lines.ToString());
- DataTable dt = new DataTable();
- dt.Columns.Add("sn", typeof(int));
- dt.Columns.Add("psn_no", typeof(string));
- dt.Columns.Add("mdtrt_id", typeof(string));
- dt.Columns.Add("setl_id", typeof(string));
- dt.Columns.Add("msgid", typeof(string));
- dt.Columns.Add("stmt_rslt", typeof(string));
- dt.Columns.Add("refd_setl_flag", typeof(string));
- dt.Columns.Add("memo", typeof(string));
- dt.Columns.Add("medfee_sumamt", typeof(string));
- dt.Columns.Add("fund_pay_sumamt", typeof(string));
- dt.Columns.Add("acct_pay", typeof(string));
- //foreach (string line in lines)
- for (int i = 0; i < lines.Length; i++)
- {
- string[] strs = (lines[i] + "\t").Split('\t');
- DataRow dr = dt.NewRow();
- //Global.inf.writeLog(lines[i].ToString());
- //Global.inf.writeLog(strs.Length.ToString());
- dr["sn"] = i;
- dr["psn_no"] = strs[0];
- dr["mdtrt_id"] = strs[1];
- dr["setl_id"] = strs[2];
- dr["msgid"] = strs[3];
- dr["stmt_rslt"] = strs[4];
- dr["refd_setl_flag"] = strs[5];
- dr["memo"] = strs[6];
- dr["medfee_sumamt"] = strs[7];
- dr["fund_pay_sumamt"] = strs[8];
- dr["acct_pay"] = strs[9];
- //dr["Field2"] = strs[2];
- dt.Rows.Add(dr);
- }
- dgvCenterSettlRec.DataSource = dt;
- }
- private int exportAndCompress(out string zipPath)
- {
- zipPath = "";
- try
- {
- //导出TXT
- string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
- string filePath = Global.curEvt.path + "\\Download";
- HISDetailDataExport(filePath, fileName);
- //压缩
- string finalDirPath = filePath + "\\" + fileName;//同名文件夹
- zipPath = finalDirPath + ".zip";
- System.IO.Compression.ZipFile.CreateFromDirectory(finalDirPath, zipPath);
- return 0;
- }
- catch (Exception ex)
- {
- zipPath = "exportAndCompress:" + ex.Message;
- return -1;
- }
- }
- /// <summary>
- /// 上传ZIP文件转字节流再转换为有符号10进制数组后上传
- /// </summary>
- /// <param name="zipPath"></param>
- /// <param name="file_qury_no"></param>
- /// <returns></returns>
- private int uploadFileToCenter(string zipPath, out string file_qury_no)
- {
- string outParam = "";
- try
- {
- byte[] bArray = ReadFileToByte(zipPath);
- string str = "[" + byteArrayToDecString(bArray) + "]";
- JObject joTmp = new JObject();
- joTmp.Add("in", JArray.Parse(str));
- joTmp.Add("filename", txtName + ".zip");
- joTmp.Add("fixmedins_code", Global.inf.hospitalNO);
- JObject joFsUploadIn = new JObject();
- joFsUploadIn.Add("fsUploadIn", joTmp);
- InvokeHelper invoker = new InvokeHelper();
- JObject jo9101Rtn = invoker.invokeCenterService("9101", JsonHelper.setCenterInpar("9101",joFsUploadIn));
- if (JsonHelper.parseCenterRtnValue(jo9101Rtn, out outParam) != 0)
- {
- file_qury_no = outParam;
- return -1;
- }
- else
- {
- file_qury_no = JsonHelper.getDestValue(jo9101Rtn, "output.file_qury_no");
- return 0;
- }
- }
- catch (Exception ex)
- {
- file_qury_no = "uploadFileToCenter:" + ex.Message;
- return -1;
- }
- }
- private int checkDetail(string file_qury_no, out string outParam, out string fileName)
- {
- fileName = "";
- try
- {
- DataTable dt = (DataTable)dgvSettlSummary.DataSource;
- int i = dgvSettlSummary.CurrentRow.Index;
- dynamic joCheck = new JObject();
- joCheck.file_qury_no = file_qury_no;
- joCheck.clr_type = dt.Rows[i]["clr_type"].ToString();
- joCheck.setl_optins = dt.Rows[i]["setl_optins"].ToString();
- joCheck.stmt_begndate = dpST.Value.ToString("yyyy-MM-dd HH:mm:ss");
- joCheck.stmt_enddate = dpED.Value.ToString("yyyy-MM-dd HH:mm:ss");
- joCheck.medfee_sumamt = dt.Rows[i]["medfee_sumamt"].ToString();
- joCheck.fund_pay_sumamt = dt.Rows[i]["fund_pay_sumamt"].ToString();
- joCheck.cash_payamt = dt.Rows[i]["cash_payamt"].ToString();
- joCheck.fixmedins_setl_cnt = dt.Rows[i]["fixmedins_setl_cnt"].ToString();
- JObject joData = new JObject();
- joData.Add("data", joCheck);
- InvokeHelper invoker = new InvokeHelper();
- JObject jo3202Rtn = invoker.invokeCenterService("3202", JsonHelper.setCenterInpar("3202", joData));
- if (JsonHelper.parseCenterRtnValue(jo3202Rtn, out outParam) != 0)
- {
- return -1;
- }
- else
- {
- outParam = JsonHelper.getDestValue(jo3202Rtn, "output.fileinfo.file_qury_no");
- fileName = JsonHelper.getDestValue(jo3202Rtn, "output.fileinfo.filename");
- return 0;
- }
- }
- catch (Exception ex)
- {
- outParam = "checkDetail:" + ex.Message;
- return -1;
- }
- }
- private int downloadZIP(string file_qury_no, string fileName, out string outParam)
- {
- outParam = "";
- try
- {
- JObject joTmp = new JObject();
- joTmp = new JObject();
- joTmp.Add("file_qury_no", file_qury_no);
- joTmp.Add("filename", fileName);
- joTmp.Add("fixmedins_code", Global.inf.hospitalNO);
- JObject joFsDownloadIn = new JObject();
- joFsDownloadIn.Add("fsDownloadIn", joTmp);
- InvokeHelper invoker = new InvokeHelper();
- JObject jo9102Rtn = invoker.DownloadCenterFile(JsonHelper.setCenterInpar("9102", joFsDownloadIn).ToString());
- string error = "";
- if (JsonHelper.parseIrisRtnValue(jo9102Rtn, out error) != 0)
- {
- outParam = error;
- return -1;
- }
- else
- {
- outParam = JsonHelper.getDestValue(jo9102Rtn, "filePath");
- return 0;
- }
- }
- catch (Exception ex)
- {
- outParam = "downloadZIP:" + ex.Message;
- return -1;
- }
- }
- private int importToDgvCenterSetlRec(string fileName, string zipFilePath, out string outParam)
- {
- outParam = "";
- try
- {
- string dir = fileName.Substring(1, fileName.Length - 4);
- //解压缩
- string txtFileDir = System.Environment.CurrentDirectory + "\\Download\\" + dir;
- string txtFilePath = zipFilePath.Substring(0, zipFilePath.Length - 4);
- if (File.Exists(txtFilePath))
- {
- File.Delete(txtFilePath);
- }
- if (!Directory.Exists(txtFileDir))
- {
- Directory.CreateDirectory(txtFileDir);
- }
- ZipFile.ExtractToDirectory(zipFilePath, txtFileDir);
- //导入文件
- GridViewSetter grd = new GridViewSetter();
- grd.SetHeaderTextOfDgvCenterSetlRec(dgvCenterSettlRec);
- //txtFileDir = txtFileDir;//E:\GHSF\SCYBDownLoad\result.txt
- string[] lines = System.IO.File.ReadAllLines(txtFileDir + "\\result.txt");
- DataTable dt = new DataTable();
- dt.Columns.Add("sn", typeof(int));
- dt.Columns.Add("psn_no", typeof(string));
- dt.Columns.Add("mdtrt_id", typeof(string));
- dt.Columns.Add("setl_id", typeof(string));
- dt.Columns.Add("msgid", typeof(string));
- dt.Columns.Add("stmt_rslt", typeof(string));
- dt.Columns.Add("refd_setl_flag", typeof(string));
- dt.Columns.Add("memo", typeof(string));
- dt.Columns.Add("medfee_sumamt", typeof(string));
- dt.Columns.Add("fund_pay_sumamt", typeof(string));
- dt.Columns.Add("acct_pay", typeof(string));
- //foreach (string line in lines)
- for (int i = 0; i < lines.Length; i++)
- {
- string[] strs = (lines[i] + "\t").Split('\t');
- DataRow dr = dt.NewRow();
- //Global.inf.writeLog(lines[i].ToString());
- //Global.inf.writeLog(strs.Length.ToString());
- dr["sn"] = i + 1;
- dr["psn_no"] = strs[0];
- dr["mdtrt_id"] = strs[1];
- dr["setl_id"] = strs[2];
- dr["msgid"] = strs[3];
- dr["stmt_rslt"] = strs[4];
- dr["refd_setl_flag"] = strs[5];
- dr["memo"] = strs[6];
- dr["medfee_sumamt"] = strs[7];
- dr["fund_pay_sumamt"] = strs[8];
- dr["acct_pay"] = strs[9];
- //dr["Field2"] = strs[2];
- dt.Rows.Add(dr);
- }
- dgvCenterSettlRec.DataSource = dt;
- return 0;
- }
- catch (Exception ex)
- {
- outParam = "importToDgvCenterSetlRec:" + ex.Message;
- return -1;
- }
- }
- private int CheckDetail_Single(out string outParam)
- {
- outParam = "";
- //先签到
- CenterBusiness cBus = new CenterBusiness();
- JObject jo9001Rtn = new JObject();
- cBus.signIn(out jo9001Rtn);
- try
- {
- //导出并压缩
- if (exportAndCompress(out outParam) != 0)
- {
- return -1;
- }
- string zipPath = outParam;
- Global.writeLog("exportAndCompress:" + zipPath);
- //上传给中心,
- if (uploadFileToCenter(zipPath, out outParam) != 0)
- {
- return -1;
- }
- Global.writeLog("uploadFileToCenter:" + outParam);
- string file_query_no = outParam;
- string fileName = "";
- //3202明细对账 输出查询号和文件名
- if (checkDetail(file_query_no, out outParam, out fileName) != 0)
- {
- return -1;
- }
- file_query_no = outParam;
- Global.writeLog("checkDetail:" + outParam + "///" + fileName);
- //下载 获取 查询号和文件名后 下载
- if (downloadZIP(file_query_no, fileName, out outParam) != 0)
- {
- return -1;
- }
- zipPath = outParam;
- Global.writeLog("downloadZIP:" + outParam);
- //导入DGV
- if (importToDgvCenterSetlRec(fileName, zipPath, out outParam) != 0)
- {
- return -1;
- }
- Global.writeLog("importToDgvCenterSetlRec:" + outParam);
- return 0;
- }
- catch (Exception ex)
- {
- outParam = "CheckDetail_Single:" + ex.Message;
- return -1;
- }
- }
- private void dgvRowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
- {
- DataGridView dgv = (DataGridView)sender;
- dgv.RowHeadersWidth = 60;
- if (dgv.Rows.Count > 1)
- e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
- }
- private void dgvSettlSummary_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
- {
- if (dgvSettlSummary.Rows.Count > 1)
- e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
- }
- private void dgvHisSettlRec_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
- {
- if (dgvHisSettlRec.Rows.Count > 1)
- e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
- }
- private int compareDataGridView(string value, string colName, Sunny.UI.UIDataGridView dgv)
- {
- try
- {
- for (int i = 0; i < dgv.RowCount; i++)
- {
- if (dgv.Rows[i].Cells[colName].Value.ToString() == value)
- {
- return 0;
- }
- }
- return -1;
- }
- catch (Exception ex)
- {
- MessageBox.Show("compareDataGridView" + ex.Message);
- return -1;
- }
- }
- private void tsmAICheck_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < dgvHisSettlRec.RowCount; i++)
- {
- string value = dgvHisSettlRec.Rows[i].Cells["SettlementID"].Value.ToString();
- string colName = "setl_id";
- if (compareDataGridView(value, colName, dgvCenterSettlRec) != 0)
- {
- dgvHisSettlRec.Rows[i].DefaultCellStyle.BackColor = Color.Red;
- rtbCheckDetailLog.AppendText("HIS结算ID:" + value + "在中心明细中未找到数据!" + "\r\n");
- }
- }
- for (int i = 0; i < dgvCenterSettlRec.RowCount; i++)
- {
- string value = dgvCenterSettlRec.Rows[i].Cells["setl_id"].Value.ToString();
- string colName = "SettlementID";
- if (compareDataGridView(value, colName, dgvHisSettlRec) != 0)
- {
- dgvCenterSettlRec.Rows[i].DefaultCellStyle.BackColor = Color.Red;
- rtbCheckDetailLog.AppendText("中心结算ID:" + value + "在HIS明细中未找到数据!" + "\r\n");
- }
- }
- }
- private void btnAddOneDay_Click(object sender, EventArgs e)
- {
- dpST.Value = dpST.Value.AddDays(1);
- dpED.Value = dpED.Value.AddDays(1);
- }
- private void btnReduceOndDay_Click(object sender, EventArgs e)
- {
- dpST.Value = dpST.Value.AddDays(-1);
- dpED.Value = dpED.Value.AddDays(-1);
- }
-
- private ArrayList getIndexArray(String inputStr, String findStr)
- {
- ArrayList list = new ArrayList();
- int start = 0;
- while (start < inputStr.Length)
- {
- int index = inputStr.IndexOf(findStr, start);
- if (index >= 0)
- {
- list.Add(index);
- start = index + findStr.Length;
- }
- else
- {
- break;
- }
- }
- return list;
- }
-
- private void tsmHandCheck_Click(object sender, EventArgs e)
- {
- JObject joData = JObject.Parse(rtbCheckDetailLog.Text);
- InvokeHelper invoker = new InvokeHelper();
- JObject joRtn = invoker.invokeCenterService("3201", joData.ToString());
- }
- private void btnClose_Click(object sender, EventArgs e)
- {
- Close();
- }
- private void Btn_Query_Click(object sender, EventArgs e)
- {
- //乘以单据类型后,IRIS会返回整数,关键不知道SQL里咋转换为浮点数
- //string sqlStr = "SELECT SUM(BillType*Sumamt) AS medfee_sumamt,count(*) AS fixmedins_setl_cnt,SUM(BillType*PersonCashPay) AS cash_payamt, ";
- //sqlStr = sqlStr + " SUM(BillType*AccountPaySumamt) AS acct_pay,SUM(BillType*FundPaySumamt) AS fund_pay_sumamt ";
- string sqlStr = "SELECT SUM(BillType*Sumamt) AS medfee_sumamt,count(*) AS fixmedins_setl_cnt,SUM(BillType*PersonCashPay) AS cash_payamt, ";
- sqlStr = sqlStr + " SUM(billType*AccountPaySumamt + BillType*AccountMutualAidAmount) AS acct_pay,SUM(BillType*FundPaySumamt) AS fund_pay_sumamt ";
- //sqlStr = sqlStr + " Interface_dr,clearingWay AS clr_way,clearingType AS clr_type ";
- string conditionStr = " Group By";
- if (cbgGroupSet.GetItemCheckState(0))
- {
- sqlStr = sqlStr + ",Interface_Dr";
- conditionStr = conditionStr + " Interface_Dr,";
- }
- if (cbgGroupSet.GetItemCheckState(1))
- {
- sqlStr = sqlStr + ",InsuranceType as insutype";
- conditionStr = conditionStr + " InsuranceType,";
- }
- if (cbgGroupSet.GetItemCheckState(2))
- {
- sqlStr = sqlStr + ",ClearingType as clr_type";
- conditionStr = conditionStr + " ClearingType,";
- }
- if (cbgGroupSet.GetItemCheckState(3))
- {
- sqlStr = sqlStr + ",ClearingOrgan as setl_optins";
- conditionStr = conditionStr + " ClearingOrgan,";
- }
- if (cbgGroupSet.GetItemCheckState(4))
- {
- sqlStr = sqlStr + ",BillType";
- conditionStr = conditionStr + " BillType,";
- }
- sqlStr = sqlStr + " FROM MedInsu_Tables.Settlement WHERE Hosp_Dr=" + Global.inf.hospitalDr;
- sqlStr = sqlStr + " and OccurTime>'" + dpST.Text + "'";
- sqlStr = sqlStr + " and OccurTime<'" + dpED.Text + "'";
- if(cbIsHaveAccountPay.Checked)
- {
- sqlStr = sqlStr + " and AccountPaySumamt>0 AND PersonPaySumamt = Sumamt";
- }
- if (cbxInsuType.Text != "")
- {
- sqlStr = sqlStr + " and InsuranceType ='" + cbxInsuType.SelectedValue + "'";
- }
- if (cbxClrType.Text != "")
- {
- sqlStr = sqlStr + " and ClearingType ='" + cbxClrType.SelectedValue + "'";
- }
- if (tbSettlOption.Text != "")
- {
- sqlStr = sqlStr + " and ClearingOrgan ='" + tbSettlOption.Text + "'";
- }
- //ValidFlag=1 and BillType=1 表示正常结算记录 ValidFlag=0 and BillType=-1 表示退费记录 ValidFlag=0表示无效记录
- if (cbxValid.SelectedIndex != 0)
- {
- if (cbxValid.SelectedIndex == 1)
- sqlStr = sqlStr + " and ValidFlag =1 and BillType=1";
- else
- sqlStr = sqlStr + " and ValidFlag =0 and BillType=-1";
- }
- //conditionStr = conditionStr.Substring(0,conditionStr.Length -1 );
- conditionStr = conditionStr.Remove(conditionStr.Length - 1, 1);
- sqlStr = sqlStr + conditionStr;
- JObject joSqlstr = new JObject();
- joSqlstr.Add("sqlStr", sqlStr);
- JArray jaParam = new JArray();
- jaParam.Add(joSqlstr);
- JObject joSettlQuery = new JObject();
- joSettlQuery.Add("params", jaParam);
- joSettlQuery.Add("code", "09010061");
- InvokeHelper invoker = new InvokeHelper();
- JObject joRtn = invoker.invokeInsuService(joSettlQuery.ToString(), "查询汇总结算信息");
- DataTable dt = (DataTable)joRtn["result"]["data"].ToObject(typeof(DataTable));
- dgvSettlSummary.DataSource = dt;
- //初始化HIS结算明细View数据
- dgvHisSettlRec.DataSource = null;
- }
-
- private void dgvSettlSummary_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- string error;
- if (queryHisSettlementInfo(out error) != 0)
- {
- MessageBox.Show(error);
- }
- }
- private void btCheckBatch_Click(object sender, EventArgs e)
- {
- string errMsg = "";
- bool success = true;
- for (int i = 0; i < dgvSettlSummary.RowCount; i++)
- {
- dgvSettlSummary.CurrentCell = dgvSettlSummary.Rows[i].Cells[0];
- if (Check_Single(out errMsg) != 0)
- {
- dgvSettlSummary.Rows[i].DefaultCellStyle.BackColor = Color.Red;
- rtbCheckLog.AppendText("第" + (i+1).ToString() + "条对账失败!" + errMsg + "\r\n");
- success = false;
- }
- }
- if (success)
- {
- MessageBox.Show("批量对账全部成功!");
- }
- else
- {
- MessageBox.Show("部分对账失败,请查看对账结果!");
- }
- }
- }
- }
|