示例#1
0
 void CheckAndAddParent(Int32 roleid, IMenu menu)
 {
     // 如果父级没有授权,则授权
     while ((menu = menu.Parent) != null)
     {
         IRoleMenu rm = FindByRoleAndMenu(roleid, menu.ID);
         if (rm == null)
         {
             rm                = Factory.Create(false) as IRoleMenu;
             rm.RoleID         = roleid;
             rm.MenuID         = menu.ID;
             rm.PermissionFlag = PermissionFlags.All;
             rm.Save();
         }
     }
 }
示例#2
0
    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RoleID < 1)
        {
            return;
        }

        CheckBoxList cb = sender as CheckBoxList;

        //只需判断cb是否为空,该角色只有“查看”权限时cb.SelectedItem为空。
        //if (cb == null || cb.SelectedItem == null) return;
        if (cb == null)
        {
            return;
        }

        GridViewRow row = cb.BindingContainer as GridViewRow;

        if (row == null)
        {
            return;
        }

        IMenu menu = CommonManageProvider.Provider.MenuRoot.AllChilds[row.DataItemIndex] as IMenu;

        if (menu == null)
        {
            return;
        }

        // 检查权限
        IRoleMenu rm = FindByRoleAndMenu(RoleID, menu.ID);

        // 没有权限,增加
        if (rm == null)
        {
            if (!Manager.Acquire(PermissionFlags.Insert))
            {
                WebHelper.Alert("没有添加权限!");
                return;
            }

            rm        = Factory.Create(false) as IRoleMenu;
            rm.RoleID = RoleID;
            rm.MenuID = menu.ID;
        }

        // 遍历权限项
        PermissionFlags flag = PermissionFlags.None;

        foreach (ListItem item in cb.Items)
        {
            if (item.Selected)
            {
                flag |= (PermissionFlags)(Int32.Parse(item.Value));
            }
        }

        if (rm.PermissionFlag != flag)
        {
            if (!Manager.Acquire(PermissionFlags.Update))
            {
                WebHelper.Alert("没有编辑权限!");
                return;
            }

            rm.PermissionFlag = flag;
            rm.Save();

            // 如果父级没有授权,则授权
            CheckAndAddParent(RoleID, menu);
        }

        // 清空缓存,否则一会绑定的时候会绑定旧数据
        _rms = null;
        gv.DataBind();
    }
示例#3
0
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (RoleID < 1)
        {
            return;
        }

        CheckBox cb = sender as CheckBox;

        if (cb == null)
        {
            return;
        }

        GridViewRow row = cb.BindingContainer as GridViewRow;

        if (row == null)
        {
            return;
        }

        IMenu menu = CommonManageProvider.Provider.MenuRoot.AllChilds[row.DataItemIndex] as IMenu;

        if (menu == null)
        {
            return;
        }

        // 检查权限
        IRoleMenu rm = FindByRoleAndMenu(RoleID, menu.ID);

        if (cb.Checked)
        {
            // 没有权限,增加
            if (rm == null)
            {
                if (!Manager.Acquire(PermissionFlags.Insert))
                {
                    WebHelper.Alert("没有添加权限!");
                    return;
                }

                rm                = Factory.Create(false) as IRoleMenu;
                rm.RoleID         = RoleID;
                rm.MenuID         = menu.ID;
                rm.PermissionFlag = PermissionFlags.All;
                rm.Save();

                // 如果父级没有授权,则授权
                CheckAndAddParent(RoleID, menu);
            }
        }
        else
        {
            // 如果有权限,删除
            if (rm != null)
            {
                if (!Manager.Acquire(PermissionFlags.Delete))
                {
                    WebHelper.Alert("没有删除权限!");
                    return;
                }

                (rm as IEntity).Delete();
            }
        }

        // 清空缓存,否则一会绑定的时候会绑定旧数据
        _rms = null;
        gv.DataBind();
    }