Imports IntraSell_DLL
Imports IntraSell_Net_Base

Public Class KuechenDisplay

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

    Private Sub KuecheAuftraege_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            ParentBindingNavigator.Visible = False
            LoadData()
            AddHandler VorgangKuecheEvent, AddressOf OnVorgangKuecheEvent
            CheckBoxKuechenDisplayAktiv.Checked = IsKuechenDisplayAktiv()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub


    Sub LoadData()
        Dim offene = GetOffeneVorgaenge()
        FlowLayoutPanelAuftraege.Controls.Clear()
        If offene.Count = 0 Then
            FlowLayoutPanelAuftraege.Controls.Add(LabelWilkommen)
        End If
        For Each auftrag In offene
            Dim uc = New ucKuechenAuftrag With {
                .Vorgang = auftrag,
                .Margin = New Padding(5),
                .Height = Height - 100
            }
            AddHandler uc.FertigEvent, AddressOf OnAuftragFertig
            FlowLayoutPanelAuftraege.Controls.Add(uc)
        Next
    End Sub

    Private Sub ButtonAktualisieren_Click(sender As Object, e As EventArgs) Handles ButtonAktualisieren.Click
        Try
            LoadData()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub OnVorgangKuecheEvent(vorgang As VorgangInBearbeitung, auftrag As String)
        Try
            LoadData()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub CheckBoxKuechenDisplayAktiv_Click(sender As Object, e As EventArgs) Handles CheckBoxKuechenDisplayAktiv.Click
        Try
            SetVarValue(VARNAME_KUECHENDISPLAY_AKTIVIERT, CheckBoxKuechenDisplayAktiv.Checked)
            If CheckBoxKuechenDisplayAktiv.Checked Then
                InitKuechenDisplayData()
            End If
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub OnAuftragFertig()
        LoadData()
    End Sub

    Private Sub ButtonKuechenDisplayLink_Click(sender As Object, e As EventArgs) Handles ButtonKuechenDisplayLink.Click
        Try
            Dim achtung As New Achtung
            achtung.Show()
            achtung.ShowMessage("Küchen Display ", "Küchen Display URL kannst Du mit dem Plugin weborder.pro starten.")
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub
End Class