|
发个我的代码供楼主参考
前台:
/// <summary>
/// 树型菜单
/// </summary>
/// <returns></returns>
private FineUI.Tree GetTree(Guid rootId)
{
AccountEntity Me = Session["Account"] as AccountEntity;
FineUI.Tree tree = new Tree();
tree.AutoScroll = true;
tree.EnableArrows = true;
tree.EnableLines = false;
tree.ShowBorder = false;
tree.ShowHeader = false;
//动态加载下级节点
tree.AutoLeafIdentification = false;
tree.NodeLazyLoad += Tree_NodeLazyLoad;
//获取一级节点
Menus menuBll = new Menus();
bll.Roles bll = new abcebiz.bll.Roles();
Collection<RolesViewEntity> roles = bll.SelectRolesByParentId(rootId, Me.GroupId);
foreach (RolesViewEntity ro in roles)
{
FineUI.TreeNode node = new FineUI.TreeNode();
node.Text = ro.Name;
node.NodeID = ro.MenuId.ToString();
if (menuBll.SelectByParentId(ro.MenuId).Count > 0)
{
node.Leaf = false;
}
else
{
node.Leaf = true;
node.NavigateUrl = ro.URL;
//node.OnClientClick = mainTabStrip.GetAddTabReference(menu.Name, menu.URL, menu.Name, true);
}
tree.Nodes.Add(node);
}
return tree;
}
/// <summary>
/// 动态加载下级菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Tree_NodeLazyLoad(object sender, FineUI.TreeNodeEventArgs e)
{
AccountEntity Me = Session["Account"] as AccountEntity;
e.Node.Expanded = true;
Menus menuBll = new Menus();
Guid ParentId = ValidateHelper.GetNullableGuid(e.NodeID);
bll.Roles bll = new abcebiz.bll.Roles();
Collection<RolesViewEntity> roles = bll.SelectRolesByParentId(ParentId, Me.GroupId);
foreach (RolesViewEntity ro in roles)
{
FineUI.TreeNode node = new FineUI.TreeNode();
node.Text = ro.Name;
node.NodeID = ro.MenuId.ToString();
if (menuBll.SelectByParentId(ro.MenuId).Count > 0)
{
node.Leaf = false;
}
else
{
node.Leaf = true;
//node.OnClientClick = mainTabStrip.GetAddTabReference(menu.Name, menu.URL, menu.Name, true);
node.NavigateUrl = ro.URL;
}
e.Node.Nodes.Add(node);
}
}
BLL:
/// <summary>
/// 根据菜单父ID和用户组ID查询 Roles 视图中的指定记录
/// </summary>
/// <param name="ParentId">菜单父ID</param>
/// <param name="GroupId">用户组ID</param>
/// <returns></returns>
public virtual Collection<RolesViewEntity> SelectRolesByParentId(Guid ParentId, Guid GroupId)
{
return dal.SelectRolesByParentId(ParentId, GroupId);
}
DAL:
public virtual Collection<RolesViewEntity> SelectRolesByParentId(Guid ParentId, Guid GroupId)
{
string sql = @"
SELECT *
FROM
[RolesView]
WHERE
[ParentId]=@ParentId
AND
[AccountGroupId] = @AccountGroupId
AND
[CanRead]=1
AND
[visible]=1
ORDER BY Sequence
";
SqlParameter[] args = new SqlParameter[]
{
Parameter.Menus.ParentId,
Parameter.Roles.AccountGroupId
};
args[0].Value = ParentId;
args[1].Value = GroupId;
return RolesViewEntity.FillCollection(SqlHelper.ExecuteReader(CommandType.Text, sql, args));
}
SQL SERVER做个视图,把MENUS跟ROLES做到一起
|
|