Public Class ControlPanelForm
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents txtClassCode As System.Windows.Forms.TextBox
    Friend WithEvents lblCodeCaption As System.Windows.Forms.Label
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents txtFirst As System.Windows.Forms.TextBox
    Friend WithEvents dtBirth As System.Windows.Forms.DateTimePicker
    Friend WithEvents txtLast As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents cmdClose As System.Windows.Forms.Button
    Friend WithEvents cmdAdd As System.Windows.Forms.Button
    Friend WithEvents lstChildren As System.Windows.Forms.ListBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents cmdGetYoungest As System.Windows.Forms.Button

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ControlPanelForm))
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.lstChildren = New System.Windows.Forms.ListBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.cmdAdd = New System.Windows.Forms.Button
        Me.Label2 = New System.Windows.Forms.Label
        Me.cmdGetYoungest = New System.Windows.Forms.Button
        Me.txtLast = New System.Windows.Forms.TextBox
        Me.dtBirth = New System.Windows.Forms.DateTimePicker
        Me.txtFirst = New System.Windows.Forms.TextBox
        Me.txtClassCode = New System.Windows.Forms.TextBox
        Me.lblCodeCaption = New System.Windows.Forms.Label
        Me.cmdClose = New System.Windows.Forms.Button
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.lstChildren)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.cmdAdd)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.cmdGetYoungest)
        Me.GroupBox1.Controls.Add(Me.txtLast)
        Me.GroupBox1.Controls.Add(Me.dtBirth)
        Me.GroupBox1.Controls.Add(Me.txtFirst)
        Me.GroupBox1.Location = New System.Drawing.Point(8, 16)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(308, 268)
        Me.GroupBox1.TabIndex = 4
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Panel Sterowania"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(12, 128)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(52, 12)
        Me.Label4.TabIndex = 7
        Me.Label4.Text = "Dzieci:"
        '
        'lstChildren
        '
        Me.lstChildren.Location = New System.Drawing.Point(12, 144)
        Me.lstChildren.Name = "lstChildren"
        Me.lstChildren.Size = New System.Drawing.Size(280, 108)
        Me.lstChildren.TabIndex = 6
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(12, 92)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(36, 12)
        Me.Label3.TabIndex = 4
        Me.Label3.Text = "Data:"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(12, 36)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(36, 12)
        Me.Label1.TabIndex = 4
        Me.Label1.Text = "Imię:"
        '
        'cmdAdd
        '
        Me.cmdAdd.Location = New System.Drawing.Point(200, 32)
        Me.cmdAdd.Name = "cmdAdd"
        Me.cmdAdd.Size = New System.Drawing.Size(88, 20)
        Me.cmdAdd.TabIndex = 3
        Me.cmdAdd.Text = "Dodaj Dziecko"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(12, 64)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(52, 12)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "Nazwisko:"
        '
        'cmdGetYoungest
        '
        Me.cmdGetYoungest.Location = New System.Drawing.Point(200, 88)
        Me.cmdGetYoungest.Name = "cmdGetYoungest"
        Me.cmdGetYoungest.Size = New System.Drawing.Size(88, 20)
        Me.cmdGetYoungest.TabIndex = 5
        Me.cmdGetYoungest.Text = "Najmłodsze"
        '
        'txtLast
        '
        Me.txtLast.Location = New System.Drawing.Point(72, 59)
        Me.txtLast.Name = "txtLast"
        Me.txtLast.Size = New System.Drawing.Size(112, 21)
        Me.txtLast.TabIndex = 1
        '
        'dtBirth
        '
        Me.dtBirth.Format = System.Windows.Forms.DateTimePickerFormat.[Short]
        Me.dtBirth.Location = New System.Drawing.Point(72, 88)
        Me.dtBirth.Name = "dtBirth"
        Me.dtBirth.Size = New System.Drawing.Size(112, 21)
        Me.dtBirth.TabIndex = 2
        '
        'txtFirst
        '
        Me.txtFirst.Location = New System.Drawing.Point(72, 32)
        Me.txtFirst.Name = "txtFirst"
        Me.txtFirst.Size = New System.Drawing.Size(112, 21)
        Me.txtFirst.TabIndex = 0
        '
        'txtClassCode
        '
        Me.txtClassCode.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtClassCode.BackColor = System.Drawing.Color.White
        Me.txtClassCode.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtClassCode.ForeColor = System.Drawing.Color.DarkGreen
        Me.txtClassCode.Location = New System.Drawing.Point(332, 32)
        Me.txtClassCode.Multiline = True
        Me.txtClassCode.Name = "txtClassCode"
        Me.txtClassCode.ReadOnly = True
        Me.txtClassCode.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtClassCode.Size = New System.Drawing.Size(264, 252)
        Me.txtClassCode.TabIndex = 7
        Me.txtClassCode.Text = resources.GetString("txtClassCode.Text")
        '
        'lblCodeCaption
        '
        Me.lblCodeCaption.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCodeCaption.Location = New System.Drawing.Point(332, 12)
        Me.lblCodeCaption.Name = "lblCodeCaption"
        Me.lblCodeCaption.Size = New System.Drawing.Size(172, 20)
        Me.lblCodeCaption.TabIndex = 2
        Me.lblCodeCaption.Text = "Kod klasy NuclearFamily:"
        '
        'cmdClose
        '
        Me.cmdClose.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cmdClose.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cmdClose.Location = New System.Drawing.Point(504, 300)
        Me.cmdClose.Name = "cmdClose"
        Me.cmdClose.Size = New System.Drawing.Size(92, 28)
        Me.cmdClose.TabIndex = 8
        Me.cmdClose.Text = "Zamknij"
        '
        'ControlPanelForm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.CancelButton = Me.cmdClose
        Me.ClientSize = New System.Drawing.Size(604, 334)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.cmdClose)
        Me.Controls.Add(Me.lblCodeCaption)
        Me.Controls.Add(Me.txtClassCode)
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "ControlPanelForm"
        Me.Text = "NuclearFamily Tester"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Family As New NuclearFamily()

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
        Me.Close()
    End Sub

    Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        Family.Children.Add(New Person(txtFirst.Text, txtLast.Text, dtBirth.Value))
        lstChildren.Items.Add(txtFirst.Text & " " & txtLast.Text & " (" & Int((DateTime.Now.Subtract(dtBirth.Value)).TotalDays / 365) & " years old)")
    End Sub

    Private Sub cmdGetYoungest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetYoungest.Click
        MessageBox.Show("Najmłodsze dziecko to: " & Family.FindYoungestChild.FirstName, "Najmłodsze Dziecko")
    End Sub

    Private Sub txtLast_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLast.TextChanged

    End Sub

    Private Sub ControlPanelForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Public Class Person

    ' Dane zawarte w obiekcie klasy Person
    Private _FirstName As String
    Private _LastName As String
    Private _BirthDate As Date

    Public Property FirstName() As String
        Get
            Return _FirstName
        End Get

        Set(ByVal Value As String)
            _FirstName = Value
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return _LastName
        End Get

        Set(ByVal Value As String)
            _LastName = Value
        End Set
    End Property

    Public ReadOnly Property BirthDate() As Date
        Get
            Return _BirthDate
        End Get
    End Property

    ' konstruktory.
    Public Sub New(ByVal FirstName As String, ByVal LastName As String, _
     ByVal BirthDate As Date)
        _FirstName = FirstName
        _LastName = LastName
        _BirthDate = BirthDate
    End Sub

    Public Sub New(ByVal FirstName As String, ByVal LastName As String)
        _FirstName = FirstName
        _LastName = LastName
        _BirthDate = DateTime.Now
    End Sub

    Public Sub New(ByVal FirstName As String, ByVal LastName As String, _
     ByVal Age As Integer)
        _FirstName = FirstName
        _LastName = LastName
        _BirthDate = DateTime.Now.AddYears(-Age)
    End Sub

    ' Built-in feature to get the Person object to introduce itself.
    Public Function GetIntroduction() As String
        Dim Intro As String
        Intro = "Nazywam się " & FirstName & " " & LastName & ". "
        Intro &= "Urodziłem się " & BirthDate.ToString
        Return Intro
    End Function

End Class

Public Class NuclearFamily
    Public Father As Person
    Public Mother As Person
    Public Children As New Collection()

    Public Sub New(ByVal Father As Person, ByVal Mother As Person)
        Me.Father = Father
        Me.Mother = Mother
    End Sub

    Public Sub New()
    End Sub

    Public Function FindYoungestChild() As Person
        Dim Child As Person
        Dim Youngest As Person

        For Each Child In Children
            If Youngest Is Nothing Then
                Youngest = Child
            ElseIf Youngest.BirthDate < Child.BirthDate Then
                Youngest = Child
            End If
        Next

        Return Youngest
    End Function

End Class

