1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
Imports MySql.Data.MySqlClient
Imports MyDll.MyDll
Public Class FrmUser
Dim MyCmd As MySqlCommand
Dim MyDr As MySqlDataReader
Dim Requette As String
Dim z1, z2, z3, z4, z5, z6, z7, z8, z9 As String
Private Sub FrmUser_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Requette = "select distinct nom from usertable where noeud<>'x' order by nom"
MyCmd = New MySqlCommand(Requette, MyDb)
MyDr = MyCmd.ExecuteReader
While MyDr.Read()
List1.Items.Add(MyDr.GetValue(0).ToString())
End While
MyDr.Close()
RemplirTreeView()
Catch ex As Exception
MessageBox.Show(ex.Message, "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub List1_Click(sender As Object, e As EventArgs) Handles List1.SelectedIndexChanged
TxtUser.Text = List1.SelectedItem
TxtUser.Enabled = False
RemplirTreeView()
End Sub
Private Sub RemplirTreeView()
Try
TreeView1.Nodes.Clear()
If TxtUser.Text = "" And TxtPwd.Text = "" Then Exit Sub
TxtPwd.Text = ""
Requette = "select distinct pass from usertable where nom='" & TxtUser.Text & "' and app='" & My.Application.Info.AssemblyName & "' and autoris<>3"
MyCmd = New MySqlCommand(Requette, MyDb)
MyDr = MyCmd.ExecuteReader
While MyDr.Read()
TxtPwd.Text = MyDr.GetValue(0).ToString()
End While
MyDr.Close()
Requette = "select * from usertable where app='" & My.Application.Info.AssemblyName & "' and nom='" & TxtUser.Text & "' order by cle"
MyCmd = New MySqlCommand(Requette, MyDb)
MyDr = MyCmd.ExecuteReader
While MyDr.Read()
Dim wCle As String = MyDr.GetValue(4).ToString()
Dim wCaption As String = MyDr.GetValue(6).ToString()
Dim wAutoris As Integer = MyDr.GetValue(5) - 1
z1 = wCle.Substring(0, 2)
With TreeView1
If wCle.Length = 2 Then
.Nodes.Add(wCle, wCaption, wAutoris, wAutoris)
ElseIf wCle.Length = 3 Then
.Nodes(z1).Nodes.Add(wCle, wCaption, wAutoris, wAutoris)
ElseIf wCle.Length = 4 Then
z2 = wCle.Substring(0, 3)
.Nodes(z1).Nodes(z2).Nodes.Add(wCle, wCaption, wAutoris, wAutoris)
ElseIf wCle.Length = 5 Then
z3 = wCle.Substring(0, 4)
.Nodes(z1).Nodes(z2).Nodes(z3).Nodes.Add(wCle, wCaption, wAutoris, wAutoris)
ElseIf wCle.Length = 6 Then
z4 = wCle.Substring(0, 5)
.Nodes(z1).Nodes(z2).Nodes(z3).Nodes(z4).Nodes.Add(wCle, wCaption, wAutoris, wAutoris)
ElseIf wCle.Length = 7 Then
z5 = wCle.Substring(0, 6)
.Nodes(z1).Nodes(z2).Nodes(z3).Nodes(z4).Nodes(z5).Nodes.Add(wCle, wCaption, wAutoris, wAutoris)
ElseIf wCle.Length = 8 Then
z6 = wCle.Substring(0, 7)
.Nodes(z1).Nodes(z2).Nodes(z3).Nodes(z4).Nodes(z5).Nodes(z6).Nodes.Add(wCle, wCaption, wAutoris, wAutoris)
ElseIf wCle.Length = 9 Then
z7 = wCle.Substring(0, 8)
.Nodes(z1).Nodes(z2).Nodes(z3).Nodes(z4).Nodes(z5).Nodes(z6).Nodes(z7) _
.Nodes.Add(wCle, wCaption, wAutoris, wAutoris)
ElseIf wCle.Length = 10 Then
z8 = wCle.Substring(0, 9)
.Nodes(z1).Nodes(z2).Nodes(z3).Nodes(z4).Nodes(z5).Nodes(z6).Nodes(z7) _
.Nodes(z8).Nodes.Add(wCle, wCaption, wAutoris, wAutoris)
ElseIf wCle.Length = 10 Then
z9 = wCle.Substring(0, 10)
.Nodes(z1).Nodes(z2).Nodes(z3).Nodes(z4).Nodes(z5).Nodes(z6).Nodes(z7) _
.Nodes(z8).Nodes(z9).Nodes.Add(wCle, wCaption, wAutoris, wAutoris)
End If
End With
End While
MyDr.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub TreeView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles TreeView1.MouseDoubleClick, TreeView1.LostFocus
Dim i As Integer = TreeView1.SelectedNode.SelectedImageIndex
i = i - 1
If i < 0 Then i = 2
TreeView1.SelectedNode.SelectedImageIndex = i
End Sub
End Class |
Partager