protected void gv_List_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { if (ViewState["Details"] == null) { return; } ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"]; int id = (int)gv_List.DataKeys[e.NewSelectedIndex]["ID"]; PBM_DeliveryDetail d = Details[id.ToString()]; PDT_Product product = new PDT_ProductBLL(d.Product, true).Model; if (product == null) { return; } //RadComboBox1.SelectedValue = d.Product.ToString(); //RadComboBox1.Text = product.FullName; //RadComboBox1_SelectedIndexChanged(null, null); select_Product.SelectText = product.FullName; select_Product.SelectValue = product.ID.ToString(); select_Product_SelectChange(null, null); if (ddl_LotNumber.Items.FindByValue(d.LotNumber) != null) { ddl_LotNumber.SelectedValue = d.LotNumber; } if (d.DeliveryQuantity % product.ConvertFactor == 0) { ddl_Unit.SelectedValue = "T"; tbx_Price.Text = (d.Price * product.ConvertFactor).ToString("0.##"); tbx_Quantity.Text = (d.DeliveryQuantity / product.ConvertFactor).ToString(); } else { ddl_Unit.SelectedValue = "P"; tbx_Price.Text = d.Price.ToString("0.##"); tbx_Quantity.Text = d.DeliveryQuantity.ToString(); } ViewState["SelectedDetail"] = d; bt_AddDetail.Text = "修 改"; }
protected void gv_List_RowDataBound(object sender, GridViewRowEventArgs e) { if (ViewState["Details"] == null) { return; } ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"]; if (e.Row.RowType == DataControlRowType.DataRow) { int id = (int)((GridView)sender).DataKeys[e.Row.RowIndex]["ID"]; PBM_DeliveryDetail d = Details[id.ToString()]; if (d == null) { return; } PDT_Product product = new PDT_ProductBLL(d.Product, true).Model; if (product == null) { return; } Dictionary <string, Dictionary_Data> dic = DictionaryBLL.GetDicCollections("PDT_Packaging"); string _T = dic[product.TrafficPackaging.ToString()].Name; string _P = dic[product.Packaging.ToString()].Name; Label lbProduct = (Label)e.Row.FindControl("lbProduct"); if (lbProduct != null) { lbProduct.Text = product.FullName; } #region 显示产品价格包装信息 Label lb_Price = (Label)e.Row.FindControl("lb_Price"); if (lb_Price != null) { lb_Price.Text = (d.Price * product.ConvertFactor).ToString("0.##") + "元/" + _T;// +"(" + product.ConvertFactor.ToString() + _P + ")"; } #endregion #region 显示产品数量信息 Label lb_Quantity = (Label)e.Row.FindControl("lb_Quantity"); if (lb_Quantity != null) { if (d.SignInQuantity / product.ConvertFactor > 0) { lb_Quantity.Text = (d.SignInQuantity / product.ConvertFactor).ToString() + _T; } if (d.SignInQuantity % product.ConvertFactor > 0) { lb_Quantity.Text += "" + (d.SignInQuantity % product.ConvertFactor).ToString() + _P; } } #endregion #region 追加订货模式 if (d.SalesMode > 1) { Dictionary_Data dic_data = DictionaryBLL.GetDicCollections("PBM_SalseMode")[d.SalesMode.ToString()]; if (dic_data != null) { lbProduct.Text += "(" + dic_data.Name + ")"; } } #endregion Label lb_Fee = (Label)e.Row.FindControl("lb_Fee"); if (lb_Fee != null) { lb_Fee.Text = (Math.Round(d.Price * d.ConvertFactor, 2) * d.SignInQuantity / d.ConvertFactor).ToString("0.##"); } Label lbDiscountRate = (Label)e.Row.FindControl("lbDiscountRate"); if (lbDiscountRate != null) { lbDiscountRate.Text = d.DiscountRate.ToString("0.##%"); } } }
private bool Save() { if (ViewState["Details"] == null) { return(false); } ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"]; PBM_DeliveryBLL _bll = new PBM_DeliveryBLL((int)ViewState["ID"]); pl_detail.GetData(_bll.Model); #region 判断必填项 if (_bll.Model.Supplier == 0) { MessageBox.Show(this, "请正确选择供货商!"); return(false); } if (_bll.Model.SupplierWareHouse == 0) { MessageBox.Show(this, "请正确选择盘点仓库!"); return(false); } #endregion #region 循环设置盘点调整数量 foreach (GridViewRow row in gv_List.Rows) { int _id = (int)gv_List.DataKeys[row.RowIndex]["ID"]; PBM_DeliveryDetail d = Details[_id.ToString()]; if (d == null) { continue; } int quantity = 0; TextBox tbx_Quantity_T = (TextBox)row.FindControl("tbx_Quantity_T"); TextBox tbx_Quantity_P = (TextBox)row.FindControl("tbx_Quantity_P"); if (tbx_Quantity_T != null) { int.TryParse(tbx_Quantity_T.Text, out quantity); d.DeliveryQuantity = quantity * d.ConvertFactor; } if (tbx_Quantity_P != null) { int.TryParse(tbx_Quantity_P.Text, out quantity); d.DeliveryQuantity += quantity; } DropDownList ddl_Mode = (DropDownList)row.FindControl("ddl_Mode"); if (ddl_Mode != null && ddl_Mode.SelectedValue == "D") { int inv_quantity = 0; int.TryParse(d["PreInventoryQuantity"], out inv_quantity); if (inv_quantity < d.DeliveryQuantity) { MessageBox.Show(this, "盘亏数量不能大于当前库存!"); return(false); } d.DeliveryQuantity = -1 * d.DeliveryQuantity; d.SignInQuantity = d.DeliveryQuantity; } Details.Update(d); } #endregion _bll.Model.DiscountAmount = 0; _bll.Model.WipeAmount = 0; //实际成交价 _bll.Model.ActAmount = Math.Round(Details.GetListItem().Sum(p => Math.Round(p.Price * p.ConvertFactor, 2) * p.DeliveryQuantity / p.ConvertFactor), 2); if ((int)ViewState["ID"] != 0) { //修改 _bll.Model.UpdateStaff = (int)Session["UserID"]; #region 保存明细 foreach (PBM_DeliveryDetail d in Details.GetListItem(ItemState.Modified)) { _bll.UpdateDetail(d); } #endregion if (_bll.Update() == 0) { return(true); } } return(false); }
protected void gv_List_RowDataBound(object sender, GridViewRowEventArgs e) { if (ViewState["Details"] == null) { return; } ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"]; if (e.Row.RowType == DataControlRowType.DataRow) { int id = (int)gv_List.DataKeys[e.Row.RowIndex]["ID"]; PBM_DeliveryDetail d = Details[id.ToString()]; PDT_Product product = new PDT_ProductBLL(d.Product, true).Model; PDT_ProductExtInfo extInfo = new PDT_ProductBLL(d.Product, true).GetProductExtInfo((int)Session["OwnerClient"]); if (product == null || extInfo == null) { return; } Dictionary <string, Dictionary_Data> dic = DictionaryBLL.GetDicCollections("PDT_Packaging"); string _T = dic[product.TrafficPackaging.ToString()].Name; string _P = dic[product.Packaging.ToString()].Name; #region 显示产品分类价格包装信息 Label lb_ProductCategory = (Label)e.Row.FindControl("lb_ProductCategory"); if (lb_ProductCategory != null || extInfo.Category > 0) { lb_ProductCategory.Text = TreeTableBLL.GetFullPathName("MCS_PUB.dbo.PDT_Category", extInfo.Category); } Label lb_Price = (Label)e.Row.FindControl("lb_Price"); if (lb_Price != null) { lb_Price.Text = (d.Price * product.ConvertFactor).ToString("0.##") + "元 / " + _T + "(" + product.ConvertFactor.ToString() + _P + ")"; } #endregion #region 显示产品调整数量信息 Label lb_Quantity = (Label)e.Row.FindControl("lb_Quantity"); DropDownList ddl_Mode = (DropDownList)e.Row.FindControl("ddl_Mode"); TextBox tbx_Quantity_T = (TextBox)e.Row.FindControl("tbx_Quantity_T"); TextBox tbx_Quantity_P = (TextBox)e.Row.FindControl("tbx_Quantity_P"); Label lb_P_T = (Label)e.Row.FindControl("lb_P_T"); Label lb_P_P = (Label)e.Row.FindControl("lb_P_P"); if ((int)ViewState["State"] == 1) { lb_Quantity.Visible = false; if (ddl_Mode != null) { ddl_Mode.SelectedValue = (d.DeliveryQuantity >= 0 ? "I" : "D"); } if (tbx_Quantity_T != null) { tbx_Quantity_T.Text = Math.Abs(d.DeliveryQuantity / product.ConvertFactor).ToString(); } if (tbx_Quantity_P != null) { tbx_Quantity_P.Text = Math.Abs(d.DeliveryQuantity % product.ConvertFactor).ToString(); } if (lb_P_T != null) { lb_P_T.Text = _T; } if (lb_P_P != null) { lb_P_P.Text = _P; } } else { if (d.DeliveryQuantity != 0) { lb_Quantity.ForeColor = d.DeliveryQuantity >= 0 ? System.Drawing.Color.Blue : System.Drawing.Color.Red; lb_Quantity.Text = d.DeliveryQuantity >= 0 ? "盘盈 " : "盘亏 "; if (d.DeliveryQuantity / d.ConvertFactor != 0) { lb_Quantity.Text += (d.DeliveryQuantity / d.ConvertFactor).ToString() + _T; } if (d.DeliveryQuantity % d.ConvertFactor != 0) { lb_Quantity.Text += " " + (d.DeliveryQuantity % d.ConvertFactor).ToString() + _P; } } ddl_Mode.Visible = false; tbx_Quantity_T.Visible = false; tbx_Quantity_P.Visible = false; lb_P_T.Visible = false; lb_P_P.Visible = false; } #endregion #region 显示库存数量 Label lb_InventoryQuantity = (Label)e.Row.FindControl("lb_InventoryQuantity"); if (lb_InventoryQuantity != null) { int inv_quantity = 0; int.TryParse(d["PreInventoryQuantity"], out inv_quantity); if (inv_quantity / product.ConvertFactor != 0) { lb_InventoryQuantity.Text = (inv_quantity / product.ConvertFactor).ToString() + _T; } if (inv_quantity % product.ConvertFactor != 0) { lb_InventoryQuantity.Text += " " + (inv_quantity % product.ConvertFactor).ToString() + _P; } } #endregion } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[0].Text = "盈亏小计"; e.Row.Cells[5].Text = Details.GetListItem().Sum(p => Math.Round(p.Price * p.ConvertFactor, 2) * p.DeliveryQuantity / p.ConvertFactor).ToString("<font color=red size='larger'>0.##元</font>"); } }
protected void bt_AddDetail_Click(object sender, EventArgs e) { if ((int)ViewState["ID"] == 0) { return; } PBM_DeliveryBLL _bll = new PBM_DeliveryBLL((int)ViewState["ID"]); if (ViewState["Details"] == null) { return; } ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"]; int product = 0; int.TryParse(select_Product.SelectValue, out product); //int.TryParse(RadComboBox1.SelectedValue, out product); if (product != 0) { PDT_ProductBLL productbll = new PDT_ProductBLL(product, true); if (productbll.Model == null) { return; } if (productbll.Model.ConvertFactor == 0) { productbll.Model.ConvertFactor = 1; productbll.Update(); } int quantity = 0; decimal price = 0; int.TryParse(tbx_Quantity.Text, out quantity); decimal.TryParse(tbx_Price.Text, out price); if (ddl_Unit.SelectedValue == "T") { //整件单位 quantity = quantity * productbll.Model.ConvertFactor; price = price / productbll.Model.ConvertFactor; } if (quantity == 0) { MessageBox.Show(this, "请填写数量!"); return; } if ((int)ViewState["Classify"] != 2) { #region 销售时判断库存数量是否够退货 int inv_quantity = INV_InventoryBLL.GetProductQuantity((int)ViewState["WareHouse"], product, ddl_LotNumber.SelectedValue); if (quantity > inv_quantity) { MessageBox.Show(this, "库存不足,不可销售出库!"); return; } #endregion } INV_Inventory inv = INV_InventoryBLL.GetInventoryByProductAndLotNumber((int)ViewState["WareHouse"], product, ddl_LotNumber.SelectedValue); if (inv == null) { MessageBox.Show(this, "请正确选择销售批号!"); return; } PBM_DeliveryDetail d = null; if (ViewState["SelectedDetail"] != null) { d = (PBM_DeliveryDetail)ViewState["SelectedDetail"]; } else { d = new PBM_DeliveryDetail(); d.DeliveryID = (int)ViewState["ID"]; if (Details.GetListItem().Count == 0) { d.ID = 1; } else { d.ID = Details.GetListItem().Max(p => p.ID) + 1; } } d.Product = product; d.LotNumber = ddl_LotNumber.SelectedValue; d.CostPrice = inv.Price; //成本价取当前库存表的价格 d.Price = price; //实际销售价 d.ConvertFactor = productbll.Model.ConvertFactor; d.DiscountRate = 1; //默认全价 d.DeliveryQuantity = quantity; d.SignInQuantity = d.DeliveryQuantity; d.LostQuantity = 0; d.BadQuantity = 0; d.SalesMode = 1; if (d.SalesMode == 2) { d.Price = 0; } if (ViewState["SelectedDetail"] != null) { Details.Update(d); //_bll.UpdateDetail(d); ViewState["SelectedDetail"] = null; bt_AddDetail.Text = "新 增"; gv_List.SelectedIndex = -1; } else { Details.Add(d); //_bll.AddDetail(d); } tbx_Quantity.Text = "0"; BindGrid(); } }
protected void gv_List_RowDataBound(object sender, GridViewRowEventArgs e) { if (ViewState["Details"] == null) { return; } ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"]; if (e.Row.RowType == DataControlRowType.DataRow) { int id = (int)gv_List.DataKeys[e.Row.RowIndex]["ID"]; PBM_DeliveryDetail d = Details[id.ToString()]; PDT_Product product = new PDT_ProductBLL(d.Product, true).Model; if (product == null) { return; } Dictionary <string, Dictionary_Data> dic = DictionaryBLL.GetDicCollections("PDT_Packaging"); string _T = dic[product.TrafficPackaging.ToString()].Name; string _P = dic[product.Packaging.ToString()].Name; #region 显示产品价格包装信息 Label lb_Price = (Label)e.Row.FindControl("lb_Price"); if (lb_Price != null) { lb_Price.Text = (d.Price * product.ConvertFactor).ToString("0.##") + "元 / " + _T + "(" + product.ConvertFactor.ToString() + _P + ")"; } #endregion #region 显示产品数量信息 Label lb_Quantity = (Label)e.Row.FindControl("lb_Quantity"); if (lb_Quantity != null) { if (d.DeliveryQuantity / product.ConvertFactor > 0) { lb_Quantity.Text = (d.DeliveryQuantity / product.ConvertFactor).ToString() + _T; } if (d.DeliveryQuantity % product.ConvertFactor > 0) { lb_Quantity.Text += " " + (d.DeliveryQuantity % product.ConvertFactor).ToString() + _P; } } #endregion #region 显示库存数量 //Label lb_InventoryQuantity = (Label)e.Row.FindControl("lb_InventoryQuantity"); //if (lb_InventoryQuantity!=null && ViewState["State"] != null && (int)ViewState["State"] == 1) //{ // int inv_quantity = INV_InventoryBLL.GetProductQuantity((int)ViewState["WareHouse"], d.Product, d.LotNumber); // lb_InventoryQuantity.Text = (inv_quantity / product.ConvertFactor).ToString() + _T; // if (inv_quantity % product.ConvertFactor > 0) // lb_InventoryQuantity.Text += " " + (inv_quantity % product.ConvertFactor).ToString() + _P; // if ((int)ViewState["Classify"] != 2) // { // if (d.DeliveryQuantity > inv_quantity) // { // lb_InventoryQuantity.Text = "<font color=red>" + lb_InventoryQuantity.Text + "【库存不足】</font>"; // } // } //} #endregion } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[0].Text = "小计"; e.Row.Cells[4].Text = Details.GetListItem().Sum(p => p.Price * p.DeliveryQuantity).ToString("<font color=red size='larger'>0.##元</red>"); } }
protected void gv_List_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { if (ViewState["Details"] == null) { return; } ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"]; int id = (int)gv_List.DataKeys[e.NewSelectedIndex]["ID"]; //PBM_DeliveryBLL _bll = new PBM_DeliveryBLL((int)ViewState["ID"]); //PBM_DeliveryDetail d = _bll.Items.FirstOrDefault(p => p.ID == id); PBM_DeliveryDetail d = Details[id.ToString()]; PDT_Product product = new PDT_ProductBLL(d.Product, true).Model; if (product == null) { return; } //RadComboBox1.SelectedValue = d.Product.ToString(); //RadComboBox1.Text = product.FullName; //RadComboBox1_SelectedIndexChanged(null, null); select_Product.SelectText = product.FullName; select_Product.SelectValue = product.ID.ToString(); select_Product_SelectChange(null, null); #region 显示产品包装信息 //Dictionary<string, Dictionary_Data> dic = DictionaryBLL.GetDicCollections("PDT_Packaging"); //lb_PackagingName_T.Text = dic[product.TrafficPackaging.ToString()].Name; //lb_PackagingName_P.Text = dic[product.Packaging.ToString()].Name; //lb_TrafficPackagingName.Text = "元/" + lb_PackagingName_T.Text + "(" + product.ConvertFactor.ToString() + lb_PackagingName_P.Text + ")"; #endregion if (rbl_ln.SelectedValue == "N") { tbx_LotNumber.Text = d.LotNumber; } else if (ddl_LotNumber.Items.FindByValue(d.LotNumber) != null) { ddl_LotNumber.SelectedValue = d.LotNumber; } tbx_ProductDate.Text = d.ProductDate.ToString("yyyy-MM-dd"); if (d.DeliveryQuantity % product.ConvertFactor == 0) { ddl_Unit.SelectedValue = "T"; tbx_Price.Text = (d.Price * product.ConvertFactor).ToString("0.##"); tbx_Quantity.Text = (d.DeliveryQuantity / product.ConvertFactor).ToString(); } else { ddl_Unit.SelectedValue = "P"; tbx_Price.Text = d.Price.ToString("0.##"); tbx_Quantity.Text = d.DeliveryQuantity.ToString(); } tbx_DiscountRate.Text = (d.DiscountRate * 100).ToString("0.##"); ddl_SalesMode.SelectedValue = d.SalesMode.ToString(); ViewState["SelectedDetail"] = d; bt_AddDetail.Text = "修 改"; }
protected void bt_AddDetail_Click(object sender, EventArgs e) { if ((int)ViewState["ID"] == 0) { return; } PBM_DeliveryBLL _bll = new PBM_DeliveryBLL((int)ViewState["ID"]); if (ViewState["Details"] == null) { return; } ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"]; int product = 0; int.TryParse(select_Product.SelectValue, out product); //int.TryParse(RadComboBox1.SelectedValue, out product); if (product != 0) { PDT_ProductBLL productbll = new PDT_ProductBLL(product, true); if (productbll.Model == null) { return; } if (productbll.Model.ConvertFactor == 0) { productbll.Model.ConvertFactor = 1; productbll.Update(); } string lotnumber = ""; int quantity = 0; decimal price = 0; DateTime producedate = new DateTime(1900, 1, 1); int.TryParse(tbx_Quantity.Text, out quantity); decimal.TryParse(tbx_Price.Text, out price); DateTime.TryParse(tbx_ProductDate.Text, out producedate); if (producedate.Year < 1900) { producedate = new DateTime(1900, 1, 1); } if (ddl_Unit.SelectedValue == "T") { //整件单位 quantity = quantity * productbll.Model.ConvertFactor; price = price / productbll.Model.ConvertFactor; } if (quantity == 0) { //MessageBox.Show(this, "请选择采购数量!"); return; } lotnumber = rbl_ln.SelectedValue == "N" ? tbx_LotNumber.Text : ddl_LotNumber.SelectedValue; if (lotnumber == "" && producedate.Year > 1900) { lotnumber = producedate.ToString("yyyyMMdd"); } if ((int)ViewState["Classify"] == 12) { #region 判断库存数量是否够退货 int inv_quantity = INV_InventoryBLL.GetProductQuantity((int)ViewState["WareHouse"], product, lotnumber); if (quantity > inv_quantity) { MessageBox.Show(this, "库存不足,不可采购退货!"); return; } #endregion } PBM_DeliveryDetail d = null; if (ViewState["SelectedDetail"] != null) { d = (PBM_DeliveryDetail)ViewState["SelectedDetail"]; } else { d = new PBM_DeliveryDetail(); d.DeliveryID = (int)ViewState["ID"]; if (Details.GetListItem().Count == 0) { d.ID = 1; } else { d.ID = Details.GetListItem().Max(p => p.ID) + 1; } } decimal discountrate = 100; decimal.TryParse(tbx_DiscountRate.Text, out discountrate); d.Product = product; d.LotNumber = lotnumber; d.ProductDate = producedate.Year < 1900 ? new DateTime(1900, 1, 1) : producedate; d.CostPrice = price; d.Price = d.CostPrice; d.DiscountRate = discountrate / 100; //默认100为全价 d.ConvertFactor = productbll.Model.ConvertFactor; d.DeliveryQuantity = quantity; d.SignInQuantity = d.DeliveryQuantity; d.LostQuantity = 0; d.BadQuantity = 0; d.SalesMode = int.Parse(ddl_SalesMode.SelectedValue); if (d.SalesMode == 2) { d.Price = 0; } //赠送模式采购价自动设为0 if (ViewState["SelectedDetail"] != null) { Details.Update(d); ViewState["SelectedDetail"] = null; bt_AddDetail.Text = "新 增"; gv_List.SelectedIndex = -1; } else { Details.Add(d); //_bll.AddDetail(d); } tbx_LotNumber.Text = ""; tbx_Quantity.Text = "0"; BindGrid(); } }
public void ImportSAPService() { while (bIsRunning) { try { ImportExcelTDP.SAP_ZSD.Z_SD_SD_SHService sd = new ImportExcelTDP.SAP_ZSD.Z_SD_SD_SHService(); NetworkCredential c = new NetworkCredential(); c.UserName = ConfigHelper.GetConfigString("SAP_ZSD_User"); c.Password = ConfigHelper.GetConfigString("SAP_ZSD_Password"); sd.Credentials = c; ImportExcelTDP.SAP_ZSD.Ztdplog[] results1 = new ImportExcelTDP.SAP_ZSD.Ztdplog[1024]; ImportExcelTDP.SAP_ZSD.Ztdplog[] results2 = new ImportExcelTDP.SAP_ZSD.Ztdplog[1024]; sd.ZSdSdSh("1", "5200", DateTime.Today.AddDays(-1).ToString("yyyyMMdd"), ref results1); sd.ZSdSdSh("2", "5200", DateTime.Today.AddDays(-1).ToString("yyyyMMdd"), ref results1); sd.ZSdSdSh("1", "5200", DateTime.Today.ToString("yyyyMMdd"), ref results1); sd.ZSdSdSh("2", "5200", DateTime.Today.ToString("yyyyMMdd"), ref results2); List <ImportExcelTDP.SAP_ZSD.Ztdplog> results = new List <ImportExcelTDP.SAP_ZSD.Ztdplog>(); results.AddRange(results1); results.AddRange(results2); SendMessage("ImportSAPService", "获取到" + results.Count().ToString() + "条发货数量!"); if (results.Count() == 0) { Thread.Sleep(3600 * 1000); continue; } PBM_DeliveryBLL bll = new PBM_DeliveryBLL(); decimal totalamount = 0; foreach (ImportExcelTDP.SAP_ZSD.Ztdplog item in results.OrderBy(p => p.Vgbel)) { if (item.Vgbel != bll.Model.SheetCode) { #region 更新发货单 if (bll.Model.SheetCode != "" && bll.Items.Count > 0) { //计算折扣金额 bll.Model.DiscountAmount = bll.Items.Sum(p => (1 - p.DiscountRate) * Math.Round(p.Price * p.ConvertFactor, 2) * p.DeliveryQuantity / p.ConvertFactor); //明细合计金额 decimal actamount = Math.Round(bll.Items.Sum(p => p.DiscountRate * Math.Round(p.Price * p.ConvertFactor, 2) * p.SignInQuantity / p.ConvertFactor), 2); //优惠金额(明细合计金额与实际采购金额的差额) bll.Model.WipeAmount = actamount - totalamount; //计算实际销售金额 bll.Model.ActAmount = (bll.Model.Classify == 12 ? -1 : 1) * (actamount - bll.Model.WipeAmount); int ret = bll.Add(); if (ret > 0) { SendMessage("ImportSAPService", "单据号" + item.Vgbel + ",正在提交,总金额" + bll.Model.ActAmount.ToString("0.##") + "!"); } else { SendMessage("ImportSAPService", "单据号" + item.Vgbel + ",提交失败!Ret=" + ret.ToString()); } bll = null; totalamount = 0; } #endregion #region 新增采购单据 //判断单号有没有导入过 if (PBM_DeliveryBLL.GetModelList("SheetCode='" + item.Vgbel + "' AND Supplier=1000 AND Classify IN (11,12)").Count > 0) { SendMessage("ImportSAPService", "单据号" + item.Vgbel + ",之前已存在!"); continue; } bll = new PBM_DeliveryBLL(); bll.Model.Classify = 11; #region 判断TDP编码Kunage string tdpcode = item.Kunag.Substring(3); IList <CM_ClientManufactInfo> _clients = CM_ClientManufactInfoBLL.GetModelList("Code='" + tdpcode + "' AND Manufacturer=1000 AND State = 1"); if (_clients.Count == 0) { SendMessage("ImportSAPService", "门店编码无效,单据号" + item.Vgbel + ",客户编号:" + tdpcode); continue; } #endregion bll.Model.SheetCode = item.Vgbel; bll.Model.Supplier = 1000; bll.Model.Client = _clients[0].Client; #region 获取经销商主仓库 IList <CM_WareHouse> _warehouses = CM_WareHouseBLL.GetEnbaledByClient(bll.Model.Client).Where(p => p.Classify == 1).OrderBy(p => p.ID).ToList(); if (_warehouses.Count == 0) { SendMessage("ImportSAPService", "未找到客户主仓库,单据号" + item.Vgbel + ",客户编号:" + tdpcode); continue; } #endregion bll.Model.ClientWareHouse = _warehouses[0].ID; bll.Model.PrepareMode = 1; bll.Model.State = 1; //默认制单状态 bll.Model.WipeAmount = 0; bll.Model.Remark = "SAP导入"; bll.Model.ApproveFlag = 2; bll.Model.InsertStaff = 1; DateTime _prearrivaldate = DateTime.Today; DateTime.TryParse(item.WadatIst, out _prearrivaldate); bll.Model.PreArrivalDate = _prearrivaldate; #endregion } #region 新增商品明细 string productcode = item.Matnr.Substring(item.Matnr.Length - 6); IList <PDT_Product> _products = PDT_ProductBLL.GetModelList("FactoryCode='" + productcode + "' AND State=1"); if (_products.Count == 0) { SendMessage("ImportSAPService", "商品编码无效,单据号" + item.Vgbel + ",商品编号:" + productcode); continue; } int productid = _products[0].ID; PDT_ProductBLL productbll = new PDT_ProductBLL(productid); PBM_DeliveryDetail d = new PBM_DeliveryDetail(); d.Product = productid; d.ConvertFactor = _products[0].ConvertFactor == 0 ? 1 : _products[0].ConvertFactor; d.SalesMode = 1; d.DeliveryQuantity = (int)Math.Round(item.Fkimg * d.ConvertFactor, 0); if (d.DeliveryQuantity < 0) { bll.Model.Classify = 12; //采购退库单 d.DeliveryQuantity = 0 - d.DeliveryQuantity; } d.SignInQuantity = d.DeliveryQuantity; d.CostPrice = Math.Round(item.Kzwi / d.DeliveryQuantity, 4); d.Price = d.CostPrice; d.DiscountRate = Math.Round(item.Kzwi5 / item.Kzwi, 4); d.LotNumber = item.Charg; totalamount += item.Kzwi5; DateTime _productdate = new DateTime(1900, 1, 1); DateTime.TryParse(item.Hsdat, out _productdate); if (_productdate.Year < 1900) { _productdate = new DateTime(1900, 1, 1); } d.ProductDate = _productdate; d.Remark = item.Fkart; bll.Items.Add(d); #endregion #region 判断是否在默认价表中 PDT_ProductExtInfo extinfo = productbll.GetProductExtInfo(bll.Model.Client); if (extinfo == null) { extinfo = new PDT_ProductExtInfo(); extinfo.Supplier = bll.Model.Client; extinfo.Product = productid; extinfo.Category = productbll.Model.Category; extinfo.Code = productbll.Model.FactoryCode; extinfo.SalesState = 1; extinfo.BuyPrice = d.Price; extinfo.SalesPrice = d.Price; new PDT_ProductBLL(productid).SetProductExtInfo(extinfo); } #endregion } #region 更新发货单 if (bll.Model.SheetCode != "" && bll.Items.Count > 0) { //计算折扣金额 bll.Model.DiscountAmount = bll.Items.Sum(p => (1 - p.DiscountRate) * Math.Round(p.Price * p.ConvertFactor, 2) * p.DeliveryQuantity / p.ConvertFactor); //计算实际销售金额 bll.Model.ActAmount = Math.Round((bll.Model.Classify == 12 ? -1 : 1) * bll.Items.Sum(p => p.DiscountRate * Math.Round(p.Price * p.ConvertFactor, 2) * p.SignInQuantity / p.ConvertFactor) - bll.Model.WipeAmount, 2); int ret = bll.Add(); if (ret > 0) { SendMessage("ImportSAPService", "单据号" + bll.Model.SheetCode + ",提交成功,总金额" + bll.Model.ActAmount.ToString("0.##") + "!"); } else { SendMessage("ImportSAPService", "单据号" + bll.Model.SheetCode + ",提交失败!Ret=" + ret.ToString()); } } #endregion Thread.Sleep(3600 * 1000); } catch (ThreadAbortException e) { this.SendMessage("ImportSAPService.ThreadAbortException", e.Message); Thread.Sleep(10000); continue; } catch (Exception ex) { this.SendMessage("ImportSAPService.Exception", ex.Message); Thread.Sleep(10000); continue; } } }