protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (this.ProductId > 0) { XMCombination xMProduct = base.XMCombinationService.GetXMCombinationByID(this.ProductId); if (xMProduct != null) { this.lblNickId.Text = xMProduct.NickName != null ? xMProduct.NickName.nick: ""; this.lblProductName.Text = xMProduct.ProductName != null ? xMProduct.ProductName : ""; this.lblManufacturersCode.Text = xMProduct.ManufacturersCode != null ? xMProduct.ManufacturersCode : ""; } BindGrid(); } } }
/// <summary> /// 保存 /// </summary> protected void btnSave_Click(object sender, EventArgs e) { try { int NickID = int.Parse(this.ddlNickId.SelectedValue); string ProductName = this.ddlProductName.Text.Trim(); int a = 0; if (int.TryParse(this.ddlProductWeight.Text.Trim(), out a) == false) { base.ShowMessage("重量必须为整数!"); return; } string ManufacturersCode = this.ddlManufacturersCode.Text.Trim(); if (CombinationID == 0) { var list = base.XMCombinationService.GetXMCombinationByManufacturersCode(ManufacturersCode); if (list != null && list.Count > 1) { base.ShowMessage("此厂家编码在数据库中已存在!"); return; } } List <int> countList = new List <int>(); //循环grid 每行 foreach (GridViewRow item in grdvClients.Rows) { TextBox ddlCount = item.FindControl("ddlCount") as TextBox; string id = grdvClients.DataKeys[item.RowIndex].Values[0].ToString(); if (ddlCount.Visible) { //数据转换 if (ddlCount.Text.Trim() != "") { if (int.TryParse(this.ddlProductWeight.Text.Trim(), out a) == true) { countList.Add(int.Parse(ddlCount.Text.Trim())); } else { base.ShowMessage("数量必须为整数!"); return; } } else { countList.Add(0); } } } var CombinationInfo = base.XMCombinationService.GetXMCombinationByID(CombinationID); int Code = 0; if (CombinationInfo == null) { XMCombination info = new XMCombination(); info.NickId = NickID; info.ProductName = ProductName; info.ProductWeight = this.ddlProductWeight.Text.Trim(); info.ManufacturersCode = ManufacturersCode; info.IsEnabled = false; info.CreatorID = HozestERPContext.Current.User.CustomerID; info.CreateTime = DateTime.Now; info.UpdatorID = HozestERPContext.Current.User.CustomerID; info.UpdateTime = DateTime.Now; base.XMCombinationService.InsertXMCombination(info); Code = info.ID; } else { CombinationInfo.NickId = NickID; CombinationInfo.ProductName = ProductName; CombinationInfo.ProductWeight = this.ddlProductWeight.Text.Trim(); CombinationInfo.ManufacturersCode = ManufacturersCode; CombinationInfo.UpdatorID = HozestERPContext.Current.User.CustomerID; CombinationInfo.UpdateTime = DateTime.Now; base.XMCombinationService.UpdateXMCombination(CombinationInfo); } List <int> IDs = (List <int>)Session["ProductInfoList"]; //int Code = 0; if (CombinationID != 0) { Code = CombinationID; } if (CombinationID != 0) { var ProductCombinationList = base.XMProductCombinationService.GetXMProductCombinationByCombinationID(CombinationID); foreach (XMProductCombination ProductCombinationInfo in ProductCombinationList) { ProductCombinationInfo.IsEnabled = true; ProductCombinationInfo.UpdatorID = HozestERPContext.Current.User.CustomerID; ProductCombinationInfo.UpdateTime = DateTime.Now; base.XMProductCombinationService.UpdateXMProductCombination(ProductCombinationInfo); } } if (IDs != null && IDs.Count != 0) { for (int i = 0; i < IDs.Count; i++) { XMProductCombination productCom = new XMProductCombination(); productCom.ProductID = IDs[i]; productCom.CombinationID = Code; productCom.Count = countList[i]; productCom.IsEnabled = false; productCom.CreatorID = HozestERPContext.Current.User.CustomerID; productCom.CreateTime = DateTime.Now; productCom.UpdatorID = HozestERPContext.Current.User.CustomerID; productCom.UpdateTime = DateTime.Now; base.XMProductCombinationService.InsertXMProductCombination(productCom); } } base.ShowMessage("保存成功!"); Session["ProductInfoList"] = null; } catch { } }