
Imports System.Data.SqlClient
Imports System.Reflection
Imports System.Web.Configuration
Imports io.konik.zugferd

Public Class cRMC
    Property rmc_id As Integer
    Property rmc_kdNr As Object = Nothing
    Property rmc_kdName As Object = Nothing
    Property rmc_UID As Object = Nothing
    Property rmc_landKZ As Object = Nothing
    Property rmc_landBezeichnung As Object = Nothing
    Property rmc_reDatum As Object = Nothing
    Property rmc_reNr As Object = Nothing
    Property rmc_betragNetto As Object = Nothing
    Property rmc_betragBrutto As Object = Nothing
    Property rmc_betragMWST As Object = Nothing
    Property rmc_waehrung As Object = Nothing
    Property rmc_euroBrutto As Object = Nothing
    Property rmc_file As Object = Nothing
    Property rmc_fileNr As Object = Nothing
    Property rmc_importDatum As DateTime = Now
    Property rmc_version As Object = Nothing
    Property rmc_pdfFileName As Object = Nothing
    Property rmc_daId As Object = Nothing
    Property rmc_archiviertDatum As Object
    Property rmc_archiv As Boolean = False
    Property rmc_fibuNr As Object = False
    Property rmc_sammelReNr As Object = Nothing
    Property UStVAn_ID As Object = Nothing
    Property rmc_daId_InvAtt As Object = Nothing

    Public hasEntry = False

    Dim SQL As New SQL

    Sub New()

    End Sub

    Sub New(rmc_kdNr, rmc_reNr)
        Me.rmc_kdNr = rmc_kdNr
        Me.rmc_reNr = rmc_reNr
        LOAD()
    End Sub


    Sub New(rmc_kdNr, rmc_reNr, rmc_reDatum)
        Me.rmc_kdNr = rmc_kdNr
        Me.rmc_reNr = rmc_reNr
        Me.rmc_reDatum = rmc_reDatum
        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("rmc_id", rmc_id))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_kdNr", rmc_kdNr))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_kdName", rmc_kdName))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_UID", rmc_UID))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_landKZ", rmc_landKZ))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_landBezeichnung", rmc_landBezeichnung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_reDatum", rmc_reDatum))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_reNr", rmc_reNr))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_betragNetto", rmc_betragNetto))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_betragBrutto", rmc_betragBrutto))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_waehrung", rmc_waehrung))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_euroBrutto", rmc_euroBrutto))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_file", rmc_file))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_fileNr", rmc_fileNr))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_importDatum", rmc_importDatum))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_version", rmc_version))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_pdfFileName", rmc_pdfFileName))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_daId", rmc_daId))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_archiv", rmc_archiv))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_archiviertDatum", rmc_archiviertDatum))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_fibuNr", rmc_fibuNr))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_sammelReNr", rmc_sammelReNr))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_betragMWST", rmc_betragMWST))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("UStVAn_ID", UStVAn_ID))
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_daId_InvAtt", rmc_daId_InvAtt))


        Return list
    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 tblRMCImport  WHERE rmc_kdNr=@rmc_kdNr AND rmc_reNr = @rmc_reNr and rmc_reDatum  = @rmc_reDatum ) " &
                       " 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 tblRMCImport WHERE rmc_kdNr=@rmc_kdNr AND rmc_reNr = @rmc_reNr and rmc_reDatum  = @rmc_reDatum ", conn)
                    cmd.Parameters.AddWithValue("@rmc_kdNr", rmc_kdNr)
                    cmd.Parameters.AddWithValue("@rmc_reNr", rmc_reNr)
                    cmd.Parameters.AddWithValue("@rmc_reDatum", rmc_reDatum)
                    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 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 tblRMCImport SET " & str & " WHERE rmc_kdNr=@rmc_kdNr AND rmc_reNr = @rmc_reNr and rmc_reDatum  = @rmc_reDatum")

        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        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 tblRMCImport  (" & 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 Shared Function GET_Antraege_RMC(ByRef dt As DataTable, von As Date, bis As Date, KundenNr As Integer, LandKZ As String, Optional Archiv As Boolean = False) As Boolean
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()

                Using cmd As New SqlCommand(" SELECT rmc_reDatum,rmc_kdNr,[rmc_reNr],sum([rmc_betragNetto])[rmc_betragNetto],sum([rmc_betragMWST])[rmc_betragMWST] ,sum([rmc_betragBrutto] )[rmc_betragBrutto], [rmc_waehrung], sum([rmc_euroBrutto])[rmc_euroBrutto], rmc_daId, isnull(rmc_daId_InvAtt,0) as rmc_daId_InvAtt  FROM [tblRMCImport]
                                                INNER JOIN Adressen as adr on rmc_kdNr=adr.[WölflKundenNr] or rmc_kdNr=adr.[weitereWölflKundenNr]
                                                where cast(rmc_reDatum as date) between @von and @bis and AdressenNr=@AdressenNr
	                                            AND rmc_landKZ ='" & LandKZ & "'" & IIf(Not Archiv, " And rmc_archiv = 0 ", "") & "
                                                group by  rmc_reDatum,rmc_kdNr,[rmc_reNr],[rmc_waehrung], rmc_daId, isnull(rmc_daId_InvAtt,0)
                                                having sum([rmc_betragMWST])<>0
                                                order by rmc_reDatum", conn)

                    cmd.Parameters.AddWithValue("@von", von)
                    cmd.Parameters.AddWithValue("@bis", bis)
                    cmd.Parameters.AddWithValue("@AdressenNr", KundenNr)

                    Dim dr = cmd.ExecuteReader()
                    dt.Load(dr)
                    'While dr.Read
                    '    dt.Load(dr)
                    'End While
                    dr.Close()

                End Using
            End Using
            Return True
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return False

    End Function


    Public Shared Function UPDATE_ARCHIV(reDat As Date, reNr As String, rmc_kdNr As Integer, UStVAn_ID As Integer) As Boolean
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("reDat", reDat))
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("reNr", reNr))
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("rmc_kdNr", rmc_kdNr))
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("UStVAn_ID", UStVAn_ID))


            Return SQL.doSQLVarList("

                    UPDATE [tblRMCImport] set rmc_archiv=1, [rmc_archiviertDatum]=GETDATE(), UStVAn_ID = @UStVAn_ID
                    WHERE cast(rmc_reDatum as date) = @reDat and rmc_reNr = @reNr and rmc_kdNr=@rmc_kdNr
                ", "FMZOLL",, list)

        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return ""
    End Function



    Public VERARBEITUNG_PFAD
    Public ARCHIV_PFAD
    Public ERROR_PFAD
    Public ZIEL_PFAD
    Public FTP_PFAD
    Public PDFRECHNUNGEN
    Public API_STRING As String
    Public API As New DataTable

    Dim Dateiname = ""

    Public Function initImportPfade(programName As String) As Boolean


        ERROR_PFAD = cRMC.Paramter.GET_PARAM_ByName("ERROR_PFAD", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        ARCHIV_PFAD = cRMC.Paramter.GET_PARAM_ByName("ARCHIV_PFAD", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        VERARBEITUNG_PFAD = cRMC.Paramter.GET_PARAM_ByName("VERARBEITUNG_PFAD", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        ZIEL_PFAD = cRMC.Paramter.GET_PARAM_ByName("ZIEL_PFAD", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        PDFRECHNUNGEN = cRMC.Paramter.GET_PARAM_ByName("PDFRECHNUNGEN", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        If Not System.IO.Directory.Exists(VERARBEITUNG_PFAD) Then System.IO.Directory.CreateDirectory(VERARBEITUNG_PFAD)

        Return Paramter.getFTPConenction(API_STRING, API, programName)

    End Function

    Public Shared Function setBackToCustomer(SQL As SQL, backToCustomer As Boolean, ab As Date, customerNo As Integer) As Boolean


        Return SQL.doSQL("update tblRMCImport set InvToCustomer = " & IIf(backToCustomer, "1", "NULL") & "  where InvToCustomer Is null and cast(rmc_reDatum as Date) >= '" & ab.ToShortDateString & "' AND  rmc_kdNr = '" & customerNo & "'", "FMZOLL")

    End Function




    Public Shared Function setBackToCustomerCustomerID(SQL As SQL, backToCustomer As Boolean, customerNo As String) As Boolean

        Return SQL.doSQL("update tblRMCImport set InvToCustomer = " & IIf(backToCustomer, "1", "NULL") & "  where InvToCustomer Is null AND  rmc_kdNr = '" & customerNo & "'", "FMZOLL")

    End Function

    Public Shared Function setBackToCustomerInvoiceID(SQL As SQL, backToCustomer As Boolean, Optional invoiceID As String = "") As Boolean


        Return SQL.doSQL("update tblRMCImport set InvToCustomer = " & IIf(backToCustomer, "1", "0") & "  where InvToCustomer Is null " & IIf(invoiceID <> "", "AND  rmc_id = '" & invoiceID & "'", " ") & "", "FMZOLL")


    End Function

    Public Shared Function countBackToCustomerNotSet(SQL As SQL) As Integer
        Return SQL.getValueTxtBySql("SELECT count(InvToCustomer) FROM [tblRMCImport] where InvToCustomer Is null ", "FMZOLL",,, -1)
    End Function

    Public Shared Function countBackToCustomerNotSet(SQL As SQL, AdressenNrVon As Integer, AdressenNrBis As Integer) As Integer
        Return SQL.getValueTxtBySql("SELECT count(InvToCustomer) FROM [tblRMCImport] INNER JOIN Adressen On WölflKundenNr=[rmc_kdNr] Or weitereWölflKundenNr=[rmc_kdNr] where InvToCustomer Is null and Adressen.AdressenNr between " & AdressenNrVon & " AND " & AdressenNrBis, "FMZOLL",,, -1)
    End Function


    Public Shared Function getRMCQuartalsAbrechnungen(SQL As SQL, quartal As Integer, jahr As Integer, LeistungsNr As String, Optional USTV_ANTRAG As cUSTVAntrag = Nothing, Optional LANDKZ As String = "", Optional nurUnter50anzeigen As Boolean = True) As DataTable

        Dim SQLWhere As String = "WHERE POS.LeistungsNr IN (" & IIf(LeistungsNr <> "", LeistungsNr, "") & ")"

        If USTV_ANTRAG Is Nothing Then

            SQLWhere &= " AND USTVA.UStVAn_KuNr LIKE '15%' AND YEAR(R.Abfertigungsdatum) = " & jahr & ""
        Else

            SQLWhere &= " AND USTVA.UStVAn_KuNr = " & USTV_ANTRAG.UStVAn_KuNr & IIf(LANDKZ <> "", " AND [Länderverzeichnis für die Außenhandelsstatistik].LandKz = '" & LANDKZ & "'", "") & " AND R.Abfertigungsdatum between '" & CDate(USTV_ANTRAG.UStVAn_ReDatVon).ToShortDateString & "' AND '" & CDate(USTV_ANTRAG.UStVAn_ReDatBis).ToShortDateString & "'"

        End If


        Dim SQLstr = "select Temp.KundenNr, Temp.Kundenname,Temp.LandKZ, Temp.Jahr, Temp.Quartal, sum(Temp.Betrag) as 'verrechneter Bearbeitungsbetrag' " & IIf(nurUnter50anzeigen, ", 50 - sum(Temp.Betrag) as Differenzbetrag", "") & " from (SELECT
              USTVA.UStVAn_KuNr as KundenNr,
              USTVA.UStVAn_Name as Kundenname,
              [Länderverzeichnis für die Außenhandelsstatistik].LandKz as LandKZ,
              YEAR(R.Abfertigungsdatum)                    AS Jahr,
              DATEPART(QUARTER, R.Abfertigungsdatum)       AS Quartal,
              POS.LeistungsNr,
              SUM(POS.SteuerfreierBetrag + POS.SteuerpflichtigerBetrag) AS Betrag
          FROM tblUStVAntrag AS USTVA
          INNER JOIN Rechnungsausgang AS R ON R.FilialenNr     = USTVA.FilialenNr AND R.AbfertigungsNr = USTVA.AbfertigungsNr
          INNER JOIN RechnungsausgangPositionen AS POS ON R.RK_ID = POS.RK_ID 
          INNER JOIN  [Länderverzeichnis für die Außenhandelsstatistik] on UStVAn_LandNr=Landnr 
            " & SQLWhere & "
          
          GROUP BY
              USTVA.UStVAn_KuNr,
              USTVA.UStVAn_Name,
              [Länderverzeichnis für die Außenhandelsstatistik].LandKz,
              YEAR(R.Abfertigungsdatum),
              DATEPART(QUARTER, R.Abfertigungsdatum),
              POS.LeistungsNr
          ) as Temp
          	WHERE 1 = 1 " & IIf(quartal > 0, " AND temp.Quartal = " & quartal, "") & " 
          	Group by Temp.KundenNr, Temp.Kundenname,Temp.LandKZ, Temp.Jahr, Temp.Quartal
          	" & IIf(nurUnter50anzeigen, "Having sum(Temp.Betrag) < 50", "")

        Dim dt = (New VERAG_PROG_ALLGEMEIN.SQL).loadDgvBySql(SQLstr, "FMZOLL")

        Return dt



    End Function



    Public Shared Function getRMCREchnungenOhneAdressen(SQL As SQL, jahr As Integer, Optional getInvoiceData As Boolean = False) As DataTable


        Dim SQLFirst As String = ""
        If getInvoiceData Then
            SQLFirst = "SELECT [rmc_kdNr], [rmc_kdName], [rmc_landKZ], [rmc_reDatum], [rmc_reNr], [rmc_waehrung],[rmc_betragNetto],([rmc_betragBrutto] - [rmc_betragNetto]) as MWST,[rmc_betragBrutto], case WHEN rmc_daid IS NULL THEN 0 else 1 end as PDF_Rechnung, case WHEN rmc_daId_InvAtt IS NULL THEN 0 else 1 end as PDF_Anhang "
        Else
            SQLFirst = "SELECT DISTINCT r.rmc_kdNr,r.rmc_kdName "
        End If


        Dim SQLstr = "FROM tblRMCImport r
                WHERE
                    r.rmc_reDatum >= '" & jahr & "-01-01'
                    AND r.rmc_reDatum < '" & jahr + 1 & "-01-01'
                    AND NOT EXISTS (
                        SELECT 1 FROM Adressen a WHERE a.WölflKundenNr = r.rmc_kdNr
                    )
                    AND NOT EXISTS (
                        SELECT 1 FROM Adressen a WHERE a.weitereWölflKundenNr = r.rmc_kdNr)"

        Dim dt = (New VERAG_PROG_ALLGEMEIN.SQL).loadDgvBySql(SQLFirst & SQLstr, "FMZOLL")

        Return dt



    End Function

    Public Shared Function checkPDFInvoices(Optional reDatVon As Date = Nothing, Optional reDatBis As Date = Nothing, Optional dt As DataTable = Nothing, Optional AdressenNrVon As Integer = -1, Optional AdressenNrBis As Integer = -1) As Integer
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Dim sqlTime As String = ""
            Dim sqlAdressenNr As String = ""

            If IsDate(reDatVon) AndAlso CDate(reDatVon) > "01.01.2020" AndAlso IsDate(reDatBis) AndAlso CDate(reDatBis) > "01.01.2020" Then
                sqlTime = " And cast([rmc_reDatum] As Date) between '" & reDatVon.ToShortDateString & "' and '" & reDatBis.ToShortDateString & "'"
            End If

            If AdressenNrVon > 0 AndAlso AdressenNrBis > 0 Then
                sqlAdressenNr = " AND Adressen.AdressenNr between " & AdressenNrVon & " AND " & AdressenNrBis
            End If

            If dt IsNot Nothing Then
                Dim SQLstr = "Select rmc_reNr As RechnungsNr,rmc_reDatum As Rechnungsdatum, Adressen.AdressenNr As KundenNr,Adressen.[Name 1] As Kunde, kde_keineMWSt As keineMWST from [tblRMCImport] INNER JOIN Adressen On WölflKundenNr=[rmc_kdNr] Or weitereWölflKundenNr=[rmc_kdNr] INNER JOIN tblKundenErweitert On AdressenNr = kde_KundenNr  where rmc_daId Is null " & sqlTime & sqlAdressenNr & "  group by rmc_reNr, Adressen.AdressenNr, Adressen.[Name 1],rmc_reDatum, kde_keineMWSt"
                dt = (New VERAG_PROG_ALLGEMEIN.SQL).loadDgvBySql(SQLstr, "FMZOLL")
                Return dt.Rows.Count
            Else

                Dim SQLstr = "Select count(*) from [tblRMCImport] INNER JOIN Adressen On WölflKundenNr=[rmc_kdNr] Or weitereWölflKundenNr=[rmc_kdNr] INNER JOIN tblKundenErweitert On AdressenNr = kde_KundenNr  where rmc_daId Is null " & sqlTime & sqlAdressenNr
                Return SQL.getValueTxtBySql(SQLstr, "FMZOLL",,, 0)


            End If




        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try

        Return Nothing

    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='RMC' AND [Param_name]='" & tcParam_name & "' AND Param_testsystem = " & IIf(TESTSYSTEM, 1, 0), , , SQL.GetNewOpenConnectionFMZOLL_SYSTEM(TESTSYSTEM))
        End Function

        Shared Function getFTPConenction(ByRef API_String As String, ByRef API As DataTable, ByRef program As String) As Boolean

            API = SQL.loadDgvBySql("SELECT top(1) * FROM tblAPIEinstellungen WHERE api_program='" & program & "' and api_productive ='" & IIf(VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM, "0", "1") & "'", "ADMIN")
            If API.Rows.Count = 0 Then
                MsgBox("keine gültigen API-Einstellungen für " & program & " gefunden!")
            Else
                apiSettingsloaded = True
                API_String = API.Rows(0).Item("api_url")
            End If

            Return apiSettingsloaded
        End Function

    End Class


End Class
