137 lines
4.7 KiB
C#
137 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;
|
|
using System.Linq;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|
{
|
|
//=======================================================================
|
|
class SbmAffiliate_Dbas : SbmAffiliate
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly SbmInternals internals;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SbmAffiliate_Dbas(SbmInternals internals, SysId id, Sbm.AffiliateType affiliateType, ushort flags) :
|
|
base(internals.UserContext, id, affiliateType)
|
|
{
|
|
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 long GetChildAffiliates()
|
|
{
|
|
if (!SysId.IsValid(Id)) return 0;
|
|
ISacsDatabase db = internals.BusMgrDatabase;
|
|
if (db != null)
|
|
{
|
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Affiliate_AffIdParent) + "=" + Id.ToString();
|
|
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Affiliate), filter);
|
|
}
|
|
return 0;
|
|
}
|
|
public override bool HasChildAffiliates()
|
|
{
|
|
|
|
return GetChildAffiliates() > 0;
|
|
}
|
|
|
|
public override long OwnerOfAssociationsCount(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
|
{
|
|
return internals.AccountMgr.OwnerAssociationCount(Id, associationType, currentOnly);
|
|
}
|
|
public override bool OwnerOfAssociations(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
|
{
|
|
return internals.AccountMgr.OwnerHasAssociations(Id, associationType, currentOnly);
|
|
}
|
|
public override long TargetOfAssociationsCount(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
|
{
|
|
return internals.AccountMgr.TargetAssociationCount(Id, associationType, currentOnly);
|
|
}
|
|
public override bool TargetOfAssociations(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
|
{
|
|
return internals.AccountMgr.TargetHasAssociations(Id, associationType, currentOnly);
|
|
}
|
|
public override bool HasSystemUsers()
|
|
{
|
|
if (!SysId.IsValid(Id)) return false;
|
|
ISacsDatabase db = internals.BusMgrDatabase;
|
|
if (db != null)
|
|
{
|
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SystemUser_AffiliateId) + "=" + Id.ToString();
|
|
return (db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SystemUser), filter) > 0);
|
|
}
|
|
return false;
|
|
}
|
|
public override bool HasDiaryLinks()
|
|
{
|
|
/*if (!GetId().IsValid()) return false;
|
|
bool bHas = false;
|
|
SapphireDiary * pDiary = SapphireGlobal::GetDiary();
|
|
if (pDiary)
|
|
{
|
|
bHas = pDiary->DataItemHasLinks(eSapItemTypeAffiliate,GetId());
|
|
}
|
|
return bHas;
|
|
*/
|
|
return false;
|
|
}
|
|
// Dependent data should only be cleared when removing an affiliate.
|
|
public override bool ClearDependentData()
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(Id)) return false;
|
|
if (SbmGlobals.System == null) return SetErrorState("System is not available");
|
|
ISacsDatabase db = SbmGlobals.Application.GetBusMgrDatabase(internals.SessionContext);
|
|
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.
|
|
}
|
|
// Remove data item references.
|
|
if (!HasErrorState())
|
|
{
|
|
SbmDataItemMgr dataItemMgr = internals.DataItemMgr;
|
|
if (dataItemMgr != null)
|
|
{
|
|
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Affiliate, Id))
|
|
SetErrorState(dataItemMgr.ErrorStateMessage);
|
|
}
|
|
else SetErrorState("Data item manager is not available");
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|