Imports System.IO Imports DevExpress.LookAndFeel Imports DevExpress.Utils.Extensions Imports DevExpress.XtraCharts Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraSplashScreen Imports DigitalData.GUIs.Common Imports DigitalData.Modules.Base Imports DigitalData.Modules.Logging Imports EnvelopeGenerator.Common Imports EnvelopeGenerator.Common.My Public Class frmMain Private ReadOnly LogConfig As LogConfig Private ReadOnly Logger As Logger Private TempFiles As TempFiles Private GridBuilder As GridBuilder Private RefreshHelper As RefreshHelper Private State As State Private Controller As EnvelopeListController Private myFileData As Byte() Private myResFileData As Byte() Public Sub New(pState As State) ' Dieser Aufruf ist für den Designer erforderlich. InitializeComponent() ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. State = pState LogConfig = pState.LogConfig Logger = LogConfig.GetLogger() End Sub Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load Text = $"{State.DbConfig.ExternalProgramName} - {Resources.Envelope.Envelope_Overview}" TempFiles = New TempFiles(LogConfig) TempFiles.Create() RefreshHelper = New RefreshHelper(ViewEnvelopes, "Id") Controller = New EnvelopeListController(State) Try Me.LookAndFeel.UseDefaultLookAndFeel = False LookAndFeel.SetSkinStyle(SkinStyle.Office2019Colorful, SkinSvgPalette.DefaultSkin) Catch ex As Exception End Try LoadEnvelopeData() End Sub Private Sub LoadEnvelopeData() Try RefreshHelper.SaveViewInfo() LoadEnvelopes() LoadCompletedEnvelopes() RefreshHelper.LoadViewInfo() 'LoadCharts() txtRefreshLabel.Caption = String.Format(txtRefreshLabel.Tag, Now) Catch ex As Exception Logger.Error(ex) End Try End Sub Private Sub LoadEnvelopes() Try GridBuilder = New GridBuilder(ViewEnvelopes) GridBuilder.SetReadOnlyOptions(ViewEnvelopes) GridBuilder.SetReadOnlyOptions(ViewHistory) GridBuilder.SetDefaults(ViewHistory) GridEnvelopes.DataSource = Controller.ListEnvelopes() Catch ex As Exception Logger.Error(ex) End Try End Sub Private Sub LoadCompletedEnvelopes() Try GridBuilder = New GridBuilder(ViewCompleted) GridBuilder.SetReadOnlyOptions(ViewCompleted) GridBuilder.SetReadOnlyOptions(ViewHistoryCompleted) GridBuilder.SetDefaults(ViewHistoryCompleted) GridCompleted.DataSource = Controller.ListCompleted() Catch ex As Exception Logger.Error(ex) End Try End Sub Private Sub LoadCharts() Dim oChartControl As ChartControl = Controller.GetPieChart() Me.SplitContainerControl1.Panel2.AddControl(oChartControl) End Sub 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() LoadEnvelopeData() 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 oHandle = SplashScreenManager.ShowOverlayForm(Me) Try Dim oEnvelope As Envelope = DirectCast(ViewEnvelopes.GetRow(pRowHandle), Envelope) If oEnvelope.IsAlreadySent Then Exit Sub End If Dim oForm As New frmEnvelopeEditor() With {.State = State, .Envelope = oEnvelope} oForm.ShowDialog() LoadEnvelopeData() Catch ex As Exception Logger.Error(ex) Finally SplashScreenManager.CloseOverlayForm(oHandle) End Try End Sub Private Sub DeleteEnvelope(pRowHandle As Integer, pReason As String) 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, pReason) Then LoadEnvelopeData() 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 Try Dim oSelectedRows = ViewEnvelopes.GetSelectedRows() If oSelectedRows.Count > 0 Then Dim ofrmAbort As New frmRueckruf frmRueckruf.ShowDialog() If frmRueckruf.Continue_Reject = True Then DeleteEnvelope(oSelectedRows.First, frmRueckruf.Reject_reason) End If End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical) End Try End Sub Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing ' Cleanup Methods TempFiles.CleanUp() End Sub Private Sub XtraTabControl1_SelectedPageChanged(sender As Object, e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles XtraTabControl1.SelectedPageChanged Select Case XtraTabControl1.SelectedTabPageIndex Case 1 btnEditEnvelope.Enabled = False btnDeleteEnvelope.Enabled = False btnContactReceiver.Enabled = False btnShowDocument.Enabled = False bbtnitmEB.Enabled = True Case 0 btnEditEnvelope.Enabled = True btnDeleteEnvelope.Enabled = True btnContactReceiver.Enabled = True btnShowDocument.Enabled = True bbtnitmEB.Enabled = False End Select End Sub Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick LoadEnvelopeData() End Sub Private Sub ViewEnvelopes_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles ViewEnvelopes.FocusedRowChanged If ViewEnvelopes.FocusedRowHandle < 0 Then Exit Sub End If Dim oEnvelope As Envelope = ViewEnvelopes.GetRow(ViewEnvelopes.FocusedRowHandle) txtEnvelopeIdLabel.Caption = String.Format(txtEnvelopeIdLabel.Tag, oEnvelope.Id) If oEnvelope.IsAlreadySent Then btnEditEnvelope.Enabled = False Else btnEditEnvelope.Enabled = True End If End Sub Private Sub bbtnitmEB_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles bbtnitmEB.ItemClick If ViewEnvelopes.FocusedRowHandle < 0 Then Exit Sub End If Me.Cursor = Cursors.WaitCursor Dim oEnvelope As Envelope = ViewCompleted.GetRow(ViewCompleted.FocusedRowHandle) GetResRepFileStreamByte(oEnvelope.Id) Dim oTempFolder = TempFiles.TempPath Dim oTempFilename = String.Concat(oTempFolder, "\", $"ViewEnvResReport_{oEnvelope.Id}.pdf") If File.Exists(oTempFilename) Then Try File.OpenWrite(oTempFilename) Catch ex As Exception MsgBox("File might already be open?", MsgBoxStyle.Exclamation) Exit Sub End Try File.Delete(oTempFilename) End If downloadResFile(oTempFilename) Me.Cursor = Cursors.Default End Sub Private Sub ViewEnvelopes_CustomDrawCell(sender As Object, e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles ViewEnvelopes.CustomDrawCell If e.RowHandle < 0 Or XtraTabControl1.SelectedTabPageIndex = 1 Then Exit Sub End If Dim oEnvelope As Envelope = ViewEnvelopes.GetRow(e.RowHandle) If oEnvelope.Status = Common.Constants.EnvelopeStatus.EnvelopePartlySigned Then e.Appearance.BackColor = ColorTranslator.FromHtml(Common.Constants.GREEN_300) End If If oEnvelope.Status = Common.Constants.EnvelopeStatus.EnvelopeQueued Or oEnvelope.Status = Common.Constants.EnvelopeStatus.EnvelopeSent Then e.Appearance.BackColor = ColorTranslator.FromHtml(Common.Constants.ORANGE_300) End If End Sub Private Sub ViewReceivers_CustomDrawCell(sender As Object, e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles ViewReceivers.CustomDrawCell If e.RowHandle < 0 Then Exit Sub End If Dim oView As GridView = DirectCast(sender, GridView) Dim oReceiver As EnvelopeReceiver = oView.GetRow(e.RowHandle) If (oReceiver Is Nothing) Then Exit Sub End If If oReceiver.Status = Common.Constants.ReceiverStatus.Signed Then e.Appearance.BackColor = ColorTranslator.FromHtml(Common.Constants.GREEN_300) Else e.Appearance.BackColor = ColorTranslator.FromHtml(Common.Constants.RED_300) End If End Sub Private Sub ViewCompleted_CustomDrawCell(sender As Object, e As Views.Base.RowCellCustomDrawEventArgs) Handles ViewCompleted.CustomDrawCell If e.RowHandle < 0 Then Exit Sub End If Dim oEnvelope As Envelope = ViewCompleted.GetRow(e.RowHandle) If oEnvelope.Status = Common.Constants.EnvelopeStatus.EnvelopeCompletelySigned Then e.Appearance.BackColor = ColorTranslator.FromHtml(Common.Constants.GREEN_300) End If If oEnvelope.Status = Common.Constants.EnvelopeStatus.EnvelopeDeleted Then e.Appearance.BackColor = ColorTranslator.FromHtml(Common.Constants.RED_300) End If End Sub Private Sub ViewReceiversCompleted_CustomDrawCell(sender As Object, e As Views.Base.RowCellCustomDrawEventArgs) Handles ViewReceiversCompleted.CustomDrawCell If e.RowHandle < 0 Then Exit Sub End If Dim oView As GridView = DirectCast(sender, GridView) Dim oReceiver As EnvelopeReceiver = oView.GetRow(e.RowHandle) If (oReceiver Is Nothing) Then Exit Sub End If If oReceiver.Status = Common.Constants.ReceiverStatus.Signed Then e.Appearance.BackColor = ColorTranslator.FromHtml(Common.Constants.GREEN_300) Else e.Appearance.BackColor = ColorTranslator.FromHtml(Common.Constants.RED_300) End If End Sub Private Sub RefreshTimer_Tick(sender As Object, e As EventArgs) Handles RefreshTimer.Tick Try If Application.OpenForms.OfType(Of frmEnvelopeEditor).Any = False Then LoadEnvelopeData() End If Catch ex As Exception Logger.Error(ex) End Try End Sub Private Sub btnContactReceiver_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnContactReceiver.ItemClick If ViewEnvelopes.FocusedRowHandle < 0 Then Exit Sub End If Dim oEnvelope As Envelope = ViewEnvelopes.GetRow(ViewEnvelopes.FocusedRowHandle) Dim oView As GridView = GridEnvelopes.FocusedView If oView.Name = ViewReceivers.Name Then Dim oReceiver As EnvelopeReceiver = oView.GetRow(oView.FocusedRowHandle) Dim oEnvelopeTitle As String = Net.WebUtility.UrlEncode(oEnvelope.Title) Process.Start($"mailto:{oReceiver.Email}?subject={oEnvelopeTitle}") Else MsgBox(Resources.Envelope.Please_select_a_recipient_from_the_Recipients_tab, MsgBoxStyle.Information, Text) End If End Sub Private Sub btnShowDocument_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnShowDocument.ItemClick Try If ViewEnvelopes.FocusedRowHandle < 0 Then Exit Sub End If Me.Cursor = Cursors.WaitCursor Dim oEnvelope As Envelope = ViewEnvelopes.GetRow(ViewEnvelopes.FocusedRowHandle) Dim oDocument = oEnvelope.Documents.FirstOrDefault() If oDocument Is Nothing Then MsgBox(Resources.Envelope.The_envelope_does_not_contain_any_documents, MsgBoxStyle.Exclamation, Text) Me.Cursor = Cursors.Default Exit Sub Else If Not IsNothing(oDocument.Byte_Data) Then Dim oTempFolder = TempFiles.TempPath Dim oTempFilename = String.Concat(oTempFolder, "\", $"ViewEnvDoc_{oEnvelope.Id}.pdf") If File.Exists(oTempFilename) Then Try File.OpenWrite(oTempFilename) Catch ex As Exception MsgBox("File might already be open?", MsgBoxStyle.Exclamation) Me.Cursor = Cursors.Default Exit Sub End Try File.Delete(oTempFilename) End If downloadFile(oTempFilename, oDocument.Byte_Data) End If End If Catch ex As Exception MsgBox(Resources.Envelope.Document_could_not_be_opened, MsgBoxStyle.Critical, Text) Logger.Error(ex) End Try Me.Cursor = Cursors.Default End Sub 'Private Sub GetFileStreamByte(ByVal pEnvID As Long) ' Dim strSql As String ' 'For Document ' Try ' 'Get image data from gridview column. ' strSql = "Select [DOC1] from [TBSIG_ENVELOPE] WHERE GUID =" & pEnvID ' 'Get image data from DB ' Dim fileData As Byte() = DirectCast(DB_DD_ECM.GetScalarValue(strSql), Byte()) ' If Not fileData Is Nothing Then ' myFileData = fileData ' Else ' myFileData = Nothing ' End If ' Catch ex As Exception ' MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in GetFileStreamByte") ' myFileData = Nothing ' End Try 'End Sub Private Sub GetResRepFileStreamByte(ByVal pEnvID As Long) Dim strSql As String 'For Document Try 'Get image data from gridview column. strSql = "Select [DOC_RESULT] from [TBSIG_ENVELOPE] WHERE GUID = " & pEnvID Dim obyteDB = DB_DD_ECM.GetScalarValue(strSql) If Not IsDBNull(obyteDB) Then 'Get image data from DB Dim fileData As Byte() = DirectCast(DB_DD_ECM.GetScalarValue(strSql), Byte()) If Not fileData Is Nothing Then myResFileData = fileData Else myResFileData = Nothing End If Else myResFileData = Nothing End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in GetResRepFileStreamByte") myResFileData = Nothing End Try End Sub Private Sub downloadFile(ByVal sFileName As String, pByte As Byte()) 'For Document Try If Not pByte Is Nothing Then 'Read image data into a file stream Using fs As New FileStream(sFileName, FileMode.OpenOrCreate, FileAccess.Write) fs.Write(pByte, 0, pByte.Length) 'Set image variable value using memory stream. fs.Flush() fs.Close() End Using 'Open File Process.Start(sFileName) End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in downloadFile") End Try End Sub Private Sub downloadResFile(ByVal sFileName As String) Dim strSql As String 'For Document Try If Not myResFileData Is Nothing Then 'Read image data into a file stream Using fs As New FileStream(sFileName, FileMode.OpenOrCreate, FileAccess.Write) fs.Write(myResFileData, 0, myResFileData.Length) 'Set image variable value using memory stream. fs.Flush() fs.Close() End Using 'Open File Process.Start(sFileName) Else MsgBox("Could not get DocData from Database!", MsgBoxStyle.Exclamation, "Error in downloadResFile") End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in downloadResFile") End Try End Sub Private Sub ViewCompleted_FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs) Handles ViewCompleted.FocusedRowChanged If ViewCompleted.FocusedRowHandle < 0 Then Exit Sub End If Dim oEnvelope As Envelope = ViewCompleted.GetRow(ViewCompleted.FocusedRowHandle) If oEnvelope.Status = Common.Constants.EnvelopeStatus.EnvelopeArchived Then bbtnitmEB.Enabled = True Else bbtnitmEB.Enabled = False End If txtEnvelopeIdLabel.Caption = String.Format(txtEnvelopeIdLabel.Tag, oEnvelope.Id) End Sub Private Sub btnOpenLogDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenLogDirectory.ItemClick Try Process.Start(LogConfig.LogDirectory) Catch ex As Exception Logger.Error(ex) End Try End Sub Private Sub BarCheckItem1_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarCheckItem1.CheckedChanged If BarCheckItem1.Checked = True Then If CurrLogConfig.Debug = False Then CurrLogConfig.Debug = True bsitmInfo.Caption = "DEBUG-Log is active" bsitmInfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Always End If Else CurrLogConfig.Debug = False bsitmInfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never End If End Sub Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown If CurrLogConfig.Debug Then BarCheckItem1.Checked = True Else BarCheckItem1.Checked = False End If RefreshTimer.Start() End Sub End Class