improve function + params handling

This commit is contained in:
Jonathan Jenne
2022-03-16 12:17:54 +01:00
parent e3c2e100bb
commit 4c1a3a9220
2 changed files with 36 additions and 18 deletions

View File

@@ -281,22 +281,11 @@ Namespace Documents
Continue For
End If
Dim oFunctionName = oColumn.Config?.Function?.Name
Dim oFunctionName = oColumn.Config.FunctionName
Dim oFunctionParams = oColumn.Config.FunctionParams
Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams)
' TODO: Make more nice
Dim oParams = oColumn.Config?.Function?.Params
Dim oParamsDict As New Dictionary(Of String, String)
If oParams IsNot Nothing AndAlso oParams <> String.Empty Then
Dim oParamList = oParams.Split("|").ToList()
For Each oParam In oParamList
Dim oParamSplit = oParam.Split("=")
oParamsDict.Add(oParamSplit(0), oParamSplit(1))
Next
End If
If oFunctionName = "PRICE" Then
If oFunctionName = Constants.FUNCTION_PRICE Then
Await SetPrice(oRow, oField.Key, oParamsDict, pDocument, pMandator, pTemplate)
End If
Next
@@ -319,10 +308,12 @@ Namespace Documents
Continue For
End If
Dim oFunctionName = oColumn.Config?.Function?.Name
Dim oFunctionName = oColumn.Config.FunctionName
Dim oFunctionParams = oColumn.Config.FunctionParams
Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams)
If oFunctionName = "GLN" Then
SetAccountByGLN(oRow, pMandator, oField.Key, Nothing)
SetAccountByGLN(oRow, pMandator, oField.Key, Nothing, oParamsDict)
End If
If oFunctionName = "EAN" Then
@@ -419,7 +410,7 @@ Namespace Documents
End If
End Sub
Private Sub SetAccountByGLN(oRow As DocumentRow, pMandator As Mandator, pNumberField As String, pNameField As String)
Private Sub SetAccountByGLN(oRow As DocumentRow, pMandator As Mandator, pNumberField As String, pNameField As String, pParams As Dictionary(Of String, String))
' Try to read the Account number (which is a GLN really) and account Name
Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(pNumberField)
Dim oNameItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(pNameField)
@@ -456,6 +447,20 @@ Namespace Documents
Private Function WrapFileInfo(pFileInfo As FileInfo) As Document
Return New Document With {.File = pFileInfo}
End Function
Private Function ParseFunctionParamsAsDict(pParams As String) As Dictionary(Of String, String)
Dim oParamsDict As New Dictionary(Of String, String)
If pParams <> String.Empty Then
Dim oParamList = pParams.Split("|").ToList()
For Each oParam In oParamList
Dim oParamSplit = oParam.Split("=")
oParamsDict.Add(oParamSplit(0), oParamSplit(1))
Next
End If
Return oParamsDict
End Function
End Class
End Namespace