142 lines
5.2 KiB
VB.net
142 lines
5.2 KiB
VB.net
Imports System.IO
|
|
Imports DevExpress.XtraSplashScreen
|
|
Imports DigitalData.GUIs.Common
|
|
Imports DigitalData.Modules.Base
|
|
Imports DigitalData.Modules.Config
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
Imports EnvelopeGenerator.Common
|
|
Imports EnvelopeGenerator.Common.My
|
|
|
|
Public Class frmMain
|
|
Private LogConfig As LogConfig
|
|
Private Logger As Logger
|
|
Private Database As MSSQLServer
|
|
Private ConfigManager As ConfigManager(Of Config)
|
|
Private DbConfig As DbConfig
|
|
Private TempFiles As TempFiles
|
|
|
|
Private GridBuilder As GridBuilder
|
|
|
|
Private State As State
|
|
Private Controller As EnvelopeListController
|
|
|
|
Private Sub frmMain_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()
|
|
|
|
TempFiles = New TempFiles(LogConfig)
|
|
TempFiles.Create()
|
|
|
|
Try
|
|
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath)
|
|
Dim oConnectionString = MSSQLServer.DecryptConnectionString(ConfigManager.Config.ConnectionString)
|
|
Database = New MSSQLServer(LogConfig, oConnectionString)
|
|
Dim oUserId = 0
|
|
|
|
If Database.DBInitialized = True Then
|
|
DbConfig = GetDatabaseConfig()
|
|
|
|
oUserId = Database.GetScalarValue($"SELECT GUID FROM TBDD_USER WHERE USERNAME = '{Environment.UserName}'")
|
|
End If
|
|
|
|
State = New State With {
|
|
.UserId = CInt(oUserId),
|
|
.Config = ConfigManager.Config,
|
|
.DbConfig = DbConfig,
|
|
.LogConfig = LogConfig,
|
|
.Database = Database
|
|
}
|
|
|
|
Controller = New EnvelopeListController(State)
|
|
|
|
GridBuilder = New GridBuilder(ViewEnvelopes)
|
|
GridBuilder.SetDefaults(ViewEnvelopes)
|
|
GridBuilder.SetReadOnlyOptions(ViewEnvelopes)
|
|
|
|
GridEnvelopes.DataSource = Controller.ListEnvelopes()
|
|
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
Private Function GetDatabaseConfig() As DbConfig
|
|
Try
|
|
Dim oSql As String = "SELECT TOP 1 * FROM TBSIG_CONFIG"
|
|
Dim oTable As DataTable = Database.GetDatatable(oSql)
|
|
Dim oRow = oTable.Rows.Item(0)
|
|
|
|
Return New DbConfig() With {
|
|
.DocumentPath = oRow.ItemEx("DOCUMENT_PATH", ""),
|
|
.SendingProfile = oRow.ItemEx("SENDING_PROFILE", 0)
|
|
}
|
|
Catch ex As Exception
|
|
Return New DbConfig()
|
|
End Try
|
|
End Function
|
|
|
|
Private Sub btnCreateEnvelope_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnCreateEnvelope.ItemClick
|
|
Dim oHandle = SplashScreenManager.ShowOverlayForm(Me)
|
|
Try
|
|
Dim oForm As New frmEnvelopeEditor() With {.State = State}
|
|
oForm.ShowDialog()
|
|
GridEnvelopes.DataSource = Controller.ListEnvelopes()
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Finally
|
|
SplashScreenManager.CloseOverlayForm(oHandle)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub btnEditEnvelope_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnEditEnvelope.ItemClick
|
|
Dim oSelectedRows = ViewEnvelopes.GetSelectedRows()
|
|
If oSelectedRows.Count > 0 Then
|
|
LoadEnvelope(oSelectedRows.First)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub LoadEnvelope(pRowHandle As Integer)
|
|
Dim oEnvelope As Envelope = ViewEnvelopes.GetRow(pRowHandle)
|
|
Dim oForm As New frmEnvelopeEditor() With {.State = State, .Envelope = oEnvelope}
|
|
oForm.ShowDialog()
|
|
GridEnvelopes.DataSource = Controller.ListEnvelopes()
|
|
End Sub
|
|
|
|
Private Sub DeleteEnvelope(pRowHandle As Integer)
|
|
Dim oEnvelope As Envelope = ViewEnvelopes.GetRow(pRowHandle)
|
|
|
|
If MsgBox(Resources.Envelope.Do_you_really_want_to_delete_this_envelope, MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text) = MsgBoxResult.No Then
|
|
Exit Sub
|
|
End If
|
|
|
|
If Controller.DeleteEnvelope(oEnvelope) Then
|
|
GridEnvelopes.DataSource = Controller.ListEnvelopes()
|
|
Else
|
|
MsgBox(Resources.Envelope.The_envelope_could_not_be_deleted, MsgBoxStyle.Critical, Text)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ViewEnvelopes_DoubleClick(sender As Object, e As EventArgs) Handles ViewEnvelopes.DoubleClick
|
|
Dim oSelectedRows = ViewEnvelopes.GetSelectedRows()
|
|
If oSelectedRows.Count > 0 Then
|
|
LoadEnvelope(oSelectedRows.First)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub btnDeleteEnvelope_ItemClick_1(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDeleteEnvelope.ItemClick
|
|
Dim oSelectedRows = ViewEnvelopes.GetSelectedRows()
|
|
If oSelectedRows.Count > 0 Then
|
|
DeleteEnvelope(oSelectedRows.First)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
|
|
' Cleanup Methods
|
|
TempFiles.CleanUp()
|
|
End Sub
|
|
End Class |