Imports System.Reflection

Public Class cClasses




End Class

Public Class cEssen
    Property EssenName As String = ""
    Property EssenType As String = ""
    Property EssenLastUsage As Date = Now
    Property EssenCreateDate As Date = Now

    Function getparameterlist() As List(Of SQLVariable)
        Dim list As New List(Of SQLVariable)
        list.Add(New SQLVariable("EssenName", EssenName))
        list.Add(New SQLVariable("EssenLastUsage", EssenLastUsage))
        list.Add(New SQLVariable("EssenCreateDate", EssenCreateDate))
        list.Add(New SQLVariable("EssenType", EssenType))
        Return list
    End Function

    Function getEssenByName(FutterName As String)
        Dim ds As New DataSet
        cSQL.SQL2DS("SELECT * FROM GEssen WHERE EssenName = '" & FutterName & "'", ds)
        For Each c As DataColumn In ds.Tables(0).Columns
            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(c.ColumnName)
            If propInfo IsNot Nothing Then
                If Not IsDBNull(c.Table.Rows(0).Item(c)) Then
                    propInfo.SetValue(Me, c.Table.Rows(0).Item(c))
                End If
            End If
        Next
    End Function

    Function getEssenByCreateDate(EssenCreateDate As String)
        Dim ds As New DataSet
        cSQL.SQL2DS("SELECT * FROM GEssen WHERE EssenCreateDate = '" & EssenCreateDate & "'", ds)
        For Each c As DataColumn In ds.Tables(0).Columns
            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(c.ColumnName)
            If propInfo IsNot Nothing Then
                If Not IsDBNull(c.Table.Rows(0).Item(c)) Then
                    propInfo.SetValue(Me, c.Table.Rows(0).Item(c))
                End If
            End If
        Next
    End Function

    Function update()
        Dim UpdateString As String = ""
        Dim WhereString As String = ""
        Dim list As List(Of SQLVariable) = getparameterlist()
        For Each i In list
            If Not i.SQLText = "EssenCreateDate" Then UpdateString &= "[" & i.SQLText & "]='" & i.SQLValue & "',"
        Next
        UpdateString = UpdateString.Substring(0, UpdateString.Length - 1) 'wg. ','

        cSQL.UpdateSQL("GEssen", UpdateString, "EssenCreateDate = '" & Me.EssenCreateDate & "'")
    End Function

    Function saveAsNew()
        '' (Spalten, Spalten, ...) VALUES (Werte, Werte, ...)
        Dim Spalten As String = ""
        Dim Werte As String = ""
        Dim InsertString As String = ""
        Dim List As List(Of SQLVariable) = getparameterlist()
        For Each i In List
            Spalten &= i.SQLText & ","
            Werte &= "'" & i.SQLValue & "',"
        Next
        Spalten = Spalten.Substring(0, Spalten.Length - 1)
        Werte = Werte.Substring(0, Werte.Length - 1)

        cSQL.InsertSQL("GEssen", "(" & Spalten & ") VALUES (" & Werte & ")")

    End Function

    Function Delete()
        If MsgBox("Sicher, dass die Speise " & vbCrLf & "'" & Me.EssenName & "'" & vbCrLf & "gelöscht werden soll?", MsgBoxStyle.OkCancel, "Speise löschen?") = MsgBoxResult.Ok Then
            cSQL.DeleteFromSQL("GEssen", "EssenCreateDate = '" & Me.EssenCreateDate & "'")
        Else
        End If

    End Function


End Class



Public Class cMenu
    Property MenuTitel As String = "Wochenkarte KW "
    Property MenuPrint As Boolean = False
    Property MenuDateVon As Date = Now.Date
    Property MenuDateBis As Date = Now.Date
    Property MenuDetail1 As String = cTools.LoadParametersFromInI("MenuDetail1") '"Tagesgericht: 6,50 EUR"
    Property MenuDetail2 As String = cTools.LoadParametersFromInI("MenuDetail2")
    Property MenuDetail3 As String = cTools.LoadParametersFromInI("MenuDetail3")
    Property MenuSuppe As String = ""
    Property MenuPrintSuppe As Boolean = False
    Property MenuEssenMo As String = ""
    Property MenuEssenDi As String = ""
    Property MenuEssenMi As String = ""
    Property MenuEssenDo As String = ""
    Property MenuEssenFr As String = ""
    Property MenuEssenMoDate As Date = Nothing
    Property MenuEssenDiDate As Date = Nothing
    Property MenuEssenMiDate As Date = Nothing
    Property MenuEssenDoDate As Date = Nothing
    Property MenuEssenFrDate As Date = Nothing
    Property MenuSuppeDate As Date = Nothing
    Property MenuID As String = ""
    Property MenuArt As String = ""

    Function getparameterlist() As List(Of SQLVariable)
        Dim list As New List(Of SQLVariable)
        list.Add(New SQLVariable("MenuTitel", MenuTitel))
        list.Add(New SQLVariable("MenuPrint", MenuPrint))
        list.Add(New SQLVariable("MenuDateVon", MenuDateVon))
        list.Add(New SQLVariable("MenuDateBis", MenuDateBis))
        list.Add(New SQLVariable("MenuDetail1", MenuDetail1))
        list.Add(New SQLVariable("MenuDetail2", MenuDetail2))
        list.Add(New SQLVariable("MenuDetail3", MenuDetail3))
        list.Add(New SQLVariable("MenuSuppe", MenuSuppe))
        list.Add(New SQLVariable("MenuPrintSuppe", MenuPrintSuppe))
        list.Add(New SQLVariable("MenuEssenMo", MenuEssenMo))
        list.Add(New SQLVariable("MenuEssenDi", MenuEssenDi))
        list.Add(New SQLVariable("MenuEssenMi", MenuEssenMi))
        list.Add(New SQLVariable("MenuEssenDo", MenuEssenDo))
        list.Add(New SQLVariable("MenuEssenFr", MenuEssenFr))
        list.Add(New SQLVariable("MenuEssenMoDate", MenuEssenMoDate))
        list.Add(New SQLVariable("MenuEssenDiDate", MenuEssenDiDate))
        list.Add(New SQLVariable("MenuEssenMiDate", MenuEssenMiDate))
        list.Add(New SQLVariable("MenuEssenDoDate", MenuEssenDoDate))
        list.Add(New SQLVariable("MenuEssenFrDate", MenuEssenFrDate))
        list.Add(New SQLVariable("MenuSuppeDate", MenuSuppeDate))
        list.Add(New SQLVariable("MenuID", MenuID))
        list.Add(New SQLVariable("MenuArt", MenuArt))
        Return list
    End Function

    Function update()
        Dim UpdateString As String = ""
        Dim WhereString As String = ""
        Dim list As List(Of SQLVariable) = getparameterlist()
        For Each i In list
            If Not i.SQLText = "MenuID" Then UpdateString &= i.SQLText & " ='" & i.SQLValue & "',"
        Next
        UpdateString = UpdateString.Substring(0, UpdateString.Length - 1) 'wg. ','

        cSQL.UpdateSQL("GMenu", UpdateString, "MenuID = '" & Me.MenuID & "'")
    End Function

    Function saveAsNew()
        '' (Spalten, Spalten, ...) VALUES (Werte, Werte, ...)
        Dim Spalten As String = ""
        Dim Werte As String = ""
        Dim InsertString As String = ""
        Dim List As List(Of SQLVariable) = getparameterlist()
        For Each i In List
            Spalten &= i.SQLText & ","
            Werte &= "'" & i.SQLValue & "',"
        Next
        Spalten = Spalten.Substring(0, Spalten.Length - 1)
        Werte = Werte.Substring(0, Werte.Length - 1)

        cSQL.InsertSQL("GMenu", "(" & Spalten & ") VALUES (" & Werte & ")")

    End Function

    Function loadMenu(_menuid As String)
        Dim ds As New DataSet
        Dim test As String = ""
        cSQL.SQL2DS("select * from GMenu where MenuID = '" & _menuid & "'", ds)
        For Each c As DataColumn In ds.Tables(0).Columns
            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(c.ColumnName)
            If propInfo IsNot Nothing Then
                If Not IsDBNull(c.Table.Rows(0).Item(c)) Then
                    propInfo.SetValue(Me, c.Table.Rows(0).Item(c))
                End If
            End If
        Next
    End Function

    Function loadMenuToDT(_menuid As String)
        Dim ds As New DataSet
        Dim dt As New DataTable
        Dim test As String = ""
        cSQL.SQL2DS("select * from GMenu where MenuID = '" & _menuid & "'", ds)
        dt = ds.Tables(0)
        Return dt
    End Function

    Function CheckExist()
        Dim ds As New DataSet
        cSQL.SQL2DS("SELECT * FROM GMenu WHERE MenuID = '" & Me.MenuID & "'", ds)
        If ds.Tables(0).Rows.Count > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    Function Delete()
        If MsgBox("Sicher, dass das Menü gelöscht werden soll?", MsgBoxStyle.OkCancel, "Menü löschen?") = MsgBoxResult.Ok Then
            cSQL.DeleteFromSQL("GMenu", "MenuID = '" & Me.MenuID & "'")
        Else
        End If

    End Function

End Class

Public Class cEmpfaenger
    Property EmpfName As String = ""
    Property EmpfEMail As String = ""
    Property EmpfID As String = ""

    Function getparameterlist() As List(Of SQLVariable)
        Dim list As New List(Of SQLVariable)
        list.Add(New SQLVariable("EmpfName", EmpfName))
        list.Add(New SQLVariable("EmpfEMail", EmpfEMail))
        list.Add(New SQLVariable("EmpfID", EmpfID))
        Return list
    End Function

    Function update()
        Dim UpdateString As String = ""
        Dim WhereString As String = ""
        Dim list As List(Of SQLVariable) = getparameterlist()
        For Each i In list
            If Not i.SQLText = "EmpfID" Then UpdateString &= i.SQLText & " ='" & i.SQLValue & "',"
        Next
        UpdateString = UpdateString.Substring(0, UpdateString.Length - 1) 'wg. ','

        cSQL.UpdateSQL("GVerteilerListe", UpdateString, "EmpfID = '" & Me.EmpfID & "'")

    End Function

    Function saveAsNew()
        '' (Spalten, Spalten, ...) VALUES (Werte, Werte, ...)
        Dim Spalten As String = ""
        Dim Werte As String = ""
        Dim InsertString As String = ""
        Dim List As List(Of SQLVariable) = getparameterlist()
        For Each i In List
            Spalten &= i.SQLText & ","
            Werte &= "'" & i.SQLValue & "',"
        Next
        Spalten = Spalten.Substring(0, Spalten.Length - 1)
        Werte = Werte.Substring(0, Werte.Length - 1)

        cSQL.InsertSQL("GVerteilerListe", "(" & Spalten & ") VALUES (" & Werte & ")")

    End Function

    Function loadME(_EmpfID As String)
        Dim ds As New DataSet
        Dim test As String = ""
        cSQL.SQL2DS("select * from GVerteilerListe where EmpfID = '" & _EmpfID & "'", ds)
        For Each c As DataColumn In ds.Tables(0).Columns
            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(c.ColumnName)
            If propInfo IsNot Nothing Then
                If Not IsDBNull(c.Table.Rows(0).Item(c)) Then
                    propInfo.SetValue(Me, c.Table.Rows(0).Item(c))
                End If
            End If
        Next
    End Function

    Function Delete()
        If SQLTools.CheckIfExist("SELECT * FROM GVerteilerListe WHERE EmpfID = '" & Me.EmpfID & "'") Then
            If MsgBox("Sicher, dass der Eintrag gelöscht werden soll?", MsgBoxStyle.OkCancel, "Eintrag löschen?") = MsgBoxResult.Ok Then
                cSQL.DeleteFromSQL("GVerteilerListe", "EmpfID = '" & Me.EmpfID & "'")
                Return True
            End If
        Else
            MsgBox("Nicht gefunden")
        End If

    End Function
End Class
