Imports IntraSell_DLL
Imports IntraSell_Net_Base

''' <summary>
'''  VorgangWizzard
''' </summary>
''' <remarks></remarks>
Public Class KundenWizzard

    Dim loading As Boolean = True
    Shared Property VorgangTyp As String

    Private Sub OK_Button_Click(sender As Object, e As System.EventArgs) Handles OK_Button.Click
        Try
            NummerTextBox.Text = intrasell.kunden.GetNewKundenNummer(ComboBoxKundengruppe.SelectedValue)
            DialogResult = DialogResult.OK
            Close()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub Cancel_Button_Click(sender As Object, e As System.EventArgs) Handles Cancel_Button.Click
        DialogResult = DialogResult.Cancel
        Close()
    End Sub

    Private Sub KundenWizzard_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
        Try
            loading = True
            StandardKundengruppeAnlegen()
            FillComboBox(ComboBoxKundengruppe, "SELECT '' as Gruppe union SELECT Gruppe FROM `ofadressen-kundengruppen` ORDER By Gruppe", "Gruppe", "Gruppe")
            SetControlStatus()
            loading = False
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    ''' <summary>
    ''' setzte die Vorgangnummer für neue 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub TypComboBox_SelectedIndexChanged(sender As Object, e As System.EventArgs)
        If loading Then Return
        Try
            SetControlStatus()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub


    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetControlStatus()
        Try
            If Not String.IsNullOrEmpty(ComboBoxKundengruppe.SelectedValue) Then
                NummerTextBox.Text = intrasell.kunden.GetNewKundenNummer(ComboBoxKundengruppe.SelectedValue)
            End If

            OK_Button.Enabled = Not String.IsNullOrEmpty(ComboBoxKundengruppe.SelectedValue) And IsNumeric(NummerTextBox.Text)

        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub


    Private Sub ButtonKundengruppen_Click(sender As Object, e As EventArgs) Handles ButtonKundengruppen.Click
        Main.KundengruppenToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub ComboBoxKundengruppe_SelectedValueChanged(sender As Object, e As EventArgs) Handles ComboBoxKundengruppe.SelectedValueChanged
        Try
            If loading Then Exit Sub
            NummerTextBox.Text = intrasell.kunden.GetNewKundenNummer(ComboBoxKundengruppe.SelectedValue)
            SetControlStatus()
        Catch ex As Exception
            HandleAppError(ex, Silent:=False)
        End Try
    End Sub

End Class
