This commit is contained in:
Jonathan Jenne 2020-09-11 15:56:50 +02:00
parent 614b415a98
commit c9bd8da4a6
8 changed files with 228 additions and 82 deletions

View File

@ -13,22 +13,6 @@ Public Class Database
_Config = ConfigManager _Config = ConfigManager
End Sub End Sub
Public Function LoadVendors() As DataTable
Return GetDatatable("SELECT C229, C003 FROM V050 WHERE C229 IS NOT NULL")
End Function
Public Function LoadVendorIdByCode(VendorCode As String) As String
Return GetScalarValue($"SELECT SUBSTRING(C000,0,6) C999 FROM T309 WHERE C001 = '{VendorCode}' AND C002 = 1")
End Function
Public Function LoadGroupsByVendor(VendorId As String) As DataTable
Return GetDatatable($"SELECT C001, SUBSTRING(C000,7,5) C999 FROM T309 WHERE C000 LIKE '{VendorId}%' AND C002 = 2 AND C001 LIKE '__ | %'")
End Function
Public Function LoadVersionsByVendorAndGroup(VendorId As String, GroupId As String) As DataTable
Return GetDatatable($"SELECT C001 FROM T309 WHERE C000 LIKE '{VendorId}-{GroupId}-%' AND C002 = 3 AND C001 LIKE '__ | %'")
End Function
#Region "Database-Access" #Region "Database-Access"
Private Function GetSQLConnection() As SqlConnection Private Function GetSQLConnection() As SqlConnection
Return GetSQLConnection(_Config.Config.ConnectionString) Return GetSQLConnection(_Config.Config.ConnectionString)

View File

@ -1,11 +1,9 @@
Public Class ProductGroup Public Class ProductGroup
Public Guid As Integer Public Property Id As Integer
Public Name As String Public Property Vendor As String
Public NickName As String Public Property Name As String
Public Property Versions As List(Of ProductVersion) Public Overrides Function ToString() As String
Return $"{Id.ToString.PadLeft(2, "0")} - {Name}"
Public Sub New() End Function
Versions = New List(Of ProductVersion)
End Sub
End Class End Class

View File

@ -1,4 +1,9 @@
Public Class ProductVersion Public Class ProductVersion
Public Guid As Integer Public Property Id As Integer
Public Name As String Public Property Name As String
Public Property Part As Integer
Public Overrides Function ToString() As String
Return $"{Id.ToString.PadLeft(2, "0")} - {Name}"
End Function
End Class End Class

View File

@ -1,5 +1,8 @@
Public Class Vendor Public Class Vendor
Public Guid As Integer Public Property Code As String
Public Id As String Public Property Name As String
Public Name As String
Public Overrides Function ToString() As String
Return $"{Code} - {Name}"
End Function
End Class End Class

View File

@ -145,6 +145,7 @@
</Compile> </Compile>
<Compile Include="Models\Vendor.vb" /> <Compile Include="Models\Vendor.vb" />
<Compile Include="Database.vb" /> <Compile Include="Database.vb" />
<Compile Include="Winline.vb" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="frmMain.resx"> <EmbeddedResource Include="frmMain.resx">

View File

@ -0,0 +1,111 @@
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

View File

@ -22,7 +22,6 @@ Partial Class frmMain
'Das Bearbeiten mit dem Code-Editor ist nicht möglich. 'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()> _ <System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent() Private Sub InitializeComponent()
Me.listboxVendors = New System.Windows.Forms.ListBox()
Me.listboxProductGroups = New System.Windows.Forms.ListBox() Me.listboxProductGroups = New System.Windows.Forms.ListBox()
Me.Label1 = New System.Windows.Forms.Label() Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label() Me.Label2 = New System.Windows.Forms.Label()
@ -31,28 +30,19 @@ Partial Class frmMain
Me.listBoxProductVersion = New System.Windows.Forms.ListBox() Me.listBoxProductVersion = New System.Windows.Forms.ListBox()
Me.Button3 = New System.Windows.Forms.Button() Me.Button3 = New System.Windows.Forms.Button()
Me.Label3 = New System.Windows.Forms.Label() Me.Label3 = New System.Windows.Forms.Label()
Me.listboxVendors = New System.Windows.Forms.ListBox()
Me.Button4 = New System.Windows.Forms.Button()
Me.SuspendLayout() Me.SuspendLayout()
' '
'listboxVendors
'
Me.listboxVendors.Font = New System.Drawing.Font("Consolas", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.listboxVendors.FormattingEnabled = True
Me.listboxVendors.ItemHeight = 15
Me.listboxVendors.Location = New System.Drawing.Point(12, 67)
Me.listboxVendors.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.listboxVendors.Name = "listboxVendors"
Me.listboxVendors.Size = New System.Drawing.Size(327, 244)
Me.listboxVendors.TabIndex = 0
'
'listboxProductGroups 'listboxProductGroups
' '
Me.listboxProductGroups.Font = New System.Drawing.Font("Consolas", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.listboxProductGroups.Font = New System.Drawing.Font("Segoe UI", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.listboxProductGroups.FormattingEnabled = True Me.listboxProductGroups.FormattingEnabled = True
Me.listboxProductGroups.ItemHeight = 15 Me.listboxProductGroups.ItemHeight = 17
Me.listboxProductGroups.Location = New System.Drawing.Point(345, 67) Me.listboxProductGroups.Location = New System.Drawing.Point(268, 67)
Me.listboxProductGroups.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4) Me.listboxProductGroups.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.listboxProductGroups.Name = "listboxProductGroups" Me.listboxProductGroups.Name = "listboxProductGroups"
Me.listboxProductGroups.Size = New System.Drawing.Size(327, 244) Me.listboxProductGroups.Size = New System.Drawing.Size(250, 242)
Me.listboxProductGroups.TabIndex = 0 Me.listboxProductGroups.TabIndex = 0
' '
'Label1 'Label1
@ -69,7 +59,7 @@ Partial Class frmMain
' '
Me.Label2.AutoSize = True Me.Label2.AutoSize = True
Me.Label2.Font = New System.Drawing.Font("Segoe UI Semibold", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Font = New System.Drawing.Font("Segoe UI Semibold", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(342, 18) Me.Label2.Location = New System.Drawing.Point(265, 19)
Me.Label2.Name = "Label2" Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(97, 15) Me.Label2.Size = New System.Drawing.Size(97, 15)
Me.Label2.TabIndex = 1 Me.Label2.TabIndex = 1
@ -77,7 +67,7 @@ Partial Class frmMain
' '
'Button1 'Button1
' '
Me.Button1.Location = New System.Drawing.Point(345, 36) Me.Button1.Location = New System.Drawing.Point(268, 37)
Me.Button1.Name = "Button1" Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(140, 23) Me.Button1.Size = New System.Drawing.Size(140, 23)
Me.Button1.TabIndex = 2 Me.Button1.TabIndex = 2
@ -97,18 +87,18 @@ Partial Class frmMain
' '
'listBoxProductVersion 'listBoxProductVersion
' '
Me.listBoxProductVersion.Font = New System.Drawing.Font("Consolas", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.listBoxProductVersion.Font = New System.Drawing.Font("Segoe UI", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.listBoxProductVersion.FormattingEnabled = True Me.listBoxProductVersion.FormattingEnabled = True
Me.listBoxProductVersion.ItemHeight = 15 Me.listBoxProductVersion.ItemHeight = 17
Me.listBoxProductVersion.Location = New System.Drawing.Point(678, 67) Me.listBoxProductVersion.Location = New System.Drawing.Point(524, 67)
Me.listBoxProductVersion.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4) Me.listBoxProductVersion.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.listBoxProductVersion.Name = "listBoxProductVersion" Me.listBoxProductVersion.Name = "listBoxProductVersion"
Me.listBoxProductVersion.Size = New System.Drawing.Size(327, 244) Me.listBoxProductVersion.Size = New System.Drawing.Size(250, 242)
Me.listBoxProductVersion.TabIndex = 0 Me.listBoxProductVersion.TabIndex = 0
' '
'Button3 'Button3
' '
Me.Button3.Location = New System.Drawing.Point(678, 36) Me.Button3.Location = New System.Drawing.Point(524, 37)
Me.Button3.Name = "Button3" Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(140, 23) Me.Button3.Size = New System.Drawing.Size(140, 23)
Me.Button3.TabIndex = 2 Me.Button3.TabIndex = 2
@ -120,17 +110,38 @@ Partial Class frmMain
' '
Me.Label3.AutoSize = True Me.Label3.AutoSize = True
Me.Label3.Font = New System.Drawing.Font("Segoe UI Semibold", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Font = New System.Drawing.Font("Segoe UI Semibold", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(675, 18) Me.Label3.Location = New System.Drawing.Point(521, 19)
Me.Label3.Name = "Label3" Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(90, 15) Me.Label3.Size = New System.Drawing.Size(90, 15)
Me.Label3.TabIndex = 1 Me.Label3.TabIndex = 1
Me.Label3.Text = "Produktversion:" Me.Label3.Text = "Produktversion:"
' '
'listboxVendors
'
Me.listboxVendors.Font = New System.Drawing.Font("Segoe UI", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.listboxVendors.FormattingEnabled = True
Me.listboxVendors.ItemHeight = 17
Me.listboxVendors.Location = New System.Drawing.Point(12, 67)
Me.listboxVendors.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.listboxVendors.Name = "listboxVendors"
Me.listboxVendors.Size = New System.Drawing.Size(250, 242)
Me.listboxVendors.TabIndex = 0
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(524, 316)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(250, 41)
Me.Button4.TabIndex = 3
Me.Button4.Text = "Generate"
Me.Button4.UseVisualStyleBackColor = True
'
'frmMain 'frmMain
' '
Me.AutoScaleDimensions = New System.Drawing.SizeF(7.0!, 15.0!) Me.AutoScaleDimensions = New System.Drawing.SizeF(7.0!, 15.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(1105, 430) Me.ClientSize = New System.Drawing.Size(793, 430)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button3) Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.Button1)
@ -148,8 +159,6 @@ Partial Class frmMain
Me.PerformLayout() Me.PerformLayout()
End Sub End Sub
Friend WithEvents listboxVendors As ListBox
Friend WithEvents listboxProductGroups As ListBox Friend WithEvents listboxProductGroups As ListBox
Friend WithEvents Label1 As Label Friend WithEvents Label1 As Label
Friend WithEvents Label2 As Label Friend WithEvents Label2 As Label
@ -158,4 +167,6 @@ Partial Class frmMain
Friend WithEvents listBoxProductVersion As ListBox Friend WithEvents listBoxProductVersion As ListBox
Friend WithEvents Button3 As Button Friend WithEvents Button3 As Button
Friend WithEvents Label3 As Label Friend WithEvents Label3 As Label
Friend WithEvents listboxVendors As ListBox
Friend WithEvents Button4 As Button
End Class End Class

View File

@ -3,21 +3,24 @@
Private _LogConfig As LogConfig Private _LogConfig As LogConfig
Private _Config As ConfigManager(Of Config) Private _Config As ConfigManager(Of Config)
Private _Database As Database Private _Database As Database
Private _WinLine As Winline
Private CurrentVendor As Vendor = Nothing
Private CurrentGroup As ProductGroup = Nothing
Private CurrentVersion As ProductVersion = Nothing
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
_LogConfig = New LogConfig(LogPath:=LogConfig.PathType.AppData, CompanyName:="Digital Data", ProductName:="WinLineProductNumberGenerator") _LogConfig = New LogConfig(LogPath:=LogConfig.PathType.AppData, CompanyName:="Digital Data", ProductName:="WinLineProductNumberGenerator")
_Logger = _LogConfig.GetLogger() _Logger = _LogConfig.GetLogger()
_Config = New ConfigManager(Of Config)(_LogConfig, Application.UserAppDataPath) _Config = New ConfigManager(Of Config)(_LogConfig, Application.UserAppDataPath)
_Database = New Database(_LogConfig, _Config) _Database = New Database(_LogConfig, _Config)
_WinLine = New Winline(_LogConfig, _Database)
listboxVendors.DataSource = Nothing listboxVendors.DataSource = Nothing
Dim oVendorDT = _Database.LoadVendors() Dim oVendors = _WinLine.GetVendors()
Dim oVendors = New List(Of Vendor)
listboxVendors.DataSource = oVendorDT listboxVendors.DataSource = oVendors
listboxVendors.DisplayMember = "c003"
listboxVendors.ValueMember = "c229"
End Sub End Sub
Private Sub frmMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed Private Sub frmMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
@ -25,36 +28,66 @@
End Sub End Sub
Private Sub listboxVendors_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listboxVendors.SelectedIndexChanged Private Sub listboxVendors_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listboxVendors.SelectedIndexChanged
If listboxVendors.SelectedIndex >= 0 Then If listboxVendors.SelectedItem IsNot Nothing Then
Dim oVendor As DataRowView = listboxVendors.SelectedItem() Dim oVendor As Vendor = listboxVendors.SelectedItem
Dim oVendorCode = oVendor.Item("C229") CurrentVendor = oVendor
Dim oVendorId = _Database.LoadVendorIdByCode(oVendorCode)
listboxProductGroups.DataSource = Nothing Dim oGroups As List(Of ProductGroup) = _WinLine.GetGroupsByVendor(oVendor.Code)
If oVendorId Is Nothing Then
_Logger.Warn("VendorId does not match any 'Artikeluntergruppen'.")
Exit Sub
End If
Dim oGroups = _Database.LoadGroupsByVendor(oVendorId)
listboxProductGroups.DataSource = oGroups listboxProductGroups.DataSource = oGroups
listboxProductGroups.DisplayMember = "C001"
listboxProductGroups.ValueMember = "C999"
End If End If
End Sub End Sub
Private Sub listboxProductGroups_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listboxProductGroups.SelectedIndexChanged Private Sub listboxProductGroups_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listboxProductGroups.SelectedIndexChanged
If listboxProductGroups.SelectedIndex >= 0 Then If listboxProductGroups.SelectedItem IsNot Nothing Then
Dim oVendor As DataRowView = listboxVendors.SelectedItem() Dim oGroup As ProductGroup = listboxProductGroups.SelectedItem
Dim oGroup As DataRowView = listboxProductGroups.SelectedItem() CurrentGroup = oGroup
Dim oVendorCode = oVendor.Item("C229") Dim oVersions As List(Of ProductVersion) = _WinLine.GetVersionsByVendorAndGroup(oGroup.Vendor, oGroup.Id)
Dim oVendorId = _Database.LoadVendorIdByCode(oVendorCode)
Dim oGroupId = oGroup.Item("C999")
Dim Versions = _Database.LoadVersionsByVendorAndGroup(oVendorId, oGroupId) listBoxProductVersion.DataSource = oVersions
End If End If
End Sub End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
'Dim oVendor As DataRowView = listboxVendors.SelectedItem()
'Dim oGroup As DataRowView = listboxProductGroups.SelectedItem()
'Dim oVersion As DataRowView = listBoxProductVersion.SelectedItem()
'If oVendor Is Nothing Then
' MsgBox("Bitte einen Lieferanten auswählen!", MsgBoxStyle.Information, Text)
' Exit Sub
'End If
'If oGroup Is Nothing Then
' MsgBox("Bitte eine Produkt-Gruppe auswählen!", MsgBoxStyle.Information, Text)
' Exit Sub
'End If
'If oVersion Is Nothing Then
' MsgBox("Bitte eine Produkt-Version auswählen!", MsgBoxStyle.Information, Text)
' Exit Sub
'End If
'Dim oVendorId = CurrentVendor.Id
'Dim oGroupId = CurrentGroup.Id
'Dim oVersionId = CurrentVersion.Id
'Dim oRunningNumber = _WinLine.GetNextRunningNumber(oVendorId, oGroupId, oVersionId)
'MsgBox($"{oVendorId}-{oGroupId}-{oVersionId}-00000-00000")
End Sub
Private Sub listBoxProductVersion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listBoxProductVersion.SelectedIndexChanged
'If listBoxProductVersion.SelectedIndex >= 0 Then
' Dim oVersion As DataRowView = listBoxProductVersion.SelectedItem()
' Dim oVersionId As String = oVersion.Item("C999")
' Dim oVersionName As String = oVersion.Item("C001")
' CurrentVersion = New ProductVersion With {
' .Id = oVersionId,
' .Name = oVersionName
' }
'End If
End Sub
End Class End Class