private void BindGrid() { ListTable <ORD_OrderApplyDetail> _details = ViewState["Details"] as ListTable <ORD_OrderApplyDetail>; gv_ProductList.BindGrid <ORD_OrderApplyDetail>(_details.GetListItem()); foreach (GridViewRow row in gv_ProductList.Rows) { DataTable dt = ViewState["Limit"] as DataTable; int OrderVolume = 0; string Product = gv_ProductList.DataKeys[row.RowIndex]["Product"].ToString(); DataRow[] productrow = dt.Select("Product=" + Product); if (productrow.Count() > 0) { OrderVolume = Convert.ToInt32(productrow[0]["OrderVolume"]); if ((int)ViewState["ID"] != 0 && new ORD_OrderApplyBLL((int)ViewState["ID"]).Model.State == 3) { OrderVolume = 0; } ORD_OrderApplyDetail m = _details[Product]; Label lb_state = (Label)row.FindControl("lb_State"); lb_state.ForeColor = System.Drawing.Color.Red; lb_state.Font.Bold = true; lb_state.Font.Size = 10; if ((OrderVolume + m.BookQuantity) > Convert.ToInt32(productrow[0]["MaxPurchaseVolume"])) { row.BackColor = System.Drawing.Color.FromName("#b7d8f9"); lb_state.Visible = true; lb_state.Text = "↑"; } if ((OrderVolume + m.BookQuantity) < Convert.ToInt32(productrow[0]["MinPurchaseVolume"])) { row.BackColor = System.Drawing.Color.FromName("#7d9cbb"); lb_state.Visible = true; lb_state.Text = "↓"; } } } //求销售额合计 decimal _totalcost = 0; foreach (ORD_OrderApplyDetail _detail in _details.GetListItem()) { _totalcost += _detail.Price * (_detail.BookQuantity + _detail.AdjustQuantity); } lb_TotalCost.Text = _totalcost.ToString("0.###"); }
protected void bt_AddToDeliveryList_Click(object sender, EventArgs e) { if (tr_OrganizeCity.SelectValue == "0") { MessageBox.Show(this, "必须选择管理片区才能点添加"); return; } tr_OrganizeCity.Enabled = false; //开始添加报销后,不允许选择其他的管理片区,保证所有的费用明细都来源于一个管理片区 ListTable <ORD_OrderDeliveryDetail> _details = ViewState["Details"] as ListTable <ORD_OrderDeliveryDetail>; foreach (GridViewRow row in gv_OrderAplyList.Rows) { CheckBox cb_Selected = (CheckBox)row.FindControl("cb_Selected"); if (cb_Selected.Checked) { int applyid = (int)gv_OrderAplyList.DataKeys[row.RowIndex][0]; int applydetialid = (int)gv_OrderAplyList.DataKeys[row.RowIndex][1]; ORD_OrderApplyBLL applyBLL = new ORD_OrderApplyBLL(applyid); ORD_OrderApplyDetail applydetail = applyBLL.GetDetailModel(applydetialid); ORD_OrderDeliveryDetail m = new ORD_OrderDeliveryDetail(); m.ApplyDetailID = applydetialid; m.Client = applyBLL.Model.Client; m.Product = applydetail.Product; m.Price = applydetail.Price; m.FactoryPrice = m.FactoryPrice == 0 ? applydetail.Price : m.FactoryPrice; m.DeliveryQuantity = applydetail.BookQuantity + applydetail.AdjustQuantity - applydetail.DeliveryQuantity; m.SignInQuantity = m.DeliveryQuantity; _details.Add(m); } } bNoDelivery = true; BindGrid(); gv_OrderAplyList.PageIndex = 0; BindOrderApplyCanDelivery(); }
protected void bt_SaveAdjust_Click(object sender, EventArgs e) { if ((int)ViewState["ID"] != 0) { ListTable <ORD_OrderApplyDetail> _details = ViewState["Details"] as ListTable <ORD_OrderApplyDetail>; foreach (GridViewRow row in gv_ProductList.Rows) { int productid = (int)gv_ProductList.DataKeys[row.RowIndex]["Product"]; ORD_OrderApplyDetail m = _details[productid.ToString()]; PDT_Product product = new PDT_ProductBLL(m.Product).Model; TextBox tbx_AdjustQuantity_T = (TextBox)row.FindControl("tbx_AdjustQuantity_T"); TextBox tbx_AdjustQuantity = (TextBox)row.FindControl("tbx_AdjustQuantity"); int quantity = int.Parse(tbx_AdjustQuantity_T.Text) * product.ConvertFactor + int.Parse(tbx_AdjustQuantity.Text); if (m.BookQuantity + quantity < 0) { MessageBox.Show(this, "对不起,扣减的调整数量不能大于定货数量!"); return; } m.AdjustQuantity = quantity; m.AdjustReason = ((TextBox)row.FindControl("tbx_AdjustReason")).Text; _details.Update(m); } ORD_OrderApplyBLL bll = new ORD_OrderApplyBLL((int)ViewState["ID"]); bll.Items = _details.GetListItem(ItemState.Modified); bll.UpdateDetail(); BindGrid(); } }
private bool Save() { ORD_OrderCartBLL cart = null; if (Session["LogisticsOrderApplyDetail"] != null) { cart = (ORD_OrderCartBLL)Session["LogisticsOrderApplyDetail"]; } if ((int)ViewState["ID"] == 0) { if (cart == null || cart.Items.Count == 0) { MessageBox.Show(this, "对不起,定单申请明细不能为空!"); return(false); } ORD_OrderApplyBLL bll = new ORD_OrderApplyBLL(); pn_OrderApply.GetData(bll.Model); #region 判断有没有填写经销商 if (bll.Model.Client == 0) { MessageBox.Show(this, "对不起,请填写申请定购的经销商!"); return(false); } #endregion #region 初始化定单字段 bll.Model.OrganizeCity = cart.OrganizeCity; bll.Model.PublishID = cart.Publish; bll.Model.AccountMonth = cart.AccountMonth; bll.Model.SheetCode = ORD_OrderApplyBLL.GenerateSheetCode(bll.Model.OrganizeCity, bll.Model.AccountMonth); //自动产生备案号 bll.Model.ApproveFlag = 2; bll.Model.State = 1; bll.Model.InsertStaff = (int)Session["UserID"]; bll.Model["AddressID"] = cart.AddressID.ToString(); bll.Model["Receiver"] = cart.Receiver.ToString(); if (cart.Publish > 0) { ORD_ApplyPublish publish = new ORD_ApplyPublishBLL(cart.Publish).Model; if (publish != null) { bll.Model["ProductBrand"] = publish["ProductBrand"]; bll.Model["GiftClassify"] = publish["GiftClassify"]; } } #endregion ViewState["ID"] = bll.Add(); #region 新增定单明细明细 foreach (ORD_OrderCart cartitem in cart.Items) { if (cartitem.BookQuantity == 0) { continue; } ORD_OrderApplyDetail m = new ORD_OrderApplyDetail(); m.ApplyID = (int)ViewState["ID"]; m.Product = cartitem.Product; m.Price = cartitem.Price; m.BookQuantity = cartitem.BookQuantity; m.AdjustQuantity = 0; m.DeliveryQuantity = 0; bll.AddDetail(m); } #endregion } else { ORD_OrderApplyBLL bll = new ORD_OrderApplyBLL((int)ViewState["ID"]); pn_OrderApply.GetData(bll.Model); bll.Model.UpdateStaff = (int)Session["UserID"]; bll.Update(); #region 修改明细 if (cart != null) { //先将现有定单中每个品项与购物中的比较 //如果购物车中没有该产品,则删除,如有且数量不同,则更新,并从购物车中移除该品项 foreach (ORD_OrderApplyDetail m in bll.Items) { ORD_OrderCart cartitem = cart.Items.FirstOrDefault(p => p.Product == m.Product); if (cartitem == null) { bll.DeleteDetail(m.ID); } else { if (cartitem.BookQuantity != m.BookQuantity) { m.BookQuantity = cartitem.BookQuantity; bll.UpdateDetail(m); } cart.RemoveProduct(m.Product); } } //新购物车中新增的品项加入定单明细中 foreach (ORD_OrderCart cartitem in cart.Items) { ORD_OrderApplyDetail m = new ORD_OrderApplyDetail(); m.ApplyID = (int)ViewState["ID"]; m.Product = cartitem.Product; m.Price = cartitem.Price; m.BookQuantity = cartitem.BookQuantity; m.AdjustQuantity = 0; m.DeliveryQuantity = 0; bll.AddDetail(m); } } #endregion } return(true); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { #region 判断传入参数是否为SheetCode if (Request.QueryString["SheetCode"] != null) { string code = Request.QueryString["SheetCode"]; IList <ORD_OrderApply> list = ORD_OrderApplyBLL.GetModelList("SheetCode='" + code + "'"); if (list.Count > 0) { Response.Redirect("OrderProductApplyDetail.aspx?ID=" + list[0].ID.ToString()); } else { Response.Redirect("OrderApplyList.aspx"); } } #endregion ViewState["ID"] = Request.QueryString["ID"] == null ? 0 : int.Parse(Request.QueryString["ID"]); BindDropDown(); ViewState["Product"] = 0; #region 创建空的列表 ListTable <ORD_OrderApplyDetail> _details = new ListTable <ORD_OrderApplyDetail>(new ORD_OrderApplyBLL((int)ViewState["ID"]).Items, "Product"); ViewState["Details"] = _details; #endregion if (Session["LogisticsOrderApplyDetail"] != null && (int)ViewState["ID"] == 0) { #region 新费用申请时,初始化申请信 ORD_OrderCartBLL cart = (ORD_OrderCartBLL)Session["LogisticsOrderApplyDetail"]; ORD_OrderApply model = new ORD_OrderApply(); if (cart.Client != 0) { model.OrganizeCity = new CM_ClientBLL(cart.Client).Model.OrganizeCity; model.Client = cart.Client; } model.InsertStaff = (int)Session["UserID"]; model.InsertTime = DateTime.Now; model["IsSpecial"] = cart.IsSpecial.ToString(); model.Type = cart.Type; ViewState["Type"] = cart.Type; model["ProductBrand"] = cart.Brand.ToString(); model["ProductType"] = cart.OrderType.ToString(); if (cart.OrderType != 1) { priceEnable = true; } model.AccountMonth = AC_AccountMonthBLL.GetCurrentMonth(); ORD_OrderLimitFactorBLL limitbll = new ORD_OrderLimitFactorBLL(); ViewState["Limit"] = limitbll.GetLimitInfo(Convert.ToInt32(model.AccountMonth), cart.Client); bt_Submit.Visible = false; foreach (ORD_OrderCart item in cart.Items) { ORD_OrderApplyDetail _detailmodel = new ORD_OrderApplyDetail(); _detailmodel.Price = item.Price; _detailmodel.Product = item.Product; _detailmodel.BookQuantity = item.BookQuantity; _details.Add(_detailmodel); } ViewState["Details"] = _details; pn_OrderApply.BindData(model); BindGrid(); #endregion } else { BindData(); } Header.Attributes["WebPageSubCode"] = "Type=" + ViewState["Type"].ToString(); } }
protected void bt_Save_Click(object sender, EventArgs e) { ORD_OrderCartBLL cart = null; if (Session["LogisticsOrderApplyDetail"] != null) { cart = (ORD_OrderCartBLL)Session["LogisticsOrderApplyDetail"]; } ListTable <ORD_OrderApplyDetail> _details = ViewState["Details"] as ListTable <ORD_OrderApplyDetail>; ORD_OrderApplyBLL bll; if ((int)ViewState["ID"] == 0) { bll = new ORD_OrderApplyBLL(); } else { bll = new ORD_OrderApplyBLL((int)ViewState["ID"]); } pn_OrderApply.GetData(bll.Model); #region 保存明细 foreach (GridViewRow row in gv_ProductList.Rows) { int productid = (int)gv_ProductList.DataKeys[row.RowIndex]["Product"]; ORD_OrderApplyDetail m = _details[productid.ToString()]; PDT_Product product = new PDT_ProductBLL(m.Product).Model; TextBox tbx_price = (TextBox)row.FindControl("tbx_Price"); TextBox tbx_BookQuantity_T = (TextBox)row.FindControl("tbx_BookQuantity_T"); TextBox tbx_BookQuantity = (TextBox)row.FindControl("tbx_BookQuantity"); int quantity = int.Parse(tbx_BookQuantity_T.Text) * product.ConvertFactor + int.Parse(tbx_BookQuantity.Text); m.BookQuantity = quantity; m.Price = decimal.Parse(tbx_price.Text); _details.Update(m); } #endregion if ((int)ViewState["ID"] == 0) { double DelayDays = Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["OrderDelayDays"]); bll.Model.OrganizeCity = cart.OrganizeCity; bll.Model.Client = cart.Client; bll.Model.PublishID = cart.Publish; bll.Model.AccountMonth = AC_AccountMonthBLL.GetMonthByDate(DateTime.Now.AddDays(-DelayDays)); bll.Model.SheetCode = ORD_OrderApplyBLL.GenerateSheetCode(bll.Model.OrganizeCity, bll.Model.AccountMonth); //自动产生备案号 bll.Model.ApproveFlag = 2; bll.Model.State = 1; bll.Model.InsertStaff = (int)Session["UserID"]; bll.Model["IsSpecial"] = cart.IsSpecial.ToString(); bll.Model.Type = cart.Type; bll.Model["ProductBrand"] = cart.Brand.ToString(); bll.Model["ProductType"] = cart.OrderType.ToString(); bll.Items = _details.GetListItem(); ViewState["ID"] = bll.Add(); } else { bll.Model.UpdateStaff = (int)Session["UserID"]; bll.Update(); #region 修改明细 bll.Items = _details.GetListItem(ItemState.Modified); bll.UpdateDetail(); #endregion } if (sender != null) { Response.Redirect("OrderProductApplyDetail.aspx?ID=" + ViewState["ID"].ToString()); } }