Exemple #1
0
        /// <summary>
        /// 发出需配送的料车。
        /// </summary>
        /// <param name="fndTaskId">料车配送任务的主键。</param>
        public void DepartCart(long fndTaskId)
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                FND_Task fndTask = dbContext.FND_Tasks
                                   .First(t => t.Id == fndTaskId);

                fndTask.FindingStatus = FindingStatus.NeedBlink;

                dbContext.SaveChanges();
            }
        }
Exemple #2
0
        /// <summary>
        /// 点亮需配送的料车。
        /// </summary>
        /// <param name="fndTaskId">料车配送任务的主键。</param>
        /// <param name="lightColor">灯色。</param>
        /// <param name="cfgEmployeeId">操作员的主键。</param>
        public void FindCart(long fndTaskId, byte lightColor, int cfgEmployeeId)
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                FND_Task fndTask = dbContext.FND_Tasks
                                   .First(t => t.Id == fndTaskId);

                fndTask.LightColor     = lightColor;
                fndTask.FindingStatus  = FindingStatus.NeedDisplay;
                fndTask.CFG_EmployeeId = cfgEmployeeId;

                dbContext.SaveChanges();
            }
        }
Exemple #3
0
 private void buttonDetail_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         FND_Task fndTask = (FND_Task)this.dataGrid.SelectedItem;
         if (fndTask != null && fndTask.FindingStatus == FindingStatus.Finished)
         {
             FndTaskItemsWindow dialog = new FndTaskItemsWindow(fndTask.Id);
             dialog.ShowDialog();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemple #4
0
        void ptl900U_Pressed(object sender, Ptl900UPressedEventArgs e, bool pickAll)
        {
            while (true)
            {
                try
                {
                    using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                    {
                        CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations
                                                         .First(ws => ws.Id == this.CFG_WorkStationId);
                        ASM_TaskItem asmTaskItem = dbContext.ASM_TaskItems
                                                   .First(ti => ti.Id == this.CurrentAsmTaskItemId.Value);
                        ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem;
                        ASM_AssembleIndication     asmAssembleIndication     = asmAssembleIndicationItem.ASM_AssembleIndication;
                        List <ASM_TaskItem>        otherAsmTaskItems         = asmAssembleIndicationItem.ASM_TaskItems
                                                                               .Where(ti => ti.Id != asmTaskItem.Id)
                                                                               .ToList();
                        CFG_Cart cfgCart = asmTaskItem.CFG_Cart;
                        List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = cfgCart.CFG_CartCurrentMaterials
                                                                                 .OrderBy(ccm => ccm.Position)
                                                                                 .ToList();
                        CFG_CartCurrentMaterial    cfgCartCurrentMaterial    = cfgCartCurrentMaterials.First(ccm => ccm.Position == asmTaskItem.CartPosition);
                        CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts
                                                                               .FirstOrDefault(wscc => wscc.CFG_WorkStationId == this.CFG_WorkStationId && wscc.CFG_CartId == cfgCart.Id);

                        if (asmTaskItem.AssembledQuantity == null)
                        {
                            asmTaskItem.AssembledQuantity = 0;
                        }

                        int pickedCount = 1;
                        if (pickAll)
                        {
                            pickedCount = asmTaskItem.ToAssembleQuantity - asmTaskItem.AssembledQuantity.Value;
                        }

                        asmTaskItem.AssembledQuantity += pickedCount;
                        asmTaskItem.AssembledTime      = DateTime.Now;

                        if (asmAssembleIndicationItem.AssembledQuantity == null)
                        {
                            asmAssembleIndicationItem.AssembledQuantity = 0;
                        }
                        asmAssembleIndicationItem.AssembledQuantity += pickedCount;
                        asmAssembleIndicationItem.AssembledTime      = DateTime.Now;

                        bool currentItemFinished = asmTaskItem.AssembledQuantity == asmTaskItem.ToAssembleQuantity;
                        if (currentItemFinished)
                        {
                            asmTaskItem.AssembleStatus = AssembleStatus.Finished;
                            if (otherAsmTaskItems.All(ti => ti.AssembleStatus == AssembleStatus.Finished))
                            {
                                asmAssembleIndicationItem.AssembleStatus = AssembleStatus.Finished;
                            }
                        }

                        if (cfgCartCurrentMaterial.Quantity != null && cfgCartCurrentMaterial.Quantity > 0)
                        {
                            cfgCartCurrentMaterial.Quantity -= pickedCount;
                        }

                        //料车上物料消耗完则施放料车并通知 AGV 回收,再尝试补充一辆料车
                        if (cfgCartCurrentMaterials.All(ccm => ccm.Quantity == null || ccm.Quantity == 0))
                        {
                            cfgCart.CartStatus = CartStatus.Free;

                            foreach (CFG_CartCurrentMaterial innerCfgCartCurrentMaterial in cfgCartCurrentMaterials)
                            {
                                innerCfgCartCurrentMaterial.AST_CartTaskItemId = null;
                                innerCfgCartCurrentMaterial.ProjectCode        = null;
                                innerCfgCartCurrentMaterial.WbsId              = null;
                                innerCfgCartCurrentMaterial.ProjectStep        = null;
                                innerCfgCartCurrentMaterial.CFG_WorkStationId  = null;
                                innerCfgCartCurrentMaterial.BatchCode          = null;
                                innerCfgCartCurrentMaterial.CFG_ChannelId      = null;
                                innerCfgCartCurrentMaterial.CFG_PalletId       = null;
                                innerCfgCartCurrentMaterial.BoxCode            = null;
                                innerCfgCartCurrentMaterial.FromPalletPosition = null;
                                innerCfgCartCurrentMaterial.MaterialCode       = null;
                                innerCfgCartCurrentMaterial.MaterialName       = null;
                                innerCfgCartCurrentMaterial.MaterialBarcode    = null;
                                innerCfgCartCurrentMaterial.Quantity           = null;
                                innerCfgCartCurrentMaterial.AssortedTime       = null;
                                innerCfgCartCurrentMaterial.CFG_EmployeeId     = null;
                                if (innerCfgCartCurrentMaterial.Usability != CartPositionUsability.DisableByOffLineDevice)
                                {
                                    innerCfgCartCurrentMaterial.Usability = CartPositionUsability.Enable;
                                }
                            }

                            if (cfgWorkStationCurrentCart != null)
                            {
                                //通知 AGV 回收当前车,尝试空满切换下一辆车
                                DST_AgvSwitch dstAgvSwitch = dbContext.DST_AgvSwitchs.FirstOrDefault(t => t.isOpen);
                                if (dstAgvSwitch != null)
                                {
                                    int    nCurPosition     = cfgWorkStationCurrentCart.Position;
                                    string sWorkStationCode = cfgWorkStationCurrentCart.CFG_WorkStation.Code;
                                    if (nCurPosition <= 4) //内侧
                                    {
                                        //如果对应外侧没有正在执行的物料超市配送任务,才生成里侧的线边配送任务
                                        string             sOutPosition      = sWorkStationCode + "-" + (nCurPosition + 4);
                                        DST_DistributeTask outDistributeTask = dbContext.DST_DistributeTasks.FirstOrDefault(t => t.DistributeReqTypes == DistributeReqTypes.MaterialMarketDistribute &&
                                                                                                                            t.endPosition.Equals(sOutPosition) &&
                                                                                                                            t.sendErrorCount < 5 &&
                                                                                                                            t.arriveTime == null);
                                        if (outDistributeTask == null)
                                        {
                                            CFG_WorkStationCurrentCart cfgOutWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts
                                                                                                      .FirstOrDefault(wscc => wscc.CFG_WorkStationId == this.CFG_WorkStationId && wscc.Position == nCurPosition + 4 && wscc.CFG_CartId != null);
                                            if (cfgOutWorkStationCurrentCart != null)
                                            {
                                                //生成料架转换任务
                                                List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductCartSwitchTask(cfgCart);
                                                foreach (DST_DistributeTask distributeTask in distributeTasks)
                                                {
                                                    dbContext.DST_DistributeTasks.Add(distributeTask);
                                                }
                                            }
                                            else
                                            {
                                                //生成线边自动清线配送任务
                                                List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductAreaAutoClearTask(sWorkStationCode, nCurPosition.ToString(), cfgCart.Code);
                                                foreach (DST_DistributeTask distributeTask in distributeTasks)
                                                {
                                                    dbContext.DST_DistributeTasks.Add(distributeTask);
                                                }
                                            }
                                        }
                                    }
                                    else //外侧
                                    {
                                        //如果对应里侧没有正在执行的空满转换任务,才生成外侧的线边配送任务
                                        string             sInPosition      = sWorkStationCode + "-" + (nCurPosition - 4);
                                        DST_DistributeTask inDistributeTask = dbContext.DST_DistributeTasks.FirstOrDefault(t => t.DistributeReqTypes == DistributeReqTypes.ProductCartSwitch &&
                                                                                                                           t.startPosition.Equals(sInPosition) &&
                                                                                                                           t.sendErrorCount < 5 &&
                                                                                                                           t.arriveTime == null);
                                        if (inDistributeTask == null)
                                        {
                                            //生成线边配送任务
                                            string sTaskSendType = "自动";
                                            List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductAreaDistributeTask(sWorkStationCode, nCurPosition.ToString(), cfgCart.Code, sTaskSendType, true, dbContext);
                                            foreach (DST_DistributeTask distributeTask in distributeTasks)
                                            {
                                                dbContext.DST_DistributeTasks.Add(distributeTask);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //解除停靠
                                    cfgWorkStationCurrentCart.CFG_CartId = null;
                                    cfgWorkStationCurrentCart.DockedTime = null;
                                }
                            }

                            //尝试发起下一车的拉料任务
                            CFG_Cart nextCfgCart = dbContext.CFG_Carts
                                                   .FirstOrDefault(c => c.CartStatus == CartStatus.ArrivedAtBufferArea &&
                                                                   c.CFG_CartCurrentMaterials.Any(ccm => ccm.CFG_WorkStationId == this.CFG_WorkStationId &&
                                                                                                  ccm.Quantity > 0));
                            if (nextCfgCart != null)
                            {
                                nextCfgCart.CartStatus = CartStatus.NeedToWorkStation;

                                CFG_CartCurrentMaterial firstCfgCartFirstCartCurrentMaterial = nextCfgCart.CFG_CartCurrentMaterials
                                                                                               .First(ccm => ccm.Quantity > 0);

                                FND_Task fndTask = new FND_Task();
                                fndTask.ProjectCode        = firstCfgCartFirstCartCurrentMaterial.ProjectCode;
                                fndTask.ProjectStep        = firstCfgCartFirstCartCurrentMaterial.ProjectStep;
                                fndTask.BatchCode          = firstCfgCartFirstCartCurrentMaterial.BatchCode;
                                fndTask.MaxNeedArrivedTime = DateTime.Now.AddHours(1);
                                fndTask.RequestTime        = DateTime.Now;
                                fndTask.CFG_WorkStationId  = firstCfgCartFirstCartCurrentMaterial.CFG_WorkStationId.Value;
                                fndTask.CFG_CartId         = nextCfgCart.Id;
                                fndTask.LightColor         = (byte)LightColor.Off;
                                fndTask.FindingStatus      = FindingStatus.New;

                                dbContext.FND_Tasks.Add(fndTask);
                            }
                        }

                        dbContext.SaveChanges();

                        CartPtl cartPtl          = CartPtlHost.Instance.GetCartPtl(asmTaskItem.CFG_CartId);
                        Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher();
                        Ptl900U ptl900U          = cartPtl.GetPtl900UByPosition(asmTaskItem.CartPosition);
                        Ptl900U ptl900ULight     = cartPtl.GetPtl900ULight();

                        if (currentItemFinished)
                        {
                            Display900UItem cartPublisherDisplay900UItem = new Display900UItem();
                            cartPublisherDisplay900UItem.Name        = "抵达工位 " + cfgWorkStation.Name;
                            cartPublisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0}
阶段:{1}
批次:{2}", cfgCartCurrentMaterial.ProjectCode, cfgCartCurrentMaterial.ProjectStep, cfgCartCurrentMaterial.BatchCode);
                            if (cfgWorkStationCurrentCart != null)
                            {
                                cartPublisherDisplay900UItem.Count = (ushort)cfgWorkStationCurrentCart.Position;
                            }
                            cartPublisherDisplay900UItem.Unit = "位";

                            ptl900UPublisher.Pressed -= this.ptl900UPublisher_Pressed;
                            ptl900UPublisher.Clear(true);
                            ptl900UPublisher.Lock();
                            ptl900UPublisher.Display(cartPublisherDisplay900UItem, LightColor.Off);

                            ptl900U.Pressed -= this.ptl900U_Pressed;

                            ptl900ULight.Clear();

                            this.CurrentAsmTaskItemId = null;
                        }
                        else
                        {
                            Display900UItem publisherDisplay900UItem = new Display900UItem();
                            publisherDisplay900UItem.Name            = asmAssembleIndicationItem.MaterialName;
                            publisherDisplay900UItem.Description     = string.Format(CultureInfo.InvariantCulture, @"项目:{0},{1}
车号:{2}
量产工位:{3}", asmAssembleIndicationItem.ProjectCode, asmAssembleIndicationItem.ProjectStep, asmAssembleIndication.ProductSequence, asmAssembleIndicationItem.Gzz);
                            publisherDisplay900UItem.LongSubLocation = asmTaskItem.ToAssembleQuantity.ToString(CultureInfo.InvariantCulture);
                            publisherDisplay900UItem.Count           = (ushort)asmTaskItem.AssembledQuantity.Value;

                            Display900UItem display900UItem = new Display900UItem();
                            display900UItem.Count = (ushort)(asmTaskItem.ToAssembleQuantity - asmTaskItem.AssembledQuantity.Value);

                            LightMode lightMode = new LightMode();
                            lightMode.Color = LightColor.Green;
                            if (asmAssembleIndicationItem.Qtxbs == "1")
                            {
                                lightMode.Color  = LightColor.Magenta;
                                lightMode.Ratio  = LightOnOffRatio.RatioP1V1;
                                lightMode.Period = LightOnOffPeriod.Period500;
                            }

                            ptl900UPublisher.Clear(true);
                            //ptl900UPublisher.Unlock();
                            ptl900UPublisher.Lock();
                            ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off, true);

                            ptl900U.Display(display900UItem, lightMode, true);

                            //如果长时间无法交互,则自动交互
                            this.AutoPressByDeviceErrorAsync(this.CurrentAsmTaskItemId.Value, ptl900U, display900UItem);
                        }

                        string logMessage = (pickAll ? " 拣选所有:" : " 拣选一个:")
                                            + asmAssembleIndication.ProductSequence + ", "
                                            + asmAssembleIndication.GzzList + ", "
                                            + asmAssembleIndicationItem.MaterialCode + ", "
                                            + asmAssembleIndicationItem.MaterialName + ", "
                                            + cfgCart.Name + ", "
                                            + asmTaskItem.CartPosition;
                        if (currentItemFinished)
                        {
                            logMessage += ", 明细完成";
                        }
                        Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + logMessage + Environment.NewLine);
                    }

                    break;
                }
                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("IndicatingExecutor.ptl900U_Pressed", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine
                               + message + Environment.NewLine
                               + Environment.NewLine);

                    Thread.Sleep(1000);
                }
            }
        }