Imports VERAG_PROG_ALLGEMEIN

Public Class usrcntlVollmacht_MDM_NICHT_EU
    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

    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 initKdNR(KdNR)
        Me.KdNR = KdNR
        Dim KUNDE As New VERAG_PROG_ALLGEMEIN.cKunde(KdNR)
        Dim KUNDE_ERW As New VERAG_PROG_ALLGEMEIN.cKundenErweitert(KdNR)
        Dim ADRESSE As New VERAG_PROG_ALLGEMEIN.cAdressen(KdNR)
        Dim KK_List As New VERAG_PROG_ALLGEMEIN.cKundenKontakteList(KdNR)

        Dim GF As cKundenKontakte = KK_List.LIST.Find(Function(c) c.kkd_kkaId = 13 And c.kkd_KundenNr = KdNR)
        If GF IsNot Nothing Then
            txt_GF_nachname.Text = IIf(GF.kkd_AnsprechpartnerNachname <> "", GF.kkd_AnsprechpartnerNachname & " ", "")
            txt_GF_vorname.Text = IIf(GF.kkd_AnsprechpartnerVorname <> "", GF.kkd_AnsprechpartnerVorname & " ", "")
            If (GF.kkd_GebDatum IsNot Nothing AndAlso IsDate(GF.kkd_GebDatum)) Then
                txt_GF_Geb.Text = CDate(GF.kkd_GebDatum).ToShortDateString
            End If

            If (GF.kkd_Passgueltigbis IsNot Nothing AndAlso IsDate(GF.kkd_Passgueltigbis)) Then
                txt_GF_Passgueltigbis.Text = CDate(GF.kkd_Passgueltigbis).ToShortDateString
            End If

            txt_GF_Adresse.Text = If(GF.kkd_Adresse, "")
            txt_GF_Ort.Text = If(GF.kkd_Ort, "")
            txt_GF_PLZ.Text = If(GF.kkd_PLZ, "")
            cbx_GF_Land.changeItem(GF.kkd_Land)
            txt_GF_Geburtsort.Text = If(GF.kkd_Geburtsort, "")
            cbx_GF_Geburtsland.changeItem(GF.kkd_Geburtsland)
        Else
            txt_GF_nachname.Text = ""
            txt_GF_vorname.Text = ""
            txt_GF_Geb.Text = ""
            txt_GF_Adresse.Text = ""
            txt_GF_Ort.Text = ""
            txt_GF_PLZ.Text = ""
            cbx_GF_Land.changeItem("")
            txt_GF_Geburtsort.Text = ""
            cbx_GF_Geburtsland.changeItem("")
        End If

        txtFirma.Text = If(ADRESSE.Name_1, "") & If(If(ADRESSE.Name_2, "") <> "", " " & ADRESSE.Name_2, "")
        txtAdresse1.Text = If(ADRESSE.Straße, "")
        cbxLandKz.changeItem(ADRESSE.LandKz)
        txtAdresse2.Text = If(ADRESSE.PLZ, "").ToString.Trim
        txtAdresse3.Text = If(ADRESSE.Ort, "").ToString.Trim
        txtUid.Text = If(ADRESSE.UstIdKz, "") & If(ADRESSE.UstIdNr, "")
        txtTel.Text = If(ADRESSE.Telefon, "")
        txtFax.Text = If(ADRESSE.Telefax, "")
        txtSteuerNr.Text = If(ADRESSE.Steuernummer, "")
        txtEmail.Text = If(ADRESSE.E_Mail, "")
        txtAnsprechpartner.Text = (If(ADRESSE.Anrede, "") & " " & If(ADRESSE.Ansprechpartner, "")).trim
        cbxKapitalWahrung.changeItem(KUNDE_ERW.kde_KapitalWaehrung)
        txtKapital.Text = If(KUNDE_ERW.kde_Kapital, "")
        txtHRNr.Text = If(KUNDE_ERW.kde_HRNr, "")
        txtGruendungsdat.Text = If(KUNDE_ERW.kde_GruendungsDatum, "")

        If txtAdresse3.Text <> "" Then
            txtOrt.Text = txtAdresse3.Text
        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_DE_Load(sender As Object, e As EventArgs) Handles Me.Load
        initControlsHandler()



        cboLand.Items.Clear()
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("", ""))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Austria", "AT"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Belgium", "BE"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Croatia", "HR"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Croatia MÖST", "HR_MOEST"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Denmark", "DK"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Finland", "FI"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("France", "FR"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Great Britain", "GB"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Hungary", "HU"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Ireland", "IE"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Italy", "IT"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Luxenbourg", "LU"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Netherlands", "NL"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Poland", "PL"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Romania", "RO"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Sweden", "SE"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Slovakia", "SK"))
        cboLand.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Slovenia", "SI"))
        cboLand.changeItem("")

        cbxLandKz.fillWithSQL("select distinct landkz, Währungstabelle.Land  from   Währungstabelle  where landkz is not null  order by LandKz", , "FMZOLL", True)

        cbxKapitalWahrung.fillWithSQL("SELECT fw_iso3,  fw_land FROM [VERAG].[dbo].[tblWahrungtabelleNEU] order by fw_land ",  , "FMZOLL", False)

        cbx_GF_Land.Items.Clear()
        cbx_GF_Land.Items.AddRange(cbxLandKz.Items.Cast(Of VERAG_PROG_ALLGEMEIN.MyListItem).ToArray())


        cbx_GF_Geburtsland.Items.Clear()
        cbx_GF_Geburtsland.Items.AddRange(cbxLandKz.Items.Cast(Of VERAG_PROG_ALLGEMEIN.MyListItem).ToArray())

        txtEmailzurueck.Text = "juricevic@verag.ag"
        txtOrt.Text = "Suben"

        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


    Sub New()

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


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

    Private Sub cboLand_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboLand.SelectedIndexChanged
        Dim privatfirma As Boolean = False

        txtAnzahlAusdrucke.Text = 1

        Select Case cboLand._value
            Case "PL"
                cbxPrintDateAndCity.Checked = False
            Case "NL"
                privatfirma = True
            Case "HR"
                privatfirma = True
            Case Else
                privatfirma = False
        End Select

        If Not privatfirma Then
            cbxPrivatfirma.Visible = False
            cbxPrivatfirma.Checked = False
        Else
            cbxPrivatfirma.Visible = True
        End If



    End Sub
End Class
