protected void bt_In_Click(object sender, EventArgs e) { Save(); CM_Client client = new CM_ClientBLL((int)ViewState["ClientID"]).Model; if (client == null) return; PDT_StandardPriceBLL standardprice = new PDT_StandardPriceBLL((int)ViewState["StandardPrice"]); foreach (GridViewRow row in gv_List_FacProd.Rows) { CheckBox cb_check = (CheckBox)row.FindControl("cb_Check"); if (cb_check.Checked) { PDT_ProductPriceBLL _bll; if ((int)ViewState["PriceID"] != 0) _bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); else return; PDT_ProductPrice_Detail pd = new PDT_ProductPrice_Detail(); pd.PriceID = (int)ViewState["PriceID"]; pd.Product = int.Parse(gv_List_FacProd.DataKeys[row.RowIndex]["ID"].ToString()); #region 将标准价表中的价格设置到价表中 if ((int)ViewState["StandardPrice"] > 0) { PDT_StandardPrice_Detail d = standardprice.Items.FirstOrDefault(p => p.Product == pd.Product); if (d != null) { pd.FactoryPrice = d.FactoryPrice; if (client.ClientType == 3) //门店 { pd.BuyingPrice = d.TradeInPrice; pd.SalesPrice = d.StdPrice; } else if (client.ClientType == 2) { if (client["DIClassify"] == "1") //一级经销商 { pd.BuyingPrice = d.FactoryPrice; pd.SalesPrice = d.TradeInPrice; } else if (client["DIClassify"] == "2") //分销商 { pd.BuyingPrice = d.TradeOutPrice; pd.SalesPrice = d.TradeInPrice; } } } } #endregion _bll.AddDetail(pd); } } Response.Redirect("PDT_ProductPriceDetail2.aspx?PriceID=" + ViewState["PriceID"].ToString()); }
protected void bt_Stop_Click(object sender, EventArgs e) { if ((int)ViewState["PriceID"] > 0) { PDT_ProductPriceBLL bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); bll.Model.EndDate = DateTime.Today.AddMinutes(-1); bll.Model.UpdateStaff = (int)Session["UserID"]; bll.Update(); MessageBox.ShowAndRedirect(this, "价表停用成功!", "PDT_ProductPrice.aspx?ClientID=" + ViewState["ClientID"].ToString()); } }
protected void bt_AddProduct_Click(object sender, EventArgs e) { int product = 0; if (int.TryParse(select_Product.SelectValue, out product) && product > 0) { PDT_Product pdt = new PDT_ProductBLL(product).Model; if (pdt == null) { return; } int quantity = int.Parse(tbx_Q1.Text) * pdt.ConvertFactor + int.Parse(tbx_Q2.Text); DataTable dt = (DataTable)ViewState["DTDetail"]; DataRow[] drs = dt.Select("ID=" + product.ToString()); if (drs.Length > 0) { drs[0]["Quantity"] = quantity; } else { DataRow dr = dt.NewRow(); decimal factoryprice = 0, price = 0; PDT_ProductPriceBLL.GetPriceByClientAndType((int)ViewState["ClientID"], product, (int)ViewState["Type"], out factoryprice, out price); dr["ID"] = product; dr["Code"] = pdt.Code; dr["FullName"] = pdt.FullName; dr["ShortName"] = pdt.ShortName; dr["Brand"] = pdt.Brand; dr["Spec"] = pdt["Spec"]; dr["Classify"] = pdt.Classify; dr["ConvertFactor"] = pdt.ConvertFactor; dr["FactoryPrice"] = factoryprice; dr["Price"] = price; dr["Quantity"] = quantity; try { dr["BrandName"] = new PDT_BrandBLL(pdt.Brand).Model.Name; dr["ClassifyName"] = new PDT_ClassifyBLL(pdt.Classify).Model.Name; dr["TrafficPackaging"] = DictionaryBLL.GetDicCollections("PDT_Packaging")[pdt.TrafficPackaging.ToString()].Name; dr["Packaging"] = DictionaryBLL.GetDicCollections("PDT_Packaging")[pdt.Packaging.ToString()].Name; } catch { } dt.Rows.Add(dr); } BindGrid(); } }
private void Save() { PDT_ProductPriceBLL _bll; if ((int)ViewState["PriceID"] != 0) { _bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); } else { _bll = new PDT_ProductPriceBLL(); } _bll.Model.ApproveFlag = 2; _bll.Model.BeginDate = DateTime.Parse(this.tbx_begin.Text.Trim()); _bll.Model.EndDate = ((DateTime.Parse(this.tbx_end.Text.Trim())).AddDays(1)).AddSeconds(-1); _bll.Model.Client = int.Parse(ViewState["ClientID"].ToString()); if ((int)ViewState["PriceID"] != 0) { _bll.Model.UpdateStaff = int.Parse(Session["UserID"].ToString()); _bll.Update(); #region 修改明细 foreach (GridViewRow row in gv_List.Rows) { int detailid = int.Parse(gv_List.DataKeys[row.RowIndex]["ID"].ToString()); PDT_ProductPrice_Detail item1 = _bll.GetDetailModel(detailid); item1.BuyingPrice = decimal.Parse(((TextBox)row.FindControl("lbl_BuyingPrice")).Text); item1.SalesPrice = decimal.Parse(((TextBox)row.FindControl("lbl_FactoryPrice")).Text); _bll.UpdateDetail(item1); } #endregion } else { _bll.Model.Client = (int)ViewState["ClientID"]; _bll.Model.InsertStaff = int.Parse(Session["UserID"].ToString()); _bll.Add(); ViewState["PriceID"] = _bll.Model.ID; foreach (GridViewRow row in gv_List.Rows) { PDT_ProductPrice_Detail item2 = new PDT_ProductPrice_Detail(); item2.PriceID = _bll.Model.ID; item2.Product = int.Parse(gv_List.DataKeys[row.RowIndex]["Product"].ToString()); item2.BuyingPrice = decimal.Parse(gv_List.DataKeys[row.RowIndex]["BuyingPrice"].ToString()); item2.SalesPrice = decimal.Parse(gv_List.DataKeys[row.RowIndex]["SalesPrice"].ToString()); _bll.AddDetail(item2); } } }
protected void btn_Save_Click(object sender, EventArgs e) { PDT_ProductPriceBLL _bll; if ((int)ViewState["PriceID"] != 0) { _bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); } else { _bll = new PDT_ProductPriceBLL(); } _bll.Model.ApproveFlag = 2; _bll.Model.BeginDate = DateTime.Parse(this.tbx_begin.Text.Trim()); _bll.Model.EndDate = ((DateTime.Parse(this.tbx_end.Text.Trim())).AddDays(1)).AddSeconds(-1); _bll.Model.Client = int.Parse(ViewState["ClientID"].ToString()); _bll.Model.InsertStaff = (int)Session["UserID"]; ListTable <PDT_ProductPrice_Detail> _details = ViewState["Details"] as ListTable <PDT_ProductPrice_Detail>; if ((int)ViewState["PriceID"] != 0) { _bll.Model.UpdateStaff = int.Parse(Session["UserID"].ToString()); _bll.Update(); #region 修改明细 _bll.Items = _details.GetListItem(ItemState.Added); _bll.AddDetail(); foreach (PDT_ProductPrice_Detail _deleted in _details.GetListItem(ItemState.Deleted)) { _bll.DeleteDetail(_deleted.ID); } _bll.Items = _details.GetListItem(ItemState.Modified); _bll.UpdateDetail(); #endregion } else { _bll.Model.Client = (int)ViewState["ClientID"]; _bll.Model.InsertStaff = int.Parse(Session["UserID"].ToString()); _bll.Items = _details.GetListItem(); ViewState["PriceID"] = _bll.Add(); } if (sender != null) { Response.Redirect("PDT_ProductPrice.aspx?ClientID=" + ViewState["ClientID"].ToString()); } }
private void BindData() { PDT_ProductPrice sv = new PDT_ProductPriceBLL((int)ViewState["PriceID"]).Model; ViewState["ClientID"] = sv.Client; ViewState["StandardPrice"] = sv.StandardPrice; if ((int)ViewState["StandardPrice"] > 0) { PDT_StandardPrice s = new PDT_StandardPriceBLL((int)ViewState["StandardPrice"]).Model; if (s != null) { lbl_StandardPrice.Text = s.FullName; } } BindClient(); tbx_begin.Text = sv.BeginDate.ToString("yyyy-MM-dd") == "1900-01-01" ? "" : sv.BeginDate.ToString("yyyy-MM-dd"); tbx_end.Text = sv.EndDate.ToString("yyyy-MM-dd") == "1900-01-01" ? "" : sv.EndDate.ToString("yyyy-MM-dd"); if (sv.ApproveFlag == 1) { tbx_begin.Enabled = false; tbx_end.Enabled = false; gv_List.Columns[0].Visible = false; btn_Save.Visible = false; btn_Delete.Visible = false; tr_tab.Visible = false; lb_ApproveFlag.Text = "已审核"; btn_Approve.Visible = false; if (sv.EndDate < DateTime.Now) { bt_Stop.Visible = false; btn_UnApprove.Visible = false; } } else { bt_Stop.Visible = false; btn_UnApprove.Visible = false; } BindGrid(); }
protected void btn_Save_Click(object sender, EventArgs e) { PDT_ProductPriceBLL _bll; if ((int)ViewState["PriceID"] != 0) _bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); else _bll = new PDT_ProductPriceBLL(); _bll.Model.ApproveFlag = 2; _bll.Model.BeginDate = DateTime.Parse(this.tbx_begin.Text.Trim()); _bll.Model.EndDate = ((DateTime.Parse(this.tbx_end.Text.Trim())).AddDays(1)).AddSeconds(-1); _bll.Model.Client = int.Parse(ViewState["ClientID"].ToString()); _bll.Model.InsertStaff = (int)Session["UserID"]; ListTable<PDT_ProductPrice_Detail> _details = ViewState["Details"] as ListTable<PDT_ProductPrice_Detail>; if ((int)ViewState["PriceID"] != 0) { _bll.Model.UpdateStaff = int.Parse(Session["UserID"].ToString()); _bll.Update(); #region 修改明细 _bll.Items = _details.GetListItem(ItemState.Added); _bll.AddDetail(); foreach (PDT_ProductPrice_Detail _deleted in _details.GetListItem(ItemState.Deleted)) { _bll.DeleteDetail(_deleted.ID); } _bll.Items = _details.GetListItem(ItemState.Modified); _bll.UpdateDetail(); #endregion } else { _bll.Model.Client = (int)ViewState["ClientID"]; _bll.Model.InsertStaff = int.Parse(Session["UserID"].ToString()); _bll.Items = _details.GetListItem(); ViewState["PriceID"] = _bll.Add(); } if (sender != null) Response.Redirect("PDT_ProductPrice.aspx?ClientID=" + ViewState["ClientID"].ToString()); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { #region 获取页面参数 ViewState["PriceID"] = Request.QueryString["PriceID"] == null ? 0 : int.Parse(Request.QueryString["PriceID"]); ViewState["ClientID"] = Request.QueryString["ClientID"] == null ? 0 : int.Parse(Request.QueryString["ClientID"]); ViewState["ClientType"] = Request.QueryString["ClientType"] == null ? 2 : int.Parse(Request.QueryString["ClientType"]); //客户类型,1.办事处 2:经销商,3:终端门店 4.总部 ViewState["StandardPrice"] = Request.QueryString["StandardPrice"] == null ? 0 : int.Parse(Request.QueryString["StandardPrice"]); #endregion BindDropDown(); if ((int)ViewState["PriceID"] != 0)//修改客户价表 { BindData(); } else if ((int)ViewState["ClientID"] > 0 && (int)ViewState["StandardPrice"] > 0) { int priceid = PDT_ProductPriceBLL.CopyFromStandardPrice((int)ViewState["StandardPrice"], (int)ViewState["ClientID"], (int)Session["UserID"]); if (priceid > 0) { MessageBox.ShowAndRedirect(this, "成功从标准价表关联成功!", "PDT_ProductPriceDetail2.aspx?PriceID=" + priceid.ToString()); } else { tbx_begin.Text = DateTime.Now.ToString("yyyy-MM-dd"); tbx_end.Text = DateTime.Now.AddMonths(12).ToString("yyyy-MM-dd"); BindClient(); btn_Delete.Visible = false; btn_Approve.Visible = false; btn_UnApprove.Visible = false; } } else { Response.Redirect("PDT_ProductPrice.aspx"); } } }
private void BindData() { #region 绑定销量头 PDT_ProductPrice sv = new PDT_ProductPriceBLL(int.Parse(ViewState["PriceID"].ToString())).Model; ViewState["ClientID"] = sv.Client; BindClient(); tbx_begin.Text = sv.BeginDate.ToString("yyyy-MM-dd") == "1900-01-01" ? "" : sv.BeginDate.ToString("yyyy-MM-dd"); tbx_end.Text = sv.EndDate.ToString("yyyy-MM-dd") == "1900-01-01" ? "" : sv.EndDate.ToString("yyyy-MM-dd"); #endregion if (sv.ApproveFlag == 1) { //已审核 tr_AddProduct.Visible = false; btn_Save.Visible = false; btn_Approve.Visible = false; btn_Delete.Visible = false; gv_List.Columns[0].Visible = false; gv_List.Columns[gv_List.Columns.Count - 1].Visible = false; } }
protected void bt_Out_Click(object sender, EventArgs e) { foreach (GridViewRow row in gv_List.Rows) { CheckBox cb_check = (CheckBox)row.FindControl("cb_Check"); if (cb_check.Checked) { PDT_ProductPriceBLL _bll; if ((int)ViewState["PriceID"] != 0) { _bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); } else { return; } _bll.DeleteDetail(int.Parse(gv_List.DataKeys[row.RowIndex]["ID"].ToString())); } } Response.Redirect("PDT_ProductPriceDetail2.aspx?PriceID=" + ViewState["PriceID"].ToString()); }
protected void bt_AddProduct_Click(object sender, EventArgs e) { SVM_InventoryBLL bll = new SVM_InventoryBLL((int)ViewState["InventoryID"]); int product = 0; if (int.TryParse(select_Product.SelectValue, out product) && product > 0) { PDT_Product pdt = new PDT_ProductBLL(product).Model; if (pdt == null) { return; } int quantity = int.Parse(tbx_Q1.Text) * pdt.ConvertFactor + int.Parse(tbx_Q2.Text); if (quantity == 0) { return; } SVM_Inventory_Detail _detail = bll.Items.FirstOrDefault(m => m.Product == product); if (_detail == null) { _detail = new SVM_Inventory_Detail(); decimal factoryprice = 0, price = 0; PDT_ProductPriceBLL.GetPriceByClientAndType((int)ViewState["ClientID"], product, 2, out factoryprice, out price); _detail.FactoryPrice = factoryprice; _detail.Product = pdt.ID; _detail.Quantity = quantity; _detail.InventoryID = (int)ViewState["InventoryID"]; bll.AddDetail(_detail); } else { _detail.Quantity = quantity; bll.UpdateDetail(_detail); } BindGrid(); } }
protected void btn_Add_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(select_Client.SelectValue)) { MessageBox.Show(this, "请先选择要添加价表的客户!"); } else { if (ddl_StandardPrice.SelectedValue == "0") { MessageBox.Show(this, "请先选择标准价表!"); return; } #region 判断当前是否已有有效的价表 string condition = " PDT_ProductPrice.Client = " + select_Client.SelectValue + " AND GETDATE() BETWEEN PDT_ProductPrice.BeginDate AND PDT_ProductPrice.EndDate "; if (PDT_ProductPriceBLL.GetModelList(condition).Count > 0) { MessageBox.Show(this, "对不起,当前客户在当前有效期内已有一个价表,您可以在原价表基础上修改,而不要重复添加价表!"); return; } #endregion Response.Redirect("PDT_ProductPriceDetail2.aspx?ClientID=" + select_Client.SelectValue + "&ClientType=" + ViewState["ClientType"].ToString() + "&StandardPrice=" + ddl_StandardPrice.SelectedValue); } }
protected void bt_In_Click(object sender, EventArgs e) { Save(); CM_Client client = new CM_ClientBLL((int)ViewState["ClientID"]).Model; if (client == null) { return; } PDT_StandardPriceBLL standardprice = new PDT_StandardPriceBLL((int)ViewState["StandardPrice"]); foreach (GridViewRow row in gv_List_FacProd.Rows) { CheckBox cb_check = (CheckBox)row.FindControl("cb_Check"); if (cb_check.Checked) { PDT_ProductPriceBLL _bll; if ((int)ViewState["PriceID"] != 0) { _bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); } else { return; } PDT_ProductPrice_Detail pd = new PDT_ProductPrice_Detail(); pd.PriceID = (int)ViewState["PriceID"]; pd.Product = int.Parse(gv_List_FacProd.DataKeys[row.RowIndex]["ID"].ToString()); #region 将标准价表中的价格设置到价表中 if ((int)ViewState["StandardPrice"] > 0) { PDT_StandardPrice_Detail d = standardprice.Items.FirstOrDefault(p => p.Product == pd.Product); if (d != null) { pd.FactoryPrice = d.FactoryPrice; if (client.ClientType == 3) //门店 { pd.BuyingPrice = d.TradeInPrice; pd.SalesPrice = d.StdPrice; } else if (client.ClientType == 2) { if (client["DIClassify"] == "1") //一级经销商 { pd.BuyingPrice = d.FactoryPrice; pd.SalesPrice = d.TradeInPrice; } else if (client["DIClassify"] == "2") //分销商 { pd.BuyingPrice = d.TradeOutPrice; pd.SalesPrice = d.TradeInPrice; } } } } #endregion _bll.AddDetail(pd); } } Response.Redirect("PDT_ProductPriceDetail2.aspx?PriceID=" + ViewState["PriceID"].ToString()); }
protected void bt_Out_Click(object sender, EventArgs e) { foreach (GridViewRow row in gv_List.Rows) { CheckBox cb_check = (CheckBox)row.FindControl("cb_Check"); if (cb_check.Checked) { PDT_ProductPriceBLL _bll; if ((int)ViewState["PriceID"] != 0) _bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); else return; _bll.DeleteDetail(int.Parse(gv_List.DataKeys[row.RowIndex]["ID"].ToString())); } } Response.Redirect("PDT_ProductPriceDetail2.aspx?PriceID=" + ViewState["PriceID"].ToString()); }
private void Save() { PDT_ProductPriceBLL _bll; if ((int)ViewState["PriceID"] != 0) _bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); else _bll = new PDT_ProductPriceBLL(); _bll.Model.ApproveFlag = 2; _bll.Model.BeginDate = DateTime.Parse(this.tbx_begin.Text.Trim()); _bll.Model.EndDate = ((DateTime.Parse(this.tbx_end.Text.Trim())).AddDays(1)).AddSeconds(-1); _bll.Model.Client = int.Parse(ViewState["ClientID"].ToString()); if ((int)ViewState["PriceID"] != 0) { _bll.Model.UpdateStaff = int.Parse(Session["UserID"].ToString()); _bll.Update(); #region 修改明细 foreach (GridViewRow row in gv_List.Rows) { int detailid = int.Parse(gv_List.DataKeys[row.RowIndex]["ID"].ToString()); PDT_ProductPrice_Detail item1 = _bll.GetDetailModel(detailid); item1.BuyingPrice = decimal.Parse(((TextBox)row.FindControl("lbl_BuyingPrice")).Text); item1.SalesPrice = decimal.Parse(((TextBox)row.FindControl("lbl_FactoryPrice")).Text); _bll.UpdateDetail(item1); } #endregion } else { _bll.Model.Client = (int)ViewState["ClientID"]; _bll.Model.InsertStaff = int.Parse(Session["UserID"].ToString()); _bll.Add(); ViewState["PriceID"] = _bll.Model.ID; foreach (GridViewRow row in gv_List.Rows) { PDT_ProductPrice_Detail item2 = new PDT_ProductPrice_Detail(); item2.PriceID = _bll.Model.ID; item2.Product = int.Parse(gv_List.DataKeys[row.RowIndex]["Product"].ToString()); item2.BuyingPrice = decimal.Parse(gv_List.DataKeys[row.RowIndex]["BuyingPrice"].ToString()); item2.SalesPrice = decimal.Parse(gv_List.DataKeys[row.RowIndex]["SalesPrice"].ToString()); _bll.AddDetail(item2); } } }
private void BindGrid() { if (MCSTabControl1.SelectedIndex == 0) { tr1.Visible = false; tr_Product.Visible = true; string condition = " 1 = 1 "; if (ddl_Brand.SelectedValue != "0") { if (ddl_Classify.SelectedValue == "0") { condition = " Brand =" + ddl_Brand.SelectedValue; } else { condition = " Classify =" + ddl_Classify.SelectedValue; } } condition += " ORDER BY PDT_Product.Code"; PDT_ProductPriceBLL bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); gv_List.BindGrid(bll.GetDetail(condition)); } else { tr1.Visible = true; tr_Product.Visible = false; //获取非价表产品列表 string condition = "State = 1 AND ID NOT IN (SELECT Product FROM MCS_Pub.dbo.PDT_ProductPrice_Detail WHERE PriceID=" + ViewState["PriceID"].ToString() + ")"; if (ddl_Brand.SelectedValue == "0") { condition += " AND Brand in (SELECT ID FROM PDT_Brand WHERE IsOpponent in ('1'))"; } else { if (ddl_Classify.SelectedValue == "0") { condition += " AND Brand =" + ddl_Brand.SelectedValue; } else { condition += " AND Classify =" + ddl_Classify.SelectedValue; } } if ((int)ViewState["StandardPrice"] != 0) { condition += " AND ID IN (SELECT Product FROM MCS_Pub.dbo.PDT_StandardPrice_Detail WHERE StandardPrice=" + ViewState["StandardPrice"].ToString() + ")"; } IList <PDT_Product> products = PDT_ProductBLL.GetModelList(condition); gv_List_FacProd.BindGrid <PDT_Product>(products); } cb_SelectAll.Checked = false; }
protected void bt_Stop_Click(object sender, EventArgs e) { if ((int)ViewState["PriceID"] > 0) { PDT_ProductPriceBLL bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); bll.Model.EndDate = DateTime.Today.AddMinutes(-1); bll.Model.UpdateStaff = (int)Session["UserID"]; bll.Update(); MessageBox.ShowAndRedirect(this, "价表停用成功!", "PDT_ProductPrice.aspx?ClientID=" + ViewState["ClientID"].ToString()); } }
private void BindData() { ORD_OrderCartBLL cart = (ORD_OrderCartBLL)Session["LogisticsOrderApplyDetail"]; ORD_ApplyPublishBLL publish = new ORD_ApplyPublishBLL(cart.Publish); if (publish == null) Response.Redirect("OrderApplyDetail0.aspx"); ViewState["Publish"] = cart.Publish; pl_ApplyPublish.BindData(publish.Model); IList<ORD_ApplyPublishDetail> productlists; if (cart.Type == 1) { #region 成品取客户价表 productlists = new List<ORD_ApplyPublishDetail>(); IList<PDT_ProductPrice> pricelists = PDT_ProductPriceBLL.GetModelList ("GETDATE() BETWEEN BeginDate AND EndDate AND Client=" + cart.Client.ToString()); if (pricelists.Count == 0) { MessageBox.ShowAndRedirect(this, "对不起,该客户没有生效的价表,不可申请产品!", "OrderApplyDetail0.aspx"); return; } PDT_ProductPriceBLL pricebll = new PDT_ProductPriceBLL(pricelists[0].ID); foreach (ORD_ApplyPublishDetail item in publish.Items) { PDT_ProductBLL _bll = new PDT_ProductBLL(item.Product); if (new PDT_BrandBLL(_bll.Model.Brand).Model.IsOpponent == "1") { PDT_ProductPrice_Detail priceitem = pricebll.Items.FirstOrDefault(p => p.Product == item.Product); if (priceitem == null) continue; item.Price = priceitem.BuyingPrice; } else { item.Price = _bll.Model.FactoryPrice; } productlists.Add(item); } #endregion } else { #region 绑定赠品申请预算信息 BindBudgetInfo(cart.OrganizeCity, cart.AccountMonth, cart.Client, cart.GiftFeeType, cart.Brand, cart.GiftClassify,cart.Receiver); tb_GiftBudgetInfo.Visible = true; #endregion productlists = publish.Items; } ViewState["PublishDetails"] = productlists; gv_List.PageIndex = 0; BindGrid(); lb_CartCount.Text = cart.Items.Count.ToString(); }
private void BindData() { ORD_OrderCartBLL cart = (ORD_OrderCartBLL)Session["LogisticsOrderApplyDetail"]; ORD_ApplyPublishBLL publish = new ORD_ApplyPublishBLL(cart.Publish); if (publish == null) { Response.Redirect("OrderApplyDetail0.aspx"); } ViewState["Publish"] = cart.Publish; pl_ApplyPublish.BindData(publish.Model); IList <ORD_ApplyPublishDetail> productlists; if (cart.Type == 1) { #region 成品取客户价表 productlists = new List <ORD_ApplyPublishDetail>(); IList <PDT_ProductPrice> pricelists = PDT_ProductPriceBLL.GetModelList ("GETDATE() BETWEEN BeginDate AND EndDate AND Client=" + cart.Client.ToString()); if (pricelists.Count == 0) { MessageBox.ShowAndRedirect(this, "对不起,该客户没有生效的价表,不可申请产品!", "OrderApplyDetail0.aspx"); return; } PDT_ProductPriceBLL pricebll = new PDT_ProductPriceBLL(pricelists[0].ID); foreach (ORD_ApplyPublishDetail item in publish.Items) { PDT_ProductBLL _bll = new PDT_ProductBLL(item.Product); if (new PDT_BrandBLL(_bll.Model.Brand).Model.IsOpponent == "1") { PDT_ProductPrice_Detail priceitem = pricebll.Items.FirstOrDefault(p => p.Product == item.Product); if (priceitem == null) { continue; } item.Price = priceitem.BuyingPrice; } else { item.Price = _bll.Model.FactoryPrice; } productlists.Add(item); } #endregion } else { #region 绑定赠品申请预算信息 BindBudgetInfo(cart.OrganizeCity, cart.AccountMonth, cart.Client, cart.GiftFeeType, cart.Brand, cart.GiftClassify, cart.Receiver); tb_GiftBudgetInfo.Visible = true; #endregion productlists = publish.Items; } ViewState["PublishDetails"] = productlists; gv_List.PageIndex = 0; BindGrid(); lb_CartCount.Text = cart.Items.Count.ToString(); }
private void BindGrid() { if (MCSTabControl1.SelectedIndex == 0) { tr1.Visible = false; tr_Product.Visible = true; string condition = " 1 = 1 "; if (ddl_Brand.SelectedValue != "0") { if (ddl_Classify.SelectedValue == "0") condition = " Brand =" + ddl_Brand.SelectedValue; else condition = " Classify =" + ddl_Classify.SelectedValue; } condition += " ORDER BY PDT_Product.Code"; PDT_ProductPriceBLL bll = new PDT_ProductPriceBLL((int)ViewState["PriceID"]); gv_List.BindGrid(bll.GetDetail(condition)); } else { tr1.Visible = true; tr_Product.Visible = false; //获取非价表产品列表 string condition = "State = 1 AND ID NOT IN (SELECT Product FROM MCS_Pub.dbo.PDT_ProductPrice_Detail WHERE PriceID=" + ViewState["PriceID"].ToString() + ")"; if (ddl_Brand.SelectedValue == "0") condition += " AND Brand in (SELECT ID FROM PDT_Brand WHERE IsOpponent in ('1'))"; else { if (ddl_Classify.SelectedValue == "0") condition += " AND Brand =" + ddl_Brand.SelectedValue; else condition += " AND Classify =" + ddl_Classify.SelectedValue; } if ((int)ViewState["StandardPrice"] != 0) condition += " AND ID IN (SELECT Product FROM MCS_Pub.dbo.PDT_StandardPrice_Detail WHERE StandardPrice=" + ViewState["StandardPrice"].ToString() + ")"; IList<PDT_Product> products = PDT_ProductBLL.GetModelList(condition); gv_List_FacProd.BindGrid<PDT_Product>(products); } cb_SelectAll.Checked = false; }
private string DoImportProduct(Worksheet worksheet, int accountmonth, int insertstaff, int cloumn, IList <PDT_Product> productlists, out int State) { string ImportInfo = ""; AC_AccountMonth month = new AC_AccountMonthBLL(accountmonth).Model; DateTime minday = month.BeginDate; DateTime maxday = DateTime.Today < month.EndDate ? DateTime.Today : month.EndDate; State = 0; tbx_Msg.AppendText("\r\n"); tbx_Msg.AppendText("-------------------------------------------------------------------------\r\n"); tbx_Msg.AppendText("----批量导入客户进货----\r\n+----批量导入客户销量----\r\nID号 门店类型 门店名 导购员 错误原因\r\n"); #region 读取Excel表格 int row = 1; int emptyrow = 0; int _cloumn = 0; while (true) { _cloumn = cloumn; row++; if (((Range)worksheet.Cells[row, 1]).Value2 == null) { emptyrow++; if (emptyrow > 5) { break; } else { continue; } } int clientid = 0; int promotorid = 0; if (!int.TryParse(((Range)worksheet.Cells[row, 1]).Value2.ToString(), out clientid)) { continue; } if (cloumn == 8 && ((Range)worksheet.Cells[row, 6]).Value2 != null && !int.TryParse(((Range)worksheet.Cells[row, 6]).Value2.ToString(), out promotorid)) { continue; } #region 验证数据 CM_Client client = new CM_ClientBLL(clientid).Model; if (client == null || client.FullName != ((Range)worksheet.Cells[row, 3]).Text.ToString()) { tbx_Msg.AppendText("ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",零售商ID与零售商名称" : ",分销商ID与分销商名称") + "不匹配!\r\n"); State = 4; continue; } int uplimit = client.ClientType == 3 ? 5000 : 9000; if (((Range)worksheet.Cells[row, 5]).Text.ToString() != month.Name) { tbx_Msg.AppendText("ID号:" + clientid.ToString() + ",归属月份必须为【" + month.Name + "】\r\n"); State = 4; continue; } #endregion #region 组织销量头 SVM_SalesVolumeBLL bll = null; string conditon = ""; if (cloumn == 6) { conditon = "Client=" + clientid.ToString() + " AND Type IN(1,2) AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd") + " AND Flag=1 " + " AND Remark='" + tbx_Remark.Text + "'"; } else { conditon = "Supplier=" + clientid.ToString() + " AND Type=3 AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd") + " AND Flag=1 AND ISNULL(Promotor,0)=" + promotorid.ToString() + " AND Remark='" + tbx_Remark.Text + "'"; } IList <SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList(conditon); if (svmlists.Count > 0) { tbx_Msg.AppendText("行号:" + row.ToString() + ",ID号:" + ((Range)worksheet.Cells[row, 1]).Text.ToString() + client.FullName + " 当月的销量单已导入!\r\n"); continue; } if (bll == null) { bll = new SVM_SalesVolumeBLL(); if (cloumn == 8) { bll.Model.Client = 0; bll.Model.Supplier = client.ID; bll.Model.Promotor = promotorid; bll.Model.Type = 3; } else { bll.Model.Client = clientid; bll.Model.Supplier = client.Supplier; bll.Model.Type = 2; } bll.Model.OrganizeCity = client.OrganizeCity; bll.Model.AccountMonth = month.ID; bll.Model.SalesDate = maxday; bll.Model.ApproveFlag = 2; bll.Model.Flag = 1; //成品销售 bll.Model["IsCXP"] = "N"; bll.Model.InsertStaff = insertstaff; bll.Model.Remark = tbx_Remark.Text; bll.Model["DataSource"] = tbx_DataSource.Text; //6:导购销售拆分 7:补录销量 } #endregion bll.Model["SubmitFlag"] = "1"; #region 读取各产品销量 IList <SVM_SalesVolume_Detail> details = new List <SVM_SalesVolume_Detail>(); bool wrongflag = false;//判断导入数量是否正常(除空导致的异常) int quantity = 0; foreach (PDT_Product product in productlists) { if (((Range)worksheet.Cells[row, _cloumn]).Value2 != null) { int.TryParse(((Range)worksheet.Cells[row, _cloumn]).Value2.ToString(), out quantity); if (quantity != 0 && quantity <= uplimit && quantity >= 0) { decimal factoryprice = 0, salesprice = 0; PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, cloumn == 8 ? 3 : 2, out factoryprice, out salesprice); if (factoryprice == 0) { factoryprice = product.FactoryPrice; } if (salesprice == 0) { salesprice = product.NetPrice; } SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail(); detail.Product = product.ID; detail.FactoryPrice = factoryprice; detail.SalesPrice = salesprice; detail.Quantity = quantity; details.Add(detail); } else if (trim(((Range)worksheet.Cells[row, _cloumn]).Text.ToString()) != "" && ((Range)worksheet.Cells[row, _cloumn]).Text.ToString() != "0") { wrongflag = true; break; } else if (quantity < 0) { wrongflag = true; break; } } _cloumn++; } if (wrongflag) { tbx_Msg.AppendText("行号:" + row.ToString() + ",ID号:" + clientid.ToString() + (client.ClientType == 3 ? "," + ((Range)worksheet.Cells[row, 4]).Text + ":" : ",分销商:") + client.FullName + (client.ClientType == 3 ? "" : ",该分销商") + (cloumn == 6 ? "当月的进货单" : ",导购:" + ((Range)worksheet.Cells[row, 7]).Text.ToString() + " 当月的销量单") + "未能导入!产品名称:" + ((Range)worksheet.Cells[1, _cloumn]).Text + "数量填写错误。\r\n"); State = 4; continue; } #endregion #region 更新销量至数据库 if (bll.Model.ID > 0) { //if (details.Count > 0) //{ // bll.DeleteDetail(); //先清除原先导入的数据 // bll.Items = details; // bll.Model.UpdateStaff = insertstaff; // bll.AddDetail(); // bll.Update(); // tbx_Msg.AppendText("<span style='color:Blue'>ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",该零售商:" : ",该分销商:") + client.FullName // + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + (cloumn == 6 ? " 的进货单" : "的销量单") + "被成功更新!产品SKU数:" // + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n"); //} } else { if (details.Count > 0) //没有产品也新增一条空销量头 { bll.Items = details; if (bll.Add() > 0) { tbx_Msg.AppendText("行号:" + row.ToString() + ",ID号:" + clientid.ToString() + (client.ClientType == 3 ? ",该零售商:" : ",该分销商:") + client.FullName + (cloumn == 6 ? " 的进货单" : "的销量单") + "已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n"); tbx_Msg.Focus(); tbx_Msg.Select(tbx_Msg.TextLength, 0); tbx_Msg.ScrollToCaret(); } } } #endregion } #endregion return(ImportInfo); }
private void BindData() { #region 绑定销量头 PDT_ProductPrice sv = new PDT_ProductPriceBLL(int.Parse(ViewState["PriceID"].ToString())).Model; ViewState["ClientID"] = sv.Client; BindClient(); tbx_begin.Text = sv.BeginDate.ToString("yyyy-MM-dd") == "1900-01-01" ? "" : sv.BeginDate.ToString("yyyy-MM-dd"); tbx_end.Text = sv.EndDate.ToString("yyyy-MM-dd") == "1900-01-01" ? "" : sv.EndDate.ToString("yyyy-MM-dd"); #endregion if (sv.ApproveFlag == 1) { //已审核 tr_AddProduct.Visible = false; btn_Save.Visible = false; btn_Approve.Visible = false; btn_Delete.Visible = false; gv_List.Columns[0].Visible = false; gv_List.Columns[gv_List.Columns.Count - 1].Visible = false; } }
private void BindData() { PDT_ProductPrice sv = new PDT_ProductPriceBLL((int)ViewState["PriceID"]).Model; ViewState["ClientID"] = sv.Client; ViewState["StandardPrice"] = sv.StandardPrice; if ((int)ViewState["StandardPrice"] > 0) { PDT_StandardPrice s = new PDT_StandardPriceBLL((int)ViewState["StandardPrice"]).Model; if (s != null) lbl_StandardPrice.Text = s.FullName; } BindClient(); tbx_begin.Text = sv.BeginDate.ToString("yyyy-MM-dd") == "1900-01-01" ? "" : sv.BeginDate.ToString("yyyy-MM-dd"); tbx_end.Text = sv.EndDate.ToString("yyyy-MM-dd") == "1900-01-01" ? "" : sv.EndDate.ToString("yyyy-MM-dd"); if (sv.ApproveFlag == 1) { tbx_begin.Enabled = false; tbx_end.Enabled = false; gv_List.Columns[0].Visible = false; btn_Save.Visible = false; btn_Delete.Visible = false; tr_tab.Visible = false; lb_ApproveFlag.Text = "已审核"; btn_Approve.Visible = false; if (sv.EndDate < DateTime.Now) { bt_Stop.Visible = false; btn_UnApprove.Visible = false; } } else { bt_Stop.Visible = false; btn_UnApprove.Visible = false; } BindGrid(); }
protected void bt_Import_Click(object sender, EventArgs e) { string ImportInfo = ""; lb_ErrorInfo.Text = ""; System.Data.DataTable dtSellIn = null, dtSellOut = null; if (Session["DataTable-SellIn"] != null && Session["DataTable-SellOut"] != null) { dtSellIn = (System.Data.DataTable)Session["DataTable-SellIn"]; dtSellOut = (System.Data.DataTable)Session["DataTable-SellOut"]; } #region 获取允许最迟的销量日期 int JXCDelayDays = ConfigHelper.GetConfigInt("JXCDelayDays"); AC_AccountMonth month = new AC_AccountMonthBLL(AC_AccountMonthBLL.GetMonthByDate(DateTime.Now.AddDays(-JXCDelayDays))).Model; DateTime minday = month.BeginDate; DateTime maxday = DateTime.Today < month.EndDate ? DateTime.Today : month.EndDate; #endregion IList <PDT_Product> productlists = PDT_ProductBLL.GetModelList("Brand IN (SELECT ID FROM dbo.PDT_Brand WHERE IsOpponent='1') AND State=1 AND ApproveFlag=1 ORDER BY ISNULL(SubUnit,999999),Code"); ImportInfo += "<span style='color: Red'>-------------------------------------------------------------------------</span><br/>"; ImportInfo += "<span style='color: Red'>----批量导入零售商进货销量----</span><br/>"; #region 开始导入零售商进货 foreach (System.Data.DataRow dr in dtSellIn.Rows) { #region 验证数据 int clientid = (int)dr["零售商ID"]; CM_Client client = new CM_ClientBLL(clientid).Model; if (client == null || client.FullName != (string)dr["零售商名称"]) { ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",零售商ID与零售商名称不匹配!</span><br/>"; continue; } if (dr["归属月份"].ToString() != month.Name) { ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",归属月份必须为【" + month.Name + "】</span><br/>"; continue; } //DateTime salesdate = (DateTime)dr["进货日期"]; //if (salesdate < minday || salesdate > maxday) //{ // ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",进货日期必须在" + minday.ToString("yyyy-MM-dd") + // "至" + maxday.ToString("yyyy-MM-dd") + "之间!</span><br/>"; // continue; //} #endregion #region 组织销量头 SVM_SalesVolumeBLL bll = null; IList <SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList("Client=" + clientid.ToString() + " AND Type=2 AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd") + " AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',1)='N' "); if (svmlists.Count > 0) { if (svmlists[0].ApproveFlag == 1) { ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",该零售商当月的进货已审核,不可再次导入!</span><br/>"; continue; } bll = new SVM_SalesVolumeBLL(svmlists[0].ID); bll.Items.Clear(); } else { bll = new SVM_SalesVolumeBLL(); bll.Model.Client = clientid; bll.Model.OrganizeCity = client.OrganizeCity; bll.Model.Supplier = client.Supplier; bll.Model.AccountMonth = month.ID; bll.Model.SalesDate = maxday; bll.Model.Type = 2; bll.Model.ApproveFlag = 2; bll.Model.Flag = 1; //成品销售 bll.Model["SubmitFlag"] = "1"; bll.Model["IsCXP"] = "N"; bll.Model.InsertStaff = (int)Session["UserID"]; bll.Model.Remark = "Excel批量导入"; } #endregion #region 读取各产品销量 IList <SVM_SalesVolume_Detail> details = new List <SVM_SalesVolume_Detail>(); foreach (PDT_Product product in productlists) { int quantity = (int)dr["[" + product.ShortName + "]"]; if (quantity != 0) { decimal factoryprice = 0, salesprice = 0; PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 2, out factoryprice, out salesprice); if (factoryprice == 0) { factoryprice = product.FactoryPrice; } if (salesprice == 0) { salesprice = product.NetPrice; } SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail(); detail.Product = product.ID; detail.FactoryPrice = factoryprice; detail.SalesPrice = salesprice; detail.Quantity = quantity; details.Add(detail); } } #endregion #region 更新销量至数据库 if (bll.Model.ID > 0) { if (details.Count > 0) { bll.DeleteDetail(); //先清除原先导入的数据 bll.Items = details; bll.AddDetail(); bll.Update(); ImportInfo += "<span style='color: Blue'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + " 的进货单被成功更新!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>"; } } else { //if (details.Count > 0) //没有产品也新增一条空销量头 { bll.Items = details; bll.Add(); ImportInfo += "<span style='color: Black'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName + " 的进货单已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>"; } } #endregion } #endregion ImportInfo += "<br/><br/>"; ImportInfo += "<span style='color: Red'>-------------------------------------------------------------------------</span><br/>"; ImportInfo += "<span style='color: Red'>----批量导入零售商销货销量----</span><br/>"; #region 开始导入零售商销货 foreach (System.Data.DataRow dr in dtSellOut.Rows) { #region 验证数据 int clientid = (int)dr["零售商ID"]; CM_Client client = new CM_ClientBLL(clientid).Model; if (client == null || client.FullName != (string)dr["零售商名称"]) { ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",零售商ID与零售商名称不匹配!</span><br/>"; continue; } if (dr["归属月份"].ToString() != month.Name) { ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",归属月份必须为【" + month.Name + "】</span><br/>"; continue; } //DateTime salesdate = (DateTime)dr["销售日期"]; //if (salesdate < minday || salesdate > maxday) //{ // ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",销售日期必须在" + minday.ToString("yyyy-MM-dd") + // "至" + maxday.ToString("yyyy-MM-dd") + "之前!</span><br/>"; // continue; //} int promotorid = (int)dr["导购ID"]; if (promotorid > 0) { if (PM_PromotorInRetailerBLL.GetModelList("Client=" + client.ID.ToString() + " AND Promotor=" + promotorid.ToString()).Count == 0) { ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",零售商中没有关联该导购员!</span><br/>"; continue; } } #endregion #region 组织销量头 SVM_SalesVolumeBLL bll = null; IList <SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList("Supplier=" + clientid.ToString() + " AND Type=3 AND AccountMonth=" + month.ID.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd") + " AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',1)='N' AND ISNULL(Promotor,0)=" + promotorid.ToString()); if (svmlists.Count > 0) { if (svmlists[0].ApproveFlag == 1) { ImportInfo += "<span style='color: Red'>序号:" + dr["序号"].ToString() + ",该零售商当月的销量已审核,不可再次导入!</span><br/>"; continue; } bll = new SVM_SalesVolumeBLL(svmlists[0].ID); bll.Model["SubmitFlag"] = "1"; bll.Items.Clear(); } else { bll = new SVM_SalesVolumeBLL(); bll.Model.Client = 0; bll.Model.OrganizeCity = client.OrganizeCity; bll.Model.Supplier = client.ID; bll.Model.Promotor = promotorid; bll.Model.AccountMonth = month.ID; bll.Model.SalesDate = maxday; bll.Model.Type = 3; bll.Model.ApproveFlag = 2; bll.Model.Flag = 1; //成品销售 bll.Model["SubmitFlag"] = "1"; bll.Model["IsCXP"] = "N"; bll.Model.InsertStaff = (int)Session["UserID"]; bll.Model.Remark = "Excel批量导入"; } #endregion #region 读取各产品销量 IList <SVM_SalesVolume_Detail> details = new List <SVM_SalesVolume_Detail>(); foreach (PDT_Product product in productlists) { int quantity = (int)dr["[" + product.ShortName + "]"]; if (quantity != 0) { decimal factoryprice = 0, salesprice = 0; PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 3, out factoryprice, out salesprice); if (factoryprice == 0) { factoryprice = product.FactoryPrice; } if (salesprice == 0) { salesprice = product.StdPrice; } SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail(); detail.Product = product.ID; detail.FactoryPrice = factoryprice; detail.SalesPrice = salesprice; detail.Quantity = quantity; details.Add(detail); } } #endregion #region 更新销量至数据库 if (bll.Model.ID > 0) { if (details.Count > 0) { bll.DeleteDetail(); //先清除原先导入的数据 bll.Items = details; bll.AddDetail(); bll.Update(); ImportInfo += "<span style='color: Blue'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + " 的销量单被成功更新!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>"; } } else { //if (details.Count > 0) //没有产品也新增一条空销量头 { bll.Items = details; bll.Add(); ImportInfo += "<span style='color: Black'>序号:" + dr["序号"].ToString() + ",零售商:" + client.FullName + " 的销量单已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "</span><br/>"; } } #endregion } #endregion lb_ErrorInfo.Text = ImportInfo; bt_Import.Enabled = false; Session["DataTable-SellIn"] = null; Session["DataTable-SellOut"] = null; }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { DateTime minday, maxday = DateTime.Now; HSSFWorkbook hssfworkbook; FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite); hssfworkbook = new HSSFWorkbook(file); ISheet sheet = hssfworkbook.GetSheetAt(0); System.Collections.IEnumerator rows = sheet.GetRowEnumerator(); int i = 0, count = getRowsCount() - 1; bool flag = true; try { IRow headerRow = sheet.GetRow(0); if (headerRow.GetCell(0).ToString() != "零售商ID" || headerRow.GetCell(1).ToString() != "零售商编号" || headerRow.GetCell(2).ToString() != "零售商名称" || headerRow.GetCell(3).ToString() != "零售商分类" || headerRow.GetCell(4).ToString() != "归属月份" || headerRow.GetCell(5).ToString() != "导购ID" || headerRow.GetCell(6).ToString() != "导购姓名") { flag = false; } if (!flag) { MessageBox.Show(this, "表头(1~7列)错误!"); return; } int column = getColumnCount(headerRow) + 1; int month = 0; rows.MoveNext(); while (rows.MoveNext()) { int datacolumn = 7; i++; HSSFRow row = (HSSFRow)rows.Current; if (row.GetCell(0).ToString() == "") { break; } int clientid = 0; int promotorid = 0; if (!int.TryParse(row.GetCell(0).ToString(), out clientid)) { errormessage += "零售商:" + row.GetCell(2).ToString() + "的ID错误;\r\n"; row.GetCell(column).SetCellValue(errormessage); continue; } CM_Client client = new CM_ClientBLL(clientid).Model; if (client == null) { errormessage += "ID号:" + clientid.ToString() + "零售商在系统中不存在!\r\n"; row.GetCell(column).SetCellValue(errormessage); continue; } if (int.TryParse(row.GetCell(5).ToString(), out promotorid)) { PM_Promotor pm = new PM_PromotorBLL(promotorid).Model; if (pm == null) { errormessage += "导购ID号:" + promotorid.ToString() + "导购在系统中不存在!\r\n"; row.GetCell(column).SetCellValue(errormessage); continue; } } if (month == 0 && headerRow.GetCell(4).ToString() == "归属月份") { IList <AC_AccountMonth> _monthlist = AC_AccountMonthBLL.GetModelList("Name='" + row.GetCell(4).ToString() + "'"); if (_monthlist.Count > 0) { month = _monthlist[0].ID; minday = _monthlist[0].BeginDate; maxday = DateTime.Today < _monthlist[0].EndDate ? DateTime.Today : _monthlist[0].EndDate; } else { errormessage += "会计月错误;\r\n"; row.GetCell(column).SetCellValue(errormessage); continue; } } #region 组织销量头 SVM_SalesVolumeBLL bll = null; string conditon = ""; conditon = "Supplier=" + clientid.ToString() + "AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',4)='7' AND Type=3 AND AccountMonth=" + month.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd") + " AND Flag=1 AND ISNULL(Promotor,0)=" + promotorid.ToString(); IList <SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList(conditon); if (svmlists.Count > 0) { if (svmlists.FirstOrDefault(p => p.ApproveFlag == 1) != null) { errormessage += "ID号:" + row.GetCell(0).ToString() + "," + client.FullName + ",导购:" + row.GetCell(6).ToString() + " 当月的销量单" + "已审核,不可再次导入!\r\n"; row.GetCell(column).SetCellValue(errormessage); continue; } if (svmlists.Count == 1) { bll = new SVM_SalesVolumeBLL(svmlists[0].ID); bll.Items.Clear(); } } if (bll == null) { bll = new SVM_SalesVolumeBLL(); bll.Model.Client = 0; bll.Model.Supplier = client.ID; bll.Model.Promotor = promotorid; bll.Model.Type = 3; bll.Model.OrganizeCity = client.OrganizeCity; bll.Model.AccountMonth = month; bll.Model.SalesDate = maxday; bll.Model.ApproveFlag = 2; bll.Model.Flag = 1; //成品销售 bll.Model["IsCXP"] = "N"; bll.Model.InsertStaff = 1; bll.Model.Remark = "线下补录导入"; } #endregion bll.Model["SubmitFlag"] = "1"; bll.Model["DataSource"] = "7"; IList <SVM_SalesVolume_Detail> details = new List <SVM_SalesVolume_Detail>(); bool wrongflag = false;//判断导入数量是否正常(除空导致的异常) int quantity = 0; bool isnumber = false; while (true) { PDT_Product product = null; quantity = 0; if (headerRow.GetCell(datacolumn) == null || headerRow.GetCell(datacolumn).CellType == CellType.BLANK || headerRow.GetCell(datacolumn).ToString() == string.Empty) { break; } IList <PDT_Product> products = PDT_ProductBLL.GetModelList("ShortName='" + headerRow.GetCell(datacolumn).ToString() + "' AND State=1"); if (products.Count > 0) { product = products[0]; } else { errormessage += "产品名称:" + headerRow.GetCell(datacolumn).ToString() + "在产品列表中不存在!\r\n"; datacolumn++; row.GetCell(column).SetCellValue(errormessage); continue; } if ((product != null) && row.GetCell(datacolumn).CellType != CellType.BLANK) { int.TryParse(row.GetCell(datacolumn).ToString(), out quantity); if (int.TryParse(row.GetCell(datacolumn).ToString(), out quantity) && !isnumber) { isnumber = true; } if (quantity != 0 && quantity <= 5000 && quantity >= 0) { decimal factoryprice = 0, salesprice = 0; PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 3, out factoryprice, out salesprice); if (factoryprice == 0) { factoryprice = product.FactoryPrice; } if (salesprice == 0) { salesprice = product.NetPrice; } SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail(); detail.Product = product.ID; detail.FactoryPrice = factoryprice; detail.SalesPrice = salesprice; detail.Quantity = quantity; details.Add(detail); } else if (row.GetCell(datacolumn).CellType != CellType.BLANK && (row.GetCell(datacolumn).ToString() != "0")) { wrongflag = true; break; } else if (quantity < 0) { wrongflag = true; break; } } datacolumn++; } if (wrongflag) { errormessage += "ID号:" + clientid.ToString() + "," + client.FullName + ",导购:" + row.GetCell(6).ToString() + " 当月的线下补录销量单" + "未能导入!产品名称:" + headerRow.GetCell(datacolumn).ToString() + "数量填写错误。\r\n"; row.GetCell(column).SetCellValue(errormessage); continue; } #region 更新销量至数据库 if (bll.Model.ID > 0) { if (details.Count > 0) { bll.DeleteDetail(); //先清除原先导入的数据 bll.Items = details; bll.Model.UpdateStaff = 1; bll.AddDetail(); bll.Update(); string message = " ID号:" + clientid.ToString() + ",该零售商:" + client.FullName + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + "的销量单" + "被成功更新!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n"; improtmessage += message; row.CreateCell(column).SetCellValue(message); } if (details.Count == 0 && isnumber) { bll.DeleteDetail(); } } else { if (details.Count > 0 || svmlists.Count == 0) //没有产品也新增一条空销量头 { bll.Items = details; if (bll.Add() > 0) { foreach (SVM_SalesVolume m in svmlists) { bll = new SVM_SalesVolumeBLL(m.ID); bll.DeleteDetail(); bll.Delete(); } } string message = "ID号:" + clientid.ToString() + ",该零售商:" + client.FullName + "的销量单" + "已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n"; improtmessage += message; row.CreateCell(column).SetCellValue(message); } } #endregion ((BackgroundWorker)sender).ReportProgress(i * 100 / count, i); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { FileStream writefile = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite); hssfworkbook.Write(writefile); writefile.Close(); sheet = null; } }