From a987bb05357a451c8476098067573059287dc008 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期五, 16 一月 2026 12:21:32 +0800
Subject: [PATCH] 添加运动控制菜单
---
LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs | 298 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 289 insertions(+), 9 deletions(-)
diff --git a/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs b/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
index 5bcb882..f017dce 100644
--- a/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
+++ b/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
@@ -1,9 +1,19 @@
-锘縰sing LB_VisionControl;
-using OpenCvSharp.Flann;
-using System;
+锘縰sing LB_SmartVision.Forms.Pages.ProcessPage;
+using LB_SmartVision.ProcessRun;
+using LB_VisionControl;
+using LB_VisionProcesses;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
using System.Collections.Concurrent;
+using System.Data;
+using System.Text;
+using VisionControl.Forms;
+using LB_SmartVision.Forms.Pages.SettingPage;
+using LB_SmartVisionCommon;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
+using LB_SmartVision.Forms.Pages.CameraPage;
+using System.Security.Principal;
using System.Windows.Forms;
-using System.Xml.Linq;
namespace LB_SmartVision.Forms.Pages.UserManagementPage
{
@@ -11,18 +21,288 @@
{
public Action<string, LogInfoType> LogInfo;
-
public UserManagementEditPage()
{
- Name = "UserManagementEditPage";
+ Name = "UserManagementEditPage";
Text = "鐢ㄦ埛绠$悊璁剧疆";
+
+ InitializeComponent();
+ InitializeDataGridView();
+ InitializeComboBox();
}
- private void MESEditPage_Paint(object sender, PaintEventArgs e)
+ /// <summary>
+ /// 琛ㄦ牸鍒濆鍖�
+ /// </summary>
+ private void InitializeDataGridView()
{
- uiFlowLayoutPanel1.Controls.Clear();
+ // 璁剧疆DataGridView鍒楀
+ dataGridViewUM.ColumnCount = 4;
+
+ int totalWidth = dataGridViewUM.ClientSize.Width;
+ int columnCount = dataGridViewUM.ColumnCount;
+ int columnWidth = totalWidth / columnCount;
+
+ // 璁剧疆鏈�灏忓搴�
+ int minWidth = 100; // 鏈�灏忓搴�
+ if (columnWidth < minWidth)
+ {
+ columnWidth = minWidth;
+ }
+
+ for (int i = 0; i < columnCount; i++)
+ {
+ dataGridViewUM.Columns[i].Width = columnWidth;
+ }
+
+ // 璁剧疆鍒楁爣棰�
+ dataGridViewUM.Columns[0].Name = "鐢ㄦ埛鍚�";
+ //dataGridViewUM.Columns[1].Name = "瀵嗙爜";
+ dataGridViewUM.Columns[1].Name = "濮撳悕";
+ dataGridViewUM.Columns[2].Name = "宸ュ彿";
+ dataGridViewUM.Columns[3].Name = "鏉冮檺";
+
+ dataGridViewUM.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
+
+ // 绂佹缂栬緫鍗曞厓鏍硷紙鍙�夛級
+ dataGridViewUM.ReadOnly = true;
+
+ // 鍏佽澶氳閫夋嫨锛堝彲閫夛級
+ dataGridViewUM.MultiSelect = false;
+
+ // 鏄剧ず琛屾爣棰橈紙鍙�夛級
+ dataGridViewUM.RowHeadersVisible = true;
}
-
+ /// <summary>
+ /// 鏉冮檺涓嬫媺妗嗗垵濮嬪寲
+ /// </summary>
+ private void InitializeComboBox()
+ {
+ // 娣诲姞鏉冮檺閫夐」
+ foreach (var item in Enum.GetValues(typeof(UserPermission)))
+ {
+ comboBoxPermission.Items.Add(item.ToString());
+ }
+ //comboBoxPermission.Items.Add("鎿嶄綔鍛�");
+
+ // 璁剧疆榛樿閫夋嫨椤�
+ comboBoxPermission.SelectedIndex = 0;
+ }
+
+ private void ClearInputFields()
+ {
+ textBoxUsername.Clear();
+ textBoxPassword.Clear();
+ textBoxName.Clear();
+ textBoxEmployeeID.Clear();
+ comboBoxPermission.SelectedIndex = 0;
+ textBoxUsername.Focus(); // 灏嗙劍鐐硅缃洖鐢ㄦ埛鍚嶈緭鍏ユ
+ }
+ private void btnAdd_Click(object sender, EventArgs e)
+ {
+ // 楠岃瘉杈撳叆
+ if (string.IsNullOrWhiteSpace(textBoxUsername.Text) ||
+ string.IsNullOrWhiteSpace(textBoxPassword.Text) ||
+ string.IsNullOrWhiteSpace(textBoxName.Text) ||
+ string.IsNullOrWhiteSpace(textBoxEmployeeID.Text))
+ {
+ MessageBox.Show("璇峰~鍐欐墍鏈夊繀濉瓧娈碉紒", "鎻愮ず",
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return;
+ }
+
+ // 鍒涘缓鏂拌鏁版嵁
+ string[] row = new string[]
+ {
+ textBoxUsername.Text,
+ //textBoxPassword.Text, // 瀹為檯搴旂敤涓瘑鐮佸簲璇ュ姞瀵�
+ textBoxName.Text,
+ textBoxEmployeeID.Text,
+ comboBoxPermission.SelectedItem.ToString()
+ };
+
+ // 璁剧疆鏁翠釜DataGridView鐨勯粯璁ゅ瓧浣撳拰棰滆壊
+ dataGridViewUM.DefaultCellStyle.Font = new Font("瀹嬩綋", 12);
+ dataGridViewUM.DefaultCellStyle.ForeColor = Color.Black; // 瀛椾綋棰滆壊
+ dataGridViewUM.DefaultCellStyle.BackColor = Color.White; // 鑳屾櫙棰滆壊
+
+ // 娣诲姞鏂拌鍒癉ataGridView
+ dataGridViewUM.Rows.Add(row);
+
+ // 娓呯┖杈撳叆妗�
+ ClearInputFields();
+ }
+
+ private void btnDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridViewUM.SelectedRows.Count > 0)
+ {
+ // 纭鍒犻櫎
+ DialogResult result = MessageBox.Show("纭畾瑕佸垹闄ら�変腑鐨勮鍚楋紵",
+ "纭鍒犻櫎", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+
+ if (result == DialogResult.Yes)
+ {
+ foreach (DataGridViewRow row in dataGridViewUM.SelectedRows)
+ {
+ dataGridViewUM.Rows.Remove(row);
+ }
+ }
+ }
+ else
+ {
+ MessageBox.Show("璇峰厛閫夋嫨瑕佸垹闄ょ殑琛岋紒", "鎻愮ず",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
+ private int editingRowIndex = -1;
+ private bool isEditingMode = false;
+ private string originalButtonText = "淇敼";
+ private void btnEdit_Click(object sender, EventArgs e)
+ {
+ // 鍗曞厓鏍煎彲缂栬緫
+ //dataGridViewUM.ReadOnly = false;
+ // 绗竴娆$偣鍑伙細杩涘叆淇敼妯″紡
+ if (!isEditingMode)
+ {
+ // 妫�鏌ユ槸鍚﹂�夋嫨浜嗚
+ if (dataGridViewUM.SelectedRows.Count == 0)
+ {
+ MessageBox.Show("璇峰厛閫夋嫨瑕佷慨鏀圭殑琛岋紒", "鎻愮ず",
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return;
+ }
+
+ // 鑾峰彇閫変腑鐨勮绱㈠紩
+ editingRowIndex = dataGridViewUM.SelectedRows[0].Index;
+
+ // 灏嗛�変腑琛岀殑鏁版嵁濉厖鍒癟extBox涓�
+ FillFormWithRowData(editingRowIndex);
+
+ // 鏇存敼鎸夐挳鏂囨湰
+ btnEdit.Text = "瀹屾垚";
+
+ // 杩涘叆缂栬緫妯″紡
+ isEditingMode = true;
+
+ // 绂佺敤娣诲姞鎸夐挳锛堝彲閫夛級
+ btnAdd.Enabled = false;
+
+ // 璁剧疆鐒︾偣鍒扮敤鎴峰悕杈撳叆妗�
+ textBoxUsername.Focus();
+
+ // 楂樹寒鏄剧ず姝e湪缂栬緫鐨勮锛堝彲閫夛級
+ dataGridViewUM.Rows[editingRowIndex].DefaultCellStyle.BackColor = Color.LightYellow;
+ }
+ // 绗簩娆$偣鍑伙細淇濆瓨淇敼
+ else
+ {
+ // 楠岃瘉杈撳叆
+ if (string.IsNullOrWhiteSpace(textBoxUsername.Text) ||
+ string.IsNullOrWhiteSpace(textBoxName.Text) ||
+ string.IsNullOrWhiteSpace(textBoxEmployeeID.Text))
+ {
+ MessageBox.Show("璇峰~鍐欐墍鏈夊繀濉瓧娈碉紒", "鎻愮ず",
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return;
+ }
+
+ // 鏇存柊DataGridView涓殑琛屾暟鎹�
+ UpdateRowData(editingRowIndex);
+
+ // 鎭㈠鎸夐挳鏂囨湰
+ btnEdit.Text = originalButtonText;
+
+ // 閫�鍑虹紪杈戞ā寮�
+ isEditingMode = false;
+ editingRowIndex = -1;
+
+ // 鍚敤娣诲姞鎸夐挳锛堝彲閫夛級
+ btnAdd.Enabled = true;
+
+ // 鎭㈠琛岄鑹诧紙鍙�夛級
+ dataGridViewUM.DefaultCellStyle.BackColor = Color.White;
+
+ // 娓呯┖杈撳叆妗�
+ ClearInputFields();
+
+ MessageBox.Show("淇敼瀹屾垚锛�", "鎻愮ず",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
+
+ private void FillFormWithRowData(int rowIndex)
+ {
+ if (rowIndex >= 0 && rowIndex < dataGridViewUM.Rows.Count)
+ {
+ DataGridViewRow row = dataGridViewUM.Rows[rowIndex];
+
+ // 濉厖鐢ㄦ埛鍚�
+ if (row.Cells[0].Value != null)
+ textBoxUsername.Text = row.Cells[0].Value.ToString();
+ else
+ textBoxUsername.Text = "";
+
+ // 濉厖濮撳悕
+ if (row.Cells[1].Value != null)
+ textBoxName.Text = row.Cells[1].Value.ToString();
+ else
+ textBoxName.Text = "";
+
+ // 濉厖宸ュ彿
+ if (row.Cells[2].Value != null)
+ textBoxEmployeeID.Text = row.Cells[2].Value.ToString();
+ else
+ textBoxEmployeeID.Text = "";
+
+ // 濉厖鏉冮檺
+ if (row.Cells[3].Value != null)
+ {
+ string permission = row.Cells[3].Value.ToString();
+ int index = comboBoxPermission.FindString(permission);
+ if (index >= 0)
+ comboBoxPermission.SelectedIndex = index;
+ else
+ comboBoxPermission.SelectedIndex = 0;
+ }
+ else
+ {
+ comboBoxPermission.SelectedIndex = 0;
+ }
+
+ // 瀵嗙爜妗嗘竻绌猴紙閫氬父涓嶄細鏄剧ず瀵嗙爜锛�
+ textBoxPassword.Clear();
+ // 濡傛灉闇�瑕佷慨鏀瑰瘑鐮侊紝鍙互娣诲姞娉ㄩ噴鎴栧崰浣嶇
+ //textBoxPassword.PlaceholderText = "濡傞渶淇敼瀵嗙爜璇峰~鍐�";
+ }
+ }
+
+ private void UpdateRowData(int rowIndex)
+ {
+ if (rowIndex >= 0 && rowIndex < dataGridViewUM.Rows.Count)
+ {
+ DataGridViewRow row = dataGridViewUM.Rows[rowIndex];
+
+ // 鏇存柊鐢ㄦ埛鍚�
+ row.Cells[0].Value = textBoxUsername.Text;
+
+ // 濡傛灉瀵嗙爜涓嶄负绌猴紝鍒欐洿鏂板瘑鐮侊紙瀹為檯搴旂敤涓簲鍔犲瘑锛�
+ if (!string.IsNullOrWhiteSpace(textBoxPassword.Text))
+ {
+ // 杩欓噷鍙互娣诲姞瀵嗙爜鍔犲瘑閫昏緫
+ // row.Cells[1].Value = EncryptPassword(textBoxPassword.Text);
+ }
+
+ // 鏇存柊濮撳悕
+ row.Cells[1].Value = textBoxName.Text;
+
+ // 鏇存柊宸ュ彿
+ row.Cells[2].Value = textBoxEmployeeID.Text;
+
+ // 鏇存柊鏉冮檺
+ row.Cells[3].Value = comboBoxPermission.SelectedItem.ToString();
+ }
+ }
}
}
--
Gitblit v1.9.3