コード例 #1
0
ファイル: Menu.cs プロジェクト: shanfree/SharpReport
 /// <summary>
 /// 为单一角色绑定栏目的权限组
 /// </summary>
 /// <param name="menuID">栏目ID</param>
 /// <param name="roleID">角色ID</param>
 /// <param name="permissionGroupCode">权限组代码,假设某个权限组为:浏览1,修改10,删除100,审批1000。该用户在该栏目的权限组代码1011表示,具有浏览修改和审批权限,而不具有删除权限</param>
 public void AddRoleToMenu(string menuID, string roleID, string permissionGroupCode)
 {
     if (string.IsNullOrEmpty(menuID))
     {
         throw new ArgumentNullException("栏目ID不能为空。");
     }
     if (string.IsNullOrEmpty(roleID))
     {
         throw new ArgumentNullException("角色ID不能为空。");
     }
     if (string.IsNullOrEmpty(permissionGroupCode))
     {
         throw new ArgumentNullException("权限组代码不能为空。");
     }
     // 判断权限组代码是否对应权限组
     PermissionGroupInfo pgInfo = new PermissionGroup().GetByMenuID(menuID);
     IList<PermissionInfo> pList = new Permission().GetList(pgInfo.ID);
     if (pList == null)
     {
         throw new Exception("栏目" + menuID + "对应的权限组不存在");
     }
     if (permissionGroupCode.Length != pList.Count)
     {
         throw new Exception("角色添加失败,权限组代码的长度和权限数目不相等。");
     }
     dal.AddRoleToMenu(menuID, roleID, permissionGroupCode);
 }
コード例 #2
0
 protected void gvRoleList_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         string permissionGroupID = rblPower.SelectedValue;
         IList<PermissionInfo> pList = new Permission().GetList(permissionGroupID);
         CheckBoxList cblPermission = (CheckBoxList)e.Row.FindControl("cblPermission");
         cblPermission.DataSource = pList;
         cblPermission.DataBind();
         // 权限组赋值
         RoleInfo rInfo = e.Row.DataItem as RoleInfo;
         string menuPermissionCode = new BLL.Menu().GetPermissionGroupCodeOfMenuByRole(this.NodeID, rInfo.ID);
         char[] codeArrary = menuPermissionCode.ToCharArray();
         for (int i = 0; i < cblPermission.Items.Count; i++)
         {
             ListItem item = cblPermission.Items[i];
             item.Selected = ("0" == codeArrary[i].ToString()) ? false : true;
         }
     }
 }