SQL-Abfragen in Models verschoben
User Model neu
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
Imports System.Data
|
||||
Imports System.Data.SqlClient
|
||||
Imports System.Transactions
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports EnvelopeGenerator.Common.My.Resources
|
||||
|
||||
Public Class DocumentModel
|
||||
Inherits BaseModel
|
||||
|
||||
@@ -30,4 +34,44 @@ Public Class DocumentModel
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function Insert(pEnvelope As Envelope, pDocument As EnvelopeDocument, pTransaction As SqlTransaction) As Boolean
|
||||
Try
|
||||
Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE_DOCUMENT]
|
||||
([FILENAME]
|
||||
,[FILEPATH]
|
||||
,[ENVELOPE_ID])
|
||||
VALUES
|
||||
(@FILENAME
|
||||
,@FILEPATH
|
||||
,@ENVELOPE_ID)"
|
||||
|
||||
Dim oCommand As New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("FILENAME", SqlDbType.NVarChar).Value = pDocument.Filename
|
||||
oCommand.Parameters.Add("FILEPATH", SqlDbType.NVarChar).Value = pDocument.Filepath
|
||||
oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.Int).Value = pEnvelope.Id
|
||||
|
||||
If Database.ExecuteNonQuery(oCommand, pTransaction) Then
|
||||
pDocument.EnvelopeId = pEnvelope.Id
|
||||
pDocument.Id = GetDocumentId(pDocument.Filename, pEnvelope, pTransaction)
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetDocumentId(pFilename As String, pEnvelope As Envelope, pTransaction As SqlTransaction) As Integer
|
||||
Try
|
||||
Return Database.GetScalarValue($"SELECT MAX(GUID) FROM TBSIG_ENVELOPE_DOCUMENT WHERE FILENAME = '{pFilename}' AND ENVELOPE_ID = {pEnvelope.Id}", pTransaction)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
Imports System.Data
|
||||
Imports System.Data.SqlClient
|
||||
Imports DigitalData.Modules.Base
|
||||
|
||||
Public Class ElementModel
|
||||
@@ -53,4 +54,104 @@ Public Class ElementModel
|
||||
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]
|
||||
,[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
|
||||
|
||||
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
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
Imports System.Data.SqlClient
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports System.Data
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class EnvelopeModel
|
||||
Inherits BaseModel
|
||||
@@ -17,7 +16,8 @@ Public Class EnvelopeModel
|
||||
.Subject = pRow.ItemEx("SUBJECT", ""),
|
||||
.Message = pRow.ItemEx("MESSAGE", ""),
|
||||
.UserId = State.UserId,
|
||||
.Status = ObjectEx.ToEnum(Of Constants.EnvelopeStatus)(pRow.ItemEx("STATUS", "Created"))
|
||||
.Status = ObjectEx.ToEnum(Of Constants.EnvelopeStatus)(pRow.ItemEx("STATUS", "Created")),
|
||||
.User = New User()
|
||||
}
|
||||
|
||||
Return oEnvelope
|
||||
@@ -49,6 +49,7 @@ Public Class EnvelopeModel
|
||||
|
||||
If Database.ExecuteNonQuery(oCommand) Then
|
||||
pEnvelope.Id = GetEnvelopeId(pEnvelope)
|
||||
SetEnvelopeDate(pEnvelope) 'TODO JJ fragen
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
@@ -99,4 +100,14 @@ Public Class EnvelopeModel
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Sub SetEnvelopeDate(pEnvelope As Envelope)
|
||||
Try
|
||||
Dim addedWhen As DateTime = Database.GetScalarValue($"SELECT ADDED_WHEN FROM TBSIG_ENVELOPE WHERE GUID = {pEnvelope.Id}")
|
||||
pEnvelope.AddedWhen = addedWhen
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
Imports System.Data
|
||||
Imports System.Data.SqlClient
|
||||
Imports System.Data.SqlClient
|
||||
|
||||
Public Class HistoryModel
|
||||
Inherits BaseModel
|
||||
|
||||
39
EnvelopeGenerator.Common/Models/UserModel.vb
Normal file
39
EnvelopeGenerator.Common/Models/UserModel.vb
Normal file
@@ -0,0 +1,39 @@
|
||||
Imports System.Data.SqlClient
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports EnvelopeGenerator.Common.My.Resources
|
||||
|
||||
Public Class UserModel
|
||||
Inherits BaseModel
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
End Sub
|
||||
|
||||
Private Function ToUser(pRow As DataRow) As User
|
||||
Dim oUser = New User() With {
|
||||
.Id = pRow.ItemEx("GUID", 0),
|
||||
.Prename = pRow.ItemEx("PRENAME", ""),
|
||||
.Name = pRow.ItemEx("NAME", ""),
|
||||
.Username = pRow.ItemEx("USERNAME", ""),
|
||||
.Email = pRow.ItemEx("EMAIL", ""),
|
||||
.Language = pRow.ItemEx("LANGUAGE", "")
|
||||
}
|
||||
|
||||
Return oUser
|
||||
End Function
|
||||
|
||||
Public Function SelectUser() As User
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [dbo].[TBDD_USER] WHERE USER_ID = {State.UserId}"
|
||||
Dim oTable = Database.GetDatatable(oSql)
|
||||
|
||||
Return oTable?.Rows.Cast(Of DataRow).
|
||||
Select(AddressOf ToUser)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user