Пример #1
0
        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());
            }
        }
Пример #2
0
        private WMSDatFile GetWMSDatFile(string[] line, string fileName)
        {
            #region 检查字段
            if (line[11] == null || line[11] == string.Empty)
            {
                throw new BusinessException("Item is Empty!");
            }
            if (line[12] == null || line[12] == string.Empty)
            {
                throw new BusinessException("Qty is Empty!");
            }
            if (line[17] == null || line[17] == string.Empty)
            {
                throw new BusinessException("IpNo is Empty!");
            }
            if (line[21] == null || line[21] == string.Empty)
            {
                throw new BusinessException("OrderId is Empty!");
            }
            if (line[20] == null || line[20] == string.Empty)
            {
                throw new BusinessException("WMSNo is Empty!");
            }
            #endregion

            #region 获取数据插中间表
            WMSDatFile wmsDatFile = new WMSDatFile();
            wmsDatFile.MoveType = line[0];
            wmsDatFile.BLDAT = line[1];
            wmsDatFile.BUDAT = line[2];
            wmsDatFile.PO = line[3];
            wmsDatFile.POLine = line[4];
            wmsDatFile.VBELN = line[5];
            wmsDatFile.POSNR = line[6];
            wmsDatFile.LIFNR = line[7];
            wmsDatFile.WERKS = line[8];
            wmsDatFile.LGORT = line[9];
            wmsDatFile.SOBKZ = line[10] == string.Empty ? string.Empty : line[10].ToUpper();
            wmsDatFile.Item = line[11];
            wmsDatFile.Qty = Convert.ToDecimal(line[12]);
            wmsDatFile.Uom = line[13];
            wmsDatFile.UMLGO = line[14];
            wmsDatFile.GRUND = line[15];
            wmsDatFile.KOSTL = line[16];
            wmsDatFile.WmsNo = line[17];
            wmsDatFile.RSNUM = line[18];
            wmsDatFile.RSPOS = line[19];
            wmsDatFile.WMSId = line[20];
            wmsDatFile.WmsLine = line[21];
            wmsDatFile.OLD = line[22];
            wmsDatFile.INSMK = line[23];
            wmsDatFile.XABLN = line[24];
            wmsDatFile.AUFNR = line[25];
            wmsDatFile.UMMAT = line[26];
            wmsDatFile.UMWRK = line[27];
            wmsDatFile.WBS = line[28];
            wmsDatFile.HuId = line[29];
            wmsDatFile.CreateDate = System.DateTime.Now;
            wmsDatFile.IsHand = false;
            wmsDatFile.FileName = fileName;

            #endregion

            return wmsDatFile;
        }
Пример #3
0
        public void ReceiveWMSIpMaster(WMSDatFile wMSDatFile, DateTime effectiveDate)
        {
            try
            {
                LesINLog lesInLog = new LesINLog();

                #region 获得orderdetail
                IList<OrderDetail> orderDetailList = new List<OrderDetail>();
                OrderDetail orderDetail = this.genericMgr.FindById<OrderDetail>(Convert.ToInt32(wMSDatFile.WmsLine));

                if (orderDetail.ReceiveLotSize == 1)
                {
                    throw new BusinessException(string.Format("单号{0}中物料{1}明细行已经关闭,不能收货。", orderDetail.OrderNo, orderDetail.Item));
                }

                //#region 订单头要配置成自动收货
                //OrderMaster ordermaster = this.genericMgr.FindById<OrderMaster>(orderDetail.OrderNo);
                //if (!ordermaster.IsAutoReceive)
                //{
                //    throw new BusinessException();
                //}
                //#endregion

                orderDetail.WmsFileID = wMSDatFile.WMSId;
                orderDetail.ManufactureParty = wMSDatFile.LIFNR;
                orderDetail.ExternalOrderNo = wMSDatFile.WMSId;
                //orderDetail.ExternalSequence = wMSDatFile.WBS;//项目代码
                OrderDetailInput orderDetailInput = new OrderDetailInput();
                orderDetailInput.ShipQty = wMSDatFile.CurrentReceiveQty;
                orderDetailInput.WMSIpNo = wMSDatFile.WMSId;//先记录WMSId号,目前安吉拣货单号只用在接口日志查询中
                orderDetailInput.WMSIpSeq = wMSDatFile.HuId;//WMS行
                orderDetailInput.MoveType = wMSDatFile.MoveType + wMSDatFile.SOBKZ;//移动类型
                //只有311K才传寄售供应商,如果是411K也不传,防止两边库位结算方式设置不一致造成差异
                if (wMSDatFile.SOBKZ.ToUpper() == "K" && wMSDatFile.MoveType == "311")
                    orderDetailInput.ConsignmentParty = wMSDatFile.LIFNR;//厂商代码
                orderDetail.AddOrderDetailInput(orderDetailInput);
                orderDetailList.Add(orderDetail);
                #endregion

                #region 调用发货
                var ipMstr = this.ShipOrder(orderDetailList, effectiveDate);

                if (!ipMstr.IsAutoReceive)
                {
                    foreach (IpDetail ipDetail in ipMstr.IpDetails)
                    {
                        if (ipDetail.IpDetailInputs != null && ipDetail.IpDetailInputs.Count > 0)
                        {
                            foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
                            {
                                ipDetailInput.ReceiveQty = ipDetailInput.ShipQty;
                            }
                        }
                        else
                        {
                            IpDetailInput ipDetailInput = new IpDetailInput();
                            ipDetailInput.ReceiveQty = ipDetail.Qty;
                            ipDetail.AddIpDetailInput(ipDetailInput);
                        }
                    }
                    this.genericMgr.FlushSession();
                    ReceiveIp(ipMstr.IpDetails, effectiveDate);
                }
                //var ipDetList = base.genericMgr.FindAll<IpDetail>("from IpDetail as d where d.IpNo=?", ipMstr.IpNo);
                //if (ipDetList != null && ipDetList.Count > 0)
                //{
                //    lesInLog.Qty = ipDetList.FirstOrDefault().ReceivedQty;
                //    lesInLog.QtyMark = true;
                //}
                lesInLog.Qty = wMSDatFile.CurrentReceiveQty;
                lesInLog.QtyMark = true;
                #endregion

                #region 新建Log记录
                lesInLog.Type = "MB1B";
                lesInLog.MoveType = wMSDatFile.MoveType + wMSDatFile.SOBKZ;
                lesInLog.Sequense = "";
                lesInLog.WMSNo = wMSDatFile.WMSId;
                lesInLog.WMSLine = wMSDatFile.WmsLine;
                lesInLog.Item = wMSDatFile.Item;
                lesInLog.HandResult = "S";
                lesInLog.FileName = wMSDatFile.FileName;
                lesInLog.HandTime = System.DateTime.Now;
                lesInLog.IsCreateDat = false;
                lesInLog.ASNNo = wMSDatFile.WmsNo;
                this.genericMgr.Create(lesInLog);
                #endregion

                #region 修改中间表
                wMSDatFile.ReceiveTotal = wMSDatFile.ReceiveTotal + wMSDatFile.CurrentReceiveQty;
                this.genericMgr.Update(wMSDatFile);
                #endregion

                this.genericMgr.FlushSession();
            }
            catch (BusinessException ex)
            {
                throw new BusinessException(ex.GetMessages()[0].GetMessageString());
            }
        }