14-08-23
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user