/// <summary> /// Stat /// </summary> void Stat() { Init(); string beginDate = this.dteRq1.Value.ToString("yyyy-MM-dd"); string endDate = this.dteRq2.Value.ToString("yyyy-MM-dd"); string effectDate = this.dteEffect.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; } beginDate += " 00:00:00"; endDate += " 23:59:59"; effectDate += " 00:00:00"; try { clsPublic.PlayAvi("请稍候..."); dwRep.Modify("t_date.text = '统计时间: " + beginDate + " - " + endDate + "'"); #region 构造表 DataTable dtPrice = new DataTable(); dtPrice.Columns.Add("feeClass", typeof(string)); dtPrice.Columns.Add("feeNum", typeof(decimal)); dtPrice.Columns.Add("feeSum", typeof(decimal)); dtPrice.Columns.Add("deptName", typeof(string)); dtPrice.Columns.Add("deptNum", typeof(decimal)); dtPrice.Columns.Add("deptSum", typeof(decimal)); #endregion DataTable dtItem = new DataTable(); DataTable dtCharge = new DataTable(); clsHISReportZy_Supported_Svc svc = (clsHISReportZy_Supported_Svc)com.digitalwave.iCare.common.clsObjectGenerator.objCreatorObjectByType(typeof(clsHISReportZy_Supported_Svc)); svc.GetAdjustPrice(beginDate, endDate, effectDate, out dtItem, out dtCharge); if (dtItem != null && dtItem.Rows.Count > 0 && dtCharge != null && dtCharge.Rows.Count > 0) { #region compute string childClassName = "儿童项目上调30%"; string mateClassName = "取消300元以下耗材加成"; string calcClassName = string.Empty; string itemId = string.Empty; string ischildprice = string.Empty; string deptName = string.Empty; string catId = string.Empty; string medTypeId = string.Empty; decimal prePrice = 0; decimal curPrice = 0; decimal qty = 0; decimal total = 0; string birthday = string.Empty; string recordDate = string.Empty; DataView dv = new DataView(dtCharge); object[] objs = new object[4]; DataRow[] drr = null; DataRow drPrice = null; foreach (DataRow dr in dtItem.Rows) { itemId = dr["itemid"].ToString(); ischildprice = dr["ischildprice"].ToString(); //beginDate = dr["begindate"].ToString(); //endDate = dr["enddate"].ToString(); prePrice = clsPublic.ConvertObjToDecimal(dr["preprice"].ToString()); curPrice = clsPublic.ConvertObjToDecimal(dr["curprice"].ToString()); objs[0] = itemId; objs[1] = curPrice; objs[2] = beginDate; objs[3] = endDate; dv.RowFilter = string.Format("itemid = '{0}' and (recdate >= '{2}' and recdate <= '{3}')", objs); if (dv.Count > 0) { foreach (DataRowView drv in dv) { catId = drv["catid"].ToString(); medTypeId = drv["medtypeid"].ToString(); deptName = drv["deptname"].ToString().Trim(); calcClassName = drv["calctypename"].ToString(); qty = clsPublic.ConvertObjToDecimal(drv["qty"]); total = clsPublic.Round((curPrice - prePrice) * qty, 2); recordDate = drv["recdate"].ToString(); birthday = Convert.ToDateTime(drv["birth_dat"].ToString()).ToString("yyyy-MM-dd"); bool isChild = IsChild(Convert.ToDateTime(Convert.ToDateTime(birthday).ToString("yyyy-MM-dd"))); // 儿童价格 if (dr["ischildprice"].ToString() == "1" && isChild && Convert.ToDateTime(recordDate) >= Convert.ToDateTime("2019-03-01 00:00:00")) { drr = dtPrice.Select(string.Format("feeClass = '{0}' and deptName = '{1}'", childClassName, deptName)); prePrice = clsPublic.ConvertObjToDecimal(drv["price"].ToString()) / clsPublic.ConvertObjToDecimal(1.3); curPrice = clsPublic.ConvertObjToDecimal(drv["price"].ToString()); total = clsPublic.Round((curPrice - prePrice) * qty, 2); if (drr != null && drr.Length > 0) { drr[0]["deptNum"] = clsPublic.ConvertObjToDecimal(drr[0]["deptNum"]) + qty; drr[0]["deptSum"] = clsPublic.ConvertObjToDecimal(drr[0]["deptSum"]) + total; } else { drPrice = dtPrice.NewRow(); drPrice["feeClass"] = childClassName; drPrice["deptName"] = deptName; drPrice["deptNum"] = qty; drPrice["deptSum"] = Convert.ToDouble(total); dtPrice.LoadDataRow(drPrice.ItemArray, true); } } else { //if ((catId == "2" || catId == "4" || catId == "8") && curPrice < 300) // 300元以下耗材 if (medTypeId == "8" && curPrice < 300) // 300元以下耗材 { total = clsPublic.Round((curPrice / 1.1m) * 0.1m * qty, 2); // 加成 10% drr = dtPrice.Select(string.Format("feeClass = '{0}' and deptName = '{1}'", mateClassName, deptName)); if (drr != null && drr.Length > 0) { drr[0]["deptNum"] = clsPublic.ConvertObjToDecimal(drr[0]["deptNum"]) + qty; drr[0]["deptSum"] = clsPublic.ConvertObjToDecimal(drr[0]["deptSum"]) + total; } else { drPrice = dtPrice.NewRow(); drPrice["feeClass"] = mateClassName; drPrice["deptName"] = deptName; drPrice["deptNum"] = qty; drPrice["deptSum"] = total; dtPrice.LoadDataRow(drPrice.ItemArray, true); } } else { drr = dtPrice.Select(string.Format("feeClass = '{0}' and deptName = '{1}'", calcClassName, deptName)); if (drr != null && drr.Length > 0) { drr[0]["deptNum"] = clsPublic.ConvertObjToDecimal(drr[0]["deptNum"]) + qty; drr[0]["deptSum"] = clsPublic.ConvertObjToDecimal(drr[0]["deptSum"]) + total; } else { drPrice = dtPrice.NewRow(); drPrice["feeClass"] = calcClassName; drPrice["deptName"] = deptName; drPrice["deptNum"] = qty; drPrice["deptSum"] = total; dtPrice.LoadDataRow(drPrice.ItemArray, true); } } } } } } #endregion #region sum if (dtPrice != null && dtPrice.Rows.Count > 0) { Dictionary <string, decimal> dicFeeNum = new Dictionary <string, decimal>(); Dictionary <string, decimal> dicFeeSum = new Dictionary <string, decimal>(); foreach (DataRow dr in dtPrice.Rows) { calcClassName = dr["feeClass"].ToString(); if (dicFeeNum.ContainsKey(calcClassName)) { dicFeeNum[calcClassName] += clsPublic.ConvertObjToDecimal(dr["deptNum"]); dicFeeSum[calcClassName] += clsPublic.ConvertObjToDecimal(dr["deptSum"]); } else { dicFeeNum.Add(calcClassName, clsPublic.ConvertObjToDecimal(dr["deptNum"])); dicFeeSum.Add(calcClassName, clsPublic.ConvertObjToDecimal(dr["deptSum"])); } } foreach (DataRow dr in dtPrice.Rows) { calcClassName = dr["feeClass"].ToString(); dr["feeNum"] = dicFeeNum[calcClassName]; dr["feeSum"] = dicFeeSum[calcClassName]; } } #endregion } if (dtPrice != null && dtPrice.Rows.Count > 0) { svc.SaveAdjustPrice(dtPrice); } svc = null; dwRep.SetSqlSelect(@"select feeClass, feeNum, feeSum, deptName, deptSum from t_rpt_adjustprice"); //dwRep.SetRedrawOff(); dwRep.Retrieve(); // dwRep.SetRedrawOn(); } catch (Exception ex) { com.digitalwave.Utility.clsLogText objLogger = new clsLogText(); objLogger.LogError(ex); } finally { clsPublic.CloseAvi(); } }