Imports Mediatheek.data
Imports Mediatheek.DataAcces

Public Class frmOntleningTeLaat
    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 Label1 As System.Windows.Forms.Label
    Friend WithEvents clhAchternaam As System.Windows.Forms.ColumnHeader
    Friend WithEvents clhVoornaam As System.Windows.Forms.ColumnHeader
    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 lvwOntleningenTeLaat As System.Windows.Forms.ListView
    Friend WithEvents btnAfsluiten As System.Windows.Forms.Button
    Friend WithEvents clhTeLaat As System.Windows.Forms.ColumnHeader
    Friend WithEvents btnStuurEmail As System.Windows.Forms.Button
    Friend WithEvents clhEmail As System.Windows.Forms.ColumnHeader
    Friend WithEvents chlOntleningID As System.Windows.Forms.ColumnHeader
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmOntleningTeLaat))
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.lvwOntleningenTeLaat = 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.clhTeLaat = New System.Windows.Forms.ColumnHeader
        Me.clhEmail = New System.Windows.Forms.ColumnHeader
        Me.chlOntleningID = New System.Windows.Forms.ColumnHeader
        Me.btnAfsluiten = New System.Windows.Forms.Button
        Me.btnStuurEmail = 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
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 88)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(48, 16)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Te laat :"
        '
        'lvwOntleningenTeLaat
        '
        Me.lvwOntleningenTeLaat.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.clhAchternaam, Me.clhVoornaam, Me.clhAlbum, Me.clhAlbumUit, Me.clhAlbumIn, Me.clhTeLaat, Me.clhEmail, Me.chlOntleningID})
        Me.lvwOntleningenTeLaat.FullRowSelect = True
        Me.lvwOntleningenTeLaat.Location = New System.Drawing.Point(8, 112)
        Me.lvwOntleningenTeLaat.Name = "lvwOntleningenTeLaat"
        Me.lvwOntleningenTeLaat.Size = New System.Drawing.Size(592, 144)
        Me.lvwOntleningenTeLaat.TabIndex = 3
        Me.lvwOntleningenTeLaat.View = System.Windows.Forms.View.Details
        '
        'clhAchternaam
        '
        Me.clhAchternaam.Text = "Achternaam"
        Me.clhAchternaam.Width = 100
        '
        'clhVoornaam
        '
        Me.clhVoornaam.Text = "Voornaam"
        Me.clhVoornaam.Width = 70
        '
        'clhAlbum
        '
        Me.clhAlbum.Text = "Album"
        Me.clhAlbum.Width = 150
        '
        'clhAlbumUit
        '
        Me.clhAlbumUit.Text = "Geleend van"
        Me.clhAlbumUit.Width = 90
        '
        'clhAlbumIn
        '
        Me.clhAlbumIn.Text = "Geleend tot"
        Me.clhAlbumIn.Width = 90
        '
        'clhTeLaat
        '
        Me.clhTeLaat.Text = "Te laat"
        Me.clhTeLaat.Width = 70
        '
        'clhEmail
        '
        Me.clhEmail.Text = "Email"
        Me.clhEmail.Width = 150
        '
        'chlOntleningID
        '
        Me.chlOntleningID.Text = "ID"
        '
        'btnAfsluiten
        '
        Me.btnAfsluiten.Location = New System.Drawing.Point(320, 272)
        Me.btnAfsluiten.Name = "btnAfsluiten"
        Me.btnAfsluiten.Size = New System.Drawing.Size(112, 24)
        Me.btnAfsluiten.TabIndex = 7
        Me.btnAfsluiten.Text = "Afsluiten"
        '
        'btnStuurEmail
        '
        Me.btnStuurEmail.Location = New System.Drawing.Point(480, 272)
        Me.btnStuurEmail.Name = "btnStuurEmail"
        Me.btnStuurEmail.Size = New System.Drawing.Size(112, 24)
        Me.btnStuurEmail.TabIndex = 8
        Me.btnStuurEmail.Text = "E-mail sturen"
        '
        'frmOntleningTeLaat
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(608, 317)
        Me.Controls.Add(Me.btnStuurEmail)
        Me.Controls.Add(Me.btnAfsluiten)
        Me.Controls.Add(Me.lvwOntleningenTeLaat)
        Me.Controls.Add(Me.Label1)
        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 = "frmOntleningTeLaat"
        Me.Text = "Lopende ontleningen"
        Me.ResumeLayout(False)

    End Sub

#End Region


#Region "Opvulling"
    'hier maken we een kleine form om aan te tonen welke ontleningen nog uitgaan, dit is eerder een uitbreiding 
    ' van de opgave , er is een mogelijkheid om het programma gemakkelijk uit te breiden om te zien wie vaak te laat is
    ' enzovoort
    Private Sub frmOntleningTeLaat_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        listviewontleningenopvullen()
        btnStuurEmail.Enabled = False
    End Sub

    Private Sub listviewontleningenopvullen()

        lvwOntleningenTeLaat.Items.Clear()


        Dim arlOntlenersOntleningen As ArrayList
        arlOntlenersOntleningen = clsOntleningDA.GetOntleningen

        For Each oOntlening As clsOntlening In arlOntlenersOntleningen

            Dim sIdGevondenOntlener, iIdGevondenAlbum As String
            sIdGevondenOntlener = oOntlening.OntlenerId
            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)




                    Dim dDatumVandaag As Date

                    If oOntlening.DatumIn < dDatumVandaag.Today Then
                        olitm.SubItems.Add("Ja")
                    Else
                        olitm.SubItems.Add("Neen")
                    End If
                    olitm.SubItems.Add(oOntlener.Email)
                    If oOntlening.InBezit = "Neen" Then
                        lvwOntleningenTeLaat.Items.Add(olitm)
                    End If

                    olitm.SubItems.Add(oOntlening.OntleningId)
                    olitm.Tag = oOntlening
                Next

            Next
        Next
    End Sub

#End Region

#Region "Email sturen"
    Private Sub btnStuurEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStuurEmail.Click
        'validatie voor wanneer gebruiker in listview klikt en geen gebruiker selecteert:
        ' dan is er geen selected item en komt er nullref fout
        If lvwOntleningenTeLaat.SelectedItems.Count() = 0 Then
            MsgBox("Kies een ontlening waarvoor u een herinnerings e-mail naar zenden", MsgBoxStyle.OKOnly, "Geen ontlening geselecteerd.")
        Else
            Dim oOntlening As clsOntlening
            oOntlening = clsOntleningDA.GetOntleningById(lvwOntleningenTeLaat.SelectedItems.Item(0).SubItems(7).Text).Item(0)
            gegevensgeselecteerdinvoeren(oOntlening)
        End If
    End Sub



    Private Sub gegevensgeselecteerdinvoeren(ByVal oOntlening As clsOntlening)
        If lvwOntleningenTeLaat.SelectedItems.Item(0).SubItems(6).Text.Length = 0 Then
            MsgBox("De ontlener bezit geen emailadres", MsgBoxStyle.OKOnly, "Kan geen e-mail zenden")
        Else
            clsOutlook.zendMail(oOntlening)
        End If


    End Sub

#End Region
  
    Private Sub lvwOntleningenTeLaat_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvwOntleningenTeLaat.SelectedIndexChanged
        If Not lvwOntleningenTeLaat.SelectedItems.Count = 0 Then
            If lvwOntleningenTeLaat.SelectedItems(0).SubItems(5).Text = "Ja" Then
                btnStuurEmail.Enabled = True
            Else
                btnStuurEmail.Enabled = False
            End If

        Else
            btnStuurEmail.Enabled = False
        End If
    End Sub

    Private Sub btnAfsluiten_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAfsluiten.Click
        Me.Close()
    End Sub
End Class
