예제 #1
0
파일: power.aspx.cs 프로젝트: 262734254/OA
    protected void DisplayRoleRightInfo(int roleId)
    {
        //得到所有的父节点的信息
        IList <Power> list = rolePowerManager.GetPowerNodeInfoByConditions("paranet", 0);


        //根据父节点得到对应子节点,把父节点生成用户控件 然后循环插入到PaleHolder容器中
        foreach (Power power in list)
        {
            //得到父节点Id
            string nodeId = power.PowerId.ToString();

            //得到父节点名称
            string displayName = power.PowerName;


            ///实例化用户控件
            PowerControl powerControl = (PowerControl)LoadControl(@"~/UserControls/PowerUserControl.ascx");

            //找到隐藏控件 存储父节点Id
            HiddenField hidParentMenu = (HiddenField)powerControl.FindControl("hidParentMenu");
            hidParentMenu.Value = nodeId;

            //找到用户控件的checkBox
            CheckBox chkParenMenu = (CheckBox)powerControl.FindControl("chkPararentMenu");
            Label    lblModelName = (Label)powerControl.FindControl("lblParentName");
            //显示父菜单的名称
            //chkParenMenu.Text = displayName;
            lblModelName.Text = displayName;
            //保存角色Id
            HiddenField hidRoleId = (HiddenField)powerControl.FindControl("hidRoleId");
            hidRoleId.Value = roleId.ToString();

            //根据角色Id获取其所拥有的权限
            IList <Power> list2 = rolePowerManager.SelectPowersByRoleId(roleId);

            //循环将该角色拥有的父节点添加到角色权限数值
            ArrayList arrRoleParentNodes = new ArrayList();

            foreach (Power p in list2)
            {
                arrRoleParentNodes.Add(p.prarentId);
            }


            //如果权限中存在模块 则选中父节点
            if (arrRoleParentNodes.Contains(nodeId))
            {
                chkParenMenu.Checked = true;
            }


            //把父节点生成的用户控件追加到PlaceHolder容器中
            phRoleDistribute.Controls.Add(powerControl);
        }
    }