Public Class usrcntlVollmacht_AT_EV
    Implements FormualrInterface

    Public Event CHANGED(name, value)
    Public Event KDNR_CHANGED(kdnr)
    Public Event DELETE(c As Control)
    Public Event MOVE_UP(c As Control)
    Public Event MOVE_DOWN(c As Control)

    Public KdNR As Integer = -1
    Public Sub ChangeKDNr(kdnr As Integer) _
       Implements FormualrInterface.ChangeKDNr
        initKdNR(kdnr)
    End Sub

    'Dim KdNR As Integer = -1
    Sub initControlsHandler()
        For Each c In Me.Controls
            Select Case c.GetType.ToString
                Case GetType(VERAG_PROG_ALLGEMEIN.MyTextBox).ToString
                    AddHandler DirectCast(c, VERAG_PROG_ALLGEMEIN.MyTextBox).Leave, Sub()
                                                                                        RaiseEvent CHANGED(c.name, c.text)
                                                                                    End Sub
                Case GetType(VERAG_PROG_ALLGEMEIN.MyComboBox).ToString
                    AddHandler DirectCast(c, VERAG_PROG_ALLGEMEIN.MyComboBox).SelectedIndexChanged, Sub()
                                                                                                        RaiseEvent CHANGED(c.name, c._value)
                                                                                                    End Sub
                Case GetType(TextBox).ToString
                    AddHandler DirectCast(c, TextBox).Leave, Sub()
                                                                 RaiseEvent CHANGED(c.name, c.text)
                                                             End Sub
            End Select
        Next
    End Sub

    Private Sub cbxEinmaligeVollmacht_CheckedChanged(sender As Object, e As EventArgs) Handles cbxEinmaligeVollmacht.CheckedChanged
        txtEinmalig_RgNr.Enabled = sender.checked
        txtEinmalig_RgDat.Enabled = sender.checked
    End Sub
    Private Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
        Dim kdsrch As New SDL.frmKundenSuche
        'Panel1.Enabled = False
        If kdsrch.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
            If IsNumeric(kdsrch.kundenNrSearch.Text) Then
                initKdNR(kdsrch.kundenNrSearch.Text)
                RaiseEvent KDNR_CHANGED(KdNR)
            End If
        End If
        '  Panel1.Enabled = True
    End Sub

    Public Sub initKdNR(KdNR)
        Me.KdNR = KdNR
        Dim KUNDE As New VERAG_PROG_ALLGEMEIN.cKunde(KdNR)
        Dim ADRESSE As New VERAG_PROG_ALLGEMEIN.cAdressen(KdNR)

        txtFirma.Text = If(ADRESSE.Name_1, "") & If(If(ADRESSE.Name_2, "") <> "", " " & ADRESSE.Name_2, "")
        txtAdresse1.Text = If(ADRESSE.Straße, "")
        txtAdresse2.Text = (If(ADRESSE.LandKz, "") & " " & If(ADRESSE.PLZ, "") & " " & If(ADRESSE.Ort, "")).ToString.Trim
        txtUid.Text = If(ADRESSE.UstIdKz, "") & If(ADRESSE.UstIdNr, "")
        txtEori.Text = If(KUNDE.EORITIN, "")
        txtTel.Text = If(ADRESSE.Telefon, "")
        txtFax.Text = If(ADRESSE.Telefax, "")
        txtEmail.Text = If(ADRESSE.E_Mail, "")
        txtAnsprechpartner.Text = (If(ADRESSE.Anrede, "") & " " & If(ADRESSE.Ansprechpartner, "")).trim

    End Sub


    Private Sub btnDel_Click(sender As Object, e As EventArgs) Handles btnDel.Click
        RaiseEvent DELETE(Me)
    End Sub

    Private Sub btnup_Click(sender As Object, e As EventArgs) Handles btnUp.Click
        RaiseEvent MOVE_UP(Me)
    End Sub

    Private Sub btnDown_Click(sender As Object, e As EventArgs) Handles btnDown.Click
        RaiseEvent MOVE_DOWN(Me)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub usrcntlVollmacht_AT_Load(sender As Object, e As EventArgs) Handles Me.Load
        initControlsHandler()
        cboSprache.Items.Clear()
        cboSprache.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Deutsch", "DE"))
        cboSprache.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Englisch", "EN"))
        If KdNR > 0 Then initKdNR(KdNR)
    End Sub

    Private Sub pic_Click(sender As Object, e As EventArgs) Handles pic.Click
        FormularManagerNEU.genPDF(Me, True)
    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles cbxEinmaligeVollmachtCarnetATA.CheckedChanged
        txtEinmalig_CarnetATA.Enabled = sender.checked
    End Sub
End Class
