Public Class usrcntlImportaviso
    Implements FormualrInterface
    'IMPORTAVISO_AG
    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)
    Dim FV_ID = -1
    Public KdNR As Integer = -1
    Public KdFirma As String = ""
    Public SENDUNG As VERAG_PROG_ALLGEMEIN.cSendungen = Nothing
    Public AVISO As VERAG_PROG_ALLGEMEIN.caviso = Nothing


    Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub

    Sub New(param() As Object)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        If param.Length > 0 AndAlso param(0) IsNot Nothing Then KdNR = param(0)
        If param.Length > 1 Then KdFirma = param(1)
        If param.Length > 2 Then SENDUNG = param(2)
        If param.Length > 3 Then AVISO = param(3)
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub
    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 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 initSND()
        If SENDUNG IsNot Nothing Then
            txtWarenbez.Text = If(SENDUNG.tblSnd_Warenbezeichnung, "")
            txtAnzVerp.Text = If(SENDUNG.tblSnd_Colli, "")
            txtGewicht.Text = If(SENDUNG.tblSnd_Gewicht, "")
            txtAbsender.Text = If(SENDUNG.tblSnd_Absender, "")
           
        End If
        If AVISO IsNot Nothing Then
            txtLKWKennz.Text = If(AVISO.LKW_Nr, "")
            txtUnternehmer.Text = If(AVISO.Frächter, "")
            cbxLKWWartet.Checked = (AVISO.Status = VERAG_PROG_ALLGEMEIN.cGlobal.Status_Ankunft)
        End If
    End Sub

    Public Sub initKdNR(KdNR)
        If KdNR > 0 Then
            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, "")
            '  txtAnsprechpartnerVERAG.Text = If(ADRESSE.Ansprechpartner, "")
        Else
            txtFirma.Text = KdFirma
        End If

    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 usrcntlVollmacht_AT_Load(sender As Object, e As EventArgs) Handles Me.Load
       
        cboFirma.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VERAG Spedition AG", "AG"))
        cboFirma.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VERAG Customs Service GmbH", "CS"))
        cboFirma.changeItem("AG")
     
        initControlsHandler()
        txtAnsprechpartnerVERAG.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME
     
        If IsNumeric(VERAG_PROG_ALLGEMEIN.cAllgemein.MITARBEITER.mit_durchwahl) Then
            txtDW.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.MITARBEITER.mit_durchwahl
        End If
        initKdNR(KdNR)
        initSND()
    End Sub

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

   


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If KdNR > 0 Then
            Dim f As New frmKundenUebersichtZOLL(KdNR)
            f.ShowDialog(Me)
        End If
    End Sub

    


End Class
