From b63655b212c40b6b205bca34500326fb0d0f7a53 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 6 Jul 2023 14:24:30 +0200 Subject: [PATCH] 06-07-2023 --- .../Controllers/EnvelopeController.vb | 236 ++++++++++++++++-- EnvelopeGenerator.Form/Entities/Envelope.vb | 2 +- .../Entities/EnvelopeFile.vb | 12 +- .../Entities/EnvelopeReceiver.vb | 20 +- EnvelopeGenerator.Form/frmEditor.Designer.vb | 45 ++-- EnvelopeGenerator.Form/frmEditor.resx | 8 +- EnvelopeGenerator.Form/frmEditor.vb | 29 +-- 7 files changed, 289 insertions(+), 63 deletions(-) diff --git a/EnvelopeGenerator.Form/Controllers/EnvelopeController.vb b/EnvelopeGenerator.Form/Controllers/EnvelopeController.vb index 7c154f3e..c4dc2233 100644 --- a/EnvelopeGenerator.Form/Controllers/EnvelopeController.vb +++ b/EnvelopeGenerator.Form/Controllers/EnvelopeController.vb @@ -1,6 +1,4 @@ -Imports DevExpress.Utils.DirectXPaint -Imports System.Data.SqlClient -Imports System.Runtime.Remoting.Messaging +Imports System.Data.SqlClient Imports DigitalData.Modules.Base Imports DigitalData.Modules.Database Imports DigitalData.Modules.Logging @@ -9,15 +7,21 @@ Public Class EnvelopeController Inherits BaseClass Private ReadOnly Database As MSSQLServer + Private Envelope As Envelope = Nothing Public Sub New(pState As State) MyBase.New(pState.LogConfig) Database = pState.Database End Sub +#Region "Public" Public Function SaveEnvelope(pEnvelope As Envelope) As Boolean - If pEnvelope.Id > 0 Then - Try + Dim oConnection = Database.GetConnection() + Dim oTransaction = oConnection.BeginTransaction(IsolationLevel.ReadUncommitted) + + Try + If pEnvelope.Id > 0 Then + Dim oSql = "UPDATE [dbo].[TBSIG_ENVELOPE] SET [SUBJECT] = @SUBJECT, [MESSAGE] = @MESSAGE, [ENVELOPE_UUID] = @UUID WHERE GUID = @ID AND USER_ID = @USER_ID" Dim oCommand As New SqlCommand(oSql) oCommand.Parameters.Add("SUBJECT", SqlDbType.NVarChar).Value = pEnvelope.Subject @@ -26,18 +30,12 @@ Public Class EnvelopeController oCommand.Parameters.Add("ID", SqlDbType.Int).Value = pEnvelope.Id oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pEnvelope.UserId - Dim oResult = Database.ExecuteNonQuery(oCommand) - If oResult = True Then - Return True - Else - Return False + Dim oResult = Database.ExecuteNonQueryWithConnectionObject(oCommand, oConnection, MSSQLServer.TransactionMode.ExternalTransaction, oTransaction) + If oResult = False Then + Throw New ApplicationException End If - Catch ex As Exception - Logger.Error(ex) - End Try + Else - Else - Try Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE] (SUBJECT, MESSAGE, ENVELOPE_UUID, STATUS, USER_ID) VALUES (@SUBJECT, @MESSAGE, @UUID, @STATUS, @USER_ID)" Dim oCommand As New SqlCommand(oSql) oCommand.Parameters.Add("SUBJECT", SqlDbType.NVarChar).Value = pEnvelope.Subject @@ -46,23 +44,209 @@ Public Class EnvelopeController oCommand.Parameters.Add("STATUS", SqlDbType.NVarChar).Value = pEnvelope.Status.ToString() oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pEnvelope.UserId - Dim oResult = Database.ExecuteNonQuery(oCommand) - If oResult = True Then - pEnvelope.Id = GetEnvelopeId(pEnvelope.UserId) - Return True - Else - Return False + If Database.ExecuteNonQuery(oCommand, oTransaction) = False Then + Throw New ApplicationException + End If + + pEnvelope.Id = GetEnvelopeId(pEnvelope.UserId, oTransaction) + + If SaveEnvelopeReceivers(pEnvelope, oTransaction) = False Then + Throw New ApplicationException End If - Catch ex As Exception - Logger.Error(ex) - End Try + If SaveEnvelopeDocuments(pEnvelope, oTransaction) = False Then + Throw New ApplicationException + End If + End If + + oTransaction.Commit() + + Envelope = pEnvelope + + Return True + Catch ex As Exception + Logger.Error(ex) + oTransaction.Rollback() + + Return False + End Try + End Function + + Public Function DeleteDocument(pDocument As EnvelopeFile) As Boolean + If Envelope Is Nothing Then + Return False + End If + + Dim oSql = "DELETE FROM [dbo].[TBSIG_ENVELOPE_DOCUMENT] WHERE FILENAME = @FILENAME AND ENVELOPE_ID = @ENVELOPE_ID" + Dim oCommand As New SqlCommand(oSql) + oCommand.Parameters.Add("FILENAME", SqlDbType.NVarChar).Value = pDocument.Filename + oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.Int).Value = Envelope.Id + + Return Database.ExecuteNonQuery(oCommand) + End Function +#End Region + + Private Function SaveEnvelopeDocuments(pEnvelope As Envelope, pTransaction As SqlTransaction) As Boolean + Try + Return pEnvelope.Documents. + Select(Function(d) InsertDocument(pEnvelope, d, pTransaction)). + All(Function(pResult) pResult = True) + + Catch ex As Exception + Logger.Error(ex) + Return False + End Try + End Function + + Private Function InsertDocument(pEnvelope As Envelope, pDocument As EnvelopeFile, pTransaction As SqlTransaction) As Boolean + Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE_DOCUMENT] + ([FILENAME] + ,[FILEPATH] + ,[ENVELOPE_ID]) + VALUES + (@FILENAME + ,@FILEPATH + ,@ENVELOPE_ID)" + + Dim oCommand As New SqlCommand(oSql) + oCommand.Parameters.Add("FILENAME", SqlDbType.NVarChar).Value = pDocument.Filename + oCommand.Parameters.Add("FILEPATH", SqlDbType.NVarChar).Value = pDocument.Filepath + oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.Int).Value = pEnvelope.Id + + pDocument.EnvelopeId = pEnvelope.Id + + Return Database.ExecuteNonQuery(oCommand, pTransaction) + End Function + + Private Function SaveEnvelopeReceivers(pEnvelope As Envelope, pTransaction As SqlTransaction) As Boolean + Try + If pEnvelope.Id = Nothing Then + Throw New ArgumentNullException("EnvelopeId") + End If + + If UpdateReceivers(pEnvelope.Receivers, pTransaction) = False Then + Return False + End If + + If AssignReceivers(pEnvelope, pTransaction) = False Then + Return False + End If + + Return True + Catch ex As Exception + Logger.Error(ex) + Return False + End Try + End Function + + Private Function UpdateReceivers(pReceivers As List(Of Receiver), pTransaction As SqlTransaction) As Boolean + Try + Return pReceivers. + Select(Function(r) UpdateReceiver(r, pTransaction)). + All(Function(pResult) pResult = True) + + Catch ex As Exception + Logger.Error(ex) + Return False + End Try + End Function + + Private Function AssignReceivers(pEnvelope As Envelope, pTransaction As SqlTransaction) As Boolean + If Database.ExecuteNonQuery($"DELETE FROM [dbo].[TBSIG_ENVELOPE_RECEIVER] WHERE [ENVELOPE_ID] = {pEnvelope.Id}") = False Then + Return False End If + + Return pEnvelope.Receivers. + Select(Function(r) AssignReceiver(pEnvelope, r, pTransaction)). + All(Function(pResult) pResult = True) + + End Function + + Private Function AssignReceiver(pEnvelope As Envelope, pReceiver As Receiver, pTransaction As SqlTransaction) As Boolean + Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE_RECEIVER] + ([ENVELOPE_ID] + ,[RECEIVER_ID] + ,[PRIVATE_MESSAGE] + ,[ACCESS_CODE] + ,[SEQUENCE]) + VALUES + (@ENVELOPE_ID + ,@RECEIVER_ID + ,@MESSAGE + ,@ACCESS_CODE + ,@SEQUENCE)" + + Dim oCommand As New SqlCommand(oSql) + oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.NVarChar).Value = pEnvelope.Id + oCommand.Parameters.Add("RECEIVER_ID", SqlDbType.NVarChar).Value = pReceiver.Id + oCommand.Parameters.Add("MESSAGE", SqlDbType.NVarChar).Value = pReceiver.PrivateMessage + oCommand.Parameters.Add("ACCESS_CODE", SqlDbType.NVarChar).Value = pReceiver.AccessCode + oCommand.Parameters.Add("SEQUENCE", SqlDbType.NVarChar).Value = pReceiver.Sequence + + Return Database.ExecuteNonQuery(oCommand, pTransaction) + End Function + + Private Function UpdateReceiver(pReceiver As Receiver, pTransaction As SqlTransaction) As Boolean + If pReceiver.Id = 0 Then + Dim oSql As String = "INSERT INTO [dbo].[TBSIG_RECEIVER] + ([NAME] + ,[EMAIL_ADDRESS] + ,[SIGNATURE] + ,[COMPANY_NAME] + ,[JOB_TITLE]) + VALUES + (@NAME + ,@EMAIL + ,@SIGNATURE + ,@COMPANY + ,@JOB)" + + Dim oCommand = New SqlCommand(oSql) + oCommand.Parameters.Add("NAME", SqlDbType.NVarChar).Value = pReceiver.Name + oCommand.Parameters.Add("EMAIL", SqlDbType.NVarChar).Value = pReceiver.Email + oCommand.Parameters.Add("SIGNATURE", SqlDbType.NVarChar).Value = pReceiver.Signature + oCommand.Parameters.Add("COMPANY", SqlDbType.NVarChar).Value = pReceiver.Company + oCommand.Parameters.Add("JOB", SqlDbType.NVarChar).Value = pReceiver.JobTitle + + Dim oResult = Database.ExecuteNonQuery(oCommand, pTransaction) + If oResult = True Then + pReceiver.Id = GetReceiverId(pReceiver.Email, pTransaction) + Else + Return False + End If + + Return True + + Else + Dim oSql As String = "UPDATE [dbo].[TBSIG_RECEIVER] + SET [NAME] = @NAME + ,[COMPANY_NAME] = @COMPANY + ,[JOB_TITLE] = @JOB + WHERE GUID = @GUID" + + Dim oCommand = New SqlCommand(oSql) + oCommand.Parameters.Add("NAME", SqlDbType.NVarChar).Value = pReceiver.Name + oCommand.Parameters.Add("COMPANY", SqlDbType.NVarChar).Value = pReceiver.Company + oCommand.Parameters.Add("JOB", SqlDbType.NVarChar).Value = pReceiver.JobTitle + oCommand.Parameters.Add("GUID", SqlDbType.Int).Value = pReceiver.Id + + Return Database.ExecuteNonQuery(oCommand, pTransaction) + End If + End Function + + Private Function GetEnvelopeId(pUserId As Integer, pTransaction As SqlTransaction) As Integer + Try + Return Database.GetScalarValue($"SELECT MAX(GUID) FROM TBSIG_ENVELOPE WHERE USER_ID = {pUserId}", pTransaction) + + Catch ex As Exception + Logger.Error(ex) + Return Nothing + End Try End Function - Private Function GetEnvelopeId(pUserId As Integer) As Integer + Private Function GetReceiverId(pEmailAddress As String, pTransaction As SqlTransaction) As Integer Try - Return Database.GetScalarValue($"SELECT MAX(GUID) FROM TBSIG_ENVELOPE WHERE USER_ID = {pUserId}") + Return Database.GetScalarValue($"SELECT GUID FROM TBSIG_RECEIVER WHERE EMAIL_ADDRESS = '{pEmailAddress}'", pTransaction) Catch ex As Exception Logger.Error(ex) diff --git a/EnvelopeGenerator.Form/Entities/Envelope.vb b/EnvelopeGenerator.Form/Entities/Envelope.vb index b472866d..2bfcd707 100644 --- a/EnvelopeGenerator.Form/Entities/Envelope.vb +++ b/EnvelopeGenerator.Form/Entities/Envelope.vb @@ -7,7 +7,7 @@ Public Property Status As Constants.EnvelopeStatus = Constants.EnvelopeStatus.Created Public Property Documents As New List(Of EnvelopeFile) - Public Property Receivers As New List(Of EnvelopeReceiver) + Public Property Receivers As New List(Of Receiver) Public Sub New(pSubject As String, pMessage As String, pUserId As Integer) Subject = pSubject diff --git a/EnvelopeGenerator.Form/Entities/EnvelopeFile.vb b/EnvelopeGenerator.Form/Entities/EnvelopeFile.vb index 3e59ecb3..8fd01d95 100644 --- a/EnvelopeGenerator.Form/Entities/EnvelopeFile.vb +++ b/EnvelopeGenerator.Form/Entities/EnvelopeFile.vb @@ -1,7 +1,9 @@ Imports System.IO Public Class EnvelopeFile - Private Property FileInfo As FileInfo + Public Property FileInfo As FileInfo + + Public Property EnvelopeId As Integer = 0 Public ReadOnly Property Filename As String Get @@ -9,7 +11,9 @@ Public Class EnvelopeFile End Get End Property - Public Sub New(pFilePath As String) - FileInfo = New FileInfo(pFilePath) - End Sub + Public ReadOnly Property Filepath As String + Get + Return FileInfo.FullName + End Get + End Property End Class diff --git a/EnvelopeGenerator.Form/Entities/EnvelopeReceiver.vb b/EnvelopeGenerator.Form/Entities/EnvelopeReceiver.vb index 146ca6d3..b2ba743d 100644 --- a/EnvelopeGenerator.Form/Entities/EnvelopeReceiver.vb +++ b/EnvelopeGenerator.Form/Entities/EnvelopeReceiver.vb @@ -1,4 +1,22 @@ -Public Class EnvelopeReceiver +Imports DigitalData.Modules.Base + +Public Class Receiver + Public Property Id As Integer Public Property Name As String + Public Property Company As String = "" + Public Property JobTitle As String = "" + Public Property Email As String + Public ReadOnly Property Signature As String + Get + Return StringEx.GetChecksum(Email.ToUpper) + End Get + End Property + + Public Property Sequence As Integer = 0 + Public Property PrivateMessage As String = "" + Public Property AccessCode As String = "" + + + End Class diff --git a/EnvelopeGenerator.Form/frmEditor.Designer.vb b/EnvelopeGenerator.Form/frmEditor.Designer.vb index b1c08691..921782a8 100644 --- a/EnvelopeGenerator.Form/frmEditor.Designer.vb +++ b/EnvelopeGenerator.Form/frmEditor.Designer.vb @@ -48,6 +48,7 @@ Partial Public Class frmEditor Me.RibbonPageGroup4 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup() Me.SplitContainerControl1 = New DevExpress.XtraEditors.SplitContainerControl() Me.GridDocuments = New DevExpress.XtraGrid.GridControl() + Me.FrmEditorBindingSource = New System.Windows.Forms.BindingSource(Me.components) Me.ViewDocuments = New DevExpress.XtraGrid.Views.Tile.TileView() Me.SplitContainerControl2 = New DevExpress.XtraEditors.SplitContainerControl() Me.PanelControl2 = New DevExpress.XtraEditors.PanelControl() @@ -59,12 +60,13 @@ Partial Public Class frmEditor Me.LayoutControlItem3 = New DevExpress.XtraLayout.LayoutControlItem() Me.PanelControl1 = New DevExpress.XtraEditors.PanelControl() Me.GridReceivers = New DevExpress.XtraGrid.GridControl() - Me.envelopeReceiverBindingSource = New System.Windows.Forms.BindingSource(Me.components) + Me.EnvelopeReceiverBindingSource = New System.Windows.Forms.BindingSource(Me.components) Me.ViewReceivers = New DevExpress.XtraGrid.Views.Grid.GridView() Me.colName = New DevExpress.XtraGrid.Columns.GridColumn() Me.colEmail = New DevExpress.XtraGrid.Columns.GridColumn() - Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog() Me.RepositoryItemEmailEdit = New DevExpress.XtraEditors.Repository.RepositoryItemTextEdit() + Me.EnvelopeDocumentBindingSource = New System.Windows.Forms.BindingSource(Me.components) + Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog() CType(Me.RibbonControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.SplitContainerControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.SplitContainerControl1.Panel1, System.ComponentModel.ISupportInitialize).BeginInit() @@ -73,6 +75,7 @@ Partial Public Class frmEditor Me.SplitContainerControl1.Panel2.SuspendLayout() Me.SplitContainerControl1.SuspendLayout() CType(Me.GridDocuments, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.FrmEditorBindingSource, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.ViewDocuments, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.SplitContainerControl2, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.SplitContainerControl2.Panel1, System.ComponentModel.ISupportInitialize).BeginInit() @@ -92,9 +95,10 @@ Partial Public Class frmEditor CType(Me.PanelControl1, System.ComponentModel.ISupportInitialize).BeginInit() Me.PanelControl1.SuspendLayout() CType(Me.GridReceivers, System.ComponentModel.ISupportInitialize).BeginInit() - CType(Me.envelopeReceiverBindingSource, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.EnvelopeReceiverBindingSource, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.ViewReceivers, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.RepositoryItemEmailEdit, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.EnvelopeDocumentBindingSource, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'colFilename @@ -220,6 +224,10 @@ Partial Public Class frmEditor Me.GridDocuments.TabIndex = 0 Me.GridDocuments.ViewCollection.AddRange(New DevExpress.XtraGrid.Views.Base.BaseView() {Me.ViewDocuments}) ' + 'FrmEditorBindingSource + ' + Me.FrmEditorBindingSource.DataSource = GetType(EnvelopeGenerator.Form.frmEditor) + ' 'ViewDocuments ' Me.ViewDocuments.Columns.AddRange(New DevExpress.XtraGrid.Columns.GridColumn() {Me.colFilename}) @@ -339,7 +347,7 @@ Partial Public Class frmEditor ' 'GridReceivers ' - Me.GridReceivers.DataSource = Me.envelopeReceiverBindingSource + Me.GridReceivers.DataSource = Me.EnvelopeReceiverBindingSource Me.GridReceivers.Dock = System.Windows.Forms.DockStyle.Fill Me.GridReceivers.Location = New System.Drawing.Point(12, 12) Me.GridReceivers.MainView = Me.ViewReceivers @@ -350,10 +358,10 @@ Partial Public Class frmEditor Me.GridReceivers.TabIndex = 0 Me.GridReceivers.ViewCollection.AddRange(New DevExpress.XtraGrid.Views.Base.BaseView() {Me.ViewReceivers}) ' - 'envelopeReceiverBindingSource + 'EnvelopeReceiverBindingSource ' - Me.envelopeReceiverBindingSource.DataMember = "Receivers" - Me.envelopeReceiverBindingSource.DataSource = GetType(EnvelopeGenerator.Form.frmEditor) + Me.EnvelopeReceiverBindingSource.DataMember = "Receivers" + Me.EnvelopeReceiverBindingSource.DataSource = GetType(EnvelopeGenerator.Form.frmEditor) ' 'ViewReceivers ' @@ -379,11 +387,6 @@ Partial Public Class frmEditor Me.colEmail.Visible = True Me.colEmail.VisibleIndex = 1 ' - 'OpenFileDialog1 - ' - Me.OpenFileDialog1.FileName = "OpenFileDialog1" - Me.OpenFileDialog1.Filter = "PDF Files|*.pdf" - ' 'RepositoryItemEmailEdit ' Me.RepositoryItemEmailEdit.AutoHeight = False @@ -391,6 +394,16 @@ Partial Public Class frmEditor Me.RepositoryItemEmailEdit.MaskSettings.Set("mask", "\w+@\w+\.\w+") Me.RepositoryItemEmailEdit.Name = "RepositoryItemEmailEdit" ' + 'EnvelopeDocumentBindingSource + ' + Me.EnvelopeDocumentBindingSource.DataMember = "Documents" + Me.EnvelopeDocumentBindingSource.DataSource = GetType(EnvelopeGenerator.Form.frmEditor) + ' + 'OpenFileDialog1 + ' + Me.OpenFileDialog1.FileName = "OpenFileDialog1" + Me.OpenFileDialog1.Filter = "PDF Files|*.pdf" + ' 'frmEditor ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) @@ -409,6 +422,7 @@ Partial Public Class frmEditor CType(Me.SplitContainerControl1, System.ComponentModel.ISupportInitialize).EndInit() Me.SplitContainerControl1.ResumeLayout(False) CType(Me.GridDocuments, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.FrmEditorBindingSource, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.ViewDocuments, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.SplitContainerControl2.Panel1, System.ComponentModel.ISupportInitialize).EndInit() Me.SplitContainerControl2.Panel1.ResumeLayout(False) @@ -428,9 +442,10 @@ Partial Public Class frmEditor CType(Me.PanelControl1, System.ComponentModel.ISupportInitialize).EndInit() Me.PanelControl1.ResumeLayout(False) CType(Me.GridReceivers, System.ComponentModel.ISupportInitialize).EndInit() - CType(Me.envelopeReceiverBindingSource, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.EnvelopeReceiverBindingSource, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.ViewReceivers, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.RepositoryItemEmailEdit, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.EnvelopeDocumentBindingSource, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) Me.PerformLayout() @@ -464,10 +479,12 @@ Partial Public Class frmEditor Friend WithEvents RibbonPageGroup4 As DevExpress.XtraBars.Ribbon.RibbonPageGroup Friend WithEvents PanelControl1 As PanelControl Friend WithEvents PanelControl2 As PanelControl - Friend WithEvents envelopeReceiverBindingSource As BindingSource + Friend WithEvents EnvelopeReceiverBindingSource As BindingSource Friend WithEvents colName As DevExpress.XtraGrid.Columns.GridColumn Friend WithEvents colEmail As DevExpress.XtraGrid.Columns.GridColumn Friend WithEvents RepositoryItemEmailEdit As Repository.RepositoryItemTextEdit + Friend WithEvents EnvelopeDocumentBindingSource As BindingSource + Friend WithEvents FrmEditorBindingSource As BindingSource #End Region diff --git a/EnvelopeGenerator.Form/frmEditor.resx b/EnvelopeGenerator.Form/frmEditor.resx index 5a3ee7ed..844d5f75 100644 --- a/EnvelopeGenerator.Form/frmEditor.resx +++ b/EnvelopeGenerator.Form/frmEditor.resx @@ -215,9 +215,15 @@ dWUiIC8+DQogIDwvZz4NCjwvc3ZnPgs= - + 159, 17 + + 622, 17 + + + 385, 17 + 17, 17 diff --git a/EnvelopeGenerator.Form/frmEditor.vb b/EnvelopeGenerator.Form/frmEditor.vb index ee1d5d07..7ed4d7de 100644 --- a/EnvelopeGenerator.Form/frmEditor.vb +++ b/EnvelopeGenerator.Form/frmEditor.vb @@ -1,14 +1,10 @@ Imports System.ComponentModel -Imports System.Data.SqlClient -Imports System.Text -Imports DevExpress.XtraGrid.Views.Tile -Imports DigitalData.Modules.Database +Imports System.IO Imports DigitalData.Modules.Logging Partial Public Class frmEditor - Private ReadOnly Documents As New List(Of EnvelopeFile) - - Public Property Receivers As New List(Of EnvelopeReceiver) + Public Property Documents As New BindingList(Of EnvelopeFile) + Public Property Receivers As New BindingList(Of Receiver) Private Controller As EnvelopeController Private Logger As Logger @@ -21,10 +17,8 @@ Partial Public Class frmEditor Private Sub btnNewFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnNewFile.ItemClick If OpenFileDialog1.ShowDialog() = DialogResult.OK Then - Documents.Add(New EnvelopeFile(OpenFileDialog1.FileName)) - - GridDocuments.DataSource = Nothing - GridDocuments.DataSource = Documents + Dim oFileInfo = New FileInfo(OpenFileDialog1.FileName) + Documents.Add(New EnvelopeFile() With {.FileInfo = oFileInfo}) End If End Sub @@ -32,12 +26,16 @@ Partial Public Class frmEditor Logger = State.LogConfig.GetLogger() Controller = New EnvelopeController(State) - GridReceivers.DataSource = envelopeReceiverBindingSource + GridDocuments.DataSource = Documents + GridReceivers.DataSource = Receivers End Sub Private Sub btnDeleteFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDeleteFile.ItemClick If ViewDocuments.GetSelectedRows().Count > 0 Then - ViewDocuments.DeleteSelectedRows() + Dim oDocument As EnvelopeFile = DirectCast(ViewDocuments.GetFocusedRow(), EnvelopeFile) + If Controller.DeleteDocument(oDocument) Then + Documents.Remove(oDocument) + End If End If End Sub @@ -45,10 +43,9 @@ Partial Public Class frmEditor Try Dim oSubject = txtSubject.EditValue?.ToString Dim oMessage = txtMessage.EditValue?.ToString - Dim oReceivers As BindingList(Of EnvelopeReceiver) = envelopeReceiverBindingSource.List Dim oEnv = New Envelope(oSubject, oMessage, State.UserId) With { - .Receivers = oReceivers.ToList, - .Documents = Documents + .Receivers = Receivers.ToList, + .Documents = Documents.ToList } Dim oErrors = oEnv.Validate()