home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD28801152000.psc / TView_Mod.bas < prev   
Encoding:
BASIC Source File  |  2000-01-10  |  7.0 KB  |  181 lines

  1. Attribute VB_Name = "TView_Mod"
  2. Option Explicit
  3.  
  4. '============================================================================================================
  5. 'Used To Load The Database Into a Treview
  6. '============================================================================================================
  7. Public Function Load_DB_TO_Treeview(UserTable As String, TView As TreeView, ImgLst As ImageList) As Boolean
  8.   Dim TrvDbase As Database
  9.   Dim TrvRecSet As Recordset
  10.  'Treeview Node
  11.   Dim NodeX As Node
  12.  'Local Variables
  13.   Dim tmpName As String
  14.   Dim TmpRelation As String
  15.   Dim tCounter As Long
  16.   On Error GoTo LoadTVErr:
  17.    
  18.   TView.Nodes.Clear
  19.   
  20.  'Set The TreeView Image List
  21.   Set TView.ImageList = ImgLst
  22.  
  23.  'Add Root Node
  24.   Set NodeX = TView.Nodes.Add(, , "Root", "People", "People")
  25.  
  26.  'Set Expanded Image for the Root node
  27.   NodeX.ExpandedImage = "People"
  28.  'Expand root node so we can see what's under it
  29.   NodeX.Expanded = True
  30.      
  31.  'Create a child node under the root node called Family
  32.   Set NodeX = TView.Nodes.Add("Root", tvwChild, "Family", "Family", "Person")
  33.  'Create a child node under the root node called Spouse
  34.   Set NodeX = TView.Nodes.Add("Root", tvwChild, "Spouse", "Spouse", "Person")
  35.  'Create a child node under the root node called Friend
  36.   Set NodeX = TView.Nodes.Add("Root", tvwChild, "Friend", "Friend", "Person")
  37.  'Create a child node under the root node called Co_Worker
  38.   Set NodeX = TView.Nodes.Add("Root", tvwChild, "Co_Worker", "Co_Worker", "Person")
  39.  'Create a child node under the root node called Acquaintance
  40.   Set NodeX = TView.Nodes.Add("Root", tvwChild, "Acquaintance", "Acquaintance", "Person")
  41.   
  42.   tCounter = 0
  43.   Set TrvDbase = OpenDatabase(Database_Path & "\" & Database_Name, False, True, ";pwd=" & Database_Password)
  44.   Set TrvRecSet = TrvDbase.OpenRecordset("SELECT * FROM " & Current_LoginName)
  45.   TrvRecSet.Fields.Refresh
  46. '  TrvRecSet.MoveFirst
  47.   
  48.   If TrvRecSet.RecordCount > 0 Then
  49.    Do
  50.     tCounter = tCounter + 1
  51.     TmpRelation = TrvRecSet.Fields("Relation")
  52.     tmpName = ProperString(TrvRecSet.Fields("FirstName")) & "_" & _
  53.     ProperString(TrvRecSet.Fields("LastName"))
  54.          
  55.     Select Case TmpRelation
  56.       Case "Family"
  57.             Set NodeX = TView.Nodes.Add(TmpRelation, tvwChild, TmpRelation & Str(tCounter), tmpName, "Person2")
  58.       Case "Spouse"
  59.             Set NodeX = TView.Nodes.Add(TmpRelation, tvwChild, TmpRelation & Str(tCounter), tmpName, "Person2")
  60.       Case "Friend"
  61.             Set NodeX = TView.Nodes.Add(TmpRelation, tvwChild, TmpRelation & Str(tCounter), tmpName, "Person2")
  62.       Case "Co_Worker"
  63.             Set NodeX = TView.Nodes.Add(TmpRelation, tvwChild, TmpRelation & Str(tCounter), tmpName, "Person2")
  64.       Case "Acquaintance"
  65.             Set NodeX = TView.Nodes.Add(TmpRelation, tvwChild, TmpRelation & Str(tCounter), tmpName, "Person2")
  66.       Case Else 'Add to Acquaintance if No match found
  67.             Set NodeX = TView.Nodes.Add("Acquaintance", tvwChild, TmpRelation & Str(tCounter), tmpName, "Person2")
  68.     End Select
  69.    'Move To the Next Record
  70.     TrvRecSet.MoveNext
  71.    Loop Until TrvRecSet.EOF
  72.   End If
  73.   
  74.   TrvRecSet.Close
  75.   TrvDbase.Close
  76.   Exit Function
  77.   
  78. LoadTVErr:
  79.   If Err.Number <> 0 Then
  80.      MsgBox "Error " & Str(Err.Number) & " " & Err.Description, vbCritical + vbOKOnly
  81.      Err.Clear
  82.   End If
  83. End Function
  84. '============================================================================================================
  85. '============================================================================================================
  86.  
  87.  
  88.  
  89. '============================================================================================================
  90. 'Used To Load The Users Database Into a Treview
  91. '============================================================================================================
  92. Public Function Load_User_DB_TO_Treeview(TView As TreeView, ImgLst As ImageList) As Boolean
  93.   Dim TrvDbase As Database
  94.   Dim TrvRecSet As Recordset
  95.  'Treeview Node
  96.   Dim NodeX As Node
  97.  'Local Variables
  98.   Dim tmpName As String
  99.   Dim TmpRelation As String
  100.   'On Error GoTo LoadTVErr:
  101.    
  102.   TView.Nodes.Clear
  103.   
  104.  'Set The TreeView Image List
  105.   Set TView.ImageList = ImgLst
  106.  
  107.  'Add Root Node
  108.   Set NodeX = TView.Nodes.Add(, , "Root", "Users", "ShowFolders")
  109.  'Set Expanded Image for the Root node
  110.   NodeX.ExpandedImage = "OpenFolder"
  111.  'Set Closed Image for the Root node
  112. '  NodeX.Image = "ClosedFolder"
  113.  'Expand root node so we can see what's under it
  114.   NodeX.Expanded = True
  115.      
  116.  'Create a child node under the root node called Administrator
  117.   Set NodeX = TView.Nodes.Add("Root", tvwChild, "Administrator", "Administrator", "Crowd")
  118.  'Create a child node under the root node called User
  119.   Set NodeX = TView.Nodes.Add("Root", tvwChild, "User", "User", "Crowd")
  120.   
  121.   Set TrvDbase = OpenDatabase(Database_Path & "\" & Database_Name, False, False, ";pwd=" & Database_Password)
  122.   Set TrvRecSet = TrvDbase.OpenRecordset("SELECT * FROM Users")
  123.   
  124.  ' tCounter = 0
  125.   TrvRecSet.Fields.Refresh
  126.   If TrvRecSet.RecordCount > 0 Then
  127.    Do
  128.    ' tCounter = tCounter + 1
  129.     TmpRelation = DecryptText(TrvRecSet.Fields("AccessLevel"), Database_Password)
  130.     tmpName = DecryptText(TrvRecSet.Fields("LoginName"), Database_Password)
  131.          
  132.     Select Case TmpRelation
  133.       Case "Administrator"
  134.             Set NodeX = TView.Nodes.Add(TmpRelation, tvwChild, TmpRelation & tmpName, tmpName, "Admins")
  135.       Case "User"
  136.             Set NodeX = TView.Nodes.Add(TmpRelation, tvwChild, TmpRelation & tmpName, tmpName, "Users")
  137.     End Select
  138.    'Move To the Next Record
  139.     TrvRecSet.MoveNext
  140.    Loop Until TrvRecSet.EOF
  141.   End If
  142.   
  143.   TrvRecSet.Close
  144.   TrvDbase.Close
  145.   
  146. LoadTVErr:
  147.   If Err.Number <> 0 Then
  148.      MsgBox "Error " & Str(Err.Number) & " " & Err.Description, vbCritical + vbOKOnly
  149.      Err.Clear
  150.   End If
  151. End Function
  152. '============================================================================================================
  153. '============================================================================================================
  154.  
  155.  
  156.  
  157. '============================================================================================================
  158. 'Used To Check If A Specific Child Exist
  159. '============================================================================================================
  160. Public Function ChildExist(ParentTreeView As TreeView, pNode As String, cNode As String) As Boolean
  161.   Dim nodeChild As Node
  162.   Dim t As TreeView
  163.   Dim i As Integer
  164.   
  165.   ChildExist = False
  166.  
  167.   Set nodeChild = ParentTreeView.Nodes(pNode).Child
  168.   
  169.   Do While Not (nodeChild Is Nothing)
  170.     If UCase(nodeChild.Text) = UCase(cNode) Then
  171.        ChildExist = True
  172.        'MsgBox nodeChild.Text
  173.        Exit Function
  174.     End If
  175.     Set nodeChild = nodeChild.Next
  176.   Loop
  177. End Function
  178. '============================================================================================================
  179. '============================================================================================================
  180.  
  181.