Public Class ClassFunctionCommands
    'Public Shared Function InsertFunction(ControlId As Integer)
    '    Try
    '        Dim SQL As String = "INSERT INTO TBPMO_FUNCTION_ADD_APPOINTMENT(CONTROL_ID) VALUES (" & ControlId & ")"
    '        MYDB_ECM.ExecuteNonQuery(Sql)
    '        Return True
    '    Catch ex As Exception
    '        MsgBox("Fehler beim Anlegen der KalenderFunktion:" & vbNewLine & ex.Message)
    '        Return False
    '    End Try
    'End Function

    Public Shared Function InsertFunction(ControlId As Integer, Method As String)
        Try
            Dim SQL As String = "INSERT INTO TBPMO_FUNCTION_GENERAL (CONTROL_ID, METHOD) VALUES (" & ControlId & ", '" & Method & "')"
            MYDB_ECM.ExecuteNonQuery(Sql)
            Return True
        Catch ex As Exception
            MsgBox("Fehler beim Anlegen der Funktion " & Method & ":" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
            Return False
        End Try
    End Function
    Public Shared Function UpdateAddAppointmentFunction(ControlId As Integer, FromDateId As Integer, ToDateId As Integer, SubjectString As String, Subject2String As String, PlaceString As String, DescriptionString As String)
        Try
            Dim SQL As String = "UPDATE TBPMO_FUNCTION_GENERAL SET INTEGER1 = " & FromDateId & ", INTEGER2 = " & ToDateId & ", STRING1 = '" & SubjectString & "', STRING2 = '" & Subject2String & "', STRING3 = '" & PlaceString & "', STRING4 = '" & DescriptionString & "' WHERE CONTROL_ID = " & ControlId
            If MYDB_ECM.ExecuteNonQuery(Sql) = False Then
                Throw New Exception("Datenbankfehler.")
            End If
            Return True
        Catch ex As Exception
            MsgBox("Error in UpdateAddAppointmentFunction:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
            Return False
        End Try
    End Function

    Public Shared Function UpdateAddFormDataFunction(ControlId As Integer, FormId As Integer, ScreenId As Integer)
        Try
            Dim SQL As String = "UPDATE TBPMO_FUNCTION_GENERAL SET INTEGER1 = " & FormId & ", INTEGER2 = " & ScreenId & " WHERE CONTROL_ID = " & ControlId
            If MYDB_ECM.ExecuteNonQuery(Sql) = False Then
                Throw New Exception("Datenbankfehler.")
            End If
            Return True
        Catch ex As Exception
            MsgBox("Error in UpdateAddFormDataFunction:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
            Return False
        End Try
    End Function

    Public Shared Function LoadFunction(ControlId As Integer) As DataRow
        Try
            Dim SQL As String = "SELECT * FROM TBPMO_FUNCTION_GENERAL WHERE CONTROL_ID = " & ControlId
            Dim dt As DataTable = MYDB_ECM.GetDatatable(SQL)

            If dt.Rows.Count = 1 Then
                Return dt.Rows.Item(0)
            Else
                Throw New Exception("Funktion für " & ControlId & " wurde nicht gefunden")
            End If
        Catch ex As Exception
            MsgBox("Error in LoadFunction:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
            Return Nothing
        End Try
    End Function

    Public Shared Function GETCONTROL_ID_FOR_COL_NAME(FORM_ID As Integer, Column_Name As String)
        Try
            Dim SQL As String = "SELECT GUID FROM TBPMO_CONTROL WHERE FORM_ID = " & FORM_ID & " AND COL_NAME = '" & Column_Name & "'"
            Dim result = MYDB_ECM.GetScalarValue(SQL)
            Return result
        Catch ex As Exception
            MsgBox("Error in GETCONTROL_ID_FOR_COL_NAME:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
            Return Nothing
        End Try
    End Function

End Class
