From 4a7614183149b4f34258a36fc3c3f3290b968de8 Mon Sep 17 00:00:00 2001 From: SoulStar Date: Tue, 26 Nov 2024 13:56:39 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E8=A7=92=E8=89=B2=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=AE=8C=E6=AF=95=20=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=BE=85=E5=8A=A0=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/SysUserInfoService.cs | 2 +- .../service/SysUserRoleService.cs | 19 ++ HighWayIot.Winform/Business/RoleBusiness.cs | 16 ++ HighWayIot.Winform/HighWayIot.Winform.csproj | 19 +- .../MainForm/BaseForm.Designer.cs | 16 +- HighWayIot.Winform/MainForm/BaseForm.cs | 20 +- HighWayIot.Winform/MainForm/LoginForm.cs | 2 + .../SysConfigPages/RoleAddForm.Designer.cs | 19 +- .../SysConfigPages/RoleAddForm.cs | 46 +++- .../SysConfigPages/RoleConfigPage.Designer.cs | 4 + .../SysConfigPages/RoleConfigPage.cs | 104 +++++++- .../SysConfigPages/RoleUpdateForm.Designer.cs | 71 +++--- .../SysConfigPages/RoleUpdateForm.cs | 129 +++++++++- .../SysConfigPages/UserAddForm.cs | 5 +- .../SysConfigPages/UserConfigPage.Designer.cs | 229 +++++++++--------- .../SysConfigPages/UserConfigPage.cs | 33 ++- .../SysConfigPages/UserConfigPage.resx | 15 ++ .../SysConfigPages/UserUpDateForm.cs | 10 +- 18 files changed, 557 insertions(+), 202 deletions(-) create mode 100644 HighWayIot.Winform/Business/RoleBusiness.cs diff --git a/HighWayIot.Repository/service/SysUserInfoService.cs b/HighWayIot.Repository/service/SysUserInfoService.cs index 8ee6312..1680d3a 100644 --- a/HighWayIot.Repository/service/SysUserInfoService.cs +++ b/HighWayIot.Repository/service/SysUserInfoService.cs @@ -36,7 +36,7 @@ namespace HighWayIot.Repository.service if (!string.IsNullOrEmpty(userRole)) { - deviceInfo = deviceInfo.Where(x => x.UserName == userRole).ToList(); + deviceInfo = deviceInfo.Where(x => x.UserRole == userRole).ToList(); } if (isSelectByTime) diff --git a/HighWayIot.Repository/service/SysUserRoleService.cs b/HighWayIot.Repository/service/SysUserRoleService.cs index f30c2ef..0dcb70a 100644 --- a/HighWayIot.Repository/service/SysUserRoleService.cs +++ b/HighWayIot.Repository/service/SysUserRoleService.cs @@ -34,6 +34,25 @@ namespace HighWayIot.Repository.service } } + /// + /// 查询所有角色列表 + /// + /// + public List GetRoleInfos(string roleName) + { + try + { + List deviceInfo = _repository.GetList(x => x.RoleName == roleName); + + return deviceInfo; + } + catch (Exception ex) + { + log.Error("用户信息获取异常", ex); + return null; + } + } + /// /// 添加角色信息 /// diff --git a/HighWayIot.Winform/Business/RoleBusiness.cs b/HighWayIot.Winform/Business/RoleBusiness.cs new file mode 100644 index 0000000..748530a --- /dev/null +++ b/HighWayIot.Winform/Business/RoleBusiness.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HighWayIot.Winform.Business +{ + public class RoleBusiness + { + /// + /// 当前登录人的姓名 + /// + public static string LoginUserName = string.Empty; + } +} diff --git a/HighWayIot.Winform/HighWayIot.Winform.csproj b/HighWayIot.Winform/HighWayIot.Winform.csproj index 116ad8b..9ca819f 100644 --- a/HighWayIot.Winform/HighWayIot.Winform.csproj +++ b/HighWayIot.Winform/HighWayIot.Winform.csproj @@ -49,6 +49,7 @@ + Form @@ -82,6 +83,12 @@ MonitorMainPage.cs + + Form + + + RoleUpdateForm.cs + UserControl @@ -94,12 +101,6 @@ TestPage.cs - - Form - - - RoleUpdateForm.cs - Form @@ -149,15 +150,15 @@ MonitorMainPage.cs + + RoleUpdateForm.cs + RoleConfigPage.cs TestPage.cs - - RoleUpdateForm.cs - RoleAddForm.cs diff --git a/HighWayIot.Winform/MainForm/BaseForm.Designer.cs b/HighWayIot.Winform/MainForm/BaseForm.Designer.cs index 401907b..0e3dacd 100644 --- a/HighWayIot.Winform/MainForm/BaseForm.Designer.cs +++ b/HighWayIot.Winform/MainForm/BaseForm.Designer.cs @@ -51,7 +51,7 @@ namespace HighWayIot.Winform.MainForm this.HighWayLogo = new System.Windows.Forms.ToolStripStatusLabel(); this.SplitLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.StripLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); - this.UserToolStripLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.NowLoginUserName = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.StripLabel2 = new System.Windows.Forms.ToolStripStatusLabel(); this.TimeStripLabel = new System.Windows.Forms.ToolStripStatusLabel(); @@ -183,7 +183,7 @@ namespace HighWayIot.Winform.MainForm this.HighWayLogo, this.SplitLabel1, this.StripLabel1, - this.UserToolStripLabel, + this.NowLoginUserName, this.toolStripStatusLabel1, this.StripLabel2, this.TimeStripLabel}); @@ -211,17 +211,17 @@ namespace HighWayIot.Winform.MainForm this.StripLabel1.Size = new System.Drawing.Size(80, 17); this.StripLabel1.Text = "当前登录人:"; // - // UserToolStripLabel + // NowLoginUserName // - this.UserToolStripLabel.Name = "UserToolStripLabel"; - this.UserToolStripLabel.Size = new System.Drawing.Size(44, 17); - this.UserToolStripLabel.Text = "admin"; + this.NowLoginUserName.Name = "NowLoginUserName"; + this.NowLoginUserName.Size = new System.Drawing.Size(31, 17); + this.NowLoginUserName.Text = "N/A"; // // toolStripStatusLabel1 // this.toolStripStatusLabel1.BorderSides = ((System.Windows.Forms.ToolStripStatusLabelBorderSides)((System.Windows.Forms.ToolStripStatusLabelBorderSides.Left | System.Windows.Forms.ToolStripStatusLabelBorderSides.Right))); this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; - this.toolStripStatusLabel1.Size = new System.Drawing.Size(1144, 17); + this.toolStripStatusLabel1.Size = new System.Drawing.Size(1157, 17); this.toolStripStatusLabel1.Spring = true; // // StripLabel2 @@ -282,7 +282,7 @@ namespace HighWayIot.Winform.MainForm private ToolStripStatusLabel HighWayLogo; private ToolStripStatusLabel StripLabel1; private ToolStripStatusLabel SplitLabel1; - private ToolStripStatusLabel UserToolStripLabel; + private ToolStripStatusLabel NowLoginUserName; private ToolStripStatusLabel toolStripStatusLabel1; private ToolStripStatusLabel StripLabel2; private ToolStripStatusLabel TimeStripLabel; diff --git a/HighWayIot.Winform/MainForm/BaseForm.cs b/HighWayIot.Winform/MainForm/BaseForm.cs index 1939412..7d160a7 100644 --- a/HighWayIot.Winform/MainForm/BaseForm.cs +++ b/HighWayIot.Winform/MainForm/BaseForm.cs @@ -1,4 +1,5 @@ using HighWayIot.Log4net; +using HighWayIot.Winform.Business; using HighWayIot.Winform.UserControlPages; using HighWayIot.Winform.UserControlPages.SysConfigPages; using System; @@ -32,8 +33,9 @@ namespace HighWayIot.Winform.MainForm public void Init() { logger.Info("主页面已启动"); - UserPanelSwitch(typeof(MonitorMainPage), "监控主页面"); TimeDisplayTimer.Start(); + NowLoginUserName.Text = RoleBusiness.LoginUserName; + UserPanelSwitch(typeof(MonitorMainPage), "监控主页面"); } /// @@ -105,9 +107,9 @@ namespace HighWayIot.Winform.MainForm private void UserPanelSwitch(Type userControlType, string tag) { bool flag = false; - foreach(UserControl us in UserControls) + foreach (UserControl us in UserControls) { - if(us.GetType() == userControlType) + if (us.GetType() == userControlType) { flag = true; //如果在标签页里,切换选项卡 @@ -115,22 +117,22 @@ namespace HighWayIot.Winform.MainForm { try { - foreach(Control control in this.UserControlTabs.Controls) + foreach (Control control in this.UserControlTabs.Controls) { - if(control is TabPage page) + if (control is TabPage page) { - if(page.Text == tag) + if (page.Text == tag) { UserControlTabs.SelectedTab = page; } } } } - catch(ArgumentNullException ex) + catch (ArgumentNullException ex) { logger.Error("找不到相关标签页!请重启程序!", ex); } - catch(Exception ex) + catch (Exception ex) { logger.Error("标签页未知错误!", ex); } @@ -156,7 +158,7 @@ namespace HighWayIot.Winform.MainForm newControl.Tag = tag; UserControls.Add(newControl); // 将新实例添加到列表 TabPage tabPage = new TabPage(tag); - + newControl.Parent = tabPage; newControl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; newControl.Dock = DockStyle.Fill; diff --git a/HighWayIot.Winform/MainForm/LoginForm.cs b/HighWayIot.Winform/MainForm/LoginForm.cs index c15ca34..0a45897 100644 --- a/HighWayIot.Winform/MainForm/LoginForm.cs +++ b/HighWayIot.Winform/MainForm/LoginForm.cs @@ -1,5 +1,6 @@ using HighWayIot.Repository.domain; using HighWayIot.Repository.service; +using HighWayIot.Winform.Business; using System; using System.Collections.Generic; using System.ComponentModel; @@ -34,6 +35,7 @@ namespace HighWayIot.Winform.MainForm if (lists.Count == 1 && lists.First().Password == PassText.Text) { lists.First().LastLoginTime = DateTime.Now; + RoleBusiness.LoginUserName = UserText.Text; sysUserInfoService.UpdateUserInfo(lists.First()); DialogResult = DialogResult.OK; this.Close(); diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleAddForm.Designer.cs b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleAddForm.Designer.cs index e6bb325..3e54fa2 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleAddForm.Designer.cs +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleAddForm.Designer.cs @@ -29,7 +29,7 @@ private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); - this.UserNameTextBox = new System.Windows.Forms.TextBox(); + this.RoleNameTextBox = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.ConfrimAddButton = new System.Windows.Forms.Button(); this.panel1 = new System.Windows.Forms.Panel(); @@ -55,12 +55,12 @@ this.label1.Size = new System.Drawing.Size(0, 12); this.label1.TabIndex = 0; // - // UserNameTextBox + // RoleNameTextBox // - this.UserNameTextBox.Location = new System.Drawing.Point(216, 23); - this.UserNameTextBox.Name = "UserNameTextBox"; - this.UserNameTextBox.Size = new System.Drawing.Size(136, 21); - this.UserNameTextBox.TabIndex = 1; + this.RoleNameTextBox.Location = new System.Drawing.Point(216, 23); + this.RoleNameTextBox.Name = "RoleNameTextBox"; + this.RoleNameTextBox.Size = new System.Drawing.Size(136, 21); + this.RoleNameTextBox.TabIndex = 1; // // label2 // @@ -87,7 +87,7 @@ | System.Windows.Forms.AnchorStyles.Right))); this.panel1.Controls.Add(this.ConfrimAddButton); this.panel1.Controls.Add(this.label2); - this.panel1.Controls.Add(this.UserNameTextBox); + this.panel1.Controls.Add(this.RoleNameTextBox); this.panel1.Controls.Add(this.label1); this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; @@ -150,8 +150,8 @@ this.IsUseable}); this.RolesDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.RolesDataGridView.Location = new System.Drawing.Point(0, 0); + this.RolesDataGridView.MultiSelect = false; this.RolesDataGridView.Name = "RolesDataGridView"; - this.RolesDataGridView.ReadOnly = true; this.RolesDataGridView.RowHeadersVisible = false; this.RolesDataGridView.RowTemplate.Height = 23; this.RolesDataGridView.Size = new System.Drawing.Size(392, 541); @@ -170,6 +170,7 @@ this.IsUseable.DataPropertyName = "IsUseable"; this.IsUseable.HeaderText = "是否有权限"; this.IsUseable.Name = "IsUseable"; + this.IsUseable.ReadOnly = false; this.IsUseable.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.IsUseable.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; this.IsUseable.Width = 90; @@ -196,7 +197,7 @@ #endregion private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox UserNameTextBox; + private System.Windows.Forms.TextBox RoleNameTextBox; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button ConfrimAddButton; private System.Windows.Forms.Panel panel1; diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleAddForm.cs b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleAddForm.cs index 34a7512..6c33dce 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleAddForm.cs +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleAddForm.cs @@ -60,13 +60,7 @@ namespace HighWayIot.Winform.UserControlPages.SysConfigPages dt.Columns.Add("TableName", typeof(string)); dt.Columns.Add("IsUseable", typeof(bool)); - foreach (var config in ConfigList) - { - dt.Rows.Add(config.PageName, true); - } - - RolesDataGridView.DataSource = null; - RolesDataGridView.DataSource = dt; + GridViewRefresh(); } /// @@ -77,6 +71,44 @@ namespace HighWayIot.Winform.UserControlPages.SysConfigPages private void ConfrimAddButton_Click(object sender, EventArgs e) { + foreach (RoleConfig config in ConfigList) + { + for (int i = 0; i < ConfigList.Count; i++) + { + if (config.PageName == RolesDataGridView.Rows[i].Cells[0].Value.ToString().Trim()) + { + RoleChars[config.RoleIndex] = Convert.ToBoolean(RolesDataGridView.Rows[i].Cells[1].Value) ? '1' : '0'; + } + } + } + + if (string.IsNullOrEmpty(RoleNameTextBox.Text)) + { + MessageBox.Show("角色名不能为空!", "提示", MessageBoxButtons.OK); + return; + } + + if (_sysUserRoleService.GetRoleInfos(RoleNameTextBox.Text).Count >= 1) + { + MessageBox.Show("角色名重复!", "提示", MessageBoxButtons.OK); + return; + } + + SysRoleEntity role = new SysRoleEntity() + { + RoleName = RoleNameTextBox.Text, + RoleSet = new string(RoleChars), + }; + + if (_sysUserRoleService.InsertRoleInfo(role)) + { + MessageBox.Show("角色添加成功", "提示", MessageBoxButtons.OK); + } + else + { + MessageBox.Show("角色添加失败", "提示", MessageBoxButtons.OK); + } + this.Close(); this.Dispose(); } diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleConfigPage.Designer.cs b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleConfigPage.Designer.cs index 3c3b20d..1dd7449 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleConfigPage.Designer.cs +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleConfigPage.Designer.cs @@ -42,6 +42,8 @@ namespace HighWayIot.Winform.UserControlPages // // RoleDataGridView // + this.RoleDataGridView.AllowUserToAddRows = false; + this.RoleDataGridView.AllowUserToDeleteRows = false; this.RoleDataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); @@ -49,6 +51,8 @@ namespace HighWayIot.Winform.UserControlPages this.RoleDataGridView.Location = new System.Drawing.Point(0, 65); this.RoleDataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.RoleDataGridView.Name = "RoleDataGridView"; + this.RoleDataGridView.ReadOnly = true; + this.RoleDataGridView.RowHeadersVisible = false; this.RoleDataGridView.RowTemplate.Height = 25; this.RoleDataGridView.Size = new System.Drawing.Size(1204, 770); this.RoleDataGridView.TabIndex = 0; diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleConfigPage.cs b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleConfigPage.cs index b6ca1c5..4abf33c 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleConfigPage.cs +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleConfigPage.cs @@ -1,5 +1,7 @@ -using HighWayIot.Repository.domain; +using HighWayIot.Log4net; +using HighWayIot.Repository.domain; using HighWayIot.Repository.service; +using HighWayIot.Winform.Business; using HighWayIot.Winform.UserControlPages.SysConfigPages; using System; using System.Collections.Generic; @@ -17,8 +19,24 @@ namespace HighWayIot.Winform.UserControlPages { SysUserRoleService roleService = new SysUserRoleService(); + private static LogHelper logger = LogHelper.Instance; + + /// + /// 数据库实体类列表 + /// private List List = new List(); + /// + /// XML读取类 + /// + XmlUtil xmlUtil = new XmlUtil(); + + /// + /// 页面规则偏移量配置 + /// + List ConfigList; + + public RoleConfigPage() { @@ -30,17 +48,41 @@ namespace HighWayIot.Winform.UserControlPages { RoleDataGridView.AutoGenerateColumns = false; List = roleService.GetRoleInfos(); - RoleDataGridView.DataSource = null; - RoleDataGridView.DataSource = List; + + ConfigList = xmlUtil.ConfigReader(); + + //设置列数量 + RoleDataGridView.ColumnCount = ConfigList.Count + 1; + + //设置列头名称 + RoleDataGridView.Columns[0].Name = "RoleName"; + RoleDataGridView.Columns[0].DataPropertyName = "RoleName"; + RoleDataGridView.Columns[0].HeaderText = "角色名"; + RoleDataGridView.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; + RoleDataGridView.Columns[0].Width = 100; + + for (int i = 0; i < ConfigList.Count; i++) + { + RoleDataGridView.Columns[i + 1].Name = ConfigList[i].PageName; + RoleDataGridView.Columns[i + 1].DataPropertyName = ConfigList[i].PageName; + RoleDataGridView.Columns[i + 1].HeaderText = ConfigList[i].PageName; + RoleDataGridView.Columns[i + 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + GridViewRefresh(); } private void UpdateRole_Click(object sender, EventArgs e) { - RoleUpdateForm form = new RoleUpdateForm(roleService); + //写的很烂 + int index = RoleDataGridView.CurrentRow.Index; + + //前端数据顺序绑定的时候就是数据库的顺序,所以可以这么写。 + RoleUpdateForm form = new RoleUpdateForm(roleService, List[index]); form.ShowDialog(); + List = roleService.GetRoleInfos(); - RoleDataGridView.DataSource = null; - RoleDataGridView.DataSource = List; + GridViewRefresh(); } private void AddRole_Click(object sender, EventArgs e) @@ -48,13 +90,59 @@ namespace HighWayIot.Winform.UserControlPages RoleAddForm form = new RoleAddForm(roleService); form.ShowDialog(); List = roleService.GetRoleInfos(); - RoleDataGridView.DataSource = null; - RoleDataGridView.DataSource = List; + + GridViewRefresh(); } private void DeleteRole_Click(object sender, EventArgs e) { + //写的很烂 + int index = RoleDataGridView.CurrentRow.Index; + if (MessageBox.Show($"确认要删除{List[index].RoleName}该角色信息?", "确定?", MessageBoxButtons.OKCancel) == DialogResult.OK) + { + //前端数据顺序绑定的时候就是数据库的顺序,所以可以这么写。 + roleService.DeleteRoleInfoById(List[index].Id); + List = roleService.GetRoleInfos(); + GridViewRefresh(); + } + } + + /// + /// 刷新列 + /// + private void GridViewRefresh() + { + RoleDataGridView.Rows.Clear(); + //用户名部分初始化赋值 + for (int i = 0; i < List.Count; i++) + { + RoleDataGridView.Rows.Add(); + RoleDataGridView.Rows[i].Cells[0].Value = List[i].RoleName; + } + + //权限部分初始化赋值 + for (int rowIndex = 0; rowIndex < List.Count; rowIndex++) + { + char[] roleChars = List[rowIndex].RoleSet.ToCharArray(); + + for (int columnIndex = 1; columnIndex < RoleDataGridView.Columns.Count; columnIndex++) + { + // 获取当前单元格 + DataGridViewCell cell = RoleDataGridView.Rows[rowIndex].Cells[columnIndex]; + // 获取列名 + string columnName = RoleDataGridView.Columns[columnIndex].Name; + try + { + RoleDataGridView.Rows[rowIndex].Cells[columnIndex].Value = + roleChars[ConfigList.Where(x => x.PageName == columnName).First().RoleIndex] == '1' ? "√" : ""; + } + catch (Exception ex) + { + logger.Error("用户角色初始化发生错误,请检查Configuration.xml", ex); + } + } + } } } } diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleUpdateForm.Designer.cs b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleUpdateForm.Designer.cs index 6a28c2c..9327b5d 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleUpdateForm.Designer.cs +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleUpdateForm.Designer.cs @@ -29,7 +29,7 @@ private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); - this.UserNameTextBox = new System.Windows.Forms.TextBox(); + this.RoleNameTextBox = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.ConfrimAddButton = new System.Windows.Forms.Button(); this.panel1 = new System.Windows.Forms.Panel(); @@ -37,13 +37,13 @@ this.SelectNone = new System.Windows.Forms.Button(); this.SelectAll = new System.Windows.Forms.Button(); this.panel2 = new System.Windows.Forms.Panel(); - this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.RolesDataGridView = new System.Windows.Forms.DataGridView(); this.TableName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.IsUseable = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.panel1.SuspendLayout(); this.groupBox1.SuspendLayout(); this.panel2.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.RolesDataGridView)).BeginInit(); this.SuspendLayout(); // // label1 @@ -55,12 +55,12 @@ this.label1.Size = new System.Drawing.Size(0, 12); this.label1.TabIndex = 0; // - // UserNameTextBox + // RoleNameTextBox // - this.UserNameTextBox.Location = new System.Drawing.Point(216, 23); - this.UserNameTextBox.Name = "UserNameTextBox"; - this.UserNameTextBox.Size = new System.Drawing.Size(136, 21); - this.UserNameTextBox.TabIndex = 1; + this.RoleNameTextBox.Location = new System.Drawing.Point(216, 23); + this.RoleNameTextBox.Name = "RoleNameTextBox"; + this.RoleNameTextBox.Size = new System.Drawing.Size(136, 21); + this.RoleNameTextBox.TabIndex = 1; // // label2 // @@ -83,11 +83,12 @@ // // panel1 // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.panel1.Controls.Add(this.ConfrimAddButton); this.panel1.Controls.Add(this.label2); - this.panel1.Controls.Add(this.UserNameTextBox); + this.panel1.Controls.Add(this.RoleNameTextBox); this.panel1.Controls.Add(this.label1); - this.panel1.Dock = System.Windows.Forms.DockStyle.Top; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(398, 66); @@ -95,10 +96,12 @@ // // groupBox1 // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.SelectNone); this.groupBox1.Controls.Add(this.SelectAll); this.groupBox1.Controls.Add(this.panel2); - this.groupBox1.Dock = System.Windows.Forms.DockStyle.Bottom; this.groupBox1.Location = new System.Drawing.Point(0, 72); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(398, 593); @@ -114,6 +117,7 @@ this.SelectNone.TabIndex = 2; this.SelectNone.Text = "全不选"; this.SelectNone.UseVisualStyleBackColor = true; + this.SelectNone.Click += new System.EventHandler(this.SelectNone_Click); // // SelectAll // @@ -123,59 +127,68 @@ this.SelectAll.TabIndex = 1; this.SelectAll.Text = "全选"; this.SelectAll.UseVisualStyleBackColor = true; + this.SelectAll.Click += new System.EventHandler(this.SelectAll_Click); // // panel2 // - this.panel2.Controls.Add(this.dataGridView1); - this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel2.Controls.Add(this.RolesDataGridView); this.panel2.Location = new System.Drawing.Point(3, 49); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(392, 541); this.panel2.TabIndex = 0; // - // dataGridView1 + // RolesDataGridView // - this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.RolesDataGridView.AllowUserToAddRows = false; + this.RolesDataGridView.AllowUserToDeleteRows = false; + this.RolesDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.RolesDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.TableName, this.IsUseable}); - this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; - this.dataGridView1.Location = new System.Drawing.Point(0, 0); - this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.RowHeadersVisible = false; - this.dataGridView1.RowTemplate.Height = 23; - this.dataGridView1.Size = new System.Drawing.Size(392, 541); - this.dataGridView1.TabIndex = 0; + this.RolesDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.RolesDataGridView.Location = new System.Drawing.Point(0, 0); + this.RolesDataGridView.MultiSelect = false; + this.RolesDataGridView.Name = "RolesDataGridView"; + this.RolesDataGridView.RowHeadersVisible = false; + this.RolesDataGridView.RowTemplate.Height = 23; + this.RolesDataGridView.Size = new System.Drawing.Size(392, 541); + this.RolesDataGridView.TabIndex = 0; // // TableName // this.TableName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.TableName.DataPropertyName = "TableName"; this.TableName.HeaderText = "页面名称"; this.TableName.Name = "TableName"; + this.TableName.ReadOnly = true; // // IsUseable // + this.IsUseable.DataPropertyName = "IsUseable"; this.IsUseable.HeaderText = "是否有权限"; this.IsUseable.Name = "IsUseable"; this.IsUseable.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.IsUseable.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; this.IsUseable.Width = 90; // - // UserRoleUpdateForm + // RoleUpdateForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(398, 665); this.Controls.Add(this.groupBox1); this.Controls.Add(this.panel1); - this.Name = "UserRoleUpdateForm"; + this.Name = "RoleUpdateForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "修改角色设置"; + this.Text = "修改角色信息"; this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.groupBox1.ResumeLayout(false); this.panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.RolesDataGridView)).EndInit(); this.ResumeLayout(false); } @@ -183,7 +196,7 @@ #endregion private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox UserNameTextBox; + private System.Windows.Forms.TextBox RoleNameTextBox; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button ConfrimAddButton; private System.Windows.Forms.Panel panel1; @@ -191,7 +204,7 @@ private System.Windows.Forms.Button SelectNone; private System.Windows.Forms.Button SelectAll; private System.Windows.Forms.Panel panel2; - private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.DataGridView RolesDataGridView; private System.Windows.Forms.DataGridViewTextBoxColumn TableName; private System.Windows.Forms.DataGridViewCheckBoxColumn IsUseable; } diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleUpdateForm.cs b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleUpdateForm.cs index f65237d..ee8af64 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleUpdateForm.cs +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/RoleUpdateForm.cs @@ -1,5 +1,6 @@ using HighWayIot.Repository.domain; using HighWayIot.Repository.service; +using HighWayIot.Winform.Business; using System; using System.Collections.Generic; using System.ComponentModel; @@ -14,27 +15,149 @@ namespace HighWayIot.Winform.UserControlPages.SysConfigPages { public partial class RoleUpdateForm : Form { + /// + /// Sql业务类 + /// SysUserRoleService _sysUserRoleService; - public RoleUpdateForm(SysUserRoleService sysUserRoleService) + /// + /// XML读取类 + /// + XmlUtil xmlUtil = new XmlUtil(); + + /// + /// 规则字符数组 + /// + char[] RoleChars = new char[80]; + + /// + /// 页面规则偏移量配置 + /// + List ConfigList; + + /// + /// 前端展示DataTable + /// + DataTable dt = new DataTable(); + + /// + /// 要更改的数据 + /// + SysRoleEntity _roleEntity; + + public RoleUpdateForm(SysUserRoleService sysUserRoleService, SysRoleEntity sysRoleEntity) { InitializeComponent(); this._sysUserRoleService = sysUserRoleService; + this._roleEntity = sysRoleEntity; + Init(); + } + + private void Init() + { + RolesDataGridView.AutoGenerateColumns = false; + RoleNameTextBox.Text = _roleEntity.RoleName; + RoleChars = _roleEntity.RoleSet.ToCharArray(); + ConfigList = xmlUtil.ConfigReader(); + + dt.Columns.Add("TableName", typeof(string)); + dt.Columns.Add("IsUseable", typeof(bool)); + + GridViewRefresh(); } /// - /// 确认添加按钮 + /// 确认修改按钮 /// /// /// private void ConfrimAddButton_Click(object sender, EventArgs e) { - + + foreach (RoleConfig config in ConfigList) + { + for (int i = 0; i < ConfigList.Count; i++) + { + if (config.PageName == RolesDataGridView.Rows[i].Cells[0].Value.ToString().Trim()) + { + RoleChars[config.RoleIndex] = Convert.ToBoolean(RolesDataGridView.Rows[i].Cells[1].Value) ? '1' : '0'; + } + } + } + + if (string.IsNullOrEmpty(RoleNameTextBox.Text)) + { + MessageBox.Show("角色名不能为空!", "提示", MessageBoxButtons.OK); + return; + } + + if (_sysUserRoleService.GetRoleInfos(RoleNameTextBox.Text).Where(x => x.Id != _roleEntity.Id).Count() > 0) + { + MessageBox.Show("角色名重复!", "提示", MessageBoxButtons.OK); + return; + } + + _roleEntity.RoleName = RoleNameTextBox.Text; + _roleEntity.RoleSet = new string(RoleChars); + + if (_sysUserRoleService.UpdateRoleInfo(_roleEntity)) + { + MessageBox.Show("角色修改成功", "提示", MessageBoxButtons.OK); + } + else + { + MessageBox.Show("角色修改失败", "提示", MessageBoxButtons.OK); + } this.Close(); this.Dispose(); } + /// + /// 全选按钮 + /// + /// + /// + private void SelectAll_Click(object sender, EventArgs e) + { + for (int i = 0; i < 80; i++) + { + RoleChars[i] = '1'; + } + GridViewRefresh(); + } + /// + /// 取消全选按钮 + /// + /// + /// + private void SelectNone_Click(object sender, EventArgs e) + { + for (int i = 0; i < 80; i++) + { + RoleChars[i] = '0'; + } + GridViewRefresh(); + } + + /// + /// 前端页面刷新 + /// + private void GridViewRefresh() + { + dt.Rows.Clear(); + + foreach (var config in ConfigList) + { + var dr = dt.NewRow(); + dr[0] = config.PageName; + dr[1] = RoleChars[config.RoleIndex] == '1'; + dt.Rows.Add(dr); + } + + RolesDataGridView.DataSource = null; + RolesDataGridView.DataSource = dt; + } } } diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/UserAddForm.cs b/HighWayIot.Winform/UserControlPages/SysConfigPages/UserAddForm.cs index 52198cc..8331e9d 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/UserAddForm.cs +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/UserAddForm.cs @@ -15,14 +15,15 @@ namespace HighWayIot.Winform.UserControlPages.SysConfigPages public partial class UserAddForm : Form { /// - /// 数据库服务类 + /// 角色数据库业务实例 /// SysUserInfoService SysUserInfoService; - public UserAddForm(SysUserInfoService sysUserInfoService) + public UserAddForm(SysUserInfoService sysUserInfoService, string[] roleList) { InitializeComponent(); this.SysUserInfoService = sysUserInfoService; + UserRoleComboBox.DataSource = roleList; } /// diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.Designer.cs b/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.Designer.cs index 638c4ab..5c6537d 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.Designer.cs +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.Designer.cs @@ -32,26 +32,26 @@ namespace HighWayIot.Winform.UserControlPages private void InitializeComponent() { this.UserInfoDataGridView = new System.Windows.Forms.DataGridView(); + this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.UserName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Password = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.UserRole = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.LastLoginTime = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.AddUser = new System.Windows.Forms.Button(); this.UpdateUser = new System.Windows.Forms.Button(); this.DeleteUser = new System.Windows.Forms.Button(); this.ButtonPanel = new System.Windows.Forms.Panel(); this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.SelectUser = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - this.SelectUserName = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); - this.SelectUserRole = new System.Windows.Forms.ComboBox(); - this.label3 = new System.Windows.Forms.Label(); - this.IsCheckByLoginTime = new System.Windows.Forms.CheckBox(); - this.SelectUserLoginBeginTime = new System.Windows.Forms.DateTimePicker(); - this.SelectUserLoginEndTime = new System.Windows.Forms.DateTimePicker(); this.label4 = new System.Windows.Forms.Label(); - this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.UserName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Password = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.UserRole = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.LastLoginTime = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SelectUserLoginEndTime = new System.Windows.Forms.DateTimePicker(); + this.SelectUserLoginBeginTime = new System.Windows.Forms.DateTimePicker(); + this.IsCheckByLoginTime = new System.Windows.Forms.CheckBox(); + this.label3 = new System.Windows.Forms.Label(); + this.SelectUserRole = new System.Windows.Forms.ComboBox(); + this.label2 = new System.Windows.Forms.Label(); + this.SelectUserName = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.SelectUser = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.UserInfoDataGridView)).BeginInit(); this.ButtonPanel.SuspendLayout(); this.groupBox1.SuspendLayout(); @@ -78,6 +78,46 @@ namespace HighWayIot.Winform.UserControlPages this.UserInfoDataGridView.Size = new System.Drawing.Size(1188, 869); this.UserInfoDataGridView.TabIndex = 0; // + // Id + // + this.Id.DataPropertyName = "Id"; + this.Id.HeaderText = "ID"; + this.Id.Name = "Id"; + this.Id.ReadOnly = true; + this.Id.Width = 50; + // + // UserName + // + this.UserName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.UserName.DataPropertyName = "UserName"; + this.UserName.HeaderText = "用户名"; + this.UserName.Name = "UserName"; + this.UserName.ReadOnly = true; + // + // Password + // + this.Password.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Password.DataPropertyName = "Password"; + this.Password.HeaderText = "用户密码"; + this.Password.Name = "Password"; + this.Password.ReadOnly = true; + // + // UserRole + // + this.UserRole.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.UserRole.DataPropertyName = "UserRole"; + this.UserRole.HeaderText = "用户角色"; + this.UserRole.Name = "UserRole"; + this.UserRole.ReadOnly = true; + // + // LastLoginTime + // + this.LastLoginTime.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.LastLoginTime.DataPropertyName = "LastLoginTime"; + this.LastLoginTime.HeaderText = "上次登录时间"; + this.LastLoginTime.Name = "LastLoginTime"; + this.LastLoginTime.ReadOnly = true; + // // AddUser // this.AddUser.Location = new System.Drawing.Point(11, 11); @@ -146,58 +186,33 @@ namespace HighWayIot.Winform.UserControlPages this.groupBox1.TabStop = false; this.groupBox1.Text = "条件查询,某项为空则不判断该项"; // - // SelectUser - // - this.SelectUser.Location = new System.Drawing.Point(6, 19); - this.SelectUser.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.SelectUser.Name = "SelectUser"; - this.SelectUser.Size = new System.Drawing.Size(67, 28); - this.SelectUser.TabIndex = 4; - this.SelectUser.Text = "查询"; - this.SelectUser.UseVisualStyleBackColor = true; - this.SelectUser.Click += new System.EventHandler(this.SelectUser_Click); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(79, 12); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(53, 12); - this.label1.TabIndex = 5; - this.label1.Text = "用户名:"; - // - // SelectUserName - // - this.SelectUserName.Location = new System.Drawing.Point(81, 28); - this.SelectUserName.Name = "SelectUserName"; - this.SelectUserName.Size = new System.Drawing.Size(100, 21); - this.SelectUserName.TabIndex = 6; - // - // label2 + // label4 // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(185, 12); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(41, 12); - this.label2.TabIndex = 7; - this.label2.Text = "角色:"; + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(484, 31); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(17, 12); + this.label4.TabIndex = 13; + this.label4.Text = "到"; // - // SelectUserRole + // SelectUserLoginEndTime // - this.SelectUserRole.FormattingEnabled = true; - this.SelectUserRole.Location = new System.Drawing.Point(187, 28); - this.SelectUserRole.Name = "SelectUserRole"; - this.SelectUserRole.Size = new System.Drawing.Size(100, 20); - this.SelectUserRole.TabIndex = 8; + this.SelectUserLoginEndTime.CustomFormat = "yyyy年MM月dd日 HH:mm:ss"; + this.SelectUserLoginEndTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.SelectUserLoginEndTime.Location = new System.Drawing.Point(507, 28); + this.SelectUserLoginEndTime.Name = "SelectUserLoginEndTime"; + this.SelectUserLoginEndTime.Size = new System.Drawing.Size(185, 21); + this.SelectUserLoginEndTime.TabIndex = 12; // - // label3 + // SelectUserLoginBeginTime // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(291, 12); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(65, 12); - this.label3.TabIndex = 9; - this.label3.Text = "登陆时间:"; + this.SelectUserLoginBeginTime.CustomFormat = "yyyy年MM月dd日 HH:mm:ss"; + this.SelectUserLoginBeginTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.SelectUserLoginBeginTime.Location = new System.Drawing.Point(293, 28); + this.SelectUserLoginBeginTime.Name = "SelectUserLoginBeginTime"; + this.SelectUserLoginBeginTime.Size = new System.Drawing.Size(185, 21); + this.SelectUserLoginBeginTime.TabIndex = 11; + this.SelectUserLoginBeginTime.Value = new System.DateTime(2024, 11, 26, 13, 36, 9, 0); // // IsCheckByLoginTime // @@ -209,68 +224,58 @@ namespace HighWayIot.Winform.UserControlPages this.IsCheckByLoginTime.Text = "是否根据时间判断"; this.IsCheckByLoginTime.UseVisualStyleBackColor = true; // - // SelectUserLoginBeginTime - // - this.SelectUserLoginBeginTime.Location = new System.Drawing.Point(293, 28); - this.SelectUserLoginBeginTime.Name = "SelectUserLoginBeginTime"; - this.SelectUserLoginBeginTime.Size = new System.Drawing.Size(102, 21); - this.SelectUserLoginBeginTime.TabIndex = 11; - // - // SelectUserLoginEndTime - // - this.SelectUserLoginEndTime.Location = new System.Drawing.Point(424, 28); - this.SelectUserLoginEndTime.Name = "SelectUserLoginEndTime"; - this.SelectUserLoginEndTime.Size = new System.Drawing.Size(102, 21); - this.SelectUserLoginEndTime.TabIndex = 12; - // - // label4 + // label3 // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(401, 31); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(17, 12); - this.label4.TabIndex = 13; - this.label4.Text = "到"; + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(291, 12); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(65, 12); + this.label3.TabIndex = 9; + this.label3.Text = "登陆时间:"; // - // Id + // SelectUserRole // - this.Id.DataPropertyName = "Id"; - this.Id.HeaderText = "ID"; - this.Id.Name = "Id"; - this.Id.ReadOnly = true; - this.Id.Width = 50; + this.SelectUserRole.FormattingEnabled = true; + this.SelectUserRole.Location = new System.Drawing.Point(187, 28); + this.SelectUserRole.Name = "SelectUserRole"; + this.SelectUserRole.Size = new System.Drawing.Size(100, 20); + this.SelectUserRole.TabIndex = 8; // - // UserName + // label2 // - this.UserName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.UserName.DataPropertyName = "UserName"; - this.UserName.HeaderText = "用户名"; - this.UserName.Name = "UserName"; - this.UserName.ReadOnly = true; + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(185, 12); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(41, 12); + this.label2.TabIndex = 7; + this.label2.Text = "角色:"; // - // Password + // SelectUserName // - this.Password.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.Password.DataPropertyName = "Password"; - this.Password.HeaderText = "用户密码"; - this.Password.Name = "Password"; - this.Password.ReadOnly = true; + this.SelectUserName.Location = new System.Drawing.Point(81, 28); + this.SelectUserName.Name = "SelectUserName"; + this.SelectUserName.Size = new System.Drawing.Size(100, 21); + this.SelectUserName.TabIndex = 6; // - // UserRole + // label1 // - this.UserRole.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.UserRole.DataPropertyName = "UserRole"; - this.UserRole.HeaderText = "用户角色"; - this.UserRole.Name = "UserRole"; - this.UserRole.ReadOnly = true; + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(79, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(53, 12); + this.label1.TabIndex = 5; + this.label1.Text = "用户名:"; // - // LastLoginTime + // SelectUser // - this.LastLoginTime.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.LastLoginTime.DataPropertyName = "LastLoginTime"; - this.LastLoginTime.HeaderText = "上次登录时间"; - this.LastLoginTime.Name = "LastLoginTime"; - this.LastLoginTime.ReadOnly = true; + this.SelectUser.Location = new System.Drawing.Point(6, 19); + this.SelectUser.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.SelectUser.Name = "SelectUser"; + this.SelectUser.Size = new System.Drawing.Size(67, 28); + this.SelectUser.TabIndex = 4; + this.SelectUser.Text = "查询"; + this.SelectUser.UseVisualStyleBackColor = true; + this.SelectUser.Click += new System.EventHandler(this.SelectUser_Click); // // UserConfigPage // diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.cs b/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.cs index 853bf99..56a0056 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.cs +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.cs @@ -15,10 +15,26 @@ namespace HighWayIot.Winform.UserControlPages { public partial class UserConfigPage : UserControl { + /// + /// 用户数据库业务实例 + /// private SysUserInfoService sysUserInfoService = new SysUserInfoService(); + /// + /// 角色数据库业务实例 + /// + private SysUserRoleService sysUserRoleService = new SysUserRoleService(); + + /// + /// 用户信息列表 + /// private List List = new List(); + /// + /// 角色名称列表 + /// + private string[] RoleNames; + public UserConfigPage() { InitializeComponent(); @@ -29,6 +45,15 @@ namespace HighWayIot.Winform.UserControlPages { UserInfoDataGridView.AutoGenerateColumns = false; List = sysUserInfoService.GetUserInfos(); + + RoleNames = sysUserRoleService.GetRoleInfos().Select(x => x.RoleName).ToArray(); + Array.Resize(ref RoleNames, RoleNames.Length + 1); + Array.Copy(RoleNames, 0, RoleNames, 1, RoleNames.Length - 1); + RoleNames[0] = string.Empty; + + SelectUserLoginBeginTime.Value = DateTime.Now - TimeSpan.FromDays(3); + + this.SelectUserRole.DataSource = RoleNames; UserInfoDataGridView.DataSource = null; UserInfoDataGridView.DataSource = List; } @@ -42,7 +67,7 @@ namespace HighWayIot.Winform.UserControlPages entity.UserName = UserInfoDataGridView.Rows[a].Cells["UserName"].Value.ToString(); entity.UserRole = UserInfoDataGridView.Rows[a].Cells["UserRole"].Value.ToString(); entity.Password = UserInfoDataGridView.Rows[a].Cells["Password"].Value.ToString(); - UserUpDateForm form = new UserUpDateForm(sysUserInfoService, entity); + UserUpDateForm form = new UserUpDateForm(sysUserInfoService, entity, RoleNames); form.ShowDialog(); List = sysUserInfoService.GetUserInfos(); UserInfoDataGridView.DataSource = null; @@ -51,7 +76,7 @@ namespace HighWayIot.Winform.UserControlPages private void AddUser_Click(object sender, EventArgs e) { - UserAddForm form = new UserAddForm(sysUserInfoService); + UserAddForm form = new UserAddForm(sysUserInfoService, RoleNames); form.ShowDialog(); List = sysUserInfoService.GetUserInfos(); UserInfoDataGridView.DataSource = null; @@ -60,11 +85,11 @@ namespace HighWayIot.Winform.UserControlPages private void DeleteUser_Click(object sender, EventArgs e) { - if(MessageBox.Show("确定要删除所选行的数据?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel) + int a = UserInfoDataGridView.CurrentRow.Index; + if (MessageBox.Show($"确定要删除所选{List[a].UserName}行的数据?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } - int a = UserInfoDataGridView.CurrentRow.Index; int.TryParse(UserInfoDataGridView.Rows[a].Cells["Id"].Value.ToString(), out a); sysUserInfoService.DeleteUserInfoById(a); List = sysUserInfoService.GetUserInfos(); diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.resx b/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.resx index ef7900e..5f526e4 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.resx +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/UserConfigPage.resx @@ -132,4 +132,19 @@ True + + True + + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/HighWayIot.Winform/UserControlPages/SysConfigPages/UserUpDateForm.cs b/HighWayIot.Winform/UserControlPages/SysConfigPages/UserUpDateForm.cs index 3d21084..ec0dc22 100644 --- a/HighWayIot.Winform/UserControlPages/SysConfigPages/UserUpDateForm.cs +++ b/HighWayIot.Winform/UserControlPages/SysConfigPages/UserUpDateForm.cs @@ -14,14 +14,22 @@ namespace HighWayIot.Winform.UserControlPages.SysConfigPages { public partial class UserUpDateForm : Form { + /// + /// 角色数据库业务实例 + /// SysUserInfoService _userInfoService; + + /// + /// 要修改的实体 + /// SysUserEntity _userEntity; - public UserUpDateForm(SysUserInfoService sysUserInfoService, SysUserEntity userEntity) + public UserUpDateForm(SysUserInfoService sysUserInfoService, SysUserEntity userEntity, string[] roleList) { InitializeComponent(); this._userInfoService = sysUserInfoService; this._userEntity = userEntity; + UserRoleComboBox.DataSource = roleList; PasswordTextBox.Text = _userEntity.Password; UserNameTextBox.Text = _userEntity.UserName; for(int i = 0; i < UserRoleComboBox.Items.Count; i++)