一、功能简介
1. 数据库可使用sqlite、mssql、mysql等
2. 管理员账号不管控,其余账号进行权限管控(左侧菜单,表单按钮),且只能看到自己创建的角色、用户
二、操作界面
1. 管理员账号登陆后,左侧菜单栏自动添加 “菜单管理” ,菜单选择 Menu / Button
2. 角色分配权限
3. 用户绑定角色
4. 游客登陆后界面
三、数据库表
四、源码结构
五、权限控制代码
1. 菜单栏
public static void SetTreeView(TreeView treeView1, ImageList imageList1, string checkList, bool onlyMenu = false){if (null == checkList) checkList = string.Empty;treeView1.Nodes.Clear();treeView1.ImageList = imageList1;// 管理员特别权限if (onlyMenu && LoginUser.Root){TreeNode tn = new TreeNode();tn.Text = "菜单管理";treeView1.Nodes.Add(tn);}var list = FreeSqlHelper.GetMenu();var parents = list.Where(o => o.ParentId == 0);foreach (var item in parents){var id = item.Id.ToString();var nodeSign = GetSignTag(id);//TreeNode tn = new TreeNode();tn.Text = item.MenuTag;tn.Tag = id;tn.ImageIndex = 0; //FillTree(tn, list, checkList, onlyMenu);//if (checkList.Contains(nodeSign)){tn.Checked = true;// 菜单设置用}//if (onlyMenu){// 添加左菜单栏时用(只包含菜单,且有权限时展示)if (EnumMenuType.Menu == (EnumMenuType)item.MenuType){if (string.IsNullOrEmpty(checkList)){treeView1.Nodes.Add(tn);}else{if (checkList.Contains(nodeSign)){treeView1.Nodes.Add(tn);}}}}else{treeView1.Nodes.Add(tn);}}if (treeView1.Nodes.Count > 0)//展开一级节点{treeView1.Nodes[0].Expand();}}
2. 表单按钮
ToolStripButton btnAssign = new ToolStripButton();ToolStripTextBox txtQuery_Name = new ToolStripTextBox();ToolStripTextBox txtQuery_Tag = new ToolStripTextBox();public frmRole(){InitializeComponent();SetDataGridView();//// 控制按钮btnAssign = GetToolStripButton("btnAssign", "分配权限", Resources.btnAssign); btnAssign.Click += new EventHandler(btnAssign_Click); //// 查询按钮var label1 = new ToolStripLabel(); label1.Text = "角色名称"; toolStripQuery.Items.Insert(0, label1); toolStripQuery.Items.Insert(1, txtQuery_Name);var label2 = new ToolStripLabel(); label2.Text = "角色标记"; toolStripQuery.Items.Insert(2, label2); toolStripQuery.Items.Insert(3, txtQuery_Tag);}public void InitUI(){ if (!DataMgr.LoginUser.Root){var roleMenu = DataMgr.LoginUser.RoleMenuNames.ToLower();btnAdd.Visible = roleMenu.Contains("add_role") ? true : false;btnEdit.Visible = roleMenu.Contains("edit_role") ? true : false;btnDelete.Visible = roleMenu.Contains("delete_role") ? true : false;btnAssign.Visible = roleMenu.Contains("assign_role") ? true : false;}//base.InitData();}