コード例 #1
0
ファイル: ChannelsViewModel.cs プロジェクト: xdpcxq/GEELY
        /// <summary>
        /// 刷新视图模型。
        /// </summary>
        public void Refresh()
        {
            this.Items.Clear();

            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                List <CFG_Channel> cfgChannels = dbContext.CFG_Channels
                                                 .OrderBy(c => c.Code)
                                                 .ToList();
                foreach (CFG_Channel cfgChannel in cfgChannels)
                {
                    ChannelModel channelModel = new ChannelModel();
                    channelModel.CFG_Channel = cfgChannel;

                    CFG_Pallet cfgPallet = cfgChannel.CFG_ChannelCurrentPallet.CFG_Pallet;

                    if (cfgPallet != null)
                    {
                        channelModel.CurrentPalletCode = cfgPallet.Code;
                    }

                    CFG_Cart cfgCart1 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 1).Select(ccc => ccc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart2 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 2).Select(ccc => ccc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart3 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 3).Select(ccc => ccc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart4 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 4).Select(ccc => ccc.CFG_Cart).FirstOrDefault();

                    if (cfgCart1 != null)
                    {
                        channelModel.CurrentCartName1 = cfgCart1.Name;
                    }
                    if (cfgCart2 != null)
                    {
                        channelModel.CurrentCartName2 = cfgCart2.Name;
                    }
                    if (cfgCart3 != null)
                    {
                        channelModel.CurrentCartName3 = cfgCart3.Name;
                    }
                    if (cfgCart4 != null)
                    {
                        channelModel.CurrentCartName4 = cfgCart4.Name;
                    }

                    if (cfgChannel.Code.Equals("8"))
                    {
                        channelModel.Light1OnLine = false;
                        channelModel.Light2OnLine = false;
                        channelModel.Light3OnLine = false;
                    }
                    else
                    {
                        channelModel.Light1OnLine = cfgChannel.CFG_ChannelPtlDevices.Where(cpd => cpd.Position == 3).Select(cpd => cpd.OnLine).First();
                        channelModel.Light2OnLine = cfgChannel.CFG_ChannelPtlDevices.Where(cpd => cpd.Position == 4).Select(cpd => cpd.OnLine).First();
                        channelModel.Light3OnLine = cfgChannel.CFG_ChannelPtlDevices.Where(cpd => cpd.Position == 5).Select(cpd => cpd.OnLine).First();
                    }
                    this.Items.Add(channelModel);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 转换托盘抵达分拣口报文-PDA。
        /// </summary>
        /// <param name="xml">托盘抵达分拣口报文。</param>
        /// <param name="dbContext">数据库上下文。</param>
        /// <returns>成功解析的实体。</returns>
        public static AST_PalletArrived_PDA ConvertRequestPDA(string xml, GeelyPtlEntities dbContext)
        {
            XDocument xDocument      = XDocument.Parse(xml);
            XElement  serviceElement = xDocument.Descendants("Service").First();
            XElement  dataElement    = serviceElement.Descendants("Data").First();
            XElement  requestElement = dataElement.Descendants("Request").First();
            XElement  arrivedElement = requestElement.Descendants("ASSEMBLE").First();

            AST_PalletArrived_PDA astPalletArrived = new AST_PalletArrived_PDA();

            astPalletArrived.ProjectCode = arrivedElement.Element("ProjectCode").Value;
            astPalletArrived.WbsId       = arrivedElement.Element("PS_POSID").Value;
            astPalletArrived.ProjectStep = arrivedElement.Element("StageCode").Value;

            string batchCode = arrivedElement.Element("BatchCode").Value;

            if (!dbContext.AST_LesTask_PDAs.Any(lt => lt.BatchCode == batchCode))
            {
                throw new InterfaceDataException("该批次的任务未下发:" + batchCode);
            }

            astPalletArrived.BatchCode = batchCode;

            string      cfgChannelCode = arrivedElement.Element("ChannelCode").Value;
            CFG_Channel cfgChannel     = dbContext.CFG_Channels
                                         .FirstOrDefault(c => c.Code == cfgChannelCode);

            if (cfgChannel == null)
            {
                throw new InterfaceDataException("无效的分拣巷道:" + cfgChannelCode);
            }

            astPalletArrived.CFG_ChannelId = cfgChannel.Id;

            string     cfgPalletCode = arrivedElement.Element("PalletCode").Value;
            CFG_Pallet cfgPallet     = dbContext.CFG_Pallets
                                       .FirstOrDefault(c => c.Code == cfgPalletCode);

            if (cfgPallet == null)
            {
                throw new InterfaceDataException("无效的托盘编码:" + cfgPalletCode);
            }

            cfgPallet.PalletType = arrivedElement.Element("PalletType").Value;

            astPalletArrived.CFG_PalletId = cfgPallet.Id;
            astPalletArrived.PickBillIds  = arrivedElement.Element("PickBillIDs").Value;
            astPalletArrived.ArrivedTime  = DateTime.Now;

            return(astPalletArrived);
        }
コード例 #3
0
        /// <summary>
        /// 转换 LES 原始托盘分拣结果报文。
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="dbContext"></param>
        /// <returns></returns>
        public static List <AST_PalletPickResult_PDA> ConvertRequestPDA(string xml, GeelyPtlEntities dbContext)
        {
            XDocument xDocument      = XDocument.Parse(xml);
            XElement  serviceElement = xDocument.Descendants("Service").First();
            XElement  dataElement    = serviceElement.Descendants("Data").First();
            XElement  requestElement = dataElement.Descendants("Request").First();
            //XElement arrivedElement = requestElement.Descendants("ASSEMBLE").First();
            List <XElement> taskItemElements = requestElement.Descendants("ASSEMBLE").ToList();

            if (taskItemElements.Count == 0)
            {
                throw new InterfaceDataException("没有托盘分拣结果。");
            }

            List <AST_PalletPickResult_PDA> astPalletPickResults = new List <AST_PalletPickResult_PDA>();

            foreach (XElement taskItemElement in taskItemElements)
            {
                AST_PalletPickResult_PDA result = new AST_PalletPickResult_PDA();
                result.BatchCode    = taskItemElement.Element("BATCH").Value;
                result.PickBillIds  = taskItemElement.Element("BILLID").Value;
                result.BoxCode      = taskItemElement.Element("BOXCODE").Value;
                result.Status       = int.Parse(taskItemElement.Element("STATUS").Value);
                result.Quantity     = int.Parse(taskItemElement.Element("QUANTITY").Value);
                result.ReceivedTime = DateTime.Now;
                string     cfgPalletCode = taskItemElement.Element("PALLETCODE").Value;
                CFG_Pallet cfgPallet     = dbContext.CFG_Pallets
                                           .FirstOrDefault(c => c.Code == cfgPalletCode);
                if (cfgPallet == null)
                {
                    throw new InterfaceDataException("无效的托盘编码:" + cfgPalletCode);
                }
                result.CFG_PalletId = cfgPallet.Id;

                astPalletPickResults.Add(result);
            }
            return(astPalletPickResults);
        }
コード例 #4
0
ファイル: AST_LesTaskConverter.cs プロジェクト: xdpcxq/GEELY
        /// <summary>
        /// 转换 LES 原始任务报文。
        /// </summary>
        /// <param name="xml">LES 原始任务报文。</param>
        /// <param name="dbContext">数据库上下文。</param>
        /// <returns>成功解析的实体。</returns>
        public static AST_LesTask ConvertRequest(string xml, GeelyPtlEntities dbContext)
        {
            XDocument       xDocument        = XDocument.Parse(xml);
            XElement        serviceElement   = xDocument.Descendants("Service").First();
            XElement        dataElement      = serviceElement.Descendants("Data").First();
            XElement        requestElement   = dataElement.Descendants("Request").First();
            XElement        taskElement      = requestElement.Descendants("ASSEMBLE").First();
            List <XElement> taskItemElements = requestElement.Descendants("ASSEMBLEITEM").ToList();

            if (taskItemElements.Count == 0)
            {
                throw new InterfaceDataException("没有明细。");
            }

            AST_LesTask astLesTask  = new AST_LesTask();
            string      projectCode = taskElement.Element("ProjectCode").Value;
            string      projectStep = taskElement.Element("StageCode").Value;

            string[] codes = projectCode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string[] steps = projectStep.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (codes.Length > 1 && codes[0] == codes[1])
            {
                projectCode = codes[0];
            }
            if (steps.Length > 1 && steps[0] == steps[1])
            {
                projectStep = steps[0];
            }

            astLesTask.ProjectCode = projectCode;
            astLesTask.WbsId       = taskElement.Element("PS_POSID").Value;
            astLesTask.ProjectStep = projectStep;
            astLesTask.BillCode    = taskElement.Element("PickNO").Value;
            astLesTask.BillDate    = DateTime.Parse(taskElement.Element("Bill_Date").Value, CultureInfo.InvariantCulture);

            //工位随时会新增
            string          cfgWorkStationCode = taskElement.Element("STATIONCODE").Value;
            CFG_WorkStation cfgWorkStation     = dbContext.CFG_WorkStations
                                                 .FirstOrDefault(ws => ws.Code == cfgWorkStationCode);

            if (cfgWorkStation == null)
            {
                using (GeelyPtlEntities innerDbContext = new GeelyPtlEntities())
                {
                    cfgWorkStation      = new CFG_WorkStation();
                    cfgWorkStation.Code = cfgWorkStationCode;
                    cfgWorkStation.Name = cfgWorkStation.Code;

                    innerDbContext.CFG_WorkStations.Add(cfgWorkStation);

                    //每个工位有 8 个车位
                    for (int position = 1; position <= 8; position++)
                    {
                        CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = new CFG_WorkStationCurrentCart();
                        cfgWorkStationCurrentCart.CFG_WorkStation = cfgWorkStation;
                        cfgWorkStationCurrentCart.Position        = position;

                        innerDbContext.CFG_WorkStationCurrentCarts.Add(cfgWorkStationCurrentCart);
                    }

                    innerDbContext.SaveChanges();
                }
            }

            astLesTask.CFG_WorkStationId = cfgWorkStation.Id;
            astLesTask.GzzList           = taskElement.Element("GZZLIST").Value;
            astLesTask.BatchCode         = taskElement.Element("BatchCode").Value;

            string      cfgChannelCode = taskElement.Element("ChannelCode").Value;
            CFG_Channel cfgChannel     = dbContext.CFG_Channels
                                         .FirstOrDefault(c => c.Code == cfgChannelCode);

            if (cfgChannel == null)
            {
                throw new InterfaceDataException("无效的分拣巷道:" + cfgChannelCode);
            }

            astLesTask.CFG_ChannelId = cfgChannel.Id;

            //托盘随时会增加
            string     cfgPalletCode = taskElement.Element("PalletCode").Value;
            CFG_Pallet cfgPallet     = dbContext.CFG_Pallets
                                       .FirstOrDefault(p => p.Code == cfgPalletCode);

            if (cfgPallet == null)
            {
                using (GeelyPtlEntities innerDbContext = new GeelyPtlEntities())
                {
                    cfgPallet            = new CFG_Pallet();
                    cfgPallet.Code       = cfgPalletCode;
                    cfgPallet.PalletType = "01";

                    innerDbContext.CFG_Pallets.Add(cfgPallet);

                    innerDbContext.SaveChanges();
                }
            }

            astLesTask.CFG_PalletId       = cfgPallet.Id;
            astLesTask.BoxCode            = taskElement.Element("BoxCode").Value;
            astLesTask.FromPalletPosition = int.Parse(taskElement.Element("FromPalletPosition").Value, CultureInfo.InvariantCulture);
            if (astLesTask.FromPalletPosition < 1 || astLesTask.FromPalletPosition > 10)
            {
                astLesTask.FromPalletPosition = 1;
            }
            astLesTask.RequestTime = DateTime.Now;

            foreach (XElement taskItemElement in taskItemElements)
            {
                AST_LesTaskItem astLesTaskItem = new AST_LesTaskItem();
                astLesTaskItem.AST_LesTask     = astLesTask;
                astLesTaskItem.BillDetailId    = taskItemElement.Element("BillDtlID").Value;
                astLesTaskItem.MaterialCode    = taskItemElement.Element("MaterialCode").Value;
                astLesTaskItem.MaterialName    = taskItemElement.Element("MaterialName").Value;
                astLesTaskItem.MaterialBarcode = taskItemElement.Element("MaterialBarcode").Value;
                astLesTaskItem.ToPickQuantity  = (int)decimal.Parse(taskItemElement.Element("NEED_PICK_NUM").Value, CultureInfo.InvariantCulture);
                astLesTaskItem.MaxQuantityInSingleCartPosition = (int)decimal.Parse(taskItemElement.Element("MaxQuantityInSingleCartPosition").Value, CultureInfo.InvariantCulture);
                if (astLesTaskItem.MaxQuantityInSingleCartPosition <= 0)
                {
                    astLesTaskItem.MaxQuantityInSingleCartPosition = int.MaxValue;
                }
                astLesTaskItem.IsSpecial = taskItemElement.Element("IsSpecial").Value == "1";
                astLesTaskItem.IsBig     = taskItemElement.Element("STORETYPE").Value == "04";

                astLesTask.AST_LesTaskItems.Add(astLesTaskItem);
            }

            return(astLesTask);
        }
コード例 #5
0
ファイル: LesToPtlService.cs プロジェクト: xdpcxq/GEELY
        /// <summary>
        /// PDA拣料托盘抵达分拣口
        /// </summary>
        public string LesSendBoxPDA(string xml)
        {
            try { XDocument.Parse(xml); }
            catch (Exception ex) { return("ERROR:" + ex.Message); }

            try
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    AST_PalletArrived_PDA astPalletArrived = AST_PalletArrivedConverter.ConvertRequestPDA(xml, dbContext);
                    if (!dbContext.AST_PalletArrived_PDAs.Any(pa => pa.BatchCode == astPalletArrived.BatchCode &&
                                                              pa.CFG_PalletId == astPalletArrived.CFG_PalletId &&
                                                              pa.PickBillIds == astPalletArrived.PickBillIds))
                    {
                        AST_PalletArrivedMessage_PDA astPalletArrivedMessage = new AST_PalletArrivedMessage_PDA();
                        astPalletArrivedMessage.AST_PalletArrived_PDA = astPalletArrived;
                        astPalletArrivedMessage.ReceivedXml           = xml;
                        astPalletArrivedMessage.ReceivedTime          = DateTime.Now;

                        dbContext.AST_PalletArrived_PDAs.Add(astPalletArrived);
                        dbContext.AST_PalletArrivedMessage_PDAs.Add(astPalletArrivedMessage);

                        //托盘到达时按托合并任务
                        CFG_ChannelCurrentPallet cfgChannelCurrentPallet = dbContext.CFG_ChannelCurrentPallets
                                                                           .First(ccp => ccp.CFG_ChannelId == astPalletArrived.CFG_ChannelId);
                        cfgChannelCurrentPallet.CFG_PalletId = astPalletArrived.CFG_PalletId;
                        cfgChannelCurrentPallet.ArrivedTime  = astPalletArrived.ArrivedTime;

                        CFG_Pallet cfgPallet = astPalletArrived.CFG_Pallet;
                        cfgPallet.PalletRotationStatus = PalletRotationStatus.Normal;

                        //按托任务生成
                        AssortingTaskGenerator.GeneratePDA(astPalletArrived, dbContext);

                        dbContext.SaveChanges();
                    }
                }

                return(AST_PalletArrivedConverter.ConvertResponse(xml, true, string.Empty));
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                DbEntityValidationException dbEntityValidationException = ex as DbEntityValidationException;
                if (dbEntityValidationException != null)
                {
                    foreach (DbEntityValidationResult validationResult in dbEntityValidationException.EntityValidationErrors)
                    {
                        foreach (DbValidationError validationError in validationResult.ValidationErrors)
                        {
                            message += Environment.NewLine + validationError.ErrorMessage;
                        }
                    }
                }
                message += Environment.NewLine + ex.StackTrace;

                Logger.Log("LesSendBoxPDA", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine +
                           xml + Environment.NewLine
                           + message + Environment.NewLine
                           + Environment.NewLine);
                return(AST_PalletArrivedConverter.ConvertResponse(xml, false, message));
            }
        }