예제 #1
0
 /// <summary>
 /// 添加栏目
 /// </summary>
 /// <param name="parentMenuID">父节点ID</param>
 /// <param name="cInfo">添加的栏目,“栏目代码信息”(MenuCode)属性为系统自动生成。如系统已存在父节点(0103),并且具有2个同级节点,同级节点的最大编号为(010302),则该节点编号为010303</param>
 /// <returns>新增实体的主键</returns>
 public string AddChild(string parentMenuID, MenuInfo cInfo)
 {
     if (string.IsNullOrEmpty(parentMenuID))
     {
         throw new ArgumentNullException("父节点ID不能为空。");
     }
     // 生成新增栏目的栏目代码
     string maxChildCode = new Menu().getMaxChildCode(parentMenuID);
     MenuInfo pInfo = new Menu().GetByID(parentMenuID);
     // 末2位+1,为空则为00;
     if (string.IsNullOrEmpty(maxChildCode))
     {
         cInfo.MenuCode = pInfo.MenuCode + "00";
     }
     else
     {
         // 默认编码为00~99
         int width = 2;
         string max = maxChildCode.Substring(maxChildCode.Length - width);
         int maxNum = int.Parse(max);
         cInfo.MenuCode = pInfo.MenuCode + String.Format("{0:D2}", maxNum++); ;
     }
     cInfo.ParentID = parentMenuID;
     string menuID = dal.Add(cInfo);
     //获取副栏目权限组,子节点默认绑定
     PermissionGroupInfo pgInfo = new PermissionGroup().GetByMenuID(parentMenuID);
     if (null != pgInfo && string.IsNullOrEmpty(pgInfo.ID) == true)
     {
         AddPermissionGroup(menuID, pgInfo.ID);
     }
     return menuID;
 }
예제 #2
0
 /// <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);
 }
예제 #3
0
 protected void btnRoleBind_Click(object sender, EventArgs e)
 {
     try
     {
         if (rblPower.SelectedIndex == -1)
         {
             ShowMsg("请选择权限组绑定。");
             return;
         }
         if (string.IsNullOrEmpty(this.NodeID))
         {
             ShowMsg("请选择栏目。");
             return;
         }
         PermissionGroupInfo pgInfo = new PermissionGroup().GetByMenuID(this.NodeID);
         if (pgInfo == null || string.IsNullOrEmpty(pgInfo.ID))
         {
             ShowMsg("请先为栏目绑定权限组再添加角色。");
             return;
         }
         // 绑定选中的角色
         IList<RoleInfo> rList = new Role().GetListByMenuID(this.NodeID);
         new BLL.Menu().AddRolesToMenu(this.NodeID, pgInfo.ID, rList);
         // 显示角色的权限配置列表
         gvRoleList.DataSource = rList;
         gvRoleList.DataBind();
     }
     catch (ArgumentNullException aex)
     {
         ShowMsg(aex.Message);
     }
     catch (Exception exc)
     {
         ShowMsg(exc.Message);
         Log(exc);
     }
 }
예제 #4
0
 /// <summary>
 /// 将角色和栏目以及权限组进行绑定
 /// </summary>
 /// <param name="menuID">栏目</param>
 /// <param name="permissionGroupID">权限</param>
 /// <param name="rList">角色列表</param>
 public void AddRolesToMenu(string menuID, string permissionGroupID, IList<RoleInfo> rList)
 {
     if (string.IsNullOrEmpty(menuID))
     {
         throw new ArgumentNullException("请选择栏目");
     }
     if (string.IsNullOrEmpty(permissionGroupID))
     {
         throw new ArgumentNullException("请选择权限组绑定。");
     }
     if (rList == null || rList.Count == 0)
     {
         throw new ArgumentNullException("请选择至少一个角色进行绑定。");
     }
     string relationID = string.Empty;
     PermissionGroupInfo pgInfo = new PermissionGroup().GetByMenuID(menuID);
     if (pgInfo == null || pgInfo.ID != permissionGroupID)
     {
         // 栏目未绑定任何权限组,则先进行绑定
         relationID = new BLL.Menu().AddPermissionGroup(menuID, permissionGroupID);
     }
     else
     {
         relationID = pgInfo.RelationID;
     }
     //删除栏目权限组组合所对应的所有角色
     InitialMenuRole(menuID);
     foreach (RoleInfo rInfo in rList)
     {
         string defaultCode = new PermissionGroup().GetDefaultCodeFromPermissionGroupID(permissionGroupID);
         AddRoleToMenu(menuID, rInfo.ID, defaultCode);
     }
 }
예제 #5
0
 /// <summary>
 /// 选择编辑栏目
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void tMenus_SelectedNodeChanged(object sender, EventArgs e)
 {
     try
     {
         //选中节点值
         string value = tMenus.SelectedNode.Value;
         this.NodeID = value;
         MenuInfo mInfo = new BLL.Menu().GetByID(this.NodeID);
         this.ParentID = mInfo.ParentID;
         tbName.Text = mInfo.Name;
         tbRemark.Text = mInfo.Remark;
         tbSortNum.Text = mInfo.MenuCode;
         tbURL.Text = mInfo.URL;
         //rblIsShow.SelectedIndex = (mInfo.IsShow == true) ? 0 : 1;
         if (string.IsNullOrEmpty(mInfo.Target) == false)
         {
             rblExtend.SelectedValue = mInfo.Target;
         }
         btnSubmit.Visible = true;
         btnAdd.Visible = true;
         btnDel.Visible = true;
         btnSub.Visible = true;
         // 加载权限组
         rblPower.DataSource = new PermissionGroup().GetList();
         rblPower.DataBind();
         PermissionGroupInfo pgInfo = new PermissionGroup().GetByMenuID(mInfo.ID);
         if (pgInfo != null && string.IsNullOrEmpty(pgInfo.ID) == false)
         {
             rblPower.SelectedValue = pgInfo.ID;
             btnRoleBind.Visible = true;
         }
         // 加载角色
         IList<RoleInfo> rList = new Role().GetList();
         cblRole.DataSource = rList;
         cblRole.DataBind();
         IList<RoleInfo> mRoleList = new Role().GetListByMenuID(mInfo.ID);
         foreach (RoleInfo rInfo in mRoleList)
         {
             cblRole.Items.FindByValue(rInfo.ID).Selected = true;
         }
         // 为选中的角色绑定权限
         gvRoleList.DataSource = mRoleList;
         gvRoleList.DataBind();
     }
     catch (Exception exc)
     {
         ShowMsg(exc.Message);
         Log(exc);
     }
 }