From 0468353b5e2265935846b299afc38bb34ae23e24 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期一, 19 一月 2026 16:49:49 +0800
Subject: [PATCH] 完善运动控制参数存储以及加载
---
LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs | 331 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 321 insertions(+), 10 deletions(-)
diff --git a/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs b/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
index 2df8923..3c7371d 100644
--- a/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
+++ b/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
@@ -1,30 +1,341 @@
-锘縰sing LB_VisionControl;
-using OpenCvSharp.Flann;
-using System;
+锘縰sing LB_SmartVision.Forms.Pages.CameraPage;
+using LB_SmartVision.Forms.Pages.ProcessPage;
+using LB_SmartVision.Forms.Pages.SettingPage;
+using LB_SmartVision.ProcessRun;
+using LB_SmartVision.SQL;
+using LB_SmartVisionCommon;
+using LB_VisionControl;
+using LB_VisionProcesses;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
using System.Collections.Concurrent;
+using System.Data;
+using System.Security.Principal;
+using System.Text;
using System.Windows.Forms;
-using System.Xml.Linq;
+using VisionControl.Forms;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace LB_SmartVision.Forms.Pages.UserManagementPage
{
public partial class UserManagementEditPage : UserControl
{
public Action<string, LogInfoType> LogInfo;
-
+ List<RecordUserData> recordUserDatas = new List<RecordUserData>();
public UserManagementEditPage()
{
- InitializeComponent();
-
Name = "UserManagementEditPage";
Text = "鐢ㄦ埛绠$悊璁剧疆";
+
+ InitializeComponent();
+ InitializeComboBox();
+ InitializeDataGridView();
+
}
- private void MESEditPage_Paint(object sender, PaintEventArgs e)
+ /// <summary>
+ /// 琛ㄦ牸鍒濆鍖�
+ /// </summary>
+ private void InitializeDataGridView()
{
- uiFlowLayoutPanel1.Controls.Clear();
+ this.dataGridViewUM.DataSource = recordUserDatas;
+ // 璁剧疆DataGridView鍒楀
+ dataGridViewUM.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
}
-
+ /// <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(); // 灏嗙劍鐐硅缃洖鐢ㄦ埛鍚嶈緭鍏ユ
+ }
+
+ #region 娣诲姞鐢ㄦ埛鎸夐挳
+ 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;
+ }
+
+ RecordUserData user = new RecordUserData();
+ user.EmployeeNumber = this.textBoxEmployeeID.Text;
+ user.EmployeeAccount = this.textBoxUsername.Text;
+ user.EmployeePassword = this.textBoxPassword.Text;
+ user.EmployeeName = this.textBoxName.Text;
+ user.EmployeePermission = (UserPermission)this.comboBoxPermission.SelectedIndex;
+ // 娣诲姞鍒� UserManager
+ bool success = UserManager.Instance.AddUser(user);
+
+ if (success)
+ {
+ recordUserDatas.Add(user);
+
+ //MessageBox.Show("鐢ㄦ埛娣诲姞鎴愬姛锛�", "鎻愮ず",
+ // MessageBoxButtons.OK, MessageBoxIcon.Information);
+
+ // 娓呯┖杈撳叆妗�
+ ClearInputFields();
+ }
+ else
+ {
+ MessageBox.Show("娣诲姞鐢ㄦ埛澶辫触锛�", "閿欒",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ }
+ #endregion
+
+ #region 鍒犻櫎鐢ㄦ埛鎸夐挳
+ private void btnDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridViewUM.SelectedRows.Count > 0)
+ {
+ // 鑾峰彇閫変腑鐨勮
+ DataGridViewRow selectedRow = dataGridViewUM.SelectedRows[0];
+
+ // 纭鍒犻櫎
+ DialogResult result = MessageBox.Show("纭畾瑕佸垹闄ら�変腑鐨勮鍚楋紵",
+ "纭鍒犻櫎", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+
+ if (result == DialogResult.Yes)
+ {
+ try
+ {
+ // 鍏堣幏鍙栬鍒犻櫎鐨勬暟鎹�
+ string employeeNumber = selectedRow.Cells[0].Value?.ToString();
+
+ if (!string.IsNullOrEmpty(employeeNumber))
+ {
+ // 1. 浠庢暟鎹簮鍒犻櫎
+ var dataSource = dataGridViewUM.DataSource as List<RecordUserData>;
+ if (dataSource != null)
+ {
+ var itemToRemove = dataSource.FirstOrDefault(u => u.EmployeeNumber == employeeNumber);
+ if (itemToRemove != null)
+ {
+ dataSource.Remove(itemToRemove);
+ }
+ }
+
+ // 2. 浠庣敤鎴风鐞嗗櫒鍒犻櫎
+ UserManager.Instance.DeleteUser(employeeNumber);
+
+ // 3. 鍒锋柊鏁版嵁缁戝畾
+ dataGridViewUM.DataSource = null;
+ dataGridViewUM.DataSource = dataSource;
+
+ //MessageBox.Show("鍒犻櫎鎴愬姛锛�", "鎻愮ず",
+ // MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"鍒犻櫎澶辫触: {ex.Message}", "閿欒",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ else
+ {
+ MessageBox.Show("璇峰厛閫夋嫨瑕佸垹闄ょ殑琛岋紒", "鎻愮ず",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
+ #endregion
+ private int editingRowIndex = -1;
+ private bool isEditingMode = false;
+ private string originalButtonText = "淇敼";
+ #region 淇敼鐢ㄦ埛淇℃伅
+ 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();
+
+ RecordUserData user = new RecordUserData();
+ user.EmployeeNumber = this.textBoxEmployeeID.Text;
+ user.EmployeeAccount = this.textBoxUsername.Text;
+ user.EmployeePassword = this.textBoxPassword.Text;
+ user.EmployeeName = this.textBoxName.Text;
+ user.EmployeePermission = (UserPermission)this.comboBoxPermission.SelectedIndex;
+ UserManager.Instance.UpdateUser(user);
+
+ //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();
+ }
+ }
+ #endregion
+
+
+ #region 鏌ヨ鐢ㄦ埛淇℃伅
+ private void btnFind_Click(object sender, EventArgs e)
+ {
+ List<RecordUserData> recordUserDatas = UserManager.Instance.GetAllUsers();
+ this.dataGridViewUM.DataSource = recordUserDatas;
+ this.dataGridViewUM.AutoGenerateColumns = true;
+ }
+ #endregion
+
}
}
--
Gitblit v1.9.3