protected void bt_Add_Click(object sender, EventArgs e)
    {
        int count = 0;

        foreach (GridViewRow row in gv_List.Rows)
        {
            CheckBox cbx = (CheckBox)row.FindControl("cbx");
            if (cbx != null && cbx.Checked)
            {
                int id = (int)gv_List.DataKeys[row.RowIndex]["PDT_Product_ID"];

                PDT_ProductBLL     bll     = new PDT_ProductBLL(id);
                PDT_ProductExtInfo extinfo = new PDT_ProductExtInfo();
                extinfo.Code     = bll.Model.FactoryCode == "" ? bll.Model.Code : bll.Model.FactoryCode;
                extinfo.Supplier = (int)Session["OwnerClient"];
                bll.SetProductExtInfo(extinfo);
                count++;
            }
        }
        if (count > 0)
        {
            MessageBox.Show(this, string.Format("成功将{0}个商品加入经营范围!", count));
            cbx_CheckAll.Checked = false;
            BindGrid();
        }
        else
        {
            MessageBox.Show(this, "请选择要加入经营产商品!");
        }
    }
示例#2
0
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        PDT_ProductBLL     _Product = null;
        PDT_ProductExtInfo extinfo  = null;

        if ((int)ViewState["ID"] == 0)
        {
            _Product = new PDT_ProductBLL();
        }
        else
        {
            _Product = new PDT_ProductBLL((int)ViewState["ID"]);
            extinfo  = _Product.GetProductExtInfo((int)Session["OwnerClient"]);
        }

        if (extinfo == null)
        {
            extinfo          = new PDT_ProductExtInfo();
            extinfo.Supplier = (int)Session["OwnerClient"];
        }

        pl_detail.GetData(_Product.Model);
        pl_detail.GetData(extinfo);

        if ((int)ViewState["ID"] == 0)
        {
            _Product.Model.Category    = extinfo.Category;
            _Product.Model.State       = 1;
            _Product.Model.ApproveFlag = 1;
            _Product.Model.InsertStaff = (int)Session["UserID"];
            _Product.Model.OwnerType   = 3;
            _Product.Model.OwnerClient = (int)Session["OwnerClient"];
            extinfo.InsertStaff        = (int)Session["UserID"];

            ViewState["ID"] = _Product.Add();
        }
        else
        {
            if ((int)Session["OwnerClient"] == _Product.Model.OwnerClient)
            {
                _Product.Model.UpdateStaff = (int)Session["UserID"];
                _Product.Update();
            }
        }
        #region 将价格折算为最小单位
        extinfo.BuyPrice      = extinfo.BuyPrice / _Product.Model.ConvertFactor;
        extinfo.SalesPrice    = extinfo.SalesPrice / _Product.Model.ConvertFactor;
        extinfo.MaxSalesPrice = extinfo.MaxSalesPrice / _Product.Model.ConvertFactor;
        extinfo.MinSalesPrice = extinfo.MinSalesPrice / _Product.Model.ConvertFactor;
        #endregion

        _Product.SetProductExtInfo(extinfo);

        Response.Redirect("ProductList.aspx?Category=" + extinfo.Category.ToString());
    }
        /// <summary>
        /// 设置指定商品的TDP管理信息
        /// </summary>
        /// <param name="ProductExtInfo"></param>
        /// <returns></returns>
        public int SetProductExtInfo(PDT_ProductExtInfo ProductExtInfo)
        {
            if (ProductExtInfo == null)
            {
                return(-1);
            }
            if (ProductExtInfo.Supplier == 0)
            {
                return(-2);
            }

            PDT_ProductExtInfoBLL bll = new PDT_ProductExtInfoBLL();

            if (ProductExtInfo.ID == 0)
            {
                //判断是否已存在指定供货商的供货信息
                PDT_ProductExtInfo org = GetProductExtInfo(ProductExtInfo.Supplier);
                if (org == null)
                {
                    //不存在,新增一条供货信息
                    bll.Model         = ProductExtInfo;
                    bll.Model.Product = _m.ID;
                    if (bll.Model.Category == 0)
                    {
                        bll.Model.Category = _m.Category;
                    }
                    if (bll.Model.SalesState == 0)
                    {
                        bll.Model.SalesState = 1;
                    }
                    if (bll.Model.ApproveFlag == 0)
                    {
                        bll.Model.ApproveFlag = 1;
                    }

                    return(bll.Add());
                }
                else
                {
                    //存在,则将原ID赋给本次更新的ID,执行后续的更新操作
                    ProductExtInfo.ID = org.ID;
                }
            }

            //更新现在供货信息
            if (ProductExtInfo.ID > 0)
            {
                bll.Model = ProductExtInfo;
                return(bll.Update());
            }

            return(0);
        }
示例#4
0
    protected void select_Product_TextChange(object sender, MCSControls.MCSWebControls.TextChangeEventArgs e)
    {
        PDT_ProductExtInfo p = PDT_ProductExtInfoBLL.GetProductExtInfo_ByCode((int)Session["OwnerClient"], e.Code);

        if (p != null)
        {
            PDT_ProductBLL productbll = new PDT_ProductBLL(p.Product);
            if (productbll.Model == null)
            {
                return;
            }

            select_Product.SelectValue = p.Product.ToString();
            select_Product.SelectText  = productbll.Model.FullName;

            select_Product_SelectChange(null, null);
            tbx_Quantity.Text = "";
            tbx_Quantity.Focus();
        }
    }
    protected void bt_AddAll_Click(object sender, EventArgs e)
    {
        string ConditionStr = " PDT_Product.ID NOT IN (SELECT Product FROM MCS_PUB.dbo.PDT_ProductExtInfo WHERE Supplier=" + Session["OwnerClient"].ToString() + ")";

        if (tr_List.SelectedValue != "" && tr_List.SelectedValue != "1")
        {
            string    _categoryids = "";
            DataTable dt           = TreeTableBLL.GetAllChildByNodes("MCS_Pub.dbo.PDT_Category", "ID", "SuperID", tr_List.SelectedValue);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                _categoryids += dt.Rows[i]["ID"].ToString() + ",";
            }
            _categoryids += tr_List.SelectedValue;

            ConditionStr += " AND PDT_Product.Category IN (" + _categoryids + ")";
        }
        int count = 0;
        IList <PDT_Product> product = PDT_ProductBLL.GetModelList(ConditionStr);

        foreach (PDT_Product p in product)
        {
            int id = p.ID;

            PDT_ProductBLL     bll     = new PDT_ProductBLL(id);
            PDT_ProductExtInfo extinfo = new PDT_ProductExtInfo();
            extinfo.Code     = bll.Model.FactoryCode == "" ? bll.Model.Code : bll.Model.FactoryCode;
            extinfo.Supplier = (int)Session["OwnerClient"];
            bll.SetProductExtInfo(extinfo);
            count++;
        }
        if (count > 0)
        {
            MessageBox.Show(this, string.Format("成功将{0}个商品加入经营范围!", count));
            BindGrid();
        }
        else
        {
            MessageBox.Show(this, "请选择要加入经营产商品!");
        }
    }
    protected void bt_In_Click(object sender, EventArgs e)
    {
        Save();

        foreach (GridViewRow row in gv_NotInList.Rows)
        {
            CheckBox cb_check = (CheckBox)row.FindControl("cb_Check");
            if (cb_check.Checked)
            {
                PDT_StandardPriceBLL _bll;
                if ((int)ViewState["ID"] != 0)
                {
                    _bll = new PDT_StandardPriceBLL((int)ViewState["ID"]);
                }
                else
                {
                    return;
                }

                PDT_StandardPrice_Detail pd = new PDT_StandardPrice_Detail();
                pd.Product = int.Parse(gv_NotInList.DataKeys[row.RowIndex]["ID"].ToString());

                PDT_ProductBLL     productbll = new PDT_ProductBLL(pd.Product);
                PDT_ProductExtInfo extinfo    = productbll.GetProductExtInfo((int)Session["OwnerClient"]);
                if (extinfo != null)
                {
                    pd.Price = extinfo.SalesPrice;
                }
                else
                {
                    pd.Price = productbll.Model.StdPrice;
                }
                _bll.AddDetail(pd);
            }
        }
        Response.Redirect("StandardPriceDetail.aspx?ID=" + ViewState["ID"].ToString());
    }
示例#7
0
    private void BindData()
    {
        PDT_ProductBLL bll = new PDT_ProductBLL((int)ViewState["ID"]);

        if (bll.Model == null)
        {
            Response.Redirect("ProductList.aspx.aspx");
            return;
        }
        if (bll.Model.ConvertFactor == 0)
        {
            bll.Model.ConvertFactor = 1;
        }
        pl_detail.BindData(bll.Model);

        PDT_ProductExtInfo extinfo = bll.GetProductExtInfo((int)Session["OwnerClient"]);

        if (extinfo != null)
        {
            #region 将价格折算为整件单位
            extinfo.BuyPrice      = extinfo.BuyPrice * bll.Model.ConvertFactor;
            extinfo.SalesPrice    = extinfo.SalesPrice * bll.Model.ConvertFactor;
            extinfo.MaxSalesPrice = extinfo.MaxSalesPrice * bll.Model.ConvertFactor;
            extinfo.MinSalesPrice = extinfo.MinSalesPrice * bll.Model.ConvertFactor;
            #endregion
            pl_detail.BindData(extinfo);
        }

        if (bll.Model.OwnerClient != (int)Session["OwnerClient"])
        {
            pl_detail.SetPanelEnable("Panel_TDP_PDT_Product_Detail_01", false);
        }

        bt_OK.Text      = "修改";
        bt_OK.ForeColor = System.Drawing.Color.Red;
    }
    private bool Save()
    {
        PDT_StandardPriceBLL _bll;

        if ((int)ViewState["ID"] != 0)
        {
            //修改
            _bll = new PDT_StandardPriceBLL((int)ViewState["ID"]);
        }
        else
        {
            //新增
            _bll = new PDT_StandardPriceBLL();
        }

        pl_detail.GetData(_bll.Model);

        #region 判断必填项

        #endregion

        #region 判断是否与默认价表重复
        if (_bll.Model.IsDefault.ToUpper() == "Y")
        {
            int _priceid = PDT_StandardPriceBLL.GetDefaultPrice((int)Session["OwnerClient"]);
            if (_priceid != _bll.Model.ID)
            {
                MessageBox.Show(this, "对不起,不能重复新增默认价表,新增的价表必须限制区域或渠道!");
                return(false);
            }
        }

        #endregion

        if ((int)ViewState["ID"] != 0)
        {
            //修改
            _bll.Model.UpdateStaff = (int)Session["UserID"];
            _bll.Update();
        }
        else
        {
            //新增
            _bll.Model.Supplier    = (int)Session["OwnerClient"];
            _bll.Model.ApproveFlag = 2;
            _bll.Model.InsertStaff = (int)Session["UserID"];
            ViewState["ID"]        = _bll.Add();
        }

        #region 保存修改明细
        foreach (GridViewRow row in gv_List.Rows)
        {
            PDT_StandardPrice_Detail item = new PDT_StandardPrice_Detail();
            item.PriceID = _bll.Model.ID;
            item.ID      = int.Parse(gv_List.DataKeys[row.RowIndex]["ID"].ToString());
            item.Product = int.Parse(gv_List.DataKeys[row.RowIndex]["Product"].ToString());

            PDT_Product p = new PDT_ProductBLL(item.Product).Model;

            if (row.FindControl("tbx_Price") != null)
            {
                decimal d = 0;
                if (decimal.TryParse(((TextBox)row.FindControl("tbx_Price")).Text, out d))
                {
                    item.Price = d;
                }

                PDT_ProductBLL productbll = new PDT_ProductBLL(item.Product);
                item.Price = item.Price / productbll.Model.ConvertFactor;

                PDT_ProductExtInfo extinfo = productbll.GetProductExtInfo((int)Session["OwnerClient"]);
                if (extinfo != null)
                {
                    if (extinfo.MinSalesPrice > 0 && item.Price < extinfo.MinSalesPrice)
                    {
                        MessageBox.Show(this, "对不起,您发布的价格不能小于建议零售价!");
                        return(false);
                    }
                    else if (extinfo.MaxSalesPrice > 0 && item.Price > extinfo.MaxSalesPrice)
                    {
                        MessageBox.Show(this, "对不起,您发布的价格不能过高于建议零售价!");
                        return(false);
                    }
                }
            }


            if (row.FindControl("tbx_Remark") != null)
            {
                item.Remark = ((TextBox)row.FindControl("tbx_Remark")).Text;
            }

            _bll.UpdateDetail(item);
        }

        #endregion

        return(true);
    }
示例#9
0
    protected void rbl_ln_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddl_LotNumber.Visible   = rbl_ln.SelectedValue != "N";
        tbx_LotNumber.Visible   = rbl_ln.SelectedValue == "N";
        tbx_ProductDate.Enabled = rbl_ln.SelectedValue == "N";

        if (rbl_ln.SelectedValue == "Y")
        {
            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;
                }
                PDT_Product p = productbll.Model;

                Dictionary <string, Dictionary_Data> dic = DictionaryBLL.GetDicCollections("PDT_Packaging");
                string _T = dic[p.TrafficPackaging.ToString()].Name;
                string _P = dic[p.Packaging.ToString()].Name;

                #region 显示批号及库存信息
                ddl_LotNumber.Items.Clear();
                foreach (INV_Inventory item in INV_InventoryBLL.GetInventoryListByProduct((int)ViewState["WareHouse"], product))
                {
                    //ddl_LotNumber.Items.Add(new ListItem((item.LotNumber == "" ? "无批号" : item.LotNumber), item.LotNumber));
                    string invstr = (item.Quantity / p.ConvertFactor).ToString() + _T;
                    if (item.Quantity % p.ConvertFactor > 0)
                    {
                        invstr += " " + (item.Quantity % p.ConvertFactor).ToString() + _P;
                    }
                    ddl_LotNumber.Items.Add(new ListItem((item.LotNumber == "" ? "无批号" : item.LotNumber) + "-【库存量:" + invstr + "】", item.LotNumber));
                }
                #endregion

                ddl_LotNumber_SelectedIndexChanged(null, null);
            }
        }
        else
        {
            tbx_LotNumber.Text   = "";
            tbx_ProductDate.Text = "";

            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;
                }

                PDT_ProductExtInfo extinfo = productbll.GetProductExtInfo((int)Session["OwnerClient"]);
                if (extinfo == null)
                {
                    return;
                }

                if (ddl_Unit.SelectedValue == "T")
                {
                    tbx_Price.Text = (extinfo.BuyPrice * productbll.Model.ConvertFactor).ToString("0.##");
                }
                else
                {
                    tbx_Price.Text = extinfo.BuyPrice.ToString("0.##");
                }
            }
        }
    }
示例#10
0
        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;
                }
            }
        }
示例#11
0
        public string DoImportInventory(int TemplateID, int Client, ISheet Sheet, out int State)
        {
            string ImportInfo = "【期初库存】Excel表:";

            State = 0;
            IPT_UploadTemplateBLL _template = new IPT_UploadTemplateBLL(TemplateID);

            List <string> listSupplier = new List <string>()
            {
                "序号", "商品编码", "商品名称", "批号", "生产日期", "库存成本价", "整件数量", "零散数量"
            };

            DataTable dt   = null;
            bool      flag = VertifySheet(Sheet, listSupplier, out dt, ref ImportInfo);

            if (!flag)
            {
                State = 4; return(ImportInfo);
            }

            foreach (DataRow dr in dt.Rows)//循环导入数据
            {
                try
                {
                    int _pdtTrafficPackaging = (!string.IsNullOrEmpty(dr["整件数量"].ToString())) ? Convert.ToInt32(dr["整件数量"].ToString()) : 0;
                    int _pdtPackaging        = (!string.IsNullOrEmpty(dr["零散数量"].ToString())) ? Convert.ToInt32(dr["零散数量"].ToString()) : 0;
                    if (_pdtPackaging == 0 && _pdtTrafficPackaging == 0)
                    {
                        ImportInfo += string.Format("序号为{0}的行导入库存数量为0,跳过此行信息\r\n", dr["序号"]);
                        continue;
                    }
                    string _pdtCode = dr["商品编码"].ToString();
                    IList <PDT_ProductExtInfo> _listPdtExtInfo = PDT_ProductExtInfoBLL.GetProductExtInfoList_BySupplier(_template.Model.ClientID);
                    PDT_ProductExtInfo         _ProductExtInfo = _listPdtExtInfo.FirstOrDefault(m => m.Code == _pdtCode);
                    if (_ProductExtInfo == null || _ProductExtInfo.ID == 0)
                    {
                        ImportInfo += string.Format("序号为{0}的行找不到对应编码的产品,跳过此行信息\r\n", dr["序号"]);
                        continue;
                    }
                    int _pdtID = _ProductExtInfo.Product;

                    //string _pdtName = dr["商品名称"].ToString();
                    string   _pdtLotNumber = dr["批号"].ToString();
                    DateTime _pdtProductDate; DateTime.TryParse(dr["生产日期"].ToString(), out _pdtProductDate);
                    decimal  _pdtPrice    = (!string.IsNullOrEmpty(dr["库存成本价"].ToString())) ? Convert.ToDecimal(dr["库存成本价"].ToString()) : 0;
                    int      _pdtQuantity = new PDT_ProductBLL(_pdtID).Model.ConvertFactor *_pdtTrafficPackaging + _pdtPackaging;


                    #region 获取经销商主仓库
                    int _WareHouse = 0;
                    IList <CM_WareHouse> _listWareHouse = CM_WareHouseBLL.GetModelList("  Classify=1 AND ApproveFlag=1 AND Client=" + _template.Model.ClientID.ToString());
                    if (_listWareHouse != null || _listWareHouse.Count > 0)
                    {
                        _WareHouse = _listWareHouse[0].ID;
                    }
                    else
                    {
                        CM_WareHouseBLL _bllWareHouse = new CM_WareHouseBLL();
                        _bllWareHouse.Model.Name        = "默认主仓库";
                        _bllWareHouse.Model.Client      = _template.Model.ClientID;
                        _bllWareHouse.Model.InsertStaff = _template.Model.InsertStaff;
                        _bllWareHouse.Model.ApproveFlag = 1;
                        _WareHouse = _bllWareHouse.Add();
                    }
                    #endregion

                    int _result = INV_InventoryBLL.IncreaseQuantity(_WareHouse, _pdtID, _pdtLotNumber, _pdtPrice, _pdtQuantity);
                    if (_result != 0)
                    {
                        ImportInfo += "导入序列号为" + dr["序号"].ToString() + "的销量时出现错误";
                        State       = 5;
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    ImportInfo += "导入序列号为" + dr["序号"].ToString() + "的数据行时出现错误,错误说明:" + ex.Message + "\r\n";
                    State       = 5;
                    continue;
                }
            }
            if (State == 0)
            {
                State = 3;
            }
            ImportInfo += (State == 3 ? "导入完成!\r\n" : "");
            IPT_UploadTemplateMessageBLL _bllUploadTemplateMessage = new IPT_UploadTemplateMessageBLL();
            _bllUploadTemplateMessage.Model.TemplateID  = TemplateID;
            _bllUploadTemplateMessage.Model.MessageType = State;
            _bllUploadTemplateMessage.Model.Content     = ImportInfo;
            _bllUploadTemplateMessage.Add();
            return(ImportInfo);
        }