Public Class Edu Public ReadOnly Property NoOfRegions() As Integer Get Return Regions.Count End Get End Property Public ReadOnly Property NoOfSchools() As Integer Get Dim C As Integer, Itm As Region For Each Itm In Regions C += Itm.NoOfSchools Next Return C End Get End Property Public ReadOnly Property NoOfStudents() As Integer Get Dim C As Integer, Itm As Region For Each Itm In Regions C += Itm.NoOfStudents Next Return C End Get End Property Public ReadOnly Regions As New RegionCollection() Public Class RegionCollection Inherits CollectionBase Friend Sub New() MyBase.New() End Sub Public Function Add(ByVal Name As String) As Region Dim R As New Region(Name) list.Add(R) Return R End Function Public Property Item(ByVal index As Integer) As Region Get If index > Count - 1 Or index < 0 Then Dim Exc As New Exception("لا يوجد عنصر بهذا الرقم.") Throw Exc Else Return CType(List.Item(index), Region) End If End Get Set(ByVal Value As Region) If index > Count - 1 Or index < 0 Then Dim Exc As New Exception("لا يوجد عنصر بهذا الرقم.") Throw Exc Else List.Item(index) = Value End If End Set End Property Public Sub Remove(ByVal Item As Region) List.Remove(Item) End Sub End Class Class Region Public Name As String Public ReadOnly Property NoOfSchools() As Integer Get Return Schools.Count End Get End Property Public ReadOnly Property NoOfStudents() As Integer Get Dim Itm As School, C As Integer For Each Itm In Schools C += Itm.NoOfStudents Next End Get End Property Friend Sub New(ByVal Name As String) MyBase.New() Me.Name = Name End Sub Public ReadOnly Schools As SchoolCollection Public Class SchoolCollection Inherits CollectionBase Friend Sub New() MyBase.New() End Sub Public Function Add(ByVal Stage As School.Stages, ByVal Name As String) As School Dim S As New School(Stage, Name) list.Add(S) Return S End Function Public Property Item(ByVal index As Integer) As School Get If index > Count - 1 Or index < 0 Then Dim Exc As New Exception("لا يوجد عنصر بهذا الرقم.") Throw Exc Else Return CType(List.Item(index), School) End If End Get Set(ByVal Value As School) If index > Count - 1 Or index < 0 Then Dim Exc As New Exception("لا يوجد عنصر بهذا الرقم.") Throw Exc Else List.Item(index) = Value End If End Set End Property Public Sub Remove(ByVal Item As School) List.Remove(Item) End Sub End Class Public Class School Public ReadOnly Property NoOfStudents() As Integer Get Return Students.Count End Get End Property Public Enum Stages ابتدائي إعدادي ثانوي صناعي End Enum Public Stage As Stages Public Name As String Friend Sub New(ByVal Stage As Stages, ByVal Name As String) MyBase.New() Me.Stage = Stage Me.Name = Name End Sub '-----------------------------------مجموعة الطلاب---------------------------- Public ReadOnly Students As New StudentCollection(Stage) Public Class StudentCollection Inherits CollectionBase Dim Stage As Stages 'Friend Sub New() ' MyBase.New() 'End Sub Friend Sub New(ByVal Stage As Stages) MyBase.New() Me.Stage = Stage End Sub Public Function Add(ByVal Name As String, ByVal Year As Integer) As Student Dim S As New Student(Name, Year, Stage) list.Add(S) Return S End Function Public Property Item(ByVal Index As Integer) As Student Get If Index > Count - 1 Or Index < 0 Then Dim Exc As New Exception("لا يوجد عنصر بهذا الرقم.") Throw Exc Else Return CType(List(Index), Student) End If End Get Set(ByVal Value As Student) If Index > Count - 1 Or Index < 0 Then Dim Exc As New Exception("لا يوجد عنصر بهذا الرقم.") Throw Exc Else List(Index) = Value End If End Set End Property Public Sub Remove(ByVal Item As Student) list.Remove(Item) End Sub End Class ' ---------------------------------خليّة الطالب------------------------------- Public Class Student Public Name As String Dim Stage As Stages Friend Sub New(ByVal Name As String, ByVal Year As Integer, ByVal Stage As Stages) MyBase.New() Me.Name = Name Me.Year = Year Me.Stage = Stage End Sub Dim Yr As Integer Public Property Year() As Integer Get Return Yr End Get Set(ByVal Value As Integer) Dim exc As New Exception("قيمة غير منطقيّة") If Value < 1 And Value > 6 Then Throw exc Exit Property End If Select Case Stage Case Stages.إعدادي, Stages.ثانوي, Stages.صناعي If Value > 3 Then Throw exc Exit Property End If End Select Yr = Value End Set End Property End Class End Class End Class End Class