Compare commits
4 Commits
ed7aea5b72
...
214edf22a5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
214edf22a5 | ||
|
|
5ac3aaab54 | ||
|
|
1ab246fc46 | ||
|
|
9fe177abd3 |
@@ -34,6 +34,7 @@ Public Class ZUGFeRDInterface
|
||||
NoValidZugferd
|
||||
MissingProperties
|
||||
UnsupportedFormat
|
||||
FileTooBig
|
||||
UnknownError
|
||||
End Enum
|
||||
|
||||
|
||||
@@ -239,6 +239,12 @@ Public Class PropertyValues
|
||||
|
||||
Obj = oInfo.GetValue(Obj, Nothing)
|
||||
|
||||
' TODO: This code should check for array properties by itself
|
||||
' and should not rely on the user to
|
||||
'If oInfo.PropertyType.IsArray Then
|
||||
' Obj = Obj(0)
|
||||
'End If
|
||||
|
||||
If oHasIndex Then
|
||||
Obj = Obj(0)
|
||||
End If
|
||||
@@ -264,6 +270,8 @@ Public Class PropertyValues
|
||||
|
||||
Return oResults
|
||||
End If
|
||||
|
||||
|
||||
Next
|
||||
|
||||
Return New List(Of Object) From {Obj}
|
||||
|
||||
@@ -12,8 +12,8 @@ Imports System.Runtime.InteropServices
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("Modules.Jobs")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
||||
<Assembly: AssemblyTrademark("1.13.0.0")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2023")>
|
||||
<Assembly: AssemblyTrademark("1.14.0.0")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
@@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices
|
||||
' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
|
||||
<Assembly: AssemblyVersion("1.13.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.13.0.0")>
|
||||
<Assembly: AssemblyVersion("1.14.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.14.0.0")>
|
||||
|
||||
@@ -41,6 +41,13 @@ Public Class ImportZUGFeRDFiles
|
||||
Private _zugferd As ZUGFeRDInterface
|
||||
Private _EmailOutAccountId As Integer
|
||||
|
||||
Private Class DatabaseConnections
|
||||
Public Property SQLServerConnection As SqlConnection
|
||||
Public Property SQLServerTransaction As SqlTransaction
|
||||
Public Property FirebirdConnection As FbConnection
|
||||
Public Property FirebirdTransaction As FbTransaction
|
||||
End Class
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Firebird As Firebird, Optional MSSQL As MSSQLServer = Nothing)
|
||||
_logConfig = LogConfig
|
||||
_logger = LogConfig.GetLogger()
|
||||
@@ -170,6 +177,13 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oSQLConnection As SqlConnection = _mssql.GetConnection()
|
||||
Dim oSQLTransaction As SqlTransaction = oSQLConnection?.BeginTransaction()
|
||||
|
||||
Dim oConnections As New DatabaseConnections() With {
|
||||
.SQLServerConnection = oSQLConnection,
|
||||
.SQLServerTransaction = oSQLTransaction,
|
||||
.FirebirdConnection = oFBConnection,
|
||||
.FirebirdTransaction = oFBTransaction
|
||||
}
|
||||
|
||||
If oSQLConnection Is Nothing Then
|
||||
_logger.Warn("SQL Connection was not set. No INSERTs for MSSQL Server will be performed!")
|
||||
oArgs.InsertIntoSQLServer = False
|
||||
@@ -294,51 +308,28 @@ Public Class ImportZUGFeRDFiles
|
||||
_logger.Warn("[{0}] missing properties found. Exiting.", oCheckResult.MissingProperties.Count)
|
||||
oMissingProperties = oCheckResult.MissingProperties
|
||||
Throw New MissingValueException(oFile)
|
||||
Else
|
||||
_logger.Debug("No missing properties found. Continuing.")
|
||||
|
||||
End If
|
||||
|
||||
_logger.Debug("No missing properties found. Continuing.")
|
||||
DeleteExistingPropertyValues(oMessageId, oArgs, oConnections)
|
||||
|
||||
Dim oDelSQL = $"DELETE FROM TBEDMI_ITEM_VALUE where REFERENCE_GUID = '{oMessageId}'"
|
||||
Dim oStep As String
|
||||
|
||||
oStep = "Firebird TBEDMI_ITEM_VALUE Delete messageID Items"
|
||||
Try
|
||||
_firebird.ExecuteNonQueryWithConnection(oDelSQL, oFBConnection, Firebird.TransactionMode.ExternalTransaction, oFBTransaction)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
_logger.Warn("Step [{0}] with SQL [{1}] was not successful.", oStep, oDelSQL)
|
||||
End Try
|
||||
|
||||
If oArgs.InsertIntoSQLServer = True Then
|
||||
oStep = "MSSQL TBEDMI_ITEM_VALUE Delete messageID Items"
|
||||
Try
|
||||
_mssql.ExecuteNonQueryWithConnectionObject(oDelSQL, oSQLConnection, MSSQLServer.TransactionMode.ExternalTransaction, oSQLTransaction)
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Step [{0}] with SQL [{1}] was not successful.", oStep, oDelSQL)
|
||||
End Try
|
||||
Dim oFirstProperty = oCheckResult.ValidProperties.FirstOrDefault()
|
||||
If oFirstProperty IsNot Nothing Then
|
||||
InsertPropertyValue(oMessageId, oArgs, oConnections, New PropertyValues.ValidProperty() With {
|
||||
.MessageId = oMessageId,
|
||||
.Description = "ZUGFeRDSpezifikation",
|
||||
.GroupCounter = 0,
|
||||
.IsRequired = False,
|
||||
.Value = oDocument.Specification,
|
||||
.TableName = oFirstProperty.TableName,
|
||||
.TableColumn = "ZUGFERD_SPECIFICATION"
|
||||
})
|
||||
End If
|
||||
|
||||
For Each oProperty In oCheckResult.ValidProperties
|
||||
Dim oGroupCounterValue = oProperty.GroupCounter
|
||||
|
||||
' If GroupCounter is -1, it means this is a default property that can only occur once.
|
||||
' Set the actual inserted value to 0
|
||||
If oGroupCounterValue = -1 Then
|
||||
oGroupCounterValue = 0
|
||||
End If
|
||||
|
||||
Dim oCommand = $"INSERT INTO {oProperty.TableName} (REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, GROUP_COUNTER,SPEC_NAME,IS_REQUIRED) VALUES
|
||||
('{oMessageId}', '{oProperty.Description}', '{oProperty.Value.Replace("'", "''")}', {oGroupCounterValue},'{oProperty.TableColumn}','{oProperty.IsRequired}')"
|
||||
_logger.Debug("Mapping Property [{0}] with value [{1}], Will be inserted into table [{2}]", oProperty.TableColumn, oProperty.Value.Replace("'", "''"), oProperty.TableName)
|
||||
' Insert into SQL Server
|
||||
If oArgs.InsertIntoSQLServer = True Then
|
||||
Dim oResult = _mssql.ExecuteNonQueryWithConnectionObject(oCommand, oSQLConnection, MSSQLServer.TransactionMode.ExternalTransaction, oSQLTransaction)
|
||||
If oResult = False Then
|
||||
_logger.Warn($"SQL Command [{oCommand}] was not successful. Check the log.")
|
||||
End If
|
||||
End If
|
||||
' Insert into Firebird
|
||||
_firebird.ExecuteNonQueryWithConnection(oCommand, oFBConnection, Firebird.TransactionMode.ExternalTransaction, oFBTransaction)
|
||||
InsertPropertyValue(oMessageId, oArgs, oConnections, oProperty)
|
||||
Next
|
||||
Next
|
||||
|
||||
@@ -583,6 +574,51 @@ Public Class ImportZUGFeRDFiles
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub DeleteExistingPropertyValues(pMessageId As String, pArgs As WorkerArgs, pConnections As DatabaseConnections)
|
||||
Dim oDelSQL = $"DELETE FROM TBEDMI_ITEM_VALUE where REFERENCE_GUID = '{pMessageId}'"
|
||||
Dim oStep As String
|
||||
|
||||
oStep = "Firebird TBEDMI_ITEM_VALUE Delete messageID Items"
|
||||
Try
|
||||
_firebird.ExecuteNonQueryWithConnection(oDelSQL, pConnections.FirebirdConnection, Firebird.TransactionMode.ExternalTransaction, pConnections.FirebirdTransaction)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
_logger.Warn("Step [{0}] with SQL [{1}] was not successful.", oStep, oDelSQL)
|
||||
End Try
|
||||
|
||||
If pArgs.InsertIntoSQLServer = True Then
|
||||
oStep = "MSSQL TBEDMI_ITEM_VALUE Delete messageID Items"
|
||||
Try
|
||||
_mssql.ExecuteNonQueryWithConnectionObject(oDelSQL, pConnections.SQLServerConnection, MSSQLServer.TransactionMode.ExternalTransaction, pConnections.SQLServerTransaction)
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Step [{0}] with SQL [{1}] was not successful.", oStep, oDelSQL)
|
||||
End Try
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub InsertPropertyValue(pMessageId As String, pArgs As WorkerArgs, pConnections As DatabaseConnections, pProperty As PropertyValues.ValidProperty)
|
||||
Dim oGroupCounterValue = pProperty.GroupCounter
|
||||
|
||||
' If GroupCounter is -1, it means this is a default property that can only occur once.
|
||||
' Set the actual inserted value to 0
|
||||
If oGroupCounterValue = -1 Then
|
||||
oGroupCounterValue = 0
|
||||
End If
|
||||
|
||||
Dim oCommand = $"INSERT INTO {pProperty.TableName} (REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, GROUP_COUNTER, SPEC_NAME, IS_REQUIRED) VALUES
|
||||
('{pMessageId}', '{pProperty.Description}', '{pProperty.Value.Replace("'", "''")}', {oGroupCounterValue},'{pProperty.TableColumn}','{pProperty.IsRequired}')"
|
||||
_logger.Debug("Mapping Property [{0}] with value [{1}], Will be inserted into table [{2}]", pProperty.TableColumn, pProperty.Value.Replace("'", "''"), pProperty.TableName)
|
||||
' Insert into SQL Server
|
||||
If pArgs.InsertIntoSQLServer = True Then
|
||||
Dim oResult = _mssql.ExecuteNonQueryWithConnectionObject(oCommand, pConnections.SQLServerConnection, MSSQLServer.TransactionMode.ExternalTransaction, pConnections.SQLServerTransaction)
|
||||
If oResult = False Then
|
||||
_logger.Warn($"SQL Command [{oCommand}] was not successful. Check the log.")
|
||||
End If
|
||||
End If
|
||||
' Insert into Firebird
|
||||
_firebird.ExecuteNonQueryWithConnection(oCommand, pConnections.FirebirdConnection, Firebird.TransactionMode.ExternalTransaction, pConnections.FirebirdTransaction)
|
||||
End Sub
|
||||
|
||||
Private Function GetPropertyMapFor(pWorkerArgs As WorkerArgs, pSpecification As String) As Dictionary(Of String, XmlItemProperty)
|
||||
Dim oPropertyMap = DoGetPropertyMapFor(pWorkerArgs, pSpecification)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user