

Imports System.Data.SqlClient
    Imports System.Reflection

Public Class cGVMS
    Property gvms_id As Integer
    Property gvms_datetime As DateTime = Now
    Property gvms_firma As String
    Property gvms_notification_id As Object = Nothing
    Property gvms_notification_boxid As Object = Nothing
    Property gvms_status As Object = Nothing
    Property gvms_GMR As Object = Nothing
    Property gvms_gmr_creationDate As Object = Nothing
    Property gvms_gmr_statusVersion As Object = Nothing

    Property gvms_routeId As Integer = -1
    Property gvms_direction As String
    Property gvms_vehicleRegNum As String
    Property gvms_trailorRegNum As Object = Nothing
    Property gvms_isUnaccompanied As Object = Nothing
    Property gvms_empty As Object = Nothing
    Property gvms_emptyisOwn As Object = Nothing

    Property gvms_SS As Object = Nothing
    Property gvms_locateDateTimeOfDeparture As Object = Nothing


    Public GVMS_POSITIONEN As New List(Of cGVMS_POS)


    Public hasEntry As Boolean = False

    Dim SQL As New SQL


    Sub New()
    End Sub
    Sub New(gvms_id)
        Me.gvms_id = gvms_id
        LOAD()
    End Sub
    Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_id", gvms_id,, True))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_datetime", gvms_datetime))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_firma", gvms_firma))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_notification_id", gvms_notification_id))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_notification_boxid", gvms_notification_boxid))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_status", gvms_status))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_GMR", gvms_GMR))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_gmr_creationDate", gvms_gmr_creationDate))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_gmr_statusVersion", gvms_gmr_statusVersion))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_routeId", gvms_routeId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_direction", gvms_direction))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_vehicleRegNum", gvms_vehicleRegNum))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_trailorRegNum", gvms_trailorRegNum))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_isUnaccompanied", gvms_isUnaccompanied))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_empty", gvms_empty))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_emptyisOwn", gvms_emptyisOwn))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_SS", gvms_SS))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_locateDateTimeOfDeparture", gvms_locateDateTimeOfDeparture))

        Return list
    End Function



    Public Function SAVE(Optional saveAll = True) As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

        Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblGVMS  WHERE gvms_id=@gvms_id) " &
                       " BEGIN " & getUpdateCmd() & " END " &
                       " Else " &
                       " BEGIN " & getInsertCmd() & " END " &
                       " commit tran "

        Me.gvms_id = SQL.doSQLVarListID(gvms_id, sqlstr, "FMZOLL", , list)
        If gvms_id > 0 And saveAll Then
            SAVE_POSITIONEN()
        End If
        Return (gvms_id > 0)
    End Function


    Public Function SAVE_POSITIONEN() As Boolean
        'Zuserst alle OffertenPos von dem Offert löschen
        If DELETE_Warenpositionen() Then 'And DELETE_WarenpositionUnterlagen() Then
            'jetzt die Standartofferten  einfügen
            For Each p In GVMS_POSITIONEN
                p.gvmsPos_gvmsId = gvms_id
                p.INSERT()
            Next
        Else
            Return False
        End If

        Return True
    End Function

    Function DELETE_Warenpositionen() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
        Dim sqlstr = " DELETE FROM [tblGVMS_Pos] WHERE gvmsPos_gvmsId=" & Me.gvms_id & " "
        '  MsgBox(sqlstr)
        Return SQL.doSQL(sqlstr, "FMZOLL")
    End Function

    Public Sub LOAD()
        Try
            hasEntry = False
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblGVMS WHERE gvms_id=@gvms_id  ", conn)
                    cmd.Parameters.AddWithValue("@gvms_id", gvms_id)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In getParameterList()
                            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(Me, Nothing)
                            Else
                                propInfo.SetValue(Me, dr.Item(li.Text))
                            End If

                        Next
                        hasEntry = True
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
    End Sub

    Public Shared Function LOAD_ByNotification(gvms_notification_boxid, gvms_notification_id) As cGVMS

        Try
            Dim GVMS As New cGVMS
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblGVMS WHERE gvms_notification_boxid=@gvms_notification_boxid AND gvms_notification_id=@gvms_notification_id  ", conn)
                    cmd.Parameters.AddWithValue("@gvms_notification_id", gvms_notification_id)
                    cmd.Parameters.AddWithValue("@gvms_notification_boxid", gvms_notification_boxid)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In GVMS.getParameterList()
                            Dim propInfo As PropertyInfo = GVMS.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(GVMS, Nothing)
                            Else
                                propInfo.SetValue(GVMS, dr.Item(li.Text))
                            End If

                        Next
                        GVMS.hasEntry = True
                        dr.Close()
                        Return GVMS
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return Nothing
    End Function


    Public Function getUpdateCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

            Dim str As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            Return (" UPDATE [tblGVMS] SET " & str & " WHERE gvms_id=@gvms_id ")

        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function


    Public Function getInsertCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblGVMS  (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function

End Class


Public Class cGVMS_POS
    Property gvmsPos_id As Integer
    Property gvmsPos_gvmsId As Integer
    Property gvms_art As String
    Property gvms_RefNum As String
    Property gvms_SS As Object = Nothing

    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    Sub New()
        '  Me.nctsWpUl_nctsWPId = nctsWpUl_nctsWPId
    End Sub


    Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvmsPos_id", gvmsPos_id, , True, True))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvmsPos_gvmsId", gvmsPos_gvmsId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_art", gvms_art))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_RefNum", gvms_RefNum))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("gvms_SS", gvms_SS))
        Return list
    End Function


    Public Function INSERT() As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
        gvmsPos_id = SQL.doSQLVarListID(gvmsPos_id, getInsertCmd(), "FMZOLL", , list)
        Return gvmsPos_id > 0
    End Function

    Public Function getInsertCmd() As String

        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblGVMS_Pos (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function

End Class


Public Class cGVMS_POS_DecArt
    Public Shared EIDR As String = "EIDR"
    Public Shared EXPORT As String = "EXPORT"
    Public Shared IMPORT As String = "IMPORT"
    Public Shared TAD As String = "TAD"
    Public Shared TSAD As String = "TSAD"
    Public Shared ATA As String = "ATA"
    Public Shared TIR As String = "TIR"
    Public Shared ORAL As String = "ORAL"
    Public Shared INDIRECT As String = "INDIRECT"
End Class
Public Class cGVMS_Carriers
    Property carrierId As Integer
    Property carrierName As Object = Nothing
    Property countryCode As Object = Nothing

    Public hasEntry = False

    Dim SQL As New SQL

    Sub New()
    End Sub
    Sub New(carrierId)
        Me.carrierId = carrierId
        LOAD()
    End Sub
    Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("carrierId", carrierId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("carrierName", carrierName))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("countryCode", countryCode))

        Return list
    End Function


    Shared Function DELETE_ALL() As Boolean
        Dim SQL As New SQL
        Return SQL.doSQL(" DELETE FROM tblGVMS_Carriers", "FMZOLL")
    End Function


    Public Function SAVE() As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

        Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblGVMS_Carriers  WHERE carrierId=@carrierId) " &
                       " BEGIN " & getUpdateCmd() & " END " &
                       " Else " &
                       " BEGIN " & getInsertCmd() & " END " &
                       " commit tran "

        Return SQL.doSQLVarList(sqlstr, "FMZOLL", , list)
    End Function

    Public Sub LOAD()
        Try
            hasEntry = False
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblGVMS_Carriers WHERE carrierId=@carrierId  ", conn)
                    cmd.Parameters.AddWithValue("@carrierId", carrierId)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In getParameterList()
                            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(Me, Nothing)
                            Else
                                propInfo.SetValue(Me, dr.Item(li.Text))
                            End If

                        Next
                        hasEntry = True
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
    End Sub



    Public Function getUpdateCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

            Dim str As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            Return (" UPDATE [tblGVMS_Carriers] SET " & str & " WHERE carrierId=@carrierId ")

        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function


    Public Function getInsertCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblGVMS_Carriers  (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function

End Class




Public Class cGVMS_Routes
    Property routeId As Integer
    Property routeDirection As String
    Property routeEffectiveFrom As Object = Nothing
    Property departurePortId As Object = Nothing
    Property arrivalPortId As Object = Nothing
    Property carrierId As Object = Nothing
    Property routeEffectiveTo As Object = Nothing


    Public hasEntry = False

    Dim SQL As New SQL
    Sub New()
    End Sub
    Sub New(routeId)
        Me.routeId = routeId
        LOAD()
    End Sub
    Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("routeId", routeId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("routeDirection", routeDirection))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("routeEffectiveFrom", routeEffectiveFrom))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("departurePortId", departurePortId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("arrivalPortId", arrivalPortId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("carrierId", carrierId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("routeEffectiveTo", routeEffectiveTo))

        Return list
    End Function

    Shared Function DELETE_ALL() As Boolean
        Dim SQL As New SQL
        Return SQL.doSQL(" DELETE FROM tblGVMS_Routes", "FMZOLL")
    End Function

    Public Function SAVE() As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

        Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblGVMS_Routes  WHERE routeId=@routeId) " &
                       " BEGIN " & getUpdateCmd() & " END " &
                       " Else " &
                       " BEGIN " & getInsertCmd() & " END " &
                       " commit tran "

        Return SQL.doSQLVarList(sqlstr, "FMZOLL", , list)
    End Function

    Public Sub LOAD()
        Try
            hasEntry = False
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblGVMS_Routes WHERE routeId=@routeId  ", conn)
                    cmd.Parameters.AddWithValue("@routeId", routeId)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In getParameterList()
                            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(Me, Nothing)
                            Else
                                propInfo.SetValue(Me, dr.Item(li.Text))
                            End If

                        Next
                        hasEntry = True
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
    End Sub



    Public Function getUpdateCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

            Dim str As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            Return (" UPDATE [tblGVMS_Routes] SET " & str & " WHERE routeId=@routeId ")

        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function


    Public Function getInsertCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblGVMS_Routes  (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function

End Class




Public Class cGVMS_Ports
    Property portId As Integer
    Property portDescription As String
    Property portRegion As Object = Nothing
    Property portEffectiveFrom As Object = Nothing
    Property chiefPortCode As Object = Nothing
    Property cdsPortCode As Object = Nothing
    Property officeOfTransitCustomsOfficeCode As Object = Nothing
    Property portEffectiveTo As Object = Nothing
    Property portCountryCode As Object = Nothing
    Property isOperatingArrivedExportsProcess As Boolean


    Public hasEntry = False

    Dim SQL As New SQL

    Sub New()
    End Sub
    Sub New(portId)
        Me.portId = portId
        LOAD()
    End Sub
    Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("portId", portId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("portDescription", portDescription))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("portRegion", portRegion))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("portEffectiveFrom", portEffectiveFrom))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("chiefPortCode", chiefPortCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("cdsPortCode", cdsPortCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("officeOfTransitCustomsOfficeCode", officeOfTransitCustomsOfficeCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("portEffectiveTo", portEffectiveTo))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("portCountryCode", portCountryCode))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("isOperatingArrivedExportsProcess", isOperatingArrivedExportsProcess))


        Return list
    End Function

    Shared Function DELETE_ALL() As Boolean
        Dim SQL As New SQL
        Return SQL.doSQL(" DELETE FROM tblGVMS_Ports", "FMZOLL")
    End Function


    Public Function SAVE() As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

        Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblGVMS_Ports  WHERE portId=@portId) " &
                       " BEGIN " & getUpdateCmd() & " END " &
                       " Else " &
                       " BEGIN " & getInsertCmd() & " END " &
                       " commit tran "

        Return SQL.doSQLVarList(sqlstr, "FMZOLL", , list)
    End Function

    Public Sub LOAD()
        Try
            hasEntry = False
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT * FROM tblGVMS_Ports WHERE portId=@portId  ", conn)
                    cmd.Parameters.AddWithValue("@portId", portId)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each li In getParameterList()
                            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable)

                            If dr.Item(li.Text) Is DBNull.Value Then
                                propInfo.SetValue(Me, Nothing)
                            Else
                                propInfo.SetValue(Me, dr.Item(li.Text))
                            End If

                        Next
                        hasEntry = True
                    End If
                    dr.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
    End Sub



    Public Function getUpdateCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

            Dim str As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            Return (" UPDATE [tblGVMS_Ports] SET " & str & " WHERE portId=@portId ")

        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function


    Public Function getInsertCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblGVMS_Ports  (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
        End Try
        Return ""
    End Function

End Class
