259 lines
11 KiB
VB.net
259 lines
11 KiB
VB.net
Imports System.ComponentModel
|
|
Imports System.IO
|
|
Imports DevExpress.Utils
|
|
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 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)
|
|
|
|
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, Me)
|
|
ConfigManager = New ConfigManager(Of [Shared].Config)(LogConfig,
|
|
Application.UserAppDataPath,
|
|
Application.CommonAppDataPath,
|
|
Application.StartupPath
|
|
)
|
|
LogConfig.Debug = ConfigManager.Config.Debug
|
|
|
|
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
|
|
SplashScreenManager.SetWaitFormDescription("Initialisierung der Datenbankverbindung")
|
|
Dim oConnectionString = MSSQLServer.DecryptConnectionString(ConfigManager.Config.ConnectionString)
|
|
Database = New MSSQLServer(LogConfig, oConnectionString)
|
|
|
|
SplashScreenManager.SetWaitFormDescription("Lade Vorlagen")
|
|
Await LoadTemplateData()
|
|
|
|
SplashScreenManager.SetWaitFormDescription("Lade Winline Stammdaten")
|
|
My.Winline = New WinlineData(LogConfig, Database, My.GeneralConfiguration, My.MappingConfiguration, My.MandatorConfiguration)
|
|
Dim oBindingSource As BindingList(Of Template) = Await LoadWinlineData(My.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 Async Function LoadWinlineData(Winline As WinlineData) As Task(Of BindingList(Of Template))
|
|
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
|
|
|
|
Dim oBindingSource = New BindingList(Of Template)
|
|
For Each oTemplate As Template In TemplateLoader.TemplateList
|
|
oBindingSource.Add(oTemplate)
|
|
Next
|
|
Return oBindingSource
|
|
End Function
|
|
|
|
Private Async Function LoadTemplateData() As Task
|
|
' Initialize Schemas
|
|
TemplateLoader = New TemplateLoader(LogConfig, Database)
|
|
Await TemplateLoader.LoadTemplates()
|
|
Await TemplateLoader.LoadTemplateConfiguration()
|
|
Await TemplateLoader.LoadGeneralConfiguration()
|
|
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
|
|
End Function
|
|
|
|
Private Sub btnOpenImportExportForm_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenImportExportForm.ItemClick
|
|
Dim oTemplate As Template = GridViewTemplates.GetRow(GridViewTemplates.FocusedRowHandle)
|
|
OpenImportExportForm(oTemplate)
|
|
End Sub
|
|
|
|
Private Sub frmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
|
|
If e.KeyCode = Keys.F5 Then
|
|
Dim oTemplate As Template = GridViewTemplates.GetRow(GridViewTemplates.FocusedRowHandle)
|
|
OpenImportExportForm(oTemplate)
|
|
End If
|
|
End Sub
|
|
|
|
Private Function TryCreateTemplateDirectories(pDirectories As List(Of String)) As Boolean
|
|
For Each oDirectory In pDirectories
|
|
If Directory.Exists(oDirectory) = False Then
|
|
Dim oResult As MsgBoxResult = MsgBox($"Das Verzeichnis [{oDirectory}] existiert noch nicht, wird aber zum Benutzen des Programms benötigt. Wollen Sie es jetzt anlegen?", vbQuestion Or vbYesNo, Text)
|
|
If oResult = MsgBoxResult.Yes Then
|
|
Try
|
|
Directory.CreateDirectory(oDirectory)
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
MsgBox($"Das Verzeichnis [{oDirectory}] konnte nicht angelegt werden. Grund: [{ex.Message}]")
|
|
|
|
Return False
|
|
End Try
|
|
Else
|
|
Return False
|
|
End If
|
|
End If
|
|
Next
|
|
|
|
Return True
|
|
End Function
|
|
|
|
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
|
|
FormHelper.TryOpenDirectory(oUserConfigDirectory.FullName, My.Resources.frmImportMainExtra.Konfigurationsverzeichnis)
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem3.ItemClick
|
|
FormHelper.TryOpenDirectory(LogConfig.LogDirectory, My.Resources.frmImportMainExtra.Logverzeichnis)
|
|
End Sub
|
|
|
|
Private Sub btnOpenSchemaDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenSchemaDirectory.ItemClick
|
|
FormHelper.TryOpenDirectory(My.GeneralConfiguration.TemplateDirectory, My.Resources.frmImportMainExtra.Vorlagenverzeichnis)
|
|
End Sub
|
|
|
|
Private Sub GridViewTemplates_DoubleClick(sender As Object, e As EventArgs) Handles GridViewTemplates.DoubleClick
|
|
Dim oArgs As DXMouseEventArgs = TryCast(e, DXMouseEventArgs)
|
|
Dim oHitInfo = GridViewTemplates.CalcHitInfo(oArgs.Location)
|
|
If oHitInfo.InRow Then
|
|
Dim oTemplate As Template = GridViewTemplates.GetRow(oHitInfo.RowHandle)
|
|
OpenImportExportForm(oTemplate)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub OpenImportExportForm(pTemplate As Template)
|
|
Try
|
|
If pTemplate 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
|
|
pTemplate.Tables = New List(Of Template.Table)
|
|
|
|
' Fill tables
|
|
pTemplate = TemplateLoader.UpdateTemplateFromFile(pTemplate, My.GeneralConfiguration.TemplateDirectory)
|
|
pTemplate = TemplateLoader.UpdateTemplateFromDatabase(pTemplate)
|
|
pTemplate = TemplateLoader.UpdateTemplateTablesFromDatabase(pTemplate, TemplateLoader.TemplateConfiguration)
|
|
|
|
Dim oBaseDirectories As New List(Of String) From {
|
|
pTemplate.InputDirectory,
|
|
pTemplate.OutputDirectory,
|
|
pTemplate.ArchiveDirectory
|
|
}
|
|
Dim oOutputDirectories As New List(Of String) From {
|
|
pTemplate.OutputReportDirectory,
|
|
pTemplate.OutputWebserviceDirectory,
|
|
pTemplate.OutputXmlFileDirectory
|
|
}
|
|
|
|
If TryCreateTemplateDirectories(oBaseDirectories) Then
|
|
If TryCreateTemplateDirectories(oOutputDirectories) Then
|
|
If pTemplate.IsImport Then
|
|
Dim oForm As New frmImportMain(LogConfig, ConfigManager, pTemplate)
|
|
oForm.ShowDialog()
|
|
Else
|
|
Dim oForm As New frmExportMain(LogConfig, ConfigManager, pTemplate)
|
|
oForm.ShowDialog()
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
FormHelper.ShowError(ex, My.Resources.frmMainExtra.Laden_der_Vorlage)
|
|
|
|
End Try
|
|
End Sub
|
|
|
|
Private Async Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
|
|
If SplashScreenManager.IsSplashFormVisible Then
|
|
Exit Sub
|
|
End If
|
|
|
|
SplashScreenManager.ShowWaitForm()
|
|
|
|
Try
|
|
SplashScreenManager.SetWaitFormDescription("Lade Vorlagen")
|
|
Await LoadTemplateData()
|
|
|
|
SplashScreenManager.SetWaitFormDescription("Lade Winline Stammdaten")
|
|
Dim oBindingSource As BindingList(Of Template) = Await LoadWinlineData(My.Winline)
|
|
GridControl1.DataSource = oBindingSource
|
|
|
|
Catch ex As Exception
|
|
FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Laden_der_Winline_Daten)
|
|
|
|
Finally
|
|
SplashScreenManager.CloseWaitForm()
|
|
|
|
End Try
|
|
End Sub
|
|
End Class |