Dim dbAccess As New DBAccess
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
PopulateNodes(TreeView1.Nodes, 0)
End If
End Sub
Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
PopulateNodes(e.Node.ChildNodes, e.Node.Value)
End Sub
Public Sub PopulateNodes(ByVal nodes As TreeNodeCollection, Optional ByVal intParentID As Int32 = 0)
Dim dt As New DataTable()
dt = GetTreeTable()
Dim strExpression As String
strExpression = "[parentID] = " & intParentID
Dim foundRows() As DataRow
foundRows = dt.Select(strExpression)
Dim I As Integer
For I = 0 To foundRows.GetUpperBound(0)
Dim tn As New TreeNode()
tn.Text = foundRows(I).Item("TableName").ToString()
tn.Value = foundRows(I).Item("ID").ToString()
tn.NavigateUrl = foundRows(I).Item("url").ToString()
tn.Target = foundRows(I).Item("target").ToString()
tn.CollapseAll()
tn.Expand()
Dim dr() As DataRow
dr = dt.Select("[parentID] = " & tn.Value)
If dr.GetUpperBound(0) > -1 Then
tn.PopulateOnDemand = True
End If
nodes.Add(tn)
Next
End Sub
Public Function GetTreeTable() As DataTable
Dim dt As New DataTable()
Dim ds As New DataSet()
'''''''''''''''''''''''''TreeView Visible ~~~~~~~~~~~~~~~~~~~~~~@#@!~~~ by Vegas
Dim cookies As HttpCookie
cookies = Request.Cookies("PAS")
Dim workid As String = cookies("Emp_No")
Dim strPa_Rank As String = cookies("Job_Rank")
Dim super_user As String = cookies("Super_User")
If Integer.Parse(strPa_Rank) > 30 Then
If Integer.Parse(super_user) = 0 Then
dt = dbAccess.GetDataTable("select * from treeview where id<>2 and id<>4 order by id")
HttpContext.Current.Cache.Insert("Treeview", dt)
Else
dt = dbAccess.GetDataTable("select * from treeview order by id")
HttpContext.Current.Cache.Insert("Treeview", dt)
End If
Else
If Integer.Parse(super_user) = 0 Then
dt = dbAccess.GetDataTable("select * from treeview where id<>2 order by id")
HttpContext.Current.Cache.Insert("Treeview", dt)
Else
dt = dbAccess.GetDataTable("select * from treeview order by id")
HttpContext.Current.Cache.Insert("Treeview", dt)
End If
End If
Return dt
End Function
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
PopulateNodes(TreeView1.Nodes, 0)
End If
End Sub
Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
PopulateNodes(e.Node.ChildNodes, e.Node.Value)
End Sub
Public Sub PopulateNodes(ByVal nodes As TreeNodeCollection, Optional ByVal intParentID As Int32 = 0)
Dim dt As New DataTable()
dt = GetTreeTable()
Dim strExpression As String
strExpression = "[parentID] = " & intParentID
Dim foundRows() As DataRow
foundRows = dt.Select(strExpression)
Dim I As Integer
For I = 0 To foundRows.GetUpperBound(0)
Dim tn As New TreeNode()
tn.Text = foundRows(I).Item("TableName").ToString()
tn.Value = foundRows(I).Item("ID").ToString()
tn.NavigateUrl = foundRows(I).Item("url").ToString()
tn.Target = foundRows(I).Item("target").ToString()
tn.CollapseAll()
tn.Expand()
Dim dr() As DataRow
dr = dt.Select("[parentID] = " & tn.Value)
If dr.GetUpperBound(0) > -1 Then
tn.PopulateOnDemand = True
End If
nodes.Add(tn)
Next
End Sub
Public Function GetTreeTable() As DataTable
Dim dt As New DataTable()
Dim ds As New DataSet()
'''''''''''''''''''''''''TreeView Visible ~~~~~~~~~~~~~~~~~~~~~~@#@!~~~ by Vegas
Dim cookies As HttpCookie
cookies = Request.Cookies("PAS")
Dim workid As String = cookies("Emp_No")
Dim strPa_Rank As String = cookies("Job_Rank")
Dim super_user As String = cookies("Super_User")
If Integer.Parse(strPa_Rank) > 30 Then
If Integer.Parse(super_user) = 0 Then
dt = dbAccess.GetDataTable("select * from treeview where id<>2 and id<>4 order by id")
HttpContext.Current.Cache.Insert("Treeview", dt)
Else
dt = dbAccess.GetDataTable("select * from treeview order by id")
HttpContext.Current.Cache.Insert("Treeview", dt)
End If
Else
If Integer.Parse(super_user) = 0 Then
dt = dbAccess.GetDataTable("select * from treeview where id<>2 order by id")
HttpContext.Current.Cache.Insert("Treeview", dt)
Else
dt = dbAccess.GetDataTable("select * from treeview order by id")
HttpContext.Current.Cache.Insert("Treeview", dt)
End If
End If
Return dt
End Function
End Class
表结构:
id | parentID | tableName | url | target | expanded |
1 | 0 | 绩效考核系统 | |||
2 | 1 | 管理者设定 |