This commit is contained in:
Jonathan Jenne
2023-08-14 13:33:53 +02:00
parent 7c31ccee1c
commit 069f5a6f88
4 changed files with 220 additions and 48 deletions

View File

@@ -1,8 +1,12 @@
Imports DevExpress.XtraBars
Imports System.Windows.Forms.VisualStyles.VisualStyleElement.Window
Imports DevExpress.Utils
Imports DevExpress.XtraBars
Imports DevExpress.XtraBars.Ribbon.ViewInfo
Imports DigitalData.Modules.Logging
Imports EnvelopeGenerator.Common
Imports GdPicture14
Imports GdPicture14.Annotations
Imports NLog.Fluent
Partial Public Class frmFieldEditor
Private LogConfig As LogConfig
@@ -63,23 +67,38 @@ Partial Public Class frmFieldEditor
Private Function CreateBarItem(pReceiver As EnvelopeReceiver) As BarItem
Dim oItem = New BarButtonItem(BarManager1, pReceiver.Name)
AddHandler oItem.ItemClick, AddressOf BarItem_Click
AddHandler oItem.ItemClick, AddressOf ReceiverItem_Click
oItem.Tag = pReceiver
Return oItem
End Function
Private Sub BarItem_Click(sender As Object, e As ItemClickEventArgs)
AddElements()
Private Sub ReceiverItem_Click(sender As Object, e As ItemClickEventArgs)
Me.SuspendLayout()
Dim oReceiver As EnvelopeReceiver = e.Item.Tag
Dim oCurrentPage = GDViewer.CurrentPage
Dim oCurrentPosition = GDViewer.GetVScrollBarPosition()
If oReceiver.Id = SelectedReceiver.Id Then
Exit Sub
End If
AddElementsToController()
If Controller.SaveElements(SelectedReceiver.Id) Then
Dim oReceiver As EnvelopeReceiver = e.Item.Tag
SetReceiver(oReceiver)
ClearAnnotations()
LoadAnnotations(oReceiver.Id)
GDViewer.DisplayFirstPage()
DisplayPage(oCurrentPage)
GDViewer.SetVScrollBarPosition(oCurrentPosition)
GDViewer.Redraw()
TestViewerActionSuccessful("ReceiverItem_Click/Redraw")
Else
MsgBox("Elemente konnten nicht gespeichert werden!", MsgBoxStyle.Critical, Text)
End If
Me.ResumeLayout()
End Sub
Private Sub SetReceiver(pReceiver As EnvelopeReceiver)
@@ -87,7 +106,14 @@ Partial Public Class frmFieldEditor
SelectedReceiver = pReceiver
End Sub
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
Private Sub DisplayPage(pPage As Integer)
GDViewer.LockViewer = True
GDViewer.DisplayPage(pPage)
GDViewer.LockViewer = False
End Sub
Private Sub BarButtonItem1_ItemClick(sender As Object, e As ItemClickEventArgs) Handles BarButtonItem1.ItemClick
If GDViewer IsNot Nothing Then
AddHandler GDViewer.BeforeAnnotationAddedByUser, AddressOf Viewer_BeforeAnnotationAddedByUser
@@ -102,7 +128,7 @@ Partial Public Class frmFieldEditor
Private Sub Viewer_AnnotationAddedByUser(pAnnotationIdx As Integer)
Dim oAnnotation = GDViewer.GetAnnotationFromIdx(pAnnotationIdx)
Dim oPage = GDViewer.CurrentPage
Dim oTag = GetAnnotationTag(SelectedReceiver.Id, oPage, pAnnotationIdx)
Dim oTag = GetAnnotationTag(SelectedReceiver.Id, oPage, -1)
If TypeOf oAnnotation Is AnnotationStickyNote Then
Dim oStickyNote As AnnotationStickyNote = oAnnotation
@@ -123,34 +149,67 @@ Partial Public Class frmFieldEditor
'NOOP
End Sub
Private Sub btnSave_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSave.ItemClick
'TODO: Save Annotations in Background
AddElements()
Private Sub btnSave_ItemClick(sender As Object, e As ItemClickEventArgs) Handles btnSave.ItemClick
Dim oCurrentPage = GDViewer.CurrentPage
AddElementsToController()
If Not Controller.SaveElements(SelectedReceiver.Id) Then
MsgBox("Elemente konnten nicht gespeichert werden!", MsgBoxStyle.Critical, Text)
End If
GDViewer.DisplayPage(GDViewer.CurrentPage)
UpdateAnnotationTag()
DisplayPage(oCurrentPage)
GDViewer.Redraw()
TestViewerActionSuccessful("btnSave_ItemClick/Redraw")
End Sub
Private Sub AddElements()
Private Sub AddElementsToController()
Dim oPageCount = GDViewer.PageCount
For oPage = 1 To oPageCount
GDViewer.DisplayPage(oPage)
Dim oAnnotationCount = GDViewer.GetAnnotationCount()
AddElementsToController(oPage)
Next
End Sub
Private Sub AddElementsToController(pPage As Integer)
Dim oAnnotationCount = GDViewer.GetAnnotationCount()
For oAnnotationIndex = 0 To oAnnotationCount - 1
Dim oAnnotation As Annotation = GDViewer.GetAnnotationFromIdx(oAnnotationIndex)
If TypeOf oAnnotation Is AnnotationStickyNote Then
Dim oStickyNote As AnnotationStickyNote = oAnnotation
Controller.AddOrUpdateElement(oStickyNote)
End If
Next
End Sub
Private Sub UpdateAnnotationTag()
Dim oPageCount = GDViewer.PageCount
For oPage = 1 To oPageCount
GDViewer.DisplayPage(oPage)
Dim oAnnotationCount = GDViewer.GetAnnotationCount()
For oAnnotationIndex = 0 To oAnnotationCount - 1
Dim oAnnotation As Annotation = GDViewer.GetAnnotationFromIdx(oAnnotationIndex)
If TypeOf oAnnotation Is AnnotationStickyNote Then
Dim oStickyNote As AnnotationStickyNote = oAnnotation
Controller.AddOrUpdateElement(oStickyNote)
Dim oTag = oStickyNote.Tag
Dim oInfo = Controller.GetElementInfo(oTag)
If oInfo.Guid = -1 Then
Dim oElement = Controller.GetElement(oStickyNote)
oStickyNote.Tag = GetAnnotationTag(SelectedReceiver.Id, oPage, oElement.Id)
End If
End If
Next
Next
End Sub
Private Sub ApplyAnnotationStyle(ByRef pAnnotation As Annotation)
If TypeOf pAnnotation Is AnnotationStickyNote Then
Dim oStickyNote As AnnotationStickyNote = pAnnotation
@@ -163,21 +222,36 @@ Partial Public Class frmFieldEditor
End Sub
Private Sub BarButtonItem3_ItemClick_1(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDelete.ItemClick
Private Sub btnDelete_ItemClick(sender As Object, e As ItemClickEventArgs) Handles btnDelete.ItemClick
Dim oSelected = GDViewer.GetSelectedAnnotationIdx()
If TestViewerActionSuccessful("btnDelete_ItemClick/GetSelectedAnnotationIdx") = False Then
Logger.Warn("Selected Annotation could not be fetched!")
Exit Sub
End If
If oSelected = -1 Then
Exit Sub
End If
If MsgBox("Wollen Sie die Annotation löschen?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question, Text) = DialogResult.Yes Then
Dim oAnnotation = GDViewer.GetAnnotationFromIdx(oSelected)
Dim oElement = Controller.GetElement(oAnnotation)
' Delete Element if it was already saved to db
If oElement IsNot Nothing Then
Controller.DeleteElement(oElement)
End If
GDViewer.DeleteAnnotation(oSelected)
If TestViewerActionSuccessful("btnDelete_ItemClick/DeleteAnnotation") = False Then
Logger.Warn("Annotation could not be deleted!")
End If
End If
End Sub
Private Sub LoadAnnotation(pElement As EnvelopeDocumentElement, pReceiverId As Integer)
Dim oAnnotation As AnnotationStickyNote = Manager.AddStickyNoteAnnot(0, 0, 0, 0, "SIGNATUR")
Dim oIndex = Manager.GetAnnotationIdx(oAnnotation)
Dim oPage = pElement.Page
If Manager.GetStat() = GdPictureStatus.OK Then
@@ -188,29 +262,54 @@ Partial Public Class frmFieldEditor
oAnnotation.Fill = True
oAnnotation.FillColor = Color.DarkRed
oAnnotation.Text = "SIGNATUR"
oAnnotation.Tag = GetAnnotationTag(pReceiverId, oPage, oIndex)
'If Manager.SaveAnnotationsToPage() = GdPictureStatus.OK Then
'End If
oAnnotation.Tag = GetAnnotationTag(pReceiverId, oPage, pElement.Id)
Else
Dim oStatus = Manager.GetStat()
MsgBox(String.Format("GDViewer returned error [{0}] on action [{1}]", oStatus.ToString, "LoadAnnotation"))
Logger.Error("GDViewer returned error [{0}] on action [{1}]", oStatus.ToString, "LoadAnnotation")
End If
End Sub
Private Sub ClearAnnotations()
Dim oPageCount = GDViewer.PageCount
For oPage = 1 To oPageCount
GDViewer.DisplayPage(oPage)
DisplayPage(oPage)
Dim oAnnotationCount = GDViewer.GetAnnotationCount()
For oAnnotationIndex = 0 To oAnnotationCount - 1
GDViewer.DeleteAnnotation(oAnnotationIndex)
' We always delete the first item in the list of annotations,
' because DeleteAnnotation expects and index, not an identifier
GDViewer.DeleteAnnotation(0)
If TestViewerActionSuccessful("ClearAnnotations") = False Then
Logger.Warn("Annotation could not be cleared!")
End If
Next
Next
End Sub
Private Function TestViewerActionSuccessful(pAction As String) As Boolean
Dim oStatus = GDViewer.GetStat()
If oStatus = GdPictureStatus.OK Then
Return True
Else
MsgBox(String.Format("GDViewer returned error [{0}] on action [{1}]", oStatus.ToString, pAction))
Logger.Error("GDViewer returned error [{0}] on action [{1}]", oStatus.ToString, pAction)
Return False
End If
End Function
Private Sub LoadAnnotations(pReceiverId As Integer)
Dim oPageCount = GDViewer.PageCount
For oPage = 1 To oPageCount
GDViewer.DisplayPage(oPage)
DisplayPage(oPage)
If TestViewerActionSuccessful("LoadAnnotations/DisplayPage") = False Then
Logger.Warn("Page could not be displayed!")
End If
Dim oCurrentPage = oPage
Dim oElements = Controller.Elements.
Where(Function(e) e.Page = oCurrentPage And e.ReceiverId = pReceiverId).
@@ -222,8 +321,8 @@ Partial Public Class frmFieldEditor
Next
End Sub
Private Function GetAnnotationTag(pReceiver As Integer, pPage As Integer, pIndex As Integer) As String
Return $"{pReceiver}|{pPage}|{pIndex}"
Private Function GetAnnotationTag(pReceiver As Integer, pPage As Integer, pGuid As Integer) As String
Return $"{pReceiver}|{pPage}|{pGuid}"
End Function
End Class