public virtual void ProcessInboundFile(InboundControl InboundControl, string[] files) { //log.Info("Start process inbound "); // IList<FormatControl> lenArray = this.genericMgr.FindAll<FormatControl>("from FormatControl f where f.SystemCode=? order by Sequence asc", InboundControl.SystemCode); foreach (var fileName in files) { try { this.LESINbound(InboundControl, fileName); this.genericMgr.FlushSession(); //log.Info(fileName + " successful."); ArchiveFile(fileName, InboundControl.ArchiveFloder); } catch (Exception ex) { this.genericMgr.CleanSession(); try { ArchiveFile(fileName, InboundControl.ErrorFloder); //log.Info(" file success: " + fileName, ex); } catch (Exception) { log.Error(" file error: " + fileName + "存档失败。"); } } } }
private void LESINbound(InboundControl InboundControl, string fileName) { bool noError = true; try { string[] datStrs = System.IO.File.ReadAllLines(fileName); if (datStrs.Length == 0) { throw new BusinessException("文件为空。"); } fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1); string[] datStr = new string[datStrs.Length - 1]; for (int i = 0; i < datStrs.Length; i++) { if (i > 0) { datStr[i - 1] = datStrs[i]; } } if (fileName.Substring(0, 4) == "MIGO") { //log.Info("开始读文件" + fileName); int rowCount = 0; #region 供应商采购 foreach (var datLine in datStr) //循环每一行 { rowCount++; var line = datLine.Split(new char[] { '\t' }).ToArray(); LesINLog lesInLog = new LesINLog(); try { try { #region Log IList<LesINLog> existsLesInLogList = this.genericMgr.FindAll<LesINLog>("select l from LesINLog as l where l.WMSNo=? and HandResult='S'", (string)line[20]); if (existsLesInLogList != null && existsLesInLogList.Count > 0) { #region LES中已经存在相同的WMS号 并且成功处理 existsLesInLogList.First().IsCreateDat = false; this.genericMgr.Update(existsLesInLogList.First()); continue; #endregion } lesInLog.Type = "MIGO"; lesInLog.MoveType = (string)line[0] + (line[10] == string.Empty ? string.Empty : line[10].ToUpper()); lesInLog.Sequense = ""; lesInLog.PO = (string)line[3];// lesInLog.POLine = (string)line[4];// lesInLog.WMSNo = (string)line[20]; lesInLog.WMSLine = (string)line[21]; lesInLog.Item = (string)line[11]; lesInLog.HandResult = "S"; lesInLog.FileName = fileName; lesInLog.HandTime = System.DateTime.Now;// System.DateTime.Now.ToString("yyMMddHHmmss"); lesInLog.IsCreateDat = false; lesInLog.ASNNo = line[17]; lesInLog.ExtNo = (string)line[3]; #endregion if (line[11] == null || line[11] == string.Empty) { throw new BusinessException("Item is Empty!"); } if (line[17] == null || line[17] == string.Empty) { throw new BusinessException("IpNo is Empty!"); } if (line[0] == "102") { #region 冲销 IList<ReceiptDetail> receiptDetailList = this.genericMgr.FindAll<ReceiptDetail>("select r from ReceiptDetail as r where r.IpNo=? and r.Item=? and r.ExternalOrderNo=? and r.ExternalSequence=" + Convert.ToInt32(line[4]) + "", new object[] { line[17], line[11], line[3] }); ReceiptMaster receiptMstr = this.genericMgr.FindById<ReceiptMaster>(receiptDetailList.First().ReceiptNo); //更新收货单的wms号为冲销记录的行号 receiptMstr.WMSNo = (string)line[20]; receiptMgr.CancelReceipt(receiptMstr, System.DateTime.Now); lesInLog.PO = receiptMstr.ReceiptNo; #endregion } else { #region 正常收货 IList<IpDetail> datIpdetailList = new List<IpDetail>(); if (line[12] == null || line[12] == string.Empty) { throw new BusinessException("Qty is Empty!"); } IList<IpDetail> ipDetails = this.genericMgr.FindAll<IpDetail>("select i from IpDetail as i where i.IpNo=? and i.Item=? and i.ExternalOrderNo=? and i.ExternalSequence=" + Convert.ToInt32(line[4]) + "", new object[] { line[17], line[11], line[3] }); if (ipDetails == null || ipDetails.Count == 0) { throw new BusinessException("此ASN{0}物料{1},PO号{2},PO行号{3}找不到对应明细", line[17], line[11], line[3], line[4]); } decimal remianReceivedQty = Convert.ToDecimal(line[12].ToString());//数量 //单位换算 if (line[13].ToUpper() != ipDetails.First().Uom.ToUpper()) { remianReceivedQty = remianReceivedQty / ipDetails.First().UnitQty; } ipDetails.First().BWART = line[0] + (line[10] == string.Empty ? string.Empty : line[10].ToUpper());//移动类型 if (ipDetails.First().IpDetailInputs == null) { ipDetails.First().IpDetailInputs = new List<Entity.ORD.IpDetailInput>(); ipDetails.First().AddIpDetailInput(new Entity.ORD.IpDetailInput()); ipDetails.First().IpDetailInputs.Single().WMSRecNo = (string)line[20]; } ipDetails.First().IpDetailInputs.Single().ReceiveQty += remianReceivedQty; datIpdetailList.Add(ipDetails.First()); if (datIpdetailList != null && datIpdetailList.Count > 0) { ReceiptMaster recMaster = orderMgr.ReceiveIp(datIpdetailList); lesInLog.PO = recMaster.ReceiptNo; } #endregion } } catch (BusinessException ex) { this.genericMgr.CleanSession(); lesInLog.HandResult = "F"; lesInLog.ErrorCause = ex.GetMessages()[0].GetMessageString(); noError = false; } } catch (Exception ex) { this.genericMgr.CleanSession(); lesInLog.HandResult = "F"; lesInLog.ErrorCause = ex.Message; noError = false; } #region 更新或插入Log IList<LesINLog> lesLogList = new List<LesINLog>(); lesLogList = this.genericMgr.FindAll<LesINLog>("select l from LesINLog as l where l.WMSNo=?", lesInLog.WMSNo); if (lesLogList != null && lesLogList.Count > 0) { #region 如果已存在记录的状态为失败时根据当前执行情况更新此记录 if (lesLogList.First().HandResult == "F") { lesLogList.First().HandResult = lesInLog.HandResult; lesLogList.First().IsCreateDat = false; lesLogList.First().HandTime = lesInLog.HandTime; lesLogList.First().FileName = lesInLog.FileName; lesLogList.First().ErrorCause = lesInLog.ErrorCause; lesLogList.First().Item = lesInLog.Item; lesLogList.First().ExtNo = lesInLog.ExtNo; lesLogList.First().PO = lesInLog.PO; this.genericMgr.Update(lesLogList.First()); } #endregion #region 如果已存在记录为成功则不处理,但需要重发反馈信息给安吉,可以避免安吉不断重发 else { lesLogList.First().IsCreateDat = false; } #endregion } else { this.genericMgr.Create(lesInLog); } #endregion } // } #endregion if (rowCount < datStr.Length) { throw new BusinessException("文件读取行数不对,处理失败。"); } //log.Info("文件" + fileName + "读完成功。"); } else if (fileName.Substring(0, 4) == "MB1B") { //log.Info("开始读文件" + fileName); int rowCount = 0; #region 安吉移库 var Query = from dat in datStr let x = dat.Split(new char[] { '\t' }).ToArray() select x; foreach (var line in Query) { rowCount++; WMSDatFile newMSDatFile = new WMSDatFile(); try { #region IList<WMSDatFile> ExitxswmsDatFile = this.genericMgr.FindAll<WMSDatFile>("select w from WMSDatFile as w where w.WMSId=?", line[20]); if (ExitxswmsDatFile != null && ExitxswmsDatFile.Count > 0) { #region 通过 WMSId 如果存在中间表中 过滤掉 continue; //if (ExitxswmsDatFile.First().IsHand) //{ // #region 已经处理 // IList<LesINLog> exitxLesLog = this.genericMgr.FindAll<LesINLog>("select l from LesINLog as l where l.WMSNo=?", ExitxswmsDatFile.First().WMSId); // if (exitxLesLog.First().HandResult == "S") // { // #region 已经成功处理的重新发送Log // if (exitxLesLog.First().IsCreateDat)//已经创建logDAT // { // exitxLesLog.First().IsCreateDat = false; // this.genericMgr.Update(exitxLesLog.First()); // continue; // } // continue; // #endregion // } // else // { // #region 处理失败的更新中间表数据 // newMSDatFile = this.GetWMSDatFile(line, fileName); // newMSDatFile.Id = ExitxswmsDatFile.First().Id; // newMSDatFile.IsHand = false; // this.genericMgr.Update(newMSDatFile); // continue; // #endregion // } // #endregion //} //else //{ // #region 没有处理过的 更新中间表的数据 // newMSDatFile = this.GetWMSDatFile(line, fileName); // newMSDatFile.Id = ExitxswmsDatFile.First().Id; // this.genericMgr.Update(newMSDatFile); // continue; // #endregion //} #endregion } else { try { #region 不存在,将数据插入到中间表 newMSDatFile = this.GetWMSDatFile(line, fileName); this.genericMgr.Create(newMSDatFile); //如果是退货单明细,则直接收货 int orderDetailId = 0; try { orderDetailId = Convert.ToInt32(newMSDatFile.WmsLine); } catch { continue; } OrderDetail orderDetail = this.genericMgr.FindById<OrderDetail>(orderDetailId); if (orderDetail != null) { OrderMaster orderMstr = this.genericMgr.FindById<OrderMaster>(orderDetail.OrderNo); if (orderMstr != null) { if (orderMstr.SubType == CodeMaster.OrderSubType.Return) orderMgr.ReceiveWMSIpMaster(newMSDatFile, System.DateTime.Now); } } continue; #endregion } catch (Exception e) { throw new BusinessException(e.Message); } } #endregion } catch (BusinessException ex) { #region Log LesINLog lesInLog = new LesINLog(); lesInLog.Type = "MB1B"; lesInLog.MoveType = (string)line[0] + (line[10] == string.Empty ? string.Empty : line[10].ToUpper()); lesInLog.Sequense = ""; // lesInLog.PO = (string)line[3];// //lesInLog.POLine = (string)line[4];// lesInLog.WMSNo = (string)line[20]; lesInLog.WMSLine = (string)line[21]; lesInLog.Item = (string)line[11]; lesInLog.HandResult = "F"; lesInLog.FileName = fileName; lesInLog.HandTime = System.DateTime.Now; lesInLog.IsCreateDat = false; lesInLog.ASNNo = line[17]; lesInLog.ErrorCause = ex.GetMessages()[0].GetMessageString(); this.genericMgr.Create(lesInLog); noError = false; continue; #endregion } } #endregion if (rowCount < datStr.Length) { throw new BusinessException("文件读取行数不对,处理失败。"); } //log.Info("文件" + fileName + "读完成功。"); } else { log.Info("文件" + fileName + "类型不对。"); throw new BusinessException("文件类型不对。"); } if (!noError) { throw new BusinessException("ERROR"); } } catch (BusinessException ex) { throw new BusinessException(ex.GetMessages()[0].GetMessageString()); } }