From 0b5ccdca6263cf7a2cee460f30c76ef1efea2811 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期六, 27 四月 2024 17:47:27 +0800
Subject: [PATCH] 人工出库,人工入库,人工移库,PDA扫码确认外协物料已被取走接口

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs | 1141 +++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 827 insertions(+), 314 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs"
index 7f19a23..ae19956 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs"
@@ -1,34 +1,37 @@
 锘縰sing 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;
 using WIDESEA_Comm;
 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;
 using WIDESEA_WCS.Repositories;
 using WIDESEA_WCS.WCSClient;
+using WIDESEA_WMS.IRepositories;
+using WIDESEA_WMS.Repositories;
+using static FreeSql.Internal.GlobalFilter;
 using static System.Collections.Specialized.BitVector32;
 
 namespace WIDESEA_WCS
 {
     public class Gantry
     {
-        //FreeDB freeDB = new FreeDB();
-        //static VOLContext Context = new VOLContext();
-        //Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
-        //Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
-        //Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
-        //Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
-        ////Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
-        //Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
-        //Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
-        //Idt_patternRepository patternRepository = new dt_patternRepository(Context);
         #region 鏌ヨ杞﹁疆鏁版嵁
+        /// <summary>
+        /// 鏌ヨ杞﹁疆鏁版嵁
+        /// </summary>
+        /// <param name="client"></param>
         public void QueryWheeldata(PLCClient client)
         {
             try
@@ -36,7 +39,10 @@
                 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);
                 Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
                 var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                 List<string> names = new List<string>() { "1鍗曞厓杈婇亾涓嬫枡鏌ヨ杞﹁疆", "2鍗曞厓杈婇亾涓嬫枡鏌ヨ杞﹁疆", "3鍗曞厓杈婇亾涓嬫枡鏌ヨ杞﹁疆", "杈婇亾涓婃枡鏌ヨ杞﹁疆" };
@@ -47,10 +53,54 @@
                     if ((byte)on == 1)
                     {
                         var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
+
+                        var number = "1鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟";
+                        if (name == "2鍗曞厓杈婇亾涓嬫枡鏌ヨ杞﹁疆") number = "2鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟";
+                        if (name == "3鍗曞厓杈婇亾涓嬫枡鏌ヨ杞﹁疆") number = "3鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟";
+                        if (name == "杈婇亾涓婃枡鏌ヨ杞﹁疆") number = "杈婇亾涓婃枡鏌ヨ璁㈠崟";
+                        var wp_id = client.ReadByOrder<string>("R_o_wp_id", number);
+
+                        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;
+                        }
+
+                        #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);
-                            if (geometry == null)
+                            //var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
+                            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);
                                 //1-鎵惧埌鏁版嵁锛�2-鏈壘鍒板伐浠剁被鍨嬫暟鎹�
@@ -64,25 +114,34 @@
                             {
                                 //1-鎵惧埌鏁版嵁锛�2-鏈壘鍒板伐浠剁被鍨嬫暟鎹�
                                 client.WriteByOrder("W_i_status", (byte)1, name);
-                                client.WriteByOrder("W_i_parameter_a", (float)geometry.a, name);
-                                client.WriteByOrder("W_i_parameter_b", (float)geometry.b, name);
-                                client.WriteByOrder("W_i_parameter_c", (float)geometry.c, name);
-                                client.WriteByOrder("W_i_parameter_d", (float)geometry.d, name);
-                                client.WriteByOrder("W_i_parameter_e", (float)geometry.e, name);
-                                client.WriteByOrder("W_i_parameter_f", (float)geometry.f, name);
-                                client.WriteByOrder("W_i_parameter_g", (float)geometry.g, name);
-                                client.WriteByOrder("W_i_parameter_h", (float)geometry.h, name);
+                                client.WriteByOrder("W_i_parameter_a", geometry == null ? (float)geometry1.a : (float)geometry.a, name);
+                                client.WriteByOrder("W_i_parameter_b", geometry == null ? (float)geometry1.b : (float)geometry.b, name);
+                                client.WriteByOrder("W_i_parameter_c", geometry == null ? (float)geometry1.c : (float)geometry.c, name);
+                                client.WriteByOrder("W_i_parameter_d", geometry == null ? (float)geometry1.d : (float)geometry.d, name);
+                                client.WriteByOrder("W_i_parameter_e", geometry == null ? (float)geometry1.e : (float)geometry.e, name);
+                                client.WriteByOrder("W_i_parameter_f", geometry == null ? (float)geometry1.f : (float)geometry.f, name);
+                                client.WriteByOrder("W_i_parameter_g", geometry == null ? (float)geometry1.g : (float)geometry.g, name);
+                                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" + $"\na锛歿(float)geometry.a}\nb锛歿(float)geometry.b}\nc锛歿(float)geometry.c}\n" +
-                                    $"d锛歿(float)geometry.d}\ne锛歿(float)geometry.e}\nf锛歿(float)geometry.f}\ng锛歿(float)geometry.g}\nh锛歿(float)geometry.h}\nR_oi_on锛�0", "PCS");
+                                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");
                                 #endregion
                             }
                         }
                         else
                         {
-                            var geometry = detectionlineRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
-                            if (geometry == null)
+                            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);
                                 client.WriteByOrder("R_oi_on", (byte)0, name);
@@ -93,18 +152,26 @@
                             else
                             {
                                 client.WriteByOrder("W_i_status", (byte)1, name);
-                                client.WriteByOrder("W_i_parameter_a", (float)geometry.a, name);
-                                client.WriteByOrder("W_i_parameter_b", (float)geometry.b, name);
-                                client.WriteByOrder("W_i_parameter_c", (float)geometry.c, name);
-                                client.WriteByOrder("W_i_parameter_d", (float)geometry.d, name);
-                                client.WriteByOrder("W_i_parameter_e", (float)geometry.e, name);
-                                client.WriteByOrder("W_i_parameter_f", (float)geometry.f, name);
-                                client.WriteByOrder("W_i_parameter_g", (float)geometry.g, name);
-                                client.WriteByOrder("W_i_parameter_h", (float)geometry.h, name);
+                                client.WriteByOrder("W_i_parameter_a", geometry == null ? (float)geometry1.a : (float)geometry.a, name);
+                                client.WriteByOrder("W_i_parameter_b", geometry == null ? (float)geometry1.b : (float)geometry.b, name);
+                                client.WriteByOrder("W_i_parameter_c", geometry == null ? (float)geometry1.c : (float)geometry.c, name);
+                                client.WriteByOrder("W_i_parameter_d", geometry == null ? (float)geometry1.d : (float)geometry.d, name);
+                                client.WriteByOrder("W_i_parameter_e", geometry == null ? (float)geometry1.e : (float)geometry.e, name);
+                                client.WriteByOrder("W_i_parameter_f", geometry == null ? (float)geometry1.f : (float)geometry.f, name);
+                                client.WriteByOrder("W_i_parameter_g", geometry == null ? (float)geometry1.g : (float)geometry.g, name);
+                                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" + $"\na锛歿(float)geometry.a}\nb锛歿(float)geometry.b}\nc锛歿(float)geometry.c}\n" +
-                                    $"d锛歿(float)geometry.d}\ne锛歿(float)geometry.e}\nf锛歿(float)geometry.f}\ng锛歿(float)geometry.g}\nh锛歿(float)geometry.h}\nR_oi_on锛�0", "PCS");
+                                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");
                                 #endregion
                             }
                         }
@@ -114,12 +181,16 @@
             }
             catch (Exception ex)
             {
-                throw;
+                WriteDBLog.Error("鏌ヨ杞﹁疆鏁版嵁", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
             }
         }
         #endregion
 
         #region 鏌ヨ璁㈠崟,鏄惁闇�瑕佸姞宸�
+        /// <summary>
+        /// 鏌ヨ璁㈠崟
+        /// </summary>
+        /// <param name="client"></param>
         public void QueryOrder(PLCClient client)
         {
             try
@@ -130,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);
@@ -153,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);
@@ -171,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 != "杈婇亾涓婃枡鏌ヨ璁㈠崟")
                         {
@@ -196,8 +275,9 @@
                                 continue;
                             }
                             //var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
-                            var geometry = dataRepository.Find(x => x.Description == mes_Head.drawingNo && x.TypeId == (Int32)wp_type).FirstOrDefault();
-                            if (geometry == null)
+                            var geometry = dataRepository.Find(x => x.Description == mes_Head.drawingNo /*&& x.TypeId == (Int32)wp_type*/).FirstOrDefault();
+                            var geometry1 = detectionlineRepository.Find(x => x.Description == mes_Head.drawingNo).FirstOrDefault();
+                            if (geometry == null && geometry1 == null)
                             {
                                 //1-濂�,鍏佽鍔犲伐锛�2-涓嶅湪鍒楄〃涓紝3-涓嶅姞宸ヨ溅杞被鍨嬶紝4-鎵嬪姩鍏ュ簱妯″紡浜哄伐鏈�夋嫨搴撳尯
                                 client.WriteByOrder("W_i_status", (byte)2, name);
@@ -211,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 != "杈婇亾涓婃枡鏌ヨ杞﹁疆")
@@ -227,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
@@ -235,8 +315,9 @@
                         }
                         else
                         {
-                            var geometry = detectionlineRepository.Find(x => x.Description == mes_Head.drawingNo && x.TypeId == (Int32)wp_type).FirstOrDefault();
-                            if (geometry == null)
+                            var geometry = detectionlineRepository.Find(x => x.Description == mes_Head.drawingNo /*&& x.TypeId == (Int32)wp_type*/).FirstOrDefault();
+                            var geometry1 = dataRepository.Find(x => x.Description == mes_Head.drawingNo).FirstOrDefault();
+                            if (geometry == null && geometry1 == null)
                             {
                                 //1-濂�,鍏佽鍔犲伐锛�2-涓嶅湪鍒楄〃涓紝3-涓嶅姞宸ヨ溅杞被鍨嬶紝4-鎵嬪姩鍏ュ簱妯″紡浜哄伐鏈�夋嫨搴撳尯
                                 client.WriteByOrder("W_i_status", (byte)2, name);
@@ -250,32 +331,33 @@
                             {
                                 //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
                             }
                         }
-
-
-
                     }
                 }
             }
             catch (Exception ex)
             {
-                throw;
+                WriteDBLog.Error("鏌ヨ杞﹁疆璁㈠崟", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
             }
         }
         #endregion
 
-        #region 涓嬫枡浣嶄氦浜�   锛侊紒锛佷笅鏂欓�昏緫闇�淇敼
+        #region 涓嬫枡浣嶄氦浜�
+        /// <summary>
+        /// 涓嬫枡
+        /// </summary>
+        /// <param name="client"></param>
         public void Layofflevel(PLCClient client)
         {
             try
@@ -288,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 == "閾炬潯鏈�");
@@ -298,291 +381,721 @@
 
                 foreach (string name in names)
                 {
-                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
-
-                    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)
+                    try
                     {
-                        #region 鏃ュ織璁板綍
-                        WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n\n鏈煡璇㈠埌宸ュ崟璇︽儏", "PCS");
+                        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鍙�
+                        //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
-                        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");
+
+                        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锛歠alse", "PCS");
+                        //    #endregion
+                        //}
                         #endregion
-                        continue;
-                    }
 
 
-                    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);//璐т綅鐘舵�佹洿鏂�
-                    if (!finished && updatefinished)
-                    {
-                        client.WriteByOrder("W_Storage_update", false, name);//璐т綅鐘舵�佹洿鏂�
-                        #region 鏃ュ織璁板綍
-                        WriteDBLog.Success(name + "璐т綅鐘舵�佹洿鏂板浣�", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_Storage_update锛歠alse", "PCS");
-                        #endregion
-                    }
-                    if (finished && !updatefinished)
-                    {
-                        var AreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_AreaNr").First(), client);
-                        var areaCode = PipelineJob.area_code(name);   //鏍规嵁涓嬫枡鍙e崟鍏冨悕鑾峰彇鍖哄煙浠g爜
-                        var station = stationinfoRepository.FindFirst(x => x.area == areaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString());  //姝ゅ鏈夐棶棰� 涓嶇煡閬撴槸缁撳熬涓�1鐨勫摢涓笅鏂欏彛
-                        station.quantity++;    //todo 姝ゅ鏁伴噺涓嶄細澧炲姞  浣嗘槸鏇存柊瀹炰綋褰卞搷鎶ラ敊 鏄庢棩娴嬭瘯
-                        if (station.quantity > 5)
-                            throw new Exception($"涓嬫枡浣嶄俊鎭洿鏂板け璐ワ紒涓嬫枡浣嶈溅杞暟閲忓ぇ浜�5锛歿station.stationCode}");
-                        //station.bindSN = station.bindSN == string.Empty ? Wheel_id : station.bindSN + "," + Wheel_id;
-                        station.bindSN = string.IsNullOrEmpty(station.bindSN) ? Wheel_id : station.bindSN + "," + Wheel_id;
-                        if (station.quantity == 1)
+                        if (finished && !updatefinished)
                         {
-                            station.stationType = mes_Head.drawingNo;
-                            station.Number = mes_Head.jobID;
-                            station.heatNumber = mes_Detail.heatID;
-                            station.tray_status = "StrogeTray";
-                        }
-                        var count = stationinfoRepository.Update(station, true);
-                        if (count < 1)
-                            throw new Exception($"涓嬫枡浣嶄俊鎭洿鏂板け璐ワ紒涓嬫枡浣嶇紪鍙凤細{station.stationCode}");
-                        client.WriteByOrder("W_Storage_update", true, name);//璐т綅鐘舵�佹洿鏂�
-                        client.WriteByOrder("W_Enabl_Load", false, name);//鏄惁鍏佽
-                        #region 鏃ュ織璁板綍
-                        WriteDBLog.Success(name + "鏀炬枡瀹屾垚", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n涓嬫枡浣嶅彿锛歿AreaNr}" +
-                            $"\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_Storage_update锛歵rue" + $"\nW_Enabl_Load锛歠alse", "PCS");
-                        #endregion
-                    }
+                            client.WriteByOrder("W_Enabl_Load", false, name);//鏄惁鍏佽
 
-                    var Request = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Request_Load").First(), client);
-                    if (!Request) continue;
-
-                    var Stations = stationinfoRepository.Find(x => x.area == PipelineJob.area_code(name));
-
-                    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);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                    }
-
-                    //var currentAreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Are00aNr").First(), client);
-                    //var currentAreaCode = PipelineJob.area_code(name);   //鏍规嵁涓嬫枡鍙e崟鍏冨悕鑾峰彇鍖哄煙浠g爜
-                    //var currentStation = stationinfoRepository.FindFirst(x => x.area == currentAreaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == currentAreaNr.ToString());
-                    //if (!currentStation.enable || currentStation.location_state == LocationStateEnum.Empty.ToString())
-                    //    client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-
-                    var wheel = PipelineJob.QueryMateriel(mes_Head.drawingNo);
-                    if (wheel == null)
-                    {
-                        #region 鏃ュ織璁板綍
-                        WriteDBLog.Error(name, $"鏈煡璇㈠埌杞﹁疆淇℃伅锛�", "PCS");
-                        #endregion
-                        continue;
-                    }
-
-                    var PartStatus = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PartStatus").First(), client);//1:ok;2:nok
-                    if ((Int16)PartStatus == 1)
-                    {
-                        var 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.e < 1100 ? "SmallTray" : "LargeTray")
-                        && x.Number == mes_Detail.jobID
-                        && x.heatNumber == mes_Detail.heatID)
-                        .OrderByDescending(x => x.quantity)
-                        .FirstOrDefault();
-                        if (Stationinfo == null)
-                            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.e < 1100 ? "SmallTray" : "LargeTray"))
+                            #region 璇诲彇妗佹灦淇℃伅
+                            var WheelType = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_Type").First(), client);//杞﹁疆绫诲瀷
+                            var Wheel_SN = client.ReadByOrder<string>("R_Wheel_id", name);//杞﹁疆SN鍙�
+                            if (string.IsNullOrEmpty(Wheel_SN))
                             {
-                                Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
-                                Stationinfo.tray_type = Stationinfo.tray_type == "SmallTray" ? "SmallTray/LargeTray" : "LargeTray/SmallTray";
-                                Stationinfo.remark = "鎵樼洏绫诲瀷涓嶄竴鑷撮渶鏇存崲鎵樼洏";
-                                stationinfoRepository.Update(Stationinfo, true);
+                                //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 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");
+                                WriteLog.Write_Log(name + "鏀炬枡瀹屾垚鍑洪敊", Wheel_SN, "璇诲彇妗佹灦淇℃伅锛�", $"杞﹁疆SN鍙凤細{Wheel_SN}鏈煡璇㈠埌宸ュ崟淇℃伅");
+                                #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
 
-                            var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == Stationinfo.stationCode).ToList();
-                            var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), Pipeline_client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
-                            //var MaterialSignal = (Int16)DBExtension.Read(details.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)
+                            #endregion
+
+                            var AreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_AreaNr").First(), client);
+                            if (AreaNr == 0)
                             {
-                                List<string> list = new List<string>();
-                                if (Stationinfo.bindSN != null)
+                                client.WriteByOrder("W_Storage_update", true, name);//璐т綅鐘舵�佹洿鏂�
+                                continue;
+                            }
+
+
+                            var areaCode = PipelineJob.area_code(name);   //鏍规嵁涓嬫枡鍙e崟鍏冨悕鑾峰彇鍖哄煙浠g爜
+                            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 (station.bindSN.Contains(Wheel_SN))
+                                    throw new Exception($"{station.stationCode}宸插瓨鍦ㄨ溅杞甋N鍙凤細{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";
+                            }
+                            //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($"宸ュ崟瀛愯〃淇℃伅鏇存柊澶辫触锛佽溅杞甋N鍙凤細{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锛歵rue" + $"\nW_Enabl_Load锛歠alse", "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;
+
+                        //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))
+                        {
+                            WriteLog.Write_Log(name + "鐢宠鏀炬枡寮傚父", "杞﹁疆SN鍙蜂负绌�", "", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙凤細{Wheel_id}涓虹┖");
+                            continue;
+                        }
+
+
+                        var Work = workinfoRepository.Find(x => x.SN == Wheel_id && x.processCode == "17").FirstOrDefault();
+                        if (Work == null)
+                        {
+                            client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                            //WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n\n鏈煡璇㈠埌宸ュ崟淇℃伅", "PCS");
+                            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);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                        //    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);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                        //    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);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                        //}
+
+                        #region MyRegion
+                        //var currentAreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Are00aNr").First(), client);
+                        //var currentAreaCode = PipelineJob.area_code(name);   //鏍规嵁涓嬫枡鍙e崟鍏冨悕鑾峰彇鍖哄煙浠g爜
+                        //var currentStation = stationinfoRepository.FindFirst(x => x.area == currentAreaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == currentAreaNr.ToString());
+                        //if (!currentStation.enable || currentStation.location_state == LocationStateEnum.Empty.ToString())
+                        //    client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                        #endregion
+
+
+                        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);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                            //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}\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 (Work.heatID != null)
+                            {
+                                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 == Work.workOrder
+                           && x.heatNumber == Work.heatID)
+                           .OrderByDescending(x => x.quantity)
+                           .FirstOrDefault();
+                            }
+                            else
+                            {
+                                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 == 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)
+                                //{
+                                //    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)
                                 {
-                                    var SNS = Stationinfo.bindSN.Split(",");
-                                    foreach (var SN in SNS)
-                                    {
-                                        if (!string.IsNullOrEmpty(SN))
-                                            list.Add(SN);
-                                    }
+                                    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 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)
+                            {
+
+                                #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");
                                 }
 
-                                //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
-                                if (list.Count != Stationinfo.quantity)
+                                #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);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
                                     Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
-                                    Stationinfo.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
+                                    Stationinfo.tray_type = Stationinfo.tray_type == "SmallTray" ? "SmallTray/LargeTray" : "LargeTray/SmallTray";
+                                    Stationinfo.remark = "鎵樼洏绫诲瀷涓嶄竴鑷撮渶鏇存崲鎵樼洏";
                                     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);//鍖哄煙璐т綅鍙�
-                                client.WriteByOrder("W_IndexNr", (Int16)(Stationinfo.quantity + 1), name);//鎵樼洏涓婄殑绗嚑涓溅杞�
-                                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" +
-                                    $"\n璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}" +
-                                    $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\nW_Enabl_Load锛歵rue", "PCS");
                                 #endregion
-                                return;
+
+                                var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == Stationinfo.stationCode).ToList();
+                                var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), Pipeline_client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+
+                                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>();
+                                    if (Stationinfo.bindSN != null)
+                                    {
+                                        var SNS = Stationinfo.bindSN.Split(",");
+                                        foreach (var SN in SNS)
+                                        {
+                                            if (!string.IsNullOrEmpty(SN))
+                                                list.Add(SN);
+                                        }
+                                    }
+
+                                    #region 璐т綅鏁伴噺涓庡厜鐢典笉鍖归厤锛屾姤璀�
+                                    if (list.Count > 0 && MaterialSignal != 1)
+                                    {
+                                        client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                                        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);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                                        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
+
+                                    //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
+                                    if (list.Count != Stationinfo.quantity)
+                                    {
+                                        Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                        Stationinfo.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
+                                        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);//鍖哄煙璐т綅鍙�
+                                    client.WriteByOrder("W_IndexNr", (Int16)(Stationinfo.quantity + 1), name);//鎵樼洏涓婄殑绗嚑涓溅杞�
+                                    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" +$"\n璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}" +
+                                    //    $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\nW_Enabl_Load锛歵rue", "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\n鏄惁鍏佽涓嬫枡锛歵rue");
+                                    #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)
-                    {
-                        var Stationinfo = Stations
+                        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 == mes_Head.drawingNo
-                        && x.tray_type == (wheel.e < 1100 ? "SmallTray" : "LargeTray")
-                        && x.Number == mes_Detail.jobID
-                        && x.heatNumber == mes_Detail.heatID).FirstOrDefault();
-                        if (Stationinfo == null)
-                            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.e < 1100 ? "SmallTray" : "LargeTray"))
+                        && 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)
                             {
-                                Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
-                                Stationinfo.tray_type = Stationinfo.tray_type == "SmallTray" ? "SmallTray/LargeTray" : "LargeTray/SmallTray";
-                                Stationinfo.remark = "鎵樼洏绫诲瀷涓嶄竴鑷撮渶鏇存崲鎵樼洏";
-                                stationinfoRepository.Update(Stationinfo, true);
-                            }
-                            #endregion
-                            var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == Stationinfo.stationCode).ToList();
-                            var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), Pipeline_client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
-                            if (PalletSignal == 1)
-                            {
-                                var SNS = Stationinfo.bindSN.Split(",");
-                                List<string> list = new List<string>();
-                                if (Stationinfo.bindSN != 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)
                                 {
-                                    foreach (var SN in SNS)
-                                    {
-                                        if (!string.IsNullOrEmpty(SN))
-                                            list.Add(SN);
-                                    }
+                                    agvtask(stationinfoRepository, NG, Work, "TaskType_OutsourceInbound");
+                                    continue;
                                 }
 
-                                //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
-                                if (list.Count != Stationinfo.quantity)
+                                #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 != "LargeTray" && (wheel == null ? wheel1.e : wheel.e) > 1100)
                                 {
                                     Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
-                                    Stationinfo.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
+                                    Stationinfo.tray_type = Stationinfo.tray_type == "SmallTray" ? "SmallTray/LargeTray" : "LargeTray/SmallTray";
+                                    Stationinfo.remark = "鎵樼洏绫诲瀷涓嶄竴鑷撮渶鏇存崲鎵樼洏";
                                     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);//鍖哄煙璐т綅鍙�
-                                client.WriteByOrder("W_IndexNr", (Int16)(Stationinfo.quantity + 1), name);//鎵樼洏涓婄殑绗嚑涓溅杞�
-                                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" +
-                                    $"\n璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}" +
-                                    $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\nW_Enabl_Load锛歵rue", "PCS");
                                 #endregion
-                                return;
+                                var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == Stationinfo.stationCode).ToList();
+                                var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), Pipeline_client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                                var MaterialSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), Pipeline_client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+                                if (PalletSignal == 1)
+                                {
+                                    List<string> list = new List<string>();
+                                    if (Stationinfo.bindSN != null)
+                                    {
+                                        var SNS = Stationinfo.bindSN.Split(",");
+                                        foreach (var SN in SNS)
+                                        {
+                                            if (!string.IsNullOrEmpty(SN))
+                                                list.Add(SN);
+                                        }
+                                    }
+
+                                    #region 璐т綅鏁伴噺涓庡厜鐢典笉鍖归厤锛屾姤璀�
+                                    //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);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                                        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);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                                        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
+
+                                    //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
+                                    if (list.Count != Stationinfo.quantity)
+                                    {
+                                        Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                        Stationinfo.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
+                                        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);//鍖哄煙璐т綅鍙�
+                                    client.WriteByOrder("W_IndexNr", (Int16)(Stationinfo.quantity + 1), name);//鎵樼洏涓婄殑绗嚑涓溅杞�
+                                    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" +$"\n璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}" +
+                                    //    $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\nW_Enabl_Load锛歵rue", "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\n鏄惁鍏佽涓嬫枡锛歵rue");
+                                    #endregion
+                                    continue;
+                                }
                             }
                         }
+                        #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
                     }
-                    #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");
+                    }
                 }
             }
             catch (Exception ex)
             {
-                throw;
+                WriteDBLog.Error("涓嬫枡鍖�", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
             }
         }
         #endregion
+
+        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);
+            var task = agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).FirstOrDefault();
+            if (task != null) return;
+            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
+
     }
 }

--
Gitblit v1.9.3