using HighWayIot.Repository.domain; using HighWayIot.Repository.service; using HighWayIot.Winform.Business; 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; namespace HighWayIot.Winform.UserControlPages.SysConfigPages { public partial class RoleUpdateForm : Form { /// /// Sql业务类 /// 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; } } }