轮胎外观检测添加思谋语义分割模型检测工具
C3204
2026-03-30 06c627ec032b3f3876fd7db8a3ff0ff1a6614fa2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
using LB_SmartVision.Forms.Pages.SettingPage;
using LB_SmartVision.SQL;
using LB_SmartVisionCommon;
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 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()
        {
            Name = "UserManagementEditPage";
            Text = "用户管理设置";
 
            InitializeComponent();
            InitializeComboBox();
            InitializeDataGridView();
        }
 
        /// <summary>
        /// 表格初始化
        /// </summary>
        private void InitializeDataGridView()
        {
            this.dataGridViewUM.DataSource = recordUserDatas;
            // 设置DataGridView列宽
            dataGridViewUM.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridViewUM.ForeColor=Color.Black;
        }
 
        /// <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;
 
                // 将选中行的数据填充到TextBox中
                FillFormWithRowData(editingRowIndex);
 
                // 更改按钮文本
                btnEdit.Text = "完成";
 
                // 进入编辑模式
                isEditingMode = true;
 
                // 禁用添加按钮(可选)
                btnAdd.Enabled = false;
 
                // 设置焦点到用户名输入框
                textBoxUsername.Focus();
 
                // 高亮显示正在编辑的行(可选)
                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
 
    }
}