Imports IntraSell_DLL
Imports IntraSell_Net_Base

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

    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.vorgang.GetNewVorgangNummer(TypComboBox.SelectedValue, KundNrAdressenControl.IDNR)
            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 VorgangWizzard_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
        Try
            loading = True
            FillComboBox(TypComboBox, "SELECT '' as Typ, '' as Bezeichnung union SELECT Typ, Bezeichnung FROM buchVorgangTyp ORDER By Bezeichnung", "Bezeichnung", "Typ")
            If VorgangTyp IsNot Nothing Then
                TypComboBox.SelectedValue = VorgangTyp
            End If

            KundNrAdressenControl.IDNR = KundenIDNR
            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) Handles TypComboBox.SelectedIndexChanged
        If loading Then Return
        Try
            SetControlStatus()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub KundeAnlegenButton_Click(sender As Object, e As System.EventArgs)
        Try
            Dim k As New Kunden With {
                .BeginNewFlag = True
            }
            k.ShowDialog()
            'hier wartet bis dialog fenster zu ist
            'If k.DialogResult = Windows.Forms.DialogResult.OK Then
            KundNrAdressenControl.Refresh()
            KundNrAdressenControl.IDNR = k.AdressenDetailControl1.IDNRTextBox.Text
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetControlStatus()
        Try
            If Not String.IsNullOrEmpty(TypComboBox.SelectedValue) Then
                DatumDateTimePicker.Value = Date.Now
            Else 'disable

            End If

            OK_Button.Enabled = Not IsNull(DatumDateTimePicker.Value) And Not String.IsNullOrEmpty(TypComboBox.SelectedValue) And KundNrAdressenControl.IDNR > 0

        Catch ex As Exception
        End Try
    End Sub

    Private Sub KundNrAdressenControl_IDNRChanged(IDNR As Integer) Handles KundNrAdressenControl.IDNRChanged
        SetControlStatus()
    End Sub

End Class
