Imports System.Windows.Forms

Public Class usrCntlAdresseEZA
    Public Property _Titel As String = "ADRESSE:"
    Dim PROG As New SDL.cProgramFunctions

    Public KundenNr As Integer = -1

    Private Sub usrCntlAdresse_Layout(sender As Object, e As Windows.Forms.LayoutEventArgs) Handles Me.Layout
        Me.Label9.Text = Me._Titel
    End Sub
    Sub New()

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

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

    End Sub


    Private Sub usrCntlAdresse_Load(sender As Object, e As EventArgs) Handles Me.Load
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        initME()
    End Sub
    Public Sub initME()
        kdFirma.initKdBox(Me.FindForm, txtkdNr)
        '      MsgBox("A" & Me.Name)
        '  sbLand.initSearchBox(Me.FindForm, "LandKz,LandBez FROM [Länderverzeichnis für die Außenhandelsstatistik]", {"LandKz", "LandBez"}, "", "LandKz", "LandKz", "LandKz")
        sbLand.initSearchBox(Me.FindForm, " [Code] ,[Description] as Land  FROM tbl_DY_ZollDE_C0008_LaenderFull", {"Code", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", "Code", "Code", "Code", "FMZOLL", , 400, 200)

    End Sub

    Private Sub kdFirma_TextChanged(sender As Object, e As EventArgs) Handles kdFirma.PropertyChanged
        KundenNr = kdFirma.KdNr_value
        txtStrasse.Text = ""
        sbLand.SET_VALUE("")
        txtPlz.Text = ""
        txtOrt.Text = ""
        txtEORI.Text = ""
        '  txtAnsprechpartner.Text = ""

        FlatButton3.Enabled = (kdFirma.KdNr_value > 0)
        FlatButton3.Image = IIf(kdFirma.KdNr > 0, My.Resources.person1, My.Resources.personInaktiv)
        If kdFirma.KdNr_value > 0 Then
            If kdFirma.KdData_ADRESSEN IsNot Nothing Then
                txtStrasse.Text = If(kdFirma.KdData_ADRESSEN.Straße, "")
                sbLand.SET_VALUE(cProgramFunctions.getISO2Land(If(kdFirma.KdData_ADRESSEN.LandKz, "")))

                txtName1.Text = If(kdFirma.KdData_ADRESSEN.Name_1, "")
                txtName2.Text = If(kdFirma.KdData_ADRESSEN.Name_2, "")

                txtPlz.Text = If(kdFirma.KdData_ADRESSEN.PLZ, "")
                txtOrt.Text = If(kdFirma.KdData_ADRESSEN.Ort, "")
                'txtAnsprechpartner.Text = ""
            End If
            If kdFirma.KdData_KUNDE IsNot Nothing Then
                txtEORI.Text = If(kdFirma.KdData_KUNDE.EORITIN, "")
                txtEORINL.Text = If(kdFirma.KdData_KUNDE.EORITIN_NL, "")
            End If
        End If
    End Sub

    Private Sub FlatButton3_Click(sender As Object, e As EventArgs) Handles FlatButton3.Click
        If kdFirma.KdNr > 0 Then
            Me.Cursor = Cursors.WaitCursor
            PROG.showKd(kdFirma.KdNr)
            Me.Cursor = Cursors.Default
        End If
    End Sub


    Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click
        newKunde(kdFirma)
    End Sub


    Sub newKunde(KD As VERAG_PROG_ALLGEMEIN.KdSearchBox)
        If VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG_bool("Kundendaten_bearbeiten", "SDL") Then
            Dim frmKundenblatt As New SDL.frmKundenblatt
            frmKundenblatt.showEdit = True
            frmKundenblatt.kdNr = -1
            'frmKundenblatt.BERECHTIGUNEN = BERECHTIGUNEN
            If frmKundenblatt.ShowDialog(Me) Then
                If frmKundenblatt.kdNr > 0 Then
                    KD.KdNr = frmKundenblatt.kdNr
                End If
            End If
        Else
            Dim frmKd As New SDL.frmNeuerKunde
            frmKd.openKd = False
            frmKd.timerIntervall = 500
            frmKd.username = VERAG_PROG_ALLGEMEIN.cGlobal.AktiverMitarbeiter.mit_username
            If frmKd.username.Length > 15 Then frmKd.username = frmKd.username.Substring(0, 15)
            frmKd.tmpFiliale = VERAG_PROG_ALLGEMEIN.cGlobal.AktiverMitarbeiter.StandartFiliale
            '  frmKd.tmpKdNrKreis = 9
            If KD.KdNr = -1 Then
                frmKd.tmpKdName = KD.Text
            End If
            frmKd.ShowDialog()
            If frmKd.kdnr > 0 Then
                KD.KdNr = frmKd.kdnr
            End If

        End If

    End Sub
End Class
