1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066 |
- 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.Clearings
- {
- public partial class MainForm : Form
- {
- private string txtPath;
- private string txtName;
- private string finalAchPath;
- private string fileDir;
- private UIDataGridViewFooter dgvHisSettlRecFooter = new Sunny.UI.UIDataGridViewFooter();
- JObject jo9102Rtn = new JObject();
- #region 初始化
- public MainForm()
- {
- InitializeComponent();
- //初始化界面
- InitForm();
- //添加转院备案
- AddForm(this.tpOutOfAreaClearing, new OutOfAreaClearing(this));
- }
- private void InitForm()
- {
- this.StartPosition = FormStartPosition.CenterParent;
- ComboxSetter cbxSetter = new ComboxSetter();
- cbxSetter.setCbxInterfaceDataSource(cbxInterface);
- 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 = 1;
- cbReservelFlag.SelectedIndex = 2;
- cbConfirmFlag.SelectedIndex = 1;
- dpST.Text = DateTime.Now.ToString("yyyy-MM-01");
- dpED.Value = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1);
- WindowState = FormWindowState.Maximized;
- fileDir = Global.currentDirectory + "\\Download";
- this.WindowState = FormWindowState.Maximized;
- this.uiTabControl1.SelectedIndex = 1;
- }
- private void AddForm(TabPage tabpage, Form frm)
- {
- tabpage.Controls.Add(frm);
- frm.Show();
- }
- #endregion
- #region 非按钮事件
- #region 查询HIS
- private int queryHisSettlementInfo(out string error)
- {
- GridViewSetter grdSetter = new GridViewSetter();
- grdSetter.SetHeaderTextOfHisSettlRec(dgvHisSettlRec);
- error = "";
- try
- {
- DataTable dtInteface = (DataTable)cbxInterface.DataSource;
- int i = cbxInterface.SelectedIndex;
- string sqlStr = "";
- 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 * " + getWhereCondition();
- 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;
- if (dt.Rows.Count == 0)
- {
- error = "未查询到数据";
- return -1;
- }
- //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 string getWhereCondition()
- {
- string sqlStr = "";
- sqlStr = sqlStr + " FROM BS_MedInsuSettlement WHERE Hospital_Dr=" + Global.inf.hospitalDr;
- sqlStr = sqlStr + " and OccurTime>'" + dpST.Text + " 00:00:00'";
- sqlStr = sqlStr + " and OccurTime<'" + dpED.Text + " 23:59:59'";
- sqlStr = sqlStr + " and (left(InsuranceAreaCode,2)='44')";
- DataTable dtInteface = (DataTable)cbxInterface.DataSource;
- int i = cbxInterface.SelectedIndex;
- if (cbxInterface.Text != "")
- {
- sqlStr = sqlStr + " and Interface_Dr =" + dtInteface.Rows[i]["ID"].ToString();
- }
- 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";
- }
- //确认标志
- if (cbConfirmFlag.SelectedIndex != 0)
- {
- if (cbConfirmFlag.SelectedIndex == 1)
- sqlStr = sqlStr + " and ((ConfirmFlag = 1 and AdmType = 3) or (AdmType in ('1','2'))) ";
- else
- sqlStr = sqlStr + " and ConfirmFlag <> 1";
- }
- // ReversalFlag = 1 表示数据已冲正,ReversalFlag =0 表示 正常未冲正数据
- if (cbReservelFlag.SelectedIndex != 0)
- {
- if (cbReservelFlag.SelectedIndex == 1)
- sqlStr = sqlStr + " and ReversalFlag =1 ";
- else
- sqlStr = sqlStr + " and ReversalFlag <> 1 ";
- }
- return sqlStr;
- }
- #endregion
- #region 对明细账
- 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 int exportAndCompress(out string zipPath)
- {
- zipPath = "";
- try
- {
- //导出TXT
- string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
- string filePath = Global.currentDirectory + "\\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(TradeEnum.FileUpload, joFsUploadIn);
- if (JsonHelper.parseCenterReturnJson(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.Replace(@"\\", @"\");
- 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(TradeEnum.FeeDetailCheck, joData);
- if (JsonHelper.parseCenterReturnJson(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.Replace(@"\\", @"\"));
- 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;
- //上传给中心,
- if (uploadFileToCenter(zipPath, out outParam) != 0)
- {
- return -1;
- }
- 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;
- }
- }
- #endregion
- #region 对账
- /// <summary>
- /// 单条对总账【本地】
- /// </summary>
- /// <param name="error"></param>
- /// <returns></returns>
- private int Check_Single(out string error)
- {
- error = ""; string setlOptins = "";
- 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(); //清算类别
- //if (tbSettlOption.Text != "")
- //{
- // joCheck.setl_optins = tbSettlOption.Text; //dt.Rows[i]["setl_optins"].ToString(); //结算经办机构
- // setlOptins = tbSettlOption.Text;
- //}
- //else
- //{
- joCheck.setl_optins = dt.Rows[i]["setl_optins"].ToString(); //结算经办机构
- setlOptins = 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 00:00:00"); //对账开始日期
- joCheck.stmt_enddate = dpED.Value.ToString("yyyy-MM-dd 23:59:59"); //对账结束日期
- JObject joData = new JObject();
- joData.Add("data", joCheck);
- //上传给中心
- //先签到
- CenterBusiness cBus = new CenterBusiness();
- JObject jo9001Rtn = new JObject();
- cBus.signIn(out jo9001Rtn);
- Global.pat.insuplc_admdvs = setlOptins;
- InvokeHelper invoker = new InvokeHelper();
- JObject joRtn = invoker.invokeCenterService(TradeEnum.FeeSummaryCheck, joData);
- if (JsonHelper.parseCenterReturnJson(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;
- }
- }
- }
- #endregion
- #region 智能比对
- 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;
- }
- }
- #endregion
- #endregion
- #region 按钮事件
- private void Btn_Query_Click(object sender, EventArgs e)
- {
- DataTable dtInteface = (DataTable)cbxInterface.DataSource;
- int i = cbxInterface.SelectedIndex;
- //乘以单据类型后,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+AccountMutualAidAmount)) AS acct_pay,SUM(BillType*FundPaySumamt) AS fund_pay_sumamt ";
- //sqlStr = sqlStr + " Interface_dr,clearingWay AS clr_way,clearingType AS clr_type ";
- // 增加先行自付金额、医疗救助基金、公务员医疗补助、个人账户共济支付、企业补充、职工大额
- sqlStr += ",Sum(BillType*PreSelfPayAmount) as PreSelfPayAmount,sum(BillType*MedicalAssistPay) as MedicalAssistPay,sum(BillType*CivilserviceAllowancePay) as CivilserviceAllowancePay,"
- + "sum(BillType*AccountMutualAidAmount) as AccountMutualAidAmount ,sum(BillType*LargeExpensesSupplementPay) as LargeExpensesSupplementPay,"
- + "sum(BillType*EnterpriseSupplementPay) as EnterpriseSupplementPay ";
- 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 + getWhereCondition();
- conditionStr = conditionStr.Remove(conditionStr.Length - 1, 1);
- sqlStr = sqlStr + conditionStr;
- JObject joSqlstr = new JObject();
- //MessageBox.Show(sqlStr);
- 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 btBatchCheck_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("部分对账失败,请查看对账结果!");
- }
- }
- private void tsmCheck_Single_Click(object sender, EventArgs e)
- {
- string error = "";
- if (Check_Single(out error) != 0)
- {
- MessageBox.Show("对总账失败:" + error);
- }
- else
- {
- if (dgvHisSettlRec.SelectedIndex != -1)
- {
- dgvHisSettlRec.Rows[dgvHisSettlRec.SelectedIndex].DefaultCellStyle.BackColor = Color.White;
- }
- MessageBox.Show("对总账成功");
- }
- }
- 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);
- }
- }
- private void tsmCheck_Batch_Click(object sender, EventArgs e)
- {
- btBatchCheck_Click(sender, e);
- }
- private void tsmCheckDetail_Batch_Click(object sender, EventArgs e)
- {
- }
- private void tsmHisRecord_Click(object sender, EventArgs e)
- {
- string error;
- if (queryHisSettlementInfo(out error) != 0)
- {
- MessageBox.Show(error);
- }
- }
- 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 tsmExport_Click(object sender, EventArgs e)
- {
- txtName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
- txtPath = Global.currentDirectory + "\\Download";
- if (HISDetailDataExport(txtPath, txtName) != 0)
- {
- MessageBox.Show("导出TXT失败!");
- }
- else
- {
- MessageBox.Show("导出TXT成功!");
- }
- }
- private void tsmCompress_Click(object sender, EventArgs e)
- {
- string finalDirPath = txtPath + "\\" + txtName;
- finalAchPath = finalDirPath + ".zip";
- System.IO.Compression.ZipFile.CreateFromDirectory(finalDirPath, finalAchPath);
- MessageBox.Show("将TXT压缩为ZIP成功!");
- }
- private void tsmZIPToSDec_Click(object sender, EventArgs e)
- {
- byte[] bArray = ReadFileToByte(finalAchPath);
- string str = byteArrayToDecString(bArray);
- Global.writeLog(str);
- MessageBox.Show("ZIP转为有符号整数成功!");
- }
- private void tsmUploadZIP_Click(object sender, EventArgs e)
- {
- string outParam = "";
- byte[] bArray = ReadFileToByte(finalAchPath);
- string str = "[" + byteArrayToDecString(bArray) + "]";
- JObject joTmp = new JObject();
- joTmp.Add("in", JArray.Parse(str));
- joTmp.Add("filename", txtName + ".zip");
- Global.inf.fileName = txtName + ".zip";
- //joTmp.Add("filename", finalAchPath.Replace("\\",@"\"));
- joTmp.Add("fixmedins_code", Global.inf.hospitalNO);
- JObject joFsUploadIn = new JObject();
- joFsUploadIn.Add("fsUploadIn", joTmp);
- InvokeHelper invoker = new InvokeHelper();
- JObject jo9101Rtn = invoker.invokeCenterService(TradeEnum.FileUpload, joFsUploadIn);
- if (JsonHelper.parseCenterRtnValue(jo9101Rtn, out outParam) != 0)
- {
- outParam = JsonHelper.setExceptionJson(-1, "【9101】文件上传失败", outParam).ToString();
- return;
- }
- else
- {
- MessageBox.Show("【9101】文件上传成功");
- }
- }
- private void tsm3202_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(Global.inf.areaCode))
- {
- MessageBox.Show("请先签到!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- string outParam = "";
- DataTable dt = (DataTable)dgvSettlSummary.DataSource;
- int i = dgvSettlSummary.CurrentRow.Index;
- dynamic joCheck = new JObject();
- joCheck.file_qury_no = JObject.Parse(fileDir);
- 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(TradeEnum.FeeDetailCheck, joData);
- if (JsonHelper.parseCenterRtnValue(jo3202Rtn, out outParam) != 0)
- {
- outParam = JsonHelper.setExceptionJson(-1, "【3202】医保明细对账失败", outParam).ToString();
- MessageBox.Show(outParam);
- return;
- }
- else
- {
- MessageBox.Show("【3202】医保明细对账成功");
- }
- }
- private void tsmDownload_Click(object sender, EventArgs e)
- {
- string outParam = "";
- JObject joTmp = new JObject();
- joTmp.Add("file_qury_no", JObject.Parse(fileDir.Replace(@"\\", @"\")));
- 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(TradeEnum.FileDownload, joFsDownloadIn);
- if (JsonHelper.parseCenterRtnValue(jo9102Rtn, out outParam) != 0)
- {
- outParam = JsonHelper.setExceptionJson(-1, "【9102】文件下载失败", outParam).ToString();
- MessageBox.Show(outParam);
- return;
- }
- else
- {
- MessageBox.Show("【9102】文件下载成功");
- }
- }
- 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 = fileDir;//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 void tsmHandCheck_Click(object sender, EventArgs e)
- {
- JObject joData = JObject.Parse(rtbCheckDetailLog.Text);
- InvokeHelper invoker = new InvokeHelper();
- JObject joRtn = invoker.invokeCenterService(TradeEnum.FeeSummaryCheck, joData);
- }
- private void btClose_Click(object sender, EventArgs e)
- {
- Close();
- }
- #endregion
- }
- }
|