187 lines
7.5 KiB
VB.net
187 lines
7.5 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 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")
|
|
CurrLogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, CompanyName:="Digital Data", ProductName:="Envelope Generator")
|
|
Logger = CurrLogConfig.GetLogger()
|
|
MyLogger = Logger
|
|
Try
|
|
ConfigManager = New ConfigManager(Of Config)(CurrLogConfig, Application.UserAppDataPath, Application.CommonAppDataPath, Application.StartupPath)
|
|
|
|
If ConfigManager.Config.ConnectionString = String.Empty Then
|
|
Dim oSQLConfig As New frmSQLConfig(CurrLogConfig)
|
|
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 = CurrLogConfig,
|
|
.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
|
|
MyState = DirectCast(e.Argument, State)
|
|
|
|
Worker.ReportProgress(20, "Initializing Database")
|
|
Thread.Sleep(300)
|
|
|
|
Dim oConnectionString = MSSQLServer.DecryptConnectionString(MyState.Config.ConnectionString)
|
|
MyState.Database = New MSSQLServer(MyState.LogConfig, oConnectionString)
|
|
|
|
If MyState.Database?.DBInitialized = False Then
|
|
Throw New ApplicationException("Could not connect to the database. Application will close!")
|
|
Else
|
|
DB_DD_ECM = MyState.Database
|
|
End If
|
|
|
|
Worker.ReportProgress(40, "Initializing Configuration")
|
|
Thread.Sleep(300)
|
|
|
|
Dim oSQl = "SELECT * FROM TBDD_SQL_COMMANDS"
|
|
Dim oDT = MyState.Database.GetDatatable(oSQl)
|
|
For Each oROW As DataRow In oDT.Rows
|
|
If oROW.Item("TITLE") = "REPORT ENV USER THIS_MONTH" Then
|
|
SQL_REP_ENV_USER_TM = oROW.Item("SQL_COMMAND")
|
|
ElseIf oROW.Item("TITLE") = "REPORT ENV USER LAST_MONTH" Then
|
|
SQL_REP_ENV_USER_LM = oROW.Item("SQL_COMMAND")
|
|
ElseIf oROW.Item("TITLE") = "REPORT ENV USER YEAR" Then
|
|
SQL_REP_ENV_USER_Y = oROW.Item("SQL_COMMAND")
|
|
ElseIf oROW.Item("TITLE") = "REPORT ENV USER ALL" Then
|
|
SQL_REP_ENV_USER_ALL = oROW.Item("SQL_COMMAND")
|
|
End If
|
|
|
|
Next
|
|
oSQl = "SELECT * FROM TBSIG_CHART"
|
|
DT_CHARTS = MyState.Database.GetDatatable(oSQl)
|
|
|
|
Dim ConfigModel = New ConfigModel(MyState)
|
|
MyState.DbConfig = ConfigModel.LoadConfiguration()
|
|
DEF_TF_ENABLED = MyState.DbConfig.Default_TFA_Enabled
|
|
DEF_TF_ENABLED_WITH_PHONE = MyState.DbConfig.Default_TFA_WithPhone
|
|
' DOCUMENT_PATH_MOVE_AFTSEND = oState.DbConfig.DOCUMENT_PATH_MOVE_AFTSEND
|
|
Worker.ReportProgress(60, "Initializing User")
|
|
Dim oKey = MyState.Database.GetScalarValue("SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE' and ACTIVE = 1")
|
|
Thread.Sleep(300)
|
|
If oKey.ToString <> String.Empty Then
|
|
MS_GDPICTUREKEY = oKey
|
|
End If
|
|
MyUserModel = New UserModel(MyState)
|
|
MyState.UserId = MyUserModel.SelectUserId(Environment.UserName)
|
|
|
|
Dim oUser = MyUserModel.SelectUser()
|
|
|
|
Worker.ReportProgress(80, "Initializing Rights")
|
|
Thread.Sleep(300)
|
|
|
|
' This checks for module access and admin rights
|
|
If oUser IsNot Nothing Then
|
|
MyUserModel.CheckUserLogin(oUser)
|
|
End If
|
|
MYUSER = oUser
|
|
|
|
Worker.ReportProgress(100, "Starting Application")
|
|
Thread.Sleep(300)
|
|
|
|
MyState.User = oUser
|
|
|
|
e.Result = MyState
|
|
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
|
|
|
|
Private Sub frmSplashScreen_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
|
|
If Not IsNothing(MYUSER) Then
|
|
If MYUSER.IsAdmin Then
|
|
If e.KeyCode = Keys.Escape Then
|
|
USER_GHOST_MODE_ACTIVE = True
|
|
lblGhostMode.Visible = True
|
|
End If
|
|
End If
|
|
End If
|
|
End Sub
|
|
End Class |