using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Student.Models;
using Student.BLL;
using System.Collections.Generic;
public partial class SysFunTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
LoginInfo user = Session[“CurrentUser”] as LoginInfo;
if (!Page.IsPostBack)
{
DisplayUserMenu(user);
}
}
protected void DisplayUserMenu(LoginInfo user)
{
tvUserRightMenu.Nodes.Clear();
IList<SysFun> parentSysFun = SysFunManager.GetAllByTiaojian(user.URole.RoleId);
if (parentSysFun.Count != 0)
{
foreach (SysFun sfParent in parentSysFun)
{
string nodeId = sfParent.NodeId.ToString();//第一层节点id
string displayName = sfParent.DisplayName;//第一层节点显示名称
TreeNode fatherNode = this.CreatTreeNode(displayName, nodeId, “”, “Image/fclose.gif”);//根据节点信息,创建第一层节点
CreateChildTree(sfParent.NodeId.ToString(), user.URole.RoleId, fatherNode);//创建子节点
tvUserRightMenu.Nodes.Add(fatherNode);//将第一层节点加入到用户权限TreeView中
}
}
else
{
Response.Write(“<script>alert(‘您没有这些权限!‘)</script>”);
}
}
//创建第二层节点
private void CreateChildTree(string nodeId, int roleId, TreeNode fatherNode)
{
IList<SysFun> childSysFun = SysFunManager.GetAllZiByFu(Convert.ToInt32(nodeId), roleId);//获得父节点为nodeId的所有子节点
foreach (SysFun sfChild in childSysFun)
{
string childNodeId = sfChild.NodeId.ToString();//第二层节点id
string childDisplayName = sfChild.DisplayName;//第二层节点名称
string nodeURL = ResolveUrl(sfChild.NodeURL.Trim());//将路径转换为在客户端可用的URL
TreeNode childNode = this.CreatTreeNode(childDisplayName, childNodeId, nodeURL, “Image/doc.gif”);//根据节点信息,创建第二层节点
AddTree(fatherNode, childNode);//将子节点加入到父节点中
}
}
/// <summary>
/// 创建一个树节点,返回一个树节点对象,参数内容是:
/// 节点名称,节点ID,链接地址,正常图标,展开后的图标
/// </summary>
private TreeNode CreatTreeNode(string strText, string strId, string strUrl, string strImg)
{
TreeNode newNode = new TreeNode();
newNode.Text = strText;
newNode.Value = strId;
newNode.NavigateUrl = strUrl;
newNode.ImageUrl = strImg;
return newNode;
}
/// <summary>
/// 把子节点添加到父节点当中
/// </summary>
private void AddTree(TreeNode FatherNode, TreeNode ChildNode)
{
FatherNode.ChildNodes.Add(ChildNode);
}
}