splash screen
This commit is contained in:
@@ -6,6 +6,7 @@ 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
|
||||
@@ -13,83 +14,125 @@ Public Class frmSplashScreen
|
||||
Private Database As MSSQLServer
|
||||
Private ConfigManager As ConfigManager(Of Config)
|
||||
|
||||
|
||||
Private State As State
|
||||
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 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)
|
||||
Database = New MSSQLServer(oState.LogConfig, oConnectionString)
|
||||
|
||||
oState = New State With {
|
||||
.UserId = 0,
|
||||
.Config = oState.Config,
|
||||
.DbConfig = New DbConfig(),
|
||||
.LogConfig = LogConfig,
|
||||
.Database = Database
|
||||
}
|
||||
|
||||
If 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
|
||||
oUserModel.CheckUserLogin(oUser)
|
||||
|
||||
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
|
||||
If e.Error IsNot Nothing Then
|
||||
Logger.Error(e.Error)
|
||||
MsgBox(e.Error.Message, MsgBoxStyle.Critical, Text)
|
||||
Application.Exit()
|
||||
End If
|
||||
|
||||
Dim oState As State = DirectCast(e.Result, State)
|
||||
|
||||
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
|
||||
|
||||
Dim oForm As New frmMain(oState)
|
||||
oForm.ShowDialog()
|
||||
|
||||
' Close this form after frmMain is closed
|
||||
Close()
|
||||
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()
|
||||
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath, Application.CommonAppDataPath, Application.StartupPath)
|
||||
|
||||
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()
|
||||
|
||||
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()
|
||||
Application.Restart()
|
||||
Else
|
||||
Throw New ApplicationException("No Database configured. Application will close!")
|
||||
End If
|
||||
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
|
||||
|
||||
Dim oConnectionString = MSSQLServer.DecryptConnectionString(ConfigManager.Config.ConnectionString)
|
||||
Database = New MSSQLServer(LogConfig, oConnectionString)
|
||||
|
||||
State = New State With {
|
||||
.UserId = 0,
|
||||
.Config = ConfigManager.Config,
|
||||
.DbConfig = New DbConfig(),
|
||||
.LogConfig = LogConfig,
|
||||
.Database = Database
|
||||
}
|
||||
|
||||
If Database.DBInitialized = False Then
|
||||
Throw New ApplicationException("Could not connect to the database. Application will close!")
|
||||
End If
|
||||
|
||||
Dim ConfigModel = New ConfigModel(State)
|
||||
State.DbConfig = ConfigModel.LoadConfiguration()
|
||||
|
||||
Dim oUserModel = New UserModel(State)
|
||||
State.UserId = oUserModel.SelectUserId()
|
||||
|
||||
Dim oUser = oUserModel.SelectUser()
|
||||
oUser = oUserModel.CheckUserLogin(oUser)
|
||||
|
||||
Dim oCultureInfo As CultureInfo
|
||||
oCultureInfo = New CultureInfo(oUser.Language)
|
||||
Thread.CurrentThread.CurrentCulture = oCultureInfo
|
||||
Thread.CurrentThread.CurrentUICulture = oCultureInfo
|
||||
CultureInfo.DefaultThreadCurrentCulture = oCultureInfo
|
||||
CultureInfo.DefaultThreadCurrentUICulture = oCultureInfo
|
||||
|
||||
If oUser.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(State.DbConfig.ExternalProgramName) Then
|
||||
Text = State.DbConfig.ExternalProgramName
|
||||
End If
|
||||
|
||||
Dim oForm As New frmMain(State)
|
||||
oForm.ShowDialog()
|
||||
|
||||
' Close this form after frmMain is closed
|
||||
Close()
|
||||
|
||||
Catch ex As ApplicationException
|
||||
Logger.Error(ex)
|
||||
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
|
||||
Application.Exit()
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
MsgBox($"Unexpected error: {ex.Message}", MsgBoxStyle.Critical, Text)
|
||||
Application.Exit()
|
||||
|
||||
End Try
|
||||
Worker.RunWorkerAsync(New State() With {
|
||||
.LogConfig = LogConfig,
|
||||
.Config = ConfigManager.Config
|
||||
})
|
||||
End Sub
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user