Imports IntraSell_DLL
Imports IntraSell_Net_Base

Public Class TelefonischeBestellung
    Inherits AbstractForm

    Dim INITIAL_TOP_ORDERLIST As Integer

    Private Sub Form_Verlassen() Handles MyBase.Verlassen
        Me.Close()
    End Sub

    Private Sub TelefonischeBestellung_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            ParentBindingNavigator.Visible = False
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Public Sub LadeKunde(idnr As Integer)
        TouchOrdersListe2.FilterByKundNr(idnr)
        Dim anzahlDerBestellungen = TouchOrdersListe2.DataGridViewVorgangListe.Rows.Count
        If anzahlDerBestellungen > 0 Then
            TabPageAlteOrders.Text = $"Frühere Bestellungen ({anzahlDerBestellungen})"
            TabPageAlteOrders.BackColor = System.Drawing.SystemColors.Highlight
        End If
    End Sub

    Private Sub TouchKundeAnlegen1_IDNRChanged(idnr As Integer) Handles TouchKundeAnlegen1.IDNRChanged
        Try
            LadeKunde(idnr)
        Catch ex As Exception
            HandleAppError(ex, Silent:=True)
        End Try
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="idnr"></param>
    ''' <param name="notiz"></param>
    ''' <remarks></remarks>
    Private Sub TouchKundeAnlegen1_Order(idnr As Integer, notiz As String, lieferMethode As String, typ As String) Handles TouchKundeAnlegen1.Order
        Try
            'Kunde Angelegt kann weiter eine Order erfasst werden

            If typ = VorgangTypen.AU Then
                Dim neueBestellung As New OffeneBestellung(0, VorgangTypen.AU, idnr, Nothing, notiz, lieferMethode)
                TouchBestellung.MdiParent = Main
                TouchBestellung.Show()
                TouchBestellung.ZeigeListe(True)
                TouchBestellung.StarteNeueBestellung(neueBestellung)
            ElseIf typ = VorgangTypen.AR Then
                Dim bar = New VorgangBar With {
                    .MdiParent = Main
                }
                bar.Show()
                bar.BeginNewVorgang(VorgangTypen.AR, idnr, notiz, lieferMethode)
            End If

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

    Sub SucheNachNummer(telnummer As String)
        TouchKundeAnlegen1.SucheNachNummer(telnummer)
    End Sub

    Private Sub ZustellgebieteToolStripMenuItem_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub ButtonZustellgebiete_Click(sender As Object, e As EventArgs) Handles ButtonZustellgebiete.Click
        ZustellgebieteToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub ButtonZustellpreise_Click(sender As Object, e As EventArgs) Handles ButtonZustellpreise.Click
        Try
            OeffneKundenPreise(IDNR:=-1, Preisliste:=Transportmethoden.Zustellung)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ButtonaAbholpreise_Click(sender As Object, e As EventArgs) Handles ButtonaAbholpreise.Click
        Try
            OeffneKundenPreise(IDNR:=-1, Preisliste:=Transportmethoden.Abholung)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ButtonEinstellungen_Click(sender As Object, e As EventArgs) Handles ButtonEinstellungen.Click
        Try
            Einstellungen.MdiParent = Main
            Einstellungen.Show()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ZustellpreiseToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ZustellpreiseToolStripMenuItem.Click

    End Sub

    Private Sub ZustellungToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ZustellungToolStripMenuItem.Click
        ButtonZustellpreise_Click(Nothing, Nothing)
    End Sub

    Private Sub AbholungToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AbholungToolStripMenuItem.Click
        ButtonaAbholpreise_Click(Nothing, Nothing)
    End Sub

    Private Sub EinstellungenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EinstellungenToolStripMenuItem.Click

    End Sub



    Sub UpdateRoute()
        Try
            If TouchKundeAnlegen1.PLZ <> "" And TouchKundeAnlegen1.Adresse <> "" Then
                UcRoute1.RouteNach(TouchKundeAnlegen1.PLZ, TouchKundeAnlegen1.Ort, TouchKundeAnlegen1.Adresse)
                UcRoute1.Route()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ButtonRoute_Click(sender As Object, e As EventArgs) Handles ButtonRoute.Click
        UpdateRoute()
    End Sub

    Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles TabPage2.Enter
        UpdateRoute()
    End Sub

    Private Sub TabControl1_TabIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
        If TabControl1.SelectedIndex = 1 Then
            UpdateRoute()
        End If
    End Sub

    Private Sub FahrerabrechnungToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FahrerabrechnungToolStripMenuItem.Click
        Try
            ZustellerAbrechnung.Show()
            ZustellerAbrechnung.Focus()
            ZustellerAbrechnung.BringToFront()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    'Save Kunde
    Friend Sub BindingNavigatorSaveItem_Click(sender As Object, e As System.EventArgs) Handles MyBase.Save
        Try
            TouchKundeAnlegen1.Save()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub KassaEinstellungenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles KassaEinstellungenToolStripMenuItem.Click
        ButtonEinstellungen_Click(Nothing, Nothing)
    End Sub

    Private Sub ZustellgebieteToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ZustellgebieteToolStripMenuItem1.Click
        Zustellgebiete.MdiParent = Main
        Zustellgebiete.Show()
    End Sub

    Private Sub KundenBeimAnrufenErkennenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles KundenBeimAnrufenErkennenToolStripMenuItem.Click
        FormKundenErkennen.Show()
    End Sub
End Class