Пример #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    ASM_Task asmTask = dbContext.ASM_Tasks
                                       .Include(at => at.ASM_AssembleIndication)
                                       .First(at => at.Id == this.asmTaskId);
                    //List<ASM_TaskItem> asmTaskItems = dbContext.ASM_TaskItems
                    //                                      .Include(ati => ati.ASM_AssembleIndicationItem)
                    //                                      .Include(ati => ati.CFG_Cart)
                    //                                      .Where(ati => ati.ASM_TaskId == this.asmTaskId)
                    //                                      .OrderBy(ati => ati.CFG_CartId)
                    //                                      .ThenBy(ati => ati.CartPosition)
                    //                                      .ToList();
                    List <ASM_TaskItem> asmTaskItems = dbContext.ASM_TaskItems
                                                       .Include(ati => ati.ASM_AssembleIndicationItem)
                                                       .Include(ati => ati.CFG_Cart)
                                                       .Where(ati => ati.ASM_TaskId == this.asmTaskId)
                                                       .OrderBy(ati => ati.AssembleSequence)
                                                       .ToList();

                    this.Title = this.Title + ":" + asmTask.ASM_AssembleIndication.ProductSequence;
                    this.dataGrid.ItemsSource = asmTaskItems;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
            }
        }
Пример #2
0
 private void buttonDetail_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         ASM_Task asmTask = (ASM_Task)this.dataGrid.SelectedItem;
         if (asmTask != null)
         {
             AssembleTaskItemsWindow dialog = new AssembleTaskItemsWindow(asmTask.Id);
             dialog.ShowDialog();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Пример #3
0
        /// <summary>
        /// 生成装配指引任务。
        /// </summary>
        /// <param name="asmAssembleIndication">从接口解析还未持久化的车身抵达记录。</param>
        /// <param name="dbContext">数据上下文。</param>
        public static void Generate(ASM_AssembleIndication asmAssembleIndication, GeelyPtlEntities dbContext)
        {
            List <ASM_AssembleIndicationItem> asmAssembleIndicationItems = asmAssembleIndication.ASM_AssembleIndicationItems
                                                                           .OrderBy(aii => aii.AssembleSequence)
                                                                           .ToList();
            List <CFG_Cart> dockedCfgCarts = dbContext.CFG_WorkStationCurrentCarts
                                             .Where(wscc => wscc.CFG_WorkStationId == asmAssembleIndication.CFG_WorkStationId &&
                                                    (wscc.CFG_Cart.CartStatus == CartStatus.ArrivedAtWorkStation || wscc.CFG_Cart.CartStatus == CartStatus.Indicating))
                                             .OrderBy(wscc => wscc.DockedTime)
                                             .Select(wscc => wscc.CFG_Cart)
                                             .Distinct()
                                             .ToList();

            List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = new List <CFG_CartCurrentMaterial>();

            foreach (CFG_Cart cfgCart in dockedCfgCarts)
            {
                cfgCartCurrentMaterials.AddRange(cfgCart.CFG_CartCurrentMaterials.Where(ccm => ccm.AST_CartTaskItemId != null && ccm.Quantity > 0));
            }

            ASM_Task asmTask = new ASM_Task();

            asmTask.ASM_AssembleIndication = asmAssembleIndication;
            asmTask.AssembleStatus         = AssembleStatus.New;

            dbContext.ASM_Tasks.Add(asmTask);

            Dictionary <string, int> lockedQuantityByMaterialCode = new Dictionary <string, int>();

            foreach (ASM_AssembleIndicationItem asmAssembleIndicationItem in asmAssembleIndicationItems)
            {
                string materialCode = asmAssembleIndicationItem.MaterialCode;
                string projectCode  = asmAssembleIndicationItem.ProjectCode;
                string projectStep  = asmAssembleIndicationItem.ProjectStep;
                string batchCode    = asmAssembleIndicationItem.BatchCode;

                int lockedQuantity = 0;
                if (lockedQuantityByMaterialCode.ContainsKey(materialCode))
                {
                    lockedQuantity = lockedQuantityByMaterialCode[materialCode];
                }
                else
                {
                    lockedQuantityByMaterialCode.Add(materialCode, lockedQuantity);
                }

                List <CFG_CartCurrentMaterial> sameMaterialCfgCartCurrentMaterials = cfgCartCurrentMaterials
                                                                                     .Where(ccm => ccm.MaterialCode == materialCode &&
                                                                                            string.Equals(ccm.ProjectCode, projectCode, StringComparison.OrdinalIgnoreCase) &&
                                                                                            string.Equals(ccm.ProjectStep, projectStep, StringComparison.OrdinalIgnoreCase))
                                                                                     .OrderBy(ccm => ccm.Position)
                                                                                     .ToList();
                //替代料
                foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials
                         .Where(ccm => ccm.MaterialCode == materialCode))
                {
                    if (!sameMaterialCfgCartCurrentMaterials.Contains(cfgCartCurrentMaterial))
                    {
                        List <AST_LesTaskItem> astLesTaskItems = cfgCartCurrentMaterial
                                                                 .AST_CartTaskItem
                                                                 .AST_PalletTaskItem
                                                                 .AST_LesTaskItems
                                                                 .ToList();
                        foreach (AST_LesTaskItem astLesTaskItem in astLesTaskItems)
                        {
                            if (astLesTaskItem.AST_LesTask.ProjectCode.EndsWith(projectCode) && astLesTaskItem.AST_LesTask.ProjectStep.EndsWith(projectStep))
                            {
                                sameMaterialCfgCartCurrentMaterials.Add(cfgCartCurrentMaterial);
                                break;
                            }
                        }
                    }
                }

                //如果给出了批次,则应用限制
                if (!string.IsNullOrEmpty(batchCode))
                {
                    for (int i = sameMaterialCfgCartCurrentMaterials.Count - 1; i >= 0; i--)
                    {
                        if (sameMaterialCfgCartCurrentMaterials[i].BatchCode != batchCode)
                        {
                            sameMaterialCfgCartCurrentMaterials.RemoveAt(i);
                        }
                    }
                }

                //如果料不够,一个原始装配明细可能被拆分到不同库位,生成多个指引明细
                int currentAsmAssembleIndicationItemAssignedQuantity = 0;
                while (currentAsmAssembleIndicationItemAssignedQuantity < asmAssembleIndicationItem.ToAssembleQuantity)
                {
                    //找到第一个未被完全锁定的库位
                    CFG_CartCurrentMaterial cfgCartCurrentMaterial = null;

                    //针对单个储位的未完成明细数量
                    int unfinishedQuantity = 0;

                    int temporaryLockedQuantity = lockedQuantity;
                    foreach (CFG_CartCurrentMaterial temporaryCfgCartCurrentMaterial in sameMaterialCfgCartCurrentMaterials)
                    {
                        //未完成的任务也会锁定库存
                        List <ASM_TaskItem> unfinishedAsmTaskItems = dbContext.ASM_TaskItems
                                                                     .Where(ti => ti.CFG_CartId == temporaryCfgCartCurrentMaterial.CFG_CartId &&
                                                                            ti.CartPosition == temporaryCfgCartCurrentMaterial.Position &&
                                                                            ti.AssembleStatus != AssembleStatus.Finished)
                                                                     .ToList();
                        unfinishedQuantity = 0;
                        foreach (ASM_TaskItem unfinishedAsmTaskItem in unfinishedAsmTaskItems)
                        {
                            unfinishedQuantity += unfinishedAsmTaskItem.ToAssembleQuantity;
                            if (unfinishedAsmTaskItem.AssembledQuantity != null)
                            {
                                unfinishedQuantity -= unfinishedAsmTaskItem.AssembledQuantity.Value;
                            }
                        }

                        if (temporaryLockedQuantity < temporaryCfgCartCurrentMaterial.Quantity - unfinishedQuantity)
                        {
                            cfgCartCurrentMaterial = temporaryCfgCartCurrentMaterial;

                            break;
                        }
                        else
                        {
                            temporaryLockedQuantity -= temporaryCfgCartCurrentMaterial.Quantity.Value - unfinishedQuantity;

                            if (temporaryLockedQuantity < 0)
                            {
                                temporaryLockedQuantity = 0;
                            }
                        }
                    }

                    if (cfgCartCurrentMaterial == null)
                    {
                        int unfinishedAsmTaskItemsQuantity = dbContext.ASM_TaskItems
                                                             .Where(ti => ti.ASM_Task.ASM_AssembleIndication.CFG_WorkStationId == asmAssembleIndication.CFG_WorkStationId &&
                                                                    ti.ASM_AssembleIndicationItem.MaterialCode == asmAssembleIndicationItem.MaterialCode &&
                                                                    ti.AssembleStatus != AssembleStatus.Finished)
                                                             .Select(ti => ti.ToAssembleQuantity)
                                                             .ToList()
                                                             .Sum();
                        List <string> storageDetails = dbContext.CFG_CartCurrentMaterials
                                                       .Where(ccm => ccm.BatchCode == asmAssembleIndicationItem.BatchCode &&
                                                              ccm.CFG_WorkStationId == asmAssembleIndication.CFG_WorkStationId &&
                                                              ccm.MaterialCode == asmAssembleIndicationItem.MaterialCode &&
                                                              ccm.Quantity > 0)
                                                       .ToList()
                                                       .Select(ccm => ccm.CFG_Cart.Name + " 储位 " + ccm.Position + " 存量 " + ccm.Quantity + " (" + ccm.ProjectCode + ", " + ccm.ProjectStep + ")")
                                                       .ToList();
                        List <string> dockedCfgCartNames = dockedCfgCarts
                                                           .Select(c => c.Name)
                                                           .ToList();
                        int lesPickedQuantity = dbContext.AST_LesTaskItems
                                                .Where(lti => lti.MaterialCode == asmAssembleIndicationItem.MaterialCode &&
                                                       lti.AST_LesTask.BatchCode == asmAssembleIndicationItem.BatchCode)
                                                .Select(lti => lti.ToPickQuantity)
                                                .ToList()
                                                .Sum();
                        List <string> mesAssembledItems = dbContext.ASM_AssembleIndicationItems
                                                          .Include(aii => aii.ASM_AssembleIndication)
                                                          .Where(aii => aii.MaterialCode == asmAssembleIndicationItem.MaterialCode &&
                                                                 aii.BatchCode == asmAssembleIndicationItem.BatchCode)
                                                          .ToList()
                                                          .Select(aii => aii.ASM_AssembleIndication.ProductSequence + "," + aii.AssembledQuantity)
                                                          .ToList();

                        string message = "线边库存不足:" + materialCode + "。" + Environment.NewLine
                                         + "需求数量:" + asmAssembleIndicationItem.ToAssembleQuantity + Environment.NewLine;
                        if (unfinishedAsmTaskItemsQuantity > 0)
                        {
                            message += "前车未完:" + unfinishedAsmTaskItemsQuantity + Environment.NewLine;
                        }
                        if (storageDetails.Count > 0)
                        {
                            message += "料车存量:" + Environment.NewLine;
                            message += string.Join(Environment.NewLine, storageDetails) + Environment.NewLine;
                        }
                        if (dockedCfgCartNames.Count > 0)
                        {
                            message += "停靠料车:" + string.Join(", ", dockedCfgCartNames) + Environment.NewLine;
                        }
                        message += "LES 出库数量:" + lesPickedQuantity + Environment.NewLine;
                        if (mesAssembledItems.Count > 0)
                        {
                            message += "MES 使用情况:" + Environment.NewLine;
                            message += string.Join(Environment.NewLine, mesAssembledItems) + Environment.NewLine;
                        }

                        throw new Exception(message);
                    }

                    int remainQuantity     = cfgCartCurrentMaterial.Quantity.Value - unfinishedQuantity - temporaryLockedQuantity;
                    int toAssembleQuantity = asmAssembleIndicationItem.ToAssembleQuantity - currentAsmAssembleIndicationItemAssignedQuantity;
                    toAssembleQuantity = Math.Min(remainQuantity, toAssembleQuantity);

                    ASM_TaskItem asmTaskItem = new ASM_TaskItem();
                    asmTaskItem.ASM_Task = asmTask;
                    asmTaskItem.ASM_AssembleIndicationItem = asmAssembleIndicationItem;
                    asmTaskItem.Gzz                = asmAssembleIndicationItem.Gzz;
                    asmTaskItem.CFG_CartId         = cfgCartCurrentMaterial.CFG_CartId;
                    asmTaskItem.CartPosition       = cfgCartCurrentMaterial.Position;
                    asmTaskItem.AssembleSequence   = asmAssembleIndicationItem.AssembleSequence;
                    asmTaskItem.ToAssembleQuantity = toAssembleQuantity;
                    asmTaskItem.Qtxbs              = asmAssembleIndicationItem.Qtxbs;
                    asmTaskItem.AssembleStatus     = AssembleStatus.New;

                    dbContext.ASM_TaskItems.Add(asmTaskItem);

                    lockedQuantity += toAssembleQuantity;
                    lockedQuantityByMaterialCode[materialCode] = lockedQuantity;

                    currentAsmAssembleIndicationItemAssignedQuantity += toAssembleQuantity;
                }
            }
        }
Пример #4
0
        void threadStart(object notUsed)
        {
            while (true)
            {
                //加载线程推动新明细,按钮交互推进明细的进度
                if (this.CurrentAsmTaskId != null && this.CurrentAsmTaskItemId == null)
                {
                    try
                    {
                        using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                        {
                            CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations
                                                             .First(ws => ws.Id == this.CFG_WorkStationId);
                            ASM_Task asmTask = dbContext.ASM_Tasks
                                               .First(t => t.Id == this.CurrentAsmTaskId.Value);

                            //因为 IndicatingExecutorLoader 加载和 IndicatingExecutor 是不同线程,所以再次核对状态
                            if (asmTask.AssembleStatus == AssembleStatus.Finished)
                            {
                                this.CurrentAsmTaskId = null;

                                continue;
                            }

                            ASM_AssembleIndication asmAssembleIndication = asmTask.ASM_AssembleIndication;
                            ASM_TaskItem           asmTaskItem           = dbContext.ASM_TaskItems
                                                                           .OrderBy(ti => ti.Gzz)
                                                                           .ThenBy(ti => ti.AssembleSequence)
                                                                           .FirstOrDefault(ti => ti.ASM_TaskId == asmTask.Id &&
                                                                                           ti.AssembleStatus != AssembleStatus.Finished);
                            if (asmTaskItem == null)
                            {
                                asmTask.AssembleStatus = AssembleStatus.Finished;
                                asmAssembleIndication.AssembleStatus = asmTask.AssembleStatus;

                                #region 当前装配可以提交

                                List <ASM_AssembleIndicationItem> asmAssembleIndicatonItems = asmAssembleIndication.ASM_AssembleIndicationItems
                                                                                              .ToList();

                                ASM_AssembleResult asmAssembleResult = new ASM_AssembleResult();
                                asmAssembleResult.ASM_AssembleIndicationId = asmAssembleIndication.Id;
                                asmAssembleResult.FactoryCode        = asmAssembleIndication.FactoryCode;
                                asmAssembleResult.ProductionLineCode = asmAssembleIndication.ProductionLineCode;
                                asmAssembleResult.CFG_WorkStationId  = asmAssembleIndication.CFG_WorkStationId;
                                asmAssembleResult.GzzList            = asmAssembleIndication.GzzList;
                                asmAssembleResult.MONumber           = asmAssembleIndication.MONumber;
                                asmAssembleResult.ProductSequence    = asmAssembleIndication.ProductSequence;
                                asmAssembleResult.BeginTime          = asmTask.ASM_TaskItems.OrderBy(ati => ati.AssembledTime).First().AssembledTime.Value;
                                asmAssembleResult.EndTime            = asmTask.ASM_TaskItems.OrderBy(ati => ati.AssembledTime).Last().AssembledTime.Value;

                                dbContext.ASM_AssembleResults.Add(asmAssembleResult);

                                ASM_AssembleResultMessage asmAssembleResultMessage = new ASM_AssembleResultMessage();
                                asmAssembleResultMessage.ASM_AssembleResult = asmAssembleResult;
                                asmAssembleResultMessage.SentSuccessful     = false;

                                dbContext.ASM_AssembleResultMessages.Add(asmAssembleResultMessage);

                                foreach (ASM_AssembleIndicationItem asmAssembleIndicationItem in asmAssembleIndicatonItems)
                                {
                                    List <ASM_TaskItem> asmTaskItems = asmAssembleIndicationItem.ASM_TaskItems
                                                                       .ToList();
                                    ASM_TaskItem lastAsmTaskItem = asmTaskItems.Last();

                                    ASM_AssembleResultItem asmAssembleResultItem = new ASM_AssembleResultItem();
                                    asmAssembleResultItem.ASM_AssembleResult = asmAssembleResult;
                                    asmAssembleResultItem.CFG_CartId         = lastAsmTaskItem.CFG_CartId;
                                    asmAssembleResultItem.CartPosition       = lastAsmTaskItem.CartPosition;
                                    asmAssembleResultItem.Gzz                = asmAssembleIndicationItem.Gzz;
                                    asmAssembleResultItem.MaterialCode       = asmAssembleIndicationItem.MaterialCode;
                                    asmAssembleResultItem.MaterialName       = asmAssembleIndicationItem.MaterialName;
                                    asmAssembleResultItem.AssembleSequence   = asmAssembleIndicationItem.AssembleSequence;
                                    asmAssembleResultItem.ToAssembleQuantity = asmAssembleIndicationItem.ToAssembleQuantity;
                                    asmAssembleResultItem.AssembledQuantity  = asmTaskItems.Sum(ti => ti.AssembledQuantity.Value);
                                    asmAssembleResultItem.PickedTime         = lastAsmTaskItem.AssembledTime.Value;
                                    asmAssembleResultItem.ProjectCode        = asmAssembleIndicationItem.ProjectCode;
                                    asmAssembleResultItem.ProjectStep        = asmAssembleIndicationItem.ProjectStep;

                                    dbContext.ASM_AssembleResultItems.Add(asmAssembleResultItem);
                                }

                                #endregion

                                dbContext.SaveChanges();

                                this.CurrentAsmTaskId = null;

                                Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " 装配任务完成:"
                                           + asmAssembleIndication.ProductSequence + ", "
                                           + asmAssembleIndication.GzzList + Environment.NewLine);
                            }
                            else
                            {
                                ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem;
                                CFG_Cart cfgCart = asmTaskItem.CFG_Cart;

                                //先更新数据库
                                asmTask.AssembleStatus                   = AssembleStatus.Assembling;
                                asmTaskItem.AssembleStatus               = AssembleStatus.Assembling;
                                asmAssembleIndication.AssembleStatus     = AssembleStatus.Assembling;
                                asmAssembleIndicationItem.AssembleStatus = AssembleStatus.Assembling;
                                cfgCart.CartStatus = CartStatus.Indicating;

                                dbContext.SaveChanges();

                                //再控制设备
                                CartPtl cartPtl          = CartPtlHost.Instance.GetCartPtl(asmTaskItem.CFG_CartId);
                                Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher();
                                Ptl900U ptl900U          = cartPtl.GetPtl900UByPosition(asmTaskItem.CartPosition);
                                Ptl900U ptl900ULight     = cartPtl.GetPtl900ULight();

                                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           = 0;

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

                                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.Pressed += this.ptl900UPublisher_Pressed;
                                ptl900UPublisher.Clear(true);
                                //ptl900UPublisher.Unlock();
                                ptl900UPublisher.Lock();
                                ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off, true);

                                ptl900U.Pressed += this.ptl900U_Pressed;
                                ptl900U.Unlock();
                                ptl900U.Display(display900UItem, lightMode, true);

                                ptl900ULight.Clear();
                                ptl900ULight.Display(new Display900UItem(), lightMode, false);

                                this.CurrentAsmTaskItemId = asmTaskItem.Id;

                                Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " 点亮装配明细:"
                                           + asmAssembleIndication.ProductSequence + ", "
                                           + asmAssembleIndication.GzzList + ", "
                                           + asmAssembleIndicationItem.MaterialCode + ", "
                                           + asmAssembleIndicationItem.MaterialName + ", "
                                           + cfgCart.Name + ", "
                                           + asmTaskItem.CartPosition + Environment.NewLine);

                                //如果新底盘抵达,则自动完成之前的
                                this.AutoPressByNewCarArrivedAsync(this.CurrentAsmTaskId.Value, this.CurrentAsmTaskItemId.Value, ptl900U, display900UItem);
                                //如果长时间无法交互,则自动交互
                                this.AutoPressByDeviceErrorAsync(this.CurrentAsmTaskItemId.Value, ptl900U, display900UItem);
                            }
                        }
                    }
                    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.threadStart", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine
                                   + message + Environment.NewLine
                                   + Environment.NewLine);

                        Thread.Sleep(1000);
                    }
                }

                Thread.Sleep(1);
            }
        }