From eda17eddf88e6108cadbf8dcef5c2195c1a7b708 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期三, 01 四月 2026 10:55:05 +0800
Subject: [PATCH] 提交VS生成临时文件

---
 LB_SmartVision/Forms/Pages/BarcodeReaderPage/BarcodeReadersEditPage.cs |  226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 226 insertions(+), 0 deletions(-)

diff --git a/LB_SmartVision/Forms/Pages/BarcodeReaderPage/BarcodeReadersEditPage.cs b/LB_SmartVision/Forms/Pages/BarcodeReaderPage/BarcodeReadersEditPage.cs
new file mode 100644
index 0000000..1f27f89
--- /dev/null
+++ b/LB_SmartVision/Forms/Pages/BarcodeReaderPage/BarcodeReadersEditPage.cs
@@ -0,0 +1,226 @@
+using LB_VisionControls;
+using LB_VisionProcesses.BarcodeReaders;
+using LB_VisionProcesses.BarcodeReaders.Huayray;
+using System;
+using System.Collections.Concurrent;
+using System.Windows.Forms;
+
+namespace LB_SmartVision.Forms.Pages.BarcodeReaderPage
+{
+    public partial class BarcodeReadersEditPage : UserControl
+    {
+        public Action<string, LogInfoType> LogInfo;
+
+
+        public BarcodeReadersEditPage()
+        {
+            InitializeComponent();
+
+            Name = "BarcodeReadersEditPage";
+            Text = "璇荤爜鍣ㄨ缃�";
+        }
+
+        private void BarcodeReadersEditPage_Paint(object sender, PaintEventArgs e)
+        {
+            uiFlowLayoutPanel1.Controls.Clear();
+
+            if (GlobalVar.dicBarcodeReaders.Count <= 0)
+                return;
+
+            foreach (var item in GlobalVar.dicBarcodeReaders)
+            {
+                string ReaderSN = item.Key;
+                string ReaderBrand = item.Value.Brand.ToString();
+
+                if (string.IsNullOrEmpty(ReaderSN) || string.IsNullOrEmpty(ReaderBrand))
+                    continue;
+
+                UserItem flow = new UserItem(new string[] { "娴嬭瘯", "鍒锋柊", "绉婚櫎" });
+                flow.Name = ReaderSN;
+                flow.Text = $"[{ReaderBrand}] {ReaderSN}";
+                if (item.Value.IsConnected)
+                    flow.state = State.Pass;
+                else
+                    flow.state = State.Error;
+                LoadFlowEvent(flow);
+
+                uiFlowLayoutPanel1.Controls.Add(flow);
+            }
+        }
+
+
+        private void uiButton1_Click(object sender, System.EventArgs e)
+        {
+            CreateBarcodeReaderForm createForm = new CreateBarcodeReaderForm();
+            createForm.ShowDialog();
+
+            if (createForm.bCreate)
+            {
+                BarcodeReaderBase reader = createForm.barcodeReader;
+                if (GlobalVar.dicBarcodeReaders.ContainsKey(reader.SN))
+                {
+                    MessageBox.Show($"璇荤爜鍣╗{reader.SN}]宸插瓨鍦�!", "寮傚父");
+                    return;
+                }
+
+                string ReaderSN = reader.SN;
+                string ReaderBrand = reader.Brand.ToString();
+
+                if (string.IsNullOrEmpty(ReaderSN) || string.IsNullOrEmpty(ReaderBrand))
+                    return;
+
+                GlobalVar.dicBarcodeReaders.TryAdd(ReaderSN, reader);
+                LogInfo?.Invoke(string.Format("娣诲姞璇荤爜鍣╗{0}][{1}]鎴愬姛", ReaderBrand, ReaderSN), LogInfoType.PASS);
+            }
+            this.Invalidate();
+        }
+
+        private void uiButton2_Click(object sender, System.EventArgs e)
+        {
+            //娓呴櫎鐢–lear鏂规硶
+            uiFlowLayoutPanel1.Controls.Clear();
+            foreach (var reader in GlobalVar.dicBarcodeReaders.Values)
+            {
+                reader.Dispose();
+            }
+            GlobalVar.dicBarcodeReaders.Clear();
+        }
+
+        private void LoadFlowEvent(UserItem flow)
+        {
+            //鎸夐敭1涓烘祴璇�
+            flow.MenuItem1ClickedEvent += TestEvent;
+            //鎸夐敭2涓哄埛鏂�
+            flow.MenuItem2ClickedEvent += ReconnectEvent;
+            //鎸夐敭3涓虹Щ闄�
+            flow.MenuItem3ClickedEvent += DeleteEvent;
+        }
+
+        private void RemoveFlowEvent(UserItem flow)
+        {
+            //鎸夐敭1涓烘祴璇�
+            flow.MenuItem1ClickedEvent -= TestEvent;
+            //鎸夐敭2涓哄埛鏂�
+            flow.MenuItem2ClickedEvent -= ReconnectEvent;
+            //鎸夐敭3涓虹Щ闄�
+            flow.MenuItem3ClickedEvent -= DeleteEvent;
+        }
+
+        // 娴嬭瘯璇荤爜鍣�
+        private void TestEvent(string Name, string Text)
+        {
+            for (int i = 0; i < uiFlowLayoutPanel1.Controls.Count; i++)
+            {
+                UserItem flow = (UserItem)uiFlowLayoutPanel1.Controls[i];
+                string name = flow.Name;
+                if (name != Name)
+                    continue;
+
+                if (GlobalVar.dicBarcodeReaders.ContainsKey(name))
+                {
+                    BarcodeReaderForm readerForm = new BarcodeReaderForm(GlobalVar.dicBarcodeReaders[name]);
+                    readerForm.Show();
+                }
+            }
+        }
+
+        // 绉婚櫎璇荤爜鍣�
+        private void DeleteEvent(string Name, string Text)
+        {
+            for (int i = 0; i < uiFlowLayoutPanel1.Controls.Count; i++)
+            {
+                UserItem flow = (UserItem)uiFlowLayoutPanel1.Controls[i];
+                string name = flow.Name;
+                if (name != Name)
+                    continue;
+
+                RemoveFlowEvent(flow);
+                uiFlowLayoutPanel1.Controls.Remove(uiFlowLayoutPanel1.Controls[i]);
+                if (GlobalVar.dicBarcodeReaders.TryRemove(name, out BarcodeReaderBase barcodeReader))
+                {
+                    barcodeReader.Dispose();
+                    LogInfo?.Invoke(string.Format("绉婚櫎璇荤爜鍣╗{0}]", name), LogInfoType.INFO);
+                }
+                else
+                    LogInfo?.Invoke(string.Format("绉婚櫎璇荤爜鍣╗{0}]澶辫触", name), LogInfoType.ERROR);
+
+            }
+        }
+
+        // 閲嶈繛璇荤爜鍣�
+        private void ReconnectEvent(string Name, string Text)
+        {
+            for (int i = 0; i < uiFlowLayoutPanel1.Controls.Count; i++)
+            {
+                UserItem flow = (UserItem)uiFlowLayoutPanel1.Controls[i];
+                string name = flow.Name;
+                if (name != Name)
+                    continue;
+
+                if (!GlobalVar.dicBarcodeReaders.ContainsKey(name))
+                {
+                    LogInfo?.Invoke(string.Format("璇荤爜鍣╗{0}]涓嶅瓨鍦�", name), LogInfoType.ERROR);
+                    flow.state = State.Error;
+                    flow.Refresh();
+                    return;
+                }
+
+                var reader = GlobalVar.dicBarcodeReaders[name];
+                if (reader == null)
+                {
+                    LogInfo?.Invoke(string.Format("璇荤爜鍣╗{0}]瀹炰緥涓虹┖", name), LogInfoType.ERROR);
+                    flow.state = State.Error;
+                    flow.Refresh();
+                    return;
+                }
+
+                try
+                {
+                    // 鍏堥噴鏀炬棫瀹炰緥鐨勮祫婧�
+                    reader.Dispose();
+
+                    // 娣诲姞鐭殏寤惰繜锛岀‘淇漇DK搴曞眰璧勬簮瀹屽叏閲婃斁
+                    System.Threading.Thread.Sleep(500);
+
+                    // 寮哄埗鍨冨溇鍥炴敹锛岀‘淇濈浉鏈哄璞¤瀹屽叏閲婃斁
+                    GC.Collect();
+                    GC.WaitForPendingFinalizers();
+                    GC.Collect();
+
+                    // 浠庡瓧鍏镐腑绉婚櫎鏃у疄渚�
+                    GlobalVar.dicBarcodeReaders.TryRemove(name, out _);
+
+                    // 鍒涘缓鏂板疄渚�
+                    BarcodeReaderBase newReader = null;
+                    switch (reader.Brand)
+                    {
+                        case BarcodeReaderBrand.Huayray:
+                            newReader = new HRBarcodeReader();
+                            break;
+                        default:
+                            throw new Exception($"涓嶆敮鎸佺殑璇荤爜鍣ㄥ搧鐗�: {reader.Brand}");
+                    }
+
+                    if (newReader.Open(name))
+                    {
+                        // 娣诲姞鍒板瓧鍏�
+                        GlobalVar.dicBarcodeReaders.TryAdd(name, newReader);
+                        flow.state = State.Pass;
+                        LogInfo?.Invoke(string.Format("閲嶈繛璇荤爜鍣╗{0}]鎴愬姛", name), LogInfoType.PASS);
+                    }
+                    else
+                    {
+                        flow.state = State.Error;
+                        LogInfo?.Invoke(string.Format("璇荤爜鍣╗{0}]閲嶆柊鍒涘缓鍚庝粛杩炴帴澶辫触", name), LogInfoType.ERROR);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    flow.state = State.Error;
+                    LogInfo?.Invoke(string.Format("閲嶈繛璇荤爜鍣╗{0}]寮傚父: {1}", name, ex.Message), LogInfoType.ERROR);
+                }
+                flow.Refresh();
+            }
+        }
+    }
+}

--
Gitblit v1.9.3