
Imports System.Web.UI.WebControls.Expressions
Imports com.sun.org.apache.xpath.internal.functions
Imports VERAG_PROG_ALLGEMEIN

Public Class frmEssensbestellungen

    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
    Dim essen As New cEssensbestellung()
    Dim dt As New DataTable
    Dim ttMontag, ttDienstag, ttMittwoch, ttDonnerstag, ttFreitag As New ToolTip()
    Private ToolTipFont As New Font("Courier New", 12)
    Dim preisProMahlzeit As Double = 3
    Dim menu As String = "Menü"
    Dim alacarte As String = "A la carte"
    Dim outdated As Boolean = False
    Dim urlaub As String = "urlaub"
    Dim feiertag As String = "feiertag"


    Private Sub frmEssensbestellungen_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        PictureBox5.Visible = True

        Dim list As New List(Of MyListItem)
        list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Kebap", "Kebap"))
        list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Dürüm", "Dürüm"))
        'list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("", ""))

        cbxMenu.fillWithSQL("SELECT Distinct Top 50 (REPLACE(MenuTitel,'Wochenkarte ','')) + ' - ' +  Convert(varchar, Year(MenuDateVon)) , MenuDateVon from tblEBMenu order by MenuDateVon desc", True, "AVISO", True) '/ where MenuDateVon >= GETDATE() 

        cbxAlt_montag.Items.AddRange(list.ToArray())
        cbxAlt_dienstag.Items.AddRange(list.ToArray())
        cbxAlt_mittwoch.Items.AddRange(list.ToArray())
        cbxAlt_donnerstag.Items.AddRange(list.ToArray())
        cbxAlt_freitag.Items.AddRange(list.ToArray())

        txtMA.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME
        txtAbteilung.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.ABTEILUNG
        loadDGVBestellungen()

        cbxGebauede.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Frontoffice", "Frontoffice"))
        'cbxGebauede.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Backoffice", "Backoffice"))
        cbxGebauede.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Verag VERR", "Verag VERR"))
        cbxGebauede.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Maut", "Maut"))
        cbxGebauede.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Suben West", "Suben West"))
        cbxGebauede.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("", ""))
        cbxGebauede.changeItem("")
        btnSave.Enabled = False
        calcOffeneSumme()

    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

        If cbxGebauede._value = "" Then
            MsgBox("Bitte Gebäude für die Essensbestellung angeben!")
            Exit Sub
        End If

        Dim menuDate = cbxMenu.SelectedItem.ToString.Replace(cbxMenu.SelectedItem.Value & " - ", "")
        Dim MenuID As String = SQL.getValueTxtBySql("select MenuID from tblEBMenu where MenuDateVon = '" & menuDate & "'", "AVISO")

        essen = New cEssensbestellung(cbxMenu._value, cAllgemein.USRID, cbxGebauede._value, cAllgemein.ABTEILUNG, cAllgemein.MITARBEITER.mit_vname & " " & cAllgemein.MITARBEITER.mit_nname, txtAnmerkung)

        If cb_montag.Checked Then
            If rbMenu_montag.Checked Then
                essen.eb_montag = menu
                setWarning(False)
            ElseIf rbMenuAlt_montag.Checked Then

                If cbxAlt_montag._value.ToString.Replace(" ", "") <> "" Then
                    essen.eb_montag = cbxAlt_montag._value 'txtAlt_montag.Text.ToString
                    setWarning(False)
                Else
                    setWarning(True)
                    Exit Sub
                End If
            Else
                essen.eb_montag = Nothing
            End If
            setWarning(False)
        Else
            essen.eb_montag = Nothing
        End If


        If cb_dienstag.Checked Then
            If rbMenu_dienstag.Checked Then
                essen.eb_dienstag = menu
                setWarning(False)
            ElseIf rbMenuAlt_dienstag.Checked Then
                If cbxAlt_dienstag._value.ToString.Replace(" ", "") <> "" Then
                    essen.eb_dienstag = cbxAlt_dienstag._value 'txtAlt_dienstag.Text.ToString
                    setWarning(False)
                Else
                    setWarning(True)
                    Exit Sub
                End If
            Else
                essen.eb_dienstag = Nothing
            End If
            setWarning(False)
        Else
            essen.eb_dienstag = Nothing
        End If

        If cb_mittwoch.Checked Then
            If rbMenu_mittwoch.Checked Then
                essen.eb_mittwoch = menu
                setWarning(False)
            ElseIf rbMenuAlt_mittwoch.Checked Then
                If cbxAlt_mittwoch._value.ToString.Replace(" ", "") <> "" Then
                    essen.eb_mittwoch = cbxAlt_mittwoch._value 'txtAlt_mittwoch.Text.ToString
                    setWarning(False)
                Else
                    setWarning(True)
                    Exit Sub
                End If
            Else
                essen.eb_mittwoch = Nothing
            End If
            setWarning(False)
        Else
            essen.eb_mittwoch = Nothing
        End If

        If cbdonnerstag.Checked Then
            If rbMenu_donnerstag.Checked Then
                essen.eb_donnerstag = menu
                setWarning(False)
            ElseIf rbMenuAlt_donnerstag.Checked Then
                If cbxAlt_donnerstag._value.ToString.Replace(" ", "") <> "" Then
                    essen.eb_donnerstag = cbxAlt_donnerstag._value 'txtAlt_donnerstag.Text.ToString
                    setWarning(False)
                Else
                    setWarning(True)
                    Exit Sub
                End If
            Else
                essen.eb_donnerstag = Nothing
            End If
            setWarning(False)
        Else
            essen.eb_donnerstag = Nothing
        End If

        If cb_freitag.Checked Then
            If rbMenu__freitag.Checked Then
                essen.eb_freitag = menu
                setWarning(False)
            ElseIf rbMenuAlt_freitag.Checked Then
                If cbxAlt_freitag._value.ToString.Replace(" ", "") <> "" Then
                    essen.eb_freitag = cbxAlt_freitag._value 'txtAlt_freitag.Text.ToString
                    setWarning(False)
                Else
                    setWarning(True)
                    Exit Sub
                End If
            Else
                essen.eb_freitag = Nothing
            End If
            setWarning(False)
        Else
            essen.eb_freitag = Nothing
        End If

        If txtPreis.Text IsNot "" Then
            essen.eb_preis = CDbl(txtPreis.Text)
        End If

        essen.eb_datum = CDate(dt.Rows(0).Item("MenuDateVon"))
        essen.eb_gebaeude = cbxGebauede._value
        essen.eb_anmerkung = txtAnmerkung.Text
        essen.eb_firma = cAllgemein.MITARBEITER.getFirma
        essen.eb_MenuID = MenuID

        essen.SAVE()
        loadDGVBestellungen()

    End Sub


    Private Sub cbxMenu_SelectedValueChanged(sender As Object, e As EventArgs) Handles cbxMenu.SelectedValueChanged

        If cbxMenu._value Is Nothing Or cbxMenu._value = "" Then
            'Button1.Visible = False
            lblDatum.Text = "Datum: "
            lblBestellungBis.Text = ""
            loadDGVBestellungen()
            btnSave.Enabled = False

            For Each comp As System.ComponentModel.Component In Me.components.Components
                If TypeOf comp Is ToolTip Then
                    Dim tip = DirectCast(comp, ToolTip)
                    tip.RemoveAll()
                End If
            Next

            Exit Sub
        End If

        btnSave.Enabled = True
        'Button1.Visible = True
        dt.Clear()
        dt = SQL.loadDgvBySql("SELECT Top 1 * from (SELECT (REPLACE(MenuTitel,'Wochenkarte ','')) + ' - ' +  Convert(varchar, Year(MenuDateVon)) as kwDate, * FROM tblEBMenu) kwDate where kwDate = '" & cbxMenu._value & "'", "AVISO", 100, True)

        If dt.Rows.Count > 0 Then
            If checkIfOrderIsPossible() Then
                MyPanel1.Enabled = True
            Else
                MyPanel1.Enabled = False
            End If
            lblDatum.Text = "Datum: " & CDate(dt.Rows(0).Item("MenuDateVon")).ToString("dd.MM.yyyy") & " - " & CDate(dt.Rows(0).Item("MenuDateBis")).ToString("dd.MM.yyyy")
            loadMenuInfo(dt)

            btnSave.Enabled = True
        Else
            btnSave.Enabled = False
        End If

        uncheckGroupBoxesAndRadioButtons(sender, e)
        loadDGVBestellungen()

    End Sub

    Private Sub rbaLaCarte_CheckedChanged(sender As Object, e As EventArgs) Handles rbMenuAlt_montag.CheckedChanged, rbMenuAlt_dienstag.CheckedChanged, rbMenuAlt_donnerstag.CheckedChanged, rbMenuAlt_mittwoch.CheckedChanged, rbMenuAlt_freitag.CheckedChanged

        If rbMenuAlt_montag.Checked Then
            'txtAlt_montag.Visible = True
            cbxAlt_montag.Visible = True
        Else
            cbxAlt_montag.Visible = False
            'txtAlt_montag.Visible = False
        End If

        If rbMenuAlt_dienstag.Checked Then
            cbxAlt_dienstag.Visible = True
            'txtAlt_dienstag.Visible = True
        Else

            cbxAlt_dienstag.Visible = False
            'txtAlt_dienstag.Visible = False
        End If

        If rbMenuAlt_mittwoch.Checked Then
            cbxAlt_mittwoch.Visible = True
            'txtAlt_mittwoch.Visible = True
        Else
            cbxAlt_mittwoch.Visible = False
            'txtAlt_mittwoch.Visible = False
        End If


        If rbMenuAlt_donnerstag.Checked Then
            cbxAlt_donnerstag.Visible = True
            'txtAlt_donnerstag.Visible = True
        Else
            cbxAlt_donnerstag.Visible = False
            'txtAlt_donnerstag.Visible = False
        End If

        If rbMenuAlt_freitag.Checked Then
            cbxAlt_freitag.Visible = True
            'txtAlt_freitag.Visible = True
        Else
            cbxAlt_freitag.Visible = False
            'txtAlt_freitag.Visible = False
        End If
        countChecks()
    End Sub

    Private Sub cbFields_CheckedChanged(sender As Object, e As EventArgs) Handles cb_montag.CheckedChanged, cb_dienstag.CheckedChanged, cb_mittwoch.CheckedChanged, cbdonnerstag.CheckedChanged, cb_freitag.CheckedChanged


        If cb_montag.Checked Then
            If Not txtMenu_montag.Text.ToLower.StartsWith(urlaub) AndAlso Not txtMenu_montag.Text.ToLower.StartsWith(feiertag) Then
                rbMenuAlt_montag.Enabled = True
                rbMenu_montag.Enabled = True
                cbxAlt_montag.Enabled = True
                If checkIfGroupBoxIsSetFirstTime(GroupBoxMontag) Then
                    rbMenu_montag.Checked = True
                End If
            End If

        Else
            rbMenuAlt_montag.Enabled = False
            rbMenu_montag.Enabled = False
            cbxAlt_montag.Enabled = False
            txtAlt_montag.Text = ""
        End If


        If cb_dienstag.Checked Then
            If Not txtMenu_dienstag.Text.ToLower.StartsWith(urlaub) AndAlso Not txtMenu_dienstag.Text.ToLower.StartsWith(feiertag) Then
                rbMenuAlt_dienstag.Enabled = True
                rbMenu_dienstag.Enabled = True
                cbxAlt_dienstag.Enabled = True
                If checkIfGroupBoxIsSetFirstTime(GroupBoxDienstag) Then
                    rbMenu_dienstag.Checked = True
                End If
            End If

        Else
            rbMenu_dienstag.Enabled = False
            rbMenuAlt_dienstag.Enabled = False
            cbxAlt_dienstag.Enabled = False
            txtAlt_dienstag.Text = ""
        End If

        If cb_mittwoch.Checked Then
            If Not txtMenu_mittwoch.Text.ToLower.StartsWith(urlaub) AndAlso Not txtMenu_mittwoch.Text.ToLower.StartsWith(feiertag) Then
                rbMenuAlt_mittwoch.Enabled = True
                cbxAlt_mittwoch.Enabled = True
                rbMenu_mittwoch.Enabled = True
                If checkIfGroupBoxIsSetFirstTime(Mittwoch) Then
                    rbMenu_mittwoch.Checked = True
                End If
            End If

        Else
            rbMenu_mittwoch.Enabled = False
            rbMenuAlt_mittwoch.Enabled = False
            cbxAlt_mittwoch.Enabled = False
            txtAlt_mittwoch.Text = ""
        End If


        If cbdonnerstag.Checked Then
            If Not txtMenu_donnerstag.Text.ToLower.StartsWith(urlaub) AndAlso Not txtMenu_donnerstag.Text.ToLower.StartsWith(feiertag) Then
                rbMenuAlt_donnerstag.Enabled = True
                cbxAlt_donnerstag.Enabled = True
                rbMenu_donnerstag.Enabled = True
                If checkIfGroupBoxIsSetFirstTime(GroupBoxDonnerstag) Then
                    rbMenu_donnerstag.Checked = True
                End If
            End If

        Else
            rbMenu_donnerstag.Enabled = False
            rbMenuAlt_donnerstag.Enabled = False
            cbxAlt_donnerstag.Enabled = False
            txtAlt_donnerstag.Text = ""
        End If

        If cb_freitag.Checked Then
            If Not txtMenu_freitag.Text.ToLower.StartsWith(urlaub) AndAlso Not txtMenu_freitag.Text.ToLower.StartsWith(feiertag) Then
                rbMenuAlt_freitag.Enabled = True
                rbMenu__freitag.Enabled = True
                cbxAlt_freitag.Enabled = True
                If checkIfGroupBoxIsSetFirstTime(GroupBoxFreitag) Then
                    rbMenu__freitag.Checked = True
                End If
            End If

        Else
            rbMenu__freitag.Enabled = False
            rbMenuAlt_freitag.Enabled = False
            cbxAlt_freitag.Enabled = False
            txtAlt_freitag.Text = ""
        End If
        countChecks()
    End Sub


    Private Sub loadDGVBestellungen()

        Dim SQLWhere As String = ""
        If cbxMenu._value IsNot "" Then SQLWhere = " AND [eb_kw] = '" & cbxMenu._value.ToString & "'"

        Dim SQLString As String = "SELECT [eb_kw], [eb_mitid] , [eb_gebaeude],[eb_abteilung],[eb_montag],[eb_dienstag],[eb_mittwoch],[eb_donnerstag] ,[eb_freitag],[eb_preis], [eb_mitname], [eb_datum], [eb_anmerkung], [eb_abgerechnet], [eb_storniert] FROM [tblEssensbestellungen] where [eb_mitid] = '" & VERAG_PROG_ALLGEMEIN.cAllgemein.USRID & "'" & SQLWhere & " order by [eb_datum] desc"

        dgvBestellungen.SET_SQL(SQLString, "AVISO", ,)
        dgvBestellungen.LOAD()


        If dgvBestellungen.Columns.Count < 1 Then Exit Sub

        With dgvBestellungen
            .RowHeadersWidth = 10
            .Columns("eb_kw").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
            .Columns("eb_kw").HeaderText = "KW"
            .Columns("eb_mitid").Visible = False
            .Columns("eb_mitname").Visible = False
            .Columns("eb_datum").Visible = False
            .Columns("eb_storniert").Visible = False
            .Columns("eb_abteilung").Visible = False
            .Columns("eb_montag").Width = 80
            .Columns("eb_montag").HeaderText = "Montag"
            .Columns("eb_montag").Width = 80
            .Columns("eb_dienstag").HeaderText = "Dienstag"
            .Columns("eb_dienstag").Width = 80
            .Columns("eb_mittwoch").HeaderText = "Mittwoch"
            .Columns("eb_mittwoch").Width = 80
            .Columns("eb_donnerstag").HeaderText = "Donnerstag"
            .Columns("eb_donnerstag").Width = 80
            .Columns("eb_freitag").HeaderText = "Freitag"
            .Columns("eb_freitag").Width = 80
            .Columns("eb_gebaeude").HeaderText = "Gebäude"
            .Columns("eb_gebaeude").Width = 80
            .Columns("eb_preis").HeaderText = "Preis"
            .Columns("eb_preis").Width = 40
            .Columns("eb_preis").DefaultCellStyle.Format = "N"
            .Columns("eb_anmerkung").HeaderText = "Anm."
            .Columns("eb_anmerkung").Width = 70
            .Columns("eb_abgerechnet").HeaderText = "verrechnet"
            .Columns("eb_abgerechnet").Width = 70
        End With

        For Each row As DataGridViewRow In dgvBestellungen.Rows
            If Not IsDBNull(row.Cells("eb_abgerechnet").Value) Then
                If row.Cells("eb_abgerechnet").Value Then row.DefaultCellStyle.BackColor = Color.LightGreen
            End If
            If Not IsDBNull(row.Cells("eb_storniert").Value) Then
                If row.Cells("eb_storniert").Value Then
                    row.DefaultCellStyle.BackColor = Color.IndianRed
                    row.DefaultCellStyle.Font = New Font(Me.Font.FontFamily, Me.Font.Size, FontStyle.Strikeout)

                End If
            End If

        Next


    End Sub

    Private Sub uncheckGroupBoxesAndRadioButtons(sender, e)
        For Each gb As Control In MyPanel1.Controls
            If TypeOf gb Is GroupBox Then
                For Each c As Control In gb.Controls
                    If TypeOf c Is CheckBox Then
                        Dim checkbox As CheckBox = c
                        checkbox.Checked = False
                    End If
                    If TypeOf c Is RadioButton Then
                        Dim radiobutton As RadioButton = c
                        radiobutton.Checked = False
                    End If

                Next
            End If
        Next
        cbFields_CheckedChanged(sender, e)
    End Sub

    Private Sub countChecks()

        Dim countMenus As Integer
        Dim countlaCarte As Integer
        Dim countKebab As Integer

        countMenus = 0
        countlaCarte = 0
        countKebab = 0

        For Each gb As Control In MyPanel1.Controls
            If TypeOf gb Is GroupBox Then
                For Each c As Control In gb.Controls

                    If c.Text.ToLower.StartsWith(menu.ToLower) AndAlso TypeOf c Is VERAG_PROG_ALLGEMEIN.MyRadioButton AndAlso (c.Enabled = True Or outdated = True And MyPanel1.Enabled = False) Then
                        Dim rb As VERAG_PROG_ALLGEMEIN.MyRadioButton = c
                        If rb.Checked Then countMenus = countMenus + 1
                    End If

                    If c.Text.ToLower.StartsWith(alacarte.ToLower) AndAlso TypeOf c Is VERAG_PROG_ALLGEMEIN.MyRadioButton AndAlso (c.Enabled = True Or outdated = True And MyPanel1.Enabled = False) Then
                        Dim rb As VERAG_PROG_ALLGEMEIN.MyRadioButton = c
                        If rb.Checked Then countlaCarte = countlaCarte + 1

                    End If

                    If TypeOf c Is VERAG_PROG_ALLGEMEIN.MyComboBox AndAlso (c.Enabled = True Or outdated = True And MyPanel1.Enabled = False) Then
                        Dim cbx As VERAG_PROG_ALLGEMEIN.MyComboBox = c

                        If cbx.Visible = True AndAlso cbx.SelectedItem IsNot Nothing Then
                            'If gb.Enabled Then
                            countKebab = countKebab + 1
                            countlaCarte = countlaCarte - 1
                        End If
                        'End If
                    End If

                Next
            End If
        Next

        txtAnzahlMenu.Text = countMenus.ToString()
        txtAnzahlLaCart.Text = countlaCarte.ToString
        txtAnzahlKeb.Text = countKebab.ToString

        If CDate(dt.Rows(0).Item("MenuDateVon")).ToString("dd.MM.yyyy") >= DateTime.Parse("01/06/2024") Then

            txtPreis.Text = (CDbl(countKebab) + CDbl(countMenus)) * 3 + CDbl(countlaCarte) * 5
        Else

            txtPreis.Text = (CDbl(countlaCarte) + CDbl(countMenus) + CDbl(countKebab)) * preisProMahlzeit
        End If

        'IIf(bestellung.eb_storniert, preisProMahlzeit * 0, preisProMahlzeit * 1)


    End Sub

    Private Sub loadMenuInfo(dt As DataTable)

        If dt.Rows(0).Item("MenuEssenMo") IsNot Nothing Then
            'pbMontag.Visible = True
            rbMenu_montag.Text = menu
            txtMenu_montag.Text = dt.Rows(0).Item("MenuEssenMo").ToString

            ttMontag.SetToolTip(pb_montag, dt.Rows(0).Item("MenuEssenMo").ToString)
        Else
            pb_montag.Visible = False
            txtMenu_montag.Text = ""
        End If


        If dt.Rows(0).Item("MenuEssenDi") IsNot Nothing Then
            'pbDienstag.Visible = True
            rbMenu_dienstag.Text = menu
            txtMenu_dienstag.Text = dt.Rows(0).Item("MenuEssenDi").ToString()
            ttDienstag.SetToolTip(pb_dienstag, dt.Rows(0).Item("MenuEssenDi").ToString)

        Else
            pb_dienstag.Visible = False
        End If


        If dt.Rows(0).Item("MenuEssenMi") IsNot Nothing Then
            'pbMittwoch.Visible = True
            rbMenu_mittwoch.Text = menu
            txtMenu_mittwoch.Text = dt.Rows(0).Item("MenuEssenMi").ToString()
            ttMittwoch.SetToolTip(pb_mittwoch, dt.Rows(0).Item("MenuEssenMi").ToString)
        Else
            pb_mittwoch.Visible = False
        End If

        If dt.Rows(0).Item("MenuEssenDo") IsNot Nothing Then
            'pbDonnerstag.Visible = True
            rbMenu_donnerstag.Text = menu
            txtMenu_donnerstag.Text = dt.Rows(0).Item("MenuEssenDo").ToString()
            ttDonnerstag.SetToolTip(pb_donnerstag, dt.Rows(0).Item("MenuEssenDo").ToString)
        Else
            pb_donnerstag.Visible = False
        End If

        If dt.Rows(0).Item("MenuEssenFr") IsNot Nothing Then
            'pbFreitag.Visible = True
            rbMenu__freitag.Text = menu
            txtMenu_freitag.Text = dt.Rows(0).Item("MenuEssenFr").ToString()
            ttFreitag.SetToolTip(pb_freitag, dt.Rows(0).Item("MenuEssenFr").ToString)
        Else
            pb_freitag.Visible = False
        End If

    End Sub

    Private Sub dgvBestellungen_Click(sender As Object, e As EventArgs) Handles dgvBestellungen.Click

        If dgvBestellungen.Rows.Count = 0 Then Exit Sub

        Dim currentEssen As New cEssensbestellung(dgvBestellungen.CurrentRow.Cells("eb_kw").Value, dgvBestellungen.CurrentRow.Cells("eb_mitid").Value, dgvBestellungen.CurrentRow.Cells("eb_gebaeude").Value, dgvBestellungen.CurrentRow.Cells("eb_abteilung").Value, dgvBestellungen.CurrentRow.Cells("eb_mitname").Value, dgvBestellungen.CurrentRow.Cells("eb_anmerkung").Value)

        cbxMenu.changeItem(currentEssen.eb_kw)

        If currentEssen.eb_montag IsNot Nothing Then
            cb_montag.Checked = True
            If currentEssen.eb_montag.ToString = menu Then
                rbMenu_montag.Checked = True
            Else
                rbMenuAlt_montag.Checked = True
                If currentEssen.eb_montag IsNot Nothing Then cbxAlt_montag.changeItem(currentEssen.eb_montag.ToString)
                If cbxAlt_montag.SelectedValue = Nothing Then
                    cbxAlt_montag.Text = currentEssen.eb_montag.ToString
                End If
            End If
        Else
            cb_montag.Checked = False
        End If



        If currentEssen.eb_dienstag IsNot Nothing Then
            cb_dienstag.Checked = True
            If currentEssen.eb_dienstag.ToString = menu Then
                rbMenu_dienstag.Checked = True
            Else
                rbMenuAlt_dienstag.Checked = True
                If currentEssen.eb_dienstag IsNot Nothing Then cbxAlt_dienstag.changeItem(currentEssen.eb_dienstag.ToString)
                If cbxAlt_dienstag.SelectedValue = Nothing Then
                    cbxAlt_dienstag.Text = currentEssen.eb_dienstag.ToString
                End If
            End If
        Else
            cb_dienstag.Checked = False
        End If


        If currentEssen.eb_mittwoch IsNot Nothing Then
            cb_mittwoch.Checked = True
            If currentEssen.eb_mittwoch.ToString = menu Then
                rbMenu_mittwoch.Checked = True
            Else
                rbMenuAlt_mittwoch.Checked = True
                If currentEssen.eb_mittwoch IsNot Nothing Then cbxAlt_mittwoch.changeItem(currentEssen.eb_mittwoch.ToString)
                If cbxAlt_mittwoch.SelectedValue = Nothing Then
                    cbxAlt_mittwoch.Text = currentEssen.eb_mittwoch.ToString
                End If
            End If
        Else
            cb_mittwoch.Checked = False
        End If


        If currentEssen.eb_donnerstag IsNot Nothing Then
            cbdonnerstag.Checked = True
            If currentEssen.eb_donnerstag.ToString = menu Then
                rbMenu_donnerstag.Checked = True
            Else
                rbMenuAlt_donnerstag.Checked = True
                If currentEssen.eb_donnerstag IsNot Nothing Then cbxAlt_donnerstag.changeItem(currentEssen.eb_donnerstag.ToString)
                If cbxAlt_donnerstag.SelectedValue = Nothing Then
                    cbxAlt_donnerstag.Text = currentEssen.eb_donnerstag.ToString
                End If
            End If
        Else
            cbdonnerstag.Checked = False
        End If



        If currentEssen.eb_freitag IsNot Nothing Then
            cb_freitag.Checked = True
            If currentEssen.eb_freitag.ToString = menu Then
                rbMenu__freitag.Checked = True
            Else
                rbMenuAlt_freitag.Checked = True
                If currentEssen.eb_freitag IsNot Nothing Then cbxAlt_freitag.changeItem(currentEssen.eb_freitag.ToString)
                If cbxAlt_freitag.SelectedValue = Nothing Then
                    cbxAlt_freitag.Text = currentEssen.eb_freitag.ToString
                End If
            End If
        Else
            cb_freitag.Checked = False
        End If


        cbxGebauede._value = currentEssen.eb_gebaeude
        txtAnmerkung.Text = currentEssen.eb_anmerkung


    End Sub

    Private Sub ToolTipInfoMo_Draw(sender As Object, e As DrawToolTipEventArgs) Handles ToolTipInfoMo.Draw, ToolTipInfoDi.Draw, ToolTipInfoMi.Draw, ToolTipInfoDo.Draw, ToolTipInfoFr.Draw
        e.DrawBackground()
        e.DrawBorder()
        e.Graphics.DrawString(e.ToolTipText,
                          Me.ToolTipFont,
                          Brushes.Black,
                          e.Bounds)


    End Sub

    Private Sub ToolTipInfoMo_Popup(sender As Object, e As PopupEventArgs) Handles ToolTipInfoMo.Popup

        e.ToolTipSize = TextRenderer.MeasureText(Me.ToolTipInfoMo.GetToolTip(e.AssociatedControl), Me.ToolTipFont)

    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click

        Dim webAddress As String = "http://www.highway-118.de/speisekarte/speisekarte.html"
        Process.Start(webAddress)
    End Sub

    Private Function checkIfOrderIsPossible() As Boolean

        If dt.Rows.Count = 0 Then
            outdated = True
            Return False
        End If

        Try
            Dim startMenu = Date.Parse(dt.Rows(0).Item("MenuDateVon"))

            Dim tageBisBestellende = dt.Rows(0).Item("MenuBestellungBisTageVorher") * -1

            If tageBisBestellende > 0 Then
                lblTest.Text = "Zu Testzwecken darf aktuell " & tageBisBestellende & " Tage im Nachhinein bestellt werden!"
            Else
                lblTest.Text = ""
            End If

            Dim newTime As New TimeSpan(14, 30, 0)
            Dim timeToOrderLimit = startMenu.AddDays(tageBisBestellende) + newTime
            lblBestellungBis.Text = "Bestellung möglich bis: " & timeToOrderLimit.ToShortDateString & " - " & timeToOrderLimit.ToShortTimeString

            If Now >= timeToOrderLimit Then
                lblBestellungBis.ForeColor = Color.Red
                outdated = True
                Return False
            Else
                lblBestellungBis.ForeColor = Color.Black
                outdated = False
                Return True
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try


    End Function


    Private Sub rbMenu_Mo_Click(sender As Object, e As EventArgs) Handles rbMenu_montag.Click, rbMenu_dienstag.Click, rbMenu_mittwoch.Click, rbMenu_donnerstag.Click, rbMenu__freitag.Click
        countChecks()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'If cbxMenu._value Is Nothing Then Exit Sub
        'Process.Start("\\YM5T001348\Gastro\FTPUpload\Menues\" & cbxMenu._value & ".pdf")

    End Sub

    Private Sub PictureBox5_Click(sender As Object, e As EventArgs) Handles PictureBox5.Click
        Dim webAddress As String = "https://wiki.verag.ag/aviso/featurerelease_essensbestellungen.pdf"
        Process.Start(webAddress)
    End Sub

    Private Sub cbxAlt_freitag_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxAlt_montag.SelectedValueChanged, cbxAlt_dienstag.SelectedValueChanged, cbxAlt_mittwoch.SelectedValueChanged, cbxAlt_donnerstag.SelectedValueChanged, cbxAlt_freitag.SelectedValueChanged, cbxAlt_montag.TextChanged, cbxAlt_dienstag.TextChanged, cbxAlt_mittwoch.TextChanged, cbxAlt_donnerstag.TextChanged, cbxAlt_freitag.TextChanged
        countChecks()
    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        cbxMenu.changeItem("")
    End Sub

    Private Function checkIfGroupBoxIsSetFirstTime(gb As GroupBox)

        For Each c As Control In gb.Controls
            If TypeOf c Is RadioButton Then
                Dim radioButton As RadioButton = c
                If radioButton.Checked = True Then
                    Return False
                End If
            End If
        Next
        Return True

    End Function

    Private Sub setWarning(warning As Boolean)

        If warning Then
            lblWarning.Text = "Bezeichnung für A la carte fehlt"
        Else

            lblWarning.Text = ""

        End If

    End Sub

    Private Sub calcOffeneSumme()

        Dim sum As Double
        sum = SQL.DLookup("SUM(eb_preis)", "[tblEssensbestellungen]", "eb_mitid ='" & VERAG_PROG_ALLGEMEIN.cAllgemein.USRID & "' AND ISNULL([eb_abgerechnet],0)=0", "AVISO", "0")

        lbloffenerBetrag.Text &= sum.ToString("C2")

    End Sub

End Class