Rename Shared to Common
This commit is contained in:
25
MultiTool.Common/Winline/Entities/Account.vb
Normal file
25
MultiTool.Common/Winline/Entities/Account.vb
Normal file
@@ -0,0 +1,25 @@
|
||||
Namespace Winline.Entities
|
||||
Public Class Account
|
||||
Public Property Id As String
|
||||
Public Property Name As String
|
||||
|
||||
Public Property StreetName As String
|
||||
Public Property CityName As String
|
||||
Public Property ZipCode As String
|
||||
Public Property GLN As String
|
||||
|
||||
Public Property Mandator As Mandator
|
||||
|
||||
Public Overrides Function GetHashCode() As Integer
|
||||
Return Id.GetHashCode()
|
||||
End Function
|
||||
|
||||
Public Overrides Function Equals(obj As Object) As Boolean
|
||||
Return DirectCast(obj, Account).Id = Id
|
||||
End Function
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return $"{Name} ({Id})"
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
21
MultiTool.Common/Winline/Entities/Article.vb
Normal file
21
MultiTool.Common/Winline/Entities/Article.vb
Normal file
@@ -0,0 +1,21 @@
|
||||
Namespace Winline.Entities
|
||||
Public Class Article
|
||||
Public Property Id As String
|
||||
Public Property Name As String
|
||||
Public Property EAN As String
|
||||
Public Property Mandator As Mandator
|
||||
|
||||
Public Overrides Function GetHashCode() As Integer
|
||||
Return Id.GetHashCode()
|
||||
End Function
|
||||
|
||||
Public Overrides Function Equals(obj As Object) As Boolean
|
||||
Return DirectCast(obj, Article).Id = Id
|
||||
End Function
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return $"{Name} ({Id})"
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
12
MultiTool.Common/Winline/Entities/Contact.vb
Normal file
12
MultiTool.Common/Winline/Entities/Contact.vb
Normal file
@@ -0,0 +1,12 @@
|
||||
Namespace Winline.Entities
|
||||
Public Class Contact
|
||||
Public Property Id As Integer
|
||||
Public Property Number As String
|
||||
Public Property Name As String
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return Name
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
19
MultiTool.Common/Winline/Entities/DocumentKind.vb
Normal file
19
MultiTool.Common/Winline/Entities/DocumentKind.vb
Normal file
@@ -0,0 +1,19 @@
|
||||
Namespace Winline.Entities
|
||||
Public Class DocumentKind
|
||||
Public Property Id As Integer
|
||||
Public Property Name As String
|
||||
Public Property Mandator As Mandator
|
||||
|
||||
Public Overrides Function GetHashCode() As Integer
|
||||
Return Id.GetHashCode()
|
||||
End Function
|
||||
|
||||
Public Overrides Function Equals(obj As Object) As Boolean
|
||||
Return DirectCast(obj, DocumentKind).Id = Id
|
||||
End Function
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return $"{Name} ({Id})"
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
28
MultiTool.Common/Winline/Entities/ExportDocument.vb
Normal file
28
MultiTool.Common/Winline/Entities/ExportDocument.vb
Normal file
@@ -0,0 +1,28 @@
|
||||
Namespace Winline.Entities
|
||||
Public Class ExportDocument
|
||||
Public Property Schema As Templates.Template
|
||||
|
||||
Public Property Account As Account
|
||||
Public ReadOnly Property AccountName As String
|
||||
Get
|
||||
Return Account?.ToString()
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Property Kind As DocumentKind
|
||||
Public Property RunningNumber As String
|
||||
Public Property Number As String
|
||||
Public Property [Date] As Date
|
||||
Public Property DateColumn As String
|
||||
Public Property NetAmount As Double
|
||||
Public Property GrossAmount As Double
|
||||
|
||||
Public Property IsSelected As Boolean = False
|
||||
Public Property IsExported As Boolean = False
|
||||
|
||||
Public Property FilenameExport As String
|
||||
Public Property ExportedWhen As Date
|
||||
Public Property ExportedWho As String
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
23
MultiTool.Common/Winline/Entities/Mandator.vb
Normal file
23
MultiTool.Common/Winline/Entities/Mandator.vb
Normal file
@@ -0,0 +1,23 @@
|
||||
Namespace Winline.Entities
|
||||
Public Class Mandator
|
||||
Public Property Id As String
|
||||
Public Property Name As String
|
||||
Public Property Database As String
|
||||
Public Property Server As String
|
||||
Public Property Regex As String
|
||||
Public Property Order As Integer
|
||||
Public Property IsWhitelisted As Boolean
|
||||
|
||||
Public Overrides Function GetHashCode() As Integer
|
||||
Return Id.GetHashCode()
|
||||
End Function
|
||||
|
||||
Public Overrides Function Equals(obj As Object) As Boolean
|
||||
Return DirectCast(obj, Mandator).Id = Id
|
||||
End Function
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return $"{Name} ({Id})"
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
128
MultiTool.Common/Winline/Entities/Response.vb
Normal file
128
MultiTool.Common/Winline/Entities/Response.vb
Normal file
@@ -0,0 +1,128 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' Dieser Code wurde von einem Tool generiert.
|
||||
' Laufzeitversion:4.0.30319.42000
|
||||
'
|
||||
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
' der Code erneut generiert wird.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict Off
|
||||
Option Explicit On
|
||||
|
||||
'
|
||||
'This source code was auto-generated by xsd, Version=4.8.3928.0.
|
||||
'
|
||||
Namespace Templates.Entities
|
||||
|
||||
'''<remarks/>
|
||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.8.3928.0"),
|
||||
System.SerializableAttribute(),
|
||||
System.Diagnostics.DebuggerStepThroughAttribute(),
|
||||
System.ComponentModel.DesignerCategoryAttribute("code"),
|
||||
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True),
|
||||
System.Xml.Serialization.XmlRootAttribute([Namespace]:="", IsNullable:=False)>
|
||||
Partial Public Class MESOWebServiceResult
|
||||
|
||||
Private overallSuccessField As Boolean
|
||||
|
||||
Private resultDetailsField As MESOWebServiceResultResultDetails()
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
|
||||
Public Property OverallSuccess() As Boolean
|
||||
Get
|
||||
Return Me.overallSuccessField
|
||||
End Get
|
||||
Set
|
||||
Me.overallSuccessField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlElementAttribute("ResultDetails", Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
|
||||
Public Property ResultDetails() As MESOWebServiceResultResultDetails()
|
||||
Get
|
||||
Return Me.resultDetailsField
|
||||
End Get
|
||||
Set
|
||||
Me.resultDetailsField = Value
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
|
||||
'''<remarks/>
|
||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.8.3928.0"),
|
||||
System.SerializableAttribute(),
|
||||
System.Diagnostics.DebuggerStepThroughAttribute(),
|
||||
System.ComponentModel.DesignerCategoryAttribute("code"),
|
||||
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
|
||||
Partial Public Class MESOWebServiceResultResultDetails
|
||||
|
||||
Private successField As Boolean
|
||||
|
||||
Private errorCodeField As String
|
||||
|
||||
Private errorTextField As String
|
||||
|
||||
Private keyValueField As String
|
||||
|
||||
Private voucherNumberField As String
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
|
||||
Public Property Success() As Boolean
|
||||
Get
|
||||
Return Me.successField
|
||||
End Get
|
||||
Set
|
||||
Me.successField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
|
||||
Public Property ErrorCode() As String
|
||||
Get
|
||||
Return Me.errorCodeField
|
||||
End Get
|
||||
Set
|
||||
Me.errorCodeField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
|
||||
Public Property ErrorText() As String
|
||||
Get
|
||||
Return Me.errorTextField
|
||||
End Get
|
||||
Set
|
||||
Me.errorTextField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
|
||||
Public Property KeyValue() As String
|
||||
Get
|
||||
Return Me.keyValueField
|
||||
End Get
|
||||
Set
|
||||
Me.keyValueField = Value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
|
||||
Public Property VoucherNumber() As String
|
||||
Get
|
||||
Return Me.voucherNumberField
|
||||
End Get
|
||||
Set
|
||||
Me.voucherNumberField = Value
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
402
MultiTool.Common/Winline/WebServiceData.vb
Normal file
402
MultiTool.Common/Winline/WebServiceData.vb
Normal file
@@ -0,0 +1,402 @@
|
||||
Imports System.Net.Http
|
||||
Imports System.Text
|
||||
Imports System.Xml
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Filesystem
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports MultiTool.Common.Documents
|
||||
Imports MultiTool.Common.Exceptions
|
||||
Imports MultiTool.Common.Templates
|
||||
Imports MultiTool.Common.Templates.GeneralConfig
|
||||
Imports MultiTool.Common.Winline.Entities
|
||||
|
||||
Namespace Winline
|
||||
Public Class WebServiceData
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly Config As WebServiceConfig
|
||||
Private ReadOnly Serializer As Serializer
|
||||
Private ReadOnly Winline As WinlineData
|
||||
Private ReadOnly FileEx As File
|
||||
Private ReadOnly Patterns As Patterns
|
||||
|
||||
Public Event WebServiceProgress As EventHandler(Of String)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pWinline As WinlineData, pWebserviceConfig As WebServiceConfig, pGeneralConfig As GeneralConfig)
|
||||
MyBase.New(pLogConfig, pDatabase)
|
||||
Serializer = New Serializer(pLogConfig)
|
||||
Config = pWebserviceConfig
|
||||
Patterns = New Patterns(pLogConfig, pGeneralConfig)
|
||||
FileEx = New File(LogConfig)
|
||||
Winline = pWinline
|
||||
End Sub
|
||||
|
||||
Public Sub RaiseWebServiceProgress(pMessage As String)
|
||||
RaiseEvent WebServiceProgress(Me, pMessage)
|
||||
End Sub
|
||||
|
||||
#Region "Import"
|
||||
''' <summary>
|
||||
''' Transfers a document to winline via Webservices
|
||||
''' </summary>
|
||||
''' <param name="pDocument"></param>
|
||||
''' <param name="pTemplate"></param>
|
||||
''' <param name="pMandator"></param>
|
||||
''' <param name="pIsTest"></param>
|
||||
''' <exception cref="HttpRequestException"></exception>
|
||||
''' <exception cref="WebServiceException"></exception>
|
||||
''' <exception cref="TaskCanceledException"></exception>
|
||||
''' <returns>True if request was successful.</returns>
|
||||
Public Async Function TransferDocumentToWinline(pDocument As Documents.Document, pTemplate As Template, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean)
|
||||
Dim oBytes As Byte() = GetBytesFromDocument(pDocument)
|
||||
Dim oWS = Config
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Einstellungen laden")
|
||||
|
||||
' --- Build all teh filenamez and pathz
|
||||
Dim oBaseFileName As String = FileEx.GetDateTimeString()
|
||||
Dim oFileName = $"{pTemplate.Name}-{oBaseFileName}-Request.xml"
|
||||
|
||||
' --- Get and create path for request/response files
|
||||
Dim oOutputDirectory = FileEx.CreateDateDirectory(pTemplate.OutputWebserviceDirectory)
|
||||
Dim oOutputFilePath = IO.Path.Combine(oOutputDirectory, oFileName)
|
||||
|
||||
' Generate absolute path to copy xml file to
|
||||
Dim oAbsolutePath = IO.Path.Combine(oWS.ImportBasePath, oWS.ImportRelativePath)
|
||||
oAbsolutePath = FileEx.CreateDateDirectory(oAbsolutePath)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(oAbsolutePath, oFileName)
|
||||
|
||||
' Generate relative path to supply to winline
|
||||
Dim oRelativePath = IO.Path.Combine(oWS.ImportRelativePath)
|
||||
oRelativePath = FileEx.GetDateDirectory(oRelativePath)
|
||||
Dim oImportRelativeFilePath = IO.Path.Combine(oRelativePath, oFileName)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Dateien schreiben")
|
||||
|
||||
' --- Serialize Data into XML string
|
||||
IO.File.WriteAllBytes(oOutputFilePath, oBytes)
|
||||
|
||||
' --- Copy file to Winline Import Directory
|
||||
Try
|
||||
IO.File.Copy(oOutputFilePath, oImportAbsoluteFilePath, True)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
|
||||
' --- Prepare URL and HTTP Client
|
||||
Dim oTemplateType = pDocument.TemplateType
|
||||
Dim oTemplateName = pDocument.TemplateName
|
||||
|
||||
' ActionCode: Should this be a test or not?
|
||||
' 0 = Test call
|
||||
' 1 = Real call
|
||||
Dim oActionCode = 1
|
||||
If pIsTest = True Then
|
||||
oActionCode = 0
|
||||
End If
|
||||
|
||||
' Byref: Should data be supplied as file or as string?
|
||||
' 0 = As String
|
||||
' 1 = As File (relative to Winline Server directory)
|
||||
Dim oByref = 1
|
||||
|
||||
Dim oURL As String = $"{oWS.BaseUrl}/ewlservice/import?User={oWS.Username}&Password={oWS.Password}&Company={pMandator.Id}&Type={oTemplateType}&Vorlage={oTemplateName}&ActionCode={oActionCode}&Byref={oByref}&Data={oImportRelativeFilePath}"
|
||||
Dim oClient As New HttpClient With {
|
||||
.Timeout = TimeSpan.FromSeconds(Constants.HTTP_REQUEST_TIMEOUT_IN_SECONDS)
|
||||
}
|
||||
|
||||
Logger.Info("Creating HTTP Request to [{0}]", oWS.BaseUrl)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Anfrage absenden")
|
||||
|
||||
' --- Bring the action!
|
||||
Try
|
||||
Dim oResponse As HttpResponseMessage = Await oClient.GetAsync(oURL)
|
||||
Await HandleImportResponse(oResponse, pTemplate, oBaseFileName)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
Finally
|
||||
oClient.Dispose()
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Async Function HandleImportResponse(pResponse As HttpResponseMessage, pTemplate As Template, pBaseFileName As String) As Task
|
||||
pResponse.EnsureSuccessStatusCode()
|
||||
Dim oResponseBody As String = Await pResponse.Content.ReadAsStringAsync()
|
||||
Dim oContentType = pResponse.Content.Headers.ContentType.MediaType
|
||||
Dim oSerializer = Serializer.GetSerializer(GetType(Templates.Entities.MESOWebServiceResult))
|
||||
Dim oOutputDirectory = FileEx.CreateDateDirectory(pTemplate.OutputWebserviceDirectory)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Antwort verarbeiten")
|
||||
|
||||
Select Case oContentType
|
||||
Case "text/xml"
|
||||
WriteResponseFile(oOutputDirectory, oResponseBody, $"{pTemplate.Name}-{pBaseFileName}-Response.xml")
|
||||
|
||||
Dim oBytes As Byte() = Encoding.UTF8.GetBytes(oResponseBody)
|
||||
Using oStream As New IO.MemoryStream(oBytes)
|
||||
Dim oResponseObject As Templates.Entities.MESOWebServiceResult = oSerializer.Deserialize(oStream)
|
||||
Dim oErrorStrings As New List(Of String)
|
||||
|
||||
If oResponseObject.ResultDetails IsNot Nothing Then
|
||||
For Each oDetails As Templates.Entities.MESOWebServiceResultResultDetails In oResponseObject.ResultDetails
|
||||
|
||||
If oDetails.Success = True Then
|
||||
Logger.Info("KeyValue: [{0}]", oDetails.KeyValue)
|
||||
Logger.Info("VoucherNumber: [{0}]", oDetails.VoucherNumber)
|
||||
Else
|
||||
Logger.Warn("ErrorCode: [{0}]", oDetails.ErrorCode)
|
||||
Logger.Warn("ErrorText: [{0}]", oDetails.ErrorText)
|
||||
oErrorStrings.Add($"[{oDetails.ErrorCode}] {oDetails.ErrorText}")
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
If oResponseObject.OverallSuccess = False Then
|
||||
Dim oMessage = $"Request to Webservice was unsuccessful:{vbNewLine}{vbNewLine}{String.Join(vbNewLine, oErrorStrings.ToArray)}"
|
||||
|
||||
Throw New WebServiceException(oMessage)
|
||||
End If
|
||||
End Using
|
||||
|
||||
Case "text/html"
|
||||
WriteResponseFile(oOutputDirectory, oResponseBody, $"{pTemplate.Name}-{pBaseFileName}-Response.xml")
|
||||
|
||||
Throw New WebServiceException(oResponseBody)
|
||||
|
||||
Case Else
|
||||
Throw New WebServiceException(oResponseBody)
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Private Function GetBytesFromDocument(pDocument As Documents.Document) As Byte()
|
||||
Using oStream As New IO.MemoryStream()
|
||||
Dim w = XmlWriter.Create(oStream)
|
||||
|
||||
w.WriteStartDocument()
|
||||
w.WriteStartElement("MESOWebService")
|
||||
w.WriteAttributeString("Template", pDocument.TemplateName)
|
||||
w.WriteAttributeString("TemplateType", pDocument.TemplateType)
|
||||
w.WriteAttributeString("option", pDocument.Option)
|
||||
w.WriteAttributeString("printVoucher", pDocument.PrintVoucher)
|
||||
|
||||
pDocument.Rows.Sort()
|
||||
|
||||
For Each oRow In pDocument.Rows
|
||||
w.WriteStartElement(oRow.TableName)
|
||||
|
||||
For Each oField As KeyValuePair(Of String, DocumentRow.FieldValue) In oRow.Fields
|
||||
If oField.Value.Final = String.Empty Then
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If oField.Value.IsVirtual Then
|
||||
Continue For
|
||||
End If
|
||||
|
||||
w.WriteStartElement(oField.Key)
|
||||
w.WriteValue(oField.Value.Final)
|
||||
w.WriteEndElement() ' Field
|
||||
Next
|
||||
|
||||
w.WriteEndElement() ' Row
|
||||
Next
|
||||
w.WriteEndElement() ' MESOWebService
|
||||
w.WriteEndDocument() ' Document
|
||||
w.Close()
|
||||
|
||||
Return oStream.ToArray()
|
||||
End Using
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "Export"
|
||||
Async Function ExportDocumentFromWinline(pDocument As Entities.ExportDocument, pTemplate As Template, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean)
|
||||
Dim oWS = Config
|
||||
|
||||
' --- Build all teh filenamez and pathz
|
||||
Dim oBaseFileName As String = FileEx.GetDateTimeString()
|
||||
Dim oFileName = $"{pTemplate.Name}-{oBaseFileName}.xml"
|
||||
'Dim oFileName = FileEx.GetFilenameWithPrefix(oBaseFileName, pTemplate.Name, "xml")
|
||||
|
||||
' Save the filename to the document
|
||||
pDocument.FilenameExport = oFileName
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Dateien schreiben")
|
||||
|
||||
' --- Prepare URL and HTTP Client
|
||||
Dim oTemplateType = 30
|
||||
Dim oTemplateName = pDocument.Schema.Name
|
||||
Dim oKey = $"{pDocument.Account.Id}-{pDocument.RunningNumber}"
|
||||
|
||||
' ActionCode: Should this be a test or not?
|
||||
' 0 = Test call
|
||||
' 1 = Real call
|
||||
Dim oActionCode = 1
|
||||
If pIsTest = True Then
|
||||
oActionCode = 0
|
||||
End If
|
||||
|
||||
Dim oURL As String = $"{oWS.BaseUrl}/ewlservice/export?User={oWS.Username}&Password={oWS.Password}&Company={pMandator.Id}&Type={oTemplateType}&Vorlage={oTemplateName}&ActionCode={oActionCode}&Key={oKey}"
|
||||
Dim oClient As New HttpClient()
|
||||
|
||||
Logger.Info("Creating HTTP Request to [{0}]", oWS.BaseUrl)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Anfrage absenden")
|
||||
|
||||
' --- Bring the action!
|
||||
Try
|
||||
Dim oResponse As HttpResponseMessage = Await oClient.GetAsync(oURL)
|
||||
Await HandleExportResponse(oResponse, pDocument, pTemplate, pMandator, oBaseFileName)
|
||||
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
|
||||
Finally
|
||||
oClient.Dispose()
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Async Function HandleExportResponse(pResponse As HttpResponseMessage, pDocument As Entities.ExportDocument, pTemplate As Template, pMandator As Mandator, pBaseFileName As String) As Task
|
||||
pResponse.EnsureSuccessStatusCode()
|
||||
Dim oResponseBody As String = Await pResponse.Content.ReadAsStringAsync()
|
||||
Dim oContentType = pResponse.Content.Headers.ContentType.MediaType
|
||||
Dim oSerializer = Serializer.GetSerializer(GetType(Templates.Entities.MESOWebServiceResult))
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Antwort verarbeiten")
|
||||
|
||||
oResponseBody = ApplyItemFunctionsForExport(pDocument, pTemplate, pMandator, oResponseBody)
|
||||
|
||||
Select Case oContentType
|
||||
Case "text/xml"
|
||||
' Webservice
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, oResponseBody, $"{pTemplate.Name}-{pBaseFileName}-Response.xml")
|
||||
' XML
|
||||
WriteResponseFile(pTemplate.OutputXmlFileDirectory, oResponseBody, $"{pTemplate.Name}-{pBaseFileName}.xml")
|
||||
' Archive
|
||||
WriteResponseFile(FileEx.CreateDateDirectory(pTemplate.ArchiveDirectory), oResponseBody, $"{pTemplate.Name}-{pBaseFileName}.xml")
|
||||
|
||||
Case "text/html"
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, oResponseBody, $"{pTemplate.Name}-{pBaseFileName}-Response.txt")
|
||||
|
||||
Throw New ApplicationException(oResponseBody)
|
||||
|
||||
Case Else
|
||||
Throw New ApplicationException(oResponseBody)
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Private Function ApplyItemFunctionsForExport(pDocument As Entities.ExportDocument, pTemplate As Template, pMandator As Mandator, oResponseBody As String) As String
|
||||
Dim oDoc As New XmlDocument()
|
||||
oDoc.LoadXml(oResponseBody)
|
||||
|
||||
For Each oTable In pTemplate.Tables
|
||||
For Each oItem As Template.Column In oTable.Columns
|
||||
Dim oTableName As String = oTable.Name
|
||||
Dim oItemName As String = oItem.Name
|
||||
|
||||
If oItem.Config.Function Is Nothing Then
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim oFunction = oItem.Config.Function.Name
|
||||
|
||||
Dim oPath = $"//MESOWebService/{oTableName}/{oItemName}"
|
||||
Dim oNodes As XmlNodeList = oDoc.SelectNodes(oPath)
|
||||
|
||||
For Each oNode As XmlNode In oNodes
|
||||
If oItem.Config.Function.Name = "GLN" Then
|
||||
Dim oGLN = Winline.TryGetGLN(oNode.InnerText, pMandator)
|
||||
|
||||
If oGLN Is Nothing Then
|
||||
Throw New Exceptions.MissingAttributeException("GLN")
|
||||
End If
|
||||
|
||||
oNode.InnerText = oGLN
|
||||
|
||||
ElseIf oItem.Config.Function.Name = "EAN" Then
|
||||
Dim oEAN = Winline.TryGetEAN(oNode.InnerText, pMandator)
|
||||
|
||||
If oEAN Is Nothing Then
|
||||
Throw New Exceptions.MissingAttributeException("EAN")
|
||||
End If
|
||||
|
||||
oNode.InnerText = oEAN
|
||||
|
||||
ElseIf oItem.Config.Function.Name = "SQL" Then
|
||||
Dim oSQL = Patterns.ReplaceForExport(pDocument, pMandator, oItem.Config.Function.Params)
|
||||
Dim oValue = Database.GetScalarValue(oSQL)
|
||||
|
||||
If oValue Is Nothing Then
|
||||
Throw New Exceptions.MissingAttributeException("SQL")
|
||||
End If
|
||||
|
||||
oNode.InnerText = oValue
|
||||
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
Next
|
||||
|
||||
Dim oArray As Byte()
|
||||
Using oStream As New IO.MemoryStream
|
||||
oDoc.Save(oStream)
|
||||
oArray = oStream.ToArray()
|
||||
End Using
|
||||
|
||||
Dim oXml = Text.Encoding.UTF8.GetString(oArray)
|
||||
oResponseBody = oXml
|
||||
Return oResponseBody
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
|
||||
Private Function WriteResponseFileWithSuffix(pPath As String, pBaseFileName As String, pResponseBody As String, pExtension As String, pSuffix As String) As Boolean
|
||||
Try
|
||||
Dim oRequestFileName As String = FileEx.GetFilenameWithSuffix(pBaseFileName, pSuffix, pExtension)
|
||||
Dim oFilePath As String = IO.Path.Combine(pPath, oRequestFileName)
|
||||
IO.File.WriteAllText(oFilePath, pResponseBody)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function WriteResponseFileWithPrefix(pPath As String, pBaseFileName As String, pResponseBody As String, pExtension As String, pPrefix As String) As Boolean
|
||||
Try
|
||||
Dim oRequestFileName As String = FileEx.GetFilenameWithPrefix(pBaseFileName, pPrefix, pExtension)
|
||||
Dim oFilePath As String = IO.Path.Combine(pPath, oRequestFileName)
|
||||
IO.File.WriteAllText(oFilePath, pResponseBody)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function WriteResponseFile(pPath As String, pResponseBody As String, pFileName As String) As Boolean
|
||||
Try
|
||||
Dim oFilePath As String = IO.Path.Combine(pPath, pFileName)
|
||||
IO.File.WriteAllText(oFilePath, pResponseBody)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
881
MultiTool.Common/Winline/WinlineData.vb
Normal file
881
MultiTool.Common/Winline/WinlineData.vb
Normal file
@@ -0,0 +1,881 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports MultiTool.Common.Winline.Entities
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports MultiTool.Common.Templates
|
||||
Imports MultiTool.Common.Constants
|
||||
Imports DigitalData.Modules.Language
|
||||
|
||||
Namespace Winline
|
||||
Public Class WinlineData
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly Property Config As GeneralConfig
|
||||
Private ReadOnly Property MandatorConfig As MandatorConfig
|
||||
Private ReadOnly Property MappingConfig As MappingConfig
|
||||
Private ReadOnly Property Patterns As Patterns
|
||||
|
||||
Public Property Articles As New List(Of Article)
|
||||
Public Property Accounts As New List(Of Account)
|
||||
Public Property Mandators As New List(Of Mandator)
|
||||
Public Property DocumentKinds As New List(Of DocumentKind)
|
||||
|
||||
Public Property Years As List(Of Integer)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As GeneralConfig, pMappingConfig As MappingConfig, pMandatorConfig As MandatorConfig)
|
||||
MyBase.New(pLogConfig, pDatabase)
|
||||
Patterns = New Patterns(pLogConfig, pConfig)
|
||||
Config = pConfig
|
||||
MandatorConfig = pMandatorConfig
|
||||
MappingConfig = pMappingConfig
|
||||
End Sub
|
||||
|
||||
Public Enum DocumentType
|
||||
Undefined
|
||||
OutgoingOffer
|
||||
OutgoingOrder
|
||||
OutgoingDeliveryNote
|
||||
OutgoingInvoice
|
||||
IncomingOffer
|
||||
IncomingOrder
|
||||
IncomingDeliveryNote
|
||||
IncomingInvoice
|
||||
End Enum
|
||||
|
||||
Public Class GetDocumentArgs
|
||||
Public Property Account As Account
|
||||
Public Property Kinds As List(Of DocumentKind)
|
||||
Public Property DateFrom As Date
|
||||
Public Property DateTo As Date
|
||||
Public Property DocNumberFrom As String
|
||||
Public Property DocNumberTo As String
|
||||
Public Property ShowExported As Boolean
|
||||
Public Property Year As Integer
|
||||
End Class
|
||||
|
||||
|
||||
Public Async Function LoadArticles(pMandator As Mandator) As Task
|
||||
Logger.Info("Loading Articles for Mandator [{0}]", pMandator)
|
||||
Dim oYear = Config.GetWinLineYear()
|
||||
|
||||
Try
|
||||
Dim oSQL = $"
|
||||
SELECT DISTINCT
|
||||
[c002], -- Artikelnummer
|
||||
[c003], -- Bezeichnung
|
||||
[c075] -- EAN
|
||||
FROM [{pMandator.Server}].[{pMandator.Database}].[dbo].[v021]
|
||||
WHERE
|
||||
mesocomp = '{pMandator.Id}'
|
||||
AND mesoyear = {oYear}"
|
||||
|
||||
Dim oTable = Await Database.GetDatatableAsync(oSQL)
|
||||
Dim oArticles As New List(Of Article)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oArticleId As String = ItemEx(oRow, V21_ARTICLENUMBER, String.Empty)
|
||||
Dim oArticleDescription As String = ItemEx(oRow, V21_ARTICLEDESCRIPTION, String.Empty)
|
||||
Dim oEAN As String = ItemEx(oRow, V21_EAN, String.Empty)
|
||||
|
||||
oArticles.Add(New Article With {
|
||||
.Id = oArticleId,
|
||||
.Name = oArticleDescription,
|
||||
.EAN = oEAN,
|
||||
.Mandator = pMandator
|
||||
})
|
||||
Next
|
||||
Articles.AddRange(oArticles)
|
||||
|
||||
Logger.Info("[{0}] Articles loaded for Mandator [{1}]", oArticles.Count, pMandator)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not load Articles for Mandator [{0}]", pMandator)
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function LoadAccounts(pMandator As Mandator) As Task
|
||||
Logger.Info("Loading Accounts for Mandator [{0}]", pMandator)
|
||||
Dim oYear = Config.GetWinLineYear()
|
||||
|
||||
Try
|
||||
Dim oSQL = $"
|
||||
SELECT DISTINCT
|
||||
[c002], -- Kundennummer
|
||||
[c003], -- Kundenname
|
||||
[c050], -- Straße
|
||||
[c052], -- Ort
|
||||
[c051], -- PLZ
|
||||
[c260] -- GLN
|
||||
FROM [{pMandator.Server}].[{pMandator.Database}].[dbo].[v050]
|
||||
WHERE
|
||||
c139 IS NULL
|
||||
AND mesocomp = '{pMandator.Id}'
|
||||
AND mesoyear = {oYear}"
|
||||
Dim oTable = Await Database.GetDatatableAsync(oSQL)
|
||||
Dim oAccounts As New List(Of Account)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oAccountNumber As String = ItemEx(oRow, V50_ACCOUNTNUMBER, String.Empty)
|
||||
Dim oAccountName As String = ItemEx(oRow, V50_ACCOUNTNAME, String.Empty)
|
||||
Dim oStreetName As String = ItemEx(oRow, V50_STREETNAME, String.Empty)
|
||||
Dim oZipCode As String = ItemEx(oRow, V50_ZIPCODE, String.Empty)
|
||||
Dim oCityName As String = ItemEx(oRow, V50_CITYNAME, String.Empty)
|
||||
Dim oGLN As String = ItemEx(oRow, V50_GLN, String.Empty)
|
||||
|
||||
oAccounts.Add(New Account With {
|
||||
.Id = oAccountNumber,
|
||||
.Name = oAccountName,
|
||||
.StreetName = oStreetName,
|
||||
.ZipCode = oZipCode,
|
||||
.CityName = oCityName,
|
||||
.GLN = oGLN,
|
||||
.Mandator = pMandator
|
||||
})
|
||||
Next
|
||||
Accounts.AddRange(oAccounts)
|
||||
|
||||
If oAccounts.Count = 0 Then
|
||||
Logger.Warn("No Accounts loaded for Mandator [{0}]", pMandator)
|
||||
End If
|
||||
|
||||
Logger.Info("[{0}] Accounts loaded for Mandator [{1}]", oAccounts.Count, pMandator)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not load Accounts for Mandator [{0}]", pMandator)
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function LoadMandators() As Task
|
||||
Try
|
||||
Dim oSQL = "SELECT [c000], [c003], [c004] FROM [cwlsystem].[dbo].[T001SRV] (NOLOCK)"
|
||||
Dim oTable = Await Database.GetDatatableAsync(oSQL)
|
||||
|
||||
Mandators.Clear()
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oDbInfo = SplitConnectionInfo(oRow)
|
||||
Dim oMandator = New Mandator With {
|
||||
.Id = ItemEx(oRow, T01_MANDATORID, String.Empty),
|
||||
.Name = ItemEx(oRow, T01_MANDATORNAME, String.Empty),
|
||||
.Database = oDbInfo.Item1,
|
||||
.Server = oDbInfo.Item2
|
||||
}
|
||||
|
||||
Dim oMandatorConfig As MandatorConfigItem = MandatorConfig.Items.
|
||||
Where(Function(item) item.Name = oMandator.Id).
|
||||
SingleOrDefault()
|
||||
|
||||
If oMandatorConfig IsNot Nothing Then
|
||||
oMandator.IsWhitelisted = True
|
||||
oMandator.Order = oMandatorConfig.OrderKey
|
||||
End If
|
||||
|
||||
Mandators.Add(oMandator)
|
||||
Next
|
||||
|
||||
Logger.Info("[{0}] Mandators loaded", Mandators.Count)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not load Mandators")
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Sub LoadEconomicYears()
|
||||
Dim oCurrentYear = Now.Year
|
||||
Dim oRange As IEnumerable(Of Integer) = Enumerable.Range(oCurrentYear - 10, 12).ToList()
|
||||
Years = oRange
|
||||
End Sub
|
||||
|
||||
Public Async Function LoadDocumentKinds(pMandator As Mandator) As Task
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
|
||||
Try
|
||||
' TODO: This is Schaum specific, maybe move to config later
|
||||
Dim oSQL = $"
|
||||
SELECT
|
||||
[c030],
|
||||
[c001],
|
||||
[mesocomp]
|
||||
FROM [{pMandator.Database}].[dbo].[t357] (NOLOCK)
|
||||
WHERE (
|
||||
[c001] LIKE 'Werk%(VK)' OR
|
||||
[c001] LIKE 'Werk%(WK)'
|
||||
)
|
||||
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSQL)
|
||||
Dim oKinds As New List(Of DocumentKind)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
oKinds.Add(New DocumentKind With {
|
||||
.Id = ItemEx(oRow, T357_KINDID, String.Empty),
|
||||
.Name = ItemEx(oRow, T357_KINDNAME, String.Empty),
|
||||
.Mandator = pMandator
|
||||
})
|
||||
Next
|
||||
|
||||
DocumentKinds.AddRange(oKinds)
|
||||
|
||||
Logger.Info("[{0}] DocumentKinds loaded for [{1}]", Mandators.Count, pMandator)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not load DocumentKinds")
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function TryGetAccount(pGLN As String, pMandator As Mandator) As Account
|
||||
Return TryGetAccount(pGLN, pMandator, "c260", String.Empty)
|
||||
End Function
|
||||
|
||||
Public Function TryGetAccount(pGLN As String, pMandator As Mandator, pSearchField As String) As Account
|
||||
Return TryGetAccount(pGLN, pMandator, pSearchField, String.Empty)
|
||||
End Function
|
||||
|
||||
Public Function TryGetAccount(pIdentifier As String, pMandator As Mandator, pSearchField As String, pAlternativeField As String) As Account
|
||||
Try
|
||||
If pIdentifier Is Nothing OrElse pIdentifier = String.Empty Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oSQL = $"
|
||||
SELECT
|
||||
[c002], -- Kundennummer
|
||||
[c003], -- Kundenname
|
||||
[c050], -- Straße
|
||||
[c052], -- Ort
|
||||
[c051], -- PLZ
|
||||
* -- Everything else
|
||||
FROM [{pMandator.Database}].[dbo].[v050]
|
||||
WHERE [c004] IN (2, 3) -- KontoTyp Debitor/Kreditor
|
||||
AND [{pSearchField}] = '{pIdentifier}'
|
||||
AND [mesocomp] = '{pMandator.Id}' and [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
' GLN not found in this Mandator, continue to next one
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Logger.Debug("GLN [{0}] was not found in Mandator: [{1}]", pIdentifier, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
' Duplicate GLN, exit and do nothing about this number
|
||||
If oTable.Rows.Count > 1 Then
|
||||
Logger.Warn("GLN [{0}] was found more than once in Mandator: [{1}]", pIdentifier, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oAccountNumber As String = ItemEx(oRow, V50_ACCOUNTNUMBER, String.Empty)
|
||||
Dim oAccountName As String = ItemEx(oRow, V50_ACCOUNTNAME, String.Empty)
|
||||
Dim oStreetName As String = ItemEx(oRow, V50_STREETNAME, String.Empty)
|
||||
Dim oZipCode As String = ItemEx(oRow, V50_ZIPCODE, String.Empty)
|
||||
Dim oCityName As String = ItemEx(oRow, V50_CITYNAME, String.Empty)
|
||||
|
||||
|
||||
If pAlternativeField <> String.Empty Then
|
||||
Dim oAlternativeValue = ItemEx(oRow, pAlternativeField, String.Empty)
|
||||
|
||||
If oAlternativeValue <> String.Empty Then
|
||||
Return TryGetAccount(oAlternativeValue, pMandator, "c002")
|
||||
End If
|
||||
End If
|
||||
|
||||
Return New Account With {
|
||||
.Id = oAccountNumber,
|
||||
.Name = oAccountName,
|
||||
.StreetName = oStreetName,
|
||||
.CityName = oCityName,
|
||||
.ZipCode = oZipCode,
|
||||
.Mandator = pMandator
|
||||
}
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error while trying to get account for GLN [{0}]", pIdentifier)
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function TryGetGLN(pAccountId As String, pMandator As Mandator) As String
|
||||
Try
|
||||
If pAccountId Is Nothing OrElse pAccountId = String.Empty Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oSQL = $"
|
||||
SELECT
|
||||
[c260] -- GLN
|
||||
FROM [{pMandator.Database}].[dbo].[v050]
|
||||
WHERE [c004] IN (2, 3) -- KontoTyp Debitor/Kreditor
|
||||
AND [c002] = '{pAccountId}'
|
||||
AND [mesocomp] = '{pMandator.Id}' and [mesoyear] = {oYear}"
|
||||
Dim oGLN As String = Database.GetScalarValue(oSQL)
|
||||
|
||||
' GLN not found in this Mandator, continue to next one
|
||||
If oGLN Is Nothing Then
|
||||
Logger.Debug("Account [{0}] was not found in Mandator: [{1}]", pAccountId, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
Return oGLN
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error while trying to get GLN for Account [{0}]", pAccountId)
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function TryGetArticlePrice(pArticle As String, pAccountNumber As String, pQuantity As String, pDocumentDate As Date, pMandator As Mandator, pTemplate As Template) As Task(Of Double)
|
||||
Return Await TryGetArticlePrice(pArticle, pAccountNumber, pQuantity, pDocumentDate, pMandator, pTemplate, 0)
|
||||
End Function
|
||||
|
||||
Public Async Function TryGetArticlePrice(pArticle As String, pAccountNumber As String, pQuantity As String, pDocumentDate As Date, pMandator As Mandator, pTemplate As Template, pWaitingDays As Integer) As Task(Of Double)
|
||||
Try
|
||||
Dim oUserName = Environment.UserName
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oDebug = Convert.ToInt32(LogConfig.Debug)
|
||||
|
||||
' TODO: pGroupPropertyID in config
|
||||
' TODO: pTempTableSuffix in config (nice to have)
|
||||
|
||||
Dim oDateFrom = pDocumentDate.AddDays(pWaitingDays * -1)
|
||||
Dim oDateTo = pDocumentDate
|
||||
|
||||
Dim oSQL As String = $"
|
||||
EXEC [{pMandator.Database}].[dbo].[PRCUST_GET_ACCOUNT_PRICE_CONDITION_VALUES]
|
||||
@pAccountNr = '{pAccountNumber}',
|
||||
@pGroupNr = '*',
|
||||
@pProductNr = '{pArticle}',
|
||||
@pProductQuantity = '<={pQuantity}',
|
||||
@pProductPriceDateFrom = '{oDateFrom:dd.MM.yyyy}',
|
||||
@pProductPriceDateTo = '{oDateTo:dd.MM.yyyy}',
|
||||
@pmesocomp = '{pMandator.Id}',
|
||||
@pmesoyear = {oYear},
|
||||
@pGroupPropertyID = 1008,
|
||||
@pTempTableSuffix = 'MT_USER_{oUserName}',
|
||||
@pBatchID = NULL,
|
||||
@pPrintDebug = 0,
|
||||
@pLog2DB = {oDebug},
|
||||
@pComment = 'Multitool/{pTemplate.Name}',
|
||||
@pResultType = 'CalcPricing'
|
||||
"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSQL)
|
||||
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Logger.Debug("Price for article [{0}] and Account [{1}] was not found in Mandator: [{2}]", pArticle, pAccountNumber, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oPrice As Double = oRow.Item("PRICE")
|
||||
|
||||
Return oPrice
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error while trying to get Price for Article [{0}] and Account [{1}]", pArticle, pAccountNumber)
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' This function is completely SCHAUM related.
|
||||
''' </summary>
|
||||
Public Async Function TryGetWaitingDays(pDocumentKind As Integer, pMandator As Mandator) As Task(Of Integer)
|
||||
Try
|
||||
Dim oSql = $"
|
||||
SELECT [Karenztage].[u012] FROM [{pMandator.Database}].[dbo].[t670] As [Werksdefinition]
|
||||
INNER JOIN [{pMandator.Database}].[dbo].[t670] AS [Werkszuordnung] ON [Werksdefinition].[u007] = [Werkszuordnung].[u007]
|
||||
INNER JOIN [{pMandator.Database}].[dbo].[t670] AS [Karenztage] ON [Werksdefinition].[u000] = [Karenztage].[u032]
|
||||
WHERE [Werksdefinition].[u011] In ({pDocumentKind},{pDocumentKind}*10)
|
||||
AND [Werkszuordnung].[u006] = '%ConditionAccountNr%'
|
||||
AND [Karenztage].[u002] = 'Karenztage'
|
||||
"
|
||||
Dim oWaitingDays As Integer = Await Database.GetScalarValueAsync(oSql)
|
||||
|
||||
If IsNothing(oWaitingDays) Then
|
||||
oWaitingDays = 0
|
||||
End If
|
||||
|
||||
Return oWaitingDays
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return 0
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function TryGetArticleNumber(pEAN As String, pMandator As Mandator) As String
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oSQL As String = $"
|
||||
SELECT
|
||||
[c011], -- Artikelnummer
|
||||
[c003], -- Artikelbezeichnung
|
||||
[c075], -- EAN-Nummer
|
||||
[c123] -- Ersatzartikelnummer
|
||||
FROM [{pMandator.Database}].[dbo].[v021]
|
||||
WHERE [c075] = '{pEAN}'
|
||||
AND [mesocomp] = '{pMandator.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}]", pEAN, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
' Duplicate EAN, exit and do nothing about this number
|
||||
If oTable.Rows.Count > 1 Then
|
||||
Logger.Warn("EAN [{0}] was found more than once", pEAN)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oArticleNumber As String = ItemEx(oRow, V21_MAINARTICLENUMBER, String.Empty)
|
||||
Return oArticleNumber
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function TryGetEAN(pArticleNumber As String, pMandator As Mandator) As String
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oSQL As String = $"
|
||||
SELECT
|
||||
[c075] -- EAN-Nummer
|
||||
FROM [{pMandator.Database}].[dbo].[v021]
|
||||
WHERE [c011] = '{pArticleNumber}'
|
||||
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
Dim oEAN As String = Database.GetScalarValue(oSQL)
|
||||
|
||||
' EAN not found in this Mandator, continue to next one
|
||||
If oEAN Is Nothing Then
|
||||
Logger.Debug("ArticleNumber [{0}] was not found in Mandator: [{1}]", pArticleNumber, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
Return oEAN
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetContacts(pAccountNumber As String, pMandator As Mandator) As List(Of Contact)
|
||||
Try
|
||||
Dim oContacts As New List(Of Contact)
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oSQL As String = $"
|
||||
SELECT
|
||||
[c000], -- Key
|
||||
[c001], -- Name
|
||||
[c063] -- Kontaktnummer
|
||||
FROM [{pMandator.Database}].[dbo].[t045]
|
||||
WHERE [c063] LIKE '{pAccountNumber}-%'
|
||||
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
' Contact not found in this Mandator, continue to next one
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Logger.Debug("Contact for Account [{0}] was not found in Mandator: [{1}]", pAccountNumber, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
For Each oRow In oTable.Rows
|
||||
oContacts.Add(New Contact With {
|
||||
.Id = ItemEx(Of String)(oRow, T45_KEY, Nothing),
|
||||
.Name = ItemEx(Of String)(oRow, T45_NAME, Nothing),
|
||||
.Number = ItemEx(Of String)(oRow, T45_CONTACTNUMBER, Nothing)
|
||||
})
|
||||
Next
|
||||
|
||||
Return oContacts
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetReplacementArticleNumber(pArticleNumber As String, pMandator As Mandator)
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oSQL As String = $"
|
||||
SELECT
|
||||
[c011], -- Artikelnummer
|
||||
[c003], -- Artikelbezeichnung
|
||||
[c075], -- EAN-Nummer
|
||||
[c123] -- Ersatzartikelnummer
|
||||
FROM [{pMandator.Database}].[dbo].[v021]
|
||||
WHERE [c011] = '{pArticleNumber}'
|
||||
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
' ArticleNumber not found in this Mandator, continue to next one
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Logger.Debug("ArticleNumber [{0}] was not found in Mandator: [{1}]", pArticleNumber, pMandator.Id)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
' Duplicate EAN, exit and do nothing about this number
|
||||
If oTable.Rows.Count > 1 Then
|
||||
Logger.Warn("ArticleNumber [{0}] was found more than once", pArticleNumber)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oReplacementArticleNumber = ItemEx(Of String)(oRow, V21_REPLACEMENTARTICLENUMBER, Nothing)
|
||||
|
||||
If oReplacementArticleNumber Is Nothing Then
|
||||
Return pArticleNumber
|
||||
End If
|
||||
|
||||
Return GetReplacementArticleNumber(oReplacementArticleNumber, pMandator)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function FindMatchingMandatorFromOrder(pData As Documents.Document) As Mandator
|
||||
Dim oPositions = pData.Rows.
|
||||
Where(Function(r) r.TableName.ToUpper.EndsWith("T026")).
|
||||
ToList()
|
||||
Dim oEANNumbers = oPositions.
|
||||
Select(Function(p)
|
||||
If p.Fields.ContainsKey("Artikelnummer") Then
|
||||
Return p.Fields.Item("Artikelnummer").Original
|
||||
Else
|
||||
Return Nothing
|
||||
End If
|
||||
End Function).
|
||||
Where(Function(ean) ean IsNot Nothing).
|
||||
Distinct().
|
||||
ToList()
|
||||
|
||||
Dim oYear = Config.GetWinLineYear()
|
||||
Dim oMandatorId As String = String.Empty
|
||||
Dim oWhitelistedMandators = Mandators.
|
||||
Where(Function(m) m.IsWhitelisted = True).
|
||||
OrderBy(Function(m) m.Order).
|
||||
ToList()
|
||||
|
||||
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] = '{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}]", 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}]", oEANNumber, oMandator.Id)
|
||||
Exit For
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oArticleNumber As String = ItemEx(oRow, V21_MAINARTICLENUMBER, String.Empty)
|
||||
|
||||
' EAN was found, now we need to check it against the Regex of the current Mandantor, if one exists
|
||||
Dim oMappingConfigItems = MappingConfig.Items.
|
||||
Where(Function(item) item.DestinationName = "MANDATOR" And item.DestinationValue = oMandator.Id And item.SourceName = "ARTICLE").
|
||||
ToList()
|
||||
|
||||
' If not match was found, continune to next mandator.
|
||||
' For a catch all mandator, a regex like ".+" is needed.
|
||||
For Each oItem In oMappingConfigItems
|
||||
Try
|
||||
Dim oRegex As New Regex(oItem.SourceRegex)
|
||||
Dim oMatch = oRegex.Match(oArticleNumber)
|
||||
|
||||
' If ArticleNumber matches the regex, we assign it and exit
|
||||
If oMatch.Success Then
|
||||
Return oMandator
|
||||
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
|
||||
Next ' CONFIG ITEM
|
||||
Next ' MANDATOR
|
||||
Next ' EAN
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Public Function GetDocuments(pMandator As Mandator, pTemplate As Template, pDocumentType As DocumentType, pOptions As GetDocumentArgs) As List(Of ExportDocument)
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
|
||||
If pOptions.Year > 0 Then
|
||||
oYear = Config.GetWinLineYear(pOptions.Year)
|
||||
End If
|
||||
|
||||
Dim oTypeConstraint
|
||||
Select Case pDocumentType
|
||||
Case DocumentType.OutgoingOffer
|
||||
oTypeConstraint = $"T.c137 = 2 AND c139 = 1 AND "
|
||||
|
||||
Case DocumentType.OutgoingOrder
|
||||
oTypeConstraint = $"T.c137 = 2 AND c139 = 2 AND "
|
||||
|
||||
Case DocumentType.OutgoingDeliveryNote
|
||||
oTypeConstraint = $"T.c137 = 2 AND (c139 = 3 OR c139 = -3) AND "
|
||||
|
||||
Case DocumentType.OutgoingInvoice
|
||||
oTypeConstraint = $"T.c137 = 2 AND c139 = 4 AND "
|
||||
|
||||
Case DocumentType.IncomingOffer
|
||||
oTypeConstraint = $"T.c137 = 3 AND c139 = 1 AND "
|
||||
|
||||
Case DocumentType.IncomingOrder
|
||||
oTypeConstraint = $"T.c137 = 3 AND c139 = 2 AND "
|
||||
|
||||
Case DocumentType.IncomingDeliveryNote
|
||||
oTypeConstraint = $"T.c137 = 3 AND c139 = 3 AND "
|
||||
|
||||
Case DocumentType.IncomingInvoice
|
||||
oTypeConstraint = $"T.c137 = 3 AND c139 = 4 AND "
|
||||
|
||||
Case Else
|
||||
oTypeConstraint = ""
|
||||
End Select
|
||||
|
||||
Dim oAccountConstraint = ""
|
||||
If pOptions.Account IsNot Nothing Then
|
||||
oAccountConstraint = $"T.c021 = '{pOptions.Account.Id}' AND "
|
||||
End If
|
||||
|
||||
Dim oKindConstraint = ""
|
||||
If pOptions.Kinds IsNot Nothing AndAlso pOptions.Kinds.Count > 0 Then
|
||||
Dim oKindIdList = pOptions.Kinds.Select(Function(kind) kind.Id)
|
||||
Dim oKindIdString = String.Join(",", oKindIdList)
|
||||
|
||||
oKindConstraint = $"T.c035 IN ({oKindIdString}) AND "
|
||||
End If
|
||||
|
||||
Dim oDateFromConstraint = ""
|
||||
If pOptions.DateFrom <> Date.MinValue Then
|
||||
oDateFromConstraint = $"T2.DATE >= CAST('{pOptions.DateFrom:yyyy-MM-dd}' as date) AND "
|
||||
End If
|
||||
|
||||
Dim oDateToConstraint = ""
|
||||
If pOptions.DateTo <> Date.MinValue Then
|
||||
oDateToConstraint = $"T2.DATE <= CAST('{pOptions.DateTo:yyyy-MM-dd}' as date) AND "
|
||||
End If
|
||||
|
||||
Dim oDocNumberConstraint = ""
|
||||
If pOptions.DocNumberFrom <> String.Empty Then
|
||||
oDocNumberConstraint &= $"T.c044 >= '{pOptions.DocNumberFrom}' AND "
|
||||
End If
|
||||
If pOptions.DocNumberTo <> String.Empty Then
|
||||
oDocNumberConstraint &= $"T.c044 <= '{pOptions.DocNumberTo}' AND "
|
||||
End If
|
||||
|
||||
' Build the constraint so that the default view will show all documents that do not have an exported
|
||||
' flag set to the current document type.
|
||||
' Ex. Search for orders will not show exported flag = 2 by default
|
||||
Dim oDocType As Integer = Math.Abs(Convert.ToInt32(pDocumentType))
|
||||
Dim oExportedConstraint = $"(T.U010 IS NULL OR T.U010 <> {oDocType}) AND"
|
||||
If pOptions.ShowExported Then
|
||||
oExportedConstraint = ""
|
||||
End If
|
||||
|
||||
Dim oSql = $"
|
||||
SELECT
|
||||
T2.DATE,
|
||||
T.c139 DOCUMENT_TYPE,
|
||||
T.c035 DOCUMENT_KIND,
|
||||
T.c021 ACCOUNT_NUMBER,
|
||||
T.c022 RUNNING_NUMBER,
|
||||
T.c043 OFFER_NUMBER,
|
||||
T.c027 OFFER_DATE,
|
||||
T.c044 ORDER_NUMBER,
|
||||
T.c028 ORDER_DATE,
|
||||
T.c045 DELIVERY_NUMBER,
|
||||
T.c029 DELIVERY_DATE,
|
||||
T.c055 INVOICE_NUMBER,
|
||||
T.c032 INVOICE_DATE,
|
||||
T.c100 GROSS_AMOUNT,
|
||||
T.c114 NET_AMOUNT,
|
||||
T.U010 ALREADY_EXPORTED,
|
||||
T.U011 EXPORTED_WHO,
|
||||
T.U012 EXPORTED_WHEN,
|
||||
T.U013 EXPORTED_FILE
|
||||
FROM [{pMandator.Database}].[dbo].[T025] T
|
||||
INNER JOIN (SELECT * FROM (
|
||||
SELECT c021, c022, mesoyear, mesocomp, c027 [DATE] FROM [{pMandator.Database}].[dbo].[T025]
|
||||
WHERE c139 = 1 OR c139 = -1
|
||||
UNION
|
||||
SELECT c021, c022, mesoyear, mesocomp, c028 [DATE] FROM [{pMandator.Database}].[dbo].[T025]
|
||||
WHERE c139 = 2 OR c139 = -2
|
||||
UNION
|
||||
SELECT c021, c022, mesoyear, mesocomp, c029 [DATE] FROM [{pMandator.Database}].[dbo].[T025]
|
||||
WHERE c139 = 3 OR c139 = -3
|
||||
UNION
|
||||
SELECT c021, c022, mesoyear, mesocomp, c032 [DATE] FROM [{pMandator.Database}].[dbo].[T025]
|
||||
WHERE c139 = 4 OR c139 = -4
|
||||
) QUERY) T2 ON T.c021 = T2.c021 AND T.c022 = T2.c022 AND T.mesoyear = T2.mesoyear AND T.mesocomp = T2.mesocomp
|
||||
WHERE
|
||||
{oTypeConstraint}
|
||||
{oAccountConstraint}
|
||||
{oKindConstraint}
|
||||
{oExportedConstraint}
|
||||
{oDocNumberConstraint}
|
||||
{oDateFromConstraint}
|
||||
{oDateToConstraint}
|
||||
T.[mesocomp] = '{pMandator.Id}' AND T.[mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSql)
|
||||
Dim oDocuments As New List(Of ExportDocument)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Try
|
||||
Dim oDocument = GetDocumentFromDataRow(oRow)
|
||||
oDocument.Schema = pTemplate
|
||||
oDocuments.Add(oDocument)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Next
|
||||
|
||||
Return oDocuments
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error while loading documents for mandator [{0}] and document type [{1}]", pMandator, pDocumentType)
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function ExecuteFinalSQL(pDocument As ExportDocument, pTemplate As Template, pMandator As Mandator) As Task(Of Boolean)
|
||||
Try
|
||||
Dim oSql As String = Patterns.ReplaceForExport(pDocument, pMandator, pTemplate.FinalSQL)
|
||||
Return Await Database.ExecuteNonQueryAsync(oSql)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetDocumentFromDataRow(pDataRow As DataRow) As ExportDocument
|
||||
Dim oAccountNumber = pDataRow.Item("ACCOUNT_NUMBER")
|
||||
Dim oRunningNumber As String = pDataRow.Item("RUNNING_NUMBER")
|
||||
Dim oDocumentType As Integer = pDataRow.Item("DOCUMENT_TYPE")
|
||||
Dim oDocumentKind As Integer = pDataRow.Item("DOCUMENT_KIND")
|
||||
Dim oGrossAmount As Double = pDataRow.Item("GROSS_AMOUNT")
|
||||
Dim oNetAmount As Double = pDataRow.Item("NET_AMOUNT")
|
||||
Dim oExported As Boolean = pDataRow.ItemEx("ALREADY_EXPORTED", False)
|
||||
Dim oExportedWho As String = pDataRow.ItemEx("EXPORTED_WHO", "")
|
||||
Dim oExportedWhen As Date = pDataRow.ItemEx(Of Date)("EXPORTED_WHEN", Nothing)
|
||||
Dim oExportFile As String = pDataRow.ItemEx("EXPORTED_FILE", "")
|
||||
|
||||
Dim oDocumentNumber As String = Nothing
|
||||
Dim oDocumentDate As Date = Nothing
|
||||
Dim oDocumentDateColumn As String = Nothing
|
||||
|
||||
Dim oAccount = Accounts.
|
||||
Where(Function(acc) acc.Id = oAccountNumber).
|
||||
FirstOrDefault()
|
||||
|
||||
Dim oKind = DocumentKinds.
|
||||
Where(Function(kind) kind.Id = oDocumentKind).
|
||||
FirstOrDefault()
|
||||
|
||||
Select Case oDocumentType
|
||||
Case 1
|
||||
oDocumentNumber = pDataRow.Item("OFFER_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("OFFER_DATE")
|
||||
oDocumentDateColumn = "c027"
|
||||
Case 2
|
||||
oDocumentNumber = pDataRow.Item("ORDER_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("ORDER_DATE")
|
||||
oDocumentDateColumn = "c028"
|
||||
Case 3
|
||||
oDocumentNumber = pDataRow.Item("DELIVERY_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("DELIVERY_DATE")
|
||||
oDocumentDateColumn = "c029"
|
||||
Case 4
|
||||
oDocumentNumber = pDataRow.Item("INVOICE_NUMBER")
|
||||
oDocumentDate = pDataRow.Item("INVOICE_DATE")
|
||||
oDocumentDateColumn = "c032"
|
||||
|
||||
End Select
|
||||
|
||||
Dim oDocument As New ExportDocument With {
|
||||
.Account = oAccount,
|
||||
.RunningNumber = oRunningNumber,
|
||||
.Number = oDocumentNumber,
|
||||
.[Date] = oDocumentDate,
|
||||
.DateColumn = oDocumentDateColumn,
|
||||
.Kind = oKind,
|
||||
.GrossAmount = oGrossAmount,
|
||||
.NetAmount = oNetAmount,
|
||||
.IsExported = oExported,
|
||||
.ExportedWhen = oExportedWhen,
|
||||
.ExportedWho = oExportedWho,
|
||||
.FilenameExport = oExportFile
|
||||
}
|
||||
|
||||
Return oDocument
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Turns a database info like "SQLCWLDATEN on SERVER\INSTANCE" into a Tuple of two strings
|
||||
''' </summary>
|
||||
''' <param name="pRow"></param>
|
||||
''' <returns></returns>
|
||||
Private Function SplitConnectionInfo(pRow As DataRow) As Tuple(Of String, String)
|
||||
Dim oDbInfo = pRow.Item(T01_DATABASEINFO).ToString()
|
||||
Dim oSplittedInfo = SplitAtString(oDbInfo.ToUpper, "ON")
|
||||
Dim oServer = oSplittedInfo.Item(1).Trim()
|
||||
|
||||
Dim oDatabase = oSplittedInfo.Item(0).Trim()
|
||||
If oDatabase.StartsWith("SQL") Then
|
||||
oDatabase = oDatabase.Remove(0, 3)
|
||||
End If
|
||||
|
||||
Return New Tuple(Of String, String)(oDatabase, oServer)
|
||||
End Function
|
||||
|
||||
Private Function SplitAtString(pStringToSplit As String, pDelimiter As String) As List(Of String)
|
||||
Dim oDelimiter As String() = New String(0) {pDelimiter}
|
||||
Return pStringToSplit.
|
||||
Split(oDelimiter, StringSplitOptions.None).
|
||||
ToList()
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user