This commit is contained in:
Jonathan Jenne
2021-10-18 14:25:51 +02:00
parent b7602d896a
commit 5c58e05204
19 changed files with 630 additions and 124 deletions

View File

@@ -16,8 +16,10 @@ Namespace Winline
Public Mandators As New List(Of Mandator)
Public DocumentKinds As New List(Of DocumentKind)
Public Years As List(Of Integer)
Public XmlConfigHead As List(Of XmlItem)
Public XmlConfigPositions As List(Of XmlItem)
Public TemplateConfiguration As New List(Of TemplateColumn)
'Public XmlConfigHead As List(Of TemplateColumn)
'Public XmlConfigPositions As List(Of TemplateColumn)
Public Const ALL_MESOCOMP = "mesocomp"
@@ -340,39 +342,47 @@ Namespace Winline
End Try
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).
Public Function FindMatchingMandatorFromOrder(pData As Documents.Document) As Mandator
Dim oPositions = pData.Rows.
Where(Function(r) r.Name.ToUpper.EndsWith("T026")).
ToList()
Dim oEANNumbers = oPositions.
Select(Function(p) p.Fields.Item("Artikelnummer").Original).
Distinct().
ToList()
'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 oEANNumber In oEANNumbers
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}"
SELECT
[c011], -- Artikelnummer
[c003], -- Artikelbezeichnung
[c075], -- EAN-Nummer
[c123] -- Ersatzartikelnummer
FROM [{oMandator.Database}].[dbo].[v021]
WHERE [c075] = '{oEANNumber}'
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)
Logger.Debug("EAN [{0}] was not found in Mandator: [{1}]", oEANNumber, 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)
Logger.Warn("EAN [{0}] was found more than once. Skipping Mandator [{1}]", oEANNumber, oMandator.Id)
Exit For
End If
@@ -413,23 +423,107 @@ Namespace Winline
End If
End Function
Public Sub GetXmlConfiguration()
'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
Try
Dim oSql = $"SELECT XML_NAME, XML_ROOT, DATA_TYPE, IS_HEAD FROM [DD_ECM].[dbo].[VWEDI_XML_ITEMS]"
Dim oSql = $"SELECT XML_NAME, XML_ROOT, TEMPLATE_NAME, DATA_TYPE, IS_HEAD, FUNCTION_ID, READ_ONLY FROM [DD_ECM].[dbo].[VWEDI_XML_ITEMS]"
Dim oTable As DataTable = Database.GetDatatable(oSql)
Dim oItems As New List(Of TemplateColumn)
For Each oRow As DataRow In oTable.Rows
Dim oXmlItem As New XmlItem With {
Dim oColumn As New TemplateColumn With {
.Name = oRow.Item("XML_NAME"),
.Root = oRow.Item("XML_ROOT"),
.Type = oRow.Item("XML_TYPE")
.Type = oRow.Item("XML_TYPE"),
.Template = oRow.Item("TEMPLATE_NAME"),
.[Function] = oRow.Item("FUNCTION_ID"),
.[ReadOnly] = oRow.Item("READ_ONLY")
}
oItems.Add(oColumn)
Next
TemplateConfiguration = oItems
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Sub
End Function
''' <summary>
''' Turns a database info like "SQLCWLDATEN on SERVER\INSTANCE" into a Tuple of two strings

View File

@@ -1,9 +1,12 @@
Namespace Winline
Public Class XmlItem
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 [Function] As Constants.XmlFunction
End Class
End Namespace