diff --git a/WinLineArtikelnummerGenerator/Database.vb b/WinLineArtikelnummerGenerator/Database.vb
index 6f90e37..aac68a4 100644
--- a/WinLineArtikelnummerGenerator/Database.vb
+++ b/WinLineArtikelnummerGenerator/Database.vb
@@ -13,22 +13,6 @@ Public Class Database
_Config = ConfigManager
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"
Private Function GetSQLConnection() As SqlConnection
Return GetSQLConnection(_Config.Config.ConnectionString)
diff --git a/WinLineArtikelnummerGenerator/Models/ProductGroup.vb b/WinLineArtikelnummerGenerator/Models/ProductGroup.vb
index 0924337..5942011 100644
--- a/WinLineArtikelnummerGenerator/Models/ProductGroup.vb
+++ b/WinLineArtikelnummerGenerator/Models/ProductGroup.vb
@@ -1,11 +1,9 @@
Public Class ProductGroup
- Public Guid As Integer
- Public Name As String
- Public NickName As String
+ Public Property Id As Integer
+ Public Property Vendor As String
+ Public Property Name As String
- Public Property Versions As List(Of ProductVersion)
-
- Public Sub New()
- Versions = New List(Of ProductVersion)
- End Sub
+ Public Overrides Function ToString() As String
+ Return $"{Id.ToString.PadLeft(2, "0")} - {Name}"
+ End Function
End Class
diff --git a/WinLineArtikelnummerGenerator/Models/ProductVersion.vb b/WinLineArtikelnummerGenerator/Models/ProductVersion.vb
index 48406bb..3ee759f 100644
--- a/WinLineArtikelnummerGenerator/Models/ProductVersion.vb
+++ b/WinLineArtikelnummerGenerator/Models/ProductVersion.vb
@@ -1,4 +1,9 @@
Public Class ProductVersion
- Public Guid As Integer
- Public Name As String
+ Public Property Id As Integer
+ 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
diff --git a/WinLineArtikelnummerGenerator/Models/Vendor.vb b/WinLineArtikelnummerGenerator/Models/Vendor.vb
index 691aa37..c39a47c 100644
--- a/WinLineArtikelnummerGenerator/Models/Vendor.vb
+++ b/WinLineArtikelnummerGenerator/Models/Vendor.vb
@@ -1,5 +1,8 @@
Public Class Vendor
- Public Guid As Integer
- Public Id As String
- Public Name As String
+ Public Property Code As String
+ Public Property Name As String
+
+ Public Overrides Function ToString() As String
+ Return $"{Code} - {Name}"
+ End Function
End Class
diff --git a/WinLineArtikelnummerGenerator/WinLineArtikelnummerGenerator.vbproj b/WinLineArtikelnummerGenerator/WinLineArtikelnummerGenerator.vbproj
index b73b935..1799bfe 100644
--- a/WinLineArtikelnummerGenerator/WinLineArtikelnummerGenerator.vbproj
+++ b/WinLineArtikelnummerGenerator/WinLineArtikelnummerGenerator.vbproj
@@ -145,6 +145,7 @@
+
diff --git a/WinLineArtikelnummerGenerator/Winline.vb b/WinLineArtikelnummerGenerator/Winline.vb
new file mode 100644
index 0000000..9b3ac97
--- /dev/null
+++ b/WinLineArtikelnummerGenerator/Winline.vb
@@ -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
+
diff --git a/WinLineArtikelnummerGenerator/frmMain.Designer.vb b/WinLineArtikelnummerGenerator/frmMain.Designer.vb
index 5f33330..2df90e7 100644
--- a/WinLineArtikelnummerGenerator/frmMain.Designer.vb
+++ b/WinLineArtikelnummerGenerator/frmMain.Designer.vb
@@ -22,7 +22,6 @@ Partial Class frmMain
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
_
Private Sub InitializeComponent()
- Me.listboxVendors = New System.Windows.Forms.ListBox()
Me.listboxProductGroups = New System.Windows.Forms.ListBox()
Me.Label1 = 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.Button3 = New System.Windows.Forms.Button()
Me.Label3 = New System.Windows.Forms.Label()
+ Me.listboxVendors = New System.Windows.Forms.ListBox()
+ Me.Button4 = New System.Windows.Forms.Button()
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
'
- 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.ItemHeight = 15
- Me.listboxProductGroups.Location = New System.Drawing.Point(345, 67)
+ Me.listboxProductGroups.ItemHeight = 17
+ Me.listboxProductGroups.Location = New System.Drawing.Point(268, 67)
Me.listboxProductGroups.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
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
'
'Label1
@@ -69,7 +59,7 @@ Partial Class frmMain
'
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.Location = New System.Drawing.Point(342, 18)
+ Me.Label2.Location = New System.Drawing.Point(265, 19)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(97, 15)
Me.Label2.TabIndex = 1
@@ -77,7 +67,7 @@ Partial Class frmMain
'
'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.Size = New System.Drawing.Size(140, 23)
Me.Button1.TabIndex = 2
@@ -97,18 +87,18 @@ Partial Class frmMain
'
'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.ItemHeight = 15
- Me.listBoxProductVersion.Location = New System.Drawing.Point(678, 67)
+ Me.listBoxProductVersion.ItemHeight = 17
+ Me.listBoxProductVersion.Location = New System.Drawing.Point(524, 67)
Me.listBoxProductVersion.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
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
'
'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.Size = New System.Drawing.Size(140, 23)
Me.Button3.TabIndex = 2
@@ -120,17 +110,38 @@ Partial Class frmMain
'
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.Location = New System.Drawing.Point(675, 18)
+ Me.Label3.Location = New System.Drawing.Point(521, 19)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(90, 15)
Me.Label3.TabIndex = 1
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
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(7.0!, 15.0!)
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.Button3)
Me.Controls.Add(Me.Button1)
@@ -148,8 +159,6 @@ Partial Class frmMain
Me.PerformLayout()
End Sub
-
- Friend WithEvents listboxVendors As ListBox
Friend WithEvents listboxProductGroups As ListBox
Friend WithEvents Label1 As Label
Friend WithEvents Label2 As Label
@@ -158,4 +167,6 @@ Partial Class frmMain
Friend WithEvents listBoxProductVersion As ListBox
Friend WithEvents Button3 As Button
Friend WithEvents Label3 As Label
+ Friend WithEvents listboxVendors As ListBox
+ Friend WithEvents Button4 As Button
End Class
diff --git a/WinLineArtikelnummerGenerator/frmMain.vb b/WinLineArtikelnummerGenerator/frmMain.vb
index 9863f9c..65a0a8b 100644
--- a/WinLineArtikelnummerGenerator/frmMain.vb
+++ b/WinLineArtikelnummerGenerator/frmMain.vb
@@ -3,21 +3,24 @@
Private _LogConfig As LogConfig
Private _Config As ConfigManager(Of Config)
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
_LogConfig = New LogConfig(LogPath:=LogConfig.PathType.AppData, CompanyName:="Digital Data", ProductName:="WinLineProductNumberGenerator")
_Logger = _LogConfig.GetLogger()
_Config = New ConfigManager(Of Config)(_LogConfig, Application.UserAppDataPath)
_Database = New Database(_LogConfig, _Config)
+ _WinLine = New Winline(_LogConfig, _Database)
listboxVendors.DataSource = Nothing
- Dim oVendorDT = _Database.LoadVendors()
- Dim oVendors = New List(Of Vendor)
+ Dim oVendors = _WinLine.GetVendors()
- listboxVendors.DataSource = oVendorDT
- listboxVendors.DisplayMember = "c003"
- listboxVendors.ValueMember = "c229"
+ listboxVendors.DataSource = oVendors
End Sub
Private Sub frmMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
@@ -25,36 +28,66 @@
End Sub
Private Sub listboxVendors_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listboxVendors.SelectedIndexChanged
- If listboxVendors.SelectedIndex >= 0 Then
- Dim oVendor As DataRowView = listboxVendors.SelectedItem()
- Dim oVendorCode = oVendor.Item("C229")
- Dim oVendorId = _Database.LoadVendorIdByCode(oVendorCode)
+ If listboxVendors.SelectedItem IsNot Nothing Then
+ Dim oVendor As Vendor = listboxVendors.SelectedItem
+ CurrentVendor = oVendor
- listboxProductGroups.DataSource = Nothing
-
- If oVendorId Is Nothing Then
- _Logger.Warn("VendorId does not match any 'Artikeluntergruppen'.")
- Exit Sub
- End If
-
- Dim oGroups = _Database.LoadGroupsByVendor(oVendorId)
+ Dim oGroups As List(Of ProductGroup) = _WinLine.GetGroupsByVendor(oVendor.Code)
listboxProductGroups.DataSource = oGroups
- listboxProductGroups.DisplayMember = "C001"
- listboxProductGroups.ValueMember = "C999"
End If
+
End Sub
Private Sub listboxProductGroups_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listboxProductGroups.SelectedIndexChanged
- If listboxProductGroups.SelectedIndex >= 0 Then
- Dim oVendor As DataRowView = listboxVendors.SelectedItem()
- Dim oGroup As DataRowView = listboxProductGroups.SelectedItem()
+ If listboxProductGroups.SelectedItem IsNot Nothing Then
+ Dim oGroup As ProductGroup = listboxProductGroups.SelectedItem
+ CurrentGroup = oGroup
- Dim oVendorCode = oVendor.Item("C229")
- Dim oVendorId = _Database.LoadVendorIdByCode(oVendorCode)
- Dim oGroupId = oGroup.Item("C999")
+ Dim oVersions As List(Of ProductVersion) = _WinLine.GetVersionsByVendorAndGroup(oGroup.Vendor, oGroup.Id)
- Dim Versions = _Database.LoadVersionsByVendorAndGroup(oVendorId, oGroupId)
+ listBoxProductVersion.DataSource = oVersions
End If
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
\ No newline at end of file