• 【Vegas原创】TreeView操作数据库的使用方法(VB)


         Dim dbAccess As New DBAccess

            
    Protected Sub Page_Load(ByVal sender As ObjectByVal 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 ObjectByVal 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 管理者设定      
  • 相关阅读:
    flask_日期和时间
    使用SQLAlchemy对博客文章进行分页
    P2725 邮票 Stamps
    P2679 子串
    P3396 哈希冲突
    P1754 球迷购票问题
    P1504 积木城堡
    P1244 青蛙过河
    CSP-S 2019 考试分析
    2019.11.11 模拟赛 T2 乘积求和
  • 原文地址:https://www.cnblogs.com/amadeuslee/p/3744606.html
Copyright © 2020-2023  润新知