using MESClassLibrary.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MESClassLibrary.BLL.Log;
using System.Reflection;
using System.Data;
using MESClassLibrary.DAL.User;
namespace MESClassLibrary.BLL.User
{
public class Sys_NavMenuService
{
///
/// 根据userID查询用户菜单
///
///
///
public List BuilderLeftMenu(string userID)
{
try
{
List returnList = new List();
Sys_NavMenuData dal = new Sys_NavMenuData();
DataTable dt = new DataTable();
List navList = new List();
dt = dal.BuilderLeftMenu(userID);
navList = Tool.ConvertTo(dt).ToList();
foreach (Sys_NavMenuInfo item in navList)
{
Sys_NavMenuInfo menuItem = BuilderItem(item, navList);
if (menuItem != null)
returnList.Add(menuItem);
}
return returnList;
}
catch(Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
///
/// 生成菜单list
///
///
///
///
///
public Sys_NavMenuInfo BuilderItem(Sys_NavMenuInfo item, List allItem)
{
Sys_NavMenuInfo returnItem = new Sys_NavMenuInfo();
returnItem.ItemPic = item.ItemPic;
returnItem.MenuID = item.MenuID;
returnItem.MenuName = item.MenuName;
returnItem.OrderNum = item.OrderNum;
returnItem.ParentMenuID = item.ParentMenuID;
returnItem.PowerID = item.PowerID;
returnItem.URLStr = item.URLStr;
List subItemList = new List();
StringBuilder sb = new StringBuilder();
List subList = allItem.FindAll(p => p.ParentMenuID == item.MenuID);
if (subList.Count > 0)
{
foreach (Sys_NavMenuInfo subItem in subList.OrderBy(p => p.OrderNum))
{
returnItem.SubNavMenuList.Add(subItem);
}
}
if (returnItem.SubNavMenuList.Count == 0)
return null;
else
return returnItem;
}
}
}