Imports Mediatheek.data
Imports Mediatheek.DataAcces

Public Class frmOntleningWijzigen
    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

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

    '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.
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents btnVoegAlbumTerug As System.Windows.Forms.Button
    Friend WithEvents btnVoegAlbumToe As System.Windows.Forms.Button
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents lvwBeschikbaar As System.Windows.Forms.ListView
    Friend WithEvents txtToevoegId As System.Windows.Forms.TextBox
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents cboKiesOntlener As System.Windows.Forms.ComboBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents groupbox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents lvwVanOntlener As System.Windows.Forms.ListView
    Friend WithEvents btnWijzigOntleningWijzig As System.Windows.Forms.Button
    Friend WithEvents dtpDatumIn As System.Windows.Forms.DateTimePicker
    Friend WithEvents dtpDatumUit As System.Windows.Forms.DateTimePicker
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents chkInBezit As System.Windows.Forms.CheckBox
    Friend WithEvents clhAlbumNaam As System.Windows.Forms.ColumnHeader
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmOntleningWijzigen))
        Me.GroupBox3 = New System.Windows.Forms.GroupBox
        Me.btnVoegAlbumTerug = New System.Windows.Forms.Button
        Me.btnVoegAlbumToe = New System.Windows.Forms.Button
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.lvwVanOntlener = New System.Windows.Forms.ListView
        Me.lvwBeschikbaar = New System.Windows.Forms.ListView
        Me.txtToevoegId = New System.Windows.Forms.TextBox
        Me.Label7 = New System.Windows.Forms.Label
        Me.btnWijzigOntleningWijzig = New System.Windows.Forms.Button
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.cboKiesOntlener = New System.Windows.Forms.ComboBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.groupbox2 = New System.Windows.Forms.GroupBox
        Me.chkInBezit = New System.Windows.Forms.CheckBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.dtpDatumIn = New System.Windows.Forms.DateTimePicker
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.dtpDatumUit = New System.Windows.Forms.DateTimePicker
        Me.clhAlbumNaam = New System.Windows.Forms.ColumnHeader
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox1.SuspendLayout()
        Me.groupbox2.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.Add(Me.btnVoegAlbumTerug)
        Me.GroupBox3.Controls.Add(Me.btnVoegAlbumToe)
        Me.GroupBox3.Controls.Add(Me.Label6)
        Me.GroupBox3.Controls.Add(Me.Label5)
        Me.GroupBox3.Controls.Add(Me.lvwVanOntlener)
        Me.GroupBox3.Controls.Add(Me.lvwBeschikbaar)
        Me.GroupBox3.Location = New System.Drawing.Point(27, 240)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(544, 200)
        Me.GroupBox3.TabIndex = 11
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "Kies album"
        '
        'btnVoegAlbumTerug
        '
        Me.btnVoegAlbumTerug.Location = New System.Drawing.Point(248, 112)
        Me.btnVoegAlbumTerug.Name = "btnVoegAlbumTerug"
        Me.btnVoegAlbumTerug.Size = New System.Drawing.Size(32, 32)
        Me.btnVoegAlbumTerug.TabIndex = 5
        Me.btnVoegAlbumTerug.Text = "<"
        '
        'btnVoegAlbumToe
        '
        Me.btnVoegAlbumToe.Location = New System.Drawing.Point(248, 64)
        Me.btnVoegAlbumToe.Name = "btnVoegAlbumToe"
        Me.btnVoegAlbumToe.Size = New System.Drawing.Size(32, 32)
        Me.btnVoegAlbumToe.TabIndex = 4
        Me.btnVoegAlbumToe.Text = ">"
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(320, 32)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(160, 24)
        Me.Label6.TabIndex = 3
        Me.Label6.Text = "Gekozen albums"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(24, 32)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(160, 24)
        Me.Label5.TabIndex = 2
        Me.Label5.Text = "Beschikbare albums"
        '
        'lvwVanOntlener
        '
        Me.lvwVanOntlener.FullRowSelect = True
        Me.lvwVanOntlener.Location = New System.Drawing.Point(320, 56)
        Me.lvwVanOntlener.MultiSelect = False
        Me.lvwVanOntlener.Name = "lvwVanOntlener"
        Me.lvwVanOntlener.Size = New System.Drawing.Size(184, 120)
        Me.lvwVanOntlener.TabIndex = 1
        Me.lvwVanOntlener.View = System.Windows.Forms.View.List
        '
        'lvwBeschikbaar
        '
        Me.lvwBeschikbaar.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.clhAlbumNaam})
        Me.lvwBeschikbaar.FullRowSelect = True
        Me.lvwBeschikbaar.Location = New System.Drawing.Point(24, 56)
        Me.lvwBeschikbaar.MultiSelect = False
        Me.lvwBeschikbaar.Name = "lvwBeschikbaar"
        Me.lvwBeschikbaar.Size = New System.Drawing.Size(184, 120)
        Me.lvwBeschikbaar.Sorting = System.Windows.Forms.SortOrder.Ascending
        Me.lvwBeschikbaar.TabIndex = 0
        Me.lvwBeschikbaar.View = System.Windows.Forms.View.Details
        '
        'txtToevoegId
        '
        Me.txtToevoegId.Location = New System.Drawing.Point(83, 456)
        Me.txtToevoegId.Name = "txtToevoegId"
        Me.txtToevoegId.ReadOnly = True
        Me.txtToevoegId.Size = New System.Drawing.Size(40, 20)
        Me.txtToevoegId.TabIndex = 14
        Me.txtToevoegId.Text = ""
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(43, 456)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(16, 16)
        Me.Label7.TabIndex = 13
        Me.Label7.Text = "ID:"
        '
        'btnWijzigOntleningWijzig
        '
        Me.btnWijzigOntleningWijzig.Location = New System.Drawing.Point(435, 456)
        Me.btnWijzigOntleningWijzig.Name = "btnWijzigOntleningWijzig"
        Me.btnWijzigOntleningWijzig.Size = New System.Drawing.Size(112, 24)
        Me.btnWijzigOntleningWijzig.TabIndex = 12
        Me.btnWijzigOntleningWijzig.Text = "Wijzig ontlening "
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.cboKiesOntlener)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(27, 88)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(544, 56)
        Me.GroupBox1.TabIndex = 9
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Kies ontlener"
        '
        'cboKiesOntlener
        '
        Me.cboKiesOntlener.Location = New System.Drawing.Point(160, 24)
        Me.cboKiesOntlener.Name = "cboKiesOntlener"
        Me.cboKiesOntlener.Size = New System.Drawing.Size(320, 21)
        Me.cboKiesOntlener.TabIndex = 1
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Ontlener :"
        '
        'PictureBox1
        '
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
        Me.PictureBox1.Location = New System.Drawing.Point(-5, 0)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(608, 72)
        Me.PictureBox1.TabIndex = 8
        Me.PictureBox1.TabStop = False
        '
        'groupbox2
        '
        Me.groupbox2.Controls.Add(Me.chkInBezit)
        Me.groupbox2.Controls.Add(Me.Label4)
        Me.groupbox2.Controls.Add(Me.dtpDatumIn)
        Me.groupbox2.Controls.Add(Me.Label3)
        Me.groupbox2.Controls.Add(Me.Label2)
        Me.groupbox2.Controls.Add(Me.dtpDatumUit)
        Me.groupbox2.Location = New System.Drawing.Point(27, 152)
        Me.groupbox2.Name = "groupbox2"
        Me.groupbox2.Size = New System.Drawing.Size(544, 80)
        Me.groupbox2.TabIndex = 10
        Me.groupbox2.TabStop = False
        Me.groupbox2.Text = "Kies uitlening"
        '
        'chkInBezit
        '
        Me.chkInBezit.Location = New System.Drawing.Point(456, 48)
        Me.chkInBezit.Name = "chkInBezit"
        Me.chkInBezit.Size = New System.Drawing.Size(16, 16)
        Me.chkInBezit.TabIndex = 10
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(384, 48)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(64, 16)
        Me.Label4.TabIndex = 9
        Me.Label4.Text = "Ingediend :"
        '
        'dtpDatumIn
        '
        Me.dtpDatumIn.Format = System.Windows.Forms.DateTimePickerFormat.Short
        Me.dtpDatumIn.Location = New System.Drawing.Point(160, 48)
        Me.dtpDatumIn.Name = "dtpDatumIn"
        Me.dtpDatumIn.TabIndex = 8
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 48)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(96, 24)
        Me.Label3.TabIndex = 7
        Me.Label3.Text = "Datum terug :"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 24)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96, 24)
        Me.Label2.TabIndex = 0
        Me.Label2.Text = "Datum uitlening :"
        '
        'dtpDatumUit
        '
        Me.dtpDatumUit.Format = System.Windows.Forms.DateTimePickerFormat.Short
        Me.dtpDatumUit.Location = New System.Drawing.Point(160, 16)
        Me.dtpDatumUit.Name = "dtpDatumUit"
        Me.dtpDatumUit.TabIndex = 6
        '
        'clhAlbumNaam
        '
        Me.clhAlbumNaam.Text = "Album naam"
        Me.clhAlbumNaam.Width = 160
        '
        'frmOntleningWijzigen
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(598, 492)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.txtToevoegId)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.btnWijzigOntleningWijzig)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.groupbox2)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "frmOntleningWijzigen"
        Me.Text = "Ontlening wijzigen"
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox1.ResumeLayout(False)
        Me.groupbox2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Event OntleningGewijzigd()

#Region "Opvulling"
    Private Sub frmOntleningWijzigen_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        vulcboontlenersop()
        beschikbarealbumsopvullen()
    End Sub

    Private Sub vulcboontlenersop()

        'cbo met ontleners worden opgevuld
        Dim arlOntlening As ArrayList
        Dim arlOntlener As ArrayList

        arlOntlening = clsOntleningDA.GetOntleningen
        Dim iIndexOntlener As Integer
        For Each oOntlening As clsOntlening In arlOntlening
            iIndexOntlener = oOntlening.OntlenerId
            arlOntlener = clsOntlenerDA.GetOntlenersById(iIndexOntlener)

            For Each oOntlener As clsOntlener In arlOntlener
                cboKiesOntlener.Items.Add(oOntlener)
            Next

        Next
       
    End Sub

   

    Private Sub beschikbarealbumsopvullen()
        lvwBeschikbaar.Items.Clear()
        Dim arlBeschikbaarId As New ArrayList
        Dim arlOntleningen As ArrayList
        arlOntleningen = clsOntleningDA.GetOntleningen
        Dim iAlbumIdInBezit As Integer

        'alle ontleningen checken
        For Each oOntlening As clsOntlening In arlOntleningen
            If oOntlening.InBezit = "Neen" Then
                iAlbumIdInBezit = oOntlening.AlbumId
                'alle albmus id toevoegen waarbij ontlening inbezit neeis
                'inbezit neen = uitgeleend
                arlBeschikbaarId.Add(iAlbumIdInBezit)
            End If
        Next

        Dim arlAlbums As New ArrayList
        arlAlbums = clsAlbumDA.GetAlbums

        Dim iInArr As Integer = 0
        For Each oAlbum As clsAlbum In arlAlbums
            'controleert telkes als het albumid overeenkomt 
            'met een element uit die arraylist van albums ids 
            'die uitgeleend zijn

            For i As Integer = 0 To arlBeschikbaarId.Count - 1
                Dim iID As Integer = arlBeschikbaarId(i)

                If oAlbum.AlbumId = iID Then

                    iInArr = 1
                End If

            Next
            If iInArr = 0 Then
                Dim olitm As ListViewItem
                olitm = New ListViewItem

                olitm.Text = oAlbum.AlbumNaam
                olitm.Tag = oAlbum
                lvwBeschikbaar.Items.Add(olitm)
            End If
            iInArr = 0

        Next

    End Sub


#End Region

#Region "Invulling gegevens bij verandering ontlener"

   

    Private Sub cboKiesOntlener_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboKiesOntlener.SelectedIndexChanged
        If Not cboKiesOntlener.SelectedIndex = -1 Then
            vulJuisteGegevensIn(cboKiesOntlener.SelectedItem)
            btnWijzigOntleningWijzig.Enabled = True
        Else
            btnWijzigOntleningWijzig.Enabled = False
        End If

    End Sub

    Private Sub vulJuisteGegevensIn(ByVal selectedOntlener As clsOntlener)
        'gegevens per ontlening worden ingevuld
        chkInBezit.Checked = False
        lvwVanOntlener.Items.Clear()
        dtpDatumIn.Text = ""
        dtpDatumUit.Text = ""
        Dim iIdOntlenerGekozen As Integer





        Dim arlOntlening As ArrayList
        arlOntlening = clsOntleningDA.GetOntleningByOntlenerId(selectedOntlener.Id) 'clsOntleningDA.GetOntleningById(Convert.ToString(iIdOntlenerGekozen))

        For Each oOntlening As clsOntlening In arlOntlening
            txtToevoegId.Text = oOntlening.OntleningId
            dtpDatumIn.Text = oOntlening.DatumIn
            dtpDatumUit.Text = oOntlening.DatumUit
            If oOntlening.InBezit = "Ja" Then
                chkInBezit.Checked = True
            Else
                chkInBezit.Checked = False
            End If
            Dim oItem As ListViewItem
            oItem = New ListViewItem

            Dim arlAlbums As ArrayList
            Dim iGevondenAlbumId As Integer
            iGevondenAlbumId = oOntlening.AlbumId
            arlAlbums = clsAlbumDA.GetAlbumByID(Convert.ToString(iGevondenAlbumId))
            For Each oAlbum As clsAlbum In arlAlbums
                oItem.Text = oAlbum.AlbumNaam
                oItem.Tag = oAlbum
                lvwVanOntlener.Items.Add(oItem)
            Next
        Next

    End Sub

#End Region

#Region "Actions"

    Private Sub btnVoegAlbumToe_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVoegAlbumToe.Click


        If lvwVanOntlener.Items.Count() = 0 Then
            albumtoevoegen()
        Else
            MsgBox("Een ontlener mag maar 1 album tegelijk ontlenen." & vbCrLf & "Maak het ontleende album eerst terug beschikbaar", MsgBoxStyle.OKOnly, "Maximum 1 album.")
        End If

        

    End Sub
    Private Sub btnVoegAlbumTerug_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVoegAlbumTerug.Click
        albumterugzetten()
    End Sub

    Private Sub albumtoevoegen()
        'albums worden uit bezit gehaald 
        Dim iId As Integer
        Dim olitm As ListViewItem
        Dim oAlbum As clsAlbum
        For Each oItem As ListViewItem In lvwBeschikbaar.SelectedItems
            oAlbum = oItem.Tag
            lvwBeschikbaar.Items.Remove(oItem)
            lvwVanOntlener.Items.Add(oItem)
        Next
    End Sub

    Private Sub albumterugzetten()
        'albums worden in bezit gehaald
        Dim iId As Integer
        Dim olitm As ListViewItem
        Dim oAlbum As clsAlbum
        For Each oItem As ListViewItem In lvwVanOntlener.SelectedItems
            oAlbum = oItem.Tag
            lvwVanOntlener.Items.Remove(oItem)
            lvwBeschikbaar.Items.Add(oItem)
        Next
    End Sub



#End Region

#Region "Wijzigingen uitvoeren"

    Private Sub btnWijzigOntleningWijzig_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnWijzigOntleningWijzig.Click
        If cboKiesOntlener.Text <> "" Then
            controletijd()
        Else
            MsgBox("Kies een ontlening aub!  ")
        End If


    End Sub
    Private Sub controletijd()

        Dim iDatumCheck As Integer = Date.Compare(dtpDatumUit.Text, dtpDatumIn.Text)
        If iDatumCheck = 1 Then
            MsgBox("De ontleningsdatums zijn ongeldig, gelieve die te wijzigen.", MsgBoxStyle.OKOnly, "U kunt geen album terugbrengen (" & dtpDatumIn.Text & ") voordat u het hebt uitgeleend (" & dtpDatumUit.Text & ").")
        Else
            controleBestaand()
        End If
    End Sub


    Private Sub controleBestaand()
        'controle op bestaande uitlening
        Dim iIdOntlener As Integer
        Dim ctrlOntlener As clsOntlener
        ctrlOntlener = cboKiesOntlener.SelectedItem
        iIdOntlener = ctrlOntlener.Id

        Dim iAantal As Integer
        iAantal = lvwVanOntlener.Items.Count
        Dim sIngeDiend As String
        Dim iId As Integer
        Do While iAantal <> 0

            Dim sGevondenNaam As String

            For Each olitm As ListViewItem In lvwVanOntlener.Items
                sGevondenNaam = olitm.Text
                Dim arlAlbums As New ArrayList
                arlAlbums = clsAlbumDA.GetAlbumByNaam(sGevondenNaam)
                For Each oAlbum As clsAlbum In arlAlbums
                    iId = oAlbum.AlbumId
                Next
                Dim arlOntleningenChecked As ArrayList
                arlOntleningenChecked = clsOntleningDA.GetOntleningen

                For Each oOntlening As clsOntlening In arlOntleningenChecked
                    If chkInBezit.Checked = True Then
                        sIngeDiend = "Ja"
                    Else
                        sIngeDiend = "Neen"
                    End If

                Next

            Next

            Dim oOntlening2 As New clsOntlening(txtToevoegId.Text, Convert.ToString(iId), Convert.ToString(iIdOntlener), dtpDatumUit.Text, dtpDatumIn.Text, sIngeDiend)
            Dim arlOntleningen As ArrayList
            arlOntleningen = clsOntleningDA.GetOntleningen
            Dim uitvoeren As Integer = 0

            For Each oOntlening As clsOntlening In arlOntleningen
                If oOntlening2.AlbumId = oOntlening.AlbumId And oOntlening2.DatumUit = oOntlening.DatumUit And oOntlening2.DatumIn = oOntlening.DatumIn And oOntlening.InBezit = oOntlening2.InBezit Then
                    MsgBox("De ontlening die u wilt toevoegen bestaat al!")

                    uitvoeren = 1
                End If

            Next
            If uitvoeren = 0 Then
                voeruitopdatabase()

            End If
            iAantal -= 1
        Loop
    End Sub

    Private Sub voeruitopdatabase()
        'uitvoering op database
        Dim arlOntleningen As ArrayList
        Dim sGekozenNaam As String
        sGekozenNaam = Convert.ToString(cboKiesOntlener.SelectedIndex + 1)


        arlOntleningen = clsOntleningDA.GetOntleningById(sGekozenNaam)

        For Each oOntlening As clsOntlening In arlOntleningen
            Try


                Dim sGevondenNaam As String
                Dim iId As Integer
                For Each olitm As ListViewItem In lvwVanOntlener.Items
                    sGevondenNaam = olitm.Text

                    Dim arlAlbums As New ArrayList
                    arlAlbums = clsAlbumDA.GetAlbumByNaam(sGevondenNaam)
                    For Each oAlbum As clsAlbum In arlAlbums
                        iId = oAlbum.AlbumId



                        'Dim sWoord, sVoorNaamGekozen, sAchterNaam As String
                        'Dim iIndexOff As Integer
                        'sWoord = cboKiesOntlener.Text
                        'iIndexOff = sWoord.IndexOf(",")
                        'sAchterNaam = sWoord.Substring(0, iIndexOff).Trim

                        'sVoorNaamGekozen = sWoord.Substring(iIndexOff + 1).Trim


                        Dim arlOntleners As ArrayList
                        Dim iOntlenerId As Integer

                        ' arlOntleners = clsOntlenerDA.GetOntleners3(sAchterNaam, sVoorNaamGekozen)
                        Dim selectedOntlener As clsOntlener
                        selectedOntlener = cboKiesOntlener.SelectedItem()
                        'arlOntleners = clsOntlenerDA.GetOntlenersById(selectedOntlener.Id)

                        'For Each oOntlener As clsOntlener In arlOntleners
                        '    iOntlenerId = oOntlener.Id


                        'Next


                        oOntlening.OntleningId = txtToevoegId.Text
                        oOntlening.AlbumId = iId
                        oOntlening.OntlenerId = selectedOntlener.Id 'iOntlenerId
                        oOntlening.DatumIn = dtpDatumIn.Text
                        oOntlening.DatumUit = dtpDatumUit.Text
                        Dim dDatum As Date
                        If chkInBezit.Checked = True Then
                            oOntlening.InBezit = "Ja"
                        Else
                            oOntlening.InBezit = "Neen"
                        End If

                        clsOntleningDA.WijzigOntlening(oOntlening)


                        RaiseEvent OntleningGewijzigd()
                    Next

                Next

                ledigform()


            Catch ex As Exception
                MessageBox.Show("Er trad een onverwachte fout op bij het wijzigen van de ontlening")
            End Try
        Next
    End Sub

    Private Sub ledigform()

        Dim dDatum As Date
        cboKiesOntlener.Text = ""
        dtpDatumIn.Text = dDatum.Today
        dtpDatumUit.Text = dDatum.Today

    End Sub

#End Region


End Class
