Jonathan Jenne c9bd8da4a6 jj
2020-09-11 15:56:50 +02:00

112 lines
3.6 KiB
VB.net

Public Class Winline
Private _LogConfig As LogConfig
Private _Logger As Logger
Private _Db As Database
Public Sub New(LogConfig As LogConfig, Database As Database)
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
_Db = Database
End Sub
Public Function GetVendors() As List(Of Vendor)
Try
Dim oDatatable As DataTable = _Db.GetDatatable("SELECT * FROM TBDD_ARTICLE_GENERATOR_VENDORS")
Dim oVendors As New List(Of Vendor)
For Each oRow As DataRow In oDatatable.Rows
Dim oVendor As New Vendor() With {
.Code = oRow.Item("CODE"),
.Name = oRow.Item("NAME")
}
oVendors.Add(oVendor)
Next
Return oVendors
Catch ex As Exception
_Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetGroupsByVendor(VendorCode As String) As List(Of ProductGroup)
Try
Dim oDatatable = _Db.GetDatatable($"SELECT * FROM TBDD_ARTICLE_GENERATOR_GROUPS WHERE CODE = '{VendorCode}'")
Dim oGroups As New List(Of ProductGroup)
For Each oRow As DataRow In oDatatable.Rows
Dim oGroup As New ProductGroup() With {
.Name = oRow.Item("NAME"),
.Id = oRow.Item("GROUP"),
.Vendor = oRow.Item("CODE")
}
oGroups.Add(oGroup)
Next
Return oGroups
Catch ex As Exception
_Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetVersionsByVendorAndGroup(VendorCode As String, GroupId As String) As List(Of ProductVersion)
Try
Dim oDatatable = _Db.GetDatatable($"SELECT * FROM TBDD_ARTICLE_GENERATOR_PRODUCTS WHERE VENDOR = '{VendorCode}' AND [GROUP] = {GroupId}")
Dim oVersions As New List(Of ProductVersion)
For Each oRow As DataRow In oDatatable.Rows
Dim oVersion As New ProductVersion() With {
.Id = oRow.Item("VERSION"),
.Name = oRow.Item("NAME"),
.Part = oRow.Item("PART")
}
oVersions.Add(oVersion)
Next
Return oVersions
Catch ex As Exception
_Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetVendorIdByCode(VendorCode As String) As String
Try
Return _Db.GetScalarValue($"SELECT SUBSTRING(C000,0,6) C999 FROM T309 WHERE C001 = '{VendorCode}' AND C002 = 1")
Catch ex As Exception
_Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetNextRunningNumber(VendorId As Integer, GroupId As Integer, VersionId As Integer) As Integer
Try
VendorId = VendorId.ToString.PadLeft(2)
GroupId = GroupId.ToString.PadLeft(2)
VersionId = VersionId.ToString.PadLeft(3)
Dim oResult = _Db.GetScalarValue($"SELECT MAX(C223) C999 FROM [CWLDATEN_MEDS].[dbo].[v021] where c078 LIKE '{VendorId}-{GroupId}-{VersionId}-_____-_____'")
If IsNothing(oResult) Then
Return 1
ElseIf IsNumeric(oResult) Then
Return Integer.Parse(oResult) + 1
Else
Return Nothing
End If
Catch ex As Exception
_Logger.Error(ex)
Return Nothing
End Try
End Function
End Class