/// <summary> /// 根据仓库和商品获取原账面数量 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAccountNumberOld_Click(object sender, EventArgs e) { if (DropDownList_WHCode.SelectedIndex == 0 || tbxCargoCode.Text == "") { ScriptManager.RegisterClientScriptBlock(this.Page, Page.GetType(), "btnAccountNumberOld_Click_WH", "alert('请先选择仓库和商品!');", true); return; } if (tbxCargoCode.Text.Trim() != "") { using (GoldEntities context = new GoldEntities()) { Cargos existModel = (from r in context.Cargos where r.CargoCode == tbxCargoCode.Text.Trim() select r).FirstOrDefault(); if (existModel == null) { ScriptManager.RegisterClientScriptBlock(this.Page, Page.GetType(), "btnAccountNumberOld_Click_Cargos", "alert('商品编码[" + tbxCargoCode.Text.Trim() + "]在系统中不存在,请先选择正确的商品!');", true); return; } } } string whCode = DropDownList_WHCode.SelectedItem.Value.ToString(); string cargoCode = tbxCargoCode.Text.Trim(); using (GoldEntities context = new GoldEntities()) { //获取之前的余额 StorePickAccount lastExistModel = null; if (ViewState["EditType"].ToString() == "1")//新增 { lastExistModel = (from r in context.StorePickAccount orderby r.StockPickAccountID descending where r.WHCode == whCode && r.CargoCode == cargoCode select r).FirstOrDefault(); } else //编辑 { int storePickAccountID = int.Parse(ViewState["EditID"].ToString()); lastExistModel = (from r in context.StorePickAccount orderby r.StockPickAccountID descending where r.WHCode == whCode && r.CargoCode == cargoCode && r.StockPickAccountID != storePickAccountID select r).FirstOrDefault(); } if (lastExistModel == null) { tbxAccountNumberOld.Text = "0"; tbxFactCheckNumberOld.Text = "0"; tbxIsProfitOrLostOld.Text = "0"; } else { tbxAccountNumberOld.Text = lastExistModel.AccountNumber.ToString(); tbxFactCheckNumberOld.Text = lastExistModel.FactCheckNumber.ToString(); tbxIsProfitOrLostOld.Text = lastExistModel.IsProfitOrLoss.ToString(); } } }
protected void btnSave_Click(object sender, EventArgs e) { try { lblSaveMsg.Text = ""; string outMsg = ""; if (ViewState["EditType"].ToString() == "1")//新增Insert { DAL.StorePickAccount newModel = new StorePickAccount(); bool getNewOK = GetNewModel(out newModel, out outMsg); if (getNewOK == false) { lblSaveMsg.Text = "新增失败![" + outMsg + "]"; return; } using (GoldEntities context = new GoldEntities()) { context.StorePickAccount.AddObject(newModel); int AffectRowsCount = context.SaveChanges(); lblSaveMsg.Text = "保存成功"; btnSave.Enabled = false; btnSave.CssClass = "ButtonImageStyleEnableFalse"; } } else//更新Update { using (GoldEntities context = new GoldEntities()) { int EditID = int.Parse(ViewState["EditID"].ToString()); DAL.StorePickAccount updateModel = (from r in context.StorePickAccount where r.StockPickAccountID == EditID select r).FirstOrDefault(); bool getUpdateOK = GetUpdateModel(ref updateModel, out outMsg); if (getUpdateOK == false) { lblSaveMsg.Text = "更新失败![" + outMsg + "]"; return; } //context.WareHouse.Attach(updateModel); int AffectRowsCount = context.SaveChanges(); lblSaveMsg.Text = "保存成功"; btnSave.Enabled = false; btnSave.CssClass = "ButtonImageStyleEnableFalse"; } } } catch (Exception ex) { lblSaveMsg.Text = "更新失败![" + Utility.LogHelper.GetExceptionMsg(ex) + "]"; } }
private void LoadInfo(string ItemID) { using (GoldEntities context = new GoldEntities()) { //绑定存提状态 List <NameValueModel> ListPickOrStore = Gold.Utility.EnumData.GetEnumsList(typeof(Gold.Utility.EnumData.PickOrStore)); DropDownList_StorePickType.Items.Clear(); DropDownList_StorePickType.DataTextField = "Name"; DropDownList_StorePickType.DataValueField = "Value"; DropDownList_StorePickType.DataSource = ListPickOrStore; DropDownList_StorePickType.DataBind(); DropDownList_StorePickType.Items.Insert(0, new ListItem("", "")); //绑定包装 var result = (from r in context.Packages select new { r.PackageId, r.PackageName }).OrderBy(r => r.PackageName).ToList(); DropDownList_PackageName.Items.Clear(); DropDownList_PackageName.DataTextField = "PackageName"; DropDownList_PackageName.DataValueField = "PackageId"; DropDownList_PackageName.DataSource = result; DropDownList_PackageName.DataBind(); DropDownList_PackageName.Items.Insert(0, new ListItem("", "")); //绑定仓库 var resultWH = (from r in context.WareHouse select new { r.WHCode, r.WHName }).OrderBy(r => r.WHCode).ToList(); DropDownList_WHCode.Items.Clear(); DropDownList_WHCode.DataTextField = "WHName"; DropDownList_WHCode.DataValueField = "WHCode"; DropDownList_WHCode.DataSource = resultWH; DropDownList_WHCode.DataBind(); DropDownList_WHCode.Items.Insert(0, new ListItem("", "")); //编辑状态下进入此页面时 if (ItemID != "-1") { tbxCargoCode.Enabled = false; tbxCargoName.Enabled = false; btnSelectCargo1.Enabled = false; btnSelectCargo2.Enabled = false; DropDownList_WHCode.Enabled = false; DropDownList_StorePickType.Enabled = false; btnAccountNumberOld.Visible = false; btnComputeNewNumber.Visible = false; tbxStorePickNumber.Enabled = false; tbxAccountNumberNew.Enabled = false; tbxFactCheckNumberNew.Enabled = false; tbxIsProfitOrLostNew.Enabled = false; int ItemIDInt = int.Parse(ItemID); StorePickAccount existModel = (from r in context.StorePickAccount where r.StockPickAccountID == ItemIDInt select r).FirstOrDefault(); if (existModel != null) { string storePickType = existModel.StorePickType; DropDownList_StorePickType.SelectedIndex = DropDownList_StorePickType.Items.IndexOf(DropDownList_StorePickType.Items.FindByValue(storePickType)); tbxStorePickNumber.Text = existModel.StorePickNumber.ToString(); DropDownList_WHCode.SelectedIndex = DropDownList_WHCode.Items.IndexOf(DropDownList_WHCode.Items.FindByValue(existModel.WHCode)); tbxCargoCode.Text = existModel.CargoCode; tbxCargoName.Text = existModel.CargoName; tbxStorePickNumber.Text = existModel.StorePickNumber.ToString(); tbxAccountNumberOld.Text = existModel.AccountNumber.ToString(); tbxFactCheckNumberOld.Text = existModel.FactCheckNumber.ToString(); tbxIsProfitOrLostOld.Text = existModel.IsProfitOrLoss.ToString(); //编辑时数据一致 tbxAccountNumberNew.Text = existModel.AccountNumber.ToString(); tbxFactCheckNumberNew.Text = existModel.FactCheckNumber.ToString(); tbxIsProfitOrLostNew.Text = existModel.IsProfitOrLoss.ToString(); DropDownList_PackageName.SelectedIndex = DropDownList_PackageName.Items.IndexOf(DropDownList_PackageName.Items.FindByText(existModel.PackageName)); tbxPackageCount.Text = existModel.PackageCount.Value.ToString(); tbxStandardCountEachBag.Text = existModel.StandardCountEachBag.Value.ToString(); tbxPackageNoStart.Text = existModel.PackageNoStart; tbxPackageNoEnd.Text = existModel.PackageNoEnd; tbxStoreDescription.Text = existModel.StoreDescription; tbxRemark.Text = existModel.Remark; tbxPackageLockNo.Text = existModel.PackageLockNo; tbxPackageShareNo.Text = existModel.PackageShareNo; tbxRecordDetail.Text = existModel.RecordDetail; lblRecordTime.Text = existModel.RecordTime.ToString(); lblRecordMonth.Text = existModel.RecordMonth; } } } }
/// <summary> /// 根据界面数据填充更新的对象 /// </summary> /// <param name="updateModel"></param> /// <param name="msg"></param> /// <returns></returns> private bool GetUpdateModel(ref StorePickAccount updateModel, out string msg) { msg = ""; try { //updateModel.RecordTime = DateTime.Now; //updateModel.RecordMonth = DateTime.Now.ToString("yyyy-MM"); updateModel.Remark += DateTime.Now.ToString("yyyy-MM-dd") + "编辑1次 "; if (DropDownList_WHCode.SelectedIndex == 0 || DropDownList_StorePickType.SelectedIndex == 0) { msg = "仓库和存提类型不能为空,请选择!"; return(false); } updateModel.WHCode = DropDownList_WHCode.SelectedItem.Value; updateModel.StorePickType = DropDownList_StorePickType.SelectedItem.Value; string cargoCode = tbxCargoCode.Text.Trim(); using (DAL.GoldEntities context = new GoldEntities()) { Cargos cargoExist = context.Cargos.Where(r => r.CargoCode == cargoCode).FirstOrDefault <Cargos>(); if (cargoExist == null) { msg = "商品编码错误,请重新选择商品编码"; return(false); } else { updateModel.CargoCode = cargoExist.CargoCode; updateModel.CargoName = cargoExist.CargoName; updateModel.CargoModel = cargoExist.CargoModel; updateModel.CargoSpec = cargoExist.CargoSpec; updateModel.CargoUnits = cargoExist.CargoUnits; updateModel.ReleaseYear = cargoExist.ProduceYear; } } double AccountNumber = 0, FactCheckNumber = 0, StorePickNumber = 0; int IsProfitOrLoss = 0, PackageCount = 0, StandardCountEachBag = 0; double.TryParse(tbxStorePickNumber.Text.Trim(), out StorePickNumber); double.TryParse(tbxAccountNumberNew.Text.Trim(), out AccountNumber); double.TryParse(tbxFactCheckNumberNew.Text.Trim(), out FactCheckNumber); int.TryParse(tbxIsProfitOrLostNew.Text.Trim(), out IsProfitOrLoss); int.TryParse(tbxPackageCount.Text.Trim(), out PackageCount); int.TryParse(tbxStandardCountEachBag.Text.Trim(), out StandardCountEachBag); updateModel.StorePickNumber = StorePickNumber; updateModel.AccountNumber = AccountNumber; updateModel.FactCheckNumber = FactCheckNumber; updateModel.IsProfitOrLoss = IsProfitOrLoss; if (DropDownList_PackageName.SelectedIndex != 0) { updateModel.PackageId = int.Parse(DropDownList_PackageName.SelectedItem.Value.ToString()); updateModel.PackageName = DropDownList_PackageName.SelectedItem.Text; } else { updateModel.PackageId = 0; updateModel.PackageName = ""; } updateModel.PackageCount = PackageCount; updateModel.StandardCountEachBag = StandardCountEachBag; updateModel.PackageNoStart = tbxPackageNoStart.Text; updateModel.PackageNoEnd = tbxPackageNoEnd.Text; updateModel.StoreDescription = tbxStoreDescription.Text; updateModel.Remark = tbxRemark.Text; updateModel.PackageLockNo = tbxPackageLockNo.Text; updateModel.PackageShareNo = tbxPackageShareNo.Text; updateModel.RecordDetail = tbxRecordDetail.Text; updateModel.BadRate = tbxBadRate.Text; return(true); } catch (Exception ex) { msg = ex.Message.ToString(); return(false); } }