14-08-23
This commit is contained in:
parent
7c31ccee1c
commit
069f5a6f88
@ -1,5 +1,5 @@
|
||||
Public Class EnvelopeDocumentElement
|
||||
Public Property Id As Integer = 0
|
||||
Public Property Id As Integer = -1
|
||||
Public Property X As Double
|
||||
Public Property Y As Double
|
||||
Public Property Width As Double
|
||||
@ -11,5 +11,18 @@
|
||||
Public Property [ReadOnly] As Boolean = False
|
||||
Public Property Page As Integer = 1
|
||||
Public Property Status As Constants.ElementStatus = Constants.ElementStatus.Created
|
||||
Public Property AnnotationIndex As Integer
|
||||
Public Property Index As Integer = 0
|
||||
|
||||
Public ReadOnly Property Top As Single
|
||||
Get
|
||||
Return Math.Round(Y, 5)
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property Left As Single
|
||||
Get
|
||||
Return Math.Round(X, 5)
|
||||
End Get
|
||||
End Property
|
||||
|
||||
End Class
|
||||
|
||||
@ -19,8 +19,7 @@ Public Class ElementModel
|
||||
.Y = pRow.ItemEx("POSITION_Y", 0.0),
|
||||
.Width = pRow.ItemEx("WIDTH", 0.0),
|
||||
.Height = pRow.ItemEx("HEIGHT", 0.0),
|
||||
.Page = pRow.ItemEx("PAGE", 0),
|
||||
.AnnotationIndex = pRow.ItemEx("ANNOTATION_INDEX", 0)
|
||||
.Page = pRow.ItemEx("PAGE", 0)
|
||||
}
|
||||
End Function
|
||||
|
||||
@ -41,7 +40,7 @@ Public Class ElementModel
|
||||
|
||||
Public Function List(pDocumentId As Integer) As List(Of EnvelopeDocumentElement)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [dbo].[TBSIG_DOCUMENT_RECEIVER_ELEMENT] WHERE DOCUMENT_ID = {pDocumentId} ORDER BY PAGE ASC, ANNOTATION_INDEX ASC"
|
||||
Dim oSql = $"SELECT * FROM [dbo].[TBSIG_DOCUMENT_RECEIVER_ELEMENT] WHERE DOCUMENT_ID = {pDocumentId} ORDER BY PAGE ASC"
|
||||
Dim oTable = Database.GetDatatable(oSql)
|
||||
|
||||
Return oTable?.Rows.Cast(Of DataRow).
|
||||
@ -67,8 +66,7 @@ Public Class ElementModel
|
||||
,[REQUIRED]
|
||||
,[READ_ONLY]
|
||||
,[STATUS]
|
||||
,[PAGE]
|
||||
,[ANNOTATION_INDEX])
|
||||
,[PAGE])
|
||||
VALUES
|
||||
(@DOCUMENT_ID
|
||||
,@RECEIVER_ID
|
||||
@ -80,8 +78,7 @@ Public Class ElementModel
|
||||
,@REQUIRED
|
||||
,@READ_ONLY
|
||||
,@STATUS
|
||||
,@PAGE
|
||||
,@INDEX)"
|
||||
,@PAGE)"
|
||||
|
||||
Dim oCommand As New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("DOCUMENT_ID", SqlDbType.NVarChar).Value = pElement.DocumentId
|
||||
@ -95,7 +92,6 @@ Public Class ElementModel
|
||||
oCommand.Parameters.Add("READ_ONLY", SqlDbType.Bit).Value = pElement.ReadOnly
|
||||
oCommand.Parameters.Add("STATUS", SqlDbType.NVarChar).Value = pElement.Status.ToString
|
||||
oCommand.Parameters.Add("PAGE", SqlDbType.Int).Value = pElement.Page
|
||||
oCommand.Parameters.Add("INDEX", SqlDbType.Int).Value = pElement.AnnotationIndex
|
||||
|
||||
If Database.ExecuteNonQuery(oCommand) Then
|
||||
pElement.Id = GetElementId(pElement)
|
||||
|
||||
@ -12,6 +12,12 @@ Public Class FieldEditorController
|
||||
Private ReadOnly Document As EnvelopeDocument
|
||||
Public Property Elements As New List(Of EnvelopeDocumentElement)
|
||||
|
||||
Public Class ElementInfo
|
||||
Public ReceiverId As Integer
|
||||
Public Page As Integer
|
||||
Public Guid As Integer
|
||||
End Class
|
||||
|
||||
Public Sub New(pState As State, pDocument As EnvelopeDocument)
|
||||
MyBase.New(pState.LogConfig)
|
||||
Database = pState.Database
|
||||
@ -20,19 +26,56 @@ Public Class FieldEditorController
|
||||
ElementModel = New ElementModel(pState)
|
||||
End Sub
|
||||
|
||||
Public Sub AddOrUpdateElement(pAnnotation As AnnotationStickyNote)
|
||||
Dim oTag As String() = pAnnotation.Tag.Split("|"c)
|
||||
Public Function GetElementInfo(pAnnotationTag As String) As ElementInfo
|
||||
Dim oTag As String() = pAnnotationTag.Split("|"c)
|
||||
Dim oReceiverId = Integer.Parse(oTag(0))
|
||||
Dim oPage = Integer.Parse(oTag(1))
|
||||
Dim oIndex = Integer.Parse(oTag(2))
|
||||
Dim oELement = Elements.Where(Function(e) e.AnnotationIndex = oIndex And e.Page = oPage And e.ReceiverId = oReceiverId).SingleOrDefault()
|
||||
Dim oGuid = Integer.Parse(oTag(2))
|
||||
|
||||
If oELement IsNot Nothing Then
|
||||
oELement.Height = pAnnotation.Height
|
||||
oELement.Width = pAnnotation.Width
|
||||
oELement.X = pAnnotation.Left
|
||||
oELement.Y = pAnnotation.Top
|
||||
Return New ElementInfo With {
|
||||
.Guid = oGuid,
|
||||
.Page = oPage,
|
||||
.ReceiverId = oReceiverId
|
||||
}
|
||||
End Function
|
||||
|
||||
Private Function GetElementByPosition(pAnnotation As AnnotationStickyNote, pPage As Integer, pReceiverId As Integer) As EnvelopeDocumentElement
|
||||
Dim oElement = Elements.
|
||||
Where(Function(e)
|
||||
Return e.Left = CSng(Math.Round(pAnnotation.Left, 5)) And
|
||||
e.Top = CSng(Math.Round(pAnnotation.Top, 5)) And
|
||||
e.Page = pPage And
|
||||
e.ReceiverId = pReceiverId
|
||||
End Function).SingleOrDefault()
|
||||
Return oElement
|
||||
End Function
|
||||
|
||||
Private Function GetElementByGuid(pGuid As Integer) As EnvelopeDocumentElement
|
||||
Dim oElement = Elements.Where(Function(e) pGuid = e.Id).SingleOrDefault()
|
||||
Return oElement
|
||||
End Function
|
||||
|
||||
Public Function GetElement(pAnnotation As AnnotationStickyNote) As EnvelopeDocumentElement
|
||||
Dim oInfo = GetElementInfo(pAnnotation.Tag)
|
||||
|
||||
If oInfo.Guid = -1 Then
|
||||
Return GetElementByPosition(pAnnotation, oInfo.Page, oInfo.ReceiverId)
|
||||
Else
|
||||
Return GetElementByGuid(oInfo.Guid)
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Sub AddOrUpdateElement(pAnnotation As AnnotationStickyNote)
|
||||
Dim oElement = GetElement(pAnnotation)
|
||||
|
||||
If oElement IsNot Nothing Then
|
||||
oElement.Height = pAnnotation.Height
|
||||
oElement.Width = pAnnotation.Width
|
||||
oElement.X = pAnnotation.Left
|
||||
oElement.Y = pAnnotation.Top
|
||||
Else
|
||||
Dim oInfo = GetElementInfo(pAnnotation.Tag)
|
||||
|
||||
Elements.Add(New EnvelopeDocumentElement() With {
|
||||
.ElementType = Common.Constants.ElementType.Signature.ToString,
|
||||
.Height = pAnnotation.Height,
|
||||
@ -40,13 +83,18 @@ Public Class FieldEditorController
|
||||
.X = pAnnotation.Left,
|
||||
.Y = pAnnotation.Top,
|
||||
.DocumentId = Document.Id,
|
||||
.ReceiverId = oReceiverId,
|
||||
.AnnotationIndex = oIndex,
|
||||
.Page = oPage
|
||||
.ReceiverId = oInfo.ReceiverId,
|
||||
.Page = oInfo.Page
|
||||
})
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Function ClearElements(pPage As Integer, pReceiverId As Integer) As IEnumerable(Of EnvelopeDocumentElement)
|
||||
Return Elements.
|
||||
Where(Function(e) e.Page <> pPage And e.ReceiverId <> pReceiverId).
|
||||
ToList()
|
||||
End Function
|
||||
|
||||
Public Function LoadElements() As Boolean
|
||||
Elements = ElementModel.List(Document.Id)
|
||||
|
||||
@ -77,4 +125,20 @@ Public Class FieldEditorController
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function DeleteElement(pElement As EnvelopeDocumentElement) As Boolean
|
||||
Try
|
||||
' Element aus Datenbank löschen
|
||||
If ElementModel.DeleteElement(pElement) Then
|
||||
Dim oElement = New List(Of EnvelopeDocumentElement)() From {pElement}
|
||||
Elements = Elements.Except(oElement).ToList()
|
||||
Return True
|
||||
Else
|
||||
Logger.Error("Element [{0}] could not be deleted!", pElement.Id)
|
||||
Return False
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user