2020-09-14 17:08:43 +02:00

85 lines
3.7 KiB
VB.net

Public Class frmMain
Private _Logger As Logger
Private _Database As Database
Private _WinLine As Winline
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
My.Application.LogConfig = New LogConfig(LogPath:=LogConfig.PathType.AppData, CompanyName:="Digital Data", ProductName:="WinLineProductNumberGenerator")
My.Application.ConfigManager = New ConfigManager(Of Config)(My.Application.LogConfig, Application.UserAppDataPath)
_Logger = My.Application.LogConfig.GetLogger()
_Database = New Database(My.Application.LogConfig, My.Application.ConfigManager)
_WinLine = New Winline(My.Application.LogConfig, _Database)
listboxVendors.DataSource = Nothing
Dim oVendors = _WinLine.GetVendors()
listboxVendors.DataSource = oVendors
End Sub
Private Sub frmMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
My.Application.ConfigManager.Save()
End Sub
Private Sub listboxVendors_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listboxVendors.SelectedIndexChanged
If listboxVendors.SelectedItem IsNot Nothing Then
Dim oVendor As Vendor = listboxVendors.SelectedItem
Dim oGroups As List(Of ProductGroup) = _WinLine.GetGroupsByVendor(oVendor.Code)
listboxProductGroups.DataSource = oGroups
End If
End Sub
Private Sub listboxProductGroups_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listboxProductGroups.SelectedIndexChanged
If listboxProductGroups.SelectedItem IsNot Nothing Then
Dim oGroup As ProductGroup = listboxProductGroups.SelectedItem
Dim oVersions As List(Of ProductVersion) = _WinLine.GetVersionsByVendorAndGroup(oGroup.Code, oGroup.GroupId)
listBoxProductVersion.DataSource = oVersions
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim oVendor As Vendor = listboxVendors.SelectedItem()
Dim oGroup As ProductGroup = listboxProductGroups.SelectedItem()
Dim oVersion As ProductVersion = 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 oArticleNumber = $"{oVendor.Code}{oGroup.GroupString}{oVersion.VersionString}"
Try
Dim oRunningNumber = _WinLine.GetNextRunningNumber(oVendor.Code, oGroup.GroupId, oVersion.VersionId)
MsgBox($"{oArticleNumber}{oRunningNumber}")
Catch ex As Exception
Select Case ex.Message
Case _WinLine.NO_RUNNING_NUMBER_FOUND
Dim oMessage = $"Für die Artikelnummer [{oArticleNumber}___] wurde im WinLine-System keine Laufende Nummer hinterlegt."
oMessage &= "Diese Nummer ist für die Automatische Artikelnummer-Generierung zwingend notwendig"
MsgBox(oMessage, MsgBoxStyle.Critical, Text)
Case Else
MsgBox("Folgender Fehler ist aufgetreten:" & vbNewLine & vbNewLine & ex.Message, MsgBoxStyle.Critical, Text)
End Select
End Try
End Sub
Private Sub EinstellungenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EinstellungenToolStripMenuItem.Click
frmWinlineConfig.ShowDialog()
End Sub
End Class