Exemplo n.º 1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!Manager.Acquire(PermissionFlags.Insert))
        {
            WebHelper.Alert("没有添加权限!");
            return;
        }

        if (string.IsNullOrEmpty(txtName.Text))
        {
            WebHelper.Alert("角色名不能为空!");
            txtName.Focus();
            return;
        }

        try
        {
            IRole role = Factory.Create(false) as IRole;

            role.Name = txtName.Text;
            role.Save();

            txtName.Text = "";

            WebHelper.Alert("添加成功!");

            //重新绑定数据
            gv.DataBind();
        }
        catch (Exception ex)
        {
            //异常发生时,要给出错误提示
            WebHelper.Alert("添加失败!" + ex.Message);
        }
    }
Exemplo n.º 2
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (!Manager.Acquire(PermissionFlags.Insert))
        {
            WebHelper.Alert("没有添加权限!");
            return;
        }

        if (string.IsNullOrEmpty(txtName.Text))
        {
            WebHelper.Alert("角色名不能为空!");
            txtName.Focus();
            return;
        }

        try
        {
            IRole role = Factory.Create(false) as IRole;

            role.Name = txtName.Text;

            Int32[] vs = gvExt.SelectedIntValues;
            if (vs != null && vs.Length > 0)
            {
                IRole entity = FindByRoleID(vs[0]);
                role.Permission = entity.Permission;
            }

            role.Save();

            txtName.Text = "";

            WebHelper.Alert("添加成功!");

            //重新绑定数据
            gv.DataBind();
        }
        catch (Exception ex)
        {
            //异常发生时,要给出错误提示
            WebHelper.Alert("添加失败!" + ex.Message);
        }
    }
Exemplo n.º 3
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();
    }
Exemplo n.º 4
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();
    }