Jonathan Jenne 462bf4a61f 2023-08-07
2023-08-07 11:23:52 +02:00

137 lines
5.2 KiB
VB.net

Imports System.ComponentModel
Imports System.IO
Imports DigitalData.Modules.Logging
Imports EnvelopeGenerator.Common
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("Dokument konnte nicht gespeichert werden!", 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()
If Envelope Is Nothing Then
Controller = New EnvelopeEditorController(State)
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
End If
GridDocuments.DataSource = Documents
GridReceivers.DataSource = Receivers
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
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
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
Dim oError = "Fehler beim Speichern des Umschlags:" & vbNewLine & vbNewLine & String.Join(vbNewLine, oErrors)
MsgBox(oError, MsgBoxStyle.Exclamation, Text)
Return False
ElseIf Controller.SaveEnvelope(oEnvelope) = False Then
MsgBox("Fehler beim Speichern des Umschlags!", MsgBoxStyle.Critical, Text)
Return False
Else
Return True
End If
End Function
Private Sub RibbonControl1_Click(sender As Object, e As EventArgs) Handles RibbonControl1.Click
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
' TODO: Delete receivers for ALL documents
Dim oMessage2 = "Es gibt für diesen Empfänger bereits Elemente. Wollen Sie den Empfänger trotzdem löschen?"
Dim oMessage = "Wollen Sie den ausgewählten Empfänger löschen?"
If MsgBox(oMessage, MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text) = MsgBoxResult.No Then
Exit Sub
End If
End Sub
End Class