Imports System.ComponentModel Imports System.IO Imports DigitalData.Controls.SQLConfig Imports DigitalData.GUIs.Common Imports DigitalData.Modules.Config Imports DigitalData.Modules.Database Imports DigitalData.Modules.Logging Imports MultiTool.Shared.Templates Public Class frmMain Private LogConfig As LogConfig Private Logger As Logger Private ConfigManager As ConfigManager(Of [Shared].Config) Private Database As MSSQLServer Private TemplateLoader As TemplateLoader Private GridBuilder As GridBuilder Private FormHelper As FormHelper Private Async Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try Text = String.Format(My.Resources.frmShared._0____WebService_Multitool_für_WinLine, My.Resources.frmShared.Auswahl_der_Vorlage) LogConfig = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing, Application.CompanyName, Application.ProductName) Logger = LogConfig.GetLogger() Logger.Info("Starting {0}, Version [{1}]", Application.ProductName, Application.ProductVersion) FormHelper = New FormHelper(LogConfig) ConfigManager = New ConfigManager(Of [Shared].Config)(LogConfig, Application.UserAppDataPath, Application.CommonAppDataPath, Application.StartupPath ) GridBuilder = New GridBuilder(GridViewTemplates) GridBuilder.WithDefaults.WithReadOnlyOptions.WithClipboardHandler() GridViewTemplates.OptionsView.ShowAutoFilterRow = False ' If ConnectionString does not exist, show SQL Config Form If ConfigManager.Config.ConnectionString = String.Empty Then Dim oForm As New frmSQLConfig(LogConfig) With { .FormTitle = Application.ProductName } Dim oResult = oForm.ShowDialog() If oResult = DialogResult.OK Then ConfigManager.Config.ConnectionString = oForm.ConnectionString ConfigManager.Save() End If End If ' Initialize Database Dim oConnectionString = MSSQLServer.DecryptConnectionString(ConfigManager.Config.ConnectionString) Database = New MSSQLServer(LogConfig, oConnectionString) ' Initialize Schemas TemplateLoader = New TemplateLoader(LogConfig, Database) Await TemplateLoader.LoadTemplates() Await TemplateLoader.LoadTemplateConfiguration() Await TemplateLoader.LoadMappingConfiguration() Await TemplateLoader.LoadMandatorConfiguration() ' Save Schema data in 'My' Namespace My.MappingConfiguration = TemplateLoader.MappingConfiguration My.TemplateConfiguration = TemplateLoader.TemplateConfiguration My.MandatorConfiguration = TemplateLoader.MandatorConfiguration Dim oBindingSource = New BindingList(Of Template) For Each oTemplate As Template In TemplateLoader.TemplateList oBindingSource.Add(oTemplate) Next GridControl1.DataSource = oBindingSource Catch ex As Exception FormHelper.ShowError(ex, My.Resources.frmShared.Laden_des_Formulars) End Try End Sub Private Sub btnOpenImportExportForm_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenImportExportForm.ItemClick Try Dim oTemplate As Template = GridViewTemplates.GetRow(GridViewTemplates.FocusedRowHandle) If oTemplate Is Nothing Then MsgBox("Keine Vorlage ausgewählt! Bitte wählen Sie eine Vorlage aus!", MsgBoxStyle.Exclamation, Text) Exit Sub End If oTemplate = TemplateLoader.UpdateTemplateFromFile(oTemplate, ConfigManager.Config.SchemaDirectory) oTemplate = TemplateLoader.UpdateTemplateFromDatabase(oTemplate, TemplateLoader.TemplateConfiguration) If oTemplate.IsImport Then Dim oForm As New frmImportMain(LogConfig, ConfigManager, oTemplate) oForm.ShowDialog() Else MsgBox("Export-Vorlagen werden noch nicht unterstützt!", MsgBoxStyle.Exclamation, Text) End If Catch ex As Exception FormHelper.ShowError(ex, My.Resources.frmMainExtra.Laden_der_Vorlage) End Try End Sub Private Sub TryOpenDirectory(pPath As String, pDisplayName As String) If Directory.Exists(pPath) Then Process.Start(pPath) Else Dim oMessage = String.Format(My.Resources.frmImportMainExtra._0__nicht_konfiguriert_oder_nicht_gefunden, pDisplayName) MsgBox(oMessage, MsgBoxStyle.Exclamation, Text) End If End Sub Private Sub TryOpenFile(pPath As String, pDisplayName As String) If File.Exists(pPath) Then Process.Start(pPath) Else Dim oMessage = String.Format(My.Resources.frmImportMainExtra._0__nicht_konfiguriert_oder_nicht_gefunden, pDisplayName) MsgBox(oMessage, MsgBoxStyle.Exclamation, Text) End If End Sub Private Sub BarButtonItem4_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem4.ItemClick Dim oForm As New frmConfig(LogConfig) With { .ConfigManager = ConfigManager } oForm.ShowDialog() End Sub Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick Dim oUserConfigDirectory = New FileInfo(ConfigManager.UserConfigPath).Directory TryOpenDirectory(oUserConfigDirectory.FullName, My.Resources.frmImportMainExtra.Konfigurationsverzeichnis) End Sub Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem3.ItemClick TryOpenDirectory(LogConfig.LogDirectory, My.Resources.frmImportMainExtra.Logverzeichnis) End Sub End Class