Imports System.Windows.Forms

Public Class Rekening

    Public reknummer As Integer
    Public creatieDatum As Date
    Public saldo As Double
    Public testDatum As Date = #1/1/1900#
    Public eigenaar As Klant = New Klant("", "")


    'constructor

    Public Sub New(ByVal reknummer As Integer, ByVal datum As Date, ByVal saldo As Double)
        'me slaat dus op de classe variabelen
        Me.reknummer = reknummer
        Try
            If saldo < 0 Then
                Throw New Exception("Dit mag niet!")
                Me.saldo = 0

            ElseIf datum.CompareTo(testDatum) < 0 Then
                Throw New Exception("Dit mag ook niet")
                creatieDatum = #1/1/2004#
            End If

            creatieDatum = datum
            Me.saldo = saldo
        Catch ex As Exception
            MessageBox.Show("Er heeft zich een fout voorgedaan!", "Fout", MessageBoxButtons.OK)


        End Try


    End Sub

    Public Sub storten(ByVal bedrag As Double)
        Me.saldo += bedrag

    End Sub



    Public Property reknr() As Integer
        Get
            Return Me.reknummer

        End Get
        Set(ByVal Value As Integer)
            Me.reknummer = Value
        End Set
    End Property

    Public Property Datum() As Date
        Get
            Return Me.creatieDatum

        End Get
        Set(ByVal Value As Date)
            Me.creatieDatum = Value
        End Set
    End Property

    Public Property Sal() As Double
        Get
            Return Me.saldo

        End Get
        Set(ByVal Value As Double)
            Me.saldo = Value
        End Set
    End Property

    Public ReadOnly Property getKlant()
        Get
            Return Me.eigenaar.Name() & " " & Me.eigenaar.surname()



        End Get
    End Property

    Public Sub koppelklant(ByVal naam As String, ByVal achternaam As String)

        Me.eigenaar = New Klant(naam, achternaam)


    End Sub

    Public Overridable Sub Afbeelden()

        Console.WriteLine("Het rekeningnummer is: " & Me.reknummer _
        & vbCrLf & "De creatiedatum: " & Me.creatieDatum & vbCrLf _
        & "Het saldo bedraagt: " & Me.saldo & vbCrLf _
        & "Rekening staat op naam van: " & getKlant().ToString)

    End Sub
End Class
