Public Class frmSearchKunde
    Dim kundenSQL As New kundenSQL
    Public KUNDE As New cKundenFMZOLL
    Dim acd As List(Of cAutoCompleteData) = kundenSQL.getKundenShort()
    Public kdnr As Integer = -1

    Private Sub cboJumpToKd_Firma_KeyDown(sender As Object, e As KeyEventArgs) Handles cboJumpToKd_Firma.KeyUp
        '  txtJumpToKd_KdNR.Text = ""
        If (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return Or e.KeyCode = Keys.Tab) AndAlso sender.text <> "" Then
            getKdNrSearch()
        End If
    End Sub

    Sub getKdNrSearch()
        Me.Enabled = False
        Me.Cursor = Cursors.WaitCursor
        For Each a In acd
            If a.AutoCompleteString.ToLower = cboJumpToKd_Firma.Text.ToLower Then
                kdnr = a.AutoCompleteProperty
                txtKdNr.Text = kdnr
                txtKdNr.Focus()
            End If
        Next
        Me.Enabled = True
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub txtKdNr_TextChanged_1(sender As Object, e As EventArgs) Handles txtKdNr.TextChanged
        lblFirma.Text = ""
        lblStrasse.Text = ""
        lblOrt.Text = ""
        If IsNumeric(txtKdNr.Text) Then
            KUNDE = kundenSQL.getKundeFMZOLLByKdNr(txtKdNr.Text)
            If Not KUNDE Is Nothing Then
                lblFirma.Text = KUNDE.Ordnungsbegriff
                lblStrasse.Text = KUNDE.Straße
                lblOrt.Text = KUNDE.LandKz & " " & KUNDE.PLZ & " " & KUNDE.Ort
            End If
        End If
    End Sub

    Private Sub txtKdNr_KeyDown(sender As Object, e As KeyEventArgs) Handles txtKdNr.KeyDown
        If (Keys.Return Or e.KeyCode = Keys.Enter) AndAlso sender.text <> "" Then
            FlatButton1.PerformClick()
        End If
    End Sub

    Private Sub btnKdSearch_Click(sender As Object, e As EventArgs) Handles btnKdSearch.Click
        getKdNrSearch()
    End Sub
    Private Sub frmSearchKunde_Load(sender As Object, e As EventArgs) Handles Me.Load

        Dim acsc As New AutoCompleteStringCollection

        For Each a In acd
            acsc.Add(a.AutoCompleteString)
            '   cboJumpToKd_Firma.Items.Add(a.AutoCompleteString)
        Next
        cboJumpToKd_Firma.AutoCompleteMode = AutoCompleteMode.SuggestAppend
        cboJumpToKd_Firma.AutoCompleteSource = AutoCompleteSource.CustomSource
        cboJumpToKd_Firma.AutoCompleteCustomSource = acsc


        cboJumpToKd_Firma.Focus()

    End Sub


    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click
        ' Set the result to pass back to the form that called this dialog
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub FlatButton2_Click(sender As Object, e As EventArgs) Handles FlatButton2.Click
        kdnr = -1
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
End Class