Beispiel #1
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);
        }