152 lines
5.8 KiB
VB.net
152 lines
5.8 KiB
VB.net
Imports DevExpress.XtraBars.Docking
|
|
Imports System.Globalization
|
|
Imports System.Threading
|
|
Imports DigitalData.GUIs.Common
|
|
Imports DigitalData.Modules.Config
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
Imports EnvelopeGenerator.Common
|
|
Imports System.ComponentModel
|
|
|
|
Public Class frmSplashScreen
|
|
Private LogConfig As LogConfig
|
|
Private Logger As Logger
|
|
Private ConfigManager As ConfigManager(Of Config)
|
|
|
|
Private WithEvents Worker As New BackgroundWorker() With {.WorkerReportsProgress = True}
|
|
|
|
Private Sub frmSplashScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
|
lblVersion.Text = String.Format("Version {0}", My.Application.Info.Version.ToString)
|
|
lblCopyright.Text = My.Application.Info.Copyright
|
|
Me.BringToFront()
|
|
End Sub
|
|
|
|
Private Sub frmSplashScreen_Shown(sender As Object, e As EventArgs) Handles Me.Shown
|
|
Dim oLogPath = IO.Path.Combine(Application.LocalUserAppDataPath, "Log")
|
|
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, CompanyName:="Digital Data", ProductName:="Envelope Generator")
|
|
Logger = LogConfig.GetLogger()
|
|
|
|
Try
|
|
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath, Application.CommonAppDataPath, Application.StartupPath)
|
|
|
|
If ConfigManager.Config.ConnectionString = String.Empty Then
|
|
Dim oSQLConfig As New frmSQLConfig(LogConfig)
|
|
If oSQLConfig.ShowDialog() = DialogResult.OK Then
|
|
ConfigManager.Config.ConnectionString = oSQLConfig.ConnectionString
|
|
ConfigManager.Save()
|
|
|
|
MsgBox("Database configured. Application will restart.", MsgBoxStyle.Critical, Text)
|
|
Application.Restart()
|
|
Else
|
|
MsgBox("No Database configured. Application will close!", MsgBoxStyle.Critical, Text)
|
|
Application.Exit()
|
|
End If
|
|
End If
|
|
|
|
Worker.RunWorkerAsync(New State() With {
|
|
.User = Nothing,
|
|
.UserId = 0,
|
|
.LogConfig = LogConfig,
|
|
.Config = ConfigManager.Config,
|
|
.Database = Nothing,
|
|
.DbConfig = New DbConfig()
|
|
})
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
MsgBox("Fehler beim Initialisieren: " & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, MsgBoxStyle.Critical, Text)
|
|
Application.Exit()
|
|
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub Worker_DoWork(sender As Object, e As DoWorkEventArgs) Handles Worker.DoWork
|
|
Dim oState As State = DirectCast(e.Argument, State)
|
|
|
|
Worker.ReportProgress(20, "Initialize Database")
|
|
Thread.Sleep(300)
|
|
|
|
Dim oConnectionString = MSSQLServer.DecryptConnectionString(oState.Config.ConnectionString)
|
|
oState.Database = New MSSQLServer(oState.LogConfig, oConnectionString)
|
|
|
|
If oState.Database?.DBInitialized = False Then
|
|
Throw New ApplicationException("Could not connect to the database. Application will close!")
|
|
End If
|
|
|
|
Worker.ReportProgress(40, "Initialize Confguration")
|
|
Thread.Sleep(300)
|
|
|
|
Dim ConfigModel = New ConfigModel(oState)
|
|
oState.DbConfig = ConfigModel.LoadConfiguration()
|
|
|
|
Worker.ReportProgress(60, "Initialize User")
|
|
Thread.Sleep(300)
|
|
|
|
Dim oUserModel = New UserModel(oState)
|
|
oState.UserId = oUserModel.SelectUserId()
|
|
|
|
Dim oUser = oUserModel.SelectUser()
|
|
|
|
Worker.ReportProgress(80, "Initialize Rights")
|
|
Thread.Sleep(300)
|
|
|
|
' This checks for module access and admin rights
|
|
If oUser IsNot Nothing Then
|
|
oUserModel.CheckUserLogin(oUser)
|
|
End If
|
|
|
|
Worker.ReportProgress(100, "Starting Application")
|
|
Thread.Sleep(300)
|
|
|
|
oState.User = oUser
|
|
|
|
e.Result = oState
|
|
End Sub
|
|
|
|
Private Sub Worker_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles Worker.ProgressChanged
|
|
pbStatus.Value = e.ProgressPercentage
|
|
lblStatus.Text = e.UserState.ToString()
|
|
End Sub
|
|
|
|
Private Sub Worker_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles Worker.RunWorkerCompleted
|
|
Try
|
|
If e.Error IsNot Nothing Then
|
|
Throw e.Error
|
|
End If
|
|
|
|
Dim oState As State = DirectCast(e.Result, State)
|
|
|
|
If oState.User Is Nothing Or oState.UserId = 0 Then
|
|
Throw New ApplicationException($"User {Environment.UserName} is unknown. Please contact your administrator. Application will close!")
|
|
End If
|
|
|
|
Dim oCultureInfo As CultureInfo
|
|
oCultureInfo = New CultureInfo(oState.User.Language)
|
|
Thread.CurrentThread.CurrentCulture = oCultureInfo
|
|
Thread.CurrentThread.CurrentUICulture = oCultureInfo
|
|
CultureInfo.DefaultThreadCurrentCulture = oCultureInfo
|
|
CultureInfo.DefaultThreadCurrentUICulture = oCultureInfo
|
|
|
|
If oState.User.HasAccess = False Then
|
|
Throw New ApplicationException("User is not activated for this module. Please contact your administrator. Application will close!")
|
|
End If
|
|
|
|
If Not String.IsNullOrEmpty(oState.DbConfig.ExternalProgramName) Then
|
|
Text = oState.DbConfig.ExternalProgramName
|
|
End If
|
|
|
|
' Hide splashscreen
|
|
Hide()
|
|
|
|
Dim oForm As New frmMain(oState)
|
|
oForm.ShowDialog()
|
|
|
|
' Close this form after frmMain is closed
|
|
Close()
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
MsgBox("Fehler beim Initialisieren: " & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, MsgBoxStyle.Critical, Text)
|
|
Application.Exit()
|
|
End Try
|
|
End Sub
|
|
|
|
End Class |