Imports System.IO
Imports MultiTool.Common.Constants
Imports MultiTool.Common.Templates
Imports MultiTool.Common.Winline.Entities
Namespace Documents
Public Class Document
Public File As FileInfo
Public Schema As Template
Public Mandator As Mandator
Public TemplateName As String
Public Property TemplateType As Integer
Public [Option] As Integer
Public PrintVoucher As Integer
'''
''' Original Values, read-only
'''
Public Property Rows As New List(Of DocumentRow)
Public Property Imported As Boolean = False
'''
''' This is used for saving the selected state via checkbox, don't remove!
'''
Public Property Selected As Boolean = False
Private DocumentErrors As New List(Of DocumentError)
Public ReadOnly Property HasErrors As Boolean
Get
Return Errors.Count > 0
End Get
End Property
Public ReadOnly Property Errors As List(Of String)
Get
Dim oRowErrors = Rows.
SelectMany(Function(row) row.Errors, Function(row, err) err.ToString).
ToList()
Dim oDocumentErrors As List(Of String) = DocumentErrors.
Select(Function(err) err.ToString()).
ToList()
Return oDocumentErrors.
Concat(oRowErrors).
ToList()
End Get
End Property
Public Sub AddDocumentError(pDocumentError As DocumentErrorType, pMessage As String)
DocumentErrors.Add(New DocumentError With {
.Type = pDocumentError,
.Message = pMessage
})
End Sub
Public ReadOnly Property MandatorId As String
Get
Return Mandator?.Id
End Get
End Property
Public ReadOnly Property CreatedAt As Date
Get
Return File?.CreationTime
End Get
End Property
Public ReadOnly Property FullName As String
Get
Return File?.FullName
End Get
End Property
Public ReadOnly Property FileName As String
Get
Return File?.Name
End Get
End Property
'''
''' Finds the first occurrence of Field and returns its value
'''
Public Function GetFieldValue(pField As String) As String
For Each oRow In Rows
For Each oField In oRow.Fields
If oField.Key = pField Then
Return oField.Value.Final
End If
Next
Next
Return Nothing
End Function
Public Overrides Function Equals(obj As Object) As Boolean
If obj Is Nothing Then
Return False
End If
Return FullName = DirectCast(obj, Document).FullName
End Function
End Class
End Namespace