Public Class frmMain Private _Logger As Logger Private _Database As Database Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try My.Application.LogConfig = New LogConfig( Suffix:=Environment.MachineName, LogPath:=LogConfig.PathType.CustomPath, CustomLogPath:=Application.StartupPath, CompanyName:="Digital Data", ProductName:="WinLineProductNumberGenerator" ) My.Application.ConfigManager = New ConfigManager(Of Config)( My.Application.LogConfig, Application.StartupPath ) _Logger = My.Application.LogConfig.GetLogger() Catch ex As Exception MsgBox("Fehler beim Initialisieren (Logging und Config):" & vbNewLine & ex.Message, MsgBoxStyle.Critical, Text) End Try Dim oLogConfig = My.Application.LogConfig Dim oConfigManager = My.Application.ConfigManager Dim oConfig As Config = oConfigManager.Config If oConfig.EXIMConnectionString = String.Empty Then MsgBox("ConnectionString zur EXIM Datenbank ist nicht hinterlegt!", MsgBoxStyle.Critical, Text) Application.Exit() End If If oConfig.WinlineConnectionString = String.Empty Then MsgBox("ConnectionString zur Winline Datenbank ist nicht hinterlegt!", MsgBoxStyle.Critical, Text) Application.Exit() End If Try My.Application.EXIMDatabase = New Database( oLogConfig, oConfigManager, oConfigManager.Config.EXIMConnectionString) My.Application.WinlineDatabase = New Database( oLogConfig, oConfigManager, oConfigManager.Config.WinlineConnectionString) My.Application.Winline = New Winline( oLogConfig, My.Application.EXIMDatabase, My.Application.WinlineDatabase, oConfigManager.Config) Dim oVendors = My.Application.Winline.GetVendors() listboxVendors.DataSource = oVendors _Logger.Info("Application started from Machine {0}", Environment.MachineName) Catch ex As Exception MsgBox("Fehler beim Initialisieren (Datenbank):" & vbNewLine & ex.Message, MsgBoxStyle.Critical, Text) _Logger.Error(ex) End Try 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) = My.Application.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) = My.Application.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}" Dim oRunningNumber As String _Logger.Info("Vendor Code: [{0}]", oVendor.Code) _Logger.Info("Group String: [{0}]", oGroup.GroupString) _Logger.Info("Version: [{0}]", oVersion.VersionString) Try oRunningNumber = My.Application.Winline.GetNextRunningNumber(oVendor.Code, oGroup.GroupId, oVersion.VersionId) _Logger.Info("New Running Number: [{0}]", oRunningNumber) If My.Application.Winline.TestArticleExists($"{oArticleNumber}{oRunningNumber}") Then Throw New ApplicationException(My.Application.Winline.ARTICLE_ALREADY_EXISTS) End If Dim oForm As New frmCreateArticle() With { .ArticleNumber = oArticleNumber, .RunningNumber = oRunningNumber, .Vendor = oVendor, .Version = oVersion, .Group = oGroup } _Logger.Info("Opening Article form..") oForm.ShowDialog() Catch ex As Exception _Logger.Error(ex) Dim oMessage As String = "" Select Case ex.Message Case My.Application.Winline.NO_RUNNING_NUMBER_FOUND oMessage = "" 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" Case My.Application.Winline.ARTICLE_ALREADY_EXISTS oMessage = "" oMessage &= $"Der Artikel [{oArticleNumber}{oRunningNumber}] existiert bereits und wird deshalb nicht angelegt." & vbNewLine oMessage &= $"Prüfen Sie, ob die Laufenden Nummern für diese Artikelversion hinterlegt korrekt hinterlegt." Case Else oMessage = "" oMessage &= "Folgender Fehler ist aufgetreten:" & vbNewLine & vbNewLine & ex.Message End Select MsgBox(oMessage, MsgBoxStyle.Critical, Text) End Try End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim oResult As DialogResult = frmNewVendor.ShowDialog() If oResult = DialogResult.OK Then Dim oVendors = My.Application.Winline.GetVendors() listboxVendors.DataSource = oVendors End If End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim oForm As New frmNewGroup() With { .Vendor = listboxVendors.SelectedItem } If oForm.ShowDialog = DialogResult.OK Then 'reload groups? End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Dim oForm As New frmNewProduct() With { .Vendor = listboxVendors.SelectedItem, .Group = listboxProductGroups.SelectedItem } If oForm.ShowDialog = DialogResult.OK Then 'reload products? End If End Sub End Class