2.8.4 Beta IDB replace Hochkomma bei Delete, Währungskonvertierung
This commit is contained in:
@@ -28,6 +28,60 @@ Public Class ClassFormat
|
||||
|
||||
End Select
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Normalisiert einen numerischen String für die invariante Kultur-Konvertierung.
|
||||
''' Entfernt Tausendertrennzeichen und ersetzt Dezimaltrennzeichen durch Punkt.
|
||||
''' </summary>
|
||||
Private Shared Function NormalizeNumericString(pValue As String) As String
|
||||
If String.IsNullOrWhiteSpace(pValue) Then
|
||||
Return pValue
|
||||
End If
|
||||
|
||||
Dim normalized As String = pValue.Trim()
|
||||
|
||||
' Entferne Währungssymbole und Leerzeichen
|
||||
normalized = System.Text.RegularExpressions.Regex.Replace(normalized, "[€$£¥\s]", "")
|
||||
|
||||
' Prüfe, ob der String sowohl Punkt als auch Komma enthält
|
||||
Dim hasDot As Boolean = normalized.Contains(".")
|
||||
Dim hasComma As Boolean = normalized.Contains(",")
|
||||
|
||||
If hasDot AndAlso hasComma Then
|
||||
' Beide vorhanden: Das letzte ist der Dezimaltrenner
|
||||
Dim lastDotPos As Integer = normalized.LastIndexOf(".")
|
||||
Dim lastCommaPos As Integer = normalized.LastIndexOf(",")
|
||||
|
||||
If lastDotPos > lastCommaPos Then
|
||||
' Punkt ist Dezimaltrenner, Komma ist Tausendertrenner
|
||||
normalized = normalized.Replace(",", "")
|
||||
Else
|
||||
' Komma ist Dezimaltrenner, Punkt ist Tausendertrenner
|
||||
normalized = normalized.Replace(".", "").Replace(",", ".")
|
||||
End If
|
||||
ElseIf hasComma Then
|
||||
' Nur Komma: Könnte Dezimal- oder Tausendertrenner sein
|
||||
' Wenn mehr als ein Komma → Tausendertrenner
|
||||
' Wenn nur ein Komma und <= 3 Stellen danach → Dezimaltrenner
|
||||
Dim commaCount As Integer = normalized.Count(Function(c) c = ","c)
|
||||
If commaCount = 1 Then
|
||||
Dim lastCommaPos As Integer = normalized.LastIndexOf(",")
|
||||
Dim digitsAfterComma As Integer = normalized.Length - lastCommaPos - 1
|
||||
If digitsAfterComma <= 3 Then
|
||||
' Wahrscheinlich Dezimaltrenner
|
||||
normalized = normalized.Replace(",", ".")
|
||||
Else
|
||||
' Wahrscheinlich Tausendertrenner
|
||||
normalized = normalized.Replace(",", "")
|
||||
End If
|
||||
Else
|
||||
' Mehrere Kommas → Tausendertrenner
|
||||
normalized = normalized.Replace(",", "")
|
||||
End If
|
||||
End If
|
||||
' Wenn nur Punkt vorhanden: bereits im richtigen Format
|
||||
|
||||
Return normalized
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Converts a string according to the type information, using the invariant culture
|
||||
@@ -41,25 +95,35 @@ Public Class ClassFormat
|
||||
|
||||
Select Case pType
|
||||
Case ClassControlCreator.CONTROL_TYPE_DOUBLE
|
||||
If Double.TryParse(pValue, NumberStyles.Float, CultureInfo.InvariantCulture, oConvertedValue) Then
|
||||
Return oConvertedValue
|
||||
End If
|
||||
|
||||
Case ClassControlCreator.CONTROL_TYPE_CURRENCY
|
||||
Try
|
||||
LOGGER.Debug($"GetConvertedValue: Converting {pValue.ToString} to Currency ")
|
||||
If Double.TryParse(pValue, NumberStyles.Currency, CultureInfo.InvariantCulture, oConvertedValue) Then
|
||||
Dim normalizedValue As String = NormalizeNumericString(pValue?.ToString())
|
||||
If Double.TryParse(normalizedValue, NumberStyles.Float, CultureInfo.InvariantCulture, oConvertedValue) Then
|
||||
Return oConvertedValue
|
||||
End If
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
End Try
|
||||
|
||||
Case ClassControlCreator.CONTROL_TYPE_CURRENCY
|
||||
Try
|
||||
Dim normalizedValue As String = NormalizeNumericString(pValue?.ToString())
|
||||
LOGGER.Debug($"GetConvertedValue: Converting {pValue.ToString} (normalized: {normalizedValue}) to Currency ")
|
||||
If Double.TryParse(normalizedValue, NumberStyles.Float, CultureInfo.InvariantCulture, oConvertedValue) Then
|
||||
Return oConvertedValue
|
||||
End If
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
End Try
|
||||
|
||||
Case ClassControlCreator.CONTROL_TYPE_INTEGER
|
||||
If Integer.TryParse(pValue, NumberStyles.Integer, CultureInfo.InvariantCulture, oConvertedValue) Then
|
||||
Return oConvertedValue
|
||||
End If
|
||||
Try
|
||||
Dim normalizedValue As String = NormalizeNumericString(pValue?.ToString())
|
||||
If Integer.TryParse(normalizedValue, NumberStyles.Integer, CultureInfo.InvariantCulture, oConvertedValue) Then
|
||||
Return oConvertedValue
|
||||
End If
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
End Try
|
||||
Case Else
|
||||
LOGGER.Debug($"GetConvertedValue - Case ELSE - pType is {pType}")
|
||||
Try
|
||||
|
||||
Reference in New Issue
Block a user