First Version with Template Config from Database
This commit is contained in:
@@ -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