コード例 #1
0
        private void InitPurview()
        {
            string str;

            this.xmlDoc = new XmlDocument();
            HttpContext current = HttpContext.Current;

            if (current != null)
            {
                str = current.Server.MapPath("~/Admin/Common/MainMenu.xml");
            }
            else
            {
                str = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Admin/Common/MainMenu.xml");
            }
            try
            {
                this.xmlDoc.Load(str);
            }
            catch (XmlException exception)
            {
                AdminPage.WriteErrMsg("MainMenu.xml配置文件不符合XML规范,具体错误信息:" + exception.Message);
            }
            XmlNode       node = this.xmlDoc.SelectSingleNode(this.xmlPath);
            StringBuilder sb   = new StringBuilder();

            if (node == null)
            {
                AdminPage.WriteErrMsg("MainMenu.xml配置文件不存在menu根元素");
            }
            if (!this.Page.IsPostBack)
            {
                XmlNodeList list = this.xmlDoc.SelectNodes("//*");
                IList <RoleModulePermissionsInfo> otherModelPermissionsById = RolePermissions.GetOtherModelPermissionsById(this.m_RoleId);
                foreach (XmlNode node2 in list)
                {
                    if (string.CompareOrdinal(this.GetAttributeValue(node2, "ShowOnForm"), "true") == 0)
                    {
                        string attributeValue = this.GetAttributeValue(node2, "operateCode");
                        foreach (RoleModulePermissionsInfo info in otherModelPermissionsById)
                        {
                            if (!Enum.IsDefined(typeof(OperateCode), attributeValue) && (RolePermissions.MD5(attributeValue).CompareTo(DataConverter.CLng(info.OperateCode)) == 0))
                            {
                                ((XmlElement)node2).SetAttribute("IsChoose", "true");
                            }
                        }
                        continue;
                    }
                }
                foreach (RoleModulePermissionsInfo info2 in RolePermissions.GetModelPermissionsById(this.m_RoleId))
                {
                    string name = Enum.GetName(typeof(OperateCode), info2.OperateCode);
                    foreach (XmlNode node3 in this.xmlDoc.SelectNodes("//*[@operateCode='" + name + "']"))
                    {
                        if (node3 != null)
                        {
                            ((XmlElement)node3).SetAttribute("IsChoose", "true");
                        }
                    }
                }
            }
            if (node.HasChildNodes)
            {
                foreach (XmlNode node4 in node)
                {
                    string str4          = this.Checked(node4);
                    string channelMenuId = this.GetAttributeValue(node4, "id");
                    if ((channelMenuId != "MenuMyDeskTop") && (this.GetAttributeValue(node4, "ShowOnForm") == "true"))
                    {
                        sb.Append("<tr>");
                        sb.Append("  <td style='width:100%;'>");
                        sb.Append("     <input type='checkbox' name='ModelPurview' value='" + this.GetAttributeValue(node4, "operateCode") + "' " + str4 + " id='" + channelMenuId + "'  onclick=\"javascript:CheckModel(this);\" />&nbsp;");
                        sb.Append(this.GetAttributeValue(node4, "title"));
                        sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;" + this.Description(node4));
                        sb.Append("  </td>");
                        sb.Append("</tr>");
                        this.InitChannelMenuLi(sb, channelMenuId);
                    }
                }
            }
            this.LblModelPurview.Text = sb.ToString();
        }