/// <summary> /// QueryDeptCharge /// </summary> public void QueryDeptCharge() { Init(); string BeginDate = this.dteRq1.Value.ToString("yyyy-MM-dd"); string EndDate = this.dteRq2.Value.ToString("yyyy-MM-dd"); List <DataTable> dtData = new List <DataTable>(); if (Convert.ToDateTime(BeginDate + " 00:00:01") > Convert.ToDateTime(EndDate + " 00:00:01")) { MessageBox.Show("开始日期不能大于结束日期。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { clsPublic.PlayAvi("请稍候..."); clsHISReportZy_Supported_Svc svc = (clsHISReportZy_Supported_Svc)com.digitalwave.iCare.common.clsObjectGenerator.objCreatorObjectByType(typeof(clsHISReportZy_Supported_Svc)); DataTable dtSum = svc.GetDeptChareg(BeginDate, EndDate, DeptIDArr); DataTable dtICU = svc.GetICUchareg(BeginDate, EndDate); List <DataRow> lstDelRow = new List <DataRow>(); List <string> lstPChargeId1 = new List <string>(); List <string> lstPChargeId2 = new List <string>(); int rowNo = -1; if (dtICU != null && dtICU.Rows.Count > 0) { foreach (DataRow dr3 in dtICU.Rows) { dr3["rowNo"] = ++rowNo; } DataRow[] drrRef = dtICU.Select("refpchargeid_chr <> ''"); foreach (DataRow dr3 in dtICU.Rows) { foreach (DataRow dr4 in drrRef) { if (dr3["pchargeid_chr"].ToString() == dr4["refpchargeid_chr"].ToString()) { dr3["catsum"] = Convert.ToDecimal(dr3["catsum"]) + Convert.ToDecimal(dr4["catsum"]); lstDelRow.Add(dr4); } } } foreach (DataRow dr3 in lstDelRow) { dtICU.Rows.Remove(dr3); } dtICU.AcceptChanges(); lstDelRow.Clear(); string regId = string.Empty; List <string> lstRegId = new List <string>(); foreach (DataRow dr3 in dtICU.Rows) { regId = dr3["registerid_chr"].ToString(); if (lstRegId.IndexOf(regId) < 0) { lstRegId.Add(regId); } } decimal totalsum = 0; string pchargeId = string.Empty; string icuDeptCode = "0201"; DataRow[] drr = null; DataTable dtTrans = null; List <EntityTrans> lstTrans = new List <EntityTrans>(); foreach (string regId2 in lstRegId) { dtTrans = svc.GetPatTransf(regId2); lstTrans.Clear(); EntityTrans vo = null; for (int k = 0; k < dtTrans.Rows.Count; k++) { if (dtTrans.Rows[k]["targetareancode"].ToString() == icuDeptCode) { vo = new EntityTrans(); vo.sourceDeptId = dtTrans.Rows[k]["sourceareacode"].ToString(); vo.sourceDeptName = dtTrans.Rows[k]["sourceareaname"].ToString(); vo.beginDate = Convert.ToDateTime(dtTrans.Rows[k]["modify_dat"]); if (k + 1 < dtTrans.Rows.Count) { vo.endDate = Convert.ToDateTime(dtTrans.Rows[k + 1]["modify_dat"]); } if (string.IsNullOrEmpty(vo.sourceDeptId)) { vo.sourceDeptId = icuDeptCode; vo.sourceDeptName = dtTrans.Rows[k]["targetareaname"].ToString(); } lstTrans.Add(vo); } } foreach (EntityTrans vo2 in lstTrans) { DataRow[] drrIcu = null; if (vo2.endDate == null) { drrIcu = dtICU.Select("registerid_chr = '" + regId2 + "' and chargeactive_dat >= '" + vo2.beginDate.ToString() + "'"); } else { drrIcu = dtICU.Select("registerid_chr = '" + regId2 + "' and chargeactive_dat >= '" + vo2.beginDate.ToString() + "' and chargeactive_dat <= '" + vo2.endDate.Value + "'"); } if (drrIcu != null && drrIcu.Length > 0) { totalsum = 0; foreach (DataRow dr2 in drrIcu) { pchargeId = dr2["pchargeid_chr"].ToString(); if (lstPChargeId1.IndexOf(pchargeId) < 0) { totalsum += Convert.ToDecimal(dr2["catsum"]); lstPChargeId1.Add(pchargeId); lstDelRow.Add(dr2); } } drr = dtSum.Select("shortno_chr = '" + vo2.sourceDeptId + "'"); if (drr != null && drr.Length > 0) { totalsum += Convert.ToDecimal(drr[0]["totalsum"]); foreach (DataRow dr3 in drr) { dr3["totalsum"] = totalsum; } foreach (DataRow dr2 in drrIcu) { pchargeId = dr2["pchargeid_chr"].ToString(); if (lstPChargeId2.IndexOf(pchargeId) < 0) { drr = dtSum.Select("shortno_chr = '" + vo2.sourceDeptId + "' and groupid_chr = '" + dr2["groupid_chr"].ToString() + "'"); if (drr != null && drr.Length > 0) { drr[0]["catsum"] = Convert.ToDecimal(drr[0]["catsum"]) + Convert.ToDecimal(dr2["catsum"]); } else { dtSum.LoadDataRow(new object[6] { vo2.sourceDeptId, vo2.sourceDeptName, totalsum, dr2["groupid_chr"].ToString(), dr2["groupname_chr"].ToString(), Convert.ToDecimal(dr2["catsum"]) }, true); } lstPChargeId1.Add(pchargeId); } } } else { foreach (DataRow dr2 in drrIcu) { pchargeId = dr2["pchargeid_chr"].ToString(); if (lstPChargeId2.IndexOf(pchargeId) < 0) { dtSum.LoadDataRow(new object[6] { vo2.sourceDeptId, vo2.sourceDeptName, totalsum, dr2["groupid_chr"].ToString(), dr2["groupname_chr"].ToString(), Convert.ToDecimal(dr2["catsum"]) }, true); lstPChargeId1.Add(pchargeId); } } } } } } foreach (DataRow dr3 in lstDelRow) { dtICU.Rows.Remove(dr3); } dtICU.AcceptChanges(); if (dtICU.Rows.Count > 0) { totalsum = 0; foreach (DataRow dr2 in dtICU.Rows) { totalsum += Convert.ToDecimal(dr2["catsum"]); } drr = dtSum.Select("shortno_chr = '" + icuDeptCode + "'"); if (drr != null && drr.Length > 0) { totalsum += Convert.ToDecimal(drr[0]["totalsum"]); foreach (DataRow dr3 in drr) { dr3["totalsum"] = totalsum; } foreach (DataRow dr2 in dtICU.Rows) { drr = dtSum.Select("shortno_chr = '" + icuDeptCode + "' and groupid_chr = '" + dr2["groupid_chr"].ToString() + "'"); if (drr != null && drr.Length > 0) { drr[0]["catsum"] = Convert.ToDecimal(drr[0]["catsum"]) + Convert.ToDecimal(dr2["catsum"]); } else { dtSum.LoadDataRow(new object[6] { icuDeptCode, dr2["deptname_vchr"].ToString(), totalsum, dr2["groupid_chr"].ToString(), dr2["groupname_chr"].ToString(), Convert.ToDecimal(dr2["catsum"]) }, true); } } } else { foreach (DataRow dr2 in dtICU.Rows) { dtSum.LoadDataRow(new object[6] { icuDeptCode, dr2["deptname_vchr"].ToString(), totalsum, dr2["groupid_chr"].ToString(), dr2["groupname_chr"].ToString(), Convert.ToDecimal(dr2["catsum"]) }, true); } } } } dtSum.AcceptChanges(); svc.AddCharegToTable(dtSum, Convert.ToDateTime(BeginDate).ToString("yyyyMM")); string sql = @"select shortno_chr, deptname_vchr, totalsum, groupid_chr, groupname_chr, catsum from t_rpt_cross1"; dwRep.SetSqlSelect(sql); //dwRep.SetRedrawOff(); dwRep.Retrieve(); dwRep.Modify("t_date.text = '统计时间: " + BeginDate + " 00:00:00 - " + EndDate + " 23:59:59'"); // dwRep.SetRedrawOn(); } catch (Exception ex) { com.digitalwave.Utility.clsLogText objLogger = new clsLogText(); objLogger.LogError(ex); } finally { clsPublic.CloseAvi(); } }