158 lines
5.5 KiB
C#
158 lines
5.5 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Sarand.Net.Standard.Base.Interfaces;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|
{
|
|
//=======================================================================
|
|
class SbmAssetCategory_Dbas : SbmAssetCategory
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly SbmInternals internals;
|
|
private List<SbmItemProcess> itemProcesses = new List<SbmItemProcess>();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SbmAssetCategory_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.AssetType assetType, ushort flags) :
|
|
base(internals.UserContext, id, affiliateIdOwner, assetType)
|
|
{
|
|
this.internals = internals;
|
|
Flags = flags;
|
|
}
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
// NB Do not dispose the Internals - owned by manager.
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Associated data.
|
|
public override bool HasProcesses()
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(Id)) return SetErrorState("invalid item");
|
|
return internals.ProcessMgr.HasItemProcesses(Sbm.ItemType.Asset, Id);
|
|
}
|
|
|
|
public override bool HasAssets()
|
|
{
|
|
if (!SysId.IsValid(Id)) return false;
|
|
ISacsDatabase db = internals.BusMgrDatabase;
|
|
if (db != null)
|
|
{
|
|
String tableAsset = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAsset);
|
|
if (db.TableExists(tableAsset))
|
|
{
|
|
String columnSaAsset_Id = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaAsset_Id);
|
|
List<String> filter = new List<String>();
|
|
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaAsset_AssetCategoryId) + "=" + Id.ToString());
|
|
if (db.GetRowCount(tableAsset, filter.Concat(" AND ", "(", ")")) > 0) return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
public override bool ClearDependentData()
|
|
{
|
|
ClearErrorState();
|
|
if (this == null || !SysId.IsValid(Id)) return false;
|
|
ISacsDatabase db = internals.BusMgrDatabase;
|
|
if (db != null && !HasErrorState())
|
|
{
|
|
if (!HasErrorState())
|
|
{
|
|
/* ToDo SaItemDocConsole for Remove document references:
|
|
SaItemDocConsole itemDocConsole = SbmGlobals.Application.GetItemDocConsole(SessionContext);
|
|
if (itemDocConsole != null)
|
|
{
|
|
if (!itemDocConsole.ClearItemDocs(Sbm.ItemType.AssetCategory, Id))
|
|
SetErrorState(itemDocConsole.Exception());
|
|
}
|
|
else SetErrorState("Failed to retrieve item document console");
|
|
itemDocConsole = null;*/ // Do not delete this global object.
|
|
}
|
|
if (!HasErrorState())
|
|
{
|
|
/* ToDo SaItemDataConsole for Remove Item Data:
|
|
SaItemDataConsole itemDataConsole = SbmGlobals.Application.GetItemDataConsole(SessionContext);
|
|
if (itemDataConsole != null)
|
|
{
|
|
if (!itemDataConsole.ClearItemData(Sbm.ItemType.AssetCategory, Id, ""))
|
|
SetErrorState(itemDataConsole.Exception());
|
|
}
|
|
else SetErrorState("Failed to retrieve item Dataument console");
|
|
itemDataConsole = null;*/ // Do not delete this global object.
|
|
}
|
|
if (!HasErrorState())
|
|
{
|
|
// Remove interface data items:
|
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
|
//DbUpdateInfo dbUpdateInfo = userContext.DbUpdateInfo;
|
|
if (interfaceConsole != null)
|
|
{
|
|
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), internals.DbUpdateInfo))
|
|
SetErrorState(interfaceConsole.ErrorStateMessage);
|
|
}
|
|
else SetErrorState("Failed to retrieve interface console");
|
|
interfaceConsole = null; // Do not delete this global object.
|
|
}
|
|
}
|
|
else SetErrorState("database is unavailable");
|
|
return !HasErrorState();
|
|
}
|
|
// AssetCategory processes.
|
|
public override List<SbmItemProcess> GetProcesses(bool activeOnly)
|
|
{
|
|
ClearErrorState();
|
|
List<SbmItemProcess> itemProcesesCopy = null;
|
|
if (activeOnly)
|
|
{
|
|
// Retrieve the list of 'active' processes for this item.
|
|
internals.ProcessMgr.GetProcessesForItem(Sbm.ItemType.AssetCategory, Id, true);
|
|
}
|
|
else
|
|
{
|
|
// Full list required - check whether the internal list has been populated yet.
|
|
if (itemProcesses == null && SysId.IsValid(Id))
|
|
{
|
|
// Get the list of processes:
|
|
internals.ProcessMgr.GetProcessesForItem(Sbm.ItemType.AssetCategory, Id, false);
|
|
}
|
|
// Clone the list.
|
|
itemProcesesCopy = itemProcesses.Clone();
|
|
}
|
|
if (itemProcesesCopy != null) itemProcesesCopy.Sort();
|
|
return itemProcesesCopy;
|
|
}
|
|
public override bool SetProcesses(List<SbmItemProcess> itemProcessesNew)
|
|
{
|
|
ClearErrorState();// Clear the existing list.
|
|
if (itemProcesses != null) itemProcesses.Clear();
|
|
// Copy all items from the specified list.
|
|
itemProcesses = itemProcessesNew.Clone();
|
|
return !HasErrorState();
|
|
}
|
|
public override bool CommitProcesses()
|
|
{
|
|
ClearErrorState();
|
|
/*if (!processMgr.UpdateProcessesForItem(Sbm.ItemType.AssetCategory, Id, itemProcesses))
|
|
SetErrorState(processMgr.ErrorStateMessage.ToString());*/
|
|
return !HasErrorState();
|
|
}
|
|
}
|
|
//=======================================================================
|
|
}
|