248 lines
9.4 KiB
VB.net
248 lines
9.4 KiB
VB.net
Imports System.ComponentModel
|
|
Imports DevExpress.XtraGrid
|
|
Imports DevExpress.XtraGrid.Views.Grid
|
|
Imports DevExpress.XtraSplashScreen
|
|
Imports DigitalData.Modules.Logging
|
|
Imports EnvelopeGenerator.Common
|
|
Imports EnvelopeGenerator.Common.My
|
|
|
|
Partial Public Class frmEnvelopeEditor
|
|
Public Property Envelope As Envelope
|
|
Public Property Documents As New BindingList(Of EnvelopeDocument)
|
|
Public Property Receivers As New BindingList(Of EnvelopeReceiver)
|
|
|
|
Private Controller As EnvelopeEditorController
|
|
Private Logger As Logger
|
|
|
|
Public Property State As State
|
|
|
|
Public Sub New()
|
|
InitializeComponent()
|
|
End Sub
|
|
|
|
Private Sub btnNewFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnNewFile.ItemClick
|
|
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
|
|
Dim oDocument = Controller.CreateDocument(OpenFileDialog1.FileName)
|
|
|
|
If oDocument IsNot Nothing Then
|
|
Documents.Add(oDocument)
|
|
Else
|
|
MsgBox(Resources.Envelope.Document_Could_Not_Be_Saved, MsgBoxStyle.Critical, Text)
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub frmEditor_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
Logger = State.LogConfig.GetLogger()
|
|
Me.Text = State.DbConfig.ExternalProgramName + " Umschlag-Editor"
|
|
|
|
If Envelope Is Nothing Then
|
|
Controller = New EnvelopeEditorController(State)
|
|
|
|
' Get additional data
|
|
Dim oDataForm As New frmEnvelopeMainData() With {.State = State, .NewEnvelopeMode = True}
|
|
Dim oResult As DialogResult = oDataForm.ShowDialog()
|
|
If oResult = DialogResult.OK Then
|
|
Controller.Envelope.Title = oDataForm.EnvelopeTitle
|
|
Controller.Envelope.ContractType = oDataForm.EnvelopeContractType
|
|
Else
|
|
Me.Close()
|
|
End If
|
|
Else
|
|
Controller = New EnvelopeEditorController(State, Envelope)
|
|
Documents = New BindingList(Of EnvelopeDocument)(Controller.Envelope.Documents)
|
|
Receivers = New BindingList(Of EnvelopeReceiver)(Controller.Envelope.Receivers)
|
|
txtMessage.EditValue = Controller.Envelope.Message
|
|
txtSubject.EditValue = Controller.Envelope.Subject
|
|
|
|
For Each docItem As EnvelopeDocument In Documents
|
|
If docItem.Thumbnail Is Nothing Then
|
|
docItem.Thumbnail = Controller.CreateThumbnail(docItem.Filepath)
|
|
End If
|
|
Next
|
|
|
|
If Envelope.Status = Constants.EnvelopeStatus.Sent Then
|
|
' TODO - Nach Testen
|
|
' SetFormReadonly()
|
|
End If
|
|
End If
|
|
|
|
GridDocuments.DataSource = Documents
|
|
GridReceivers.DataSource = Receivers
|
|
End Sub
|
|
|
|
Private Sub SetFormReadonly()
|
|
RibbonPageGroup1.Enabled = False
|
|
RibbonPageGroup2.Enabled = False
|
|
RibbonPageGroup3.Enabled = False
|
|
RibbonPageGroup5.Enabled = False
|
|
btnEditFields.Enabled = False
|
|
txtSubject.Properties.ReadOnly = True
|
|
txtMessage.Properties.ReadOnly = True
|
|
ViewReceivers.OptionsBehavior.ReadOnly = True
|
|
ViewDocuments.OptionsBehavior.ReadOnly = True
|
|
End Sub
|
|
|
|
Private Sub frmEnvelopeEditor_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
|
|
Controller.CleanupEnvelope()
|
|
End Sub
|
|
|
|
Private Sub btnDeleteFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDeleteFile.ItemClick
|
|
If ViewDocuments.GetSelectedRows().Count > 0 Then
|
|
Dim oDocument As EnvelopeDocument = DirectCast(ViewDocuments.GetFocusedRow(), EnvelopeDocument)
|
|
If Controller.DeleteDocument(oDocument) Then
|
|
Documents.Remove(oDocument)
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub btnSave_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSave.ItemClick
|
|
Try
|
|
If SaveEnvelope() Then
|
|
|
|
End If
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub btnEditFields_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnEditFields.ItemClick
|
|
Dim oHandle = SplashScreenManager.ShowOverlayForm(Me)
|
|
|
|
Try
|
|
If ViewDocuments.GetSelectedRows().Count > 0 Then
|
|
Dim oDocument As EnvelopeDocument = DirectCast(ViewDocuments.GetFocusedRow(), EnvelopeDocument)
|
|
Dim oGDPictureKey As String = "21182889975216572111813147150675976632"
|
|
|
|
If SaveEnvelope() Then
|
|
Dim oForm As New frmFieldEditor() With {
|
|
.Document = Controller.Envelope.Documents.
|
|
Where(Function(d) d.Filename = oDocument.Filename).
|
|
SingleOrDefault(),
|
|
.GDPictureKey = oGDPictureKey,
|
|
.Receivers = Receivers.ToList,
|
|
.State = State
|
|
}
|
|
oForm.ShowDialog()
|
|
End If
|
|
End If
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Finally
|
|
SplashScreenManager.CloseOverlayForm(oHandle)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Function SaveEnvelope() As Boolean
|
|
Dim oSubject = txtSubject.EditValue?.ToString
|
|
Dim oMessage = txtMessage.EditValue?.ToString
|
|
|
|
' Ensure all receivers are saved
|
|
ViewReceivers.CloseEditor()
|
|
|
|
Dim oEnvelope = Controller.Envelope
|
|
oEnvelope.Subject = oSubject
|
|
oEnvelope.Message = oMessage
|
|
oEnvelope.Receivers = Receivers.ToList
|
|
oEnvelope.Documents = Documents.ToList
|
|
|
|
Dim oErrors = oEnvelope.Validate()
|
|
If oErrors.Any Then
|
|
ShowValidationErrors(Resources.Envelope.Errors_when_saving_the_envelope, oErrors)
|
|
Return False
|
|
End If
|
|
|
|
If Controller.CreateEnvelopeReceivers(oEnvelope.Receivers) = False Then
|
|
MsgBox(Resources.Envelope.Error_when_saving_the_recipients, MsgBoxStyle.Critical, Text)
|
|
Return False
|
|
End If
|
|
|
|
If Controller.SaveEnvelope() = False Then
|
|
MsgBox(Resources.Envelope.Error_when_saving_the_envelope, MsgBoxStyle.Critical, Text)
|
|
Return False
|
|
Else
|
|
Return True
|
|
End If
|
|
End Function
|
|
|
|
Private Sub ShowValidationErrors(pErrorTitle As String, pErrors As List(Of String))
|
|
Dim oError = pErrorTitle & vbNewLine & vbNewLine & String.Join(vbNewLine, pErrors)
|
|
MsgBox(oError, MsgBoxStyle.Exclamation, Text)
|
|
End Sub
|
|
|
|
Private Sub btnDeleteReceiver_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDeleteReceiver.ItemClick
|
|
If ViewReceivers.SelectedRowsCount = 0 Then
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim oReceiver As EnvelopeReceiver = ViewReceivers.GetFocusedRow()
|
|
|
|
If oReceiver Is Nothing Then
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim oMessage = Resources.Envelope.Do_you_want_to_delete_the_selected_recipient
|
|
If Controller.ElementsExist(oReceiver.Id) Then
|
|
oMessage = "Es gibt für diesen Empfänger bereits Elemente. Wollen Sie den Empfänger trotzdem löschen?"
|
|
End If
|
|
|
|
If MsgBox(oMessage, MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text) = MsgBoxResult.No Then
|
|
Exit Sub
|
|
End If
|
|
|
|
If Controller.DeleteReceiver(oReceiver) Then
|
|
Receivers.Remove(oReceiver)
|
|
Else
|
|
MsgBox(Resources.Envelope.Recipient_could_not_be_deleted, MsgBoxStyle.Critical, Text)
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Private Sub btnSendEnvelope_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSendEnvelope.ItemClick
|
|
If SaveEnvelope() = False Then
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim oErrors = Controller.ValidateEnvelopeForSending()
|
|
If oErrors.Any() Then
|
|
ShowValidationErrors(Resources.Envelope.Error_sending_the_envelope, oErrors)
|
|
Exit Sub
|
|
End If
|
|
|
|
If Controller.SendEnvelope() = False Then
|
|
MsgBox(Resources.Envelope.Envelope_could_not_be_sent, MsgBoxStyle.Critical, Text)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub btnCancel_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnCancel.ItemClick
|
|
|
|
End Sub
|
|
|
|
Private Sub btnEditData_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnEditData.ItemClick
|
|
Dim oForm As New frmEnvelopeMainData() With
|
|
{
|
|
.State = State,
|
|
.EnvelopeTitle = Controller.Envelope.Title,
|
|
.EnvelopeContractType = Controller.Envelope.ContractType,
|
|
.NewEnvelopeMode = False
|
|
}
|
|
If oForm.ShowDialog() = DialogResult.OK Then
|
|
Controller.Envelope.Title = oForm.EnvelopeTitle
|
|
Controller.Envelope.ContractType = oForm.EnvelopeContractType
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub GridReceivers_PaintEx(sender As Object, e As DevExpress.XtraGrid.PaintExEventArgs) Handles GridReceivers.PaintEx
|
|
Dim grid As GridControl = sender, view As GridView = Nothing
|
|
|
|
If TypeOf sender Is GridControl AndAlso TypeOf grid.MainView Is GridView Then
|
|
view = grid.MainView
|
|
Dim pen = New Pen(Color.Gainsboro, 2)
|
|
Dim info = view.GetViewInfo()
|
|
e.Cache.DrawRectangle(pen, info.Bounds)
|
|
pen.Dispose()
|
|
End If
|
|
End Sub
|
|
End Class
|