using RS.BLL; using RS.Common; using RS.Model; using Sunny.UI; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MorClient; using MorClient.UserFrmFrame; using Sunny.UI.Win32; using RS.Module.Common; using System.Diagnostics; namespace MorClient { public partial class ToolUserMent : UserControl { // 当前选中用户 static string user = ""; //默认展示分组 /// /// Operator/Process/Admin /// string userGrouping = "Operator"; UIPage uiPage = new UIPage(); DataGridViewHandle gridHdl = new DataGridViewHandle(); BToolsManageInfo bToolsManageInfo = new BToolsManageInfo(); public ToolUserMent() { InitializeComponent(); LoadDataNew(); GenerateDataGridViewColumns(); } public void set() { if (PublicParams.currUserInfo.userGroup == "Operator") { uiButton6.Enabled = true; uiButton5.Enabled = false; uiButton8.Enabled = false; uiButton1.Enabled = false; uiButton4.Enabled = false; uiButton2.Enabled = false; if (userGrouping != "Operator") { userGrouping = "Operator"; SetHighLiaght(); LoadDataNew(); GenerateDataGridViewColumns(); } } else if (PublicParams.currUserInfo.userGroup == "Process") { uiButton6.Enabled = true; uiButton5.Enabled = true; uiButton8.Enabled = false; if (userGrouping != "Process") { userGrouping = "Process"; SetHighLiaght(); LoadDataNew(); GenerateDataGridViewColumns(); } } else if (PublicParams.currUserInfo.userGroup == "Admin") { uiButton6.Enabled = true; uiButton5.Enabled = true; uiButton8.Enabled = true; if (userGrouping != "Admin") { userGrouping = "Admin"; SetHighLiaght(); LoadDataNew(); GenerateDataGridViewColumns(); } } else if (PublicParams.currUserInfo.userGroup == "OEM") { uiButton6.Enabled = true; uiButton5.Enabled = true; uiButton8.Enabled = true; if (userGrouping != "Operator") { userGrouping = "Operator"; SetHighLiaght(); LoadDataNew(); GenerateDataGridViewColumns(); } } } #region 设置按钮高亮效果 /// /// 设置按钮颜色 /// public void SetHighLiaght() { switch (userGrouping) { case "Operator": uiButton6.FillColor = Color.FromArgb(124, 156, 214); uiButton5.FillColor = Color.FromArgb(199, 213, 237); uiButton8.FillColor = Color.FromArgb(199, 213, 237); break; case "Process": uiButton5.FillColor = Color.FromArgb(124, 156, 214); uiButton6.FillColor = Color.FromArgb(199, 213, 237); uiButton8.FillColor = Color.FromArgb(199, 213, 237); break; case "Admin": uiButton8.FillColor = Color.FromArgb(124, 156, 214); uiButton5.FillColor = Color.FromArgb(199, 213, 237); uiButton6.FillColor = Color.FromArgb(199, 213, 237); break; } } #endregion 设置按钮高亮效果 #region 操作员管理 // 生成DataGridView列 private void GenerateDataGridViewColumns() { if (OperatorInfo.DataSource != null) { if (OperatorInfo.Columns.Count > 0) { OperatorInfo.Columns[0].HeaderText = "用户名"; OperatorInfo.Columns[1].HeaderText = "用户密码"; gridHdl._dbgrid = OperatorInfo; gridHdl.GenerateBaseDataGridView(); } foreach (DataGridViewColumn column in OperatorInfo.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; } } } /// /// 展示工单数据 /// private void LoadDataNew() { try { //展示工单数据表 DataTable dtResult = null; dtResult = bToolsManageInfo.GetUserManageInfo(userGrouping); if (dtResult != null) { OperatorInfo.DataSource = dtResult; } } catch (Exception ex) { ex.ToString(); } } #endregion 操作员管理 #region 用户分组切换 /// /// userGrouping = "Process"; /// /// /// private void uiButton5_Click_1(object sender, EventArgs e) { if (userGrouping != "Process") { userGrouping = "Process"; SetHighLiaght(); LoadDataNew(); GenerateDataGridViewColumns(); } } /// /// userGrouping = "Operate"; /// /// /// private void uiButton6_Click(object sender, EventArgs e) { if (userGrouping != "Operator") { userGrouping = "Operator"; SetHighLiaght(); LoadDataNew(); GenerateDataGridViewColumns(); } } /// /// userGrouping = "Admin"; /// /// /// private void uiButton8_Click(object sender, EventArgs e) { if (userGrouping != "Admin") { userGrouping = "Admin"; SetHighLiaght(); LoadDataNew(); GenerateDataGridViewColumns(); } } #endregion 用户分组切换 #region 操作员按钮 /// /// 新增 /// /// /// private void uiButton1_Click_1(object sender, EventArgs e) { if (PublicParams.currUserInfo.userGroup == "Operator") { MessageBox.Show("权限不足"); return; } string userName = uiTextBox1.Text.Replace(" ", ""); string userPw = uiTextBox2.Text.Replace(" ", ""); if (!string.IsNullOrEmpty(userName)) { if (!string.IsNullOrEmpty(userPw)) { if (PublicParams.currUserInfo.userGroup == "Operator" && PublicParams.currUserInfo.userName == "OP") { } else if (PublicParams.currUserInfo.userGroup == "Process" && PublicParams.currUserInfo.userName == "PRO") { } else if (PublicParams.currUserInfo.userGroup == "Admin" && PublicParams.currUserInfo.userName == "AD") { } else { MessageBox.Show("权限不足"); return; } ToolsUsersManage toolsUsersManage = new ToolsUsersManage(); bool isSuccess = bToolsManageInfo.SelUserNameInfo(uiTextBox1.Text, userGrouping); if (!isSuccess) { toolsUsersManage.userName = userName; toolsUsersManage.userPw = userPw; toolsUsersManage.userGroup = userGrouping; bToolsManageInfo.SaveUserManageInfo(toolsUsersManage); } else { MessageBox.Show("当前用户名已存在"); } } else { MessageBox.Show("新增用户用户密码为空,请重新输入"); } } else { MessageBox.Show("新增用户用户名为空,请重新输入"); } LoadDataNew(); GenerateDataGridViewColumns(); } /// /// 删除 /// /// /// private void uiButton4_Click(object sender, EventArgs e) { if (PublicParams.currUserInfo.userGroup == "Operator") { MessageBox.Show("权限不足"); return; } try { // 获取第一个选定单元格 DataGridViewCell selectedCell = OperatorInfo.SelectedCells[0]; // 获取包含该单元格的行 DataGridViewRow selectedRow = selectedCell.OwningRow; // 获取行索引 int rowIndex = selectedRow.Index; user = OperatorInfo.Rows[rowIndex].Cells[0].Value.ToString().Trim(); } catch { MessageBox.Show("请选择用户"); return; } if (userGrouping == "Operator" && user == "OP") { MessageBox.Show("当前账户不允许被删除"); return; } else if (userGrouping == "Process" && user == "PRO") { MessageBox.Show("当前账户不允许被删除"); return; } else if (userGrouping == "Admin" && user == "AD") { MessageBox.Show("当前账户不允许被删除"); return; } if (PublicParams.currUserInfo.userGroup == "Operator" && PublicParams.currUserInfo.userName == "OP") { } else if (PublicParams.currUserInfo.userGroup == "Process" && PublicParams.currUserInfo.userName == "PRO") { } else if (PublicParams.currUserInfo.userGroup == "Admin" && PublicParams.currUserInfo.userName == "AD") { } else { MessageBox.Show("权限不足"); return; } if (!string.IsNullOrEmpty(user)) { DialogResult dgRst = MessageBox.Show(this, "您确认删除当前选择的客户吗?", "警告", MessageBoxButtons.OKCancel); if (dgRst == DialogResult.OK) { bool bresult = bToolsManageInfo.DeleteUser(user, userGrouping); if (bresult) { uiPage.ShowSuccessDialog("删除成功"); } else { uiPage.ShowErrorDialog("删除失败"); } } } else { MessageBox.Show("请选择要删除的用户"); } user = null; LoadDataNew(); GenerateDataGridViewColumns(); } /// /// 修改 /// /// /// private void uiButton2_Click(object sender, EventArgs e) { if (PublicParams.currUserInfo.userGroup == "Operator") { MessageBox.Show("权限不足"); return; } user = null; try { // 获取第一个选定单元格 DataGridViewCell selectedCell = OperatorInfo.SelectedCells[0]; // 获取包含该单元格的行 DataGridViewRow selectedRow = selectedCell.OwningRow; // 获取行索引 int rowIndex = selectedRow.Index; user = OperatorInfo.Rows[rowIndex].Cells[0].Value.ToString(); } catch { MessageBox.Show("请选择用户"); return; } if (userGrouping == "Operator" && user == "OP") { MessageBox.Show("当前账户不允许更改"); return; } else if (userGrouping == "Process" && user == "PRO") { MessageBox.Show("当前账户不允许更改"); return; } else if (userGrouping == "Admin" && user == "AD") { MessageBox.Show("当前账户不允许更改"); return; } if (PublicParams.currUserInfo.userGroup == "Operator" && PublicParams.currUserInfo.userName == "OP") { } else if (PublicParams.currUserInfo.userGroup == "Process" && PublicParams.currUserInfo.userName == "PRO") { } else if (PublicParams.currUserInfo.userGroup == "Admin" && PublicParams.currUserInfo.userName == "AD") { } else { MessageBox.Show("权限不足"); return; } try { // 获取第一个选定单元格 DataGridViewCell selectedCell = OperatorInfo.SelectedCells[0]; // 获取包含该单元格的行 DataGridViewRow selectedRow = selectedCell.OwningRow; // 获取行索引 int rowIndex = selectedRow.Index; user = OperatorInfo.Rows[rowIndex].Cells[0].Value.ToString().Trim(); if (!string.IsNullOrEmpty(user)) { FrmToolsModifyUserPw frmToolsModifyUserPw = new FrmToolsModifyUserPw(user); frmToolsModifyUserPw.ShowDialog(); if (!string.IsNullOrEmpty(FrmToolsModifyUserPw.Nowpw)) { bool bresult = bToolsManageInfo.ModifyUser(user, FrmToolsModifyUserPw.Nowpw, userGrouping); if (bresult) { uiPage.ShowSuccessDialog("密码更改成功"); } else { uiPage.ShowErrorDialog("密码更改失败"); } } } else { uiPage.ShowAskDialog(String.Format("请先选择用户!")); } } catch { MessageBox.Show("请选择用户"); } user = null; LoadDataNew(); GenerateDataGridViewColumns(); } #endregion 操作员按钮 private void OperatorInfo_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { // 假设我们想要在第一列中隐藏数据,用*代替 if (e.ColumnIndex == 1) // 0是第一列的索引 { // 可以用任何条件来决定是否显示*,这里简单地显示所有单元格为* e.Value = "*"; // 设置单元格的样式为密码样式(可选) e.CellStyle.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))); e.CellStyle.ForeColor = Color.Black; e.CellStyle.BackColor = Color.White; e.FormattingApplied = true; // 表示已手动设置格式 } } private void OperatorInfo_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { OperatorInfo.ClearSelection(); OperatorInfo.Rows[e.RowIndex].Selected = true; if (OperatorInfo.Rows.Count > 0) { user = OperatorInfo.Rows[e.RowIndex].Cells[0].Value.ToString().Trim(); } } } } }