コード例 #1
0
        //完成当前
        private void bFinishThis_click(object sender, RoutedEventArgs e)
        {
            MesJobOrder mesJobOrder = gridorder.GetFocusedRow() as MesJobOrder;

            if (mesJobOrder == null)
            {
                return;
            }

            if (WPFMessageBox.ShowConfirm("确定要完成当前工序吗?", "完成当前工序") != WPFMessageBoxResult.OK)
            {
                return;
            }

            List <MesProcessCtrol> processCtrols = ws.UseService(s => s.GetMesProcessCtrols($"PROCESS_STATE < 10 "))
                                                   .OrderBy(c => c.PROCESS_INDEX).ThenBy(c => c.CREATION_DATE).ToList(); //执行的动作

            MesProcessCtrol processCtrol = processCtrols.FirstOrDefault(c => c.JOB_ORDER_PKNO == mesJobOrder.PKNO);

            if (processCtrol == null)
            {
                return;
            }

            var result = DeviceProcessControl.FinishCurBusiness(processCtrol);

            if (result != "OK")
            {
                WPFMessageBox.ShowError("当前工序的业务层完成错误,请核实。\r\n错误为:" + result, "完成当前工序");
                return;
            }
            processCtrol.PROCESS_STATE = 10;    //执行完成
            ws.UseService(s => s.UpdateMesProcessCtrol(processCtrol));


            if (processCtrol == processCtrols.LastOrDefault())
            {
                mesJobOrder.PROCESS_INFO    = "手动完成当前过程"; //生产执行信息
                mesJobOrder.ACT_FINISH_TIME = DateTime.Now;
                mesJobOrder.RUN_STATE       = 101;        //手动完成
                mesJobOrder.ONCE_QTY        = 1;          //默认订单为1
                mesJobOrder.COMPLETE_QTY    = 1;
            }
            else
            {
                mesJobOrder.PROCESS_INFO = "手动完成当前订单";  //生产执行信息
            }

            ws.UseService(s => s.UpdateMesJobOrder(mesJobOrder));

            gridItem.ItemsSource = ws.UseService(s =>
                                                 s.GetMesProcessCtrols($"JOB_ORDER_PKNO = '{mesJobOrder.PKNO}' "))
                                   .OrderBy(c => c.PROCESS_INDEX).ThenBy(c => c.CREATION_DATE).ToList();
        }
コード例 #2
0
        public bool FinishProgress()
        {
            if (curProcess.PROCESS_STATE == 2)                                                          //正在执行,完成该动作
            {
                if (!string.IsNullOrEmpty(startCondition) && !LimitConditions.Contains(startCondition)) //未完成的任务需要增加开始条件
                {
                    LimitConditions.Add(startCondition);
                }

                #region 完成执行工序 共 3 步

                /************ !!!工序完成的条件!!!  ************/
                string sCurFinishValue = "";  //当前完成的结果

                #region 1. 检验当前工序是否完成,未完成,则下一个任务

                FmsAssetTagSetting finishTag = jobTaskMode.CopyTags.FirstOrDefault(c => c.PKNO == curAction.FINISH_CONDITION_TAG_PKNO);

                if (finishTag != null)
                {
                    string condition = finishTag.PKNO + ".VALUE = " + curAction.FINISH_CONDITION_VALUE;

                    //如果前面的Job存在需要判断该状态,则不执行完成当前
                    if ((startCondition != condition) && LimitConditions.Contains(condition))
                    {
                        string sErrorInfo =
                            $"正在执行[{ctrolName}],完成条件[{finishTag?.TAG_NAME}]不足.";
                        if (mesJobOrder.PROCESS_INFO != sErrorInfo)
                        {
                            mesJobOrder.PROCESS_INFO = sErrorInfo; //生产执行信息
                            PServiceEvent?.Invoke(s => s.UpdateMesJobOrder(mesJobOrder));
                        }

                        if (FMSControlService.bStart)
                        {
                            return(true);
                        }
                    }

                    if (finishTag.SAMPLING_MODE == 11)  //动作开始后自动开启 => 尚未开启,需要开启
                    {
                        var tag0 = DeviceMonitor.GetTagSettingById(curAction.FINISH_CONDITION_TAG_PKNO);
                        tag0.SAMPLING_MODE = 10;                    //尚未开启,需要开启
                        DeviceMonitor.SetTagSettingValue(tag0, ""); //清空完成条件

                        if (FMSControlService.bStart)
                        {
                            return(true);
                        }
                    }

                    sCurFinishValue = finishTag.CUR_VALUE;             //当前设备的值

                    string checkValue = sCurFinishValue.Split('|')[0]; //多结果情况,适用于检测

                    string   finishValue  = curAction.FINISH_CONDITION_VALUE;
                    string[] finishValues = finishValue.Split('|'); //多个完成条件

                    if (!finishValues.Contains(checkValue))         //当前值不是工序结束值,不完成
                    {
                        string sErrorInfo =
                            $"正在执行[{ctrolName}],获取到完成结果为[{checkValue}],判断完成条件为[{finishValue}],生产过程[{ctrolName}]尚未完成.";
                        if (mesJobOrder.PROCESS_INFO != sErrorInfo)
                        {
                            mesJobOrder.PROCESS_INFO = sErrorInfo; //生产执行信息
                            PServiceEvent?.Invoke(s => s.UpdateMesJobOrder(mesJobOrder));
                        }

                        if (!LimitConditions.Contains(condition))
                        {
                            LimitConditions.Add(condition);                                       //完成条件不满足
                        }
                        if (FMSControlService.bStart)
                        {
                            return(true);
                        }
                    }

                    //移除完成限制条件
                    LimitConditions.Remove(condition);  //完成条件满足 则移除不满足的条件

                    if (string.IsNullOrEmpty(startCondition))
                    {
                        LimitConditions.Remove(startCondition);                                        //移除开始的限制条件
                    }
                }
                else  //没有动作完成的检测值,手动完成。
                {
                    string sErrorInfo = $"生产过程[{ctrolName}]没有设置过程完成的检测值,请手动完成该过程."; //生产执行信息
                    if (mesJobOrder.PROCESS_INFO != sErrorInfo)
                    {
                        mesJobOrder.PROCESS_INFO = sErrorInfo; //生产执行信息
                        PServiceEvent?.Invoke(s => s.UpdateMesJobOrder(mesJobOrder));
                    }

                    if (string.IsNullOrEmpty(startCondition))
                    {
                        LimitConditions.Remove(startCondition);                                        //移除开始的限制条件
                    }
                    if (FMSControlService.bStart)
                    {
                        return(true);
                    }
                }

                #endregion

                /************ !!!工序已经完成!!!  ************/

                Console.WriteLine($"收到设备完成指令,完成反馈结果为[{sCurFinishValue}],完成生产过程[{ctrolName}]");

                #region 2. 根据工序类型处理 完成当前工序

                if (curProcess.PROCESS_ACTION_TYPE == 3) //检测完成
                {
                    //合格数量
                    string[] checkResult     = sCurFinishValue.Split('|');
                    int      qualifiedNumber = 1; //合格品数量
                    if (checkResult.Count() >= 2)
                    {
                        qualifiedNumber = SafeConverter.SafeToInt(checkResult[1], 1);
                    }
                    curProcess.COMPLETE_QTY  = qualifiedNumber;                                                            //生产数量 - 含不合格的丢弃
                    curProcess.QUALIFIED_QTY = qualifiedNumber;                                                            //合格品数量

                    mesJobOrder.ONLINE_QTY = mesJobOrder.ONLINE_QTY - firstProcess.PROCESS_QTY + curProcess.QUALIFIED_QTY; //在线数量,更新再制品数量
                    if (mesJobOrder.ONLINE_QTY < 0)
                    {
                        mesJobOrder.ONLINE_QTY = 0;
                    }
                }

                if (productProcess != null)
                {
                    if (bLastProcess)
                    {
                        productProcess.PRODUCT_STATE = 100;                             //最后一道工序 正常完成
                    }
                    string result = DeviceProcessControl.FinishCurBusiness(curProcess); //完成业务
                    if (result != "OK")
                    {
                        string sErrorInfo = $"业务完成失败,写入数据库错误!";
                        if (mesJobOrder.PROCESS_INFO != sErrorInfo)
                        {
                            mesJobOrder.PROCESS_INFO = sErrorInfo; //生产执行信息
                            PServiceEvent?.Invoke(s => s.UpdateMesJobOrder(mesJobOrder));
                        }
                    }
                }

                #region 已删除 - 之前的方式

                if (curProcess.PROCESS_ACTION_TYPE == 1) //加工完成
                {
                    //if (productProcess != null)
                    //{
                    //    productProcess.CUR_ITEM_PKNO = curProcess.FINISH_ITEM_PKNO; //生产完成
                    //}
                }
                else if (curProcess.PROCESS_ACTION_TYPE == 2) //搬运完成
                {
                    //if (productProcess != null)
                    //{
                    //    productProcess.PRODUCT_POSITION = curProcess.FINISH_POSITION; //目标位置
                    //}
                }
                else if (curProcess.PROCESS_ACTION_TYPE == 3) //检测完成
                {
                    //合格数量
                    string[] result          = sCurFinishValue.Split('|');
                    int      qualifiedNumber = 1; //合格品数量
                    if (result.Count() >= 2)
                    {
                        qualifiedNumber = SafeConverter.SafeToInt(result[1], 1);
                    }
                    curProcess.COMPLETE_QTY  = qualifiedNumber;                                                            //生产数量 - 含不合格的丢弃
                    curProcess.QUALIFIED_QTY = qualifiedNumber;                                                            //合格品数量

                    mesJobOrder.ONLINE_QTY = mesJobOrder.ONLINE_QTY - firstProcess.PROCESS_QTY + curProcess.QUALIFIED_QTY; //在线数量,更新再制品数量
                    if (mesJobOrder.ONLINE_QTY < 0)
                    {
                        mesJobOrder.ONLINE_QTY = 0;
                    }
                }
                else if (curProcess.PROCESS_ACTION_TYPE == 11) //出库完成
                {
                    //if (productProcess != null) productProcess.PRODUCT_POSITION = curProcess.FINISH_POSITION; //目标位置

                    //#region 解锁货位地址 - 货位清空

                    //if (!string.IsNullOrEmpty(curProcess.BEGIN_POSITION))
                    //{
                    //    WmsAllocationInfo rawAllo = wsWMS.UseService(s =>
                    //        s.GetWmsAllocationInfoById(curProcess.BEGIN_POSITION));

                    //    if (rawAllo != null)
                    //    {
                    //        rawAllo.CUR_PALLET_NO = "";
                    //        rawAllo.ALLOCATION_STATE = 0;  //空

                    //        wsWMS.UseService(s => s.UpdateWmsAllocationInfo(rawAllo));

                    //        WmsInventory inv = wsWMS.UseService(s => s.GetWmsInventorys($"ALLOCATION_PKNO = '{rawAllo.PKNO}'"))
                    //            .FirstOrDefault();

                    //        if (inv != null) wsWMS.UseService(s => s.DelWmsInventory(inv.PKNO));
                    //    }
                    //}

                    //#endregion
                }
                else if (curProcess.PROCESS_ACTION_TYPE == 12) //入库完成
                {
                    //if (productProcess != null) productProcess.PRODUCT_POSITION = curProcess.FINISH_POSITION; //目标位置

                    //#region 产品入库处理 - 解锁货位地址、增加产品库存

                    //if (!string.IsNullOrEmpty(curProcess.FINISH_POSITION))
                    //{
                    //    WmsAllocationInfo prodAllo = wsWMS.UseService(s =>
                    //        s.GetWmsAllocationInfoById(curProcess.FINISH_POSITION));

                    //    if (prodAllo != null)  //入库货位
                    //    {
                    //        prodAllo.ALLOCATION_STATE = 100; //满货位

                    //        WmsInventory inv = new WmsInventory()
                    //        {
                    //            PKNO = CBaseData.NewGuid(),
                    //            COMPANY_CODE = "",
                    //            MATERIAL_PKNO = curProcess.FINISH_ITEM_PKNO,
                    //            ALLOCATION_PKNO = prodAllo.PKNO,
                    //            AREA_PKNO = prodAllo.AREA_PKNO,
                    //            BATCH_NO = curProcess.SUB_JOB_ORDER_NO,
                    //            INVENTORY_NUM = 1, //curProcess.QUALIFIED_QTY?? 1,
                    //            REMARK = "",
                    //        };  //库存

                    //        wsWMS.UseService(s => s.UpdateWmsAllocationInfo(prodAllo));  //修改货位

                    //        wsWMS.UseService(s => s.AddWmsInventory(inv));
                    //    }
                    //}

                    //#endregion
                }
                else if ((curProcess.PROCESS_ACTION_TYPE >= 40) &&
                         (curProcess.PROCESS_ACTION_TYPE < 50)) //换刀
                {
                    //40:换刀;41:取刀;42:卸刀;43:装刀;44:放刀
                    //if (curProcess.PROCESS_ACTION_TYPE == 41)  //取刀
                    //{
                    //    TmsToolsMaster mToolsMaster = wsTMS.UseService(s =>
                    //        s.GetTmsToolsMasterById(curProcess.BEGIN_ITEM_PKNO));   //装上刀具
                    //    if (mToolsMaster != null)
                    //    {
                    //        mToolsMaster.TOOLS_POSITION = 10;  //出库
                    //        mToolsMaster.TOOLS_POSITION_PKNO = "";
                    //        wsTMS.UseService(s => s.UpdateTmsToolsMaster(mToolsMaster));
                    //    }
                    //}
                    //else if (curProcess.PROCESS_ACTION_TYPE == 42)  //卸刀
                    //{
                    //    TmsDeviceToolsPos mTmsDeviceToolsPos = wsTMS.UseService(s => s.GetTmsDeviceToolsPosById(curProcess.BEGIN_ITEM_PKNO)); //卸下刀具
                    //    if (mTmsDeviceToolsPos != null)
                    //    {
                    //        mTmsDeviceToolsPos.TOOLS_PKNO = "";
                    //        wsTMS.UseService(s => s.UpdateTmsDeviceToolsPos(mTmsDeviceToolsPos));    //更新
                    //    }
                    //    TmsToolsMaster mToolsMaster = wsTMS.UseService(s =>
                    //        s.GetTmsToolsMasterById(curProcess.FINISH_ITEM_PKNO));  //卸下刀具
                    //    if (mToolsMaster != null)
                    //    {
                    //        mToolsMaster.TOOLS_POSITION = 10;  //已出库
                    //        mToolsMaster.TOOLS_POSITION_PKNO = "";
                    //        wsTMS.UseService(s => s.UpdateTmsToolsMaster(mToolsMaster));  //已出库
                    //    }
                    //}
                    //else if (curProcess.PROCESS_ACTION_TYPE == 43)  //装刀
                    //{
                    //    TmsDeviceToolsPos mTmsDeviceToolsPos = wsTMS.UseService(s => s.GetTmsDeviceToolsPosById(curProcess.BEGIN_ITEM_PKNO)); //装上刀具
                    //    if (mTmsDeviceToolsPos != null)
                    //    {
                    //        mTmsDeviceToolsPos.TOOLS_PKNO = curProcess.FINISH_ITEM_PKNO;  //装上刀具PKNO
                    //        wsTMS.UseService(s => s.UpdateTmsDeviceToolsPos(mTmsDeviceToolsPos));    //更新
                    //    }
                    //    TmsToolsMaster mToolsMaster = wsTMS.UseService(s =>
                    //        s.GetTmsToolsMasterById(curProcess.FINISH_ITEM_PKNO)); //装上刀具PKNO
                    //    if (mToolsMaster != null)
                    //    {
                    //        mToolsMaster.TOOLS_POSITION = 2;  //在设备
                    //        mToolsMaster.TOOLS_POSITION_PKNO = curProcess.BEGIN_POSITION;  //装刀机床PKNO
                    //        wsTMS.UseService(s => s.UpdateTmsToolsMaster(mToolsMaster));  //已出库
                    //    }
                    //}
                    //else if (curProcess.PROCESS_ACTION_TYPE == 44)  //放刀
                    //{
                    //    TmsToolsMaster mToolsMaster = wsTMS.UseService(s =>
                    //        s.GetTmsToolsMasterById(curProcess.BEGIN_ITEM_PKNO));   //卸下刀具
                    //    if (mToolsMaster != null)
                    //    {
                    //        mToolsMaster.TOOLS_POSITION = 1;
                    //        mToolsMaster.TOOLS_POSITION_PKNO = curProcess.FINISH_ITEM_PKNO;   //位置信息
                    //        wsTMS.UseService(s => s.UpdateTmsToolsMaster(mToolsMaster));  //已出库
                    //    }
                    //}
                }

                #endregion

                #endregion

                #region 3. 更新数据  共更新 4 个类

                #region 3.1 加工控制

                curProcess.PROCESS_END_TIME = DateTime.Now;
                curProcess.PROCESS_STATE    = 10;
                curProcess.PROCESS_END_TYPE = 1;
                PServiceEvent?.Invoke(s => s.UpdateMesProcessCtrol(curProcess));
                #endregion

                #region 3.2 Job处理

                #region 最后一道工序的处理

                mesJobOrder.PROCESS_INFO = "正常"; //生产执行信息

                if (bLastProcess)                //最后一道工序
                {
                    mesJobOrder.COMPLETE_QTY    = curProcess.COMPLETE_QTY;
                    mesJobOrder.ONLINE_QTY      = 0;   //任务完成
                    mesJobOrder.ACT_FINISH_TIME = DateTime.Now;
                    mesJobOrder.RUN_STATE       = 100; //正常完成
                    mesJobOrder.PROCESS_INFO    = $"正常完成,计划数量[{mesJobOrder.TASK_QTY}],完成数量[{mesJobOrder.COMPLETE_QTY}]";
                    Console.WriteLine($"订单[{mesJobOrder.JOB_ORDER_NO}]生产完成,计划数量[{mesJobOrder.TASK_QTY}],完成数量[{mesJobOrder.COMPLETE_QTY}]");
                }

                #endregion
                PServiceEvent?.Invoke(s => s.UpdateMesJobOrder(mesJobOrder));


                #endregion

                #region 3.4 清空完成反馈状态,将完成条件置空

                var tag = DeviceMonitor.GetTagSettingById(curAction.FINISH_CONDITION_TAG_PKNO);
                if (tag != null) //将完成结果置为空
                {
                    if (tag.SAMPLING_MODE == 10)
                    {
                        tag.SAMPLING_MODE = 11;                          //按照条件关闭
                    }
                    DeviceMonitor.SetTagSettingValue(tag, "");
                }

                #endregion

                #endregion

                #endregion

                Thread.Sleep(50);
                return(true);
            }
            return(true);
        }