Public Class usrcntlCreditreformBoniAuskunft
    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 Event LOADED()
    Public KdNR As Integer = -1
    Public SAVED As Boolean = False
    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 As Integer)
        pnlKunde.Enabled = False
        If KdNR > 0 Then
            pnlKunde.Enabled = True
            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

        End If
        lblKdNr.Text = If(KdNR > 0, KdNR, "-")
        lblKdNr.Cursor = If(KdNR > 0, Cursors.Hand, Cursors.Default)
    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()
        txtCRDatum._value = Now
        cboCRFrauHerr.Items.Clear()
        cboCRFrauHerr.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Frau", "Frau"))
        cboCRFrauHerr.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Herr", "Herr"))
        cboCRFrauHerr.SelectedIndex = 0
        cboCRArt.Items.Clear()
        cboCRArt.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Bundesweit", "Bundesweit"))
        cboCRArt.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Wien", "Wien"))
        cboCRArt.SelectedIndex = 0
        If KdNR > 0 Then initKdNR(KdNR)
        RaiseEvent LOADED()
    End Sub

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

    Private Sub btnStandardPreiseLaden_Click(sender As Object, e As EventArgs) Handles btnStandardPreiseLaden.Click
        If FormularManagerNEU.saveCreditreform(Me) Then
            lblCRsaved.Text = "(gespeichert)"
            lblCRsaved.ForeColor = Color.Green
        End If

    End Sub

    Public Function LoadValues(ba_id) As Boolean
        Try
            Dim cBonitaetsauskunft As New VERAG_PROG_ALLGEMEIN.cBonitaetsauskunft(ba_id)

            initKdNR(cBonitaetsauskunft.ba_KundenNr)
            cboCRFrauHerr.changeItem(cBonitaetsauskunft.ba_CRAnsprechpartnerHerrFrau)
            txtCRGesprochenMit.Text = cBonitaetsauskunft.ba_CRAnsprechpartner
            cboCRArt._value = cBonitaetsauskunft.ba_CRArt
            txtCRDatum._value = cBonitaetsauskunft.ba_Datum

            txtFirma.Text = If(cBonitaetsauskunft.ba_Firma, "")
            txtAdresse1.Text = If(cBonitaetsauskunft.ba_Adresse1, "")
            txtAdresse2.Text = If(cBonitaetsauskunft.ba_Adresse2, "")
            txtLetztesBearbeitungsDatum._value = If(cBonitaetsauskunft.ba_LetztesBearbeitungsDatum, "")
            txtBonitaetsindex.Text = If(cBonitaetsauskunft.ba_BonitaetsIndex > 0, cBonitaetsauskunft.ba_BonitaetsIndex, "")
            txtGruendungsdatum._value = If(cBonitaetsauskunft.ba_GruendundsDatum, "")
            txtUmsatz._value = If(cBonitaetsauskunft.ba_Umsatz, "")
            txtMitarbeiter.Text = If(cBonitaetsauskunft.ba_Mitarbeiter, "")
            txtBankverbindung.Text = If(cBonitaetsauskunft.ba_Bankverbindung, "")
            txtZahlungsweise.Text = If(cBonitaetsauskunft.ba_Zahlungsweise, "")
            txtHoechstkredit._value = If(cBonitaetsauskunft.ba_Hoechstkredit, "")
            txtGeschaeftsfuehrerName.Text = If(cBonitaetsauskunft.ba_GFName, "")
            txtSonstiges.Text = If(cBonitaetsauskunft.ba_Sonstiges, "")
            Return True
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try
    End Function


    Private Sub lblKdNr_Click(sender As Object, e As EventArgs) Handles lblKdNr.Click
        initKdNR(-1)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim frmBonitätsverlauf As New frmBonitätsverlauf(KdNR, Me)
        frmBonitätsverlauf.Show()
    End Sub

    Private Sub txtUmsatz_TextChanged(sender As Object, e As EventArgs) Handles txtUmsatz.Leave
        If IsNumeric(txtUmsatz.Text) Then
            txtUmsatz.Text = CDbl(txtUmsatz.Text).ToString("C2")
        End If
    End Sub
End Class
