From 388c43ee7b741eebafa98cd8ef992005f1aa56f4 Mon Sep 17 00:00:00 2001
From: 陈勇 <chenyong@hnkhzn.com>
Date: 星期二, 12 三月 2024 14:52:40 +0800
Subject: [PATCH] PDA源程序

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs |  403 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 320 insertions(+), 83 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 5dbcde3..7b6af49 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"
@@ -4,10 +4,12 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Comm;
 using WIDESEA_Core.EFDbContext;
 using WIDESEA_WCS.IRepositories;
 using WIDESEA_WCS.Repositories;
 using WIDESEA_WCS.WCSClient;
+using static System.Collections.Specialized.BitVector32;
 
 namespace WIDESEA_WCS
 {
@@ -17,9 +19,12 @@
         Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
         Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
         Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
-        /// <summary>
-        /// 鏌ヨ杞﹁疆鏁版嵁
-        /// </summary>
+        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 鏌ヨ杞﹁疆鏁版嵁
         public void QueryWheeldata(PLCClient client)
         {
             try
@@ -30,33 +35,57 @@
                 {
                     var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                     var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on").First(), client);
-                    if ((Int16)on == 1)
+                    if ((byte)on == 1)
                     {
                         var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
-                        var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
-                        if (geometry == null)
+                        if (name != "杈婇亾涓婃枡鏌ヨ杞﹁疆")
                         {
-                            //DBExtension.Write(details.Where(x => x.plcdetail_name == "W_i_status").First(), client, (Int16)2);
-                            client.WriteByOrder("W_i_status", (Int16)2, name);//1-鎵惧埌鏁版嵁锛�2-鏈壘鍒板伐浠剁被鍨嬫暟鎹�
-                            client.WriteByOrder("W_i_skip_op", "1", name);//灞忚斀宸ヨ壓(灞忚斀瑙嗚妫�娴�/灞忚斀娑傛补);
-                                                                          //0-浣跨敤锛�1-璺宠繃
-                            client.WriteByOrder("R_oi_on", (Int16)0, name);
+                            var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
+                            if (geometry == null)
+                            {
+                                //DBExtension.Write(details.Where(x => x.plcdetail_name == "W_i_status").First(), client, (Int16)2);
+                                //1-鎵惧埌鏁版嵁锛�2-鏈壘鍒板伐浠剁被鍨嬫暟鎹�
+                                client.WriteByOrder("W_i_status", (byte)2, name);
+                                client.WriteByOrder("R_oi_on", (byte)0, name);
+                            }
+                            else
+                            {
+                                //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("R_oi_on", (byte)0, name);
+                            }
                         }
                         else
                         {
-                            client.WriteByOrder("W_i_status", (Int16)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_skip_op", "0", name);//瀛楃涓插啓鍏�-2
-                            client.WriteByOrder("R_oi_on", (Int16)0, name);
+                            var geometry = detectionlineRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
+                            if (geometry == null)
+                            {
+                                client.WriteByOrder("W_i_status", (byte)2, name);
+                                client.WriteByOrder("R_oi_on", (byte)0, name);
+                            }
+                            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("R_oi_on", (byte)0, name);
+                            }
                         }
+
                     }
                 }
             }
@@ -65,9 +94,9 @@
                 throw;
             }
         }
-        /// <summary>
-        /// 鏌ヨ璁㈠崟,鏄惁闇�瑕佸姞宸�
-        /// </summary>
+        #endregion
+
+        #region 鏌ヨ璁㈠崟,鏄惁闇�瑕佸姞宸�
         public void QueryOrder(PLCClient client)
         {
             try
@@ -78,28 +107,91 @@
                 {
                     var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                     var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on").First(), client);
-                    if ((Int16)on == 1)
+                    if ((byte)on == 1)
                     {
-                        var wp_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_id").First(), client);
-                        //闇�娣诲姞鏌ヨ杞﹁疆SN鍙疯鍗曢�昏緫
-
-                        var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
-                        var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
-                        if (geometry == null)
+                        //var wp_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_id").First(), client).ToString();
+                        var wp_id = client.ReadByOrder<string>("R_o_wp_id", name);
+                        var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == wp_id);
+                        if (mes_Detail == null)
                         {
-                            client.WriteByOrder("W_i_status", (Int16)2, name);//1-濂�,鍏佽鍔犲伐锛�2-涓嶅湪鍒楄〃涓紝3-涓嶅姞宸ヨ溅杞被鍨�
-                            client.WriteByOrder("R_oi_on", (Int16)0, name);
+                            client.WriteByOrder("W_i_status", (byte)2, name);
+                            client.WriteByOrder("R_oi_on", (byte)0, name);
+                            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);
+                            continue;
+                        }
+
+                        if (name != "杈婇亾涓婃枡鏌ヨ璁㈠崟")
+                        {
+                            //闇�娣诲姞鏌ヨ杞﹁疆SN鍙疯鍗曢�昏緫   闇�娣诲姞鍏ュ簱妯″紡鍒ゆ柇锛屾墜鍔ㄥ叆搴撴ā寮忛渶浜哄伐娣诲姞鍏ュ簱搴撳尯锛屽惁鍒欐姤璀�
+                            var pattern = patternRepository.FindFirst(x => x.pattern_name == "鍏ュ簱妯″紡").pattern_state;
+                            if (pattern != 1 && string.IsNullOrEmpty(mes_Head.area))
+                            {
+                                client.WriteByOrder("W_i_status", (byte)4, name);
+                                client.WriteByOrder("R_oi_on", (byte)0, name);
+                                continue;
+                            }
+                            var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
+                            //var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
+                            var geometry = dataRepository.FindFirst(x => x.Description == mes_Head.drawingNo);
+                            if (geometry == null)
+                            {
+                                //1-濂�,鍏佽鍔犲伐锛�2-涓嶅湪鍒楄〃涓紝3-涓嶅姞宸ヨ溅杞被鍨嬶紝4-鎵嬪姩鍏ュ簱妯″紡浜哄伐鏈�夋嫨搴撳尯
+                                client.WriteByOrder("W_i_status", (byte)2, name);
+                                client.WriteByOrder("R_oi_on", (byte)0, name);
+                                continue;
+                            }
+                            else
+                            {
+                                //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_sourceheat", "", name);
+                                client.WriteByOrder("W_i_batch_id", mes_Detail.heatBatchID, name);
+
+                                //灞忚斀宸ヨ壓(灞忚斀瑙嗚妫�娴�/灞忚斀娑傛补)
+                                //if (name != "杈婇亾涓婃枡鏌ヨ杞﹁疆")
+                                //{
+                                client.WriteByOrder("W_i_skip_op_SJ1", mes_Head.skip_op_1, name);//灞忚斀瑙嗚妫�娴嬭澶�1
+                                client.WriteByOrder("W_i_skip_op_SJ2", mes_Head.skip_op_2, name);//灞忚斀瑙嗚妫�娴嬭澶�2
+                                client.WriteByOrder("W_i_skip_op_LT", mes_Head.skip_op_3, name);//灞忚斀閾炬潯鏈�
+                                //}
+                                client.WriteByOrder("R_oi_on", (byte)0, name);
+
+                            }
                         }
                         else
                         {
-                            client.WriteByOrder("W_i_status", (Int16)1, name);
-                            //client.WriteByOrder("W_i_job_id", "", name);
-                            //client.WriteByOrder("W_i_drawing_id", "", name);
-                            //client.WriteByOrder("W_i_heat_id", "", name);
-                            //client.WriteByOrder("W_i_sourceheat", "", name);
-                            //client.WriteByOrder("W_i_batch_id", "", name);
-                            client.WriteByOrder("R_oi_on", (Int16)0, name);
+                            var geometry = dataRepository.FindFirst(x => x.Description == mes_Head.drawingNo);
+                            if (geometry == null)
+                            {
+                                //1-濂�,鍏佽鍔犲伐锛�2-涓嶅湪鍒楄〃涓紝3-涓嶅姞宸ヨ溅杞被鍨嬶紝4-鎵嬪姩鍏ュ簱妯″紡浜哄伐鏈�夋嫨搴撳尯
+                                client.WriteByOrder("W_i_status", (byte)2, name);
+                                client.WriteByOrder("R_oi_on", (byte)0, name);
+                                continue;
+                            }
+                            else
+                            {
+                                //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_sourceheat", "", name);
+                                client.WriteByOrder("W_i_batch_id", mes_Detail.heatBatchID, name);
+                                client.WriteByOrder("R_oi_on", (byte)0, name);
+                            }
                         }
+
+
+
                     }
                 }
             }
@@ -108,37 +200,206 @@
                 throw;
             }
         }
-        /// <summary>
-        /// 涓嬫枡浣嶄氦浜�
-        /// </summary>
+        #endregion
+
+        #region 涓嬫枡浣嶄氦浜�   锛侊紒锛佷笅鏂欓�昏緫闇�淇敼
         public void Layofflevel(PLCClient client)
         {
             try
             {
                 var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
-                List<string> names = new List<string>() { "1鍗曞厓涓嬫枡鍖�", "2鍗曞厓涓嬫枡鍖�", "3鍗曞厓涓嬫枡鍖�", "涓婃枡鍖�" };
+                var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "閾炬潯鏈�");
+                if (Pipeline_client == null) throw new Exception("閾炬潯鏈鸿皟搴︽湇鍔℃湭寮�鍚紒");
+                if (!Pipeline_client.IsConnected) throw new Exception("涓庨摼鏉℃満杩炴帴瓒呮椂锛�");
+                var Pipelineplc = repository.FindFirst(x => x.plcinfo_name == Pipeline_client.PLCName);
+                List<string> names = new List<string>() { "1鍗曞厓涓嬫枡鍖�", "2鍗曞厓涓嬫枡鍖�", "3鍗曞厓涓嬫枡鍖�" };
                 foreach (string name in names)
                 {
                     var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
 
                     var Request = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Request_Load").First(), client);
                     if (!Request) continue;
-                    var PartStatus = (Int32)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PartStatus").First(), client);//1:ok;2:nok
-                    var Wheel_Type = (Int32)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_Type").First(), client);//杞﹁疆绫诲瀷
-                    var Wheel_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_id").First(), client).ToString();//杞﹁疆SN鍙�
 
+                    var Stations = stationinfoRepository.Find(x => x.area == PipelineJob.area_code(name));
 
-                    client.WriteByOrder("W_AreaNr", (Int16)1, name);//鍖哄煙璐т綅鍙�
-                    client.WriteByOrder("W_IndexNr", (Int16)1, name);//鎵樼洏涓婄殑绗嚑涓溅杞�
-                    client.WriteByOrder("W_Storage_Type", true, name);//鎵樼洏绫诲瀷1-妯斁;2-绔栨斁
-                    client.WriteByOrder("W_Enabl_Load", true, name);//鏄惁鍏佽
-
-                    var finished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_finished").First(), client);//鏀炬枡瀹屾垚
-                    if (finished)
+                    var NGStation = "X01001003";
+                    if (name == "2鍗曞厓涓嬫枡鍖�") NGStation = "X02001003";
+                    if (name == "3鍗曞厓涓嬫枡鍖�") NGStation = "X03001002";
+                    foreach (var station in Stations)
                     {
-
-                        client.WriteByOrder("W_Storage_update", true, name);//璐т綅鐘舵�佹洿鏂�
+                        if (!station.enable || station.location_state == LocationStateEnum.Empty.ToString())
+                            client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
                     }
+                    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鍙�
+                    //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);
+                    var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
+                    var wheel = PipelineJob.QueryMateriel(mes_Head.drawingNo);
+
+                    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)
+                        {
+                            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 Wheel_id = client.ReadByOrder<string>("R_Wheel_id", name);
+                            if (PalletSignal == 1)
+                            {
+                                var SNS = Stationinfo.bindSN.Split(",");
+                                List<string> list = new List<string>();
+                                foreach (var SN in SNS)
+                                {
+                                    if (!string.IsNullOrEmpty(SN))
+                                        list.Add(SN);
+                                }
+                                //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
+                                if (list.Count != Stationinfo.quantity)
+                                {
+                                    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                    stationinfoRepository.Update(Stationinfo, true);
+                                    //鍐欏叆妗佹灦鎶ヨ淇″彿
+                                    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);//鏄惁鍏佽
+                                return;
+                            }
+                        }
+                    }
+                    else if ((Int16)PartStatus == 2)
+                    {
+                        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).FirstOrDefault();
+                        if (Stationinfo != null)
+                        {
+                            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(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                            if (PalletSignal == 1)
+                            {
+                                var SNS = Stationinfo.bindSN.Split(",");
+                                List<string> list = new List<string>();
+                                foreach (var SN in SNS)
+                                {
+                                    if (!string.IsNullOrEmpty(SN))
+                                        list.Add(SN);
+                                }
+                                //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
+                                if (list.Count != Stationinfo.quantity)
+                                {
+                                    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                    stationinfoRepository.Update(Stationinfo, true);
+                                    //鍐欏叆妗佹灦鎶ヨ淇″彿
+                                    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);//鏄惁鍏佽
+                                return;
+                            }
+                        }
+                    }
+                    #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
+                    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);//璐т綅鐘舵�佹洿鏂�
+                    if (finished && !updatefinished)
+                    {
+                        var AreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_AreaNr").First(), client);
+                        var station = stationinfoRepository.FindFirst(x => x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString());
+                        station.quantity = station.quantity++;
+                        station.bindSN = station.bindSN == string.Empty ? Wheel_id : station.bindSN + "," + Wheel_id;
+                        if (station.quantity == 0)
+                        {
+                            station.stationType = mes_Head.drawingNo;
+                            station.Number = mes_Head.jobID;
+                            station.heatNumber = mes_Detail.heatID;
+                        }
+                        var count = stationinfoRepository.Update(station);
+                        if (count < 1)
+                            throw new Exception($"涓嬫枡浣嶄俊鎭洿鏂板け璐ワ紒涓嬫枡浣嶇紪鍙凤細{station.stationCode}");
+                        client.WriteByOrder("W_Storage_update", true, name);//璐т綅鐘舵�佹洿鏂�
+                        client.WriteByOrder("W_Enabl_Load", false, name);//鏄惁鍏佽
+                    }
+                    #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)
@@ -146,30 +407,6 @@
                 throw;
             }
         }
-        /// <summary>
-        /// 闃插憜鎺柦
-        /// </summary>
-        static bool Gantry_Out_of_Area1;//妗佹灦鏄惁鍦ㄥ尯鍩熷唴
-        static bool Gantry_Out_of_Area2;//妗佹灦鏄惁鍦ㄥ尯鍩熷唴
-        static bool Gantry_Out_of_Area3;//妗佹灦鏄惁鍦ㄥ尯鍩熷唴
-        static bool Gantry_Out_of_Area4;//妗佹灦鏄惁鍦ㄥ尯鍩熷唴
-        public void Stupidproofmeasure(PLCClient client)
-        {
-            try
-            {
-                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
-                List<string> names = new List<string>() { "1鍗曞厓闃插憜", "2鍗曞厓闃插憜", "3鍗曞厓闃插憜", "涓婃枡鍖洪槻鍛�" };
-                foreach (string name in names)
-                {
-                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
-                    var Release_In = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Release_In").First(), client);//鍏佽杩涘叆
-                    if (!Release_In) { }
-                }
-            }
-            catch (Exception ex)
-            {
-                throw;
-            }
-        }
+        #endregion
     }
 }

--
Gitblit v1.9.3