private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            PriceListDetail priceListDetail = new PriceListDetail();
            Party party = partyMgrE.CheckAndLoadParty(dssImportHistory[1]);
            if (party.Type.Equals(BusinessConstants.PARTY_TYPE_CUSTOMER))
            {
                priceListDetail.PriceList = this.LoadSalesPriceList(dssImportHistory[1], party);//销售价格单
            }
            else
            {
                priceListDetail.PriceList = this.LoadPurchasePriceList(dssImportHistory[1], party);//采购价格单
            }
            priceListDetail.Currency = this.currencyMgrE.CheckAndLoadCurrency(dssImportHistory[2]);//货币
            priceListDetail.Item = this.itemMgrE.CheckAndLoadItem(dssImportHistory[3]);//零件号
            priceListDetail.Uom = this.uomMgrE.CheckAndLoadUom(dssImportHistory[4]);//单位
            priceListDetail.StartDate = dssImportHistory[6] != null ? DssHelper.GetDate(dssImportHistory[6], BusinessConstants.DSS_SYSTEM_CODE_QAD) : DateTime.Now;//开始日期
            if (isUpdate)
            {
                priceListDetail.UnitPrice = decimal.Parse(dssImportHistory[5]);//单价
                if (dssImportHistory[7] != null) priceListDetail.EndDate = DssHelper.GetDate(dssImportHistory[7], BusinessConstants.DSS_SYSTEM_CODE_QAD);//结束日期
            }

            #region 默认值
            priceListDetail.TaxCode = entityPreferenceMgrE.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_TAX_RATE).Value;
            priceListDetail.IsIncludeTax = false;
            priceListDetail.IsProvisionalEstimate = this.CheckProvisionalEstimate(priceListDetail.UnitPrice);
            #endregion

            return priceListDetail;
        }
        private object Deserialize(DssImportHistory dssImportHistory)
        {

            Supplier supplier = new Supplier();
            supplier.Code = dssImportHistory[1].ToUpper();
            supplier.Name = dssImportHistory[3];

            ShipAddress shipAddress = new ShipAddress();
            shipAddress.Code = supplier.Code.ToUpper() + "_S";
            shipAddress.Address = dssImportHistory[4];
            shipAddress.ContactPersonName = dssImportHistory[13];
            shipAddress.TelephoneNumber = dssImportHistory[14] + dssImportHistory[15];
            shipAddress.Fax = dssImportHistory[16];
            shipAddress.MobilePhone = dssImportHistory[18] + dssImportHistory[19];
            shipAddress.PostalCode = dssImportHistory[9];
            shipAddress.Party = supplier;

            BillAddress billAddress = new BillAddress();
            billAddress.Code = supplier.Code.ToUpper() + "_B";
            billAddress.Address = dssImportHistory[4];
            billAddress.ContactPersonName = dssImportHistory[13];
            billAddress.TelephoneNumber = dssImportHistory[14] + dssImportHistory[15];
            billAddress.Fax = dssImportHistory[16];
            billAddress.MobilePhone = dssImportHistory[18] + dssImportHistory[19];
            billAddress.PostalCode = dssImportHistory[9];
            billAddress.Party = supplier;

            IList<object> list = new List<object>();
            list.Add(supplier);
            list.Add(shipAddress);
            list.Add(billAddress);
            return list;
        }
        private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            Item item = new Item();
            item.Code = dssImportHistory[1]; //零件号
            if (isUpdate)
            {
                item.Uom = this.uomMgrE.CheckAndLoadUom(dssImportHistory[2].ToUpper());//单位
                item.Desc1 = dssImportHistory[3];//描述1
                item.Desc2 = dssImportHistory[4];//描述2
                item.Type = this.GetItemType(dssImportHistory[5], BusinessConstants.DSS_SYSTEM_CODE_QAD);//P/M类型
                if (dssImportHistory[6] != null && dssImportHistory[6].Trim() != string.Empty)
                {
                    item.Bom = this.bomMgrE.CheckAndLoadBom(dssImportHistory[6]); //BOM
                }
                if (dssImportHistory[7] != null && dssImportHistory[7].Trim() != string.Empty)
                {
                    item.Routing = this.routingMgrE.CheckAndLoadRouting(dssImportHistory[7]);//Routing
                }
            }

            #region 默认值
            item.UnitCount = 1;
            item.LastModifyUser = this.userMgrE.GetMonitorUser();
            item.LastModifyDate = DateTime.Now;
            #endregion

            return item;
        }
        protected override object DeserializeForCreate(DssImportHistory dssImportHistory)
        {
            dssImportHistory.ItemCode = dssImportHistory[1];
            dssImportHistory.HuId = dssImportHistory[2];
            dssImportHistory.Qty = decimal.Parse(dssImportHistory[3]);
            dssImportHistory.ShiftCode = BarcodeHelper.GetShiftCode(dssImportHistory.HuId);

            return dssImportHistory;
        }
        private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            Bom bom = new Bom();
            bom.Code = dssImportHistory[1]; //Bom代码
            if (isUpdate)
            {
                bom.Description = dssImportHistory[2]; //说明
                bom.Uom = this.uomMgrE.CheckAndLoadUom(dssImportHistory[3]);//单位
            }

            return bom;
        }
        private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            UomConversion uomConversion = new UomConversion();
            uomConversion.BaseUom = this.uomMgrE.CheckAndLoadUom(dssImportHistory[1]);//基本单位
            uomConversion.AlterUom = this.uomMgrE.CheckAndLoadUom(dssImportHistory[2]);//替代单位
            uomConversion.Item = this.itemMgrE.CheckAndLoadItem(dssImportHistory[3]);//零件号
            if (isUpdate)
            {
                //基本单位:G,替代单位:KG,换算因子:1000 => 1 KG = 1000 G
                uomConversion.BaseQty = decimal.Parse(dssImportHistory[4]);//换算因子
                uomConversion.AlterQty = 1;
            }

            return uomConversion;
        }
        protected override void FillDssImportHistory(string[] lineData, DssImportHistory dssImportHistory)
        {
            if (lineData != null && lineData.Length > 0 && dssImportHistory != null)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (lineData[i] == "?")
                        lineData[i] = null;
                    else
                        dssImportHistory[i] = lineData[i];
                }

                dssImportHistory[5] = lineData[55];//P/M类型

                dssImportHistory[6] = lineData[74];//BOM
                dssImportHistory[7] = lineData[75];//Routing

                if (dssImportHistory[2] != null)
                    dssImportHistory[2] = dssImportHistory[2].ToUpper();//单位
            }
        }
        private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            string key = dssImportHistory[1]; //代码

            //计量单位
            if (key.Trim().ToUpper() == "PT_UM")
            {
                Uom uom = new Uom();
                uom.Code = dssImportHistory[2];//计量单位
                if (isUpdate)
                {
                    uom.Name = dssImportHistory[3];//名称
                    uom.Description = dssImportHistory[3];//描述
                }
                return uom;
            }
            else
            {
                throw new BusinessErrorException("Common.Business.Error.EntityNotExist", key);
            }
        }
 protected override object DeserializeForDelete(DssImportHistory dssImportHistory)
 {
     return dssImportHistory;
 }
 public virtual void DeleteDssImportHistory(DssImportHistory entity)
 {
     entityDao.DeleteDssImportHistory(entity);
 }
        private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            PriceListDetail priceListDetail = new PriceListDetail();

            PriceList priceList = priceListMgr.LoadPriceList(dssImportHistory[1].Trim());
            if (priceList != null)
            {
                priceListDetail.PriceList = priceList;
            }
            else
            {
                Party party = partyMgr.CheckAndLoadParty(dssImportHistory[1].Trim());
                Supplier supplier = supplierMgr.LoadSupplier(dssImportHistory[1].Trim());
                if (supplier != null)
                {
                    priceListDetail.PriceList = this.LoadPurchasePriceList(dssImportHistory[1], party);//采购价格单
                }
                else
                {
                    priceListDetail.PriceList = this.LoadSalesPriceList(dssImportHistory[1], party);//销售价格单
                }

            }

            priceListDetail.Currency = this.currencyMgr.CheckAndLoadCurrency(dssImportHistory[2]);//货币
            priceListDetail.Item = this.itemMgr.CheckAndLoadItem(dssImportHistory[3]);//零件号
            priceListDetail.Uom = this.uomMgr.CheckAndLoadUom(dssImportHistory[4]);//单位
            priceListDetail.StartDate = dssImportHistory[6] != null ? DssHelper.GetDate(dssImportHistory[6], BusinessConstants.DSS_SYSTEM_CODE_QAD) : DateTime.Now;//开始日期
            if (isUpdate)
            {
                priceListDetail.UnitPrice = decimal.Parse(dssImportHistory[5]);//单价
                if (dssImportHistory[7] != null) priceListDetail.EndDate = DssHelper.GetDate(dssImportHistory[7], BusinessConstants.DSS_SYSTEM_CODE_QAD);//结束日期
            }

            #region 默认值
            priceListDetail.TaxCode = string.Empty;//todo
            priceListDetail.IsIncludeTax = false;
            priceListDetail.IsProvisionalEstimate = this.CheckProvisionalEstimate(priceListDetail.UnitPrice);
            #endregion

            return priceListDetail;
        }
 public virtual void CreateDssImportHistory(DssImportHistory entity)
 {
     entityDao.CreateDssImportHistory(entity);
 }
 public virtual void UpdateDssImportHistory(DssImportHistory entity)
 {
     entityDao.UpdateDssImportHistory(entity);
 }
Example #14
0
        private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            Item item = new Item();
            item.Code = dssImportHistory[1]; //零件号
            if (isUpdate)
            {
                item.Uom = this.uomMgr.CheckAndLoadUom(dssImportHistory[2].ToUpper());//单位
                item.Desc1 = dssImportHistory[3];//描述1
                item.Desc2 = dssImportHistory[4];//描述2

                 item.Type = this.GetItemType(dssImportHistory[5], BusinessConstants.DSS_SYSTEM_CODE_QAD);//P/M类型
                if (dssImportHistory[6] != null && dssImportHistory[6].Trim() != string.Empty)
                {
                    item.Bom = this.bomMgr.CheckAndLoadBom(dssImportHistory[6]); //BOM
                }
                if (dssImportHistory[7] != null && dssImportHistory[7].Trim() != string.Empty)
                {
                    item.Routing = this.routingMgr.CheckAndLoadRouting(dssImportHistory[7]);//Routing
                }
                if (dssImportHistory[8] != null && dssImportHistory[8].Trim() != string.Empty)
                {
                    item.Category = dssImportHistory[8].Substring(1, 1);//Category
                    item.Plant = dssImportHistory[8].Substring(0, 1);//plant
                }
                if (dssImportHistory[9] != null && dssImportHistory[9].Trim() != string.Empty)
                {
                    item.IsActive = dssImportHistory[9].Trim().ToUpper() == "A" ? true : false;
                }
                if (dssImportHistory[12] != null && dssImportHistory[12].Trim() != string.Empty
                    && dssImportHistory[12].Trim().ToUpper() == "TL")
                {
                    item.BackFlushMethod = BusinessConstants.CODE_MASTER_BACKFLUSH_METHOD_VALUE_BATCH_FEED;
                }
                else
                {
                    item.BackFlushMethod = BusinessConstants.CODE_MASTER_BACKFLUSH_METHOD_VALUE_GOODS_RECEIVE;
                }
            }

            #region 默认值
            item.UnitCount = 1;
            item.LastModifyUser = this.userMgr.GetMonitorUser();
            item.LastModifyDate = DateTime.Now;
            #endregion

            return item;
        }
Example #15
0
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            HSSFWorkbook excel = new HSSFWorkbook(fileUpload.PostedFile.InputStream);
            Sheet sheet = excel.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();
            ImportHelper.JumpRows(rows, 10);
            //生产线	物料号	物料描述	条码	数量	上线日期	上线时间	生产单号

            #region 列定义
            int colProdLine = 1;//供货路线
            int colItemCode = 2;//物料号
            int colHuId = 4;// 条码号
            int colQty = 5;//订单数
            int colOfflineDateStr = 6;//上线日期
            int colOfflineTimeStr = 7;//上线时间
            int colOrderNo = 8;//生产单号
            #endregion
            int rowCount = 10;
            //IList<Exception> exceptionList = new List<Exception>();
            //Exception exceptio = new Exception();
            string errorMessage = string.Empty;
            DateTime nowTime = DateTime.Now;
            DssInboundControl control=TheGenericMgr.FindById<DssInboundControl>(9);
            IList<DssImportHistory> importList = new List<DssImportHistory>();
            while (rows.MoveNext())
            {
                rowCount++;
                HSSFRow row = (HSSFRow)rows.Current;
                if (!TheImportMgr.CheckValidDataRow(row, 1, 4))
                {
                    break;//边界
                }
                string prodLineCode = string.Empty;
                Item Item =null;
                string huId = string.Empty;
                decimal qty = 0;
                string offlineDateStr = string.Empty;
                string offlineTimeStr = string.Empty;
                string orderNo = string.Empty;

                #region 读取数据
                #region 生产线
                prodLineCode = row.GetCell(colProdLine) != null ? row.GetCell(colProdLine).StringCellValue : string.Empty;
                if (string.IsNullOrEmpty(prodLineCode))
                {
                    //ShowErrorMessage(string.Format("第{0}行:供货路线不能为空。", rowCount));
                    errorMessage += string.Format("第{0}行:生产线不能为空。<br/>", rowCount);
                    continue;
                }
                #endregion

                #region 读取物料代码
                string itemCode = row.GetCell(colItemCode) != null ? row.GetCell(colItemCode).StringCellValue : string.Empty;
                if (itemCode == null || itemCode.Trim() == string.Empty)
                {
                    errorMessage += string.Format("第{0}行:物料代码不能为空。<br/>", rowCount);
                    //ShowErrorMessage(string.Format("第{0}行:物料代码不能为空。", rowCount));
                    continue;
                }
                else
                {
                    Item = this.TheGenericMgr.FindById<Item>(itemCode);
                    if (Item==null)
                    {
                        errorMessage += string.Format("第{0}行:物料代码{1}不存在。<br/>", rowCount, itemCode);
                        continue;
                    }
                }

                #endregion

                #region 条码
                huId = row.GetCell(colHuId) != null ? row.GetCell(colHuId).StringCellValue : string.Empty;
                if (string.IsNullOrEmpty(huId))
                {
                    errorMessage += string.Format("第{0}行:条码不能为空。<br/>", rowCount);
                    continue;
                }
                else
                {
                    if (huId.Length < 9)
                    {
                        errorMessage += string.Format("第{0}行:条码长度不能小于9。<br/>", rowCount);
                        continue;
                    }
                    var yearCodeArr =new string[]{"1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","S","T","V","W","X","Y"};
                    var monthCodeArr =new string[]{"1","2","3","4","5","6","7","8","9","A","B","C"};
                    var yearCode = huId.Substring(huId.Length - 8, 1);
                    if (yearCodeArr.Where(a => a == yearCode).Count() == 0)
                    {
                        errorMessage += string.Format("第{0}行:批号的年份格式不正确。。<br/>", rowCount);
                        continue;
                    }

                    var monthCode = huId.Substring(huId.Length - 7, 1);
                    if (monthCodeArr.Where(a => a == monthCode).Count() == 0)
                    {
                        errorMessage += string.Format("第{0}行:批号的月份格式不正确。。。<br/>", rowCount);
                        continue;
                    }

                    var dayCode =int.Parse( huId.Substring(huId.Length - 6, 2));
                    if (dayCode<1 || dayCode>31)
                    {
                        errorMessage += string.Format("第{0}行:批号的日期格式不正确。<br/>", rowCount);
                        continue;
                    }
                }
                #endregion

                #region 读取数量
                try
                {
                    qty = Convert.ToDecimal(row.GetCell(colQty).NumericCellValue);
                }
                catch
                {
                    errorMessage += string.Format("第{0}行:数量填写有误。<br/>", rowCount);
                    continue;
                }
                #endregion

                #region 上线日期
                offlineDateStr = row.GetCell(colOfflineDateStr) != null ? row.GetCell(colOfflineDateStr).StringCellValue : string.Empty;
                if (string.IsNullOrEmpty(offlineDateStr))
                {
                    errorMessage += string.Format("第{0}行:上线日期不能为空。<br/>", rowCount);
                    continue;
                }
                #endregion

                #region 上线时间
                offlineTimeStr = row.GetCell(colOfflineTimeStr) != null ? row.GetCell(colOfflineTimeStr).StringCellValue : string.Empty;
                if (string.IsNullOrEmpty(offlineTimeStr))
                {
                    errorMessage += string.Format("第{0}行:上线时间不能为空。<br/>", rowCount);
                    continue;
                }
                else
                {
                    try
                    {
                        var offlineDateTime = DateTime.Parse(offlineDateStr + " " + offlineTimeStr);
                    }
                    catch (Exception ex)
                    {
                        errorMessage += string.Format("第{0}行:[上线日期{1}+上线时间{2}]不符合要求。<br/>", rowCount, offlineDateStr, offlineTimeStr);
                        continue;
                    }
                }
                #endregion

                #region 生产线
                orderNo = row.GetCell(colOrderNo) != null ? row.GetCell(colOrderNo).StringCellValue : string.Empty;
                if (string.IsNullOrEmpty(orderNo))
                {
                    errorMessage += string.Format("第{0}行:生产单号不能为空。<br/>", rowCount);
                    continue;
                }
                #endregion
                #endregion

                #region 填充数据
                DssImportHistory dssImportHistory = new DssImportHistory {
                    data0=prodLineCode,
                    data1=Item.Code,
                    data2=huId,
                    data3=qty.ToString(),
                    data7=offlineDateStr,
                    data8=offlineTimeStr,
                    data12=orderNo,
                    IsActive=true,
                    ErrorCount=0,
                    CreateDate = nowTime,
                    LastModifyDate = nowTime,
                    LastModifyUser=CurrentUser.Code,
                    DssInboundCtrl = control,
                    EventCode = "CREATE",
                    KeyCode="EXCEL",
                };
                importList.Add(dssImportHistory);

                #endregion
            }
            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new Exception(errorMessage);
            }
            if (importList.Count == 0)
            {
                throw new Exception("导入的有效数据为0.");
            }

            //try
            //{
            //    foreach (var dssImpHis in importList)
            //    {
            //        TheGenericMgr.Create(dssImpHis);
            //    }
            //}
            //catch (Exception ex)
            //{

            //    throw ex;
            //}

            TheMaterialFlushBackMgr.ImportProdItemHuId(importList);

            ShowSuccessMessage("导入成功。");
        }
        catch (BusinessErrorException ex)
        {
            ShowErrorMessage(ex);
        }
        catch (Exception ex)
        {
            ShowErrorMessage(ex.Message);
            return;
        }
    }
 protected override void FillDssImportHistory(string[] lineData, DssImportHistory dssImportHistory)
 {
     if (lineData != null && lineData.Length > 0 && dssImportHistory != null)
     {
         for (int i = 0; i < 4; i++)
         {
             dssImportHistory[i] = lineData[i].ToUpper();
         }
         if (lineData[1].ToUpper() == "YFK")
         {
             dssImportHistory.IsActive = false;
         }
     }
 }
 protected virtual void FillDssImportHistory(string[] lineData, DssImportHistory dssImportHistory)
 {
     if (lineData != null && lineData.Length > 0 && dssImportHistory != null)
     {
         for (int i = 0; i < lineData.Length; i++)
         {
             if (lineData[i] == "?")
                 lineData[i] = null;
             else
                 dssImportHistory[i] = lineData[i];
             //log.Debug("Read Data[" + i + "]: " + lineData[i]);
         }
     }
 }
 protected override object DeserializeForDelete(DssImportHistory dssImportHistory)
 {
     return this.Deserialize(dssImportHistory, false);
 }
        private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            Item bomItem = this.itemMgr.CheckAndLoadItem(dssImportHistory[1]);//bom头
            Item item = this.itemMgr.CheckAndLoadItem(dssImportHistory[2]);//零件号
            if (item.IsMes && bomItem.IsMes)
            {
                MesBomDetail mesBomDetail = new MesBomDetail();
                mesBomDetail.Bom = this.LoadMesBom(dssImportHistory[1]);//Bom代码
                mesBomDetail.Item = item;

                mesBomDetail.StartDate = dssImportHistory[4] != null ?
                    DssHelper.GetDate(dssImportHistory[4], BusinessConstants.DSS_SYSTEM_CODE_QAD) : new DateTime(2000, 1, 1);

                if (isUpdate)
                {
                    mesBomDetail.RateQty = decimal.Parse(dssImportHistory[5]);//用量
                    mesBomDetail.StructureType = this.GetStructureType(dssImportHistory[6], BusinessConstants.DSS_SYSTEM_CODE_QAD);//类型

                    if (dssImportHistory[8] != null) mesBomDetail.EndDate = DssHelper.GetDate(dssImportHistory[8], BusinessConstants.DSS_SYSTEM_CODE_QAD);//结束日期
                }
                return mesBomDetail;
            }
            else
            {
                BomDetail bomDetail = new BomDetail();
                bomDetail.Bom = this.LoadBom(dssImportHistory[1]);//Bom代码
                bomDetail.Item = item;//零件号
                bomDetail.Reference = dssImportHistory[3];//参考
                bomDetail.StartDate = dssImportHistory[4] != null ?
                    DssHelper.GetDate(dssImportHistory[4], BusinessConstants.DSS_SYSTEM_CODE_QAD) : new DateTime(2000, 1, 1);

                if (isUpdate)
                {
                    bomDetail.RateQty = decimal.Parse(dssImportHistory[5]);//用量
                    bomDetail.StructureType = this.GetStructureType(dssImportHistory[6], BusinessConstants.DSS_SYSTEM_CODE_QAD);//类型

                    if (dssImportHistory[8] != null) bomDetail.EndDate = DssHelper.GetDate(dssImportHistory[8], BusinessConstants.DSS_SYSTEM_CODE_QAD);//结束日期

                    //回冲方式从零件上取
                    bomDetail.BackFlushMethod = bomDetail.Item.BackFlushMethod;
                    bomDetail.ScrapPercentage = decimal.Parse(dssImportHistory[10]) / 100;//废品百分比

                    bomDetail.Operation = int.Parse(dssImportHistory[12]);

                }

                #region 默认值
                bomDetail.Uom = bomDetail.Item.Uom;
                bomDetail.Priority = 0;
                bomDetail.NeedPrint = true;
                bomDetail.IsShipScanHu = false;

                #endregion

                return bomDetail;
            }
        }
        public virtual void ProcessInboundFile(DssInboundControl dssInboundControl, string[] files)
        {
            log.Info("Start process inbound ");

            //重新提交数据
            IList<DssImportHistory> activeDssImportHistoryList = dssImportHistoryMgrE.GetActiveDssImportHistory(dssInboundControl.Id);

            #region DataReader
            IList<DssImportHistory> dssImportHistoryList = new List<DssImportHistory>();
            foreach (string fileName in files)
            {
                try
                {
                    FlatFileReader reader = null;
                    try
                    {
                        DssImportHistory dssImportHistory = new DssImportHistory();
                        dssImportHistory.DssInboundCtrl = dssInboundControl;
                        dssImportHistory.IsActive = true;
                        dssImportHistory.KeyCode = Path.GetFileNameWithoutExtension(fileName);
                        dssImportHistory.CreateDate = DateTime.Now;

                        reader = this.DataReader(fileName, Encoding.GetEncoding(dssInboundControl.FileEncoding), "|");
                        for (string[] lineData = reader.ReadLine(); lineData != null; lineData = reader.ReadLine())
                        {
                            this.FillDssImportHistory(lineData, dssImportHistory);

                            if (dssImportHistory[0] == "0")
                            {
                                dssImportHistory.EventCode = BusinessConstants.DSS_EVENT_CODE_DELETE;
                                DssHelper.FormatDeleteData(lineData, BusinessConstants.DSS_SYSTEM_CODE_QAD);//QAD删除去引号
                            }
                            else
                            {
                                dssImportHistory.EventCode = BusinessConstants.DSS_EVENT_CODE_CREATE;
                            }
                        }

                        dssImportHistoryList.Add(dssImportHistory);
                    }
                    catch (Exception ex)
                    {
                        reader.Dispose();
                        log.Error("Process inbound file: " + fileName + " Error.", ex);
                        throw ex;
                    }
                    finally
                    {
                        reader.Dispose();
                        log.Info("Process inbound file: " + fileName + " successful.");
                    }
                }
                catch (Exception ex)
                {

                    log.Error("Create DssImportHistory error:", ex);
                }
            }
            #endregion

            #region CreateDssImportHistory
            CreateDssImportHistory(dssInboundControl, dssImportHistoryList, files);
            #endregion

            #region Archive download file
            try
            {
                ArchiveFile(files, dssInboundControl.ArchiveFloder);
            }
            catch (Exception ex)
            {
                log.Error("Archive download file error:", ex);
            }
            #endregion

            IListHelper.AddRange<DssImportHistory>(activeDssImportHistoryList, dssImportHistoryList);

            IList<object> objCreate = this.ProcessCreateData(activeDssImportHistoryList);
            IList<object> objDelete = this.ProcessDeleteData(activeDssImportHistoryList);

            try
            {
                this.CreateOrUpdateObject(objCreate);
                this.DeleteObject(objDelete);

                //山寨,先把除工单的全部更新active为false,以免每次都随工单执行
                if(dssInboundControl.Id != 9)
                {
                    foreach(DssImportHistory dssImpHis in activeDssImportHistoryList)
                    {
                        dssImpHis.IsActive = false;
                        dssImportHistoryMgrE.UpdateDssImportHistory(dssImpHis);
                    }
                
                }
            }
            catch (Exception ex)
            {
                log.Error("Write to database error:", ex);
            }
        }
Example #21
0
        private void ProcessOrderIn(MesScmsTableIndex mesScmsTableIndex)
        {
            if (mesScmsTableIndex.TableName == MesDssConstants.MES_SCMS_TABLEINDEX_TABLE_NAME_MES_SCMS_COMPLETED_ORDER)
            {
                IList<MesScmsCompletedOrder> orderList = mesScmsCompletedOrderMgr.GetUpdateMesScmsCompletedOrder();
                if (orderList != null && orderList.Count > 0)
                {
                    foreach (MesScmsCompletedOrder mesScmsCompletedOrder in orderList)
                    {

                        try
                        {
                            if (mesScmsCompletedBoxMgr.GetMesScmsCompletedBox(mesScmsCompletedOrder.OrderNo) > 0) continue;
                            orderMgr.ManualCompleteOrder(mesScmsCompletedOrder.OrderNo, userMgr.GetMonitorUser());
                            mesScmsCompletedOrderMgr.Complete(mesScmsCompletedOrder);

                        }
                        catch (Exception e)
                        {
                            this.CleanSession();
                            log.Error(mesScmsCompletedOrder.OrderNo + " complete exception", e);
                            continue;
                        }
                    }
                }
            }
            else if (mesScmsTableIndex.TableName == MesDssConstants.MES_SCMS_TABLEINDEX_TABLE_NAME_MES_SCMS_COMPLETED_BOX)
            {
                IList<MesScmsCompletedBox> huList = mesScmsCompletedBoxMgr.GetUpdateMesScmsCompletedBox();
                if (huList != null && huList.Count > 0)
                {
                    DateTime dateTimeNow = DateTime.Now;
                    DssInboundControl dssInboundControl = dssInboundControlMgr.LoadDssInboundControl(9);
                    foreach (MesScmsCompletedBox mesScmsCompletedBox in huList)
                    {
                        try
                        {
                            DssImportHistory dssImportHistory = new DssImportHistory();
                            dssImportHistory.DssInboundCtrl = dssInboundControl;
                            dssImportHistory.EventCode = "CREATE";
                            dssImportHistory.IsActive = true;
                            dssImportHistory.KeyCode = "MES";
                            dssImportHistory.ItemCode = mesScmsCompletedBox.ItemCode;
                            dssImportHistory.HuId = mesScmsCompletedBox.HuId;
                            dssImportHistory.Qty = (decimal)mesScmsCompletedBox.Qty;
                            dssImportHistory.CreateDate = DateTime.Now;
                            dssImportHistory.data1 = mesScmsCompletedBox.ItemCode;
                            dssImportHistory.data2 = mesScmsCompletedBox.HuId;
                            dssImportHistory.data3 = mesScmsCompletedBox.Qty.ToString();
                            dssImportHistory.data7 = dateTimeNow.ToString("MM/dd/yyyy");
                            dssImportHistory.data8 = dateTimeNow.ToString("HH:mm:ss");
                            dssImportHistory.data12 = mesScmsCompletedBox.OrderNo;
                            this.dssImportHistoryMgr.CreateDssImportHistory(dssImportHistory);

                            mesScmsCompletedBoxMgr.Complete(mesScmsCompletedBox);
                        }
                        catch (Exception e)
                        {
                            this.CleanSession();
                            log.Error(mesScmsCompletedBox.HuId + " complete exception", e);
                            continue;
                        }
                    }
                }
            }
            mesScmsTableIndexMgr.Complete(mesScmsTableIndex);
        }
 public virtual void DeleteDssImportHistory(DssImportHistory entity)
 {
     Delete(entity);
 }
 public virtual void UpdateDssImportHistory(DssImportHistory entity)
 {
     Update(entity);
 }
 public virtual void CreateDssImportHistory(DssImportHistory entity)
 {
     Create(entity);
 }
 protected override object DeserializeForCreate(DssImportHistory dssImportHistory)
 {
     return this.Deserialize(dssImportHistory);
 }
        private object Deserialize(DssImportHistory dssImportHistory)
        {
            Customer customer = new Customer();
            customer.Code = dssImportHistory[1].ToUpper();
            customer.Name = dssImportHistory[2];

            ShipAddress shipAddress = new ShipAddress();
            shipAddress.Code = "S_" + customer.Code.ToUpper();
            shipAddress.Address = dssImportHistory[3];
            shipAddress.ContactPersonName = dssImportHistory[12];
            shipAddress.TelephoneNumber = dssImportHistory[13] + dssImportHistory[14];
            shipAddress.Fax = dssImportHistory[15];
            shipAddress.MobilePhone = dssImportHistory[17] + dssImportHistory[18];
            shipAddress.PostalCode = dssImportHistory[8];
            shipAddress.Party = customer;

            BillAddress billAddress = new BillAddress();
            billAddress.Code = "B_"+customer.Code.ToUpper() ;
            billAddress.Address = dssImportHistory[3];
            billAddress.ContactPersonName = dssImportHistory[12];
            billAddress.TelephoneNumber = dssImportHistory[13] + dssImportHistory[14];
            billAddress.Fax = dssImportHistory[15];
            billAddress.MobilePhone = dssImportHistory[17] + dssImportHistory[18];
            billAddress.PostalCode = dssImportHistory[8];
            billAddress.Party = customer;

            IList<object> list = new List<object>();
            list.Add(customer);
            list.Add(shipAddress);
            list.Add(billAddress);
            return list;
        }
        public virtual void ReceiveWo(DssImportHistory dssImportHistory)
        {
            try
            {
                string prodLine = dssImportHistory.data0;
                string itemCode = dssImportHistory.data1;
                string huId = dssImportHistory.data2;
                decimal qty = decimal.Parse(dssImportHistory.data3);
                string itemHuId = dssImportHistory.data4;
                string onlineDate = dssImportHistory.data5;
                string onlineTime = dssImportHistory.data6;
                string offlineDate = dssImportHistory.data7;
                string offlineTime = dssImportHistory.data8;

                DateTime woOffTime = DateTime.Parse(offlineDate);
                string[] timeArr = offlineTime.Split(':');
                if (timeArr == null && timeArr.Length != 3)
                {
                    log.Error("Error date format" + offlineTime);
                    dssImportHistory.Memo = "Error date format" + offlineTime;
                    dssImportHistory.ErrorCount++;
                    this.dssImportHistoryMgr.UpdateDssImportHistory(dssImportHistory);
                    return;
                }
                DateTime woTime = woOffTime.AddHours(double.Parse(timeArr[0])).AddMinutes(double.Parse(timeArr[1])).AddSeconds(double.Parse(timeArr[2]));

                string customerCode = dssImportHistory.data9;
                string customerLoc = dssImportHistory.data10;

                if (this.huMgr.LoadHu(huId) != null)
                {
                    log.Error("Hu " + huId + " already exist in database.");
                    dssImportHistory.Memo = "Hu " + huId + " already exist in database.";
                    dssImportHistory.ErrorCount++;
                    this.dssImportHistoryMgr.UpdateDssImportHistory(dssImportHistory);

                    return;
                }

                #region 查找工单
                //shiftCode = BarcodeHelper.GetShiftCode(huId);
                DetachedCriteria criteria = DetachedCriteria.For<OrderDetail>();
                criteria.CreateAlias("OrderHead", "od");
               // criteria.CreateAlias("od.Flow", "f");
                criteria.CreateAlias("Item", "i");
                //criteria.CreateAlias("Shift", "s");

                criteria.Add(Expression.Like("od.Flow", prodLine, MatchMode.End));
                criteria.Add(Expression.Eq("i.Code", itemCode));
                //criteria.Add(Expression.Eq("s.Code", shiftCode));
                criteria.Add(Expression.Eq("od.Type", BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION));
                criteria.Add(Expression.Eq("od.Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS));
                criteria.Add(Expression.Le("od.StartTime", woTime));
                criteria.Add(Expression.Ge("od.WindowTime", woTime));

                criteria.AddOrder(Order.Asc("od.StartTime"));

                IList<OrderDetail> orderDetailList = this.criteriaMgr.FindAll<OrderDetail>(criteria);

                OrderDetail orderDetail = null;
                if (orderDetailList != null && orderDetailList.Count > 0)
                {
                    for (int i = 0; i < orderDetailList.Count; i++)
                    {
                        orderDetail = orderDetailList[i];
                        if (orderDetail.ReceivedQty == null || orderDetail.OrderedQty > (decimal)orderDetail.ReceivedQty)
                        {
                            break;
                        }
                    }

                    log.Info("Find match wo " + orderDetail.OrderHead.OrderNo);
                }
                else
                {
                    FlowDetail flowDetail = this.LoadFlowDetail(prodLine, itemCode);
                    if (flowDetail != null)
                    {
                        OrderHead orderHead = this.orderManager.TransferFlow2Order(flowDetail.Flow);
                        orderDetail = orderHead.OrderDetails.SingleOrDefault(o => flowDetail.Equals(o.FlowDetail));
                        orderHead.StartTime = woTime.AddHours(-12);
                        orderHead.WindowTime = woTime.AddHours(12);
                        orderHead.Priority = BusinessConstants.CODE_MASTER_ORDER_PRIORITY_VALUE_NORMAL;
                        orderDetail.RequiredQty = qty;
                        orderDetail.OrderedQty = qty;
                        OrderHelper.FilterZeroOrderQty(orderHead);
                        this.orderManager.CreateOrder(orderHead, this.userMgr.GetMonitorUser());
                        log.Info("Find match wo " + orderHead.OrderNo);
                    }
                }

                if (orderDetail != null)
                {
                    this.FlushSession();
                    this.CleanSession();
                    this.orderManager.DoReceiveWO(huId, orderDetail, qty);
                    dssImportHistory.IsActive = false;
                    this.dssImportHistoryMgr.UpdateDssImportHistory(dssImportHistory);
                }
                else
                {
                    log.Error("No item found for item code " + itemCode + " for prodline + " + prodLine);
                    dssImportHistory.Memo = "No item found for item code " + itemCode + " for prodline + " + prodLine;
                    dssImportHistory.ErrorCount++;
                    this.dssImportHistoryMgr.UpdateDssImportHistory(dssImportHistory);
                }
                #endregion
            }
            catch (Exception ex)
            {
                this.CleanSession();
                log.Error("Receive WO Error.", ex);
                dssImportHistory.Memo = ex.Message;
                dssImportHistory.ErrorCount++;
                this.dssImportHistoryMgr.UpdateDssImportHistory(dssImportHistory);
            }
        }
        public virtual void ProcessInboundFile(DssInboundControl dssInboundControl, string[] files)
        {
            logLoadFile.Info("Start process inbound ");

            //重新提交数据
            #region DataReader
            foreach (string fileName in files)
            {
                try
                {
                    IList<DssImportHistory> dssImportHistoryList = new List<DssImportHistory>();

                    #region 读取文件
                    logLoadFile.Info("Start load file " + fileName);
                    FlatFileReader reader = null;
                    try
                    {
                        DssImportHistory dssImportHistory = new DssImportHistory();
                        dssImportHistory.DssInboundCtrl = dssInboundControl;
                        dssImportHistory.IsActive = true;
                        dssImportHistory.KeyCode = Path.GetFileNameWithoutExtension(fileName);
                        dssImportHistory.CreateDate = DateTime.Now;

                        reader = this.DataReader(fileName, Encoding.GetEncoding(dssInboundControl.FileEncoding), "|");
                        for (string[] lineData = reader.ReadLine(); lineData != null; lineData = reader.ReadLine())
                        {
                            this.FillDssImportHistory(lineData, dssImportHistory);

                            if (dssImportHistory[0] == "0")
                            {
                                dssImportHistory.EventCode = BusinessConstants.DSS_EVENT_CODE_DELETE;
                                DssHelper.FormatDeleteData(lineData, BusinessConstants.DSS_SYSTEM_CODE_QAD);//QAD删除去引号
                            }
                            else
                            {
                                dssImportHistory.EventCode = BusinessConstants.DSS_EVENT_CODE_CREATE;
                            }
                        }

                        dssImportHistoryList.Add(dssImportHistory);
                    }
                    catch (Exception ex)
                    {
                        reader.Dispose();
                        logLoadFile.Error("Process inbound file: " + fileName + " Error.", ex);
                        throw ex;
                    }
                    finally
                    {
                        reader.Dispose();
                        logLoadFile.Info("Process inbound file: " + fileName + " successful.");
                    }
                    logLoadFile.Info("End load file " + fileName);
                    #endregion

                    #region CreateDssImportHistory
                    logLoadFile.Info("Start save file" + fileName);
                    CreateDssImportHistory(dssInboundControl, dssImportHistoryList, files);
                    logLoadFile.Info("End save file" + fileName);
                    #endregion

                    #region Archive download file
                    try
                    {
                        logLoadFile.Info("Start backup file " + fileName);
                        ArchiveFile(new string[] { fileName }, dssInboundControl.ArchiveFloder);
                        logLoadFile.Info("End backup file" + fileName);
                    }
                    catch (Exception ex)
                    {
                        logLoadFile.Error("Archive download file error:", ex);
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    logLoadFile.Error("Create DssImportHistory error:", ex);
                }
            }
            #endregion
        }
 protected abstract object DeserializeForDelete(DssImportHistory dssImportHistory);
        private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            ItemReference itemReference = new ItemReference();

            if (isUpdate)
            {
                if (dssImportHistory[1] != null)
                {
                    itemReference.Party = partyMgr.CheckAndLoadParty(dssImportHistory[1]);
                }
                if (dssImportHistory[2] != null)
                {
                    itemReference.ReferenceCode = dssImportHistory[2];
                }
                if (dssImportHistory[3] != null)
                {
                    itemReference.Item = itemMgr.CheckAndLoadItem(dssImportHistory[3]);
                }
            }

            #region 默认值
            itemReference.IsActive = true;
            #endregion

            return itemReference;
        }