分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-05-07 46f7bf1ee45c97b688a370bbe45d149efb403cc1
´úÂë¹ÜÀí/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs
@@ -34,6 +34,7 @@
        /// <param name="client"></param>
        public void QueryWheeldata(PLCClient client)
        {
            string namea = "";
            try
            {
                VOLContext Context = new VOLContext();
@@ -48,6 +49,7 @@
                List<string> names = new List<string>() { "1单元辊道下料查询车轮", "2单元辊道下料查询车轮", "3单元辊道下料查询车轮", "辊道上料查询车轮" };
                foreach (string name in names)
                {
                    namea = name;
                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                    var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on").First(), client);
                    if ((byte)on == 1)
@@ -66,7 +68,8 @@
                            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");
                            WriteLog.Write_Log(name, wp_id, "错误信息!", $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单信息");
                            #endregion
                            continue;
                        }
@@ -107,7 +110,8 @@
                                client.WriteByOrder("W_i_status", (byte)2, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到机加工车轮信息", "PCS");
                                //WriteDBLog.Error(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到机加工车轮信息", "PCS");
                                WriteLog.Write_Log(name, wp_id, "错误信息!", $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到机加工车轮信息");
                                #endregion
                            }
                            else
@@ -124,7 +128,17 @@
                                client.WriteByOrder("W_i_parameter_h", geometry == null ? (float)geometry1.h : (float)geometry.h, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Success(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\n" +
                                //WriteDBLog.Success(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\n" +
                                //    $"a:{(geometry == null ? (float)geometry1.a : (float)geometry.a)}\n" +
                                //    $"b:{(geometry == null ? (float)geometry1.b : (float)geometry.b)}\n" +
                                //    $"c:{(geometry == null ? (float)geometry1.c : (float)geometry.c)}\n" +
                                //    $"d:{(geometry == null ? (float)geometry1.d : (float)geometry.d)}\n" +
                                //    $"e:{(geometry == null ? (float)geometry1.e : (float)geometry.e)}\n" +
                                //    $"f:{(geometry == null ? (float)geometry1.f : (float)geometry.f)}\n" +
                                //    $"g:{(geometry == null ? (float)geometry1.g : (float)geometry.g)}\n" +
                                //    $"h:{(geometry == null ? (float)geometry1.h : (float)geometry.h)}\n" +
                                //    $"R_oi_on:0", "PCS");
                                WriteLog.Write_Log(name, wp_id, "写入信息!", $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\n" +
                                    $"a:{(geometry == null ? (float)geometry1.a : (float)geometry.a)}\n" +
                                    $"b:{(geometry == null ? (float)geometry1.b : (float)geometry.b)}\n" +
                                    $"c:{(geometry == null ? (float)geometry1.c : (float)geometry.c)}\n" +
@@ -133,7 +147,7 @@
                                    $"f:{(geometry == null ? (float)geometry1.f : (float)geometry.f)}\n" +
                                    $"g:{(geometry == null ? (float)geometry1.g : (float)geometry.g)}\n" +
                                    $"h:{(geometry == null ? (float)geometry1.h : (float)geometry.h)}\n" +
                                    $"R_oi_on:0", "PCS");
                                    $"R_oi_on:0");
                                #endregion
                            }
                        }
@@ -146,7 +160,8 @@
                                client.WriteByOrder("W_i_status", (byte)2, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到检测线车轮信息", "PCS");
                                //WriteDBLog.Error(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到检测线车轮信息", "PCS");
                                WriteLog.Write_Log(name, wp_id, "错误信息!", $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到检测线车轮信息");
                                #endregion
                            }
                            else
@@ -162,7 +177,17 @@
                                client.WriteByOrder("W_i_parameter_h", geometry == null ? (float)geometry1.h : (float)geometry.h, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Success(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\n" +
                                //WriteDBLog.Success(name, $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\n" +
                                //    $"a:{(geometry == null ? (float)geometry1.a : (float)geometry.a)}\n" +
                                //    $"b:{(geometry == null ? (float)geometry1.b : (float)geometry.b)}\n" +
                                //    $"c:{(geometry == null ? (float)geometry1.c : (float)geometry.c)}\n" +
                                //    $"d:{(geometry == null ? (float)geometry1.d : (float)geometry.d)}\n" +
                                //    $"e:{(geometry == null ? (float)geometry1.e : (float)geometry.e)}\n" +
                                //    $"f:{(geometry == null ? (float)geometry1.f : (float)geometry.f)}\n" +
                                //    $"g:{(geometry == null ? (float)geometry1.g : (float)geometry.g)}\n" +
                                //    $"h:{(geometry == null ? (float)geometry1.h : (float)geometry.h)}\n" +
                                //    $"R_oi_on:0", "PCS");
                                WriteLog.Write_Log(name, wp_id, "写入信息!", $"读取桁架信息:\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:1" + $"\n" +
                                    $"a:{(geometry == null ? (float)geometry1.a : (float)geometry.a)}\n" +
                                    $"b:{(geometry == null ? (float)geometry1.b : (float)geometry.b)}\n" +
                                    $"c:{(geometry == null ? (float)geometry1.c : (float)geometry.c)}\n" +
@@ -171,7 +196,7 @@
                                    $"f:{(geometry == null ? (float)geometry1.f : (float)geometry.f)}\n" +
                                    $"g:{(geometry == null ? (float)geometry1.g : (float)geometry.g)}\n" +
                                    $"h:{(geometry == null ? (float)geometry1.h : (float)geometry.h)}\n" +
                                    $"R_oi_on:0", "PCS");
                                    $"R_oi_on:0");
                                #endregion
                            }
                        }
@@ -181,7 +206,8 @@
            }
            catch (Exception ex)
            {
                WriteDBLog.Error("查询车轮数据", $"错误信息:{ex.Message}", "PCS");
                //WriteDBLog.Error("查询车轮数据", $"错误信息:{ex.Message}", "PCS");
                WriteLog.Write_Log("报错日志", namea, "错误信息!", $"错误信息:{ex.Message}");
            }
        }
        #endregion
@@ -193,6 +219,7 @@
        /// <param name="client"></param>
        public void QueryOrder(PLCClient client)
        {
            string namea = "";
            try
            {
                VOLContext Context = new VOLContext();
@@ -208,6 +235,7 @@
                List<string> names = new List<string>() { "1单元辊道下料查询订单", "2单元辊道下料查询订单", "3单元辊道下料查询订单", "辊道上料查询订单" };
                foreach (string name in names)
                {
                    namea = name;
                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                    var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on").First(), client);
                    //var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on" && x.plcdetail_number == name).First(), client);
@@ -217,10 +245,11 @@
                        var wp_id = client.ReadByOrder<string>("R_o_wp_id", name);
                        if (string.IsNullOrEmpty(wp_id))
                        {
                            #region æ—¥å¿—记录
                            client.WriteByOrder("W_i_status", (byte)2, name);
                            client.WriteByOrder("R_oi_on", (byte)0, name);
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n车轮SN号为空", "PCS");
                            #region æ—¥å¿—记录
                            //WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n车轮SN号为空", "PCS");
                            WriteLog.Write_Log(name, wp_id, "错误信息!", $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n车轮SN号为空");
                            #endregion
                            continue;
                        }
@@ -232,7 +261,8 @@
                            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");
                            WriteLog.Write_Log(name, wp_id, "错误信息!", $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到工单详情");
                            #endregion
                            continue;
                        }
@@ -270,7 +300,8 @@
                                client.WriteByOrder("W_i_status", (byte)4, name);
                                client.WriteByOrder("R_oi_on", (byte)0, name);
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:4\nR_oi_on:0\n\n手动入库模式未选择库区", "PCS");
                                //WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:4\nR_oi_on:0\n\n手动入库模式未选择库区", "PCS");
                                WriteLog.Write_Log(name, wp_id, "错误信息!", $"读取桁架信息:\n车轮SN:{wp_id}\n\n写入桁架信息:\nW_i_status:4\nR_oi_on:0\n\n手动入库模式未选择库区");
                                #endregion
                                continue;
                            }
@@ -283,7 +314,8 @@
                                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轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到机加工车轮信息", "PCS");
                                //WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到机加工车轮信息", "PCS");
                                WriteLog.Write_Log(name, wp_id, "错误信息!", $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到机加工车轮信息");
                                #endregion
                                continue;
                            }
@@ -306,10 +338,14 @@
                                //}
                                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" +
                                WriteLog.Write_Log(name, wp_id, "写入信息!", $"读取桁架信息:\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_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");
                                    $"\nW_i_skip_op_LT:{mes_Head.skip_op_3}\nR_oi_on:0");
                                //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_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
                            }
                        }
@@ -323,7 +359,8 @@
                                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轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到检测线车轮信息", "PCS");
                                //WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到检测线车轮信息", "PCS");
                                WriteLog.Write_Log(name, wp_id, "错误信息!", $"读取桁架信息:\n车轮SN:{wp_id}\n轮型ID:{wp_type}\n\n写入桁架信息:\nW_i_status:2\nR_oi_on:0\n\n未查询到检测线车轮信息");
                                #endregion
                                continue;
                            }
@@ -338,8 +375,10 @@
                                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_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");
                                WriteLog.Write_Log(name, wp_id, "写入信息!", $"读取桁架信息:\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");
                                //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
                            }
                        }
@@ -348,7 +387,8 @@
            }
            catch (Exception ex)
            {
                WriteDBLog.Error("查询车轮订单", $"错误信息:{ex.Message}", "PCS");
                //WriteDBLog.Error("查询车轮订单", $"错误信息:{ex.Message}", "PCS");
                WriteLog.Write_Log("报错日志", namea, "错误信息!", $"错误信息:{ex.Message}");
            }
        }
        #endregion
@@ -388,43 +428,30 @@
                        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号
                        //if (string.IsNullOrEmpty(Wheel_id)) continue;
                        ////var Wheel_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_id").First(), client).ToString();
                        //var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == Wheel_id);
                        //if (mes_Detail == null)
                        //{
                        //    #region æ—¥å¿—记录
                        //    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 æ—¥å¿—记录
                        //    WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{Wheel_id}\n\n未查询到工单头表", "PCS");
                        //    #endregion
                        //    continue;
                        //}
                        #endregion
                        var finished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_finished").First(), client);//放料完成
                        var updatefinished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Storage_update").First(), client);//货位状态更新
                        #region è´§ä½çŠ¶æ€æ›´æ–°å¤ä½
                        //if (!finished && updatefinished)
                        //{
                        //    client.WriteByOrder("W_Storage_update", false, name);//货位状态更新
                        //    #region æ—¥å¿—记录
                        //    WriteDBLog.Success(name + "货位状态更新复位", $"读取桁架信息:\nR_load_finished:{finished}\n\n写入桁架信息:\nW_Storage_update:false", "PCS");
                        //    #endregion
                        //}
                        if (!finished && updatefinished)
                        {
                            client.WriteByOrder("W_Storage_update", false, name);//货位状态更新
                            #region æ—¥å¿—记录
                            //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
                        var Stations = stationinfoRepository.Find(x => x.area == Pipeline.area_code(name)).OrderBy(x => x.lastUpdateTime).ToList();
                        #region ä¸‹æ–™ä½æ˜¯å¦ä¸ºç©ºçŠ¶æ€åŒæ­¥ç»™æ¡æž¶
                        foreach (var station in Stations)
                        {
                            client.WriteByOrder(station.stationCode, station.location_state != LocationStateEnum.Stroge.ToString(), name);
                        }
                        #endregion
                        if (finished && !updatefinished)
                        {
@@ -450,24 +477,6 @@
                                #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
@@ -478,88 +487,90 @@
                                continue;
                            }
                            #region åˆ¤æ–­åŒºåŸŸå·æ˜¯å¦ä¸€è‡´
                            var area = client.ReadByOrder<Int16>("place_prog", name);//放料完成的区域号
                            var areaCode = PipelineJob.area_code(name);   //根据下料口单元名获取区域代码
                            var station = stationinfoRepository.FindFirst(x => x.area == areaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString());
                            if (station.quantity >= 5)
                                throw new Exception($"下料位信息更新失败!下料位车轮数量大于5:{station.stationCode}");
                            //station.bindSN = station.bindSN == string.Empty ? Wheel_id : station.bindSN + "," + Wheel_id;
                            if (!string.IsNullOrEmpty(station.bindSN))
                            if (AreaNr != area)
                            {
                                if (station.bindSN.Contains(Wheel_SN))
                                    throw new Exception($"{station.stationCode}已存在车轮SN号:{Wheel_SN}");
                                Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                //WriteDBLog.Error(name + "报警", $"PCS区域号:{AreaNr};桁架区域号:{area}错误信息:PCS区域号与桁架区域号不一致!", "PCS");
                                WriteLog.Write_Log(name + "放料完成出错", Wheel_SN, "判断区域号是否一致", $"PCS区域号:{AreaNr};\n桁架区域号:{area}\n错误信息:PCS区域号与桁架区域号不一致!");
                                continue;
                            }
                            #endregion
                            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)
                            var areaCode = Pipeline.area_code(name);   //根据下料口单元名获取区域代码
                            var station = stationinfoRepository.Find(x => x.area == areaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString()).FirstOrDefault();
                            if (station != null)
                            {
                                station.stationType = Mes_Work.drawingNo;
                                station.Number = Mes_Work.workOrder;
                                station.heatNumber = Mes_Work.heatID;
                                station.tray_status = "StrogeTray";
                                if (station.quantity >= 5)
                                {
                                    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                    WriteLog.Write_Log(name + "放料完成出错", Wheel_SN, "车轮数量已满!", $"区域号:{AreaNr};\n车轮数:{station.quantity}\n错误信息:区域号车轮数量已满!");
                                }
                                #region åˆ¤æ–­è½¦è½®æ•°é‡æ˜¯å¦ä¸€è‡´
                                var quantity = client.ReadByOrder<Int16>("pos_prog", name);//桁架记录的车轮数量
                                if (quantity != station.quantity + 1)
                                {
                                    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//报警
                                    WriteLog.Write_Log(name + "放料完成出错", Wheel_SN, "判断车轮数量是否一致", $"区域号:{AreaNr};\n桁架车轮数:{quantity}\nPCS车轮数:{station.quantity + 1}\n错误信息:PCS区域号与桁架区域号不一致!");
                                    continue;
                                }
                                #endregion
                                if (!string.IsNullOrEmpty(station.bindSN))
                                {
                                    if (station.bindSN.Contains(Wheel_SN))
                                        throw new Exception($"{station.stationCode}已存在车轮SN号:{Wheel_SN}");
                                }
                                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 = Mes_Work.drawingNo;
                                    station.Number = Mes_Work.workOrder;
                                    station.heatNumber = Mes_Work.heatID;
                                    station.tray_status = "StrogeTray";
                                }
                                var count = stationinfoRepository.Update(station, true);
                                if (count < 1)
                                    throw new Exception($"下料位信息更新失败!下料位编号:{station.stationCode}");
                                #region æ¸…空给桁架的下料信息
                                client.WriteByOrder("W_IndexNr", (Int16)0, name);//托盘上的第几个车轮
                                client.WriteByOrder("W_Storage_Type", (Int16)0, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                                client.WriteByOrder("W_AreaNr", (Int16)0, name);//区域货位号
                                client.WriteByOrder("W_Storage_update", true, name);//货位状态更新
                                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
                                #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)
                                    throw new Exception($"工单头表信息更新失败!工单号:{Head.jobID}");
                                #endregion
                            }
                            //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)
                                throw new Exception($"下料位信息更新失败!下料位编号:{station.stationCode}");
                            #region æ¸…空给桁架的下料信息
                            client.WriteByOrder("W_AreaNr", (Int16)0, name);//区域货位号
                            client.WriteByOrder("W_IndexNr", (Int16)0, name);//托盘上的第几个车轮
                            client.WriteByOrder("W_Storage_Type", (Int16)0, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                            client.WriteByOrder("W_Storage_update", true, name);//货位状态更新
                            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)
                                throw new Exception($"工单头表信息更新失败!工单号:{Head.jobID}");
                            #endregion
                            #region æ—¥å¿—记录
                            //WriteDBLog.Success(name + "放料完成", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n下料位号:{AreaNr}" +
                            //    $"\n\n写入桁架信息:\nW_Storage_update:true" + $"\nW_Enabl_Load:false", "PCS");
                            #endregion
                        }
                        #region è´§ä½çŠ¶æ€æ›´æ–°å¤ä½
                        finished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_finished").First(), client);//放料完成
                        updatefinished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Storage_update").First(), client);//货位状态更新
                        if (!finished && updatefinished)
                        {
                            client.WriteByOrder("W_Storage_update", false, name);//货位状态更新
                            #region æ—¥å¿—记录
                            //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
                        var Request = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Request_Load").First(), client);
                        if (!Request) continue;
@@ -585,39 +596,10 @@
                            WriteLog.Write_Log(name + "申请放料异常", Wheel_id, "查询机加工工单", $"读取桁架信息:\n车轮SN号:{Wheel_id}未查询到工单信息\n写入桁架信息:\n是否允许下料:{false}");
                        }
                        #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)).OrderBy(x => x.lastUpdateTime).ToList();
                        //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);
@@ -628,8 +610,8 @@
                        #endregion
                        var wheel = PipelineJob.QueryMateriel(Work.drawingNo);
                        var wheel1 = PipelineJob.QueryMateriel1(Work.drawingNo);
                        var wheel = Pipeline.QueryMateriel(Work.drawingNo);
                        var wheel1 = Pipeline.QueryMateriel1(Work.drawingNo);
                        if (wheel == null && wheel1 == null)
                        {
                            #region æ—¥å¿—记录
@@ -648,6 +630,8 @@
                        WriteLog.Write_Log(name + "申请放料", Wheel_id, "申请放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:{PartStatus}\n是否进入下料区:{load_zone}");
                        if (load_zone) continue;
                        #endregion
                        #region åˆæ ¼
                        if ((Int16)PartStatus == 1)
                        {
                            dt_stationinfo Stationinfo = null;
@@ -659,7 +643,6 @@
                           && 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 == Work.workOrder
                           && x.heatNumber == Work.heatID)
                           .OrderByDescending(x => x.quantity)
@@ -673,7 +656,6 @@
                           && 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 == Work.workOrder)
                           .OrderByDescending(x => x.quantity)
                           .FirstOrDefault();
@@ -681,16 +663,6 @@
                            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)
                                //{
                                //    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)
@@ -702,13 +674,6 @@
                                Stationinfo = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
                                #region MyRegion
                                //var stationinfo = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).FirstOrDefault();
                                //if (stationinfo != null)
                                //{
                                //    agvtask(stationinfoRepository, mes_Head, stationinfo, (wheel == null ? wheel1.e : wheel.e), name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                //}
                                #endregion
                            }
                            if (Stationinfo != null)
@@ -731,7 +696,6 @@
                                #endregion
                                #region æ‰˜ç›˜ç±»åž‹ä¸ä¸€è‡´éœ€æ›´æ¢æ‰˜ç›˜
                                //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桁架停止进入
@@ -748,7 +712,6 @@
                                var MaterialSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), Pipeline_client);//读取货物信号:1:有,2无
                                //var Wheel_id = client.ReadByOrder<string>("R_Wheel_id", name);
                                if (PalletSignal == 1)
                                {
                                    List<string> list = new List<string>();
@@ -763,25 +726,26 @@
                                    }
                                    #region è´§ä½æ•°é‡ä¸Žå…‰ç”µä¸åŒ¹é…ï¼ŒæŠ¥è­¦
                                    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");
                                    }
                                    //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");
                                    //    continue;
                                    //}
                                    //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");
                                    //    continue;
                                    //}
                                    #endregion
@@ -819,44 +783,20 @@
                                    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
                            }
                        }
                        #endregion
                        #region ä¸åˆæ ¼
                        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
                            //{
                            //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();
                            //}
                            dt_stationinfo Stationinfo = Stations.Where(x => x.enable
                            && x.stationCode == NGStation
                            && x.location_state == LocationStateEnum.Stroge.ToString()
                            && x.quantity < 5
                            && x.stationType == Work.drawingNo).FirstOrDefault();
                            if (Stationinfo == null)
                            {
@@ -901,31 +841,25 @@
                                    }
                                    #region è´§ä½æ•°é‡ä¸Žå…‰ç”µä¸åŒ¹é…ï¼ŒæŠ¥è­¦
                                    //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");
                                    //}
                                    //else if (list.Count < 1 && MaterialSignal == 1)
                                    //{
                                    //    client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                                    //    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");
                                    }
                                    //    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
                                    //    Stationinfo.remark = "车轮数量与光电不匹配";
                                    //    stationinfoRepository.Update(Stationinfo, true);
                                    //    WriteDBLog.Error(name + "报警", $"货位编号:{Stationinfo.stationCode};错误信息:{Stationinfo.remark}", "PCS");
                                    //}
                                    #endregion
                                    //缓存架上车轮数量与SN号数量不一致
@@ -935,8 +869,6 @@
                                        Stationinfo.remark = "车轮数量与SN号数量不一致";
                                        stationinfoRepository.Update(Stationinfo, true);
                                        continue;
                                        //写入桁架报警信号
                                        //throw new Exception("下料位车轮数量与SN号数量不一致,下料位编号:" + Stationinfo.stationCode);
                                    }
                                    var area = Convert.ToInt16(Stationinfo.stationCode.Substring(Stationinfo.stationCode.Length - 1, 1));
                                    client.WriteByOrder("W_AreaNr", (Int16)area, name);//区域货位号
@@ -955,133 +887,98 @@
                                }
                            }
                        }
                        #region
                        //var Stationinfo = Stations
                        //    .Where(x => x.enable
                        //    && x.location_state == LocationStateEnum.Stroge.ToString()
                        //    && x.quantity < 5
                        //    && x.stationType == PipelineJob.QueryMateriel(Wheel_Type)
                        //    && x.Number == mes_Detail.jobID
                        //    && x.heatNumber == mes_Detail.heatID).FirstOrDefault();
                        //if (Stationinfo == null)
                        //    Stationinfo = Stations.Where(x => x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
                        //if (Stationinfo != null)
                        //{
                        //}
                        //List<string> StationCodes = new List<string>() { "X01001001", "X01001002", "X01001003" };
                        //if (name == "2单元下料区")
                        //    StationCodes = new List<string>() { "X02001001", "X02001002", "X02001003" };
                        //if (name == "3单元下料区")
                        //    StationCodes = new List<string>() { "X03001001", "X03001002" };
                        #endregion
                        #region
                        //for (int i = 0; i < StationCodes.Count - 1; i++)
                        //{
                        //    var PartStatus = (Int32)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PartStatus").First(), client);//1:ok;2:nok
                        //    string NG = StationCodes[StationCodes.Count - 1];//NG货位
                        //    var station = stationinfoRepository.FindFirst(x => x.stationCode == StationCodes[i] && x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity < 5);
                        //    if (station == null) continue;
                        //    var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == StationCodes[i]).ToList();
                        //    var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//读取托盘信号:1:有,2无
                        //    if (PalletSignal == 1)
                        //    {
                        //        if (PartStatus == 1 && NG != station.stationCode)
                        //        {
                        //            client.WriteByOrder("W_AreaNr", (Int16)i + 1, name);//区域货位号
                        //            client.WriteByOrder("W_IndexNr", (Int16)station.quantity + 1, name);//托盘上的第几个车轮
                        //            client.WriteByOrder("W_Storage_Type", (Int16)1, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                        //            client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
                        //            return;
                        //        }
                        //        else if (PartStatus == 2 && NG == station.stationCode)
                        //        {
                        //            client.WriteByOrder("W_AreaNr", (Int16)i + 1, name);//区域货位号
                        //            client.WriteByOrder("W_IndexNr", (Int16)station.quantity + 1, name);//托盘上的第几个车轮
                        //            client.WriteByOrder("W_Storage_Type", (Int16)1, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                        //            client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
                        //            return;
                        //        }
                        //    }
                        //}
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        WriteDBLog.Error(name, $"错误信息:{ex.Message}", "PCS");
                        //WriteDBLog.Error(name, $"错误信息:{ex.Message}", "PCS");
                        WriteLog.Write_Log("报错日志", name, "错误信息!", $"错误信息:{ex.Message}");
                    }
                }
            }
            catch (Exception ex)
            {
                WriteDBLog.Error("下料区", $"错误信息:{ex.Message}", "PCS");
                //WriteDBLog.Error("下料区", $"错误信息:{ex.Message}", "PCS");
                WriteLog.Write_Log("报错日志", "下料区", "错误信息!", $"错误信息:{ex.Message}");
            }
        }
        #endregion
        /// <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);
            }
            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
    }
}