LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.Designer.cs
@@ -46,8 +46,8 @@ labelStartTime = new Label(); dataGridViewHD = new DataGridView(); tableLayoutPanel4 = new TableLayoutPanel(); hopeButton1 = new ReaLTaiizor.Controls.HopeButton(); hopeButton2 = new ReaLTaiizor.Controls.HopeButton(); btnHisDataFind = new ReaLTaiizor.Controls.HopeButton(); btnHisDataExport = new ReaLTaiizor.Controls.HopeButton(); grpHisData.SuspendLayout(); tableLayoutPanel1.SuspendLayout(); tableLayoutPanel2.SuspendLayout(); @@ -285,8 +285,8 @@ tableLayoutPanel4.ColumnCount = 2; tableLayoutPanel4.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); tableLayoutPanel4.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); tableLayoutPanel4.Controls.Add(hopeButton1, 0, 0); tableLayoutPanel4.Controls.Add(hopeButton2, 1, 0); tableLayoutPanel4.Controls.Add(btnHisDataFind, 0, 0); tableLayoutPanel4.Controls.Add(btnHisDataExport, 1, 0); tableLayoutPanel4.Location = new Point(657, 509); tableLayoutPanel4.Name = "tableLayoutPanel4"; tableLayoutPanel4.RowCount = 1; @@ -294,43 +294,44 @@ tableLayoutPanel4.Size = new Size(200, 39); tableLayoutPanel4.TabIndex = 1; // // hopeButton1 // btnHisDataFind // hopeButton1.BorderColor = Color.FromArgb(220, 223, 230); hopeButton1.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary; hopeButton1.DangerColor = Color.FromArgb(245, 108, 108); hopeButton1.DefaultColor = Color.FromArgb(255, 255, 255); hopeButton1.Font = new Font("Segoe UI", 12F); hopeButton1.HoverTextColor = Color.FromArgb(48, 49, 51); hopeButton1.InfoColor = Color.FromArgb(144, 147, 153); hopeButton1.Location = new Point(3, 3); hopeButton1.Name = "hopeButton1"; hopeButton1.PrimaryColor = Color.FromArgb(64, 158, 255); hopeButton1.Size = new Size(94, 33); hopeButton1.SuccessColor = Color.FromArgb(103, 194, 58); hopeButton1.TabIndex = 0; hopeButton1.Text = "查询"; hopeButton1.TextColor = Color.White; hopeButton1.WarningColor = Color.FromArgb(230, 162, 60); btnHisDataFind.BorderColor = Color.FromArgb(220, 223, 230); btnHisDataFind.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary; btnHisDataFind.DangerColor = Color.FromArgb(245, 108, 108); btnHisDataFind.DefaultColor = Color.FromArgb(255, 255, 255); btnHisDataFind.Font = new Font("Segoe UI", 12F); btnHisDataFind.HoverTextColor = Color.FromArgb(48, 49, 51); btnHisDataFind.InfoColor = Color.FromArgb(144, 147, 153); btnHisDataFind.Location = new Point(3, 3); btnHisDataFind.Name = "btnHisDataFind"; btnHisDataFind.PrimaryColor = Color.FromArgb(64, 158, 255); btnHisDataFind.Size = new Size(94, 33); btnHisDataFind.SuccessColor = Color.FromArgb(103, 194, 58); btnHisDataFind.TabIndex = 0; btnHisDataFind.Text = "查询"; btnHisDataFind.TextColor = Color.White; btnHisDataFind.WarningColor = Color.FromArgb(230, 162, 60); // // hopeButton2 // btnHisDataExport // hopeButton2.BorderColor = Color.FromArgb(220, 223, 230); hopeButton2.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary; hopeButton2.DangerColor = Color.FromArgb(245, 108, 108); hopeButton2.DefaultColor = Color.FromArgb(255, 255, 255); hopeButton2.Font = new Font("Segoe UI", 12F); hopeButton2.HoverTextColor = Color.FromArgb(48, 49, 51); hopeButton2.InfoColor = Color.FromArgb(144, 147, 153); hopeButton2.Location = new Point(103, 3); hopeButton2.Name = "hopeButton2"; hopeButton2.PrimaryColor = Color.FromArgb(64, 158, 255); hopeButton2.Size = new Size(94, 33); hopeButton2.SuccessColor = Color.FromArgb(103, 194, 58); hopeButton2.TabIndex = 1; hopeButton2.Text = "导出"; hopeButton2.TextColor = Color.White; hopeButton2.WarningColor = Color.FromArgb(230, 162, 60); btnHisDataExport.BorderColor = Color.FromArgb(220, 223, 230); btnHisDataExport.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary; btnHisDataExport.DangerColor = Color.FromArgb(245, 108, 108); btnHisDataExport.DefaultColor = Color.FromArgb(255, 255, 255); btnHisDataExport.Font = new Font("Segoe UI", 12F); btnHisDataExport.HoverTextColor = Color.FromArgb(48, 49, 51); btnHisDataExport.InfoColor = Color.FromArgb(144, 147, 153); btnHisDataExport.Location = new Point(103, 3); btnHisDataExport.Name = "btnHisDataExport"; btnHisDataExport.PrimaryColor = Color.FromArgb(64, 158, 255); btnHisDataExport.Size = new Size(94, 33); btnHisDataExport.SuccessColor = Color.FromArgb(103, 194, 58); btnHisDataExport.TabIndex = 1; btnHisDataExport.Text = "导出"; btnHisDataExport.TextColor = Color.White; btnHisDataExport.WarningColor = Color.FromArgb(230, 162, 60); btnHisDataExport.Click += btnHisDataExport_Click; // // HistoricalDataEditPage // @@ -363,8 +364,8 @@ private TableLayoutPanel tableLayoutPanel3; private DataGridView dataGridViewHD; private TableLayoutPanel tableLayoutPanel4; private ReaLTaiizor.Controls.HopeButton hopeButton1; private ReaLTaiizor.Controls.HopeButton hopeButton2; private ReaLTaiizor.Controls.HopeButton btnHisDataFind; private ReaLTaiizor.Controls.HopeButton btnHisDataExport; private TableLayoutPanel tableLayoutPanel5; private Label labelSearchBasis; private TableLayoutPanel tableLayoutPanelSN; LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.cs
@@ -57,7 +57,7 @@ } // 设置列标题 dataGridViewHD.Columns[0].Name = "SN号"; dataGridViewHD.Columns[0].Name = "SN号"; dataGridViewHD.Columns[1].Name = "时间"; dataGridViewHD.Columns[2].Name = "NG类"; dataGridViewHD.Columns[3].Name = "缺陷大小"; @@ -151,5 +151,45 @@ { dateTimePickerEnd.MinDate = dateTimePickerStart.Value; } private void btnHisDataExport_Click(object sender, EventArgs e) { } public void SaveToCSV(string filePath, int rowIndex) { // 使用 StreamWriter 来写入文件 using (StreamWriter writer = new StreamWriter(filePath)) { DataGridViewRow row = dataGridViewHD.Rows[rowIndex]; int rowCount = 10;//10改为采集次数 writer.WriteLine("SN号, 时间, NG类, 缺陷大小"); // 遍历每一行数据 for (int i = 0; i < rowCount; i++) { int batchSize = 4; // 写入这一批次的每一列数据 for (int k = 0; k < batchSize; k++) { writer.Write($"{row.Cells[k].Value}"); // 在元素之间添加逗号,除非这是最后一个元素 if (k < batchSize - 1) { writer.Write(","); } } // 写入完一行后,换行 writer.WriteLine(); } } } } } LB_SmartVision/Forms/Pages/UserManagementPage/UserManagementEditPage.Designer.cs
@@ -283,6 +283,7 @@ btnEdit.Text = "修改"; btnEdit.TextColor = Color.White; btnEdit.WarningColor = Color.FromArgb(230, 162, 60); btnEdit.Click += btnEdit_Click; // // btnFind // 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; // 将选中行的数据填充到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(); 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(); } } } }