Imports Mediatheek.data
Imports Mediatheek.DataAcces

Public Class frmOntleningen
    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 PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents lvwOntleningen As System.Windows.Forms.ListView
    Friend WithEvents clhAlbum As System.Windows.Forms.ColumnHeader
    Friend WithEvents clhAlbumUit As System.Windows.Forms.ColumnHeader
    Friend WithEvents clhAlbumIn As System.Windows.Forms.ColumnHeader
    Friend WithEvents btnNieuweOntlening As System.Windows.Forms.Button
    Friend WithEvents btnVerwijderOntlening As System.Windows.Forms.Button
    Friend WithEvents clhAchternaam As System.Windows.Forms.ColumnHeader
    Friend WithEvents clhVoornaam As System.Windows.Forms.ColumnHeader
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents btnWijzigOntlening As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmOntleningen))
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.lvwOntleningen = New System.Windows.Forms.ListView
        Me.clhAchternaam = New System.Windows.Forms.ColumnHeader
        Me.clhVoornaam = New System.Windows.Forms.ColumnHeader
        Me.clhAlbum = New System.Windows.Forms.ColumnHeader
        Me.clhAlbumUit = New System.Windows.Forms.ColumnHeader
        Me.clhAlbumIn = New System.Windows.Forms.ColumnHeader
        Me.btnNieuweOntlening = New System.Windows.Forms.Button
        Me.btnVerwijderOntlening = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.btnWijzigOntlening = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
        Me.PictureBox1.Location = New System.Drawing.Point(0, 0)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(608, 72)
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        '
        'lvwOntleningen
        '
        Me.lvwOntleningen.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.clhAchternaam, Me.clhVoornaam, Me.clhAlbum, Me.clhAlbumUit, Me.clhAlbumIn})
        Me.lvwOntleningen.FullRowSelect = True
        Me.lvwOntleningen.Location = New System.Drawing.Point(16, 80)
        Me.lvwOntleningen.Name = "lvwOntleningen"
        Me.lvwOntleningen.Size = New System.Drawing.Size(584, 144)
        Me.lvwOntleningen.TabIndex = 2
        Me.lvwOntleningen.View = System.Windows.Forms.View.Details
        '
        'clhAchternaam
        '
        Me.clhAchternaam.Text = "Achternaam"
        Me.clhAchternaam.Width = 100
        '
        'clhVoornaam
        '
        Me.clhVoornaam.Text = "Voornaam"
        Me.clhVoornaam.Width = 100
        '
        'clhAlbum
        '
        Me.clhAlbum.Text = "Album"
        Me.clhAlbum.Width = 170
        '
        'clhAlbumUit
        '
        Me.clhAlbumUit.Text = "Geleend van"
        Me.clhAlbumUit.Width = 90
        '
        'clhAlbumIn
        '
        Me.clhAlbumIn.Text = "Geleend tot"
        Me.clhAlbumIn.Width = 90
        '
        'btnNieuweOntlening
        '
        Me.btnNieuweOntlening.Location = New System.Drawing.Point(16, 248)
        Me.btnNieuweOntlening.Name = "btnNieuweOntlening"
        Me.btnNieuweOntlening.Size = New System.Drawing.Size(128, 24)
        Me.btnNieuweOntlening.TabIndex = 3
        Me.btnNieuweOntlening.Text = "Nieuwe ontlening"
        '
        'btnVerwijderOntlening
        '
        Me.btnVerwijderOntlening.Location = New System.Drawing.Point(320, 248)
        Me.btnVerwijderOntlening.Name = "btnVerwijderOntlening"
        Me.btnVerwijderOntlening.Size = New System.Drawing.Size(128, 24)
        Me.btnVerwijderOntlening.TabIndex = 5
        Me.btnVerwijderOntlening.Text = "Verwijder ontlening"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(472, 248)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(128, 24)
        Me.Button1.TabIndex = 6
        Me.Button1.Text = "Lopende ontleningen"
        '
        'btnWijzigOntlening
        '
        Me.btnWijzigOntlening.Location = New System.Drawing.Point(168, 248)
        Me.btnWijzigOntlening.Name = "btnWijzigOntlening"
        Me.btnWijzigOntlening.Size = New System.Drawing.Size(128, 24)
        Me.btnWijzigOntlening.TabIndex = 7
        Me.btnWijzigOntlening.Text = "Wijzig ontlening"
        '
        'frmOntleningen
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(608, 296)
        Me.Controls.Add(Me.btnWijzigOntlening)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.btnVerwijderOntlening)
        Me.Controls.Add(Me.btnNieuweOntlening)
        Me.Controls.Add(Me.lvwOntleningen)
        Me.Controls.Add(Me.PictureBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "frmOntleningen"
        Me.Text = "Ontleningen"
        Me.ResumeLayout(False)

    End Sub

#End Region


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

        listviewontleningenopvullen()
    End Sub


    Private Sub listviewontleningenopvullen()
        'opvullen van de listview met ALLE ontleningen  (geschiedenis)
        lvwOntleningen.Items.Clear()


        Dim arlOntlenersOntleningen As ArrayList
        arlOntlenersOntleningen = clsOntleningDA.GetOntleningen

        For Each oOntlening As clsOntlening In arlOntlenersOntleningen

            Dim sIdGevondenOntlener, iIdGevondenAlbum As String
            sIdGevondenOntlener = oOntlening.OntlenerId


            'volgende 4 regels mag weg
            'MessageBox.Show(oOntlening.OntlenerId)
            'Dim msgOntlener As clsOntlener
            'msgOntlener = clsOntlenerDA.GetOntlenersById(oOntlening.OntlenerId).Item(0)
            'MsgBox(msgOntlener.ToString & " " & oOntlening.OntlenerId & " gevonden bij ontlening id:" & oOntlening.OntleningId)

            iIdGevondenAlbum = oOntlening.AlbumId

            Dim arlOntleners As ArrayList
            Dim arlAlbums As ArrayList
            Dim olitm As ListViewItem

            olitm = New ListViewItem
            arlOntleners = clsOntlenerDA.GetOntlenersById(sIdGevondenOntlener)
            arlAlbums = clsAlbumDA.GetAlbumById(iIdGevondenAlbum)
            For Each oOntlener As clsOntlener In arlOntleners
                For Each oAlbum As clsAlbum In arlAlbums
                    olitm.Text = oOntlener.AchterNaam
                    olitm.SubItems.Add(oOntlener.VoorNaam)
                    olitm.SubItems.Add(oAlbum.AlbumNaam)
                    olitm.SubItems.Add(oOntlening.DatumUit)
                    olitm.SubItems.Add(oOntlening.DatumIn)

                    olitm.Tag = oOntlening
                    lvwOntleningen.Items.Add(olitm)

                Next

            Next
        Next
    End Sub
#End Region

#Region "Buttons"
  
    Private Sub btnNieuweOntlening_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNieuweOntlening.Click
        Dim oNieuweOntlening As New frmOntleningToevoegen
        AddHandler oNieuweOntlening.OntleningToegevoegd, AddressOf listviewontleningenopvullen
        oNieuweOntlening.Show()
    End Sub

  


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oTeLaatOntlening As New frmOntleningTeLaat
        oTeLaatOntlening.Show()
    End Sub
#End Region

#Region "Verwijderen"
    Private Sub btnVerwijderOntlening_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVerwijderOntlening.Click
        Dim response As MsgBoxResult
        response = MsgBox("Bent U zeker dat U het de ontlening wil verwijderen? ", MsgBoxStyle.YesNo, "Confirmatie Ontlener verwijderen")

        If response = MsgBoxResult.Yes Then
            voeruitopdatabaseverwijder()
        ElseIf response = MsgBoxResult.No Then
            'do nothing
        End If



    End Sub

    Private Sub voeruitopdatabaseverwijder()

        Try
            Dim oOntlening As clsOntlening
            For Each oItem As ListViewItem In lvwOntleningen.SelectedItems
                oOntlening = oItem.Tag

                clsOntleningDA.VerwijderOntlening(oOntlening.OntleningId)

            Next
            listviewontleningenopvullen()

        Catch ex As Exception
            MessageBox.Show("Er trad een onverwachte fout op bij het verwijderen van de ontlening")
        Finally

        End Try
    End Sub

#End Region
   
    
    Private Sub btnWijzigOntlening_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWijzigOntlening.Click

        Dim oWijzigOntlening As New frmOntleningWijzigen
        AddHandler oWijzigOntlening.OntleningGewijzigd, AddressOf listviewontleningenopvullen
        oWijzigOntlening.Show()
    End Sub
End Class
