154 lines
5.9 KiB
VB.net
154 lines
5.9 KiB
VB.net
Imports System.Data
|
|
Imports System.Data.SqlClient
|
|
Imports DigitalData.Modules.Base
|
|
|
|
Public Class ElementModel
|
|
Inherits BaseModel
|
|
|
|
Public Sub New(pState As State)
|
|
MyBase.New(pState)
|
|
End Sub
|
|
|
|
Private Function ToElement(pRow As DataRow) As EnvelopeDocumentElement
|
|
Return New EnvelopeDocumentElement() With {
|
|
.Id = pRow.ItemEx("GUID", 0),
|
|
.DocumentId = pRow.ItemEx("DOCUMENT_ID", 0),
|
|
.ReceiverId = pRow.ItemEx("RECEIVER_ID", 0),
|
|
.ElementType = [Enum].Parse(GetType(Constants.ElementType), pRow.ItemEx("ELEMENT_TYPE", Constants.ElementType.Signature.ToString)),
|
|
.X = pRow.ItemEx("POSITION_X", 0.0),
|
|
.Y = pRow.ItemEx("POSITION_Y", 0.0),
|
|
.Width = pRow.ItemEx("WIDTH", 0.0),
|
|
.Height = pRow.ItemEx("HEIGHT", 0.0),
|
|
.Page = pRow.ItemEx("PAGE", 0)
|
|
}
|
|
End Function
|
|
|
|
Public Function ElementsExist(pEnvelopeId As Integer, pReceiverId As Integer) As Boolean
|
|
Try
|
|
Dim oSql = $"SELECT COUNT(*) FROM [dbo].[TBSIG_DOCUMENT_RECEIVER_ELEMENT] T
|
|
JOIN TBSIG_ENVELOPE_DOCUMENT T2 ON T.DOCUMENT_ID = T2.GUID
|
|
WHERE T.RECEIVER_ID = {pReceiverId} AND T2.ENVELOPE_ID = {pEnvelopeId}"
|
|
Dim oElementCount As Integer = Database.GetScalarValue(oSql)
|
|
|
|
Return oElementCount > 0
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
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"
|
|
Dim oTable = Database.GetDatatable(oSql)
|
|
|
|
Return oTable?.Rows.Cast(Of DataRow).
|
|
Select(AddressOf ToElement).
|
|
ToList()
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
|
|
Public Function Insert(pElement As EnvelopeDocumentElement) As Boolean
|
|
Try
|
|
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])
|
|
VALUES
|
|
(@DOCUMENT_ID
|
|
,@RECEIVER_ID
|
|
,@ELEMENT_TYPE
|
|
,@POSITION_X
|
|
,@POSITION_Y
|
|
,@WIDTH
|
|
,@HEIGHT
|
|
,@REQUIRED
|
|
,@READ_ONLY
|
|
,@STATUS
|
|
,@PAGE)"
|
|
|
|
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
|
|
|
|
If Database.ExecuteNonQuery(oCommand) Then
|
|
pElement.Id = GetElementId(pElement)
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
Public Function Update(pElement As EnvelopeDocumentElement) As Boolean
|
|
Try
|
|
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)
|
|
|
|
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
|
|
|
|
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
|
|
End Class
|