public void BindGrid(bool IsCashBack, int CashBackIndex = -1, int PremiumsDetailsIndex = -1) { XMCashBackApplication CashBack = new XMCashBackApplication(); XMPremiumsDetails PremiumsDetails = new XMPremiumsDetails(); List <XMPremiumsDetails> PremiumsDetailsList = new List <XMPremiumsDetails>(); var XMOrderInfo = GetOrderInfo(); if (IsCashBack) { //返现 List <XMCashBackApplication> CashBackList = base.XMCashBackApplicationService.GetXMCashBackApplicationListByQuestionDetailID(Id.ToString()); if (XMOrderInfo != null) { CashBack.OrderCode = XMOrderInfo.OrderCode; CashBack.WantNo = XMOrderInfo.WantID; CashBack.BuyerName = XMOrderInfo.FullName; } if (CashBackIndex == -1) { CashBackList.Add(CashBack); this.gvCashback.EditIndex = CashBackList.Count - 1; } else { this.gvCashback.EditIndex = CashBackIndex; } this.gvCashback.DataSource = CashBackList; this.gvCashback.DataBind();//绑定数据源 } else { //赠品 var Premiums = base.XMPremiumsService.GetXMPremiumsListByQuestionDetailID(Id.ToString()); if (Premiums != null) { var premiumsDetailsList = base.XMPremiumsDetailsService.GetXMPremiumsDetailsListByPremiumsId(Premiums.Id); PremiumsDetailsList.AddRange(premiumsDetailsList); if (PremiumsDetailsIndex == -1) { PremiumsDetailsList.Add(PremiumsDetails); this.gvPremiums.EditIndex = PremiumsDetailsList.Count - 1; } else { this.gvPremiums.EditIndex = PremiumsDetailsIndex; } } else { this.gvPremiums.EditIndex = 0; } this.gvPremiums.DataSource = PremiumsDetailsList; this.gvPremiums.DataBind();//绑定数据源 } }
protected void gvPremiums_RowUpdating(object sender, GridViewUpdateEventArgs e) { using (TransactionScope scope = new TransactionScope()) { #region 取控件值 int n = 0; decimal d = 0; GridView a = (GridView)sender; TextBox txtPrdouctName = a.Rows[e.RowIndex].FindControl("txtPrdouctName") as TextBox; TextBox txtPlatformMerchantCode = a.Rows[e.RowIndex].FindControl("txtPlatformMerchantCode") as TextBox; TextBox txtSpecifications = a.Rows[e.RowIndex].FindControl("txtSpecifications") as TextBox; TextBox txtProductNum = a.Rows[e.RowIndex].FindControl("txtProductNum") as TextBox; TextBox txtFactoryPrice = a.Rows[e.RowIndex].FindControl("txtFactoryPrice") as TextBox; DropDownList ddlShipper = a.Rows[e.RowIndex].FindControl("ddlShipper") as DropDownList; #endregion if (txtPrdouctName.Text == "" || txtPlatformMerchantCode.Text == "" || txtFactoryPrice.Text == "" || txtProductNum.Text == "") { base.ShowMessage("数据不能为空!"); return; } if (!int.TryParse(txtProductNum.Text, out n)) { base.ShowMessage("数量数据类型不正确!"); return; } if (!decimal.TryParse(txtFactoryPrice.Text, out d)) { base.ShowMessage("出厂价数据类型不正确!"); return; } int ID = int.Parse(a.DataKeys[e.RowIndex].Value.ToString()); var Premiums = base.XMPremiumsService.GetXMPremiumsListByQuestionDetailID(Id.ToString()); string DetailId = this.hidDetailId.Value.Trim(); if (Premiums != null) { if (ID == 0) { XMPremiumsDetails orderproduct = new XMPremiumsDetails(); orderproduct.ProductDetaislId = int.Parse(DetailId); orderproduct.PremiumsId = Premiums.Id; orderproduct.PlatformMerchantCode = txtPlatformMerchantCode.Text.Trim(); orderproduct.PrdouctName = txtPrdouctName.Text.Trim(); orderproduct.ProductNum = int.Parse(txtProductNum.Text.Trim()); orderproduct.FactoryPrice = decimal.Parse(txtFactoryPrice.Text.Trim()); orderproduct.Shipper = int.Parse(ddlShipper.SelectedValue.Trim()); orderproduct.IsEnable = false; orderproduct.CreateID = HozestERPContext.Current.User.CustomerID; orderproduct.CreateDate = DateTime.Now; orderproduct.UpdateID = HozestERPContext.Current.User.CustomerID; orderproduct.UpdateDate = DateTime.Now; base.XMPremiumsDetailsService.InsertXMPremiumsDetails(orderproduct); } else { XMPremiumsDetails orderproduct = base.XMPremiumsDetailsService.GetXMPremiumsDetailsById(ID); if (!string.IsNullOrEmpty(DetailId)) { orderproduct.ProductDetaislId = int.Parse(DetailId); } orderproduct.PlatformMerchantCode = txtPlatformMerchantCode.Text.Trim(); orderproduct.PrdouctName = txtPrdouctName.Text.Trim(); orderproduct.ProductNum = int.Parse(txtProductNum.Text.Trim()); orderproduct.FactoryPrice = decimal.Parse(txtFactoryPrice.Text.Trim()); orderproduct.Shipper = int.Parse(ddlShipper.SelectedValue.Trim()); orderproduct.UpdateID = HozestERPContext.Current.User.CustomerID; orderproduct.UpdateDate = DateTime.Now; base.XMPremiumsDetailsService.UpdateXMPremiumsDetails(orderproduct); } base.ShowMessage("保存成功!"); } scope.Complete(); } BindGrid(false); }
protected void grdvClients_RowCommand(object sender, GridViewCommandEventArgs e) { try { List <XMPremiumsDetails> list = new List <XMPremiumsDetails>(); if (Session["PremiumsDetailList"] != null) { list = (List <XMPremiumsDetails>)Session["PremiumsDetailList"]; } #region 除 if (e.CommandName.Equals("ToDelete")) { if (Id != 0) { var xMOrderInfo = base.XMPremiumsDetailsService.GetXMPremiumsDetailsById(Convert.ToInt32(e.CommandArgument)); if (xMOrderInfo != null)//删除 { xMOrderInfo.IsEnable = true; xMOrderInfo.UpdateID = HozestERPContext.Current.User.CustomerID; xMOrderInfo.UpdateDate = DateTime.Now; base.XMPremiumsDetailsService.UpdateXMPremiumsDetails(xMOrderInfo); this.BindGrid(); base.ShowMessage("操作成功!"); } } else { list.RemoveAt(Convert.ToInt32(e.CommandArgument)); for (int i = 1; i <= list.Count; i++) { list[i].Id = i; } Session["PremiumsDetailList"] = list; } this.BindGrid(); } #endregion //修改 if (e.CommandName.Equals("ToAdd")) { int ID = Convert.ToInt32(e.CommandArgument); //编辑行 GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).Parent.Parent; HtmlInputText txtProductCode = (HtmlInputText)gvr.FindControl("txtProductCode"); HtmlInputText lblProductName = (HtmlInputText)gvr.FindControl("lblProductName"); TextBox txtProductNum = (TextBox)gvr.FindControl("txtProductNum"); TextBox lblFactoryPrice = (TextBox)gvr.FindControl("lblFactoryPrice"); DropDownList ddlShipper = (DropDownList)gvr.FindControl("ddlShipper"); HiddenField hidProductId = (HiddenField)gvr.FindControl("hidProductId"); if (txtProductCode.Value == "") { base.ShowMessage("商品编码不能为空!"); return; } XMPremiumsDetails one = new XMPremiumsDetails(); if (!string.IsNullOrEmpty(hidProductId.Value)) { one.ProductDetaislId = int.Parse(hidProductId.Value); } one.PlatformMerchantCode = txtProductCode.Value; one.PrdouctName = lblProductName.Value; one.ProductNum = int.Parse(txtProductNum.Text.Trim()); one.FactoryPrice = decimal.Parse(lblFactoryPrice.Text.Trim()); one.Shipper = int.Parse(ddlShipper.SelectedValue.Trim()); one.IsEnable = false; one.CreateID = HozestERPContext.Current.User.CustomerID; one.CreateDate = DateTime.Now; one.UpdateID = HozestERPContext.Current.User.CustomerID; one.UpdateDate = DateTime.Now; one.IsSingleRow = false; if (Id != 0) { if (ID == 0) { one.PremiumsId = Id; base.XMPremiumsDetailsService.InsertXMPremiumsDetails(one); } else { //订单详细信息 var detail = base.XMPremiumsDetailsService.GetXMPremiumsDetailsById(ID); if (detail != null) { detail.ProductDetaislId = one.ProductDetaislId; detail.PlatformMerchantCode = one.PlatformMerchantCode; detail.PrdouctName = one.PrdouctName; detail.ProductNum = one.ProductNum; detail.FactoryPrice = one.FactoryPrice; detail.Shipper = one.Shipper; detail.UpdateID = one.UpdateID; detail.UpdateDate = one.UpdateDate; base.XMPremiumsDetailsService.UpdateXMPremiumsDetails(one); } } } else { if (ID == 0) { one.Id = list.Count + 1; list.Add(one); } else { one.Id = ID; list[ID - 1] = one; } Session["PremiumsDetailList"] = list; } //base.ShowMessage("添加成功!"); this.BindGrid(); } } catch (Exception ex) { base.ProcessException(ex); } }