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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
'sans changement
Public Class My_nodeBis
Public node_id As Integer
Public type_id As Integer
Public name As String
Public X As Single
Public Y As Single
Public Water_company As String
Public WRZ As String
Public RWSM_type As String
End Class
'Association au lieu d'heritage
Public Class My_ReservoirBis
Public Capacity As Integer
Public Initial_Storage As Integer
'prop avec reference sur noeud support
Private m_refnode As My_nodeBis
Public Sub New(ByVal objNode As My_nodeBis)
Me.m_refnode = objNode
End Sub
'a supprimer
'Sub Fromnode(ByVal objNode As My_nodeBis)
' Me.m_refnode = objNode
'End Sub
Public Property RefNode() As My_nodeBis
Get
Return m_refnode
End Get
Set(ByVal value As My_nodeBis)
m_refnode = value
End Set
End Property
End Class
'Dicos par attribut noeud
Public Class My_WRZBis
Public Water_company As String
Public WRZ As String
'Dico par type de noeud
Public WRZ_Reservoir As New Dictionary(Of String, My_ReservoirBis)
Public WRZ_WTW As New Dictionary(Of String, My_nodeBis)
Public WRZ_JunctionBis As New Dictionary(Of String, My_nodeBis)
Public WRZ_Dembis As New Dictionary(Of String, My_nodeBis)
Public WRZ_Dem As New Dictionary(Of String, My_nodeBis)
Public Sub New()
End Sub
End Class
Public Class Form2
Dim Dico_NodesBis As New Dictionary(Of Integer, My_nodeBis)
Dim Dico_WRZBis As New Dictionary(Of String, My_WRZBis)
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim SQLreader1 As SqlClient.SqlDataReader = SQLcommand1.ExecuteReader()
While SQLreader1.Read()
Dim Anode As New My_nodeBis
Anode.node_id = SQLreader1(0)
Anode.type_id = SQLreader1(2)
Anode.name = SQLreader1(3)
Anode.X = SQLreader1(5)
Anode.Y = SQLreader1(6)
Anode.Water_company = SQLreader1(7)
Anode.WRZ = SQLreader1(8)
Anode.RWSM_type = SQLreader1(9)
Dico_NodesBis.Add(Anode.node_id, Anode)
Dim AWRZ As My_WRZBis
If Dico_WRZBis.ContainsKey(Anode.WRZ) = False Then
'nouvelle zone
AWRZ = New My_WRZBis
AWRZ.Water_company = Anode.Water_company
AWRZ.WRZ = Anode.WRZ
Dico_WRZBis.Add(AWRZ.WRZ, AWRZ)
End If
AWRZ = Dico_WRZBis(Anode.WRZ)
Select Case Anode.RWSM_type
Case "WRZ Reservoir"
Dim objReservoir As New My_ReservoirBis(Anode)
AWRZ.WRZ_Reservoir.Add(Anode.name, objReservoir)
Case "WRZ WTW"
AWRZ.WRZ_WTW.Add(Anode.name, Anode)
Case "WRZ Junction"
AWRZ.WRZ_JunctionBis.Add(Anode.name, Anode)
Case "WRZ Dembis"
AWRZ.WRZ_Dembis.Add(Anode.name, Anode)
Case "WRZ Dem"
AWRZ.WRZ_Dem.Add(Anode.name, Anode)
End Select
'If Anode.RWSM_type = "WRZ Reservoir" Then
' Dico_WRZ(Anode.WRZ).WRZ_Reservoir.Fromnode(Dico_nodes(Anode.node_id))
'ElseIf Anode.RWSM_type = "WRZ WTW" Then
' Dico_WRZ(Anode.WRZ).WRZ_WTW = Dico_nodes(Anode.node_id)
'ElseIf Anode.RWSM_type = "WRZ Junction" Then
' Dico_WRZ(Anode.WRZ).WRZ_Junction = Dico_nodes(Anode.node_id)
'ElseIf Anode.RWSM_type = "WRZ Dembis" Then
' Dico_WRZ(Anode.WRZ).WRZ_Dembis = Dico_nodes(Anode.node_id)
'ElseIf Anode.RWSM_type = "WRZ Dem" Then
' Dico_WRZ(Anode.WRZ).WRZ_Dem = Dico_nodes(Anode.node_id)
'End If
End While
SQLreader1.Close()
End Sub
'Iteration dans les differents Dicos
Private Sub btnIteration_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIteration.Click
'Find zone
Dim nameZone As String
Dim currentZone As My_WRZBis
For Each kv As KeyValuePair(Of String, My_WRZBis) In Dico_WRZBis
nameZone = kv.Key
currentZone = kv.Value
'Display namezone,type zone
MessageBox.Show(nameZone & currentZone.Water_company & currentZone.WRZ)
Next
'Find node
For Each currentNode As My_nodeBis In Dico_NodesBis.Values
nameZone = currentNode.WRZ
If Dico_WRZBis.ContainsKey(nameZone) Then
'Display reservoir
For Each xReservoir As My_ReservoirBis In Dico_WRZBis(nameZone).WRZ_Reservoir.Values
MessageBox.Show(xReservoir.RefNode.name & xReservoir.RefNode.WRZ & xReservoir.Capacity)
Next
'Display WRZ Junction
For Each xNodeJunction As My_nodeBis In Dico_WRZBis(nameZone).WRZ_JunctionBis.Values
MessageBox.Show(xNodeJunction.name & xNodeJunction.WRZ)
Next
End If
Next
End Sub
'Recherche d'un element dans les differents Dicos
Private Sub btnRecherche_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecherche.Click
'Retrouve une zone dans Values avec la cle
Dim nameZone As String = "Zone1"
Dim currentZone As My_WRZBis = Dico_WRZBis(nameZone)
'Retrouve un noeud type "WRZ Reservoir" avec la cle "nom du noeud support"
Dim xnode1 As My_nodeBis
'Test d'existance de cle est -toujour indispensable- dans un dico.
If Dico_WRZBis(nameZone).WRZ_Reservoir.ContainsKey(xnode1.name) Then
Dim currentReservoir As My_ReservoirBis = Dico_WRZBis(nameZone).WRZ_Reservoir(xnode1.name)
End If
'Retrouve un noeud type "WRZ Junction" avec la cle "nom du noeud support"
Dim xnode2 As My_nodeBis
'Test d'existance de cle est -toujour indispensable- dans un dico.
If Dico_WRZBis(nameZone).WRZ_JunctionBis.ContainsKey(xnode2.name) Then
Dim currentNodeJunction As My_nodeBis = Dico_WRZBis(nameZone).WRZ_JunctionBis(xnode2.name)
End If
End Sub
End Class |
Partager