Show Errors, Make grids usable when no mandator is selected, move completed files also when reloading

This commit is contained in:
Jonathan Jenne
2022-04-19 15:33:44 +02:00
parent 9be55f3709
commit 1bef72d65c
12 changed files with 453 additions and 294 deletions

View File

@@ -63,6 +63,10 @@
ArticleNotFound
End Enum
Public Enum DocumentError
MandatorNotFound
End Enum
Public Enum XmlFunction
None = 0
GLN = 1

View File

@@ -1,4 +1,5 @@
Imports System.IO
Imports MultiTool.Common.Constants
Imports MultiTool.Common.Templates
Imports MultiTool.Common.Winline.Entities
@@ -27,6 +28,18 @@ Namespace Documents
End Get
End Property
Public ReadOnly Property Errors As List(Of String)
Get
Dim oRowErrors = Rows.SelectMany(Function(row) row.Errors).ToList()
Dim oDocumentErrors As List(Of String) = GetDocumentErrors().
Select(Function(err) err.ToString()).
ToList()
Return oDocumentErrors.
Concat(oRowErrors).
ToList()
End Get
End Property
Public ReadOnly Property MandatorId As String
Get
Return Mandator?.Id
@@ -69,6 +82,17 @@ Namespace Documents
Public Overrides Function Equals(obj As Object) As Boolean
Return FullName = DirectCast(obj, Document).FullName
End Function
Private Function GetDocumentErrors() As List(Of DocumentError)
Dim oErrors As New List(Of DocumentError)
If Mandator Is Nothing Then
oErrors.Add(DocumentError.MandatorNotFound)
End If
Return oErrors
End Function
End Class
End Namespace

View File

@@ -22,11 +22,23 @@ Namespace Documents
Where(Function(doc) doc.Imported = True).
ToList()
If oImportedDocuments.Count = 0 Then
Logger.Debug("No exported files found. Skipping.")
Return True
End If
Logger.Debug("Cleaning [{0}] exported files, moving to [{1}]", oImportedDocuments.Count, oOutputDirectory)
Dim oRemovedDocuments As New List(Of Document)
For Each oDocument As Document In oImportedDocuments
Try
Dim oFileinfo = New FileInfo(oDocument.FullName)
Dim oDestination = Path.Combine(oOutputDirectory, oFileinfo.Name)
File.Move(oFileinfo.FullName, oDestination)
oRemovedDocuments.Add(oDocument)
Logger.Debug("File [{0}] successfully moved.", oFileinfo.Name)
Catch ex As Exception
Logger.Warn("File [{0}] could not be moved to output directory!", oDocument.FullName)
Logger.Error(ex)
@@ -34,6 +46,12 @@ Namespace Documents
End Try
Next
Logger.Debug("Moved [{0}] files successfully.", oRemovedDocuments.Count)
pDocuments = pDocuments.
Except(oRemovedDocuments).
ToList()
Return oResult
End Function
End Class

View File

@@ -314,6 +314,10 @@ Namespace Documents
Dim oFunctionName = oColumn.Config.FunctionName
Dim oFunctionParams = oColumn.Config.FunctionParams
Logger.Debug("Running Function: [{0}]", oFunctionName)
Logger.Debug("With Parameters: [{0}]", oFunctionParams)
Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams)
If oFunctionName = Constants.FUNCTION_PRICE Then
@@ -468,13 +472,26 @@ Namespace Documents
Dim oPriceItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pPriceField)
' These fields are fetched from the current row
Dim oArticleNumberField As String = oFieldMap.GetOrDefault("Article", Nothing)
Const PARAMETER_ARTICLE = "Article"
Dim oArticleNumberField As String = oFieldMap.GetOrDefault(PARAMETER_ARTICLE, Nothing)
If oArticleNumberField Is Nothing Then
Logger.Warn("Parameter '{0}' not found for Function PRICE", PARAMETER_ARTICLE)
End If
If pRow.Fields.ContainsKey(oArticleNumberField) = False Then
Logger.Warn("Value '{0}' for Parameter '{1}' not found for Function PRICE", oArticleNumberField, PARAMETER_ARTICLE)
End If
Dim oArticleNumber As String = pRow.Fields.Item(oArticleNumberField).Final
Dim oQuantityField As String = oFieldMap.GetOrDefault("Quantity", Nothing)
Const PARAMETER_QUANTITY = "Quantity"
Dim oQuantityField As String = oFieldMap.GetOrDefault(PARAMETER_QUANTITY, Nothing)
If oQuantityField Is Nothing Then
Logger.Warn("Parameter '{0}' not found for Function PRICE", PARAMETER_QUANTITY)
End If
Dim oQuantity As Integer = 1
If Integer.TryParse(pRow.Fields.Item(oQuantityField).Final, oQuantity) = False Then
Logger.Warn("Value for parameter Quantity could not be parsed. Setting to 1.")
Logger.Warn("Value for parameter '{0}' could not be parsed. Setting to 1.", PARAMETER_QUANTITY)
End If
' These fields a fetched from the head row, ie. the first row

View File

@@ -39,7 +39,7 @@ Namespace Documents
Get
Return Fields.
Where(Function(f) f.Value.HasError).
Select(Function(f) f.Key).ToList()
Select(Function(f) $"{f.Key} has Error: {f.Value.Error}").ToList()
End Get
End Property
@@ -56,7 +56,7 @@ Namespace Documents
Private _External As String = ""
Private _Original As String = ""
Public Property DataType As Constants.ColumnType = Constants.ColumnType.String
Public Property DataType As ColumnType = ColumnType.String
Public Property [Error] As FieldError = FieldError.None
Public Sub New()
@@ -117,7 +117,7 @@ Namespace Documents
Return Final
End Function
Private Function FormatValue(pValue As String, pType As Constants.ColumnType) As String
Private Function FormatValue(pValue As String, pType As ColumnType) As String
Select Case pType
Case ColumnType.Decimal
Return FormatDecimalValue(pValue)
@@ -131,11 +131,11 @@ Namespace Documents
''' This function will capture values like below and format them according to winline format values
'''
''' 1000
''' 1.000.000
''' 1.000.000,00
''' 1.000
''' 1.000,00
''' </summary>
''' <param name="pValue">A string value that represents a number</param>
''' <returns>A string value which contains at dot (.) as the decimal divider</returns>
''' <returns>A string value which contains at dot (.) as the decimal divider, ex. 1000.00</returns>
Private Function FormatDecimalValue(pValue As String) As String
If Not pValue.Contains(","c) Then
Return pValue