//结束盘点任务 protected void btnFinish_Click(object sender, EventArgs e) { try { lblGridViewMsg.Text = ""; using (GoldEntities context = new GoldEntities()) { string scpCode = lblSCPCodeShow.Text; foreach (GridViewRow row in gv_CargoList.Rows) { /* * lblSCPCode * lblDetailRowNumber * lblNumPlan * lblPeriodInNum * lblPeriodOutNum * lblNumActual * lblNumDifference */ Label lblDetailRowNumber = row.FindControl("lblDetailRowNumber") as Label; //Label lblNumPlan = row.FindControl("lblNumPlan") as Label; Label lblPeriodInNum = row.FindControl("lblPeriodInNum") as Label; Label lblPeriodOutNum = row.FindControl("lblPeriodOutNum") as Label; //Label lblNumActual = row.FindControl("lblNumActual") as Label; Label lblNumDifference = row.FindControl("lblNumDifference") as Label; string DetailRowNumber = lblDetailRowNumber.Text.Trim(); //double NumPlan=0; double PeriodInNum = 0; double PeriodOutNum = 0; //double NumActual=0; double NumDifference = 0; //if(lblNumActual!=null&&lblNumActual.Text.Trim()!="") // NumActual=double.Parse(lblNumActual.Text); if (lblPeriodInNum != null && lblPeriodInNum.Text.Trim() != "") { PeriodInNum = double.Parse(lblPeriodInNum.Text); } if (lblPeriodOutNum != null && lblPeriodOutNum.Text.Trim() != "") { PeriodOutNum = double.Parse(lblPeriodOutNum.Text); } if (lblNumDifference != null && lblNumDifference.Text.Trim() != "") { NumDifference = double.Parse(lblNumDifference.Text); } StockCountingDetail updateModel = (from r in context.StockCountingDetail where r.SCPCode == scpCode && r.DetailRowNumber == DetailRowNumber select r).FirstOrDefault(); updateModel.PeriodInNum = PeriodInNum; updateModel.PeriodOutNum = PeriodOutNum; updateModel.NumDifference = NumDifference; } StockCountingPlan planModel = (from r in context.StockCountingPlan where r.SCPCode == scpCode select r).FirstOrDefault(); planModel.SCPStatus = (int)EnumData.SCPStatusEnum.Finished; if (Session["UserInfo"] != null) { Users LoginUser = Session["UserInfo"] as Users; planModel.FinishPersonID = LoginUser.UserId; planModel.FinishPersonName = LoginUser.UserName; } planModel.FinishDate = DateTime.Now; int AffectRowsCount = context.SaveChanges(); lblGridViewMsg.Text = "盘点计划单[" + scpCode + "]成功结束![影响行数" + AffectRowsCount.ToString() + "]"; btnFinish.Enabled = false; btnFinish.CssClass = "ButtonImageStyleEnableFalse"; GridViewBind();//删除完成后重新绑定盘点计划单 } } catch (Exception ex) { lblGridViewMsg.Text = "操作失败![" + Utility.LogHelper.GetExceptionMsg(ex) + "]"; } }
/// <summary> /// 根据界面数据填充更新的对象 /// </summary> /// <param name="updateModel">传入此方法之前应先查询此对象所有值</param> /// <param name="detailList">当前所有选中的层位对应的明细</param> /// <param name="msg"></param> /// <returns></returns> private bool GetUpdateModel(ref StockCountingPlan updateModel, out List <StockCountingDetail> detailList, out string msg) { msg = ""; detailList = new List <StockCountingDetail>(); try { //updateModel.SCPCode = DAL.KeyGenerator.Instance.GetStockCountingPlanKey();//获取自动生成序列盘点计划单号 updateModel.SCPCode = tbxSCPCode.Text.Trim(); if (DropDownList_SCPType.SelectedItem == null || DropDownList_WHCode.SelectedItem == null || DropDownList_SCPType.SelectedItem.Text.Trim() == "" || DropDownList_WHCode.SelectedItem.Text.Trim() == "") { msg = "盘点类型和盘点仓库不能为空,请选择!"; return(false); } updateModel.SCPType = int.Parse(DropDownList_SCPType.Text == "" ? null : DropDownList_SCPType.SelectedItem.Value.Trim()); updateModel.WHCode = DropDownList_WHCode.SelectedItem.Value.ToString(); updateModel.WHName = DropDownList_WHCode.SelectedItem.Text; if (Session["UserInfo"] != null) { Users LoginUser = Session["UserInfo"] as Users; updateModel.CreatorID = LoginUser.UserId; updateModel.CreatorName = LoginUser.UserName; } updateModel.CreateDate = DateTime.Now; updateModel.Comment = tbxComment.Text.Trim(); List <string> BinCodeList = GetTreeViewCheckedNode(); if (BinCodeList.Count == 0) { msg = "必须选择盘点层位范围!"; return(false); } using (GoldEntities context = new GoldEntities()) { var result = (from r in context.CargoTag where BinCodeList.Contains(r.BinCode) && r.CargoCode != null && r.CargoCode != "" select r); //获取最大值 string scpCode = updateModel.SCPCode; List <string> rowNumberList = (from r in context.StockCountingDetail where r.SCPCode == scpCode select r.DetailRowNumber).ToList <string>(); List <int> rowNumberIntList = rowNumberList.ConvertAll <int>(ConvertStringToInt); int maxRowNumber = rowNumberIntList.Count == 0 ? 0 : rowNumberIntList.Max(); foreach (var temp in result) { maxRowNumber++; StockCountingDetail newObj = new StockCountingDetail(); newObj.SCPCode = updateModel.SCPCode; newObj.DetailRowNumber = maxRowNumber.ToString().PadLeft(3, '0');;//因为此处明细行是作为新增数据处理,所以设置行号 newObj.CargoCode = temp.CargoCode; newObj.CargoName = temp.Cargos.CargoName; newObj.CargoModel = temp.Cargos.CargoModel; newObj.CargoSpec = temp.Cargos.CargoSpec; newObj.CargoUnits = temp.Cargos.CargoUnits; newObj.BinCode = temp.BinCode; newObj.NumPlan = temp.Number;//商品标签表中存储的商品数量 newObj.NumActual = null; newObj.PeriodInNum = null; newObj.PeriodOutNum = null; newObj.NumDifference = null; newObj.CountingEndTime = null; newObj.CountingStartTime = updateModel.CreateDate;//DateTime.Now;//盘点开始时间即为创建时间 newObj.Status = (int)EnumData.SCDetailStatusEnum.Uncompleted; newObj.ActorID = null; newObj.ActorName = null; detailList.Add(newObj); } } return(true); } catch (Exception ex) { msg = ex.Message.ToString(); return(false); } }