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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
| Public Class VMBase
Implements INotifyPropertyChanged
Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Public Sub OnPropertyChanged(propname As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propname))
End Sub
End Class
Public Class Employe
Inherits VMBase
Private mnom As String
Public Property Nom() As String
Get
Return mnom
End Get
Set(value As String)
mnom = value
OnPropertyChanged("Nom")
End Set
End Property
Private mselectedNode As Employe
Public Property SelectedNode() As Employe
Get
Return mselectedNode
End Get
Set(ByVal value As Employe)
If mselectedNode Is value Then
Return
End If
Dim prev As Employe = mselectedNode
mselectedNode = value
If prev IsNot Nothing Then
prev.Selected = False
End If
If mselectedNode IsNot Nothing Then
mselectedNode.Selected = True
End If
OnPropertyChanged("SelectedNode")
End Set
End Property
Private mselected As Boolean
Public Property Selected() As Boolean
Get
Return mselected
End Get
Set(ByVal value As Boolean)
mselected = value
OnPropertyChanged("Selected")
End Set
End Property
Public Sub New()
Nom = ""
End Sub
Public Sub New(pemploy As String)
Me.New()
Nom = pemploy
End Sub
End Class
Imports System.Collections.ObjectModel
Public Class Service
Inherits VMBase
Private mnom As String
Public Property Nom() As String
Get
Return mnom
End Get
Set(value As String)
mnom = value
OnPropertyChanged("Nom")
End Set
End Property
Private magent As String
Public Property NomAgent() As String
Get
Return magent
End Get
Set(value As String)
magent = value
OnPropertyChanged("NomAgent")
End Set
End Property
Private memployes As ObservableCollection(Of Employe)
Public Property Employes() As Observablecollection(Of Employe)
Get
Return memployes
End Get
Set(ByVal value As ObservableCollection(Of Employe))
memployes = value
OnPropertyChanged("Employes")
End Set
End Property
Private mselectedNode As Service
Public Property SelectedNode() As Service
Get
Return mselectedNode
End Get
Set(ByVal value As Service)
If mselectedNode Is value Then
Return
End If
Dim prev As Service = mselectedNode
mselectedNode = value
If prev IsNot Nothing Then
prev.Selected = False
End If
If mselectedNode IsNot Nothing Then
mselectedNode.Selected = True
End If
OnPropertyChanged("SelectedNode")
End Set
End Property
Private mselected As Boolean
Public Property Selected() As Boolean
Get
Return mselected
End Get
Set(ByVal value As Boolean)
mselected = value
OnPropertyChanged("Selected")
End Set
End Property
Public Sub New()
Nom = ""
memployes = New ObservableCollection(Of Employe)()
End Sub
Public Sub New(svcnom As String)
Me.new()
Nom = svcnom
End Sub
End Class
Imports System.Collections.ObjectModel
Public Class Departement
Inherits VMBase
Private mnom As String
Public Property Nom() As String
Get
Return magent
End Get
Set(value As String)
magent = value
OnPropertyChanged("Nom")
End Set
End Property
Private magent As String
Public Property NomAgent() As String
Get
Return magent
End Get
Set(value As String)
magent = value
OnPropertyChanged("NomAgent")
End Set
End Property
Private mservices As ObservableCollection(Of Service)
Public Property Services As ObservableCollection(Of Service)
Get
Return mservices
End Get
Set(value As ObservableCollection(Of Service))
mservices = value
OnPropertyChanged("Services")
End Set
End Property
Private mselectedNode As Service
Public Property SelectedNode() As Service
Get
Return mselectedNode
End Get
Set(ByVal value As Service)
If mselectedNode Is value Then
Return
End If
Dim prev As Service = mselectedNode
mselectedNode = value
If prev IsNot Nothing Then
prev.Selected = False
End If
If mselectedNode IsNot Nothing Then
mselectedNode.Selected = True
End If
OnPropertyChanged("SelectedNode")
End Set
End Property
Private mselected As Boolean
Public Property Selected() As Boolean
Get
Return mselected
End Get
Set(ByVal value As Boolean)
mselected = value
OnPropertyChanged("Selected")
End Set
End Property
Public Sub New()
Nom = ""
mservices = New ObservableCollection(Of Service)()
End Sub
Public Sub New(depnom As String)
Me.new()
Nom = depnom
End Sub
End Class
Imports System.Collections.ObjectModel
Public Class MainVM
Inherits VMBase
Private mdepartements As ObservableCollection(Of Departement)
Public Property Departements() As ObservableCollection(Of Departement)
Get
Return mdepartements
End Get
Set(ByVal value As ObservableCollection(Of Departement))
mdepartements = value
OnPropertyChanged("Departements")
End Set
End Property
Private mselectedNode As Departement
Public Property SelectedNode() As Departement
Get
Return mselectedNode
End Get
Set(ByVal value As Departement)
If mselectedNode Is value Then
Return
End If
Dim prev As Departement = mselectedNode
mselectedNode = value
If prev IsNot Nothing Then
prev.Selected = False
End If
If mselectedNode IsNot Nothing Then
mselectedNode.Selected = True
End If
OnPropertyChanged("SelectedNode")
End Set
End Property
Private mselected As Boolean
Public Property Selected() As Boolean
Get
Return mselected
End Get
Set(ByVal value As Boolean)
mselected = value
OnPropertyChanged("Selected")
End Set
End Property
Private mexpanded As Boolean
Public Property Expanded() As Boolean
Get
Return mexpanded
End Get
Set(ByVal value As Boolean)
mexpanded = value
OnPropertyChanged("Expanded")
End Set
End Property
Public Sub New()
mdepartements = New ObservableCollection(Of Departement)
LoadAll()
End Sub
Private Sub LoadAll()
'add departements
Dim dept1, dept2, dept3 As Departement
dept1 = New Departement("DotNet")
dept2 = New Departement("Club Professionels")
dept3 = New Departement("Systemes")
Departements.Add(dept1)
Departements.Add(dept2)
Departements.Add(dept3)
'add services to dept1
Dim svc1, svc2, svc3 As Service
svc1 = New Service("Forum VB.Net")
svc2 = New Service("Forum C++")
dept1.Services.Add(svc1)
dept1.Services.Add(svc2)
'add employes to svc1,svc2
Dim emp1, emp2, emp3 As Employe
emp1 = New Employe("Employe1 VB.Net")
emp2 = New Employe("Employe2 VB.Net")
svc1.Employes.Add(emp1)
svc1.Employes.Add(emp2)
emp1 = New Employe("Employe1 Forum C++")
emp2 = New Employe("Employe2 Forum C++")
emp3 = New Employe("Employe3 Forum C++")
svc2.Employes.Add(emp1)
svc2.Employes.Add(emp2)
svc2.Employes.Add(emp3)
'add services to dept2
svc1 = New Service("Actualites")
svc2 = New Service("Taverne")
dept2.Services.Add(svc1)
dept2.Services.Add(svc2)
'add services to dept3
svc1 = New Service("Hardware")
svc2 = New Service("Windows")
dept3.Services.Add(svc1)
dept3.Services.Add(svc2)
'add employes to svc1,svc2
emp1 = New Employe("Employe1 Hardware")
svc1.Employes.Add(emp1)
emp2 = New Employe("Employe1,Windows")
emp3 = New Employe("Employe2,Windows")
svc2.Employes.Add(emp2)
svc2.Employes.Add(emp3)
End Sub
End Class |
Partager