133 lines
4.7 KiB
C#
133 lines
4.7 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.Dbas;
|
|
using Sarand.Net.Standard.Base.Interfaces;
|
|
using System;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|
{
|
|
//=======================================================================
|
|
class SbmAssociation_Dbas : SbmAssociation
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly SbmInternals internals;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SbmAssociation_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.AssociationType associationType, SysId affiliateIdTarget, ushort flags) :
|
|
base(internals.UserContext, id, affiliateIdOwner, associationType, affiliateIdTarget)
|
|
{
|
|
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.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Internal Processing.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Associated data.
|
|
public override bool HasTransactions()
|
|
{
|
|
if (!SysId.IsValid(Id)) return false;
|
|
ISacsDatabase db = internals.BusMgrDatabase;
|
|
if (db != null)
|
|
{
|
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Transaction_AssocId) + "=" + Id.ToString();
|
|
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Transaction), filter) > 0;
|
|
}
|
|
return false;
|
|
}
|
|
public override bool HasRequirements()
|
|
{
|
|
if (!SysId.IsValid(Id)) return false;
|
|
ISacsDatabase db = internals.BusMgrDatabase;
|
|
if (db != null)
|
|
{
|
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_AssocId) + "=" + Id.ToString();
|
|
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Requirement), filter) > 0;
|
|
}
|
|
return false;
|
|
}
|
|
public override bool HasConstituents()
|
|
{
|
|
if (!SysId.IsValid(Id)) return false;
|
|
ISacsDatabase db = internals.BusMgrDatabase;
|
|
if (db != null)
|
|
{
|
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_AssocId) + "=" + Id.ToString();
|
|
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Constituent), filter) > 0;
|
|
}
|
|
return false;
|
|
}
|
|
public override bool IsDeliveryContractor()
|
|
{
|
|
// Is associated with transaction for delivery.
|
|
if (!SysId.IsValid(Id)) return false;
|
|
ISacsDatabase db = internals.BusMgrDatabase;
|
|
if (db != null)
|
|
{
|
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Transaction_AssIdDeliver) + "=" + Id.ToString();
|
|
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Transaction), filter) > 0;
|
|
}
|
|
return false;
|
|
}
|
|
public override bool ClearDependentData()
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(Id)) return false;
|
|
if (SbmGlobals.System == null) return SetErrorState("System is not available");
|
|
ISacsDatabase db = internals.BusMgrDatabase;
|
|
if (db != null) return SetErrorState("Database is not available");
|
|
|
|
// Delete interface data items.
|
|
if (!HasErrorState())
|
|
{
|
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
|
if (interfaceConsole != null)
|
|
{
|
|
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Association, Id), internals.DbUpdateInfo))
|
|
SetErrorState("Failed to clear interface data items - " + interfaceConsole.ErrorStateMessage);
|
|
}
|
|
else SetErrorState("failed to initialise interface console");
|
|
interfaceConsole = null; // Do not delete this global object.
|
|
}
|
|
/* ToDo SaItemDocConsole for Remove document references
|
|
if (!HasErrorState())
|
|
{
|
|
SaItemDocConsole itemDocConsole = SbmGlobals.Application.GetItemDocConsole();
|
|
if (itemDocConsole != null)
|
|
{
|
|
if (!itemDocConsole.ClearItemDocs(Sbm.ItemType.Association, Id))
|
|
SetErrorState(itemDocConsole.ErrorStateMessage);
|
|
}
|
|
else SetErrorState("Failed to retrieve item document console");
|
|
itemDocConsole = null; // Do not delete this global object.
|
|
}*/
|
|
// Remove data item references.
|
|
if (!HasErrorState())
|
|
{
|
|
if (!internals.DataItemMgr.ClearDataItem(Sbm.ItemType.Association, Id))
|
|
SetErrorState(internals.DataItemMgr.ErrorStateMessage);
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|