88 lines
3.5 KiB
VB.net
88 lines
3.5 KiB
VB.net
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Language
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.EDMI.API.Client
|
|
Imports System.Data.SqlClient
|
|
|
|
Namespace IDB
|
|
Public Class Helpers
|
|
Inherits BaseClass
|
|
|
|
Private Database As MSSQLServer
|
|
|
|
Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer)
|
|
MyBase.New(pLogConfig)
|
|
Database = pMSSQLServer
|
|
End Sub
|
|
|
|
Public Function TestObjectIdExists(pObjectId As Long, Optional ByRef IsDeleted As Boolean = False, Optional ByRef IsActive As Boolean = False) As Boolean
|
|
Try
|
|
Dim oSQL As String = $"SELECT IDB_OBJ_ID, ACTIVE, DELETED FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}"
|
|
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
|
|
|
If IsNothing(oTable) OrElse oTable.Rows.Count = 0 Then
|
|
Logger.Warn("ObjectId {0} does not exist")
|
|
Return False
|
|
End If
|
|
|
|
Dim oRow As DataRow = oTable.Rows.Item(0)
|
|
Dim oActive = Utils.NotNull(oRow.Item("ACTIVE"), False)
|
|
Dim oDeleted = Utils.NotNull(oRow.Item("DELETED"), False)
|
|
|
|
IsDeleted = oDeleted
|
|
IsActive = oActive
|
|
|
|
Return True
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return False
|
|
|
|
End Try
|
|
End Function
|
|
|
|
Public Function GetAttributesForObject(pObjectId As Long, pLanguage As String) As List(Of ObjectAttribute)
|
|
Dim oAttributes As New List(Of ObjectAttribute)
|
|
|
|
Try
|
|
Dim oTable As DataTable = Database.GetDatatable($"EXEC [PRIDB_GET_VALUE_DT] {pObjectId}, '{pLanguage}'")
|
|
If oTable Is Nothing OrElse oTable.Rows.Count = 0 Then
|
|
Return Nothing
|
|
End If
|
|
|
|
For Each oRow As DataRow In oTable.Rows
|
|
Dim oAttribute As New ObjectAttribute With {
|
|
.Id = oRow.Item("AttributeId"),
|
|
.Title = oRow.Item("AttributeTitle"),
|
|
.Type = oRow.Item("AttributeType"),
|
|
.ValueBigInt = Utils.NotNull(oRow.Item("ValueBigInt"), Nothing),
|
|
.ValueDate = Utils.NotNull(oRow.Item("ValueDate"), Nothing),
|
|
.ValueDecimal = Utils.NotNull(oRow.Item("ValueDecimal"), Nothing),
|
|
.ValueText = Utils.NotNull(oRow.Item("ValueText"), Nothing)
|
|
}
|
|
|
|
oAttributes.Add(oAttribute)
|
|
Next
|
|
|
|
Return oAttributes
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
|
|
Public Function SetAttributeValue(pConnection As SqlConnection, pTransaction As SqlTransaction, pObjectId As Long, pAttributeName As String, pValue As String, pLanguage As String, pWho As String) As Boolean
|
|
Dim oSql = $"
|
|
DECLARE @NEW_OBJ_MD_ID BIGINT
|
|
EXEC PRIDB_NEW_OBJ_DATA {pObjectId}, '{pAttributeName}', '{pWho}', '{pValue}', '{pLanguage}', 0, @OMD_ID = @NEW_OBJ_MD_ID OUTPUT"
|
|
|
|
If Database.ExecuteNonQueryWithConnectionObject(oSql, pConnection, MSSQLServer.TransactionMode.ExternalTransaction, pTransaction) = False Then
|
|
Logger.Warn("Error while setting attribute value.")
|
|
Return False
|
|
End If
|
|
|
|
Return True
|
|
End Function
|
|
End Class
|
|
|
|
End Namespace |