Jonathan Jenne b63655b212 06-07-2023
2023-07-06 14:24:30 +02:00

67 lines
2.5 KiB
VB.net

Imports System.ComponentModel
Imports System.IO
Imports DigitalData.Modules.Logging
Partial Public Class frmEditor
Public Property Documents As New BindingList(Of EnvelopeFile)
Public Property Receivers As New BindingList(Of Receiver)
Private Controller As EnvelopeController
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 oFileInfo = New FileInfo(OpenFileDialog1.FileName)
Documents.Add(New EnvelopeFile() With {.FileInfo = oFileInfo})
End If
End Sub
Private Sub frmEditor_Load(sender As Object, e As EventArgs) Handles Me.Load
Logger = State.LogConfig.GetLogger()
Controller = New EnvelopeController(State)
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
Dim oDocument As EnvelopeFile = DirectCast(ViewDocuments.GetFocusedRow(), EnvelopeFile)
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
Dim oSubject = txtSubject.EditValue?.ToString
Dim oMessage = txtMessage.EditValue?.ToString
Dim oEnv = New Envelope(oSubject, oMessage, State.UserId) With {
.Receivers = Receivers.ToList,
.Documents = Documents.ToList
}
Dim oErrors = oEnv.Validate()
If oErrors.Any Then
Dim oError = "Fehler beim Speichern des Umschlags:" & vbNewLine & vbNewLine & String.Join(vbNewLine, oErrors)
MsgBox(oError, MsgBoxStyle.Exclamation, Text)
ElseIf Controller.SaveEnvelope(oEnv) = False Then
MsgBox("Fehler beim Speichern des Umschlags!", MsgBoxStyle.Critical, Text)
Else
'YAY!
End If
Catch ex As Exception
Logger.Error(ex)
End Try
End Sub
End Class