Imports System.Data.SqlClient
Imports System.Reflection

Public Class cAsfinagMaut

    Property cardnumber As Object = Nothing
    Property licenceplate As Object = Nothing
    Property turnoverdate As Object = Nothing
    Property contractPartner As Object = Nothing
    Property netAmount As Object = Nothing
    Property VATamount As Object = Nothing
    Property totalAmount As Object = Nothing
    Property additionalData As Object = Nothing
    Property receiptnumber As Object = Nothing
    Property receiptCreated As Boolean = False


    Public hasEntry = False

    Dim SQL As New SQL

    Sub New()

    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("cardnumber", cardnumber))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("licenceplate", licenceplate))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("turnoverdate", turnoverdate))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("contractPartner", contractPartner))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("netAmount", netAmount))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("VATamount", VATamount))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("totalAmount", totalAmount))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("additionalData", additionalData))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("receiptnumber", receiptnumber))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("receiptCreated", receiptCreated))
        Return list
    End Function



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

        Dim sqlstr = " BEGIN TRAN " &
                       " 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 tblAsfinagMaut WHERE cardnumber=@cardnumber  ", conn)
                    cmd.Parameters.AddWithValue("@cardnumber", cardnumber)
                    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
                VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
            End Try
        End Sub



    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 tblAsfinagMaut  (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return ""
    End Function


    Public ANLAGEN

    Dim Dateiname = ""

    Public Function initImportPfade() As Boolean

        ANLAGEN = cAsfinagMaut.Paramter.GET_PARAM_ByName("ANLAGEN", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)

        Return True

    End Function


    Public Class Paramter

        Shared apiSettingsloaded As Boolean = False
        Shared SQL As New VERAG_PROG_ALLGEMEIN.SQL

        Shared Function GET_PARAM_ByName(tcParam_name, TESTSYSTEM) As String
            Return SQL.getValueTxtBySql("SELECT TOP 1 [Param_value]  FROM [tblPartnersystem_Paramter] WHERE  Param_system='ASFINAG' AND [Param_name]='" & tcParam_name & "' AND Param_testsystem = " & IIf(TESTSYSTEM, 1, 0), , , SQL.GetNewOpenConnectionFMZOLL_SYSTEM(TESTSYSTEM))
        End Function
    End Class


End Class

