WIP
This commit is contained in:
6
ImporterShared/Constants.vb
Normal file
6
ImporterShared/Constants.vb
Normal file
@@ -0,0 +1,6 @@
|
||||
Public Class Constants
|
||||
Public Enum XmlFunction
|
||||
GLN = 1
|
||||
EAN = 2
|
||||
End Enum
|
||||
End Class
|
||||
@@ -7,11 +7,22 @@ Namespace Documents
|
||||
Public Type As DocumentType
|
||||
Public Selected As Boolean = False
|
||||
|
||||
''' <summary>
|
||||
''' TODO: Set before submitting to web services
|
||||
''' </summary>
|
||||
Public CreatedAt As Date
|
||||
|
||||
|
||||
Public TemplateName As String
|
||||
Public TemplateType As Integer
|
||||
Public [Option] As Integer
|
||||
Public PrintVoucher As Integer
|
||||
|
||||
''' <summary>
|
||||
''' Original Values, read-only
|
||||
''' </summary>
|
||||
Public Property Rows As New List(Of DocumentRow)
|
||||
|
||||
Public ReadOnly Property FullName As String
|
||||
Get
|
||||
Return File?.FullName
|
||||
@@ -24,7 +35,6 @@ Namespace Documents
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Rows As New List(Of DocumentRow)
|
||||
|
||||
' Public Type As DocumentType
|
||||
' Public Data As Object
|
||||
|
||||
@@ -18,6 +18,7 @@ Namespace Documents
|
||||
|
||||
Public Files As New List(Of Document)
|
||||
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pWinline As Winline.Data)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger())
|
||||
Winline = pWinline
|
||||
@@ -40,6 +41,7 @@ Namespace Documents
|
||||
Files = oFiles.
|
||||
Select(AddressOf WrapFileInfo).
|
||||
Select(AddressOf LoadDocumentData2).
|
||||
Select(Function(d) MatchDataFromWinLine(d, Winline.Mandators)).
|
||||
ToList()
|
||||
|
||||
Return True
|
||||
@@ -67,12 +69,15 @@ Namespace Documents
|
||||
Dim oRows As New List(Of DocumentRow)
|
||||
|
||||
For Each oElement As XElement In oRowElements
|
||||
Dim oFields As New Dictionary(Of String, String)
|
||||
Dim oFields As New Dictionary(Of String, DocumentRow.FieldValue)
|
||||
|
||||
Dim oSubElements = oElement.Descendants().ToList()
|
||||
|
||||
For Each oSubElement As XElement In oSubElements
|
||||
oFields.Add(oSubElement.Name.ToString, oSubElement.Value)
|
||||
oFields.Add(oSubElement.Name.ToString, New DocumentRow.FieldValue With {
|
||||
.Original = oSubElement.Value,
|
||||
.Final = oSubElement.Value
|
||||
})
|
||||
Next
|
||||
|
||||
Dim oRow = New DocumentRow With {
|
||||
@@ -91,68 +96,104 @@ Namespace Documents
|
||||
|
||||
Return pDocument
|
||||
End Function
|
||||
'Private Function MatchDataFromWinLine(pDocument As Document, pMandators As List(Of Winline.Mandator)) As Document
|
||||
' Dim oMandators As List(Of Winline.Mandator) = pMandators.
|
||||
' Where(Function(m) m.IsWhitelisted = True).
|
||||
' OrderBy(Function(m) m.Order).
|
||||
' ToList()
|
||||
|
||||
' If TypeOf pDocument.Data Is Schemas.Orders.Input.MESOWebService Then
|
||||
' Dim oMandator = Winline.FindMatchingMandatorFromOrder(pDocument.Data)
|
||||
' Dim oData As Schemas.Orders.Input.MESOWebService = MatchOrderData(pDocument.Data, oMandator)
|
||||
|
||||
' If oMandator Is Nothing Then
|
||||
' Logger.Warn("Mandator not found for File [{0}]", pDocument.File.Name)
|
||||
' End If
|
||||
Private Function MatchDataFromWinLine(pDocument As Document, pMandators As List(Of Winline.Mandator)) As Document
|
||||
Dim oMandators As List(Of Winline.Mandator) = pMandators.
|
||||
Where(Function(m) m.IsWhitelisted = True).
|
||||
OrderBy(Function(m) m.Order).
|
||||
ToList()
|
||||
|
||||
' pDocument.Mandator = oMandator.Id
|
||||
' pDocument.Data = oData
|
||||
' End If
|
||||
Dim oMandator = Winline.FindMatchingMandatorFromOrder(pDocument)
|
||||
|
||||
' Return pDocument
|
||||
'End Function
|
||||
If oMandator Is Nothing Then
|
||||
Logger.Warn("Mandator not found for File [{0}]", pDocument.File.Name)
|
||||
End If
|
||||
|
||||
Private Function MatchOrderData(pData As Input.MESOWebService, pMandator As Winline.Mandator) As Input.MESOWebService
|
||||
pDocument = MatchOrderData(pDocument, oMandator)
|
||||
pDocument.Mandator = oMandator.Id
|
||||
|
||||
|
||||
'If TypeOf pDocument.Data Is Schemas.Orders.Input.MESOWebService Then
|
||||
' Dim oMandator = Winline.FindMatchingMandatorFromOrder(pDocument.Data)
|
||||
' Dim oData As Schemas.Orders.Input.MESOWebService = MatchOrderData(pDocument.Data, oMandator)
|
||||
|
||||
' If oMandator Is Nothing Then
|
||||
' Logger.Warn("Mandator not found for File [{0}]", pDocument.File.Name)
|
||||
' End If
|
||||
|
||||
' pDocument.Mandator = oMandator.Id
|
||||
' pDocument.Data = oData
|
||||
'End If
|
||||
|
||||
Return pDocument
|
||||
End Function
|
||||
|
||||
Private Function MatchOrderData(pDocument As Document, pMandator As Winline.Mandator) As Document
|
||||
Dim oYear = Winline.GetWinLineYear()
|
||||
|
||||
If pMandator Is Nothing Then
|
||||
Return pData
|
||||
Return pDocument
|
||||
End If
|
||||
|
||||
Dim oHead As Input.MESOWebServiceEXIMVRG_ordersT025 = pData.Items.
|
||||
Where(Function(h) TypeOf h Is Input.MESOWebServiceEXIMVRG_ordersT025).
|
||||
SetValue(Sub(h As Input.MESOWebServiceEXIMVRG_ordersT025)
|
||||
Dim oAccount = Winline.TryGetAccount(h.Fakt_Kontonummer, pMandator)
|
||||
Dim oHead As DocumentRow = pDocument.Rows.
|
||||
Where(Function(r) r.Name.ToUpper.EndsWith("T025")).
|
||||
SetValue(Sub(r As DocumentRow)
|
||||
Dim oAccountNumberItem = IIf(r.Fields.ContainsKey("Fakt_Kontonummer"), r.Fields.Item("Fakt_Kontonummer"), Nothing)
|
||||
|
||||
Dim oAccountNameItem = Nothing
|
||||
If r.Fields.ContainsKey("Fakt_Name") Then
|
||||
oAccountNameItem = r.Fields.Item("Fakt_Name")
|
||||
End If
|
||||
|
||||
Dim oAccount = Winline.TryGetAccount(oAccountNumberItem.Original, pMandator)
|
||||
If oAccount IsNot Nothing Then
|
||||
h.Fakt_Kontonummer = oAccount.Id
|
||||
h.Fakt_Name = oAccount.Name
|
||||
oAccountNumberItem.External = oAccount.Id
|
||||
|
||||
If r.Fields.ContainsKey("Fakt_Name") Then
|
||||
oAccountNameItem.External = oAccount.Name
|
||||
End If
|
||||
End If
|
||||
End Sub).
|
||||
SetValue(Sub(h As Input.MESOWebServiceEXIMVRG_ordersT025)
|
||||
Dim oAccount = Winline.TryGetAccount(h.Lief_Kontonummer, pMandator)
|
||||
SetValue(Sub(r As DocumentRow)
|
||||
Dim oAccountNumberItem = Nothing
|
||||
If r.Fields.ContainsKey("Lief_Kontonummer") Then
|
||||
oAccountNumberItem = r.Fields.Item("Lief_Kontonummer")
|
||||
Else
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oAccountNameItem = Nothing
|
||||
If r.Fields.ContainsKey("Lief_Name") Then
|
||||
oAccountNameItem = r.Fields.Item("Lief_Name")
|
||||
End If
|
||||
|
||||
Dim oAccount = Winline.TryGetAccount(oAccountNumberItem.Original, pMandator)
|
||||
If oAccount IsNot Nothing Then
|
||||
h.Lief_Kontonummer = oAccount.Id
|
||||
h.Lief_Name = oAccount.Name
|
||||
oAccountNumberItem.External = oAccount.Id
|
||||
|
||||
If r.Fields.ContainsKey("Lief_Name") Then
|
||||
oAccountNameItem.External = oAccount.Name
|
||||
End If
|
||||
End If
|
||||
End Sub).
|
||||
FirstOrDefault()
|
||||
|
||||
Dim oPositions As List(Of Input.MESOWebServiceEXIMVRG_ordersT026) = pData.Items.
|
||||
Where(Function(p) TypeOf p Is Input.MESOWebServiceEXIMVRG_ordersT026).
|
||||
SetValue(Sub(p)
|
||||
Dim oArticleNumber = Winline.TryGetArticleNumber(p.Artikelnummer, pMandator)
|
||||
Dim oPositions As List(Of DocumentRow) = pDocument.Rows.
|
||||
Where(Function(r) r.Name.ToUpper.EndsWith("T026")).
|
||||
SetValue(Sub(p As DocumentRow)
|
||||
Dim oArticleNumberItem = p.Fields.Item("Artikelnummer")
|
||||
Dim oArticleNumber = Winline.TryGetArticleNumber(oArticleNumberItem.Original, pMandator)
|
||||
If oArticleNumber IsNot Nothing Then
|
||||
p.Artikelnummer = oArticleNumber
|
||||
oArticleNumberItem.External = oArticleNumber
|
||||
End If
|
||||
End Sub).
|
||||
Select(Of Input.MESOWebServiceEXIMVRG_ordersT026)(Function(i) i).
|
||||
ToList()
|
||||
|
||||
pData.Items = New List(Of Object) From {oHead}.
|
||||
Concat(oPositions).
|
||||
ToArray()
|
||||
Dim oList As New List(Of DocumentRow) From {oHead}
|
||||
pDocument.Rows = oList.Concat(oPositions).ToList()
|
||||
|
||||
Return pData
|
||||
Return pDocument
|
||||
End Function
|
||||
|
||||
Private Function WrapFileInfo(pFileInfo As FileInfo) As Document
|
||||
|
||||
@@ -1,4 +1,23 @@
|
||||
Public Class DocumentRow
|
||||
''' <summary>
|
||||
''' Tabellen/Elementname aus XML
|
||||
''' </summary>
|
||||
Public Name As String
|
||||
Public Fields As Dictionary(Of String, String)
|
||||
Public Id As New Guid
|
||||
|
||||
Public Fields As Dictionary(Of String, FieldValue)
|
||||
|
||||
Public Sub New()
|
||||
Id = Guid.NewGuid()
|
||||
End Sub
|
||||
|
||||
Public Class FieldValue
|
||||
Public Original As String = ""
|
||||
Public External As String = ""
|
||||
Public Final As String = ""
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return Final
|
||||
End Function
|
||||
End Class
|
||||
End Class
|
||||
|
||||
@@ -94,6 +94,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="BaseClass.vb" />
|
||||
<Compile Include="Config.vb" />
|
||||
<Compile Include="Constants.vb" />
|
||||
<Compile Include="Documents\Document.vb" />
|
||||
<Compile Include="Documents\DocumentMatch.vb" />
|
||||
<Compile Include="Documents\DocumentRow.vb" />
|
||||
@@ -130,7 +131,7 @@
|
||||
<Compile Include="Winline\Entities\Contact.vb" />
|
||||
<Compile Include="Winline\Entities\DocumentKind.vb" />
|
||||
<Compile Include="Winline\Entities\Mandator.vb" />
|
||||
<Compile Include="Winline\Entities\XmlItem.vb" />
|
||||
<Compile Include="Winline\Entities\TemplateColumn.vb" />
|
||||
<Compile Include="Winline\WebService.vb" />
|
||||
<Compile Include="XmlData.vb" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -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
|
||||
|
||||
12
ImporterShared/Winline/Entities/TemplateColumn.vb
Normal file
12
ImporterShared/Winline/Entities/TemplateColumn.vb
Normal file
@@ -0,0 +1,12 @@
|
||||
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 [Function] As Constants.XmlFunction
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -1,9 +0,0 @@
|
||||
Namespace Winline
|
||||
Public Class XmlItem
|
||||
Public Name As String
|
||||
Public Root As String
|
||||
Public Type As String
|
||||
Public IsHead As Boolean
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user