MultiTool/EDIDocumentImport/WinLineInfo.vb
Jonathan Jenne 50c1e86219 WIP
2021-08-06 16:21:28 +02:00

99 lines
3.2 KiB
VB.net

Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Database
Public Class WinLineInfo
Inherits Base
Private Database As MSSQLServer
Public Accounts As New List(Of Account)
Public Mandators As New List(Of Mandator)
Public Years As List(Of Integer)
Public Class Account
Public Property Id As String
Public Property Name As String
Public Property Mandator As String
Public Overrides Function ToString() As String
Return $"{Name} ({Id})"
End Function
End Class
Public Class Mandator
Public Property Id As String
Public Property Name As String
Public Property Database As String
Public Property Server As String
Public Overrides Function ToString() As String
Return $"{Name} ({Id})"
End Function
End Class
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
MyBase.New(pLogConfig, pLogConfig.GetLogger())
Database = pDatabase
End Sub
Public Sub LoadAccounts(pMandator As Mandator)
Dim oSQL = $"SELECT [c002], [c003] FROM [{pMandator.Server}].[{pMandator.Database}].[dbo].[v005] WHERE c139 IS NULL"
Dim oTable = Database.GetDatatable(oSQL)
For Each oRow As DataRow In oTable.Rows
Accounts.Add(New Account With {
.Id = oRow.Item("c002"),
.Name = oRow.Item("c003"),
.Mandator = pMandator.Id
})
Next
End Sub
Public Sub LoadMandators()
Dim oSQL = "SELECT [c000], [c003], [c004] FROM [cwlsystem].[dbo].[T001SRV] (NOLOCK)"
Dim oTable = Database.GetDatatable(oSQL)
Mandators.Clear()
For Each oRow As DataRow In oTable.Rows
Dim oDbInfo = SplitConnectionInfo(oRow)
Mandators.Add(New Mandator With {
.Id = oRow.Item("c000"),
.Name = oRow.Item("c003"),
.Database = oDbInfo.Item1,
.Server = oDbInfo.Item2
})
Next
End Sub
Public Sub LoadEconomicYears()
Dim oCurrentYear = Now.Year
Dim oRange As IEnumerable(Of Integer) = Enumerable.Range(oCurrentYear - 10, 12).ToList()
Years = oRange
End Sub
''' <summary>
''' Turns a database info like "CWLDATEN 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("c004").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