Add virtual property to field value, improve ui when loading files, improve initial loading
This commit is contained in:
@@ -55,6 +55,14 @@
|
||||
[Boolean]
|
||||
[Decimal]
|
||||
End Enum
|
||||
|
||||
Public Enum FieldError
|
||||
None
|
||||
MissingValue
|
||||
AccountNotFound
|
||||
ArticleNotFound
|
||||
End Enum
|
||||
|
||||
Public Enum XmlFunction
|
||||
None = 0
|
||||
GLN = 1
|
||||
|
||||
@@ -6,6 +6,7 @@ Imports MultiTool.Common.Exceptions
|
||||
Imports MultiTool.Common.Templates
|
||||
Imports MultiTool.Common.Winline
|
||||
Imports MultiTool.Common.Winline.Entities
|
||||
Imports MultiTool.Common.Constants
|
||||
|
||||
Namespace Documents
|
||||
Public Class DocumentLoader
|
||||
@@ -16,12 +17,32 @@ Namespace Documents
|
||||
Private ReadOnly TemplateConfig As TemplateConfig
|
||||
|
||||
Public Property Files As New List(Of Document)
|
||||
Public Event FileLoadComplete As EventHandler(Of FileLoadInfo)
|
||||
|
||||
Public Structure FileLoadInfo
|
||||
Public Property FilesTotal As Integer = 0
|
||||
Public Property FilesLoaded As Integer = 0
|
||||
|
||||
Public Event FileLoadComplete As EventHandler(Of FileLoadInfo)
|
||||
Public Event FileLoadProgress As EventHandler(Of FileLoadProgressInfo)
|
||||
|
||||
Public Class FileLoadInfo
|
||||
Public FilesLoaded As Integer
|
||||
Public FilesTotal As Integer
|
||||
End Structure
|
||||
|
||||
Public Sub New(pTotal As Integer, pLoaded As Integer)
|
||||
FilesTotal = pTotal
|
||||
FilesLoaded = pLoaded
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class FileLoadProgressInfo
|
||||
Inherits FileLoadInfo
|
||||
|
||||
Public RunningFunction As String
|
||||
|
||||
Public Sub New(pTotal As Integer, pLoaded As Integer)
|
||||
MyBase.New(pTotal, pLoaded)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pWinline As WinlineData, pMappingConfig As MappingConfig, pTemplateConfig As TemplateConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
@@ -37,6 +58,7 @@ Namespace Documents
|
||||
Try
|
||||
Dim oDirectory As New DirectoryInfo(pTemplate.InputDirectory)
|
||||
Dim oFiles = oDirectory.GetFiles()
|
||||
FilesTotal = oFiles.Count
|
||||
|
||||
Logger.Debug("Found [{0}] files in directory [{1}]", oFiles.Count, oDirectory)
|
||||
|
||||
@@ -44,11 +66,9 @@ Namespace Documents
|
||||
Try
|
||||
Dim oDocument = Await LoadFile(oFile, pTemplate, pMandator)
|
||||
Files.Add(oDocument)
|
||||
FilesLoaded = Files.Count
|
||||
|
||||
Dim oInfo As FileLoadInfo
|
||||
oInfo.FilesLoaded = Files.Count
|
||||
oInfo.FilesTotal = oFiles.Count
|
||||
|
||||
Dim oInfo As New FileLoadInfo(FilesTotal, FilesLoaded)
|
||||
RaiseEvent FileLoadComplete(Me, oInfo)
|
||||
|
||||
Catch ex As MissingAttributeException
|
||||
@@ -179,17 +199,19 @@ Namespace Documents
|
||||
.Final = oValue,
|
||||
.DataType = oColumn.DataType,
|
||||
.IsRequired = oRequired,
|
||||
.IsVirtual = oColumn.Config.IsVirtual,
|
||||
.SortKey = oColumnSortKey
|
||||
})
|
||||
Else
|
||||
Dim oColumnError = DocumentRow.FieldError.None
|
||||
Dim oColumnError = FieldError.None
|
||||
If oColumn.Config?.IsRequired Then
|
||||
oColumnError = DocumentRow.FieldError.MissingValue
|
||||
oColumnError = FieldError.MissingValue
|
||||
End If
|
||||
|
||||
oFields.Add(oColumn.Name, New DocumentRow.FieldValue With {
|
||||
.[Error] = oColumnError,
|
||||
.SortKey = oColumnSortKey
|
||||
.SortKey = oColumnSortKey,
|
||||
.IsVirtual = oColumn.Config.IsVirtual
|
||||
})
|
||||
End If
|
||||
|
||||
@@ -224,6 +246,9 @@ Namespace Documents
|
||||
OrderBy(Function(m) m.Order).
|
||||
ToList()
|
||||
|
||||
Dim oInfo As New FileLoadProgressInfo(FilesTotal, FilesLoaded) With {.RunningFunction = "Mandant finden"}
|
||||
RaiseEvent FileLoadProgress(Me, oInfo)
|
||||
|
||||
Dim oMandator As Mandator = Nothing
|
||||
If pMandator IsNot Nothing Then
|
||||
oMandator = pMandator
|
||||
@@ -237,12 +262,24 @@ Namespace Documents
|
||||
' Set mandator befor applying any functions that depend on a valid mandator
|
||||
pDocument.Mandator = oMandator
|
||||
|
||||
RaiseEvent FileLoadProgress(Me, New FileLoadProgressInfo(FilesTotal, FilesLoaded) With {
|
||||
.RunningFunction = "Winline-Funktionen"
|
||||
})
|
||||
|
||||
pDocument = ApplyDefinedItemFunctionsForImport(pDocument, oMandator, pTemplate)
|
||||
pDocument = ApplyDynamicItemFunctionsForImport(pDocument, oMandator)
|
||||
|
||||
RaiseEvent FileLoadProgress(Me, New FileLoadProgressInfo(FilesTotal, FilesLoaded) With {
|
||||
.RunningFunction = "Preis-Funktionen"
|
||||
})
|
||||
|
||||
' These functions will only be applied if the document does not have errors
|
||||
pDocument = Await MaybeApplyPriceFunctions(pDocument, oMandator, pTemplate)
|
||||
|
||||
RaiseEvent FileLoadProgress(Me, New FileLoadProgressInfo(FilesTotal, FilesLoaded) With {
|
||||
.RunningFunction = "Feld-Funktionen"
|
||||
})
|
||||
|
||||
' This function needs to be the last one because
|
||||
' it can relate to any previously set value
|
||||
ApplyFieldFunctionForImport(pDocument, oMandator, pTemplate)
|
||||
@@ -449,7 +486,7 @@ Namespace Documents
|
||||
|
||||
Dim oDocumentKindField As String = oFieldMap.GetOrDefault("DocumentKind", Nothing)
|
||||
Dim oDocumentKind As Integer = 0
|
||||
If Integer.TryParse(pDocument.GetFieldValue(oDocumentKindField), oDocumentKind) Then
|
||||
If Integer.TryParse(pDocument.GetFieldValue(oDocumentKindField), oDocumentKind) = False Then
|
||||
Logger.Warn("Value for parameter DocumentKind could not be parsed. Setting to 0.")
|
||||
End If
|
||||
|
||||
@@ -479,7 +516,7 @@ Namespace Documents
|
||||
oNumberItem.External = oArticleNumber
|
||||
oNumberItem.Final = oArticleNumber
|
||||
Else
|
||||
oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound
|
||||
oNumberItem.Error = FieldError.ArticleNotFound
|
||||
End If
|
||||
End Sub
|
||||
|
||||
@@ -513,7 +550,7 @@ Namespace Documents
|
||||
'})
|
||||
End If
|
||||
Else
|
||||
oNumberItem.Error = DocumentRow.FieldError.AccountNotFound
|
||||
oNumberItem.Error = FieldError.AccountNotFound
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
Namespace Documents
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports MultiTool.Common.Constants
|
||||
|
||||
Namespace Documents
|
||||
Public Class DocumentRow
|
||||
Implements IComparable
|
||||
|
||||
@@ -48,19 +51,45 @@
|
||||
Return SortKey.CompareTo(DirectCast(other, DocumentRow).SortKey)
|
||||
End Function
|
||||
|
||||
Public Enum FieldError
|
||||
None
|
||||
MissingValue
|
||||
AccountNotFound
|
||||
ArticleNotFound
|
||||
End Enum
|
||||
|
||||
Public Class FieldValue
|
||||
Private _Final As String = ""
|
||||
Private _External As String = ""
|
||||
Private _Original As String = ""
|
||||
|
||||
Public Property DataType As Constants.ColumnType = Constants.ColumnType.String
|
||||
Public Property [Error] As FieldError = FieldError.None
|
||||
Public Property Original As String = ""
|
||||
Public Property External As String = ""
|
||||
Public Property Final As String = ""
|
||||
|
||||
Public Sub New()
|
||||
|
||||
End Sub
|
||||
|
||||
Public Property Original As String
|
||||
Get
|
||||
Return FormatValue(_Original, DataType)
|
||||
End Get
|
||||
Set(value As String)
|
||||
_Original = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property External As String
|
||||
Get
|
||||
Return FormatValue(_External, DataType)
|
||||
End Get
|
||||
Set(value As String)
|
||||
_External = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property Final As String
|
||||
Get
|
||||
Return FormatValue(_Final, DataType)
|
||||
End Get
|
||||
Set(value As String)
|
||||
_Final = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property IsRequired As Boolean = False
|
||||
Public Property IsVirtual As Boolean = False
|
||||
Public Property SortKey As Integer = 0
|
||||
@@ -87,6 +116,41 @@
|
||||
Public Overrides Function ToString() As String
|
||||
Return Final
|
||||
End Function
|
||||
|
||||
Private Function FormatValue(pValue As String, pType As Constants.ColumnType) As String
|
||||
Select Case pType
|
||||
Case ColumnType.Decimal
|
||||
Return FormatDecimalValue(pValue)
|
||||
|
||||
Case Else
|
||||
Return pValue
|
||||
End Select
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' This function will capture values like below and format them according to winline format values
|
||||
'''
|
||||
''' 1000
|
||||
''' 1.000.000
|
||||
''' 1.000.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>
|
||||
Private Function FormatDecimalValue(pValue As String) As String
|
||||
If Not pValue.Contains(","c) Then
|
||||
Return pValue
|
||||
End If
|
||||
|
||||
Dim oRegex = New Regex("(?<Value>\d+(?:\.\d+)*(?:,\d+)?)")
|
||||
Dim oMatch = oRegex.Match(pValue)
|
||||
|
||||
If oMatch.Success Then
|
||||
Dim oValue = oMatch.Groups.Item("Value").Value
|
||||
Return oValue.Replace(","c, "."c)
|
||||
Else
|
||||
Return pValue
|
||||
End If
|
||||
End Function
|
||||
End Class
|
||||
End Class
|
||||
|
||||
|
||||
Reference in New Issue
Block a user