Jonathan Jenne b24fbf58fc 19.07.2023
2023-07-31 09:52:49 +02:00

190 lines
6.3 KiB
VB.net

Imports System.ComponentModel
Imports System.Text
Imports DevExpress.XtraBars
Imports DigitalData.Modules.Logging
Imports GdPicture14
Imports GdPicture14.Annotations
Partial Public Class frmFieldEditor
Private LogConfig As LogConfig
Private Logger As Logger
Private GDViewer As GdViewer
Private Manager As AnnotationManager
Private Controller As FieldEditorController
Public Property Document As EnvelopeDocument = Nothing
Public Property GDPictureKey As String = ""
Public Property Receivers As List(Of EnvelopeReceiver)
Public Property SelectedReceiver As EnvelopeReceiver = Nothing
Public Property State As State
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath, CompanyName:="Digital Data", ProductName:="EnvelopeGenerator")
Logger = LogConfig.GetLogger()
If Document Is Nothing Then
Throw New ArgumentNullException("Document")
End If
If State Is Nothing Then
Throw New ArgumentNullException("State")
End If
If GDPictureKey = "" Then
Throw New ArgumentNullException("GDPictureKey")
End If
DocumentViewer1.Init(LogConfig, GDPictureKey)
DocumentViewer1.LoadFile(Document.Filepath)
If DocumentViewer1.PdfViewer IsNot Nothing Then
GDViewer = DocumentViewer1.PdfViewer
Manager = GDViewer.GetAnnotationManager()
Manager.InitFromGdViewer(GDViewer)
End If
SetReceiver(Receivers.First())
Dim oItems = Receivers.Select(AddressOf CreateBarItem).ToArray()
PopupMenu1.AddItems(oItems)
Controller = New FieldEditorController(State, Document)
End Sub
Private Function CreateBarItem(pReceiver As EnvelopeReceiver) As BarItem
Dim oItem = New BarButtonItem(BarManager1, pReceiver.Name)
AddHandler oItem.ItemClick, AddressOf BarItem_Click
oItem.Tag = pReceiver
Return oItem
End Function
Private Sub BarItem_Click(sender As Object, e As ItemClickEventArgs)
Dim oReceiver As EnvelopeReceiver = e.Item.Tag
SetReceiver(oReceiver)
End Sub
Private Sub SetReceiver(pReceiver As EnvelopeReceiver)
txtReceiver.Caption = pReceiver.Name
SelectedReceiver = pReceiver
End Sub
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
If GDViewer IsNot Nothing Then
AddHandler GDViewer.BeforeAnnotationAddedByUser, AddressOf Viewer_BeforeAnnotationAddedByUser
AddHandler GDViewer.AnnotationAddedByUser, AddressOf Viewer_AnnotationAddedByUser
GDViewer.AddStickyNoteAnnotationInteractive("SIGNATUR", Color.Black, "Arial", FontStyle.Regular, 10, 1, 0)
End If
End Sub
Private Sub Viewer_AnnotationAddedByUser(AnnotationIdx As Integer)
Dim oAnnotation = GDViewer.GetAnnotationFromIdx(AnnotationIdx)
Dim oPage = GDViewer.CurrentPage
Dim oTag = $"{oPage}|{AnnotationIdx}"
If TypeOf oAnnotation Is AnnotationStickyNote Then
Dim oStickyNote As AnnotationStickyNote = oAnnotation
oStickyNote.Width = 1
oStickyNote.Height = 1
oStickyNote.Tag = oTag
ApplyAnnotationStyle(oAnnotation)
End If
oAnnotation.CanRotate = False
oAnnotation.CanEdit = False
oAnnotation.CanResize = False
End Sub
Private Sub Viewer_BeforeAnnotationAddedByUser(AnnotationIdx As Integer)
'NOOP
End Sub
Private Sub btnSave_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSave.ItemClick
Dim oPageCount = GDViewer.PageCount
Dim oCurrentPage = GDViewer.CurrentPage
'TODO: Save Annotations in Background
For index = 1 To oPageCount
GDViewer.DisplayPage(index)
Dim oAnnotationCount = GDViewer.GetAnnotationCount()
For index1 = 0 To oAnnotationCount - 1
Dim oAnnotation As Annotation = GDViewer.GetAnnotationFromIdx(index1)
If TypeOf oAnnotation Is AnnotationStickyNote Then
Dim oStickyNote As AnnotationStickyNote = oAnnotation
Controller.AddOrUpdateElement(oStickyNote, SelectedReceiver.Id)
End If
Next
Next
If Not Controller.SaveElements() Then
MsgBox("Element konnten nicht gespeichert werden!", MsgBoxStyle.Critical, Text)
End If
GDViewer.DisplayPage(oCurrentPage)
End Sub
Private Sub ApplyAnnotationStyle(ByRef pAnnotation As Annotation)
If TypeOf pAnnotation Is AnnotationStickyNote Then
Dim oStickyNote As AnnotationStickyNote = pAnnotation
oStickyNote.Fill = True
oStickyNote.FillColor = Color.LightGoldenrodYellow
oStickyNote.Text = "SIGNATUR"
oStickyNote.Alignment = StringAlignment.Center
oStickyNote.LineAlignment = StringAlignment.Center
End If
End Sub
Private Sub BarButtonItem3_ItemClick_1(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDelete.ItemClick
Dim oSelected = GDViewer.GetSelectedAnnotationIdx()
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
GDViewer.DeleteAnnotation(oSelected)
End If
End Sub
Private Sub LoadAnnotation()
Dim oAnnotation As AnnotationStickyNote = Manager.AddStickyNoteAnnot(0, 0, 0, 0, "SIGNATUR")
If Manager.GetStat() = GdPictureStatus.OK Then
oAnnotation.Width = 2
oAnnotation.Height = 2
oAnnotation.Left = 1
oAnnotation.Top = 1
oAnnotation.Fill = True
oAnnotation.FillColor = Color.DarkRed
oAnnotation.Text = "SIGNATUR JUNGE"
If Manager.SaveAnnotationsToPage() = GdPictureStatus.OK Then
'oManager.BurnAnnotationsToPage(True)
'GDViewer.ReloadAnnotations()
'GDViewer.Redraw()
End If
End If
End Sub
End Class