public virtual void ProcessSingleFile(string inboundDirectoryName, string inboundFileName) { log.Info("Start inbound file " + inboundFileName); FlatFileReader reader = new FlatFileReader(inboundFileName, Encoding.ASCII, "\t"); try { OrderHead orderHead = null; OrderDetail orderDetail = null; string shiftCode = string.Empty; Hu hu = null; string[] fields = reader.ReadLine(); while (fields != null) { string prodLine = fields[0]; string itemCode = fields[1]; string huId = fields[2]; decimal qty = decimal.Parse(fields[3]); string itemHuId = fields[4]; string onlineDate = fields[5]; string onlineTime = fields[6]; string offlineDate = fields[7]; string offlineTime = fields[8]; string customerCode = fields[9]; string customerLoc = fields[10]; if (orderHead == null) { #region 查找工单 shiftCode = BarcodeHelper.GetShiftCode(huId); DetachedCriteria criteria = DetachedCriteria.For <OrderHead>(); criteria.CreateAlias("Flow", "f"); //criteria.CreateAlias("Shift", "s"); criteria.Add(Expression.Like("f.Code", prodLine, MatchMode.End)); criteria.Add(Expression.Eq("s.Code", shiftCode)); criteria.Add(Expression.Eq("Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS)); criteria.AddOrder(Order.Asc("StartTime")); IList <OrderHead> orderHeadList = this.criteriaMgr.FindAll <OrderHead>(criteria); #endregion if (orderHeadList != null && orderHeadList.Count > 0) { foreach (OrderHead targetOrderHead in orderHeadList) { orderHead = targetOrderHead; #region 查找工单明细 IList <OrderDetail> orderDetailList = orderHead.OrderDetails; foreach (OrderDetail targetOrderDetail in orderDetailList) { if (targetOrderDetail.Item.Code == itemCode) { log.Info("Find match wo " + orderHead.OrderNo); orderDetail = targetOrderDetail; orderDetail.CurrentReceiveQty = qty; break; } } #endregion if (orderDetail != null) { break; } } } else { throw new BusinessErrorException("No active wo find for prodline + " + prodLine + ", shift " + shiftCode); } if (orderDetail != null) { #region 创建外包装条码 if (this.huMgr.LoadHu(huId) == null) { log.Info("Insert hu " + huId + " into database."); hu = ResolveAndCreateHu(huId, orderDetail, qty); orderDetail.HuId = hu.HuId; Receipt receipt = new Receipt(); ReceiptDetail receiptDetail = new ReceiptDetail(); receiptDetail.OrderLocationTransaction = this.orderLocationTransactionMgr.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_IN)[0]; receiptDetail.HuId = hu.HuId; receiptDetail.ReceivedQty = qty; receiptDetail.Receipt = receipt; receiptDetail.LotNo = hu.LotNo; #region 找Out的OrderLocTrans,填充MaterialFulshBack IList <OrderLocationTransaction> orderLocTransList = this.orderLocationTransactionMgr.GetOrderLocationTransaction(orderDetail.Id, BusinessConstants.IO_TYPE_OUT); foreach (OrderLocationTransaction orderLocTrans in orderLocTransList) { MaterialFlushBack material = new MaterialFlushBack(); material.OrderLocationTransaction = orderLocTrans; if (orderLocTrans.UnitQty != 0) { material.Qty = qty; } receiptDetail.AddMaterialFlushBack(material); } #endregion receipt.AddReceiptDetail(receiptDetail); this.orderManager.ReceiveOrder(receipt, this.userMgr.GetMonitorUser()); } else { throw new BusinessErrorException("Hu " + huId + " already exist in database."); } #endregion } else { throw new BusinessErrorException("No item found for item code " + itemCode + " for prodline + " + prodLine + ", shift " + shiftCode); } } #region 创建内包装条码 if (this.huMgr.LoadHu(itemHuId) == null) { log.Info("Insert hu " + itemHuId + " into database."); CreateItemHu(itemHuId, orderDetail, hu.LotNo, hu.ManufactureDate); } else { throw new BusinessErrorException("Hu " + itemHuId + " already exist in database."); } #endregion fields = reader.ReadLine(); } } finally { reader.Dispose(); } }
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 }