⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 distributerole.aspx.cs

📁 OA系统源码 办公应用软件源码 asp.net 开发
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MyOffice.BLL;
using MyOffice.Models;

public partial class Sysmagae_DistributeRole : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
            if (Request.QueryString["RoleId"] != null) {
                //获得指定的角色Id
                int roleId = int.Parse(Request.QueryString["RoleId"].ToString());
                if (!IsPostBack) {
                    RoleInfoModel rifm = SysManageBLL.SelectRoleId(roleId);
                    //显示角色名称
                    lblCurrentRole.Text = rifm.RoleName;
                }
               
                DisplayRoleRightInfo(roleId);
            }
        
    }
    protected void btnRet_Click(object sender, EventArgs e)
    {
        Response.Redirect("RoleManage.aspx");
    }
    //显示节点信息
    public void DisplayRoleRightInfo(int roleid) {
        List<RoleRightModel> currentRoleParentsNodes = companyBLL.SeUsersRId(roleid);
        ArrayList arrRoleParentNodes = new ArrayList();
        foreach (RoleRightModel roleRight in currentRoleParentsNodes) {
            arrRoleParentNodes.Add(roleRight.SysFun.NodeId.ToString());
        }
        //查询所有父节点信息
        List<SysFunModel> lisy = companyBLL.SeleSSId(0);
        //根据父节点Id查出对应的字节点,把父子节点生成用户控件,然后循环插入到PlaceHolder容器中
        foreach (SysFunModel sfmPare in lisy) { 
            //得到父节点Id
            string noeId = sfmPare.NodeId + "";
            //获取父节点Name
            string displayname = sfmPare.DisplayName;
            //实例化用户控件
            Sysmagae_RoleUserControl rolecotrol = (Sysmagae_RoleUserControl)LoadControl(@"RoleUserControl.ascx");
            //实例化隐藏域,用以存储父节点Id
            HtmlInputHidden hidParentMenu = (HtmlInputHidden)rolecotrol.FindControl("hidParentMenu");
            hidParentMenu.Value = noeId;
            //实例化隐藏域,用以存储角色Id
            HtmlInputHidden hidRoleId = (HtmlInputHidden)rolecotrol.FindControl("hidRoleId");
            hidRoleId.Value = roleid.ToString();
            //实例化用户控件中的checkbox
            CheckBox chkParentMenu = (CheckBox)rolecotrol.FindControl("chkParentMenu");
            //显示父菜单名称
            chkParentMenu.Text = displayname;
            if (arrRoleParentNodes.Contains(noeId)) {
                chkParentMenu.Checked = true;
            }
            //把父节点生成的用户控件追加到PlaceHolder容器中
            phRoleDistribute.Controls.Add(rolecotrol);
           
        }
       // int nub = phRoleDistribute.Controls.Count;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        int nub = phRoleDistribute.Controls.Count;
        //获得角色Id
        int roleId = int.Parse(Request["roleid"].ToString());
        //删除此角色下的RoleRight
        int num = companyBLL.RoleIdDeleRoleRight(roleId);
        //循环遍历每一个用户控件
        foreach (Control ct in phRoleDistribute.Controls) { 
            //实例化CheckBox
            CheckBox chk = (CheckBox)ct.FindControl("chkParentMenu");
            HtmlInputHidden hih = (HtmlInputHidden)ct.FindControl("hidParentMenu");
            //假如此节点被选中
            if (chk.Checked) { 
                //根据角色Id和节点Id添加RoleRight
                int nucomer = companyBLL.InsertRoleRight(roleId,int.Parse(hih.Value));
                CheckBoxList chklst = (CheckBoxList)ct.FindControl("chklstChildMenu");
                HtmlInputHidden hihs = (HtmlInputHidden)ct.FindControl("hidParentMenu");
                foreach (ListItem li in chklst.Items) {
                if (li.Selected)
                {
                   int nucomers = companyBLL.InsertRoleRight(roleId, int.Parse(li.Value));
                }
                
            }
        }
        Response.Write("<script>alert('权限已生效!!');self.document.location.href='RoleManage.aspx'</script>");
            }
        } 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -