Validation and stuff

This commit is contained in:
Jonathan Jenne 2021-11-16 16:16:46 +01:00
parent 964f2ee60c
commit 47c22e9361
13 changed files with 140 additions and 70 deletions

View File

@ -0,0 +1,8 @@
' This file is used by Code Analysis to maintain SuppressMessage
' attributes that are applied to this project.
' Project-level suppressions either have no target or are given
' a specific target and scoped to a namespace, type, member, etc.
Imports System.Diagnostics.CodeAnalysis
<Assembly: SuppressMessage("Style", "IDE1006:Benennungsstile", Justification:="<Ausstehend>", Scope:="member", Target:="~M:MultiTool.Form.frmRowEditor.btnApplyFromWinline_ItemClick(System.Object,DevExpress.XtraBars.ItemClickEventArgs)")>

View File

@ -8,11 +8,8 @@ Imports MultiTool.Shared.Constants
Public Class GridLoader Public Class GridLoader
Inherits BaseClass Inherits BaseClass
Private ReadOnly TemplateConfig As Winline.Configuration
Public Sub New(pLogConfig As LogConfig, pTemplateConfig As Winline.Configuration) Public Sub New(pLogConfig As LogConfig, pTemplateConfig As Winline.Configuration)
MyBase.New(pLogConfig, pLogConfig.GetLogger()) MyBase.New(pLogConfig, pLogConfig.GetLogger())
TemplateConfig = pTemplateConfig
End Sub End Sub
Public Function GetGridFromElement(pGrid As GridControl, pTable As Schemas.Schema.Table) As GridControl Public Function GetGridFromElement(pGrid As GridControl, pTable As Schemas.Schema.Table) As GridControl

View File

@ -181,6 +181,7 @@
<Compile Include="frmRowEditor.vb"> <Compile Include="frmRowEditor.vb">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="GlobalSuppressions.vb" />
<Compile Include="Reports\OrderReport.Designer.vb"> <Compile Include="Reports\OrderReport.Designer.vb">
<DependentUpon>OrderReport.vb</DependentUpon> <DependentUpon>OrderReport.vb</DependentUpon>
</Compile> </Compile>

View File

@ -5,8 +5,7 @@ Imports DigitalData.Modules.Logging
Public Class frmConfig Public Class frmConfig
Public Property ConfigManager As ConfigManager(Of MultiTool.Shared.Config) Public Property ConfigManager As ConfigManager(Of MultiTool.Shared.Config)
Private LogConfig As LogConfig Private ReadOnly FormHelper As FormHelper
Private FormHelper As FormHelper
Private ReadOnly Property Config As MultiTool.Shared.Config Private ReadOnly Property Config As MultiTool.Shared.Config
Get Get
@ -19,14 +18,14 @@ Public Class frmConfig
InitializeComponent() InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
LogConfig = pLogConfig
FormHelper = New FormHelper(pLogConfig) FormHelper = New FormHelper(pLogConfig)
End Sub End Sub
Private Sub frmConfig_Load(sender As Object, e As EventArgs) Handles MyBase.Load Private Sub frmConfig_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim oConnectionString = MSSQLServer.DecryptConnectionString(Config.ConnectionString) Dim oConnectionString = MSSQLServer.DecryptConnectionString(Config.ConnectionString)
Dim oBuilder As New SqlConnectionStringBuilder(oConnectionString) Dim oBuilder As New SqlConnectionStringBuilder(oConnectionString) With {
oBuilder.InitialCatalog = "DD_ECM" .InitialCatalog = "DD_ECM"
}
TBEDI_XML_ITEMSTableAdapter.Connection.ConnectionString = oBuilder.ToString() TBEDI_XML_ITEMSTableAdapter.Connection.ConnectionString = oBuilder.ToString()
TBEDI_XML_ITEMSTableAdapter.Fill(Me.DS_DD_ECM.TBEDI_XML_ITEMS) TBEDI_XML_ITEMSTableAdapter.Fill(Me.DS_DD_ECM.TBEDI_XML_ITEMS)

View File

@ -247,23 +247,25 @@ Public Class frmRowEditor
Private Sub GridView1_CustomDrawCell(sender As Object, e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles GridView1.CustomDrawCell Private Sub GridView1_CustomDrawCell(sender As Object, e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles GridView1.CustomDrawCell
Dim oDataRow As DataRow = GridView1.GetDataRow(e.RowHandle) Dim oDataRow As DataRow = GridView1.GetDataRow(e.RowHandle)
Dim oKey As String = oDataRow.Item(COL_KEY) Dim oKey As String = oDataRow.Item(COL_KEY)
Dim oValue As String = oDataRow.Item(COL_VALUE_FINAL)
If e.Column.FieldName = COL_VALUE_FINAL Then Dim oColumn = _Table.Columns.
Dim oColumn = _Table.Columns.
Where(Function(c) c.Name = oKey). Where(Function(c) c.Name = oKey).
SingleOrDefault() SingleOrDefault()
If e.Column.FieldName = COL_VALUE_FINAL Then
If oColumn Is Nothing Then If oColumn Is Nothing Then
Exit Sub If oColumn.Config?.IsReadOnly Then
End If e.Appearance.BackColor = Color.LightGray
End If
If oColumn.Config?.IsReadOnly Then If oColumn.Config?.IsRequired AndAlso e.CellValue.ToString.Length = 0 Then
e.Appearance.BackColor = Color.LightGray e.Appearance.BackColor = Color.LightCoral
End If
End If End If
End If
If (oColumn.IsRequired Or oColumn.Config?.IsRequired) AndAlso e.CellValue.ToString.Length = 0 Then If oColumn.Config?.IsRequired AndAlso oValue.ToString.Length = 0 Then
e.Appearance.BackColor = Color.LightCoral e.Appearance.BackColor = Color.LightCoral
End If
End If End If
End Sub End Sub
End Class End Class

View File

@ -77,7 +77,7 @@ Namespace Documents
Select(AddressOf WrapFileInfo). Select(AddressOf WrapFileInfo).
Select(Function(d) IncludeSchema(d, pSchema)). Select(Function(d) IncludeSchema(d, pSchema)).
Select(Function(d) LoadDocumentData(d, pSchema)). Select(Function(d) LoadDocumentData(d, pSchema)).
Select(Function(d) MatchDataFromWinLine(d, Winline.Mandators, pMandator)). Select(Function(d) MatchDataFromWinLine(d, Winline.Mandators, pMandator, pSchema)).
SingleOrDefault() SingleOrDefault()
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
@ -145,9 +145,9 @@ Namespace Documents
Where(Function(t) t.Name = oTopLevelElement.Name). Where(Function(t) t.Name = oTopLevelElement.Name).
FirstOrDefault() FirstOrDefault()
' TODO: All fields in the schema should be generated,
' only creating the ones with values leads to wrong visual cues when asking for
' docs/rows/fields with errors
For Each oSubElement As XElement In oSubElements For Each oSubElement As XElement In oSubElements
Dim oSchemaField = oTable.Columns. Dim oSchemaField = oTable.Columns.
@ -167,6 +167,25 @@ Namespace Documents
.Final = oValue, .Final = oValue,
.DataType = oSchemaField.DataType .DataType = oSchemaField.DataType
}) })
Next
' TODO: All fields in the schema should be generated,
' only creating the ones with values leads to wrong visual cues when asking for
' docs/rows/fields with errors
For Each oColumn In oTable.Columns
If oFields.ContainsKey(oColumn.Name) Then
Continue For
End If
Dim oColumnError = DocumentRow.FieldError.None
If oColumn.Config?.IsRequired Then
oColumnError = DocumentRow.FieldError.MissingValue
End If
oFields.Add(oColumn.Name, New DocumentRow.FieldValue With {
.[Error] = oColumnError
})
Next Next
' Create a DocumentRow object for each Top Level Element ' Create a DocumentRow object for each Top Level Element
@ -189,7 +208,7 @@ Namespace Documents
End Function End Function
Private Function MatchDataFromWinLine(pDocument As Document, pMandators As List(Of Mandator), pMandator As Mandator) As Document Private Function MatchDataFromWinLine(pDocument As Document, pMandators As List(Of Mandator), pMandator As Mandator, pSchema As Schema) As Document
Dim oMandators As List(Of Winline.Mandator) = pMandators. Dim oMandators As List(Of Winline.Mandator) = pMandators.
Where(Function(m) m.IsWhitelisted = True). Where(Function(m) m.IsWhitelisted = True).
OrderBy(Function(m) m.Order). OrderBy(Function(m) m.Order).
@ -207,45 +226,77 @@ Namespace Documents
Throw New Exceptions.NoMandatorException($"Mandator not found for file [{pDocument.File.Name}]") Throw New Exceptions.NoMandatorException($"Mandator not found for file [{pDocument.File.Name}]")
End If End If
pDocument = MatchDocumentData(pDocument, oMandator) pDocument = MatchDocumentData(pDocument, oMandator, pSchema)
pDocument.Mandator = oMandator pDocument.Mandator = oMandator
Return pDocument Return pDocument
End Function End Function
Private Function MatchDocumentData(pDocument As Document, pMandator As Winline.Mandator) As Document Private Function MatchDocumentData(pDocument As Document, pMandator As Winline.Mandator, pSchema As Schema) As Document
Dim oYear = Winline.GetWinLineYear() Dim oYear = Winline.GetWinLineYear()
If pMandator Is Nothing Then If pMandator Is Nothing Then
Return pDocument Return pDocument
End If End If
Dim oHead As DocumentRow = pDocument.Rows. For Each oRow As DocumentRow In pDocument.Rows
Where(Function(r) r.Name.ToUpper.EndsWith("T025")). Dim oTable = pSchema.Tables.Where(Function(t) t.Name = oRow.Name).SingleOrDefault()
SetValue(Sub(r As DocumentRow) SetAccountByGLN(r, pMandator, "Fakt_Kontonummer", "Fakt_Name")).
SetValue(Sub(r As DocumentRow) SetAccountByGLN(r, pMandator, "Lief_Kontonummer", "Lief_Name")).
FirstOrDefault()
Dim oPositions As List(Of DocumentRow) = pDocument.Rows. For Each oField In oRow.Fields
Where(Function(r) r.Name.ToUpper.EndsWith("T026")). If oTable Is Nothing Then
SetValue(Sub(oRow As DocumentRow) Exit For
Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault("Artikelnummer") End If
If oNumberItem Is Nothing Then
Exit Sub
End If
Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator) Dim oColumn = oTable.Columns.Where(Function(c) c.Name = oField.Key).SingleOrDefault()
If oArticleNumber IsNot Nothing Then If oColumn Is Nothing Then
oNumberItem.External = oArticleNumber Continue For
oNumberItem.Final = oArticleNumber End If
Else
oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound
End If
End Sub).
ToList()
Dim oList As New List(Of DocumentRow) From {oHead} Dim oFunctionName = oColumn.Config?.Function?.Name
pDocument.Rows = oList.Concat(oPositions).ToList()
If oFunctionName = "GLN" Then
SetAccountByGLN(oRow, pMandator, oField.Key, Nothing)
End If
If oFunctionName = "EAN" Then
Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(oField.Key)
Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator)
If oArticleNumber IsNot Nothing Then
oNumberItem.External = oArticleNumber
oNumberItem.Final = oArticleNumber
Else
oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound
End If
End If
Next
Next
'Dim oHead As DocumentRow = pDocument.Rows.
' Where(Function(r) r.Name.ToUpper.EndsWith("T025")).
' SetValue(Sub(r As DocumentRow) SetAccountByGLN(r, pMandator, "Fakt_Kontonummer", "Fakt_Name")).
' SetValue(Sub(r As DocumentRow) SetAccountByGLN(r, pMandator, "Lief_Kontonummer", "Lief_Name")).
' FirstOrDefault()
'Dim oPositions As List(Of DocumentRow) = pDocument.Rows.
' Where(Function(r) r.Name.ToUpper.EndsWith("T026")).
' SetValue(Sub(oRow As DocumentRow)
' Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault("Artikelnummer")
' If oNumberItem Is Nothing Then
' Exit Sub
' End If
' Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator)
' If oArticleNumber IsNot Nothing Then
' oNumberItem.External = oArticleNumber
' oNumberItem.Final = oArticleNumber
' Else
' oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound
' End If
' End Sub).
' ToList()
'Dim oList As New List(Of DocumentRow) From {oHead}
'pDocument.Rows = oList.Concat(oPositions).ToList()
Return pDocument Return pDocument
End Function End Function
@ -272,10 +323,11 @@ Namespace Documents
oNameItem.External = oAccount.Name oNameItem.External = oAccount.Name
oNameItem.Final = oAccount.Name oNameItem.Final = oAccount.Name
Else Else
oRow.Fields.Add(pNameField, New DocumentRow.FieldValue() With { ' TODO: What to to if name field is missing or not set?
.External = oAccount.Name, 'oRow.Fields.Add(pNameField, New DocumentRow.FieldValue() With {
.Final = oAccount.Name ' .External = oAccount.Name,
}) ' .Final = oAccount.Name
'})
End If End If
Else Else
oNumberItem.Error = DocumentRow.FieldError.AccountNotFound oNumberItem.Error = DocumentRow.FieldError.AccountNotFound

View File

@ -20,6 +20,7 @@
Public Enum FieldError Public Enum FieldError
None None
MissingValue
AccountNotFound AccountNotFound
ArticleNotFound ArticleNotFound
End Enum End Enum

View File

@ -4,6 +4,11 @@ Module IDictionaryEx
<Extension()> <Extension()>
Function GetOrDefault(Of TKey, TValue)(pDictionary As Dictionary(Of TKey, TValue), pKey As TKey, Optional pOnMissing As TValue = Nothing) As TValue Function GetOrDefault(Of TKey, TValue)(pDictionary As Dictionary(Of TKey, TValue), pKey As TKey, Optional pOnMissing As TValue = Nothing) As TValue
Dim oValue As TValue Dim oValue As TValue
If pKey Is Nothing Then
Return Nothing
End If
Return IIf(pDictionary.TryGetValue(pKey, oValue), oValue, pOnMissing) Return IIf(pDictionary.TryGetValue(pKey, oValue), oValue, pOnMissing)
End Function End Function

View File

@ -13,6 +13,9 @@ Namespace Schemas
Class Column Class Column
Public Property Name As String Public Property Name As String
Public Property DataType As Constants.ColumnType Public Property DataType As Constants.ColumnType
''' <summary>
''' Required value from Schema. This value will be written in the ColumnConfig and is not relevant from that point on.
''' </summary>
Public Property IsRequired As Boolean Public Property IsRequired As Boolean
Public Property Config As ColumnConfig Public Property Config As ColumnConfig
End Class End Class

View File

@ -87,6 +87,14 @@ Namespace Schemas
For Each oTable In pSchema.Tables For Each oTable In pSchema.Tables
For Each oColumn As Schema.Column In oTable.Columns For Each oColumn As Schema.Column In oTable.Columns
Dim oConfig = pTemplateConfig.GetColumn(oColumn.Name) Dim oConfig = pTemplateConfig.GetColumn(oColumn.Name)
If oConfig Is Nothing Then
oConfig = New Winline.ColumnConfig With {
.IsRequired = oColumn.IsRequired,
.Name = oColumn.Name
}
End If
oColumn.Config = oConfig oColumn.Config = oConfig
Next Next
Next Next

View File

@ -2,18 +2,18 @@
Namespace Winline Namespace Winline
Public Class ColumnConfig Public Class ColumnConfig
Public Name As String Public Property Name As String
Public Root As String Public Property Root As String
Public Type As ColumnType Public Property Type As ColumnType
Public Template As String Public Property Template As String
Public OrderKey As Integer Public Property OrderKey As Integer
Public IsHead As Boolean Public Property IsHead As Boolean
Public IsReadOnly As Boolean Public Property IsReadOnly As Boolean
Public IsVisible As Boolean Public Property IsVisible As Boolean
Public IsRequired As Boolean Public Property IsRequired As Boolean
Public [Function] As ColumnFunction Public Property [Function] As ColumnFunction
Public Class ColumnFunction Public Class ColumnFunction
Public Id As XmlFunction Public Id As XmlFunction

View File

@ -20,7 +20,6 @@ Namespace Winline
Serializer = New Serializer(pLogConfig) Serializer = New Serializer(pLogConfig)
Config = pConfig Config = pConfig
AppDataPath = pAppDataPath AppDataPath = pAppDataPath
'Mapper = MapperFactory.GetMapper()
End Sub End Sub
Public Async Function TransferDocumentToWinline(pDocument As Document) As Task(Of Boolean) Public Async Function TransferDocumentToWinline(pDocument As Document) As Task(Of Boolean)

View File

@ -1,10 +1,8 @@
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Language Imports DigitalData.Modules.Language
Imports DigitalData.Modules.Database Imports DigitalData.Modules.Database
Imports MultiTool.Shared
Imports System.Text.RegularExpressions Imports System.Text.RegularExpressions
Namespace Winline Namespace Winline
Public Class WinlineData Public Class WinlineData
Inherits BaseClass Inherits BaseClass
@ -20,9 +18,6 @@ Namespace Winline
Public Years As List(Of Integer) Public Years As List(Of Integer)
Public TemplateConfiguration As New Configuration Public TemplateConfiguration As New Configuration
'Public XmlConfigHead As List(Of TemplateColumn)
'Public XmlConfigPositions As List(Of TemplateColumn)
Public Const ALL_MESOCOMP = "mesocomp" Public Const ALL_MESOCOMP = "mesocomp"
Public Const VWEDI_XML_ITEMS = "VWEDI_XML_ITEMS" Public Const VWEDI_XML_ITEMS = "VWEDI_XML_ITEMS"
@ -499,7 +494,7 @@ Namespace Winline
Dim oItems As New List(Of ColumnConfig) Dim oItems As New List(Of ColumnConfig)
For Each oRow As DataRow In oTable.Rows For Each oRow As DataRow In oTable.Rows
Dim oColumn As New ColumnConfig With { Dim oColumn As New ColumnConfig() With {
.Name = GetRowItem(oRow, "XML_NAME", String.Empty), .Name = GetRowItem(oRow, "XML_NAME", String.Empty),
.Root = GetRowItem(oRow, "XML_ROOT", String.Empty), .Root = GetRowItem(oRow, "XML_ROOT", String.Empty),
.Type = ColumnConfig.ConvertType(GetRowItem(oRow, "DATA_TYPE", String.Empty)), .Type = ColumnConfig.ConvertType(GetRowItem(oRow, "DATA_TYPE", String.Empty)),
@ -520,7 +515,7 @@ Namespace Winline
Next Next
Dim oColumns = oItems Dim oColumns = oItems
TemplateConfiguration = New Winline.Configuration With { TemplateConfiguration = New Configuration With {
.Columns = oColumns .Columns = oColumns
} }