From f3493a6f6f9958cea100ad596fa84239a6e2e962 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 18 六月 2024 16:58:53 +0800
Subject: [PATCH] 获取老PCS下VK、桁架机械手、机床、状态信息

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/dt_patternService.cs |   72 ++++++++++++++++++++++++------------
 1 files changed, 48 insertions(+), 24 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/dt_patternService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/dt_patternService.cs"
index 91c04eb..7cf9eb8 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/dt_patternService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/dt_patternService.cs"
@@ -22,6 +22,7 @@
 using WIDESEA_Core.EFDbContext;
 using WIDESEA_WCS.Repositories;
 using WIDESEA_Comm;
+using WIDESEA_WCS.WCSClient;
 
 namespace WIDESEA_WCS.Services
 {
@@ -50,19 +51,32 @@
         public WebResponseContent UpdateAuto(string v)
         {
             WebResponseContent content = new WebResponseContent();
-            VOLContext context = new VOLContext();
-            Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
-            var stations = stationinfoRepository.Find(x => x.stationCode == "X01001001" || x.stationCode == "X01001002" || x.stationCode == "X02001001" || x.stationCode == "X02001002").ToList();
-            if (stations.Where(x => x.tray_status == TrayStateEnum.StrogeTray.ToString()).Any())
-                return content.Error("璁剧疆涓烘ā寮�1澶辫触锛佷笅鏂欎綅瀛樺湪杞﹁疆锛�");
+            try
+            {
+                var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "妗佹灦");
+                if (Gantry_client == null) throw new Exception("妗佹灦璋冨害鏈嶅姟鏈紑鍚紒");
+                if (!Gantry_client.IsConnected) throw new Exception("涓庢鏋惰繛鎺ヨ秴鏃讹紒");
+                VOLContext context = new VOLContext();
+                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
+                var stations = stationinfoRepository.Find(x => x.stationCode == "X01001001" || x.stationCode == "X01001002" || x.stationCode == "X02001001" || x.stationCode == "X02001002").ToList();
+                if (stations.Where(x => x.tray_status == TrayStateEnum.StrogeTray.ToString()).Any())
+                    throw new Exception("璁剧疆涓烘ā寮�1澶辫触锛佷笅鏂欎綅瀛樺湪杞﹁疆锛�");
+                #region 鍐欏叆淇″彿鍛婅瘔妗佹灦鍒囨崲妯″紡
 
-            var model = JsonConvert.DeserializeObject<dt_pattern>(v);
-            model.pattern_state = 1;
-            var cont = _repository.Update(model, true);
-            if (cont > 0)
-                content.OK(model.pattern_name + "璁剧疆涓烘ā寮�1鎴愬姛锛�");
-            else
-                content.Error(model.pattern_name + "璁剧疆涓烘ā寮�1澶辫触锛�");
+                #endregion
+
+                var model = JsonConvert.DeserializeObject<dt_pattern>(v);
+                model.pattern_state = 1;
+                var cont = _repository.Update(model, true);
+                if (cont > 0)
+                    content.OK(model.pattern_name + "璁剧疆涓烘ā寮�1鎴愬姛锛�");
+                else
+                    content.Error(model.pattern_name + "璁剧疆涓烘ā寮�1澶辫触锛�");
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
             return content;
         }
         /// <summary>
@@ -73,18 +87,28 @@
         public WebResponseContent UpdateManual(string v)
         {
             WebResponseContent content = new WebResponseContent();
-            VOLContext context = new VOLContext();
-            Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
-            var stations = stationinfoRepository.Find(x => x.stationCode == "X01001001" || x.stationCode == "X01001002" || x.stationCode == "X02001001" || x.stationCode == "X02001002").ToList();
-            if (stations.Where(x => x.tray_status == TrayStateEnum.StrogeTray.ToString()).Any())
-                return content.Error("璁剧疆涓烘ā寮�2澶辫触锛佷笅鏂欎綅瀛樺湪杞﹁疆锛�");
-            var model = JsonConvert.DeserializeObject<dt_pattern>(v);
-            model.pattern_state = 0;
-            var cont = _repository.Update(model, true);
-            if (cont > 0)
-                content.OK(model.pattern_name + "璁剧疆涓烘ā寮�2鎴愬姛锛�");
-            else
-                content.Error(model.pattern_name + "璁剧疆涓烘ā寮�2澶辫触锛�");
+            try
+            {
+                var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "妗佹灦");
+                if (Gantry_client == null) throw new Exception("妗佹灦璋冨害鏈嶅姟鏈紑鍚紒");
+                if (!Gantry_client.IsConnected) throw new Exception("涓庢鏋惰繛鎺ヨ秴鏃讹紒");
+                VOLContext context = new VOLContext();
+                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
+                var stations = stationinfoRepository.Find(x => x.stationCode == "X01001001" || x.stationCode == "X01001002" || x.stationCode == "X02001001" || x.stationCode == "X02001002").ToList();
+                if (stations.Where(x => x.tray_status == TrayStateEnum.StrogeTray.ToString()).Any())
+                    throw new Exception("璁剧疆涓烘ā寮�2澶辫触锛佷笅鏂欎綅瀛樺湪杞﹁疆锛�");
+                var model = JsonConvert.DeserializeObject<dt_pattern>(v);
+                model.pattern_state = 0;
+                var cont = _repository.Update(model, true);
+                if (cont > 0)
+                    content.OK(model.pattern_name + "璁剧疆涓烘ā寮�2鎴愬姛锛�");
+                else
+                    content.Error(model.pattern_name + "璁剧疆涓烘ā寮�2澶辫触锛�");
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
             return content;
         }
     }

--
Gitblit v1.9.3