分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-04-27 0b5ccdca6263cf7a2cee460f30c76ef1efea2811
´úÂë¹ÜÀí/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs
@@ -1,8 +1,10 @@
using FreeSql.Internal.Model;
using Newtonsoft.Json;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
@@ -10,6 +12,7 @@
using WIDESEA_Comm.LogInfo;
using WIDESEA_Comm.TaskNo;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.FreeDB;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.JobsPart.Common;
@@ -36,6 +39,7 @@
                VOLContext Context = new VOLContext();
                Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
                Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
                IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(Context);
                Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
                Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
                Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
@@ -55,32 +59,47 @@
                        if (name == "3单元辊道下料查询车轮") number = "3单元辊道下料查询订单";
                        if (name == "辊道上料查询车轮") number = "辊道上料查询订单";
                        var wp_id = client.ReadByOrder<string>("R_o_wp_id", number);
                        var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == wp_id);
                        if (mes_Detail == null)
                        var Mes_Work = workinfoRepository.Find(x => x.SN == wp_id && x.processCode == (name != "辊道上料查询车轮" ? "17" : "28")).FirstOrDefault();
                        if (Mes_Work == null)
                        {
                            client.WriteByOrder("W_i_status", (byte)2, name);
                            client.WriteByOrder("R_oi_on", (byte)0, name);
                            #region æ—¥å¿—记录
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单详情", "PCS");
                            #endregion
                            continue;
                        }
                        var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
                        if (mes_Head == null)
                        {
                            client.WriteByOrder("W_i_status", (byte)2, name);
                            client.WriteByOrder("R_oi_on", (byte)0, name);
                            #region æ—¥å¿—记录
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单头表", "PCS");
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单信息", "PCS");
                            #endregion
                            continue;
                        }
                        #region MyRegion
                        //var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == wp_id);
                        //if (mes_Detail == null)
                        //{
                        //    client.WriteByOrder("W_i_status", (byte)2, name);
                        //    client.WriteByOrder("R_oi_on", (byte)0, name);
                        //    #region æ—¥å¿—记录
                        //    WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单详情", "PCS");
                        //    #endregion
                        //    continue;
                        //}
                        //var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
                        //if (mes_Head == null)
                        //{
                        //    client.WriteByOrder("W_i_status", (byte)2, name);
                        //    client.WriteByOrder("R_oi_on", (byte)0, name);
                        //    #region æ—¥å¿—记录
                        //    WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单头表", "PCS");
                        //    #endregion
                        //    continue;
                        //}
                        #endregion
                        if (name != "辊道上料查询车轮")
                        {
                            //var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
                            var geometry = dataRepository.Find(x => x.Description == mes_Head.drawingNo).FirstOrDefault();
                            var geometry1 = detectionlineRepository.Find(x => x.Description == mes_Head.drawingNo).FirstOrDefault();
                            var geometry = dataRepository.Find(x => x.Description == Mes_Work.drawingNo).FirstOrDefault();
                            var geometry1 = detectionlineRepository.Find(x => x.Description == Mes_Work.drawingNo).FirstOrDefault();
                            if (geometry == null && geometry1 == null)
                            {
                                //DBExtension.Write(details.Where(x => x.plcdetail_name == "W_i_status").First(), client, (Int16)2);
@@ -120,8 +139,8 @@
                        }
                        else
                        {
                            var geometry = detectionlineRepository.Find(x => x.Description == mes_Head.drawingNo).FirstOrDefault();
                            var geometry1 = dataRepository.Find(x => x.Description == mes_Head.drawingNo).FirstOrDefault();
                            var geometry = detectionlineRepository.Find(x => x.Description == Mes_Work.drawingNo).FirstOrDefault();
                            var geometry1 = dataRepository.Find(x => x.Description == Mes_Work.drawingNo).FirstOrDefault();
                            if (geometry == null && geometry1 == null)
                            {
                                client.WriteByOrder("W_i_status", (byte)2, name);
@@ -182,6 +201,7 @@
                Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
                Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
                Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
                IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(Context);
                Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
                Idt_patternRepository patternRepository = new dt_patternRepository(Context);
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
@@ -205,16 +225,9 @@
                            continue;
                        }
                        var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
                        var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == wp_id);
                        #region æµ‹è¯•使用
                        //if (mes_Detail == null)
                        //{
                        //    mes_Detail = mes_DetailRepository.FindFirst(x => x.jobID == (name == "3单元辊道下料查询订单" ? "01180127004-2" : "01180127004-1"));
                        //    mes_Detail.SN = wp_id;
                        //    mes_DetailRepository.Update(mes_Detail, true);
                        //}
                        #endregion
                        if (mes_Detail == null)
                        var Mes_Work = workinfoRepository.Find(x => x.SN == wp_id && x.processCode == (name != "辊道上料查询订单" ? "17" : "28")).FirstOrDefault();
                        if (Mes_Work == null)
                        {
                            client.WriteByOrder("W_i_status", (byte)2, name);
                            client.WriteByOrder("R_oi_on", (byte)0, name);
@@ -223,16 +236,30 @@
                            #endregion
                            continue;
                        }
                        var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
                        if (mes_Head == null)
                        {
                            client.WriteByOrder("W_i_status", (byte)2, name);
                            client.WriteByOrder("R_oi_on", (byte)0, name);
                            #region æ—¥å¿—记录
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单头表", "PCS");
                            #endregion
                            continue;
                        }
                        #region MyRegion
                        //var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == wp_id);
                        //if (mes_Detail == null)
                        //{
                        //    client.WriteByOrder("W_i_status", (byte)2, name);
                        //    client.WriteByOrder("R_oi_on", (byte)0, name);
                        //    #region æ—¥å¿—记录
                        //    WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单详情", "PCS");
                        //    #endregion
                        //    continue;
                        //}
                        //var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
                        //if (mes_Head == null)
                        //{
                        //    client.WriteByOrder("W_i_status", (byte)2, name);
                        //    client.WriteByOrder("R_oi_on", (byte)0, name);
                        //    #region æ—¥å¿—记录
                        //    WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单头表", "PCS");
                        //    #endregion
                        //    continue;
                        //}
                        #endregion
                        var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == Mes_Work.jobID);
                        if (name != "辊道上料查询订单")
                        {
@@ -264,11 +291,11 @@
                            {
                                //1-好,允许加工,2-不在列表中,3-不加工车轮类型,4-手动入库模式人工未选择库区
                                client.WriteByOrder("W_i_status", (byte)1, name);
                                client.WriteByOrder("W_i_job_id", mes_Detail.jobID, name);
                                client.WriteByOrder("W_i_drawing_id", mes_Head.drawingNo, name);
                                client.WriteByOrder("W_i_heat_id", mes_Detail.heatID, name);
                                client.WriteByOrder("W_i_job_id", Mes_Work.jobID, name);
                                client.WriteByOrder("W_i_drawing_id", Mes_Work.drawingNo, name);
                                client.WriteByOrder("W_i_heat_id", Mes_Work.heatID, name);
                                //client.WriteByOrder("W_i_sourceheat", "", name);
                                client.WriteByOrder("W_i_batch_id", mes_Detail.heatBatchID, name);
                                client.WriteByOrder("W_i_batch_id", Mes_Work.heatBatchID, name);
                                //屏蔽工艺(屏蔽视觉检测/屏蔽涂油)
                                //if (name != "辊道上料查询车轮")
@@ -280,7 +307,7 @@
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Success(name, $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" +
                                    $"\nW_i_job_id:{mes_Detail.jobID}\nW_i_drawing_id:{mes_Head.drawingNo}\nW_i_heat_id:{mes_Detail.heatID}\nW_i_batch_id:{mes_Detail.heatBatchID}" +
                                    $"\nW_i_job_id:{Mes_Work.jobID}\nW_i_drawing_id:{Mes_Work.drawingNo}\nW_i_heat_id:{Mes_Work.heatID}\nW_i_batch_id:{Mes_Work.heatBatchID}" +
                                    $"\nW_i_skip_op_SJ1:{(name == "3单元辊道下料查询订单" ? true : mes_Head.skip_op_1)}\nW_i_skip_op_SJ2:{(name == "3单元辊道下料查询订单" ? true : mes_Head.skip_op_2)}" +
                                    $"\nW_i_skip_op_LT:{mes_Head.skip_op_3}\nR_oi_on:0", "PCS");
                                #endregion
@@ -304,15 +331,15 @@
                            {
                                //1-好,允许加工,2-不在列表中,3-不加工车轮类型,4-手动入库模式人工未选择库区
                                client.WriteByOrder("W_i_status", (byte)1, name);
                                client.WriteByOrder("W_i_job_id", mes_Detail.jobID, name);
                                client.WriteByOrder("W_i_drawing_id", mes_Head.drawingNo, name);
                                client.WriteByOrder("W_i_heat_id", mes_Detail.heatID, name);
                                client.WriteByOrder("W_i_job_id", Mes_Work.jobID, name);
                                client.WriteByOrder("W_i_drawing_id", Mes_Work.drawingNo, name);
                                client.WriteByOrder("W_i_heat_id", Mes_Work.heatID, name);
                                //client.WriteByOrder("W_i_sourceheat", "", name);
                                client.WriteByOrder("W_i_batch_id", mes_Detail.heatBatchID, name);
                                client.WriteByOrder("W_i_batch_id", Mes_Work.heatBatchID, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Success(name, $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\nW_i_job_id:{mes_Detail.jobID}" +
                                    $"\nW_i_drawing_id:{mes_Head.drawingNo}\nW_i_heat_id:{mes_Detail.heatID}\nW_i_batch_id:{mes_Detail.heatBatchID}\nR_oi_on:0", "PCS");
                                WriteDBLog.Success(name, $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\nW_i_job_id:{Mes_Work.jobID}" +
                                    $"\nW_i_drawing_id:{mes_Head.drawingNo}\nW_i_heat_id:{Mes_Work.heatID}\nW_i_batch_id:{Mes_Work.heatBatchID}\nR_oi_on:0", "PCS");
                                #endregion
                            }
                        }
@@ -343,6 +370,7 @@
                Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
                Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
                Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
                IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(Context);
                Idt_patternRepository patternRepository = new dt_patternRepository(Context);
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "链条机");
@@ -357,6 +385,9 @@
                    {
                        var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                        var NGStation = "X01001003";
                        if (name == "2单元下料区") NGStation = "X02001003";
                        if (name == "3单元下料区") NGStation = "X03001002";
                        #region MyRegion
                        //var Wheel_Type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_Type").First(), client);//车轮类型
                        //var Wheel_id = client.ReadByOrder<string>("R_Wheel_id", name);//车轮SN号
@@ -404,33 +435,49 @@
                            var Wheel_SN = client.ReadByOrder<string>("R_Wheel_id", name);//车轮SN号
                            if (string.IsNullOrEmpty(Wheel_SN))
                            {
                                WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN号为空", "PCS");
                                //WriteDBLog.Error(name + "放料完成", $"读取桁架信息:\n车轮SN号为空", "PCS");
                                WriteLog.Write_Log(name + "放料完成出错", "车轮SN号为空", "读取桁架信息:", $"车轮SN号:{Wheel_SN}为空");
                                continue;
                            }
                            //var Wheel_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_id").First(), client).ToString();
                            var Detail = mes_DetailRepository.FindFirst(x => x.SN == Wheel_SN);
                            if (Detail == null)
                            //var Wheel_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_id").First(), client).ToString();
                            var Mes_Work = workinfoRepository.Find(x => x.SN == Wheel_SN && x.processCode == "17").FirstOrDefault();
                            if (Mes_Work == null)
                            {
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN号:{Wheel_SN}\n\n未查询到工单详情", "PCS");
                                //WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN号:{Wheel_SN}\n\n未查询到工单详情", "PCS");
                                WriteLog.Write_Log(name + "放料完成出错", Wheel_SN, "读取桁架信息:", $"车轮SN号:{Wheel_SN}未查询到工单信息");
                                #endregion
                                continue;
                            }
                            var Head = mes_HeadRepository.FindFirst(x => x.jobID == Detail.jobID);
                            if (Head == null)
                            {
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN号:{Wheel_SN}\n\n未查询到工单头表{Detail.jobID}", "PCS");
                                #endregion
                                continue;
                            }
                            #region MyRegion
                            //var Detail = mes_DetailRepository.FindFirst(x => x.SN == Wheel_SN);
                            //if (Detail == null)
                            //{
                            //    #region æ—¥å¿—记录
                            //    WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN号:{Wheel_SN}\n\n未查询到工单详情", "PCS");
                            //    #endregion
                            //    continue;
                            //}
                            //var Head = mes_HeadRepository.FindFirst(x => x.jobID == Detail.jobID && x.processCode == "17");
                            //if (Head == null)
                            //{
                            //    #region æ—¥å¿—记录
                            //    WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN号:{Wheel_SN}\n\n未查询到工单头表{Detail.jobID}", "PCS");
                            //    #endregion
                            //    continue;
                            //}
                            #endregion
                            #endregion
                            var AreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_AreaNr").First(), client);
                            if (AreaNr == 0)
                            {
                                client.WriteByOrder("W_Storage_update", true, name);//货位状态更新
                                continue;
                            }
                            var areaCode = PipelineJob.area_code(name);   //根据下料口单元名获取区域代码
                            var station = stationinfoRepository.FindFirst(x => x.area == areaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString());
@@ -444,14 +491,19 @@
                            }
                            station.bindSN = string.IsNullOrEmpty(station.bindSN) ? Wheel_SN : station.bindSN + "," + Wheel_SN;
                            station.billetID = string.IsNullOrEmpty(station.billetID) ? Mes_Work.billetID.ToString() : station.billetID + "," + Mes_Work.billetID;
                            station.quantity++;
                            if (station.quantity == 1)
                            {
                                station.stationType = Head.drawingNo;
                                station.Number = Head.jobID;
                                station.heatNumber = Detail.heatID;
                                station.stationType = Mes_Work.drawingNo;
                                station.Number = Mes_Work.workOrder;
                                station.heatNumber = Mes_Work.heatID;
                                station.tray_status = "StrogeTray";
                            }
                            //else if (station.stationCode == NGStation)
                            //{
                            //    station.heatNumber = string.IsNullOrEmpty(station.heatNumber) ? Mes_Work.heatID : station.heatNumber + "," + Mes_Work.heatID;
                            //}
                            var count = stationinfoRepository.Update(station, true);
                            if (count < 1)
@@ -462,21 +514,27 @@
                            client.WriteByOrder("W_IndexNr", (Int16)0, name);//托盘上的第几个车轮
                            client.WriteByOrder("W_Storage_Type", (Int16)0, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                            client.WriteByOrder("W_Storage_update", true, name);//货位状态更新
                            WriteDBLog.Success(name + "桁架下料完成",
                                $"读取桁架信息:\nR_load_finished:{finished}\n车轮SN:{Wheel_SN}\n轮型ID:{WheelType}\n下料位号:{AreaNr}\n\n" +
                                $"处理写入桁架信息:\nW_AreaNr:{0}\nW_IndexNr:{0}\nW_Storage_Type:{0}\n\n" +
                                $"写入桁架信息:\nW_Storage_update:{true}\nW_Enabl_Load:{false}", "PCS");
                            WriteLog.Write_Log(name + "放料完成", Wheel_SN, "成功!",
                                $"读取桁架信息:\n放料完成信号:{finished}\n车轮SN:{Wheel_SN}\n轮型ID:{WheelType}\n下料位号:{AreaNr}\n\n" +
                                $"处理写入桁架信息:\n区域货位号:{0}\n托盘上的第几个车轮:{0}\n托盘类型:{0}\n\n" +
                                $"写入桁架信息:\n货位状态更新信号:{true}\n是否允许下料:{false}");
                            //WriteDBLog.Success(name + "桁架下料完成",
                            //    $"读取桁架信息:\nR_load_finished:{finished}\n车轮SN:{Wheel_SN}\n轮型ID:{WheelType}\n下料位号:{AreaNr}\n\n" +
                            //    $"处理写入桁架信息:\nW_AreaNr:{0}\nW_IndexNr:{0}\nW_Storage_Type:{0}\n\n" +
                            //    $"写入桁架信息:\nW_Storage_update:{true}\nW_Enabl_Load:{false}", "PCS");
                            #endregion
                            //client.WriteByOrder("W_Enabl_Load", false, name);//是否允许
                            #region ä¿®æ”¹å·¥å•状态
                            var Detail = mes_DetailRepository.FindFirst(x => x.jobID == Mes_Work.jobID && x.SN == Mes_Work.SN);
                            Detail.Status = "下线";
                            Detail.FinishTime = DateTime.Now;
                            count = mes_DetailRepository.Update(Detail, true);
                            if (count < 1)
                                throw new Exception($"工单子表信息更新失败!车轮SN号:{Detail.SN}");
                            var Head = mes_HeadRepository.FindFirst(x => x.jobID == Detail.jobID);
                            Head.finishNum = Head.finishNum + 1;
                            count = mes_HeadRepository.Update(Head, true);
                            if (count < 1)
@@ -496,7 +554,9 @@
                        {
                            client.WriteByOrder("W_Storage_update", false, name);//货位状态更新
                            #region æ—¥å¿—记录
                            WriteDBLog.Success(name + "货位状态更新复位", $"读取桁架信息:\nR_load_finished:{finished}\n\n写入桁架信息:\nW_Storage_update:{false}", "PCS");
                            //WriteDBLog.Success(name + "货位状态更新复位", $"读取桁架信息:\nR_load_finished:{finished}\n\n写入桁架信息:\nW_Storage_update:{false}", "PCS");
                            WriteLog.Write_Log(name + "放料完成", name + "货位状态更新信号复位", "成功!",
                                $"读取桁架信息:\n放料完成信号:{finished}\n\n写入桁架信息:\n货位状态更新信号:{false}");
                            #endregion
                        }
                        #endregion
@@ -504,44 +564,61 @@
                        var Request = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Request_Load").First(), client);
                        if (!Request) continue;
                        //var Area = client.ReadByOrder<Int16>("W_AreaNr", name);//读取货位号信息
                        //if (Area != 0) continue;
                        #region è¯»å–桁架信息
                        var Wheel_Type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_Type").First(), client);//车轮类型
                        var Wheel_id = client.ReadByOrder<string>("R_Wheel_id", name);//车轮SN号
                        if (string.IsNullOrEmpty(Wheel_id)) continue;
                        //var Wheel_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_id").First(), client).ToString();
                        if (string.IsNullOrEmpty(Wheel_id))
                        {
                            WriteLog.Write_Log(name + "申请放料异常", "车轮SN号为空", "", $"读取桁架信息:\n车轮SN号:{Wheel_id}为空");
                            continue;
                        }
                        var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == Wheel_id);
                        if (mes_Detail == null)
                        var Work = workinfoRepository.Find(x => x.SN == Wheel_id && x.processCode == "17").FirstOrDefault();
                        if (Work == null)
                        {
                            #region æ—¥å¿—记录
                            client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{Wheel_id}\n\n未查询到工单详情", "PCS");
                            #endregion
                            continue;
                            //WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{Wheel_id}\n\n未查询到工单信息", "PCS");
                            WriteLog.Write_Log(name + "申请放料异常", Wheel_id, "查询机加工工单", $"读取桁架信息:\n车轮SN号:{Wheel_id}未查询到工单信息\n写入桁架信息:\n是否允许下料:{false}");
                        }
                        var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
                        if (mes_Head == null)
                        {
                            #region æ—¥å¿—记录
                            client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{Wheel_id}\n\n未查询到工单头表", "PCS");
                            #endregion
                            continue;
                        }
                        #region MyRegion
                        //var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == Wheel_id);
                        //if (mes_Detail == null)
                        //{
                        //    #region æ—¥å¿—记录
                        //    client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                        //    WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{Wheel_id}\n\n未查询到工单详情", "PCS");
                        //    #endregion
                        //    continue;
                        //}
                        //var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
                        //if (mes_Head == null)
                        //{
                        //    #region æ—¥å¿—记录
                        //    client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                        //    WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{Wheel_id}\n\n未查询到工单头表", "PCS");
                        //    #endregion
                        //    continue;
                        //}
                        #endregion
                        #endregion
                        var Stations = stationinfoRepository.Find(x => x.area == PipelineJob.area_code(name));
                        var Stations = stationinfoRepository.Find(x => x.area == PipelineJob.area_code(name)).OrderBy(x => x.lastUpdateTime).ToList();
                        var NGStation = "X01001003";
                        if (name == "2单元下料区") NGStation = "X02001003";
                        if (name == "3单元下料区") NGStation = "X03001002";
                        foreach (var station in Stations)     //任何一个下料位为空或禁用时,都会停止桁架
                        {
                            if (!station.enable || station.location_state == LocationStateEnum.Empty.ToString())
                                client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                        }
                        //foreach (var station in Stations)     //任何一个下料位为空或禁用时,都会停止桁架
                        //{
                        //    if (!station.enable || station.location_state == LocationStateEnum.Empty.ToString())
                        //        client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                        //}
                        #region MyRegion
                        //var currentAreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Are00aNr").First(), client);
                        //var currentAreaCode = PipelineJob.area_code(name);   //根据下料口单元名获取区域代码
@@ -551,35 +628,40 @@
                        #endregion
                        var wheel = PipelineJob.QueryMateriel(mes_Head.drawingNo);
                        var wheel1 = PipelineJob.QueryMateriel1(mes_Head.drawingNo);
                        var wheel = PipelineJob.QueryMateriel(Work.drawingNo);
                        var wheel1 = PipelineJob.QueryMateriel1(Work.drawingNo);
                        if (wheel == null && wheel1 == null)
                        {
                            #region æ—¥å¿—记录
                            client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                            WriteDBLog.Error(name, $"未查询到车轮信息!", "PCS");
                            //WriteDBLog.Error(name, $"未查询到车轮信息!", "PCS");
                            WriteLog.Write_Log(name + "申请放料异常", Wheel_id, $"查询{Work.drawingNo}车轮参数", $"读取桁架信息:\n车轮SN号:{Wheel_id}未查询到工单信息\n写入桁架信息:\n是否允许下料:{false}");
                            #endregion
                            continue;
                        }
                        var PartStatus = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PartStatus").First(), client);//1:ok;2:nok
                        var load_zone = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_zone").First(), client);
                        #region æ—¥å¿—记录
                        WriteDBLog.Success(name + "申请放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:{PartStatus}", "PCS");
                        //WriteDBLog.Success(name + "申请放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:{PartStatus}\n是否进入下料区:{load_zone}", "PCS");
                        WriteLog.Write_Log(name + "申请放料", Wheel_id, "申请放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:{PartStatus}\n是否进入下料区:{load_zone}");
                        if (load_zone) continue;
                        #endregion
                        if ((Int16)PartStatus == 1)
                        {
                            dt_stationinfo Stationinfo = null;
                            if (mes_Detail.heatID != null)
                            if (Work.heatID != null)
                            {
                                Stationinfo = Stations
                           .Where(x => x.enable
                           && x.stationCode != NGStation
                           && x.location_state == LocationStateEnum.Stroge.ToString()
                           && x.quantity < 5
                           && x.stationType == mes_Head.drawingNo
                           && x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
                           && x.Number == mes_Detail.jobID
                           && x.heatNumber == mes_Detail.heatID)
                           && x.stationType == Work.drawingNo
                           //&& x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
                           && x.Number == Work.workOrder
                           && x.heatNumber == Work.heatID)
                           .OrderByDescending(x => x.quantity)
                           .FirstOrDefault();
                            }
@@ -590,34 +672,35 @@
                           && x.stationCode != NGStation
                           && x.location_state == LocationStateEnum.Stroge.ToString()
                           && x.quantity < 5
                           && x.stationType == mes_Head.drawingNo
                           && x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
                           && x.Number == mes_Detail.jobID)
                           && x.stationType == Work.drawingNo
                           //&& x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
                           && x.Number == Work.workOrder)
                           .OrderByDescending(x => x.quantity)
                           .FirstOrDefault();
                            }
                            if (Stationinfo == null)
                            {
                                #region ä¸‹æ–™ä½æ¡ä»¶ä¸åŒ¹é…ç›´æŽ¥è§¦å‘入库任务
                                var stationinfos = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).ToList();
                                foreach (var stationinfo in stationinfos)
                                //var stationinfos = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).ToList();
                                //foreach (var stationinfo in stationinfos)
                                //{
                                //    agvtask(stationinfoRepository, stationinfo, (wheel == null ? wheel1.e : wheel.e), name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                //}
                                #endregion
                                #region è§¦å‘NG任务
                                var NG = Stations.Where(x => x.enable && x.stationCode == NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).FirstOrDefault();
                                if (NG != null)
                                {
                                    agvtask(stationinfoRepository, stationinfo, (wheel == null ? wheel1.e : wheel.e), name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                    if (NG.stationType != Work.drawingNo || NG.Number != Work.workOrder)
                                        agvtask(stationinfoRepository, NG, Work, "TaskType_OutsourceInbound");
                                }
                                #endregion
                                Stationinfo = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
                                #region æ²¡æ‰˜ç›˜å¯ç”¨,触发入库任务
                                //if (Stationinfo == null)
                                //{
                                //    var stationinfos = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).ToList();
                                //    foreach (var stationinfo in stationinfos)
                                //    {
                                //        agvtask(stationinfoRepository, stationinfo, (wheel == null ? wheel1.e : wheel.e), name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                //    }
                                //}
                                #endregion
                                #region MyRegion
                                //var stationinfo = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).FirstOrDefault();
@@ -630,8 +713,26 @@
                            if (Stationinfo != null)
                            {
                                #region æ¢ç±»åž‹ç›´æŽ¥å…¥åº“
                                var stationinfo1 = Stations.Where(x => x.enable && x.stationCode != NGStation && x.stationCode != Stationinfo.stationCode && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0 && x.stationType != Work.drawingNo).FirstOrDefault();
                                if (stationinfo1 != null)
                                    agvtask(stationinfoRepository, stationinfo1, Work, name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                #endregion
                                #region æ‰˜ç›˜è½¦è½®å †åž›ç¬¬å››ä¸ªæ—¶ä¸‹å‘另外一个炉号的入库任务
                                if (Stationinfo.quantity + 1 >= 4)
                                {
                                    var stationinfo = Stations.Where(x => x.enable && x.stationCode != NGStation && x.stationCode != Stationinfo.stationCode && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).FirstOrDefault();
                                    if (stationinfo != null)
                                        agvtask(stationinfoRepository, stationinfo, Work, name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                }
                                #endregion
                                #region æ‰˜ç›˜ç±»åž‹ä¸ä¸€è‡´éœ€æ›´æ¢æ‰˜ç›˜
                                if (Stationinfo.tray_type != ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray"))
                                //if (Stationinfo.tray_type != ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray"))
                                if (Stationinfo.tray_type != "LargeTray" && (wheel == null ? wheel1.e : wheel.e) > 1100)
                                {
                                    client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                                    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
@@ -663,9 +764,25 @@
                                    #region è´§ä½æ•°é‡ä¸Žå…‰ç”µä¸åŒ¹é…ï¼ŒæŠ¥è­¦
                                    if (list.Count > 0 && MaterialSignal != 1)
                                    {
                                        client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                                        Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                    //else if (list.Count < 1 && MaterialSignal == 1)
                                    //    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                        Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
                                        Stationinfo.remark = "车轮数量与光电不匹配";
                                        stationinfoRepository.Update(Stationinfo, true);
                                        WriteDBLog.Error(name + "报警", $"货位编号:{Stationinfo.stationCode};错误信息:{Stationinfo.remark}", "PCS");
                                        //WriteDBLog.Error(name+"申请下料",$"{Stationinfo.stationCode}的货位","PCS");
                                    }
                                    else if (list.Count < 1 && MaterialSignal == 1)
                                    {
                                        client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                                        Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                        Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
                                        Stationinfo.remark = "车轮数量与光电不匹配";
                                        stationinfoRepository.Update(Stationinfo, true);
                                        WriteDBLog.Error(name + "报警", $"货位编号:{Stationinfo.stationCode};错误信息:{Stationinfo.remark}", "PCS");
                                    }
                                    #endregion
                                    //缓存架上车轮数量与SN号数量不一致
@@ -684,54 +801,82 @@
                                    client.WriteByOrder("W_Storage_Type", (Int16)1, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                                    client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
                                    #region æ—¥å¿—记录
                                    WriteDBLog.Success(name + "允许放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:OK" +
                                    //WriteDBLog.Success(name + "允许放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:OK" +$"\n读取托盘光电信号:{PalletSignal}" +
                                    //    $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\nW_Enabl_Load:true", "PCS");
                                    WriteLog.Write_Log(name + "申请放料", Wheel_id, "允许放料",
                                        $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:合格" +
                                        $"\n读取托盘光电信号:{PalletSignal}" +
                                        $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\nW_Enabl_Load:true", "PCS");
                                        $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\n是否允许下料:true");
                                    #endregion
                                    continue;
                                }
                            }
                            else
                            {
                                #region æ²¡æ‰˜ç›˜å¯ç”¨,触发入库任务
                                if (!Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state != LocationStateEnum.Stroge.ToString()).Any())
                                {
                                    var station = Stations.Where(x => x.enable && x.stationCode != NGStation).OrderBy(x => x.lastUpdateTime).FirstOrDefault();
                                    agvtask(stationinfoRepository, station, Work, name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                }
                                //var stationinfos = Stations.Where(x => x.enable && x.Number != Work.workOrder && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).ToList();
                                //foreach (var stationinfo in stationinfos)
                                //{
                                //    agvtask(stationinfoRepository, stationinfo, Work, name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                //}
                                #endregion
                            }
                        }
                        else if ((Int16)PartStatus == 2)
                        {
                            dt_stationinfo Stationinfo = null;
                            if (mes_Detail.heatID != null)
                            {
                                Stationinfo = Stations
                            .Where(x => x.enable
                            && x.stationCode == NGStation
                            && x.location_state == LocationStateEnum.Stroge.ToString()
                            && x.quantity < 5
                            && x.stationType == mes_Head.drawingNo
                            && x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
                            && x.Number == mes_Detail.jobID
                            && x.heatNumber == mes_Detail.heatID).FirstOrDefault();
                            }
                            else
                            {
                                Stationinfo = Stations
                            .Where(x => x.enable
                            && x.stationCode == NGStation
                            && x.location_state == LocationStateEnum.Stroge.ToString()
                            && x.quantity < 5
                            && x.stationType == mes_Head.drawingNo
                            && x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
                            && x.Number == mes_Detail.jobID).FirstOrDefault();
                            }
                            //if (mes_Detail.heatID != null)
                            //{
                            //    Stationinfo = Stations
                            //.Where(x => x.enable
                            //&& x.stationCode == NGStation
                            //&& x.location_state == LocationStateEnum.Stroge.ToString()
                            //&& x.quantity < 5
                            //&& x.stationType == mes_Head.drawingNo
                            //&& x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
                            //&& x.Number == mes_Detail.jobID
                            //&& x.heatNumber == mes_Detail.heatID).FirstOrDefault();
                            //}
                            //else
                            //{
                            //var tray_type = "SmallTray";
                            //if ((wheel == null ? wheel1.e : wheel.e) > 1100) tray_type = "LargeTray";
                            Stationinfo = Stations
                        .Where(x => x.enable
                        && x.stationCode == NGStation
                        && x.location_state == LocationStateEnum.Stroge.ToString()
                        && x.quantity < 5
                        && x.stationType == Work.drawingNo
                        //&& x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
                        /*&& x.Number == mes_Detail.jobID*/).FirstOrDefault();
                            //}
                            if (Stationinfo == null)
                            {
                                var stationinfo = Stations.Where(x => x.enable && x.stationCode == NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).FirstOrDefault();
                                if (stationinfo != null)
                                #region è§¦å‘NG任务
                                var NG = Stations.Where(x => x.enable && x.stationCode == NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).FirstOrDefault();
                                if (NG != null)
                                {
                                    agvtask(stationinfoRepository, stationinfo, (wheel == null ? wheel1.e : wheel.e), "TaskType_OutsourceInbound");
                                    agvtask(stationinfoRepository, NG, Work, "TaskType_OutsourceInbound");
                                    continue;
                                }
                                #endregion
                                Stationinfo = Stations.Where(x => x.enable && x.stationCode == NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
                            }
                            if (Stationinfo != null)
                            {
                                #region æ‰˜ç›˜ç±»åž‹ä¸ä¸€è‡´éœ€æ›´æ¢æ‰˜ç›˜
                                if (Stationinfo.tray_type != ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray"))
                                //if (Stationinfo.tray_type != ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray"))
                                if (Stationinfo.tray_type != "LargeTray" && (wheel == null ? wheel1.e : wheel.e) > 1100)
                                {
                                    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
                                    Stationinfo.tray_type = Stationinfo.tray_type == "SmallTray" ? "SmallTray/LargeTray" : "LargeTray/SmallTray";
@@ -756,10 +901,31 @@
                                    }
                                    #region è´§ä½æ•°é‡ä¸Žå…‰ç”µä¸åŒ¹é…ï¼ŒæŠ¥è­¦
                                    if (list.Count > 0 && MaterialSignal != 1)
                                        Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                    //if (list.Count > 0 && MaterialSignal != 1)
                                    //    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                    //else if (list.Count < 1 && MaterialSignal == 1)
                                    //    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                    if (list.Count > 0 && MaterialSignal != 1)
                                    {
                                        client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                                        Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                        Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
                                        Stationinfo.remark = "车轮数量与光电不匹配";
                                        stationinfoRepository.Update(Stationinfo, true);
                                        WriteDBLog.Error(name + "报警", $"货位编号:{Stationinfo.stationCode};错误信息:{Stationinfo.remark}", "PCS");
                                        //WriteDBLog.Error(name+"申请下料",$"{Stationinfo.stationCode}的货位","PCS");
                                    }
                                    else if (list.Count < 1 && MaterialSignal == 1)
                                    {
                                        client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                                        Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                        Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
                                        Stationinfo.remark = "车轮数量与光电不匹配";
                                        stationinfoRepository.Update(Stationinfo, true);
                                        WriteDBLog.Error(name + "报警", $"货位编号:{Stationinfo.stationCode};错误信息:{Stationinfo.remark}", "PCS");
                                    }
                                    #endregion
                                    //缓存架上车轮数量与SN号数量不一致
@@ -778,9 +944,12 @@
                                    client.WriteByOrder("W_Storage_Type", (Int16)1, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                                    client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
                                    #region æ—¥å¿—记录
                                    WriteDBLog.Success(name + "允许放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:NG" +
                                    //WriteDBLog.Success(name + "允许放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:NG" +$"\n读取托盘光电信号:{PalletSignal}" +
                                    //    $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\nW_Enabl_Load:true", "PCS");
                                    WriteLog.Write_Log(name + "申请放料", Wheel_id, "允许放料",
                                        $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:合格" +
                                        $"\n读取托盘光电信号:{PalletSignal}" +
                                        $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\nW_Enabl_Load:true", "PCS");
                                        $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\n是否允许下料:true");
                                    #endregion
                                    continue;
                                }
@@ -853,54 +1022,80 @@
        }
        #endregion
        /// <summary>
        /// AGV任务
        /// </summary>
        public void agvtask(Idt_stationinfoRepository stationinfoRepository, dt_stationinfo stationinfo, float e, string tasktype)
        public void agvtask(Idt_stationinfoRepository stationinfoRepository, dt_stationinfo stationinfo, VV_Mes_Workinfo Work, string tasktype)
        {
            VOLContext Context = new VOLContext();
            Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
            Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
            var task = agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).FirstOrDefault();
            if (task != null) return;
            var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == stationinfo.Number);
            dt_stationinfo TargetLocation = null;
            int CompeletedNum = Convert.ToInt32(mes_Head.quantity) - Convert.ToInt32(mes_Head.finishNum);
            if (tasktype == "TaskType_OutsourceInbound")
                TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository);
            else if (tasktype == "TaskType_Inbound")
                TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository, mes_Head, stationinfo, CompeletedNum, e);
            if (TargetLocation != null)
            {
                dt_agvtask agvtask = new dt_agvtask()
                {
                    agv_fromaddress = stationinfo.stationCode,
                    agv_id = Guid.NewGuid(),
                    agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                    agv_grade = 1,
                    agv_createtime = DateTime.Now,
                    agv_taskstate = "Create",
                    agv_materielid = stationinfo.stationType,
                    agv_qty = stationinfo.quantity,
                    agv_tasktype = tasktype,
                    agv_toaddress = TargetLocation.stationCode,
                    agv_userid = "系统",
                    bindSN = stationinfo.bindSN,
                    agv_worktype = Convert.ToInt32(mes_Head.processCode),
                    agv_materbarcode = mes_Head.materialCode,
                    agv_Traytype = stationinfo.tray_type,
                    jobID = stationinfo.Number,
                    agv_TrayStatus = stationinfo.tray_status
                };
                agvtaskRepository.Add(agvtask, true);
                stationinfo.location_state = LocationStateEnum.Busy.ToString();
                stationinfoRepository.Update(stationinfo, true);
                TargetLocation.location_state = LocationStateEnum.InBusy.ToString();
                TargetLocation.stationType = agvtask.agv_materielid;
                stationinfoRepository.Update(TargetLocation, true);
            }
            if (!string.IsNullOrEmpty(Work.area))
                tasktype = "TaskType_OutsourceInbound";
            AGVTask.AddQueueTask(stationinfoRepository, agvtaskRepository, stationinfo, tasktype, Work);
        }
        #region MyRegion
        /// <summary>
        /// AGV任务
        /// </summary>
        //public void agvtask(Idt_stationinfoRepository stationinfoRepository, dt_stationinfo stationinfo, VV_Mes_Workinfo Work, string tasktype)
        //{
        //    VOLContext Context = new VOLContext();
        //    Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
        //    Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
        //    var task = agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).FirstOrDefault();
        //    if (task != null) return;
        //    //var mes_Head = mes_HeadRepository.Find(x => x.jobID == Work.jobID).FirstOrDefault();
        //    //if (mes_Head == null)
        //    //{
        //    //    stationinfo.remark = "触发入库任务,但未找到工单头表!";
        //    //    stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
        //    //    stationinfoRepository.Update(stationinfo, true);
        //    //    return;
        //    //}
        //    dt_stationinfo TargetLocation = null;
        //    //int CompeletedNum = Convert.ToInt32(mes_Head.quantity) - Convert.ToInt32(mes_Head.finishNum);
        //    //if (mes_Head.quantity <= 50) tasktype = "TaskType_OutsourceInbound";
        //    if (tasktype == "TaskType_OutsourceInbound" || !string.IsNullOrEmpty(Work.area))
        //        TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository);
        //    else if (tasktype == "TaskType_Inbound")
        //        TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, Work, stationinfo);
        //    //TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, mes_Head, stationinfo);
        //    if (TargetLocation != null)
        //    {
        //        dt_agvtask agvtask = new dt_agvtask()
        //        {
        //            agv_fromaddress = stationinfo.stationCode,
        //            agv_id = Guid.NewGuid(),
        //            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
        //            agv_grade = 1,
        //            agv_createtime = DateTime.Now,
        //            agv_taskstate = "Create",
        //            agv_materielid = stationinfo.stationType,
        //            agv_qty = stationinfo.quantity,
        //            agv_tasktype = tasktype,
        //            agv_toaddress = TargetLocation.stationCode,
        //            agv_userid = "系统",
        //            bindSN = stationinfo.bindSN,
        //            agv_worktype = Convert.ToInt32(Work.processCode),
        //            agv_materbarcode = Work.materialCode,
        //            agv_Traytype = stationinfo.tray_type,
        //            jobID = stationinfo.Number,
        //            agv_TrayStatus = stationinfo.tray_status
        //        };
        //        agvtaskRepository.Add(agvtask, true);
        //        stationinfo.location_state = LocationStateEnum.InBusy.ToString();
        //        stationinfoRepository.Update(stationinfo, true);
        //        TargetLocation.location_state = LocationStateEnum.InBusy.ToString();
        //        TargetLocation.stationType = agvtask.agv_materielid;
        //        TargetLocation.heatNumber = stationinfo.heatNumber;
        //        TargetLocation.Number = agvtask.jobID;
        //        stationinfoRepository.Update(TargetLocation, true);
        //    }
        //}
        #endregion
    }
}