Beispiel #1
0
        public static List <StocktakeResultImportRow> FindAll(DataTable dt)
        {
            List <StocktakeResultImportRow> list = new List <StocktakeResultImportRow>();

            if (dt != null && dt.Rows != null && dt.Rows.Count != 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    StocktakeResultImportRow entity = new StocktakeResultImportRow(dr);
                    list.Add(entity);
                }
            }

            if (list != null)
            {
                list.Sort(delegate(StocktakeResultImportRow a, StocktakeResultImportRow b) { return(a.PartNumber.CompareTo(b.PartNumber)); });
            }

            return(list);
        }
Beispiel #2
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (ValidImportData())
            {
                string filename = this.fuImportFile.PostedFile.FileName;
                filename = filename.Substring(filename.LastIndexOf('\\') + 1);

                string tempFilePath = Path.Combine(Server.MapPath("/"), "ImportTemp/StocktakeResult_" + DateTime.Now.ToFileTime() + filename);

                try
                {
                    this.fuImportFile.PostedFile.SaveAs(tempFilePath);
                    DataTable dt          = new DataTable();
                    string    readDataMsg = string.Empty;
                    if (!ExcelHelper.GetImportedDataTable(this.fuImportFile.PostedFile, Server.MapPath("/"), out readDataMsg, out dt, new Hashtable(), this.SchemaFilePath))
                    {
                        ShowImportErrorInfo(readDataMsg);
                        return;
                    }

                    if (dt == null || dt.Rows == null || dt.Rows.Count == 0)
                    {
                        ShowImportErrorInfo("导入数据为空!");
                        return;
                    }

                    List <StocktakeResultImportRow> list = StocktakeResultImportRow.FindAll(dt);
                    if (list == null || list.Count == 0)
                    {
                        ShowImportErrorInfo("导入数据集合为空!");
                        return;
                    }

                    #region 基础数据

                    List <StoreLocation>         AllStoreLocation         = StoreLocation.FindAll();
                    List <StocktakeResultSimple> AllStocktakeResultSimple = StocktakeResultSimple.FindAll(this.Noficication.NotificationID, Int64.MinValue, Int64.MaxValue);

                    #endregion

                    //SGM导入数据
                    List <StocktakeItemSimple> StocktakeItems = new List <StocktakeItemSimple>();
                    //外协供应商导入数据
                    List <SupplierStocktakeItemSimple> SupplierStocktakeItems = new List <SupplierStocktakeItemSimple>();

                    List <string> errorList = new List <string>();
                    foreach (StocktakeResultImportRow stocktakeResult in list)
                    {
                        #region 验证数据

                        //存储区域
                        StoreLocation sloc = FindStoreLocation(AllStoreLocation, stocktakeResult.StoreLocation);
                        if (sloc == null)
                        {
                            errorList.Add(string.Format(@"序号【{0}】:存储区域【{1}】不存在", stocktakeResult.SerialNumber, stocktakeResult.StoreLocation));
                            continue;
                        }

                        StocktakeResultSimple StocktakeResult = FindStocktakeResult(AllStocktakeResultSimple, stocktakeResult.PartNumber, stocktakeResult.Plant, stocktakeResult.DUNS, sloc.LocationID);
                        if (StocktakeResult == null)
                        {
                            errorList.Add(string.Format(@"序号【{0}】:工厂【{1}】,DUNS【{2}】,存储区域为【{3}】的零件【{4}】不在盘点通知单中",
                                                        stocktakeResult.SerialNumber, stocktakeResult.Plant, stocktakeResult.DUNS, stocktakeResult.StoreLocation, stocktakeResult.PartNumber));
                            continue;
                        }

                        #endregion

                        #region 数据验证通过,将数据装箱

                        if (StocktakeResult.TypeID == 1)
                        {
                            StocktakeItemSimple item = new StocktakeItemSimple();
                            item.ItemID    = StocktakeResult.ItemID;
                            item.Line      = string.IsNullOrEmpty(stocktakeResult.Line) ? 0 : decimal.Parse(stocktakeResult.Line);
                            item.Machining = string.IsNullOrEmpty(stocktakeResult.Machining) ? 0 : decimal.Parse(stocktakeResult.Machining);
                            item.Store     = string.IsNullOrEmpty(stocktakeResult.Store) ? 0 : decimal.Parse(stocktakeResult.Store);
                            item.StartCSN  = stocktakeResult.CSNStart;
                            item.EndCSN    = stocktakeResult.CSNEnd;
                            item.Block     = string.IsNullOrEmpty(stocktakeResult.Block) ? 0 : decimal.Parse(stocktakeResult.Block);
                            item.Available = string.IsNullOrEmpty(stocktakeResult.Available) ? 0 : decimal.Parse(stocktakeResult.Available);
                            item.QI        = string.IsNullOrEmpty(stocktakeResult.QI) ? 0 : decimal.Parse(stocktakeResult.QI);
                            //item.BlockAdjust = stocktakeResult.Block
                        }

                        #endregion
                    }

                    #region 显示导出错误信息
                    if (errorList != null && errorList.Count != 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat(string.Format(@"共【{0}】条错误数据</br>", errorList.Count));

                        foreach (string error in errorList)
                        {
                            sb.AppendFormat(@"{0}</br>", error);
                        }

                        ShowImportErrorInfo(sb.ToString());
                    }
                    #endregion
                    else
                    {
                        ShowImportErrorInfo("导入成功!");
                    }
                }
                catch (Exception er)
                {
                    ShowImportErrorInfo(er.Message);
                }
            }
        }