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 | 324 ++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 256 insertions(+), 68 deletions(-)
diff --git a/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs b/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
index 0cd133d..3c7371d 100644
--- a/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
+++ b/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
@@ -1,86 +1,63 @@
-锘縰sing LB_SmartVision.Forms.Pages.ProcessPage;
+锘縰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.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.Text;
using System.Windows.Forms;
+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;
- RunSettingPage RunSettingPage = new RunSettingPage();
- LayoutPage LayoutPage = new LayoutPage();
- CsvPage CsvPage = new CsvPage();
+ List<RecordUserData> recordUserDatas = new List<RecordUserData>();
+
public UserManagementEditPage()
{
- Name = "UserManagementEditPage";
+ Name = "UserManagementEditPage";
Text = "鐢ㄦ埛绠$悊璁剧疆";
InitializeComponent();
- InitializeDataGridView();
InitializeComboBox();
+ InitializeDataGridView();
+
}
+ /// <summary>
+ /// 琛ㄦ牸鍒濆鍖�
+ /// </summary>
private void InitializeDataGridView()
{
+ this.dataGridViewUM.DataSource = recordUserDatas;
// 璁剧疆DataGridView鍒楀
- dataGridViewUM.ColumnCount = 5;
-
- 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[2].Name = "濮撳悕";
- dataGridViewUM.Columns[3].Name = "宸ュ彿";
- dataGridViewUM.Columns[4].Name = "鏉冮檺";
-
dataGridViewUM.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
-
- // 绂佹缂栬緫鍗曞厓鏍硷紙鍙�夛級
- dataGridViewUM.ReadOnly = true;
-
- // 鍏佽澶氳閫夋嫨锛堝彲閫夛級
- dataGridViewUM.MultiSelect = false;
-
- // 鏄剧ず琛屾爣棰橈紙鍙�夛級
- dataGridViewUM.RowHeadersVisible = true;
}
+ /// <summary>
+ /// 鏉冮檺涓嬫媺妗嗗垵濮嬪寲
+ /// </summary>
private void InitializeComboBox()
{
// 娣诲姞鏉冮檺閫夐」
- comboBoxPermission.Items.Add("绠$悊鍛�");
- comboBoxPermission.Items.Add("鎿嶄綔鍛�");
+ foreach (var item in Enum.GetValues(typeof(UserPermission)))
+ {
+ comboBoxPermission.Items.Add(item.ToString());
+ }
+ //comboBoxPermission.Items.Add("鎿嶄綔鍛�");
// 璁剧疆榛樿閫夋嫨椤�
- comboBoxPermission.SelectedIndex = 1;
+ comboBoxPermission.SelectedIndex = 0;
}
private void ClearInputFields()
@@ -89,9 +66,11 @@
textBoxPassword.Clear();
textBoxName.Clear();
textBoxEmployeeID.Clear();
- comboBoxPermission.SelectedIndex = 1;
+ comboBoxPermission.SelectedIndex = 0;
textBoxUsername.Focus(); // 灏嗙劍鐐硅缃洖鐢ㄦ埛鍚嶈緭鍏ユ
}
+
+ #region 娣诲姞鐢ㄦ埛鎸夐挳
private void btnAdd_Click(object sender, EventArgs e)
{
// 楠岃瘉杈撳叆
@@ -105,41 +84,81 @@
return;
}
- // 鍒涘缓鏂拌鏁版嵁
- string[] row = new string[]
+ 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)
{
- textBoxUsername.Text,
- textBoxPassword.Text, // 瀹為檯搴旂敤涓瘑鐮佸簲璇ュ姞瀵�
- textBoxName.Text,
- textBoxEmployeeID.Text,
- comboBoxPermission.SelectedItem.ToString()
- };
+ recordUserDatas.Add(user);
- // 璁剧疆鏁翠釜DataGridView鐨勯粯璁ゅ瓧浣撳拰棰滆壊
- dataGridViewUM.DefaultCellStyle.Font = new Font("瀹嬩綋", 12);
- dataGridViewUM.DefaultCellStyle.ForeColor = Color.Black; // 瀛椾綋棰滆壊
- dataGridViewUM.DefaultCellStyle.BackColor = Color.White; // 鑳屾櫙棰滆壊
+ //MessageBox.Show("鐢ㄦ埛娣诲姞鎴愬姛锛�", "鎻愮ず",
+ // MessageBoxButtons.OK, MessageBoxIcon.Information);
- // 娣诲姞鏂拌鍒癉ataGridView
- dataGridViewUM.Rows.Add(row);
+ // 娓呯┖杈撳叆妗�
+ ClearInputFields();
+ }
+ else
+ {
+ MessageBox.Show("娣诲姞鐢ㄦ埛澶辫触锛�", "閿欒",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
- // 娓呯┖杈撳叆妗�
- ClearInputFields();
}
+ #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)
{
- foreach (DataGridViewRow row in dataGridViewUM.SelectedRows)
+ try
{
- dataGridViewUM.Rows.Remove(row);
+ // 鍏堣幏鍙栬鍒犻櫎鐨勬暟鎹�
+ 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);
}
}
}
@@ -149,5 +168,174 @@
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