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 RoleAddForm : Form { /// /// Sql业务类 /// SysUserRoleService _sysUserRoleService = SysUserRoleService.Instance; /// /// XML读取类 /// XmlUtil xmlUtil = XmlUtil.Instance; /// /// 规则字符数组 /// char[] RoleChars = new char[80]; /// /// 页面规则偏移量配置 /// List ConfigList; /// /// 前端展示DataTable /// DataTable dt = new DataTable(); public RoleAddForm() { InitializeComponent(); Init(); } private void Init() { RolesDataGridView.AutoGenerateColumns = false; for (int i = 0; i < 80; i++) { RoleChars[i] = '0'; } 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).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(); } /// /// 全选按钮 /// /// /// 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; } } }