protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string result = JsonConvert.SerializeObject(GetMenuData());
Response.Write(result);
Response.End();
}
}
#endregion
#region 根据用户权限配置菜单
public List<Menu> GetMenuData()
{
List<Menu> listMenu = new List<Menu>();
using (var ctx = new HSQDataDataContext())
{
var list1 = from p in ctx.OT_Menu
where p.ParentMenuId == 0
select p.Id;
foreach (var l in list1)
{
var lm = from p in ctx.OT_Menu
from q in ctx.OT_Module
where p.ModuleId == q.Id && p.Id == l
select q.Name;
if (PowerCheck(lm.First(), "浏览"))
{
var list2 = from p in ctx.OT_Menu
where p.Id == l
select p;
Menu temp = new Menu();
temp.Id = list2.SingleOrDefault().Id;
temp.NavigateUrl = list2.SingleOrDefault().NavigateUrl;
temp.ParentId = (int)list2.SingleOrDefault().ParentMenuId;
temp.Title = list2.SingleOrDefault().Title;
listMenu.Add(temp);
ResvlutionMenu(l, listMenu);
}
}
}
return listMenu;
}
/// <summary>
/// 取出id菜单的子菜单
/// </summary>
/// <param name="Id">父菜单Id</param>
/// <param name="list">引用传递</param>
private void ResvlutionMenu(int Id, List<Menu> list)
{
using (var ctx = new HSQDataDataContext())
{
var lm = from p in ctx.OT_Menu
from q in ctx.OT_Module
where p.ModuleId == q.Id && p.ParentMenuId == Id
select q.Name;
if (PowerCheck(lm.First(), "浏览"))
{
var list1 = from p in ctx.OT_Menu
where p.ParentMenuId == Id
select p;
foreach (var l in list1)
{
Menu temp = new Menu();
temp.Id = l.Id;
temp.NavigateUrl = l.NavigateUrl;
temp.ParentId = (int)l.ParentMenuId;
temp.Title = l.Title;
list.Add(temp);
ResvlutionMenu(l.Id, list);
}
}
}
}
[Serializable]
public class Menu
{
public int Id { get; set; }
public int ParentId { get; set; }
public string Title { get; set; }
public string NavigateUrl { get; set; }
}