161 lines
6.3 KiB
VB.net
161 lines
6.3 KiB
VB.net
Imports System.Data.SqlClient
|
|
Imports DevExpress.Utils.CommonDialogs
|
|
Imports DevExpress.XtraBars.Docking2010.Views.NativeMdi
|
|
Imports DigitalData.Modules.Base
|
|
Imports DigitalData.Modules.Database
|
|
Imports GdPicture14.Annotations
|
|
|
|
Public Class FieldEditorController
|
|
Inherits BaseClass
|
|
|
|
Private ReadOnly ElementModel As ElementModel
|
|
|
|
Private ReadOnly Database As MSSQLServer
|
|
Private ReadOnly Document As EnvelopeDocument
|
|
Public Property Elements As New List(Of EnvelopeDocumentElement)
|
|
|
|
Public Sub New(pState As State, pDocument As EnvelopeDocument)
|
|
MyBase.New(pState.LogConfig)
|
|
Database = pState.Database
|
|
Document = pDocument
|
|
|
|
ElementModel = New ElementModel(pState)
|
|
End Sub
|
|
|
|
Public Sub AddOrUpdateElement(pAnnotation As AnnotationStickyNote, pReceiverId As Integer)
|
|
Dim oTag As String() = pAnnotation.Tag.Split("|"c)
|
|
Dim oPage = Integer.Parse(oTag(0))
|
|
Dim oIndex = Integer.Parse(oTag(1))
|
|
Dim oELement = Elements.Where(Function(e) e.AnnotationIndex = oIndex And e.Page = oPage).SingleOrDefault()
|
|
|
|
If oELement IsNot Nothing Then
|
|
oELement.Height = pAnnotation.Height
|
|
oELement.Width = pAnnotation.Width
|
|
oELement.X = pAnnotation.Left
|
|
oELement.Y = pAnnotation.Top
|
|
Else
|
|
Elements.Add(New EnvelopeDocumentElement() With {
|
|
.ElementType = Constants.ElementType.Signature.ToString,
|
|
.Height = pAnnotation.Height,
|
|
.Width = pAnnotation.Width,
|
|
.X = pAnnotation.Left,
|
|
.Y = pAnnotation.Top,
|
|
.DocumentId = Document.Id,
|
|
.ReceiverId = pReceiverId,
|
|
.AnnotationIndex = oIndex,
|
|
.Page = oPage
|
|
})
|
|
End If
|
|
End Sub
|
|
|
|
Public Function LoadElements() As Boolean
|
|
Elements = ElementModel.List(Document.Id)
|
|
|
|
If Elements Is Nothing Then
|
|
Return False
|
|
Else Return True
|
|
End If
|
|
End Function
|
|
|
|
Public Function SaveElements() As Boolean
|
|
Return Elements.
|
|
Select(AddressOf SaveElement).
|
|
All(Function(pResult) pResult = True)
|
|
End Function
|
|
|
|
Public Function SaveElement(pElement As EnvelopeDocumentElement) As Boolean
|
|
Try
|
|
If pElement.Id > 0 Then
|
|
Dim oSql = "UPDATE [dbo].[TBSIG_DOCUMENT_RECEIVER_ELEMENT]
|
|
SET [POSITION_X] = @POSITION_X
|
|
,[POSITION_Y] = @POSITION_Y
|
|
,[WIDTH] = @WIDTH
|
|
,[HEIGHT] = @HEIGHT
|
|
WHERE GUID = @GUID"
|
|
|
|
Dim oCommand As New SqlCommand(oSql)
|
|
oCommand.Parameters.Add("GUID", SqlDbType.NVarChar).Value = pElement.Id
|
|
oCommand.Parameters.Add("POSITION_X", SqlDbType.Float).Value = pElement.X
|
|
oCommand.Parameters.Add("POSITION_Y", SqlDbType.Float).Value = pElement.Y
|
|
oCommand.Parameters.Add("WIDTH", SqlDbType.Float).Value = pElement.Width
|
|
oCommand.Parameters.Add("HEIGHT", SqlDbType.Float).Value = pElement.Height
|
|
|
|
Return Database.ExecuteNonQuery(oCommand)
|
|
|
|
Else
|
|
Dim oSql = "INSERT INTO [dbo].[TBSIG_DOCUMENT_RECEIVER_ELEMENT]
|
|
([DOCUMENT_ID]
|
|
,[RECEIVER_ID]
|
|
,[ELEMENT_TYPE]
|
|
,[POSITION_X]
|
|
,[POSITION_Y]
|
|
,[WIDTH]
|
|
,[HEIGHT]
|
|
,[REQUIRED]
|
|
,[READ_ONLY]
|
|
,[STATUS]
|
|
,[PAGE]
|
|
,[ANNOTATION_INDEX])
|
|
VALUES
|
|
(@DOCUMENT_ID
|
|
,@RECEIVER_ID
|
|
,@ELEMENT_TYPE
|
|
,@POSITION_X
|
|
,@POSITION_Y
|
|
,@WIDTH
|
|
,@HEIGHT
|
|
,@REQUIRED
|
|
,@READ_ONLY
|
|
,@STATUS
|
|
,@PAGE
|
|
,@INDEX)"
|
|
|
|
Dim oCommand As New SqlCommand(oSql)
|
|
oCommand.Parameters.Add("DOCUMENT_ID", SqlDbType.NVarChar).Value = pElement.DocumentId
|
|
oCommand.Parameters.Add("RECEIVER_ID", SqlDbType.NVarChar).Value = pElement.ReceiverId
|
|
oCommand.Parameters.Add("ELEMENT_TYPE", SqlDbType.NVarChar).Value = pElement.ElementType
|
|
oCommand.Parameters.Add("POSITION_X", SqlDbType.Float).Value = pElement.X
|
|
oCommand.Parameters.Add("POSITION_Y", SqlDbType.Float).Value = pElement.Y
|
|
oCommand.Parameters.Add("WIDTH", SqlDbType.Float).Value = pElement.Width
|
|
oCommand.Parameters.Add("HEIGHT", SqlDbType.Float).Value = pElement.Height
|
|
oCommand.Parameters.Add("REQUIRED", SqlDbType.Bit).Value = pElement.Required
|
|
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)
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
End If
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
Public Function DeleteElement(pElement As EnvelopeDocumentElement) As Boolean
|
|
Try
|
|
Dim oSql = $"DELETE FROM TBSIG_DOCUMENT_RECEIVER_ELEMENT WHERE GUID = {pElement.Id}"
|
|
Return Database.ExecuteNonQuery(oSql)
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
Private Function GetElementId(pElement As EnvelopeDocumentElement) As Integer
|
|
Try
|
|
Return Database.GetScalarValue($"SELECT MAX(GUID) FROM TBSIG_DOCUMENT_RECEIVER_ELEMENT
|
|
WHERE DOCUMENT_ID = {pElement.DocumentId} AND RECEIVER_ID = {pElement.ReceiverId}")
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
End Class
|