Modules.Interface: Bei Item_Type = 2 wird der Wert in eine decimal-Zahl mit 2 Nachkommastellen umgewandelt, abhängig vom Dezimaltrennzeichen

This commit is contained in:
2026-09-10 14:30:21 +02:00
parent 676b43bbe1
commit 1871cca2a6
2 changed files with 69 additions and 13 deletions

View File

@@ -1,8 +1,8 @@
Public Enum Item_Types Public Enum Item_Types
StringType '0 StringType = 0 '0
DateType '1 DateType = 1 '1
MoneyType '2 MoneyType = 2 '2
FileType '3 FileType = 3 '3
ListType '4 - vgl. Währung ListType = 4 '4 - vgl. Währung
End Enum End Enum

View File

@@ -1,7 +1,9 @@
Imports System.Globalization Imports System.Globalization
Imports System.Reflection Imports System.Reflection
Imports System.Text.RegularExpressions Imports System.Text.RegularExpressions
Imports System.Xml
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports GdPicture.Internal.MSOfficeBinary.translator.Tools
Public Class PropertyValues Public Class PropertyValues
Private _logger As Logger Private _logger As Logger
@@ -122,12 +124,13 @@ Public Class PropertyValues
' Returns nothing if oColumn.Value contains an empty list ' Returns nothing if oColumn.Value contains an empty list
Dim oPropertyValue = oColumn.Value.ElementAtOrDefault(oRowIndex) Dim oPropertyValue = oColumn.Value.ElementAtOrDefault(oRowIndex)
_logger.Debug("Processing itemColumn *TableColumn* [{0}].", oTableColumn) '_logger.Debug("Processing itemColumn *TableColumn* [{0}].", oTableColumn)
If oTableColumn = "INVOICE_SELLER_EMAIL" Then 'If oTableColumn = "INVOICE_SELLER_EMAIL" Then
Console.WriteLine("INVOICE_SELLER_EMAIL") ' Console.WriteLine("INVOICE_SELLER_EMAIL")
ElseIf oTableColumn = "INVOICE_POSITION_ARTICLE" Then 'ElseIf oTableColumn = "INVOICE_POSITION_ARTICLE" Then
Console.WriteLine("INVOICE_POSITION_ARTICLE") ' Console.WriteLine("INVOICE_POSITION_ARTICLE")
End If 'End If
If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then
If oColumn.Key.IsRequired Then If oColumn.Key.IsRequired Then
_logger.Warn($"{MessageId} - oPropertyValue for column [{oTableColumn}] is empty or not found but is required. Continuing with Empty String.") _logger.Warn($"{MessageId} - oPropertyValue for column [{oTableColumn}] is empty or not found but is required. Continuing with Empty String.")
@@ -154,7 +157,11 @@ Public Class PropertyValues
End If End If
If oTableColumn = "INVOICE_CURRENCY" Or oItemType = 4 Then If oItemType = Item_Types.MoneyType Then
oPropertyValue = GetFormattedDecimalValue(oPropertyValue)
End If
If oTableColumn = "INVOICE_CURRENCY" Or oItemType = Item_Types.ListType Then
Dim oValuestring = oPropertyValue.ToString() Dim oValuestring = oPropertyValue.ToString()
' Bei Listenelementen entfernen wir den String Item, um den Wert zu erhalten ' Bei Listenelementen entfernen wir den String Item, um den Wert zu erhalten
@@ -247,6 +254,10 @@ Public Class PropertyValues
End If End If
End If End If
If oItemType = Item_Types.MoneyType Then
oPropertyValue = GetFormattedDecimalValue(oPropertyValue)
End If
' Statt dem Zahlenwert des Enums, wollen wir die Währungsbezeichnung ' Statt dem Zahlenwert des Enums, wollen wir die Währungsbezeichnung
If oTableColumn = "INVOICE_CURRENCY" Or oItemType = 4 Then If oTableColumn = "INVOICE_CURRENCY" Or oItemType = 4 Then
Dim oValuestring = oPropertyValue.ToString() Dim oValuestring = oPropertyValue.ToString()
@@ -275,6 +286,51 @@ Public Class PropertyValues
Return oResult Return oResult
End Function End Function
Private Function GetFormattedDecimalValue(pPropertyValue As Object) As Object
' wir versuchen den gefundenen Wert in einen decimal mit 2 Nachommastellen umzuwandeln
' Eingaben können mit . oder mit , als Dezimal-Trenner kommen: 19.00 = 19,00
If IsNothing(pPropertyValue) OrElse String.IsNullOrEmpty(pPropertyValue) Then
Return String.Empty
End If
Try
Dim stringValue = pPropertyValue.ToString()
Dim deCulture As New CultureInfo("de-DE")
Dim usCulture As New CultureInfo("en-US")
Dim decimalValue As Decimal
If stringValue.Contains(".") AndAlso Not stringValue.Contains(",") Then
' Wir wandeln mit en-US um
If Decimal.TryParse(pPropertyValue, NumberStyles.Any, usCulture, decimalValue) Then
decimalValue = Math.Round(decimalValue, 2)
pPropertyValue = decimalValue.ToString("F2", CultureInfo.InvariantCulture)
End If
ElseIf stringValue.Contains(",") AndAlso Not stringValue.Contains(".") Then
' Wir wandeln mit de-DE um, wenn Komma als Trennzeichen enthalten ist
If Decimal.TryParse(pPropertyValue, NumberStyles.Any, deCulture, decimalValue) Then
decimalValue = Math.Round(decimalValue, 2)
pPropertyValue = decimalValue.ToString("F2", CultureInfo.InvariantCulture)
End If
ElseIf Not stringValue.Contains(",") AndAlso Not stringValue.Contains(".") Then
' Wir wandeln mit en-US um, wenn KEIN Trennzeichen enthalten ist
If Decimal.TryParse(pPropertyValue, NumberStyles.Any, usCulture, decimalValue) Then
decimalValue = Math.Round(decimalValue, 2)
pPropertyValue = decimalValue.ToString("F2", CultureInfo.InvariantCulture)
End If
End If
Return pPropertyValue
Catch ex As Exception
_logger.Error(ex)
Return Nothing
End Try
End Function
Public Function CheckRootAttributeValues(pDocument As Object, pPropertyMap As Dictionary(Of String, XmlItemProperty), pMessageId As String, pCheckResult As CheckPropertyValuesResult) As CheckPropertyValuesResult Public Function CheckRootAttributeValues(pDocument As Object, pPropertyMap As Dictionary(Of String, XmlItemProperty), pMessageId As String, pCheckResult As CheckPropertyValuesResult) As CheckPropertyValuesResult
If pPropertyMap Is Nothing Then If pPropertyMap Is Nothing Then
@@ -368,7 +424,7 @@ Public Class PropertyValues
Case "SubsequentDebit" Case "SubsequentDebit"
Return 1 Return 1
Case Else Case Else
Return 380 Return 0
End Select End Select
End Function End Function