73 lines
2.9 KiB
VB.net
73 lines
2.9 KiB
VB.net
Imports DevExpress.Utils.DirectXPaint
|
|
Imports System.Data.SqlClient
|
|
Imports System.Runtime.Remoting.Messaging
|
|
Imports DigitalData.Modules.Base
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Public Class EnvelopeController
|
|
Inherits BaseClass
|
|
|
|
Private ReadOnly Database As MSSQLServer
|
|
|
|
Public Sub New(pState As State)
|
|
MyBase.New(pState.LogConfig)
|
|
Database = pState.Database
|
|
End Sub
|
|
|
|
Public Function SaveEnvelope(pEnvelope As Envelope) As Boolean
|
|
If pEnvelope.Id > 0 Then
|
|
Try
|
|
Dim oSql = "UPDATE [dbo].[TBSIG_ENVELOPE] SET [SUBJECT] = @SUBJECT, [MESSAGE] = @MESSAGE, [ENVELOPE_UUID] = @UUID WHERE GUID = @ID AND USER_ID = @USER_ID"
|
|
Dim oCommand As New SqlCommand(oSql)
|
|
oCommand.Parameters.Add("SUBJECT", SqlDbType.NVarChar).Value = pEnvelope.Subject
|
|
oCommand.Parameters.Add("MESSAGE", SqlDbType.NVarChar).Value = pEnvelope.Message
|
|
oCommand.Parameters.Add("UUID", SqlDbType.NVarChar).Value = pEnvelope.Uuid
|
|
oCommand.Parameters.Add("ID", SqlDbType.Int).Value = pEnvelope.Id
|
|
oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pEnvelope.UserId
|
|
|
|
Dim oResult = Database.ExecuteNonQuery(oCommand)
|
|
If oResult = True Then
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
End Try
|
|
|
|
Else
|
|
Try
|
|
Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE] (SUBJECT, MESSAGE, ENVELOPE_UUID, STATUS, USER_ID) VALUES (@SUBJECT, @MESSAGE, @UUID, @STATUS, @USER_ID)"
|
|
Dim oCommand As New SqlCommand(oSql)
|
|
oCommand.Parameters.Add("SUBJECT", SqlDbType.NVarChar).Value = pEnvelope.Subject
|
|
oCommand.Parameters.Add("MESSAGE", SqlDbType.NVarChar).Value = pEnvelope.Message
|
|
oCommand.Parameters.Add("UUID", SqlDbType.NVarChar).Value = pEnvelope.Uuid
|
|
oCommand.Parameters.Add("STATUS", SqlDbType.NVarChar).Value = pEnvelope.Status.ToString()
|
|
oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pEnvelope.UserId
|
|
|
|
Dim oResult = Database.ExecuteNonQuery(oCommand)
|
|
If oResult = True Then
|
|
pEnvelope.Id = GetEnvelopeId(pEnvelope.UserId)
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
End Try
|
|
End If
|
|
End Function
|
|
|
|
Private Function GetEnvelopeId(pUserId As Integer) As Integer
|
|
Try
|
|
Return Database.GetScalarValue($"SELECT MAX(GUID) FROM TBSIG_ENVELOPE WHERE USER_ID = {pUserId}")
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
End Class
|