First Version with Template Config from Database
This commit is contained in:
@@ -2,10 +2,21 @@
|
||||
Public Const COLUMN_GUID = "GUID"
|
||||
|
||||
Public Enum XmlFunction
|
||||
None = 0
|
||||
GLN = 1
|
||||
EAN = 2
|
||||
End Enum
|
||||
|
||||
Public Const SCHEMA_TYPE_DATE = "xs:date"
|
||||
Public Const SCHEMA_TYPE_INTEGER = "xs:integer"
|
||||
Public Const SCHEMA_TYPE_DECIMAL = "xs:decimal"
|
||||
Public Const SCHEMA_TYPE_BOOLEAN = "xs:boolean"
|
||||
|
||||
Public Const DB_TYPE_DATE = "DATE"
|
||||
Public Const DB_TYPE_INTEGER = "INTEGER"
|
||||
Public Const DB_TYPE_DECIMAL = "DECIMAL"
|
||||
Public Const DB_TYPE_BOOLEAN = "BOOLEAN"
|
||||
|
||||
Public Enum ColumnType As Integer
|
||||
[String]
|
||||
[Integer]
|
||||
|
||||
@@ -141,7 +141,7 @@
|
||||
<Compile Include="Winline\Entities\Contact.vb" />
|
||||
<Compile Include="Winline\Entities\DocumentKind.vb" />
|
||||
<Compile Include="Winline\Entities\Mandator.vb" />
|
||||
<Compile Include="Winline\Entities\TemplateColumn.vb" />
|
||||
<Compile Include="Winline\Entities\ColumnConfig.vb" />
|
||||
<Compile Include="Winline\WebService.vb" />
|
||||
<Compile Include="XmlData.vb" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
Namespace Schemas
|
||||
Imports MultiTool.Shared.Winline
|
||||
|
||||
Namespace Schemas
|
||||
Public Class Schema
|
||||
Public Property Tables As New List(Of Table)
|
||||
Public Property Name As String
|
||||
@@ -10,8 +12,9 @@
|
||||
|
||||
Class Column
|
||||
Public Property Name As String
|
||||
Public Property Required As String
|
||||
Public Property DataType As Constants.ColumnType
|
||||
Public Property IsRequired As Boolean
|
||||
Public Property Config As ColumnConfig
|
||||
End Class
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
@@ -63,8 +63,8 @@ Namespace Schemas
|
||||
|
||||
Dim oSchemaColumn As New Schema.Column With {
|
||||
.Name = oName,
|
||||
.Required = oRequired,
|
||||
.DataType = oType
|
||||
.DataType = oType,
|
||||
.IsRequired = oRequired
|
||||
}
|
||||
oSchemaColumns.Add(oSchemaColumn)
|
||||
Next
|
||||
@@ -79,6 +79,21 @@ Namespace Schemas
|
||||
Return oSchema
|
||||
End Function
|
||||
|
||||
Public Function UpdateSchemaWithDatabaseConfiguration(pSchema As Schema, pTemplateConfig As Winline.Configuration) As Schema
|
||||
If pTemplateConfig Is Nothing Then
|
||||
Return pSchema
|
||||
End If
|
||||
|
||||
For Each oTable In pSchema.Tables
|
||||
For Each oColumn As Schema.Column In oTable.Columns
|
||||
Dim oConfig = pTemplateConfig.GetColumn(oColumn.Name)
|
||||
oColumn.Config = oConfig
|
||||
Next
|
||||
Next
|
||||
|
||||
Return pSchema
|
||||
End Function
|
||||
|
||||
Public Function GetElementType(pElement As XElement) As Constants.ColumnType
|
||||
Dim oTypeString = XmlData.GetElementAttribute(pElement, "type")
|
||||
|
||||
@@ -91,13 +106,13 @@ Namespace Schemas
|
||||
End If
|
||||
|
||||
Select Case oTypeString
|
||||
Case "xs:date"
|
||||
Case Constants.SCHEMA_TYPE_DATE
|
||||
Return Constants.ColumnType.Date
|
||||
Case "xs:integer"
|
||||
Case Constants.SCHEMA_TYPE_INTEGER
|
||||
Return Constants.ColumnType.Integer
|
||||
Case "xs:decimal"
|
||||
Case Constants.SCHEMA_TYPE_DECIMAL
|
||||
Return Constants.ColumnType.Decimal
|
||||
Case "xs:boolean"
|
||||
Case Constants.SCHEMA_TYPE_BOOLEAN
|
||||
Return Constants.ColumnType.Boolean
|
||||
Case Else
|
||||
Return Constants.ColumnType.String
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
|
||||
''' <summary>
|
||||
''' Class for loading column/field config from database
|
||||
''' </summary>
|
||||
Public Class Configuration
|
||||
Namespace Winline
|
||||
''' <summary>
|
||||
''' Class for loading column/field config from database
|
||||
''' </summary>
|
||||
Public Class Configuration
|
||||
Public Columns As List(Of Winline.ColumnConfig)
|
||||
|
||||
End Class
|
||||
Public Function GetColumn(pName As String) As ColumnConfig
|
||||
Return Columns.
|
||||
Where(Function(c) c.Name = pName).
|
||||
FirstOrDefault()
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
45
MultiTool.Shared/Winline/Entities/ColumnConfig.vb
Normal file
45
MultiTool.Shared/Winline/Entities/ColumnConfig.vb
Normal file
@@ -0,0 +1,45 @@
|
||||
Imports MultiTool.Shared.Constants
|
||||
|
||||
Namespace Winline
|
||||
Public Class ColumnConfig
|
||||
Public Name As String
|
||||
Public Root As String
|
||||
Public Type As ColumnType
|
||||
Public Template As String
|
||||
Public OrderKey As Integer
|
||||
|
||||
Public IsHead As Boolean
|
||||
Public IsReadOnly As Boolean
|
||||
Public IsVisible As Boolean
|
||||
Public IsRequired As Boolean
|
||||
|
||||
Public [Function] As ColumnFunction
|
||||
|
||||
Public Class ColumnFunction
|
||||
Public Id As XmlFunction
|
||||
Public Name As String
|
||||
Public Params As String
|
||||
End Class
|
||||
|
||||
Public Shared Function ConvertType(pType As String) As ColumnType
|
||||
Select Case pType
|
||||
Case DB_TYPE_DATE
|
||||
Return ColumnType.Date
|
||||
|
||||
Case DB_TYPE_DECIMAL
|
||||
Return ColumnType.Date
|
||||
|
||||
Case DB_TYPE_BOOLEAN
|
||||
Return ColumnType.Boolean
|
||||
|
||||
Case DB_TYPE_INTEGER
|
||||
Return ColumnType.Integer
|
||||
|
||||
Case Else
|
||||
Return ColumnType.String
|
||||
End Select
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -1,13 +0,0 @@
|
||||
Namespace Winline
|
||||
Public Class TemplateColumn
|
||||
Public Name As String
|
||||
Public Root As String
|
||||
Public Type As String
|
||||
Public IsHead As Boolean
|
||||
Public Template As String
|
||||
Public [ReadOnly] As Boolean
|
||||
Public Visible As Boolean
|
||||
Public [Function] As Constants.XmlFunction
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -18,13 +18,15 @@ Namespace Winline
|
||||
Public DocumentKinds As New List(Of DocumentKind)
|
||||
|
||||
Public Years As List(Of Integer)
|
||||
Public TemplateConfiguration As New List(Of TemplateColumn)
|
||||
Public TemplateConfiguration As New Configuration
|
||||
|
||||
'Public XmlConfigHead As List(Of TemplateColumn)
|
||||
'Public XmlConfigPositions As List(Of TemplateColumn)
|
||||
|
||||
Public Const ALL_MESOCOMP = "mesocomp"
|
||||
|
||||
Public Const VWEDI_XML_ITEMS = "VWEDI_XML_ITEMS"
|
||||
|
||||
Public Const V21_ARTICLENUMBER = "c002"
|
||||
Public Const V21_ARTICLEDESCRIPTION = "c003"
|
||||
Public Const V21_MAINARTICLENUMBER = "c011"
|
||||
@@ -87,9 +89,9 @@ Namespace Winline
|
||||
Dim oArticles As New List(Of Article)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oArticleId As String = Utils.NotNull(oRow.Item(V21_ARTICLENUMBER), String.Empty)
|
||||
Dim oArticleDescription As String = Utils.NotNull(oRow.Item(V21_ARTICLEDESCRIPTION), String.Empty)
|
||||
Dim oEAN As String = Utils.NotNull(oRow.Item(V21_EAN), String.Empty)
|
||||
Dim oArticleId As String = GetRowItem(oRow, V21_ARTICLENUMBER, String.Empty)
|
||||
Dim oArticleDescription As String = GetRowItem(oRow, V21_ARTICLEDESCRIPTION, String.Empty)
|
||||
Dim oEAN As String = GetRowItem(oRow, V21_EAN, String.Empty)
|
||||
|
||||
oArticles.Add(New Article With {
|
||||
.Id = oArticleId,
|
||||
@@ -129,12 +131,12 @@ Namespace Winline
|
||||
Dim oAccounts As New List(Of Account)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oAccountNumber As String = Utils.NotNull(oRow.Item(V50_ACCOUNTNUMBER), String.Empty)
|
||||
Dim oAccountName As String = Utils.NotNull(oRow.Item(V50_ACCOUNTNAME), String.Empty)
|
||||
Dim oStreetName As String = Utils.NotNull(oRow.Item(V50_STREETNAME), String.Empty)
|
||||
Dim oZipCode As String = Utils.NotNull(oRow.Item(V50_ZIPCODE), String.Empty)
|
||||
Dim oCityName As String = Utils.NotNull(oRow.Item(V50_CITYNAME), String.Empty)
|
||||
Dim oGLN As String = Utils.NotNull(oRow.Item(V50_GLN), String.Empty)
|
||||
Dim oAccountNumber As String = GetRowItem(oRow, V50_ACCOUNTNUMBER, String.Empty)
|
||||
Dim oAccountName As String = GetRowItem(oRow, V50_ACCOUNTNAME, String.Empty)
|
||||
Dim oStreetName As String = GetRowItem(oRow, V50_STREETNAME, String.Empty)
|
||||
Dim oZipCode As String = GetRowItem(oRow, V50_ZIPCODE, String.Empty)
|
||||
Dim oCityName As String = GetRowItem(oRow, V50_CITYNAME, String.Empty)
|
||||
Dim oGLN As String = GetRowItem(oRow, V50_GLN, String.Empty)
|
||||
|
||||
oAccounts.Add(New Account With {
|
||||
.Id = oAccountNumber,
|
||||
@@ -164,8 +166,8 @@ Namespace Winline
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oDbInfo = SplitConnectionInfo(oRow)
|
||||
Dim oMandator = New Mandator With {
|
||||
.Id = oRow.Item(T01_MANDATORID),
|
||||
.Name = oRow.Item(T01_MANDATORNAME),
|
||||
.Id = GetRowItem(oRow, T01_MANDATORID, String.Empty),
|
||||
.Name = GetRowItem(oRow, T01_MANDATORNAME, String.Empty),
|
||||
.Database = oDbInfo.Item1,
|
||||
.Server = oDbInfo.Item2
|
||||
}
|
||||
@@ -218,8 +220,8 @@ Namespace Winline
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
oKinds.Add(New DocumentKind With {
|
||||
.Id = oRow.Item(T357_KINDID),
|
||||
.Name = oRow.Item(T357_KINDNAME),
|
||||
.Id = GetRowItem(oRow, T357_KINDID, String.Empty),
|
||||
.Name = GetRowItem(oRow, T357_KINDNAME, String.Empty),
|
||||
.Mandator = pMandator
|
||||
})
|
||||
Next
|
||||
@@ -268,11 +270,11 @@ Namespace Winline
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oAccountNumber As String = Utils.NotNull(oRow.Item(V50_ACCOUNTNUMBER), String.Empty)
|
||||
Dim oAccountName As String = Utils.NotNull(oRow.Item(V50_ACCOUNTNAME), String.Empty)
|
||||
Dim oStreetName As String = Utils.NotNull(oRow.Item(V50_STREETNAME), String.Empty)
|
||||
Dim oZipCode As String = Utils.NotNull(oRow.Item(V50_ZIPCODE), String.Empty)
|
||||
Dim oCityName As String = Utils.NotNull(oRow.Item(V50_CITYNAME), String.Empty)
|
||||
Dim oAccountNumber As String = GetRowItem(oRow, V50_ACCOUNTNUMBER, String.Empty)
|
||||
Dim oAccountName As String = GetRowItem(oRow, V50_ACCOUNTNAME, String.Empty)
|
||||
Dim oStreetName As String = GetRowItem(oRow, V50_STREETNAME, String.Empty)
|
||||
Dim oZipCode As String = GetRowItem(oRow, V50_ZIPCODE, String.Empty)
|
||||
Dim oCityName As String = GetRowItem(oRow, V50_CITYNAME, String.Empty)
|
||||
|
||||
Return New Account With {
|
||||
.Id = oAccountNumber,
|
||||
@@ -318,7 +320,7 @@ Namespace Winline
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oArticleNumber As String = Utils.NotNull(oRow.Item(V21_MAINARTICLENUMBER), String.Empty)
|
||||
Dim oArticleNumber As String = GetRowItem(oRow, V21_MAINARTICLENUMBER, String.Empty)
|
||||
Return oArticleNumber
|
||||
|
||||
Catch ex As Exception
|
||||
@@ -351,9 +353,9 @@ Namespace Winline
|
||||
|
||||
For Each oRow In oTable.Rows
|
||||
oContacts.Add(New Contact With {
|
||||
.Id = Utils.NotNull(oRow.Item(T45_KEY), Nothing),
|
||||
.Name = Utils.NotNull(oRow.Item(T45_NAME), Nothing),
|
||||
.Number = Utils.NotNull(oRow.Item(T45_CONTACTNUMBER), Nothing)
|
||||
.Id = GetRowItem(Of String)(oRow, T45_KEY, Nothing),
|
||||
.Name = GetRowItem(Of String)(oRow, T45_NAME, Nothing),
|
||||
.Number = GetRowItem(Of String)(oRow, T45_CONTACTNUMBER, Nothing)
|
||||
})
|
||||
Next
|
||||
|
||||
@@ -393,7 +395,7 @@ Namespace Winline
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oReplacementArticleNumber = Utils.NotNull(oRow.Item(V21_REPLACEMENTARTICLENUMBER), Nothing)
|
||||
Dim oReplacementArticleNumber = GetRowItem(Of String)(oRow, V21_REPLACEMENTARTICLENUMBER, Nothing)
|
||||
|
||||
If oReplacementArticleNumber Is Nothing Then
|
||||
Return pArticleNumber
|
||||
@@ -454,7 +456,7 @@ Namespace Winline
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oArticleNumber As String = Utils.NotNull(oRow.Item(V21_MAINARTICLENUMBER), String.Empty)
|
||||
Dim oArticleNumber As String = GetRowItem(oRow, V21_MAINARTICLENUMBER, String.Empty)
|
||||
|
||||
' EAN was found, now we need to check it against the Regex of the current Mandantor, if one exists
|
||||
If oMandator.Regex <> String.Empty Then
|
||||
@@ -490,100 +492,38 @@ Namespace Winline
|
||||
End If
|
||||
End Function
|
||||
|
||||
'Public Function FindMatchingMandatorFromOrder(pData As Schemas.Orders.Input.MESOWebService) As Mandator
|
||||
' Dim oPositions As List(Of Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT026) = pData.Items.
|
||||
' Where(Function(i) TypeOf i Is Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT026).
|
||||
' Select(Of Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT026)(Function(i) i).
|
||||
' ToList()
|
||||
' Dim oYear = GetWinLineYear()
|
||||
' Dim oMandatorId As String = String.Empty
|
||||
' Dim oWhitelistedMandators = Mandators.
|
||||
' Where(Function(m) m.IsWhitelisted = True).
|
||||
' ToList()
|
||||
|
||||
' For Each oPos In oPositions
|
||||
' For Each oMandator In oWhitelistedMandators
|
||||
' Dim oSQL As String = $"
|
||||
' SELECT
|
||||
' [c011], -- Artikelnummer
|
||||
' [c003], -- Artikelbezeichnung
|
||||
' [c075], -- EAN-Nummer
|
||||
' [c123] -- Ersatzartikelnummer
|
||||
' FROM [{oMandator.Database}].[dbo].[v021]
|
||||
' WHERE [c075] = '{oPos.Artikelnummer}'
|
||||
' AND [mesocomp] = '{oMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
' Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
' ' EAN not found in this Mandator, continue to next one
|
||||
' If oTable.Rows.Count = 0 Then
|
||||
' Logger.Debug("EAN [{0}] was not found in Mandator: [{1}]", oPos.Artikelnummer, oMandator.Id)
|
||||
' Continue For
|
||||
' End If
|
||||
|
||||
' ' Duplicate EAN, exit and do nothing about this manda
|
||||
' If oTable.Rows.Count > 1 Then
|
||||
' Logger.Warn("EAN [{0}] was found more than once. Skipping Mandator [{1}]", oPos.Artikelnummer, oMandator.Id)
|
||||
' Exit For
|
||||
' End If
|
||||
|
||||
' Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
' Dim oArticleNumber As String = Utils.NotNull(oRow.Item(V21_ARTICLENUMBER), String.Empty)
|
||||
|
||||
' ' EAN was found, now we need to check it against the Regex of the current Mandantor, if one exists
|
||||
' If oMandator.Regex <> String.Empty Then
|
||||
' Try
|
||||
' Dim oRegex As New Regex(oMandator.Regex)
|
||||
' Dim oMatch = oRegex.Match(oArticleNumber)
|
||||
|
||||
' ' If ArticleNumber matches the regex, we assign it and exit
|
||||
' If oMatch.Success Then
|
||||
' oMandatorId = oMandator.Id
|
||||
' Exit For
|
||||
' Else
|
||||
' ' If it does not match, continue to the next mandator
|
||||
' End If
|
||||
' Catch ex As Exception
|
||||
' Logger.Error(ex)
|
||||
' Logger.Warn("Regex [{0}] could not be parsed. Skipping.", oMandator.Regex)
|
||||
' End Try
|
||||
' Else
|
||||
' ' If no regex was found, we assume the number matches
|
||||
' oMandatorId = oMandator.Id
|
||||
' End If
|
||||
' Next
|
||||
' Next
|
||||
|
||||
' If oMandatorId = String.Empty Then
|
||||
' Return Nothing
|
||||
' Else
|
||||
' Return oWhitelistedMandators.
|
||||
' Where(Function(m) m.Id = oMandatorId).
|
||||
' Take(1).
|
||||
' SingleOrDefault()
|
||||
' End If
|
||||
'End Function
|
||||
|
||||
Public Function LoadTemplateConfiguration() As Boolean
|
||||
Public Async Function LoadTemplateConfiguration() As Task(Of Boolean)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[VWEDI_XML_ITEMS]"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSql)
|
||||
Dim oItems As New List(Of TemplateColumn)
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{VWEDI_XML_ITEMS}]"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oItems As New List(Of ColumnConfig)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oColumn As New TemplateColumn With {
|
||||
.Name = oRow.Item("XML_NAME"),
|
||||
.Root = oRow.Item("XML_ROOT"),
|
||||
.Type = oRow.Item("XML_TYPE"),
|
||||
.Template = oRow.Item("TEMPLATE_NAME"),
|
||||
.[Function] = oRow.Item("FUNCTION_ID"),
|
||||
.[ReadOnly] = oRow.Item("IS_READ_ONLY"),
|
||||
.[Visible] = oRow.Item("IS_VISIBLE")
|
||||
Dim oColumn As New ColumnConfig With {
|
||||
.Name = GetRowItem(oRow, "XML_NAME", String.Empty),
|
||||
.Root = GetRowItem(oRow, "XML_ROOT", String.Empty),
|
||||
.Type = ColumnConfig.ConvertType(GetRowItem(oRow, "DATA_TYPE", String.Empty)),
|
||||
.Template = GetRowItem(oRow, "TEMPLATE_NAME", String.Empty),
|
||||
.[Function] = New ColumnConfig.ColumnFunction With {
|
||||
.Id = GetRowItem(oRow, "FUNCTION_ID", 0),
|
||||
.Name = GetRowItem(oRow, "FUNCTION_NAME", String.Empty),
|
||||
.Params = GetRowItem(oRow, "FUNCTION_PARAMETERS", String.Empty)
|
||||
},
|
||||
.OrderKey = GetRowItem(oRow, "ORDER_KEY", 0),
|
||||
.IsReadOnly = GetRowItem(oRow, "IS_READ_ONLY", False),
|
||||
.IsVisible = GetRowItem(oRow, "IS_VISIBLE", True),
|
||||
.IsRequired = GetRowItem(oRow, "IS_REQUIRED", False),
|
||||
.IsHead = GetRowItem(oRow, "IS_HEAD", True)
|
||||
}
|
||||
|
||||
oItems.Add(oColumn)
|
||||
Next
|
||||
|
||||
TemplateConfiguration = oItems
|
||||
Dim oColumns = oItems
|
||||
TemplateConfiguration = New Winline.Configuration With {
|
||||
.Columns = oColumns
|
||||
}
|
||||
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
@@ -619,5 +559,12 @@ Namespace Winline
|
||||
End Function
|
||||
|
||||
|
||||
Private Function GetRowItem(Of T)(pRow As DataRow, pFieldName As String, Optional pDefaultValue As T = Nothing) As T
|
||||
Try
|
||||
Return Utils.NotNull(pRow.Item(pFieldName), pDefaultValue)
|
||||
Catch ex As Exception
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
Reference in New Issue
Block a user