Imports System.Data.SqlClient

Public Class SQL
    Public Const LeerDatum As Date = #12/30/1899#

    Public Shared Function GetSDLConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.SDLConnectionString
        Else
            Return My.MySettings.Default.SDL_PRODConnectionString
        End If
    End Function
    Public Shared Function GetUIDConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.UIDConnectionString
        Else
            Return My.MySettings.Default.UID_PRODConnectionString
        End If
    End Function


    Public Shared Function GetADMINConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.ADMINConnectionString_DEV
        Else
            Return My.MySettings.Default.ADMINConnectionString_DEV
        End If
    End Function
    Public Shared Function GetFMZOLLConnectionString() As String
        'Properties.Settings.Default.

        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Try
                Return My.MySettings.Default.FMZOLLConnectionString
            Catch ex As Exception
                'Return "Data Source=DEVELOPER.verag.ost.dmn\DEVSQL;Initial Catalog=VERAG;Integrated Security=false;User ID=sa;Password=BmWr501956;"
                Return "Data Source=DEVELOPER.verag.ost.dmn\DEVSQL;Initial Catalog=VERAG;Integrated Security=false;User ID=AppUser;Password=yp/THDd?xM+pZ$;"
            End Try


        Else
            Try
                Return My.MySettings.Default.FMZOLL_PRODConnectionString
            Catch ex As Exception
                ' Return "Data Source=192.168.0.91\SQLFMZOLL;Initial Catalog=VERAG;Integrated Security=false;User ID=test;Password=BmWr501956;"
                Return "Data Source=192.168.0.91\SQLFMZOLL;Initial Catalog=VERAG;Integrated Security=false;User ID=test;Password=BmWr501956;"
            End Try
        End If


    End Function
    Public Shared Function GetPARKZEITConnectionString() As String
        'Properties.Settings.Default.

        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.PARKZEITConnectionString_DEV


        Else
            Return My.MySettings.Default.PARKZEITConnectionString_PROD

        End If


    End Function



    Public Shared Function GetAsfinagConnectionString() As String
        'Properties.Settings.Default.

        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Try
                Return My.MySettings.Default.AsfinagConnectionString
            Catch ex As Exception
                'Return "Data Source=DEVELOPER.verag.ost.dmn\DEVSQL;Initial Catalog=VERAG;Integrated Security=false;User ID=sa;Password=BmWr501956;"
                Return "Data Source=DEVELOPER.verag.ost.dmn\DEVSQL;Initial Catalog=ASFINAG;Integrated Security=false;User ID=AppUser;Password=yp/THDd?xM+pZ$;"
            End Try


        Else
            Try
                Return My.MySettings.Default.AsfinagConnectionString 'nach Prod-Start austauschen!
            Catch ex As Exception
                ' Return "Data Source=192.168.0.91\SQLFMZOLL;Initial Catalog=VERAG;Integrated Security=false;User ID=test;Password=BmWr501956;"
                Return "Data Source=192.168.0.91\SQLFMZOLL;Initial Catalog=ASFINAG;Integrated Security=false;User ID=test;Password=BmWr501956;"
            End Try
        End If


    End Function
    Public Shared Function GetWEBConnectionString() As String
        'Properties.Settings.Default.

        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return "Data Source=192.168.0.90\DEVSQL;Initial Catalog=VERAG_HOMEPAGE;Integrated Security=false;User ID=AppUser;Password=yp/THDd?xM+pZ$;"
            '  Return "Data Source=192.168.0.90\DEVSQL;Initial Catalog=VERAG_HOMEPAGE;Integrated Security=false;User ID=sa;Password=BmWr501956;"
        Else
            Return "Data Source=192.168.0.91\SQLFMZOLL;Initial Catalog=VERAG_HOMEPAGE;Integrated Security=false;User ID=AppUser;Password=yp/THDd?xM+pZ$;"
            '  Return "Data Source=192.168.0.91\SQLFMZOLL;Initial Catalog=VERAG_HOMEPAGE;Integrated Security=false;User ID=sa;Password=BmWr501956;"
        End If


    End Function

    Public Shared Function GetFMZOLLConnectionString(TESTSYSTEM) As String
        If TESTSYSTEM Then
            Return My.MySettings.Default.FMZOLLConnectionString
        Else
            Try
                Return My.MySettings.Default.FMZOLL_PRODConnectionString
            Catch ex As Exception
                '   Return "Data Source=192.168.0.91\SQLFMZOLL;Initial Catalog=VERAG;Integrated Security=false;User ID=test;Password=BmWr501956;"
                Return "Data Source=192.168.0.91\SQLFMZOLL;Initial Catalog=VERAG;Integrated Security=false;User ID=test;Password=BmWr501956;"
            End Try
        End If
    End Function

    Public Shared Function GetAsfinagConnectionString(TESTSYSTEM) As String
        If TESTSYSTEM Then
            Return My.MySettings.Default.AsfinagConnectionString()
        Else
            Try
                Return My.MySettings.Default.FMZOLL_PRODConnectionString
            Catch ex As Exception
                '   Return "Data Source=192.168.0.91\SQLFMZOLL;Initial Catalog=VERAG;Integrated Security=false;User ID=test;Password=BmWr501956;"
                Return "Data Source=192.168.0.91\Asfinag;Initial Catalog=VERAG;Integrated Security=false;User ID=test;Password=BmWr501956;"
            End Try
        End If
    End Function

    Public Shared Function GetFDConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.FDConnectionString
        Else
            Return My.MySettings.Default.FD_PRODConnectionString
        End If
    End Function
    Public Shared Function GetSCANCANONConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.SCANCANON_PRODConnectionString
        Else
            Return My.MySettings.Default.SCANCANON_PRODConnectionString
        End If
    End Function
    Public Shared Function GetATLASConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.ATLASConnectionString
        Else
            Return My.MySettings.Default.ATLASConnectionString
        End If
    End Function

    Public Shared Function GetATLAS_SBGConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.ATLAS_SBGConnectionString
        Else
            Return My.MySettings.Default.ATLAS_SBGConnectionString
        End If
    End Function


    Public Shared Function GetEZOLLConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.EZOLLConnectionString
        Else
            Return My.MySettings.Default.EZOLLConnectionString
        End If
    End Function


    Public Shared Function GetEZOLL_UNISPEDConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.EZOLL_UNISPEDConnectionString
        Else
            Return My.MySettings.Default.EZOLL_UNISPEDConnectionString
        End If
    End Function


    Public Shared Function GetAVISOConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.AVISOConnectionStringTEST
        Else
            If VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "ATILLA" Then
                Return My.MySettings.Default.AVISO_ATILLAConnectionString
            Else
                Try
                    Return My.MySettings.Default.AVISOConnectionString
                Catch ex As Exception
                    Return "Data Source=SQLGUIDE01.verag.ost.dmn;Initial Catalog=AVISO;Integrated Security=false;User ID=AppUser;Password=yp/THDd?xM+pZ$;Pooling=true;Min Pool Size=5;Max Pool Size=200"
                End Try
            End If
        End If
    End Function


    Public Shared Function GetDISPOConnectionString() As String
        If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
            Return My.MySettings.Default.DISPOConnectionStringTEST
        Else
            Return My.MySettings.Default.DISPOConnectionString
        End If
    End Function


    Public Shared Function GetNewOpenConnectionSDL(Optional pooling As Boolean = True) As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetSDLConnectionString() & IIf(pooling, "", ";pooling=false")
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing

    End Function
    Public Shared Function GetNewOpenConnectionSYSKA(Optional pooling As Boolean = True) As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetSYSKAConnectionString() & IIf(pooling, "", ";pooling=false")
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing

    End Function
    Public Shared Function GetSYSKAConnectionString() As String
        Return My.MySettings.Default.SYSKAConnectionString
    End Function

    Public Shared Function GetNewOpenConnectionUID(Optional pooling As Boolean = True) As SqlConnection
        Dim cn As New SqlConnection()
        'cn.ConnectionString = My.Resources.connStringSDL_DEV
        ' IMMER DIE AKTUELLE CONNECTION IN MY.SETTINGS ÄNDERN!!! --> WG. BINDING
        cn.ConnectionString = GetUIDConnectionString() & IIf(pooling, "", ";pooling=false")
        cn.Open()
        Return cn
    End Function


    Public Shared Function GetNewOpenConnectionADMIN() As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetADMINConnectionString()
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing


    End Function


    Public Shared Function GetNewOpenConnectionFD() As SqlConnection
        Dim cn As New SqlConnection()
        cn.ConnectionString = GetFDConnectionString()
        cn.Open()
        Return cn
    End Function
    Public Shared Function GetNewOpenConnectionFMZOLL(Optional pooling As Boolean = True) As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetFMZOLLConnectionString() & IIf(pooling, "", ";pooling=false")
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing

    End Function

    Public Shared Function GetNewOpenConnectionAsfinag(Optional pooling As Boolean = True) As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetAsfinagConnectionString() & IIf(pooling, "", ";pooling=false")
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing

    End Function
    Public Shared Function GetNewOpenConnectionPARKZEIT(Optional pooling As Boolean = True) As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetPARKZEITConnectionString() & IIf(pooling, "", ";pooling=false")
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing

    End Function
    Public Shared Function GetNewOpenConnectionWEB(Optional pooling As Boolean = True) As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetWEBConnectionString() & IIf(pooling, "", ";pooling=false")

            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing

    End Function
    Public Shared Function GetNewOpenConnectionFMZOLL_SYSTEM(TESTSYSTEM As Boolean, Optional pooling As Boolean = True) As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetFMZOLLConnectionString(TESTSYSTEM) & IIf(pooling, "", ";pooling=false")
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing

    End Function

    Public Shared Function GetNewOpenConnectionFAsfinag_SYSTEM(TESTSYSTEM As Boolean, Optional pooling As Boolean = True) As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetAsfinagConnectionString(TESTSYSTEM) & IIf(pooling, "", ";pooling=false")
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing

    End Function
    Public Shared Function GetNewOpenConnectionSCANCANON(Optional pooling As Boolean = True) As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetSCANCANONConnectionString() & IIf(pooling, "", ";pooling=false")
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing

    End Function

    Public Shared Function GetNewOpenConnectionATLAS() As SqlConnection
        Dim cn As New SqlConnection()
        cn.ConnectionString = GetATLASConnectionString()
        cn.Open()
        Return cn
    End Function

    Public Shared Function GetNewOpenConnectionATLAS_SBG() As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetATLAS_SBGConnectionString()
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing


    End Function


    Public Shared Function GetNewOpenConnectionATLAS_SUBorSBG() As SqlConnection
        Dim cn As New SqlConnection()
        Try
            If VERAG_PROG_ALLGEMEIN.cAllgemein.MITARBEITER.mit_niederlassung = "SBG" Then
                cn.ConnectionString = GetATLAS_SBGConnectionString()
            Else
                cn.ConnectionString = GetATLASConnectionString()
            End If

            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing


    End Function

    Public Shared Function GetNewOpenConnectionEZOLL() As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetEZOLLConnectionString()
            cn.Open()
            Return cn
        Catch
            System.Threading.Thread.Sleep(500) 'warten...
            '2.Versuch
            Try
                cn.ConnectionString = GetEZOLLConnectionString()
                cn.Open()
                Return cn
            Catch ex As Exception
                VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
            End Try
        End Try
        Return Nothing

    End Function
    Public Shared Function GetNewOpenConnectionEZOLL_UNISPED() As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetEZOLL_UNISPEDConnectionString()
            cn.Open()
            Return cn
        Catch
            System.Threading.Thread.Sleep(500) 'warten...
            '2.Versuch
            Try
                cn.ConnectionString = GetEZOLL_UNISPEDConnectionString()
                cn.Open()
                Return cn
            Catch ex As Exception
                VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
            End Try
        End Try
        Return Nothing

    End Function

    Public Shared Function GetNewOpenConnectionAVISO() As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetAVISOConnectionString()
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing

    End Function


    Public Shared Function GetNewOpenConnectionDISPO() As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = GetDISPOConnectionString()
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing


    End Function
    Public Shared Function GetNewOpenConnectionAVISO_ATILLA() As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = My.MySettings.Default.AVISO_ATILLAConnectionString
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing


    End Function

    Public Shared Function GetNewOpenConnectionFMZOLLREAL() As SqlConnection
        Dim cn As New SqlConnection()
        Try
            cn.ConnectionString = My.MySettings.Default.FMZOLL_PRODConnectionString
            cn.Open()
            Return cn
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, "SQL CONNECTION | " & cn.ConnectionString.Replace("BmWr501956", "*******").Replace("yp/THDd?xM+pZ$", "*******") & " | Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return Nothing


    End Function


    Public Shared Function isNullReturnValue(o, ReturnValue) As Object
        If o Is Nothing Then Return o
        If o Is DBNull.Value Then Return ReturnValue
        If o.ToString = "" Then Return ReturnValue
        Return o
    End Function
    Public Shared Function isNullNothing(o) As Object
        If o Is Nothing Then Return o
        If o Is DBNull.Value Then Return Nothing
        If o.ToString = "" Then Return Nothing
        Return o
    End Function

    Function isleernothing(s) As Object
        Return isNullNothing(s)
    End Function

    Public Shared Function isNullNothingDbl(o) As Object
        If o Is Nothing Then Return o
        If o.ToString = "" Then Return Nothing
        Return CDbl(o)
    End Function

    Public Shared Function isNullDBNull(o) As Object
        If o Is Nothing Then Return DBNull.Value
        If o.ToString = "" Then Return DBNull.Value
        Return o
    End Function


    Function IsNull(o) As Boolean
        Try
            If o Is Nothing Then Return True
            If o Is DBNull.Value Then Return True
            If o.ToString.Trim = "" Then Return True
        Catch : End Try
        Return False
    End Function

    Function isleernothingDateFormatstring(o) As Object
        If o Is Nothing Then Return o
        If o.ToString = "" Then Return Nothing
        If IsDate(o) Then Return CDate(o).ToShortDateString
        Return Nothing
    End Function

    Public Function loadDgvBySql(ByVal sql As String, Optional conn_art As String = "SDL", Optional timeout As Integer = 0, Optional showerror As Boolean = True) As DataTable
        Try
            Dim myTable = New DataTable()
            Dim conn As New SqlConnection
            Select Case conn_art
                Case "SDL" : conn = GetNewOpenConnectionSDL()
                Case "FMZOLL" : conn = GetNewOpenConnectionFMZOLL()
                Case "ADMIN" : conn = GetNewOpenConnectionADMIN()
                Case "ASFINAG" : conn = GetNewOpenConnectionAsfinag()
                Case "DISPO" : conn = GetNewOpenConnectionDISPO()
                Case "ATLAS" : conn = GetNewOpenConnectionATLAS()
                Case "ATLAS_SBG" : conn = GetNewOpenConnectionATLAS_SBG()
                Case "EZOLL" : conn = GetNewOpenConnectionEZOLL()
                Case "EZOLL_UNISPED" : conn = GetNewOpenConnectionEZOLL_UNISPED()
                Case "AVISO" : conn = GetNewOpenConnectionAVISO()
                Case "VERAG" : conn = GetNewOpenConnectionFMZOLL()
                Case "FD" : conn = GetNewOpenConnectionFD()
                Case "WEB" : conn = GetNewOpenConnectionWEB()
                Case "FIBU", "SYSKA" : conn = GetNewOpenConnectionSYSKA()
                Case "PARKZEIT" : conn = GetNewOpenConnectionPARKZEIT()


                Case "AVISO_ATILLA"
                    conn.ConnectionString = "Data Source=172.16.0.98;Initial Catalog=AVISO_ATILLA;Integrated Security=false;User ID=sa;Password=BmWr501956;Pooling=true;Min Pool Size=5;Max Pool Size=200"
                    conn.Open()
            End Select
            '  MsgBox(cAllgemein.TESTSYSTEM)
            ' Using conn As SqlConnection = cSqlDb.GetNewOpenConnection()
            Using cmd As New SqlCommand(sql, conn)
                If timeout > 0 Then cmd.CommandTimeout = timeout 'Seconds
                Dim dr As SqlDataReader = cmd.ExecuteReader()

                myTable.Load(dr)
                dr.Close()
            End Using
            conn.Close()
            '  End Using
            Return myTable  'While Schleife wird hier verlassen
        Catch ex As Exception
            If showerror Then VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name, , "WiedergestellungsDatum Fehler", , , sql)
        End Try

        Return Nothing

    End Function
    Public Function loadCboBySql(ByVal sql As String, Optional conn_art As String = "SDL") As List(Of Object)


        Dim o As New List(Of Object)
        Try
            Dim conn As New SqlConnection
            Select Case conn_art
                Case "SDL" : conn = GetNewOpenConnectionSDL()
                Case "FMZOLL" : conn = GetNewOpenConnectionFMZOLL()
                Case "ADMIN" : conn = GetNewOpenConnectionADMIN()
                Case "ASFINAG" : conn = GetNewOpenConnectionAsfinag()
                Case "DISPO" : conn = GetNewOpenConnectionDISPO()
                Case "ATLAS" : conn = GetNewOpenConnectionATLAS()
                Case "ATLAS_SBG" : conn = GetNewOpenConnectionATLAS_SBG()
                Case "EZOLL" : conn = GetNewOpenConnectionEZOLL()
                Case "EZOLL_UNISPED" : conn = GetNewOpenConnectionEZOLL_UNISPED()
                Case "AVISO" : conn = GetNewOpenConnectionAVISO()
                Case "VERAG" : conn = GetNewOpenConnectionFMZOLL()
                Case "WEB" : conn = GetNewOpenConnectionWEB()
                Case "PARKZEIT" : conn = GetNewOpenConnectionPARKZEIT()
            End Select

            ' Using conn As SqlConnection = GetNewOpenConnection()
            Using cmd As New SqlCommand(sql, conn)
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                While dr.Read
                    o.Add(dr.Item(0))
                End While
                dr.Close()
            End Using
            conn.Close()
            ' End Using
            Return o  'While Schleife wird hier verlassen
        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 Function loadCboBySqlWithListItem(ByVal sql As String, Optional showValueInText As Boolean = True, Optional conn_art As String = "SDL") As List(Of MyListItem)
        Dim o As New List(Of MyListItem)
        Try
            Dim conn As New SqlConnection
            Select Case conn_art
                Case "SDL" : conn = GetNewOpenConnectionSDL()
                Case "FMZOLL" : conn = GetNewOpenConnectionFMZOLL()
                Case "ADMIN" : conn = GetNewOpenConnectionADMIN()
                Case "ASFINAG" : conn = GetNewOpenConnectionAsfinag()
                Case "ATLAS" : conn = GetNewOpenConnectionATLAS()
                Case "ATLAS_SBG" : conn = GetNewOpenConnectionATLAS_SBG()
                Case "EZOLL" : conn = GetNewOpenConnectionEZOLL()
                Case "EZOLL_UNISPED" : conn = GetNewOpenConnectionEZOLL_UNISPED()
                Case "AVISO" : conn = GetNewOpenConnectionAVISO()
                Case "VERAG" : conn = GetNewOpenConnectionFMZOLL()
                Case "DISPO" : conn = GetNewOpenConnectionDISPO()
                Case "WEB" : conn = GetNewOpenConnectionWEB()
                Case "PARKZEIT" : conn = GetNewOpenConnectionPARKZEIT()
            End Select

            Using cmd As New SqlCommand(sql, conn)
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                While dr.Read
                    If showValueInText Then
                        o.Add(New MyListItem(dr.Item(0) & " - " & dr.Item(1), dr.Item(0)))
                    Else
                        Try
                            Dim item1 = dr.Item(1) 'Sonst ist der fehelr im mylistitem
                            o.Add(New MyListItem(item1, dr.Item(0)))
                        Catch ex As Exception
                            o.Add(New MyListItem(dr.Item(0), dr.Item(0)))
                        End Try
                    End If

                End While
                dr.Close()
            End Using
            conn.Close()

            Return o  'While Schleife wird hier verlassen
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try

        Return Nothing
    End Function


    Function DLookup(srchField, table, where, Optional conn_art = "SDL", Optional nullvalue = "") As Object
        Return getValueTxtBySql("SELECT isnull(" & srchField & ",'" & nullvalue & "') FROM " & table & " WHERE " & where & "", conn_art,,, nullvalue)
    End Function


    Function DLookupArray(srchField, table, where, Optional conn_art = "SDL", Optional srchFieldClearName = "") As List(Of String)
        Dim list As New List(Of String)
        Dim dt = loadDgvBySql("SELECT  " & srchField & "  FROM " & table & " WHERE " & where & "", conn_art)

        If srchFieldClearName = "" Then srchFieldClearName = srchField

        If dt IsNot Nothing Then
            For Each r As DataRow In dt.Rows
                list.Add(r(srchFieldClearName))
            Next
        End If
        Return list
    End Function


    Public Function getValueTxtBySql(ByVal sql As String, Optional conn_art As String = "SDL", Optional List As List(Of MyListItem2) = Nothing, Optional conn As SqlConnection = Nothing, Optional defaultReturn As Object = "", Optional timeout As Integer = 0) As String

        Try
            If conn Is Nothing Then
                conn = New SqlConnection
                Select Case conn_art
                    Case "SDL" : conn = GetNewOpenConnectionSDL()
                    Case "FMZOLL" : conn = GetNewOpenConnectionFMZOLL()
                    Case "ADMIN" : conn = GetNewOpenConnectionADMIN()
                    Case "ASFINAG" : conn = GetNewOpenConnectionAsfinag()
                    Case "DISPO" : conn = GetNewOpenConnectionDISPO()
                    Case "ATLAS" : conn = GetNewOpenConnectionATLAS()
                    Case "ATLAS_SBG" : conn = GetNewOpenConnectionATLAS_SBG()
                    Case "EZOLL" : conn = GetNewOpenConnectionEZOLL()
                    Case "EZOLL_UNISPED" : conn = GetNewOpenConnectionEZOLL_UNISPED()
                    Case "AVISO" : conn = GetNewOpenConnectionAVISO()
                    Case "VERAG" : conn = GetNewOpenConnectionFMZOLL()
                    Case "SCANCANON" : conn = GetNewOpenConnectionSCANCANON()
                    Case "WEB" : conn = GetNewOpenConnectionWEB()
                    Case "FIBU", "SYSKA" : conn = GetNewOpenConnectionSYSKA()
                    Case "PARKZEIT" : conn = GetNewOpenConnectionPARKZEIT()

                End Select
            End If

            Using cmd As New SqlCommand(sql, conn)
                If timeout > 0 Then cmd.CommandTimeout = timeout
                If List IsNot Nothing Then
                    For Each i In List
                        'MsgBox(i.Text.trim & " " & IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                        cmd.Parameters.AddWithValue("@" & i.Text.trim, IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                    Next
                End If
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                If dr.HasRows Then
                    dr.Read()
                    If Not dr.Item(0) Is DBNull.Value Then
                        defaultReturn = CStr(dr.Item(0))
                    End If
                End If
                dr.Close()
            End Using
            conn.Close()

            Return defaultReturn
        Catch ex As Exception
            Dim connstr = ""
            If conn IsNot Nothing Then connstr = conn.ConnectionString
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & connstr, System.Reflection.MethodInfo.GetCurrentMethod.Name & sql)
        End Try
        'MsgBox("3")
        Return defaultReturn
    End Function

    Public Function getValueTxtBySqlVarList(ByVal sql As String, Optional conn_art As String = "SDL", Optional List As List(Of SQLVariable) = Nothing, Optional defaultReturn As Object = "") As String
        Dim s As String = defaultReturn
        Try
            'MsgBox("1")
            Dim conn As New SqlConnection
            Select Case conn_art
                Case "SDL" : conn = GetNewOpenConnectionSDL()
                Case "FMZOLL" : conn = GetNewOpenConnectionFMZOLL()
                Case "ADMIN" : conn = GetNewOpenConnectionADMIN()
                Case "ASFINAG" : conn = GetNewOpenConnectionAsfinag()
                Case "ATLAS" : conn = GetNewOpenConnectionATLAS()
                Case "DISPO" : conn = GetNewOpenConnectionDISPO()
                Case "ATLAS_SBG" : conn = GetNewOpenConnectionATLAS_SBG()
                Case "EZOLL" : conn = GetNewOpenConnectionEZOLL()
                Case "EZOLL_UNISPED" : conn = GetNewOpenConnectionEZOLL_UNISPED()
                Case "AVISO" : conn = GetNewOpenConnectionAVISO()
                Case "VERAG" : conn = GetNewOpenConnectionFMZOLL()
                Case "WEB" : conn = GetNewOpenConnectionWEB()
                Case "PARKZEIT" : conn = GetNewOpenConnectionPARKZEIT()
            End Select

            Using cmd As New SqlCommand(sql, conn)
                If List IsNot Nothing Then
                    For Each i In List
                        'MsgBox(i.Text.trim & " " & IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                        cmd.Parameters.AddWithValue("@" & i.Scalarvariable.trim, IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                    Next
                End If
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                If dr.HasRows Then
                    dr.Read()
                    If Not dr.Item(0) Is DBNull.Value Then
                        s = CStr(dr.Item(0))
                    End If
                End If
                dr.Close()
            End Using
            conn.Close()

            Return s
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        'MsgBox("3")
        Return defaultReturn

    End Function
    Public Function doSQL(ByVal sql As String, Optional conn_art As String = "SDL", Optional showErr As Boolean = True, Optional list As List(Of MyListItem2) = Nothing, Optional conn As SqlConnection = Nothing) As Boolean

        If conn Is Nothing Then
            conn = New SqlConnection
            Select Case conn_art
                Case "SDL" : conn = GetNewOpenConnectionSDL()
                Case "FMZOLL" : conn = GetNewOpenConnectionFMZOLL()
                Case "ADMIN" : conn = GetNewOpenConnectionADMIN()
                Case "ASFINAG" : conn = GetNewOpenConnectionAsfinag()
                Case "ATLAS" : conn = GetNewOpenConnectionATLAS()
                Case "ATLAS_SBG" : conn = GetNewOpenConnectionATLAS_SBG()
                Case "EZOLL" : conn = GetNewOpenConnectionEZOLL()
                Case "EZOLL_UNISPED" : conn = GetNewOpenConnectionEZOLL_UNISPED()
                Case "AVISO" : conn = GetNewOpenConnectionAVISO()
                Case "VERAG" : conn = GetNewOpenConnectionFMZOLL()
                Case "DISPO" : conn = GetNewOpenConnectionDISPO()
                Case "WEB" : conn = GetNewOpenConnectionWEB()
                Case "FIBU", "SYSKA" : conn = GetNewOpenConnectionSYSKA()
                Case "PARKZEIT" : conn = GetNewOpenConnectionPARKZEIT()

                Case "AVISO_ATILLA"
                    conn.ConnectionString = "Data Source=172.16.0.98;Initial Catalog=AVISO_ATILLA;Integrated Security=false;User ID=sa;Password=BmWr501956;Pooling=true;Min Pool Size=5;Max Pool Size=200"
                    conn.Open()
            End Select
        End If
        Try
            '  MsgBox(sql)
            Using cmd As New SqlCommand(sql, conn)
                If list IsNot Nothing Then
                    For Each i In list
                        'MsgBox(i.Text.trim & " " & IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                        cmd.Parameters.AddWithValue("@" & i.Text.trim, IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                    Next
                End If
                cmd.ExecuteNonQuery()
            End Using
            conn.Close()
            Return True
        Catch ex As Exception
            If showErr Then VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name, , , , , sql)
        End Try
        Return False
    End Function


    Public Function doSQLVarList(ByVal sql As String, Optional conn_art As String = "SDL", Optional showErr As Boolean = True, Optional list As List(Of SQLVariable) = Nothing) As Boolean
        Dim conn As New SqlConnection
        Select Case conn_art
            Case "SDL" : conn = GetNewOpenConnectionSDL()
            Case "FMZOLL" : conn = GetNewOpenConnectionFMZOLL()
            Case "ADMIN" : conn = GetNewOpenConnectionADMIN()
            Case "ASFINAG" : conn = GetNewOpenConnectionAsfinag()
            Case "ATLAS" : conn = GetNewOpenConnectionATLAS()
            Case "ATLAS_SBG" : conn = GetNewOpenConnectionATLAS_SBG()
            Case "EZOLL" : conn = GetNewOpenConnectionEZOLL()
            Case "EZOLL_UNISPED" : conn = GetNewOpenConnectionEZOLL_UNISPED()
            Case "AVISO" : conn = GetNewOpenConnectionAVISO()
            Case "DISPO" : conn = GetNewOpenConnectionDISPO()
            Case "VERAG" : conn = GetNewOpenConnectionFMZOLL()
            Case "WEB" : conn = GetNewOpenConnectionWEB()
            Case "PARKZEIT" : conn = GetNewOpenConnectionPARKZEIT()
        End Select
        Try
            '  MsgBox(sql)
            Using cmd As New SqlCommand(sql, conn)
                If list IsNot Nothing Then
                    For Each i In list
                        'MsgBox(i.Text.trim & " " & IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                        cmd.Parameters.AddWithValue("@" & i.Scalarvariable.trim, IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                    Next
                End If
                cmd.ExecuteNonQuery()
            End Using
            conn.Close()
            Return True
        Catch ex As Exception
            If showErr Then VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name, , , , , sql)
        End Try
        Return False
    End Function

    Public Function doSQLVarListID(ByVal id As Integer, ByVal sql As String, Optional conn_art As String = "SDL", Optional showErr As Boolean = True, Optional list As List(Of SQLVariable) = Nothing, Optional returnSelectID As Boolean = False, Optional errHinweis As String = "", Optional showErrTimeout As Boolean = True, Optional timeout As Integer = 0) As Integer

        Dim conn As New SqlConnection
        Select Case conn_art
            Case "SDL" : conn = GetNewOpenConnectionSDL()
            Case "FMZOLL" : conn = GetNewOpenConnectionFMZOLL()
            Case "ADMIN" : conn = GetNewOpenConnectionADMIN()
            Case "ASFINAG" : conn = GetNewOpenConnectionAsfinag()
            Case "ATLAS" : conn = GetNewOpenConnectionATLAS()
            Case "ATLAS_SBG" : conn = GetNewOpenConnectionATLAS_SBG()
            Case "EZOLL" : conn = GetNewOpenConnectionEZOLL()
            Case "EZOLL_UNISPED" : conn = GetNewOpenConnectionEZOLL_UNISPED()
            Case "AVISO" : conn = GetNewOpenConnectionAVISO()
            Case "DISPO" : conn = GetNewOpenConnectionDISPO()
            Case "VERAG" : conn = GetNewOpenConnectionFMZOLL()
            Case "WEB" : conn = GetNewOpenConnectionWEB()
            Case "PARKZEIT" : conn = GetNewOpenConnectionPARKZEIT()
        End Select
        Try
            Using cmd As New SqlCommand(sql, conn)
                If timeout > 0 Then cmd.CommandTimeout = timeout
                If list IsNot Nothing Then
                    For Each i In list
                        'If Not i.isonlyForLoad Then

                        ' End If
                        cmd.Parameters.AddWithValue("@" & i.Scalarvariable.trim, IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                    Next
                End If

                If returnSelectID Then
                    Dim dr As SqlDataReader = cmd.ExecuteReader()
                    If dr.HasRows Then
                        dr.Read()
                        If Not dr.Item(0) Is DBNull.Value Then
                            id = CStr(dr.Item(0))
                        End If
                    End If
                    dr.Close()
                Else
                    cmd.ExecuteNonQuery()

                    If id <= 0 Then
                        Dim newcmd As New SqlCommand("SELECT @@IDENTITY", conn)
                        id = CInt(newcmd.ExecuteScalar)
                    End If

                End If

                'Return True
            End Using
            conn.Close()
        Catch ex As TimeoutException
            If showErrTimeout Then VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & errHinweis, System.Reflection.MethodInfo.GetCurrentMethod.Name, , , , , sql)
            ' VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name, If(showErr, ERROR_OP.SHOW, ERROR_OP.MAIL), , , , sql)
            Return -2
        Catch ex As Exception
            If showErr Then VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & errHinweis, System.Reflection.MethodInfo.GetCurrentMethod.Name, , , , , sql)
            ' VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name, If(showErr, ERROR_OP.SHOW, ERROR_OP.MAIL), , , , sql)
            Return -1
        End Try
        Return id
    End Function


    Public Function loadDgvBySql_Param(ByVal sql As String, Optional conn_art As String = "SDL", Optional timeout As Integer = 0, Optional list As List(Of SQLVariable) = Nothing, Optional showErr As Boolean = True, Optional ByRef errOccured As Boolean = False) As DataTable
        Try
            Dim myTable = New DataTable()
            Dim conn As New SqlConnection
            Select Case conn_art
                Case "SDL" : conn = GetNewOpenConnectionSDL()
                Case "FMZOLL" : conn = GetNewOpenConnectionFMZOLL()
                Case "ADMIN" : conn = GetNewOpenConnectionADMIN()
                Case "ASFINAG" : conn = GetNewOpenConnectionAsfinag()
                Case "ATLAS" : conn = GetNewOpenConnectionATLAS()
                Case "ATLAS_SBG" : conn = GetNewOpenConnectionATLAS_SBG()
                Case "EZOLL" : conn = GetNewOpenConnectionEZOLL()
                Case "EZOLL_UNISPED" : conn = GetNewOpenConnectionEZOLL_UNISPED()
                Case "AVISO" : conn = GetNewOpenConnectionAVISO()
                Case "VERAG" : conn = GetNewOpenConnectionFMZOLL()
                Case "WEB" : conn = GetNewOpenConnectionWEB()
            End Select

            ' Using conn As SqlConnection = GetNewOpenConnection()
            Using cmd As New SqlCommand(sql, conn)
                If list IsNot Nothing Then
                    For Each i In list
                        'MsgBox(i.Text.trim & " " & IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                        cmd.Parameters.AddWithValue("@" & i.Scalarvariable.trim, IIf(i.Value Is Nothing, DBNull.Value, i.Value))
                    Next
                End If
                If timeout > 0 Then cmd.CommandTimeout = timeout
                Dim dr As SqlDataReader = cmd.ExecuteReader()

                myTable.Load(dr)
                dr.Close()
            End Using
            conn.Close()
            '  End Using
            Return myTable  'While Schleife wird hier verlassen
        Catch ex As Exception
            If showErr Then VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name, , , , , sql)
            errOccured = True
        End Try

        Return Nothing
    End Function

    Function getFirmaWhere()
        Dim where = ""
        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "IMEX" : where &= " AND [FilialenNr]='5501'  "
            Case "UNISPED" : where &= " AND [FilialenNr]='5601'  "
            Case "AMBAR" : where &= " AND [FilialenNr]='5701'  "
            Case "FRONTOFFICE" : where &= " AND [FilialenNr]='5801'  "
            Case Else : where &= " AND isnull([FilialenNr],0) NOT IN ('5501','5601','5701','5801') "
        End Select
        Return where
    End Function
    Public Function getFMZOLLKdNrFromEORI(ByVal eori As String, eoriNL As String) As String
        Dim s As String = ""
        Dim where = getFirmaWhere()

        Try
            Dim conn As SqlConnection = GetNewOpenConnectionFMZOLL()
            Dim sqlStr = ""
            If eoriNL <> "" Then
                sqlStr = "SELECT Adressen.AdressenNr FROM Adressen INNER JOIN Kunden ON Adressen.AdressenNr = Kunden.KundenNr WHERE (([EORITIN] = '" & eori & "' AND EORITIN_NL ='" & eoriNL & "') OR ([EORITIN] + '0000' = '" & (eori & eoriNL).Replace(" ", "") & "')) " & where & " ORDER BY AdressenNr DESC"
            Else
                sqlStr = "SELECT Adressen.AdressenNr FROM Adressen INNER JOIN Kunden ON Adressen.AdressenNr = Kunden.KundenNr WHERE ( ([EORITIN] = '" & eori & "' AND EORITIN_NL ='" & eoriNL & "') OR [EORITIN] = '" & (eori & eoriNL).Replace(" ", "") & "') " & where & " order by EORITIN_NL desc, AdressenNr DESC"
            End If
            Using cmd As New SqlCommand(sqlStr, conn)

                Dim dr As SqlDataReader = cmd.ExecuteReader()
                If dr.HasRows Then
                    Dim dt As New DataTable
                    dt.Load(dr)
                    If dt.Rows.Count > 1 Then
                        If VERAG_PROG_ALLGEMEIN.cAllgemein.ERR_OP_GLOBAL = VERAG_PROG_ALLGEMEIN.ERROR_OP.SHOW Then
                            '    MsgBox("Die EORI-Nr. " & eori & " ist in " & dt.Rows.Count & " Kundenstammsätzen eingetragen.", vbCritical)
                            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR("Die EORI-Nr. " & eori & " ist in " & dt.Rows.Count & " Kundenstammsätzen eingetragen.", "", System.Reflection.MethodInfo.GetCurrentMethod.Name)
                        End If
                    End If
                    s = dt.Rows(0).Item(0)
                End If
                dr.Close()
            End Using
            conn.Close()

            Return s
        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 SQLDatumZeitSekunden(dat As Date) As String
        'Datum inklusive Zeit für SQLAbfrage umwandeln (31.01.1998 10:15 Uhr --> #1/31/1998 10:15:00#)
        SQLDatumZeitSekunden = ""
        If Not IsDate(dat) Then Exit Function
        SQLDatumZeitSekunden = "'" & DateAndTime.Day(dat) & "." & DateAndTime.Month(dat) & "." & DateAndTime.Year(dat) & " " &
                  DateAndTime.Hour(dat) & ":" & DateAndTime.Minute(dat) & ":" & DateAndTime.Second(dat) & "'"
    End Function

    Public Shared Function SQLNullDate(d As Date) As Object
        'Wenn Datum 00.00.0000, dann wird dbnull zurückgegeben
        If d = New Date Then : SQLNullDate = DBNull.Value
        Else : SQLNullDate = d : End If
    End Function

    Public Shared Function VarToInt(ByVal wert As Object) As Integer
        Try
            If wert Is Nothing OrElse wert Is DBNull.Value Then
                Return 0
            Else
                Return CInt(wert)
            End If
        Catch generatedExceptionName As Exception
            Return 0
        End Try
    End Function


    Public Shared Function VarToInt2(ByVal wert As Object) As Integer
        Try
            If wert Is Nothing OrElse wert Is DBNull.Value OrElse Not IsNumeric(wert) Then
                Return -1
            Else
                Return CInt(wert)
            End If
        Catch generatedExceptionName As Exception
            Return -1
        End Try
    End Function

    Public Shared Function VarToLng(ByVal wert As Object) As Long
        Try
            If wert Is Nothing OrElse wert Is DBNull.Value Then
                Return 0
            Else
                Return CLng(wert)
            End If
        Catch generatedExceptionName As Exception
            Return 0
        End Try
    End Function

    Public Shared Function VarToDbl(ByVal wert As Object) As Double
        Try
            If wert Is Nothing OrElse wert Is DBNull.Value Then
                Return 0
            Else
                Return CDbl(wert)
            End If
        Catch generatedExceptionName As Exception
            Return 0
        End Try
    End Function

    Public Shared Function checkNullReturnValue(ByVal o As Object, ByVal returnValue As Object) As Object
        If o IsNot Nothing And o IsNot DBNull.Value Then Return (o)
        Return returnValue
    End Function

    Public Shared Function checkNullIntegerZero(ByVal o As Object) As Integer
        If o IsNot Nothing And o IsNot DBNull.Value Then Return CInt(o)
        Return 0
    End Function
    Public Shared Function checkNulDbl(ByVal o As Object) As Double
        If o IsNot Nothing And o IsNot DBNull.Value Then Return CDbl(o)
        Return -1
    End Function

    Public Shared Function checkNullBool(ByVal o As Object) As Boolean
        If o Is Nothing Or o Is DBNull.Value Then Return 0
        Try
            Return CBool(o)
        Catch ex As Exception
        End Try
        Return 0
    End Function

    Public Shared Function checkNullDateReturnValue(ByVal o As Object, ByVal returnValue As Object) As Object
        If o IsNot Nothing And o IsNot DBNull.Value Then
            If o.ToString <> "" AndAlso IsDate(o) Then
                Return CDate(o)
            End If
        End If
        Return returnValue
    End Function
    Public Shared Function checkNullDate(ByVal o As Object) As Date
        If o IsNot Nothing And o IsNot DBNull.Value Then Return CDate(o)
        Return Now
    End Function
    Public Shared Function checkNullDateNothing(ByVal o As Object) As Object
        If o Is DBNull.Value Then
            Return Nothing
        Else
            Return CDate(o)
        End If
    End Function
    Public Shared Function checkNullInteger(ByVal o As Object) As Integer
        If o IsNot Nothing And o IsNot DBNull.Value Then Return CInt(o)
        Return -1
    End Function
    Public Shared Function checkNullStr(ByVal o As Object) As String
        If o IsNot Nothing And o IsNot DBNull.Value Then Return CStr(o)
        Return ""
    End Function




    Public Shared Function isDbnullEmpty(o As Object, return_value As Object) As String
        If IsDBNull(o) Then : isDbnullEmpty = return_value
        ElseIf IsNothing(o) Then : isDbnullEmpty = return_value
        Else : isDbnullEmpty = o.ToString
        End If
    End Function
    Public Shared Function isDbnullEmptyCurr(o As Object, return_value As Object) As String
        If IsDBNull(o) Then : isDbnullEmptyCurr = return_value
        ElseIf IsNothing(o) Then : isDbnullEmptyCurr = return_value
        Else : isDbnullEmptyCurr = CDbl(o).ToString("C")
        End If
    End Function
    Public Shared Function isDbnullEmptyDbl(o As Object, kommastellen As Integer, return_value As Object) As String
        If IsDBNull(o) Then : isDbnullEmptyDbl = return_value
        ElseIf IsNothing(o) Then : isDbnullEmptyDbl = return_value
        Else : isDbnullEmptyDbl = CDbl(o).ToString("N" & If(kommastellen > 0, kommastellen, ""))
        End If
    End Function



    Public Shared Function VarToBool(ByVal wert As Object) As Boolean
        Try
            If wert Is Nothing OrElse wert Is DBNull.Value Then
                Return False
            Else
                Return CBool(wert)
            End If
        Catch generatedExceptionName As Exception
            Return False
        End Try
    End Function

    Public Shared Function VarToStr(ByVal wert As Object) As String
        Try
            If wert Is Nothing OrElse wert Is DBNull.Value Then
                Return ""
            Else
                Return Trim(DirectCast(wert, String))
            End If
        Catch generatedExceptionName As Exception
            Return ""
        End Try
    End Function

    Public Shared Function VarToDate(ByVal wert As Object) As Nullable(Of DateTime)
        Try
            If wert Is Nothing OrElse wert Is DBNull.Value Then
                Return LeerDatum  'Nothing
            Else
                Return DirectCast(wert, DateTime)
            End If
        Catch generatedExceptionName As Exception
            Return Nothing
        End Try
    End Function

    Public Shared Function IstGleich(i As Integer, ParamArray list As Integer()) As Boolean
        'prüft, ob ein Wert in einer Liste enthalten ist - z.B. i = 5 or 7 or 11 or 29
        For x As Integer = 0 To list.Length - 1
            If list(x) = i Then
                Return True
            End If
            On Error Resume Next
        Next
        Return False
    End Function

    Public Shared Function Minuten_auf_Text(hMinuten As Long) As String
        Dim hStunden As Long
        Dim hMinus As Boolean
        Dim hMin As Long

        Minuten_auf_Text = ""
        hMin = hMinuten

        If hMin = 0 Then
            Minuten_auf_Text = "0:00"
            Exit Function
        End If

        If hMin < 0 Then
            hMinus = True
            hMin = hMin * -1
        End If

        hStunden = CLng(Fix(hMin / 60))
        hMin = hMin - (hStunden * 60)
        If hMinus Then Minuten_auf_Text = "-" 'Minus wird nur bei Stunden angezeigt
        Minuten_auf_Text = Minuten_auf_Text & hStunden & ":" & Format(hMin, "00")
    End Function

    Public Shared Function ZeitInMinuten(hDat As Date) As Long
        ZeitInMinuten = 0
        If Not IsDate(hDat) Then Exit Function
        ZeitInMinuten = Hour(hDat) * 60 + Minute(hDat)
    End Function





    Public Function getATLASKdNrFromZollNr(ByVal ZollNr As String) As String
        Dim s As String = ""
        Dim where = getFirmaWhere()

        Try
            Dim conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL
            Using cmd As New SqlCommand("SELECT Adressen.AdressenNr FROM Adressen INNER JOIN Kunden ON Adressen.AdressenNr = Kunden.KundenNr WHERE Zollnummer = '" & String.Format(ZollNr, "0000000") & "' " & where & " ORDER BY AdressenNr DESC", conn)

                Dim dr As SqlDataReader = cmd.ExecuteReader()
                If dr.HasRows Then
                    Dim dt As New DataTable
                    dt.Load(dr)
                    If dt.Rows.Count > 1 Then
                        If VERAG_PROG_ALLGEMEIN.cAllgemein.ERR_OP_GLOBAL = VERAG_PROG_ALLGEMEIN.ERROR_OP.SHOW Then
                            '   MsgBox("Die Zollnummer " & ZollNr & " ist in " & dt.Rows.Count & " Kundenstammsätzen eingetragen.", vbCritical)
                            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR("Die Zollnummer " & ZollNr & " ist in " & dt.Rows.Count & " Kundenstammsätzen eingetragen.", "", System.Reflection.MethodInfo.GetCurrentMethod.Name)
                        End If
                    End If
                    s = dt.Rows(0).Item(0)
                End If
                dr.Close()
            End Using
            conn.Close()

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

    Public Function getATLASNacherfassungAdresse(ByVal basman_nr As String, ByVal basman_nl As String, ByVal zbant_beznr As String, ByVal zbant_regnr As String, ByVal zbant_korant As String, zbadz_typ As Integer, connArt As String) As String
        Dim s As String = ""

        Try
            Dim conn As SqlConnection
            Select Case connArt
                Case "ATLAS" : conn = SQL.GetNewOpenConnectionATLAS
                Case "ATLAS_SBG" : conn = SQL.GetNewOpenConnectionATLAS_SBG
            End Select
            Using cmd As New SqlCommand(" SELECT zbadz_name1, baslnd_alpha, zbadz_plz, zbadz_ort " &
                                        " FROM zbadz WHERE basman_nr='" & basman_nr & "' And basman_nl='" & basman_nl & "' And zbant_beznr='" & zbant_beznr & "' And zbant_regnr='" & zbant_regnr & "' And zbant_korant='" & zbant_korant & "' And zbadz_typ='" & zbadz_typ & "' " &
                                        " ORDER BY basman_nr, basman_nl, zbant_beznr, zbant_regnr, zbant_korant, zbadz_typ", conn)
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                If dr.HasRows Then
                    dr.Read()
                    s = Left(Trim(dr.Item("zbadz_name1")) & Trim(", " & dr.Item("baslnd_alpha")) & Trim(", " & dr.Item("zbadz_plz")) & Trim(", " & dr.Item("zbadz_ort")), 50)
                End If
                dr.Close()
            End Using
            conn.Close()

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


    Public Function getATLASNacherfassungAdresseNCTS(ByVal basman_nr As String, ByVal basman_nl As String, ByVal veoant_beznr As String, ByVal intLfdNr As String, ByVal intPosNr As String, lngTyp As String, connArt As String) As String
        Dim s As String = ""
        Try
            Dim conn As SqlConnection = Nothing
            Select Case connArt
                Case "ATLAS" : conn = SQL.GetNewOpenConnectionATLAS
                Case "ATLAS_SBG" : conn = SQL.GetNewOpenConnectionATLAS_SBG
            End Select
            If conn IsNot Nothing Then

                Using cmd As New SqlCommand("SELECT veoadr_name1, baslnd_alpha, veoadr_plz, veoadr_ort " &
                      " FROM veoadr WHERE basman_nr='" & basman_nr & "' And basman_nl='" & basman_nl & "' And veoant_beznr='" & veoant_beznr & "' " &
                      " And veoant_lfdnr=" & intLfdNr & " And veopos_posnr=" & intPosNr & " And veoadr_typ=" & lngTyp & " " &
                      " ORDER BY basman_nr, basman_nl, veoant_beznr, veoant_lfdnr, veopos_posnr, veoadr_typ ", conn)
                    Dim dr As SqlDataReader = cmd.ExecuteReader()
                    If dr.HasRows Then
                        dr.Read()
                        s = Left(Trim(dr.Item("veoadr_name1")) & Trim(", " & dr.Item("baslnd_alpha")) & Trim(", " & dr.Item("veoadr_plz")) & Trim(", " & dr.Item("veoadr_ort")), 50)
                    End If
                    dr.Close()
                End Using
                conn.Close()

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

    Public Function getATLASNacherfassungAdresseFrombaskun(ByVal zollNr As String, ByVal basman_nr As String, ByVal basman_nl As String, connArt As String) As String()
        Dim s(2) As String
        s(0) = ""
        s(1) = ""
        Try
            Dim conn As SqlConnection
            Select Case connArt
                Case "ATLAS" : conn = SQL.GetNewOpenConnectionATLAS
                Case "ATLAS_SBG" : conn = SQL.GetNewOpenConnectionATLAS_SBG
            End Select

            Using cmd As New SqlCommand(" SELECT TOP 1  baskun_nr, baskun_kurz,baskun_zbnr " &
                                       " FROM baskun WHERE baskun_zbnr='" & zollNr & "' And basman_nr='" & basman_nr & "' And basman_nl='" & basman_nl & "' " &
                                       " ORDER BY basman_nr, basman_nl, baskun_nr, baskun_lfd", conn)
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                If dr.HasRows Then
                    dr.Read()

                    s(0) = dr.Item("baskun_kurz").ToString
                    s(1) = dr.Item("baskun_nr").ToString
                End If
                dr.Close()
            End Using
            conn.Close()
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message)
        End Try
        Return s
    End Function

    Public Function getATLASNacherfassungAdresseFrombaskunByKuNr(ByVal baskun_nr As String, ByVal basman_nr As String, ByVal basman_nl As String, connArt As String) As String()
        Dim s(2) As String
        s(0) = ""
        s(1) = ""
        Try

            Dim conn As SqlConnection
            Select Case connArt
                Case "ATLAS" : conn = SQL.GetNewOpenConnectionATLAS
                Case "ATLAS_SBG" : conn = SQL.GetNewOpenConnectionATLAS_SBG
            End Select
            Using cmd As New SqlCommand(" SELECT TOP 1  baskun_nr, baskun_kurz, " &
                                       " FROM baskun WHERE baskun_nr='" & baskun_nr & "' And basman_nr='" & basman_nr & "' And basman_nl='" & basman_nl & "' " &
                                       " ORDER BY basman_nr, basman_nl, baskun_nr, baskun_lfd DESC", conn)
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                If dr.HasRows Then
                    dr.Read()
                    s(0) = dr.Item("baskun_kurz").ToString
                    s(1) = dr.Item("baskun_nr").ToString
                End If
                dr.Close()
            End Using
            conn.Close()
        Catch ex As Exception
            MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message)
        End Try
        Return s
    End Function

End Class
