public List <MenuInfo> GetAllMenus() { List <MenuInfo> list = new List <MenuInfo>(); if (this.Menus != null) { return(this.Menus); } string menuFilePath = ""; if (string.IsNullOrEmpty(menuFilePath) == true) { menuFilePath = MenuFilePath; } #region 从配置文件获取全部菜单 XElement xel = XElement.Load(menuFilePath); var datas = from x in xel.Descendants("MenuItem") select x; foreach (XElement d in datas) { if (d.Attribute("Visible").Value.ToLower() == "false") { continue; } MenuInfo menu = new MenuInfo(); menu.MenuID = d.Attribute("MenuID").Value; menu.MenuDes = d.Attribute("MenuDes").Value; if (d.Attribute("SystemID") != null) { menu.SystemID = d.Attribute("SystemID").Value; } else { menu.SystemID = ""; } menu.Action = d.Attribute("Action").Value; if (d.Attribute("Param") != null && !string.IsNullOrWhiteSpace(d.Attribute("Param").Value)) { menu.Action += "?" + d.Attribute("Param").Value.Replace("'", "%22"); } if (d.Attribute("Target") != null) { menu.Target = d.Attribute("Target").Value; } menu.PowerID = d.Attribute("PowerID").Value; menu.SuperID = d.Attribute("SuperID").Value; if (d.Attribute("Seq") != null && !string.IsNullOrWhiteSpace(d.Attribute("Seq").Value)) { menu.Seq = int.Parse(d.Attribute("Seq").Value); } else { menu.Seq = 1; } if (d.Attribute("Ico") != null) { menu.Ico = d.Attribute("Ico").Value; } menu.Actions = new List <ActionInfo>(); if (d.Element("Actions") != null) { foreach (XElement c in d.Element("Actions").Descendants("Action")) { ActionInfo action = new ActionInfo(); action.ContorllerName = c.Attribute("ContorllerName").Value; action.ActionName = c.Attribute("ActionName").Value; action.PowerID = c.Attribute("PowerID").Value; menu.Actions.Add(action); } } list.Add(menu); } #endregion return(list); }
/// <summary> /// 获取菜单列表 /// </summary> /// <returns>菜单列表</returns> public List <MenuInfo> GetMenuInfos(string menuFilePath) { List <MenuInfo> list = new List <MenuInfo>(); List <MenuInfo> menus = new List <MenuInfo>(); if (string.IsNullOrEmpty(menuFilePath) == true) { menuFilePath = MenuFilePath; } if (this.Menus != null) { list = this.Menus; } else { #region 从配置文件获取全部菜单 XElement xel = XElement.Load(menuFilePath); var datas = from x in xel.Descendants("MenuItem") select x; foreach (XElement d in datas) { if (d.Attribute("Visible").Value.ToLower() == "false") { continue; } MenuInfo menu = new MenuInfo(); menu.MenuID = d.Attribute("MenuID").Value; menu.MenuDes = d.Attribute("MenuDes").Value; if (d.Attribute("MenuType") != null) { menu.MenuType = d.Attribute("MenuType").Value; } else { menu.MenuType = ""; } if (d.Attribute("IsPower") != null) { menu.IsPower = bool.Parse(d.Attribute("IsPower").Value); } else { menu.IsPower = false; } if (d.Attribute("SystemID") != null) { menu.SystemID = d.Attribute("SystemID").Value; } else { menu.SystemID = ""; } menu.Action = d.Attribute("Action").Value; if (d.Attribute("Param") != null && !string.IsNullOrWhiteSpace(d.Attribute("Param").Value)) { menu.Action += "?" + d.Attribute("Param").Value.Replace("'", "%22"); } if (d.Attribute("Target") != null) { menu.Target = d.Attribute("Target").Value; } menu.PowerID = d.Attribute("PowerID").Value; menu.SuperID = d.Attribute("SuperID").Value; if (d.Attribute("Seq") != null && !string.IsNullOrWhiteSpace(d.Attribute("Seq").Value)) { menu.Seq = int.Parse(d.Attribute("Seq").Value); } else { menu.Seq = 1; } if (d.Attribute("Ico") != null) { menu.Ico = d.Attribute("Ico").Value; } menu.Actions = new List <ActionInfo>(); if (d.Element("Actions") != null) { foreach (XElement c in d.Element("Actions").Descendants("Action")) { ActionInfo action = new ActionInfo(); action.ContorllerName = c.Attribute("ContorllerName").Value; action.ActionName = c.Attribute("ActionName").Value; action.PowerID = c.Attribute("PowerID").Value; menu.Actions.Add(action); } } list.Add(menu); } #endregion } #region 添加一级菜单 var array = list.Where(i => i.SuperID == ""); foreach (MenuInfo childMenu in array) { //添加子权限 this.BuildChildItems(childMenu, list); if (this.IsPower(childMenu) == false) { continue; } if (string.IsNullOrEmpty(childMenu.Action) == false) { if (this.ActionList.ContainsKey(childMenu.Action.Substring(1)) == false) { this.ActionList.Add(childMenu.Action.Substring(1), childMenu.Action.Substring(1)); } } this.AddAction(childMenu.Actions); menus.Add(childMenu); } #endregion return(menus); }