07-12-23
This commit is contained in:
92
EnvelopeGenerator.Form/frmSplashScreen.vb
Normal file
92
EnvelopeGenerator.Form/frmSplashScreen.vb
Normal file
@@ -0,0 +1,92 @@
|
||||
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
|
||||
|
||||
Public Class frmSplashScreen
|
||||
Private LogConfig As LogConfig
|
||||
Private Logger As Logger
|
||||
Private Database As MSSQLServer
|
||||
Private ConfigManager As ConfigManager(Of Config)
|
||||
|
||||
|
||||
Private State As State
|
||||
|
||||
Private Sub frmSplashScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
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()
|
||||
Application.Restart()
|
||||
Else
|
||||
Throw New ApplicationException("No Database configured. Application will close!")
|
||||
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.Show()
|
||||
|
||||
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
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user