Add MSSQL Functions to ZUGFeRD Service
This commit is contained in:
@@ -1,29 +1,27 @@
|
||||
Imports System.Data.SqlClient
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class MSSQLServer
|
||||
Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger
|
||||
Public DBInitialized As Boolean = False
|
||||
Public CurrentSQLConnectionString As String = ""
|
||||
Private CurrentSQLConnection As SqlClient.SqlConnection
|
||||
Public Sub New(CONSTRING As String)
|
||||
Init(CONSTRING)
|
||||
End Sub
|
||||
Public Function Init(CONSTRING As String)
|
||||
Private CurrentSQLConnection As SqlConnection
|
||||
Private _Logger As Logger
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, ConnectionString As String)
|
||||
_Logger = LogConfig.GetLogger()
|
||||
|
||||
Try
|
||||
Dim oSQLconnect As New SqlClient.SqlConnection
|
||||
oSQLconnect.ConnectionString = CONSTRING
|
||||
Dim oSQLconnect As New SqlConnection
|
||||
oSQLconnect.ConnectionString = ConnectionString
|
||||
oSQLconnect.Open()
|
||||
oSQLconnect.Close()
|
||||
CurrentSQLConnectionString = CONSTRING
|
||||
CurrentSQLConnectionString = ConnectionString
|
||||
DBInitialized = True
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
DBInitialized = False
|
||||
Logger.Error(ex)
|
||||
'clsLogger.Add("Error in DatabaseInit: " & ex.Message, True)
|
||||
Return False
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Function
|
||||
End Sub
|
||||
|
||||
Private Function GetSQLConnection()
|
||||
Try
|
||||
@@ -32,22 +30,21 @@ Public Class MSSQLServer
|
||||
oSQLconnect.ConnectionString = CurrentSQLConnectionString
|
||||
CurrentSQLConnection = oSQLconnect
|
||||
CurrentSQLConnection.Open()
|
||||
|
||||
Else
|
||||
If CurrentSQLConnection.State <> ConnectionState.Open Then
|
||||
Logger.Warn($"Actual ConnectionState is: '{CurrentSQLConnection.State.ToString}'")
|
||||
_Logger.Warn($"Actual ConnectionState is: '{CurrentSQLConnection.State.ToString}'")
|
||||
Try
|
||||
CurrentSQLConnection.Open()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not reconnect to database!")
|
||||
_Logger.Warn("Could not reconnect to database!")
|
||||
Return False
|
||||
End Try
|
||||
End If
|
||||
End If
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
_Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
@@ -65,18 +62,18 @@ Public Class MSSQLServer
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oSQLCOmmand As SqlClient.SqlCommand
|
||||
Dim oSQLCOmmand As SqlCommand
|
||||
|
||||
oSQLCOmmand = CurrentSQLConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = sqlcommand
|
||||
oSQLCOmmand.CommandTimeout = commandtimeout
|
||||
Dim adapter1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(oSQLCOmmand)
|
||||
Dim adapter1 As SqlDataAdapter = New SqlDataAdapter(oSQLCOmmand)
|
||||
adapter1.Fill(dt)
|
||||
|
||||
Return dt
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Debug("sqlcommand: " & sqlcommand)
|
||||
_Logger.Error(ex)
|
||||
_Logger.Debug("sqlcommand: " & sqlcommand)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
@@ -93,7 +90,7 @@ Public Class MSSQLServer
|
||||
Return Nothing
|
||||
End If
|
||||
'Dim oSQLconnect As New SqlClient.SqlConnection
|
||||
Dim oSQLCOmmand As SqlClient.SqlCommand
|
||||
Dim oSQLCOmmand As SqlCommand
|
||||
|
||||
oSQLCOmmand = CurrentSQLConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = executeStatement
|
||||
@@ -102,8 +99,8 @@ Public Class MSSQLServer
|
||||
oSQLCOmmand.Dispose()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Debug("executeStatement: " & executeStatement)
|
||||
_Logger.Error(ex)
|
||||
_Logger.Debug("executeStatement: " & executeStatement)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
@@ -118,8 +115,8 @@ Public Class MSSQLServer
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oSQLCOmmand As SqlClient.SqlCommand
|
||||
Dim callback As New AsyncCallback(AddressOf Execute_non_Query_Async_Callback)
|
||||
Dim oSQLCOmmand As SqlCommand
|
||||
Dim callback As New AsyncCallback(AddressOf NewExecuteNonQueryAsync_Callback)
|
||||
Try
|
||||
oSQLCOmmand = CurrentSQLConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = executeStatement
|
||||
@@ -127,15 +124,15 @@ Public Class MSSQLServer
|
||||
oSQLCOmmand.BeginExecuteNonQuery(callback, oSQLCOmmand)
|
||||
oSQLCOmmand.Dispose()
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Debug("executeStatement: " & executeStatement)
|
||||
_Logger.Error(ex)
|
||||
_Logger.Debug("executeStatement: " & executeStatement)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub Execute_non_Query_Async_Callback(ByVal result As IAsyncResult)
|
||||
Dim command As SqlClient.SqlCommand = CType(result.AsyncState, SqlClient.SqlCommand)
|
||||
Private Sub NewExecuteNonQueryAsync_Callback(ByVal result As IAsyncResult)
|
||||
Dim command As SqlCommand = CType(result.AsyncState, SqlCommand)
|
||||
Dim res = command.EndExecuteNonQuery(result)
|
||||
Logger.Info(String.Format("Finished executing Async database operation: {0}", command.CommandText))
|
||||
_Logger.Info(String.Format("Finished executing Async database operation: {0}", command.CommandText))
|
||||
End Sub
|
||||
''' <summary>
|
||||
''' Executes the passed sql-statement as Scalar
|
||||
@@ -159,8 +156,8 @@ Public Class MSSQLServer
|
||||
oSQLCOmmand.Dispose()
|
||||
Return result
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Debug("executeStatement: " & executeStatement)
|
||||
_Logger.Error(ex)
|
||||
_Logger.Debug("executeStatement: " & executeStatement)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Reference in New Issue
Block a user