private void Show() { if ((txtInvName.Text == "" && txtGoodNo.Text == "") || ddlHouse.SelectedValue == "0") { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('查询条件必选全部填写!');</script>"); txtFrom.Focus(); return; } if (txtFrom.Text == "" && txtTo.Text == "") { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('日期至少选一个!');</script>"); txtFrom.Focus(); return; } try { if (txtFrom.Text != "") { if (CommHelp.VerifesToDateTime(txtFrom.Text) == false) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('日期时间 格式错误!');</script>"); return; } Convert.ToDateTime(txtFrom.Text); } if (txtTo.Text != "") { if (CommHelp.VerifesToDateTime(txtTo.Text) == false) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('日期时间 格式错误!');</script>"); return; } Convert.ToDateTime(txtTo.Text); } } catch (Exception) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('日期格式错误!');</script>"); return; } //if (txtGoodNo.Text != "" && txtInvName.Text != "") //{ // base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('查询条件必选全部填写!');</script>"); // txtFrom.Focus(); // return; //} int goodId = 0; if (txtInvName.Text != "") { //string goodName = txtInvName.Text.Replace(@"\", ","); string[] allList = txtInvName.Text.Split('\\'); if (allList.Length != 7) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('商品格式不正确!');</script>"); return; } goodId = goodsSer.GetGoodId(allList[1], allList[3], allList[4], allList[2], allList[5]); if (goodId == 0) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('你填写的商品不存在!');</script>"); return; } } if (txtGoodNo.Text != "") { var allModels = goodsSer.GetListArray(string.Format(" 1=1 and GoodNo='{0}'", txtGoodNo.Text)); if (allModels.Count != 1) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('你填写的商品不存在!');</script>"); return; } goodId = allModels[0].GoodId; } var models = goodsSer.GetListArray(" GoodId=" + goodId); var nums = goodsSer.GetGoodNum(goodId); lblGoodNum.Text = nums[0].ToString(); lblCaiKuNum.Text = nums[1].ToString(); List <TB_Good> goodList = new TB_GoodService().GetListArray_New(string.Format(" Temp.GoodId={0}", goodId)); decimal ZhiLiuKuCun = 0; if (goodList.Count > 0) { ZhiLiuKuCun = goodList[0].ZhiLiuKuCun; } lblZhiLiuNum.Text = ZhiLiuKuCun.ToString(); if (models.Count == 1) { lblGoodAreaNumber.Text = models[0].GoodAreaNumber; //名称\小类\规格 lblGoodInfo.Text = models[0].GoodName + @"\" + models[0].GoodTypeSmName + @"\" + models[0].GoodSpec; } //显示当前库存:XX,采库需 出: YY ,滞留库存:XX - YY DateTime fromDate = string.IsNullOrEmpty(txtFrom.Text)?Convert.ToDateTime("2000-1-1"):Convert.ToDateTime(txtFrom.Text); DateTime toDate = string.IsNullOrEmpty(txtTo.Text) ? Convert.ToDateTime("2036-1-1") : Convert.ToDateTime(txtTo.Text); List <Pro_JSXDetailInfo> pOOrderList = this.jxcDetailSer.GetListArray(Convert.ToInt32(ddlHouse.SelectedValue), goodId, fromDate, toDate); pOOrderList.Sort(delegate(Pro_JSXDetailInfo a, Pro_JSXDetailInfo b) { return(a.RuTime.CompareTo(b.RuTime)); }); jxcDetailSer.ReSetPro_JSXDetailInfo(pOOrderList); decimal iniNum = 0; for (int i = 0; i < pOOrderList.Count; i++) { var model = pOOrderList[i]; if (i == 0) { iniNum = model.GoodInNum - model.GoodOutNum; //i++; } else { iniNum = iniNum + model.GoodInNum - model.GoodOutNum; } pOOrderList[i].GoodResultNum = iniNum; } foreach (var m in pOOrderList) { m.KuCunTotal = m.GoodResultNum * m.TempHousePrice; } lblHadInvoice.Text = string.Format("{0:n2}", pOOrderList.Sum(t => t.HadInvoice)); lblNoInvoice.Text = string.Format("{0:n2}", pOOrderList.Sum(t => t.NoInvoice)); lblGoodInNum.Text = string.Format("{0:n2}", pOOrderList.Sum(t => t.GoodInNum)); lbllblGoodInNumTotal.Text = string.Format("{0:n2}", pOOrderList.Sum(t => t.GoodInNum * t.Price)); lblGoodOutNum.Text = string.Format("{0:n2}", pOOrderList.Sum(t => t.GoodOutNum)); lblGoodOutNumTotal.Text = string.Format("{0:n2}", pOOrderList.Sum(t => t.GoodOutTotal)); if (pOOrderList.Count > 0) { var lastModel = pOOrderList[pOOrderList.Count - 1]; lblGoodResultNum.Text = string.Format("{0:n2}", lastModel.GoodResultNum); LBLHouseTotal.Text = string.Format("{0:n2}", lastModel.KuCunTotal); } else { lblGoodResultNum.Text = "0"; } AspNetPager1.RecordCount = pOOrderList.Count; this.gvMain.PageIndex = AspNetPager1.CurrentPageIndex - 1; this.gvMain.DataSource = pOOrderList; this.gvMain.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DateTime fromDate = Convert.ToDateTime("2000-1-1"); DateTime toDate = Convert.ToDateTime("2036-1-1"); using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); var selectInfo = string.Format(@"select GoodId from TB_Good WHERE GoodStatus<>'不通过' and goodNo='12218'"); SqlCommand objCommand = conn.CreateCommand(); objCommand.CommandText = selectInfo; List <int> goodIdList = new List <int>(); using (var reader = objCommand.ExecuteReader()) { while (reader.Read()) { goodIdList.Add(Convert.ToInt32(reader["GoodId"])); } reader.Close(); } foreach (var goodId in goodIdList) { //查找进销存的所有信息 List <Pro_JSXDetailInfo> pOOrderList = this.jxcDetailSer.GetListArray(1, goodId, fromDate, toDate); pOOrderList.Sort(delegate(Pro_JSXDetailInfo a, Pro_JSXDetailInfo b) { return(a.RuTime.CompareTo(b.RuTime)); }); jxcDetailSer.ReSetPro_JSXDetailInfo(pOOrderList); decimal iniNum = 0; for (int i = 0; i < pOOrderList.Count; i++) { var model = pOOrderList[i]; if (i == 0) { iniNum = model.GoodInNum - model.GoodOutNum; //i++; } else { iniNum = iniNum + model.GoodInNum - model.GoodOutNum; } pOOrderList[i].GoodResultNum = iniNum; } //计算 Dictionary <int, decimal> inUpdatePrice = new Dictionary <int, decimal>(); Dictionary <int, decimal> outUpdatePrice = new Dictionary <int, decimal>(); Dictionary <int, decimal> sell_inUpdatePrice = new Dictionary <int, decimal>(); Dictionary <int, decimal> sell_outUpdatePrice = new Dictionary <int, decimal>(); Decimal avgPrice = 0; int startIndex = 0; foreach (var jxc in pOOrderList) { if (jxc.GoodResultNum != 0) { if (jxc.ProNo == "20120096") { } decimal topNum = startIndex > 1 ? pOOrderList[startIndex - 1].GoodResultNum : 0; if (jxc.TypeName == "采购入库") { avgPrice = (jxc.GoodInNum * jxc.avgHousePrice + avgPrice * topNum) / jxc.GoodResultNum; inUpdatePrice.Add(jxc.Ids, avgPrice); } if (jxc.TypeName == "销售退货") { avgPrice = (jxc.GoodInNum * jxc.avgHousePrice + avgPrice * topNum) / jxc.GoodResultNum; sell_outUpdatePrice.Add(jxc.Ids, avgPrice); } if (jxc.TypeName == "采购退货") { avgPrice = (avgPrice * topNum - jxc.GoodOutNum * jxc.avgHousePrice) / jxc.GoodResultNum; outUpdatePrice.Add(jxc.Ids, avgPrice); } if (jxc.TypeName == "销售出库") { avgPrice = (avgPrice * topNum - jxc.GoodOutNum * jxc.avgHousePrice) / jxc.GoodResultNum; sell_inUpdatePrice.Add(jxc.Ids, avgPrice); } } else { avgPrice = 0; } startIndex++; } StringBuilder sbSql = new StringBuilder(); foreach (var m in inUpdatePrice) { sbSql.AppendFormat("update CAI_OrderInHouses set TempHousePrice={1} where Ids={0}; ", m.Key, m.Value); } foreach (var m in outUpdatePrice) { sbSql.AppendFormat("update CAI_OrderOutHouses set TempHousePrice={1} where Ids={0}; ", m.Key, m.Value); } foreach (var m in sell_inUpdatePrice) { sbSql.AppendFormat("update Sell_OrderOutHouses set TempHousePrice={1} where Ids={0}; ", m.Key, m.Value); } foreach (var m in sell_outUpdatePrice) { sbSql.AppendFormat("update Sell_OrderInHouses set TempHousePrice={1} where Ids={0}; ", m.Key, m.Value); } if (!string.IsNullOrEmpty(sbSql.ToString())) { objCommand.CommandText = sbSql.ToString(); objCommand.ExecuteNonQuery(); } } } } }