From c48b29f9997cd8985ab898c1979b8194e4119c76 Mon Sep 17 00:00:00 2001
From: C3032 <C3032@BC3032>
Date: 星期二, 13 一月 2026 08:49:16 +0800
Subject: [PATCH] 在UserManagementEditPage.cs界面为修改按钮添加了指令,实现用户信息的修改 在HistoricalDataEditPage.cs界面为导出按钮添加了指令,还未完成
---
LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 159 insertions(+), 7 deletions(-)
diff --git a/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs b/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
index 10d745d..f017dce 100644
--- a/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
+++ b/LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.cs
@@ -31,10 +31,13 @@
InitializeComboBox();
}
+ /// <summary>
+ /// 琛ㄦ牸鍒濆鍖�
+ /// </summary>
private void InitializeDataGridView()
{
// 璁剧疆DataGridView鍒楀
- dataGridViewUM.ColumnCount = 5;
+ dataGridViewUM.ColumnCount = 4;
int totalWidth = dataGridViewUM.ClientSize.Width;
int columnCount = dataGridViewUM.ColumnCount;
@@ -54,10 +57,10 @@
// 璁剧疆鍒楁爣棰�
dataGridViewUM.Columns[0].Name = "鐢ㄦ埛鍚�";
- dataGridViewUM.Columns[1].Name = "瀵嗙爜";
- dataGridViewUM.Columns[2].Name = "濮撳悕";
- dataGridViewUM.Columns[3].Name = "宸ュ彿";
- dataGridViewUM.Columns[4].Name = "鏉冮檺";
+ //dataGridViewUM.Columns[1].Name = "瀵嗙爜";
+ dataGridViewUM.Columns[1].Name = "濮撳悕";
+ dataGridViewUM.Columns[2].Name = "宸ュ彿";
+ dataGridViewUM.Columns[3].Name = "鏉冮檺";
dataGridViewUM.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
@@ -71,6 +74,9 @@
dataGridViewUM.RowHeadersVisible = true;
}
+ /// <summary>
+ /// 鏉冮檺涓嬫媺妗嗗垵濮嬪寲
+ /// </summary>
private void InitializeComboBox()
{
// 娣诲姞鏉冮檺閫夐」
@@ -90,7 +96,7 @@
textBoxPassword.Clear();
textBoxName.Clear();
textBoxEmployeeID.Clear();
- comboBoxPermission.SelectedIndex = 1;
+ comboBoxPermission.SelectedIndex = 0;
textBoxUsername.Focus(); // 灏嗙劍鐐硅缃洖鐢ㄦ埛鍚嶈緭鍏ユ
}
private void btnAdd_Click(object sender, EventArgs e)
@@ -110,7 +116,7 @@
string[] row = new string[]
{
textBoxUsername.Text,
- textBoxPassword.Text, // 瀹為檯搴旂敤涓瘑鐮佸簲璇ュ姞瀵�
+ //textBoxPassword.Text, // 瀹為檯搴旂敤涓瘑鐮佸簲璇ュ姞瀵�
textBoxName.Text,
textBoxEmployeeID.Text,
comboBoxPermission.SelectedItem.ToString()
@@ -150,7 +156,153 @@
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