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 Imports MultiTool.Shared.Winline Imports MultiTool.Shared.Winline.Entities 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 WinLine As WinlineData Private 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) With { .Debug = True } Logger = LogConfig.GetLogger() Logger.Info("Starting {0}, Version [{1}]", Application.ProductName, Application.ProductVersion) Catch ex As Exception FormHelper.ShowError(ex, My.Resources.frmShared.Laden_des_Formulars) End Try End Sub Private Async Sub frmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown SplashScreenManager.ShowWaitForm() Try SplashScreenManager.SetWaitFormDescription("Initialisierung der Grundfunktionen") 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 SplashScreenManager.SetWaitFormDescription("Initialisierung der Datenbankverbindung") ' Initialize Database Dim oConnectionString = MSSQLServer.DecryptConnectionString(ConfigManager.Config.ConnectionString) Database = New MSSQLServer(LogConfig, oConnectionString) SplashScreenManager.SetWaitFormDescription("Initialisierung der Vorlagen") ' Initialize Schemas TemplateLoader = New TemplateLoader(LogConfig, Database) Await TemplateLoader.LoadGeneralConfiguration() 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 My.GeneralConfiguration = TemplateLoader.GeneralConfiguration My.Helpers = New [Shared].Helpers(LogConfig) Dim oBindingSource = New BindingList(Of Template) For Each oTemplate As Template In TemplateLoader.TemplateList oBindingSource.Add(oTemplate) Next SplashScreenManager.SetWaitFormDescription("Lade Winline Stammdaten") WinLine = New WinlineData(LogConfig, Database, My.GeneralConfiguration, My.MappingConfiguration, My.MandatorConfiguration) WinLine.Mandators.Clear() WinLine.LoadEconomicYears() Await WinLine.LoadMandators() For Each oMandator As Mandator In WinLine.Mandators SplashScreenManager.SetWaitFormDescription(String.Format(My.Resources.frmImportMainExtra.Lade__0__Konten, oMandator.Id)) Await WinLine.LoadAccounts(oMandator) SplashScreenManager.SetWaitFormDescription(String.Format(My.Resources.frmImportMainExtra.Lade__0__Artikel, oMandator.Id)) Await WinLine.LoadArticles(oMandator) SplashScreenManager.SetWaitFormDescription(String.Format(My.Resources.frmImportMainExtra.Lade__0__Belegarten, oMandator.Id)) Await WinLine.LoadDocumentKinds(oMandator) Next My.Winline = WinLine GridControl1.DataSource = oBindingSource txtVersion.Caption = String.Format(My.Resources.frmMainExtra.Version___0_, My.Application.Info.Version.ToString) txtCulture.Caption = String.Format(My.Resources.frmMainExtra.Sprache___0_, My.Application.UICulture.ToString) Catch ex As Exception FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Laden_der_Winline_Daten) Finally SplashScreenManager.CloseWaitForm() 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 ' Initialize template tables oTemplate.Tables = New List(Of Template.Table) ' Fill tables oTemplate = TemplateLoader.UpdateTemplateFromFile(oTemplate, My.GeneralConfiguration.TemplateDirectory) oTemplate = TemplateLoader.UpdateTemplateFromDatabase(oTemplate, TemplateLoader.TemplateConfiguration) If oTemplate.IsImport Then Dim oForm As New frmImportMain(LogConfig, ConfigManager, oTemplate) oForm.ShowDialog() Else Dim oForm As New frmExportMain(LogConfig, ConfigManager, oTemplate) oForm.ShowDialog() 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, 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 Private Sub RibbonControl1_Click(sender As Object, e As EventArgs) Handles RibbonControl1.Click End Sub End Class