
Imports Mediatheek.data
Imports Mediatheek.DataAcces

Public Class frmLocatieToevoegen
    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 GroupBox1 As System.Windows.Forms.GroupBox
    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 txtNieuweLocatieRek As System.Windows.Forms.TextBox
    Friend WithEvents txtNieuweLocatieVak As System.Windows.Forms.TextBox
    Friend WithEvents cboNieuweLocatieSoort As System.Windows.Forms.ComboBox
    Friend WithEvents lblSoort As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents txtNieuweLocatieMaxAantal As System.Windows.Forms.TextBox
    Friend WithEvents btnLocatieToevoegenToevoegen As System.Windows.Forms.Button
    Friend WithEvents txtToevoegId As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents txtNieuweLocatieSchap As System.Windows.Forms.TextBox
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmLocatieToevoegen))
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.txtNieuweLocatieMaxAantal = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.lblSoort = New System.Windows.Forms.Label
        Me.cboNieuweLocatieSoort = New System.Windows.Forms.ComboBox
        Me.txtNieuweLocatieSchap = New System.Windows.Forms.TextBox
        Me.txtNieuweLocatieVak = New System.Windows.Forms.TextBox
        Me.txtNieuweLocatieRek = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnLocatieToevoegenToevoegen = New System.Windows.Forms.Button
        Me.txtToevoegId = New System.Windows.Forms.TextBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.txtNieuweLocatieMaxAantal)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.lblSoort)
        Me.GroupBox1.Controls.Add(Me.cboNieuweLocatieSoort)
        Me.GroupBox1.Controls.Add(Me.txtNieuweLocatieSchap)
        Me.GroupBox1.Controls.Add(Me.txtNieuweLocatieVak)
        Me.GroupBox1.Controls.Add(Me.txtNieuweLocatieRek)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(16, 96)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(400, 120)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Voeg een locatie toe"
        '
        'txtNieuweLocatieMaxAantal
        '
        Me.txtNieuweLocatieMaxAantal.Location = New System.Drawing.Point(256, 64)
        Me.txtNieuweLocatieMaxAantal.Name = "txtNieuweLocatieMaxAantal"
        Me.txtNieuweLocatieMaxAantal.Size = New System.Drawing.Size(80, 20)
        Me.txtNieuweLocatieMaxAantal.TabIndex = 9
        Me.txtNieuweLocatieMaxAantal.Text = ""
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(176, 64)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(64, 23)
        Me.Label4.TabIndex = 8
        Me.Label4.Text = "Max aantal"
        '
        'lblSoort
        '
        Me.lblSoort.Location = New System.Drawing.Point(200, 24)
        Me.lblSoort.Name = "lblSoort"
        Me.lblSoort.Size = New System.Drawing.Size(40, 23)
        Me.lblSoort.TabIndex = 7
        Me.lblSoort.Text = "Soort"
        '
        'cboNieuweLocatieSoort
        '
        Me.cboNieuweLocatieSoort.Location = New System.Drawing.Point(256, 24)
        Me.cboNieuweLocatieSoort.Name = "cboNieuweLocatieSoort"
        Me.cboNieuweLocatieSoort.Size = New System.Drawing.Size(88, 21)
        Me.cboNieuweLocatieSoort.TabIndex = 6
        '
        'txtNieuweLocatieSchap
        '
        Me.txtNieuweLocatieSchap.Location = New System.Drawing.Point(72, 88)
        Me.txtNieuweLocatieSchap.Name = "txtNieuweLocatieSchap"
        Me.txtNieuweLocatieSchap.Size = New System.Drawing.Size(40, 20)
        Me.txtNieuweLocatieSchap.TabIndex = 5
        Me.txtNieuweLocatieSchap.Text = ""
        '
        'txtNieuweLocatieVak
        '
        Me.txtNieuweLocatieVak.Location = New System.Drawing.Point(72, 56)
        Me.txtNieuweLocatieVak.Name = "txtNieuweLocatieVak"
        Me.txtNieuweLocatieVak.Size = New System.Drawing.Size(40, 20)
        Me.txtNieuweLocatieVak.TabIndex = 4
        Me.txtNieuweLocatieVak.Text = ""
        '
        'txtNieuweLocatieRek
        '
        Me.txtNieuweLocatieRek.Location = New System.Drawing.Point(72, 24)
        Me.txtNieuweLocatieRek.Name = "txtNieuweLocatieRek"
        Me.txtNieuweLocatieRek.Size = New System.Drawing.Size(40, 20)
        Me.txtNieuweLocatieRek.TabIndex = 3
        Me.txtNieuweLocatieRek.Text = ""
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 88)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(40, 24)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "Schap"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 56)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(40, 24)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Vak"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(40, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Rek"
        '
        'btnLocatieToevoegenToevoegen
        '
        Me.btnLocatieToevoegenToevoegen.Location = New System.Drawing.Point(312, 224)
        Me.btnLocatieToevoegenToevoegen.Name = "btnLocatieToevoegenToevoegen"
        Me.btnLocatieToevoegenToevoegen.Size = New System.Drawing.Size(104, 23)
        Me.btnLocatieToevoegenToevoegen.TabIndex = 16
        Me.btnLocatieToevoegenToevoegen.Text = "Toevoegen"
        '
        'txtToevoegId
        '
        Me.txtToevoegId.Location = New System.Drawing.Point(64, 224)
        Me.txtToevoegId.Name = "txtToevoegId"
        Me.txtToevoegId.ReadOnly = True
        Me.txtToevoegId.Size = New System.Drawing.Size(48, 20)
        Me.txtToevoegId.TabIndex = 17
        Me.txtToevoegId.Text = ""
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(24, 224)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(24, 23)
        Me.Label5.TabIndex = 18
        Me.Label5.Text = "ID"
        '
        '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(432, 80)
        Me.PictureBox1.TabIndex = 19
        Me.PictureBox1.TabStop = False
        '
        'frmLocatieToevoegen
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(432, 272)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.txtToevoegId)
        Me.Controls.Add(Me.btnLocatieToevoegenToevoegen)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "frmLocatieToevoegen"
        Me.Text = "Nieuwe locatie"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Public Event LocatieToegevoegd()

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

#Region "TOEVOEGEN"
    Private Sub comboboxtoevoegsoortopvullen()
        'combobox wordt opgevuld
        toevoegidingeven()
        cboNieuweLocatieSoort.Items.Clear()
        cboNieuweLocatieSoort.Items.Add("CD")
        cboNieuweLocatieSoort.Items.Add("DVD")
        cboNieuweLocatieSoort.SelectedItem = "CD"
    End Sub


    Private Sub txtToevoegRek_TabIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        toevoegidingeven()
    End Sub

    Private Sub btnLocatieToevoegenToevoegen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLocatieToevoegenToevoegen.Click
        controlegegevensuitvoeren()

    End Sub

    Private Sub controlegegevensuitvoeren()
        controleaantalchars()

    End Sub

    Private Sub controleaantalchars()
        'hier controleert met dat het aantal in te geven chars niet overschreden wordt
        Dim sRek, sVak, sSchap, sMaxAantal As String
        sRek = txtNieuweLocatieRek.Text
        sVak = txtNieuweLocatieVak.Text
        sSchap = txtNieuweLocatieSchap.Text
        sMaxAantal = txtNieuweLocatieMaxAantal.Text

        If sRek.Length < 4 And sVak.Length < 4 And sSchap.Length < 4 And sMaxAantal.Length < 4 Then
            controlenumeriek()
        Else
            MsgBox("In te vullen getallen hebben een range van 1 tot 999, gelieve dit te respecteren!")
            txtboxledigen()
        End If

    End Sub
    Private Sub toevoegidingeven()
        Dim nieuweid As Integer = 0

        Dim arlLocaties As ArrayList
        arlLocaties = clsLocatieDA.GetLocaties

        For Each oLocatie As clsLocatie In arlLocaties
            nieuweid += 1
        Next
        nieuweid += 1
        txtToevoegId.Text = Convert.ToString(nieuweid)


    End Sub

    Private Sub controlenumeriek()
        'controle op numeriek van juiste velden
        If IsNumeric(txtNieuweLocatieRek.Text) And IsNumeric(txtNieuweLocatieVak.Text) And IsNumeric(txtNieuweLocatieSchap.Text) And IsNumeric(txtNieuweLocatieMaxAantal.Text) Then
            controlebestaand()

        Else
            MsgBox("Gelieve geldige waarden in te geven !")
        End If


    End Sub
    Private Sub controlebestaand()
        'controle als de locatie nog niet bestaat
        Dim oLocatie2 As New clsLocatie(txtToevoegId.Text, txtNieuweLocatieRek.Text, txtNieuweLocatieVak.Text, txtNieuweLocatieSchap.Text, cboNieuweLocatieSoort.Text, txtNieuweLocatieMaxAantal.Text)

        Dim arlLocaties As ArrayList
        arlLocaties = clsLocatieDA.GetLocaties
        Dim uitvoeren As Integer = 0

        For Each oLocatie As clsLocatie In arlLocaties
            If oLocatie2.Rek = oLocatie.Rek And oLocatie2.Vak = oLocatie.Vak And oLocatie2.Schap = oLocatie.Schap Then
                MsgBox("De locatie die u wilt toevoegen bestaat al!")
                txtboxledigen()
                uitvoeren = 1
            End If

        Next
        If uitvoeren = 0 Then
            voeruitopdatabase()
        End If

    End Sub

    Private Sub voeruitopdatabase()
        ' het uiteindelijke toevoegen van de locatie
        Try
            Dim oLocatie As New clsLocatie(txtToevoegId.Text, txtNieuweLocatieRek.Text, txtNieuweLocatieVak.Text, txtNieuweLocatieSchap.Text, cboNieuweLocatieSoort.Text, txtNieuweLocatieMaxAantal.Text)

            clsLocatieDA.VoegLocatieToe(oLocatie)

            txtboxledigen()
            RaiseEvent LocatieToegevoegd()
        Catch ex As Exception
            MessageBox.Show("Er trad een onverwachte fout op bij het toevoegen van de locatie")
        End Try
    End Sub

    Public Sub txtboxledigen()
        txtNieuweLocatieRek.Text = ""
        txtNieuweLocatieVak.Text = ""
        txtNieuweLocatieSchap.Text = ""
        txtNieuweLocatieMaxAantal.Text = ""
        cboNieuweLocatieSoort.Text = "CD"
        toevoegidingeven()
    End Sub

#End Region


End Class
