Rationalise business objects.
This commit is contained in:
@@ -12,72 +12,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmAddress_Dbas(SbmInternals internals, SysId id, Sbm.ItemType itemType, SysId itemId, Sbm.AddressType addressType, ushort flags) :
|
||||
base(internals.UserContext, id, itemType, itemId, addressType)
|
||||
public SbmAddress_Dbas(SysId id, Sbm.ItemType itemType, SysId itemId, Sbm.AddressType addressType, ushort flags) :
|
||||
base(id, itemType, itemId, addressType)
|
||||
{
|
||||
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 HasInterfaceDataItems()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||
if (interfaceConsole != null) return false;
|
||||
bool has = interfaceConsole.ItemHasDataItems(new ItemId((short)Sbm.ItemType.Address, Id));
|
||||
return has;
|
||||
}
|
||||
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.
|
||||
}
|
||||
// Remove data item references.
|
||||
if (!HasErrorState())
|
||||
{
|
||||
SbmDataItemMgr dataItemMgr = internals.DataItemMgr;
|
||||
if (dataItemMgr != null)
|
||||
{
|
||||
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Address, Id))
|
||||
SetErrorState(dataItemMgr.ErrorStateMessage);
|
||||
}
|
||||
else SetErrorState("Data item manager is not available");
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -14,121 +14,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmAffiliate_Dbas(SbmInternals internals, SysId id, Sbm.AffiliateType affiliateType, ushort flags) :
|
||||
base(internals.UserContext, id, affiliateType)
|
||||
public SbmAffiliate_Dbas(SysId id, Sbm.AffiliateType affiliateType, ushort flags) :
|
||||
base(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();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -16,142 +16,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// 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)
|
||||
public SbmAssetCategory_Dbas(SysId id, SysId affiliateIdOwner, Sbm.AssetType assetType, ushort flags) :
|
||||
base(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();
|
||||
}
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
|
||||
@@ -9,31 +9,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmAssetProcess_Dbas(SbmInternals internals, SysId id, SysId assetId, SysId processId, ushort flags) :
|
||||
base(internals.UserContext, id, assetId, processId)
|
||||
public SbmAssetProcess_Dbas(SysId id, SysId assetId, SysId processId, ushort flags) :
|
||||
base(id, assetId, processId)
|
||||
{
|
||||
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.
|
||||
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
|
||||
@@ -16,292 +16,18 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
private List<SbmItemProcess> itemProcesses = new List<SbmItemProcess>();
|
||||
private List<SbmItemPrice> itemPrices = new List<SbmItemPrice>();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmAsset_Dbas(SbmInternals internals, SysId id, SysId assetCatId, ushort flags) :
|
||||
base(internals.UserContext, id, assetCatId)
|
||||
public SbmAsset_Dbas(SysId id, SysId assetCatId, ushort flags) :
|
||||
base(id, assetCatId)
|
||||
{
|
||||
this.internals = internals;
|
||||
Id = id;
|
||||
AssetCategoryId = assetCatId;
|
||||
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 false;
|
||||
//processMgr.ItemHasProcesses(Sbm.ItemType.Asset, Id);ISacsDatabase db = SbmGlobals.Application.GetDatabase(SessionContext);
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
String tableAssetProcess = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAssetProcess);
|
||||
if (db.TableExists(tableAssetProcess))
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaAssetProcess_AssetId) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tableAssetProcess, filter.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HasRequirements()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_Id) + "=" + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_AssetId);
|
||||
return internals.BusMgrDatabase.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Requirement), filter + "=" + Id.ToString()) > 0;
|
||||
}
|
||||
public override bool HasInterfaceDataItems()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||
if (interfaceConsole == null) return false;
|
||||
return interfaceConsole.ItemHasDataItems(new ItemId((short)Sbm.ItemType.Asset, Id));
|
||||
}
|
||||
public override bool HasAssociatedDetails()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
return internals.DataItemMgr.HasItemLinks(Sbm.ItemType.Asset, Id);
|
||||
}
|
||||
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 Data Document console");
|
||||
itemDataConsole = null;*/ // Do not delete this global object.
|
||||
}
|
||||
// Remove items data.
|
||||
if (!HasErrorState())
|
||||
{
|
||||
if (internals.DataItemMgr != null)
|
||||
{
|
||||
if (!internals.DataItemMgr.ClearDataItem(Sbm.ItemType.Asset, Id))
|
||||
SetErrorState(internals.DataItemMgr.ErrorStateMessage);
|
||||
}
|
||||
else SetErrorState("Failed to retrieve Data Item manager");
|
||||
}
|
||||
if (!HasErrorState())
|
||||
{
|
||||
// Remove interface data items.
|
||||
if (internals.InterfaceConsole != null)
|
||||
{
|
||||
if (!internals.InterfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), internals.DbUpdateInfo))
|
||||
SetErrorState(internals.InterfaceConsole.ErrorStateMessage);
|
||||
}
|
||||
else SetErrorState("Failed to retrieve interface console");
|
||||
}
|
||||
}
|
||||
else SetErrorState("database is unavailable");
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
// Asset 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.Asset, 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:
|
||||
itemProcesses = internals.ProcessMgr.GetProcessesForItem(Sbm.ItemType.Asset, Id, false);
|
||||
}
|
||||
// Copy the list.
|
||||
itemProcesesCopy = new List<SbmItemProcess>(itemProcesses);
|
||||
}
|
||||
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();
|
||||
SbmAsset asset = null;
|
||||
if (!internals.ProcessMgr.StoreItemProcesses(Sbm.ItemType.Asset, Id, itemProcesses, internals.DbUpdateInfo))
|
||||
{
|
||||
// Make a note of the 'Next' process.
|
||||
SbmItemProcess itemProcessNext = itemProcesses.GetNextProcessInSequence(SaStatus.Awaiting);
|
||||
SysId itemProcessIdNext = itemProcessNext != null ? itemProcessNext.ProcessId : new SysId();
|
||||
if (ProcessIdNext != itemProcessIdNext)
|
||||
{
|
||||
ProcessIdNext = itemProcessIdNext;
|
||||
if (!internals.AssetMgr.UpdateAsset(asset, internals.DbUpdateInfo))
|
||||
SetErrorState("Failed to update next process id - " + internals.AssetMgr.ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
SetErrorState(internals.ProcessMgr.ErrorStateMessage);
|
||||
return !HasErrorState();
|
||||
}
|
||||
public override bool PopulateDefaultProcesses()
|
||||
{
|
||||
// As defined by Asset Category (for assets created by processes, eg. vehicle import).
|
||||
ClearErrorState();
|
||||
|
||||
// Retrieve processes defined against Asset Category.
|
||||
List<SbmItemProcess> itemProcessesCat = null;// processMgr.GetProcessesForItem(Sbm.ItemType.AssetCategory, AssetCatId, true);
|
||||
if (itemProcessesCat != null)
|
||||
{
|
||||
for (int i = 1; i <= itemProcessesCat.Count; i++)
|
||||
{
|
||||
SbmItemProcess itemProcess = itemProcessesCat[i];
|
||||
itemProcess.ClearItemId(Sbm.ItemType.Asset, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Store this list of processes against this asset:
|
||||
if (!HasErrorState()) SetProcesses(itemProcessesCat);
|
||||
if (!HasErrorState()) CommitProcesses();
|
||||
|
||||
// Clean-up:
|
||||
if (itemProcessesCat != null) itemProcessesCat.Clear();
|
||||
return !HasErrorState();
|
||||
}
|
||||
// Asset Payment for transaction.
|
||||
public override bool HasPrices()
|
||||
{
|
||||
if (itemPrices != null) return true;
|
||||
else if (SysId.IsValid(Id))
|
||||
{
|
||||
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
||||
SbmItemLink.Params prm = new SbmItemLink.Params();
|
||||
prm.ItemLinkType = Sbm.ItemLinkType.ItemPrice;
|
||||
prm.ItemTypeFrom = Sbm.ItemType.Asset;
|
||||
prm.ItemIdFrom = Id;
|
||||
foreach (SbmItemLink itemLink in internals.DataItemMgr.GetItemLinkList(prm))
|
||||
if (itemLink != null) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override List<SbmItemPrice> GetPrices()
|
||||
{
|
||||
List<SbmItemPrice> itemPricesCopy = null;
|
||||
if (itemPrices == null && SysId.IsValid(Id))
|
||||
{
|
||||
SbmItemLink.Params prm = new SbmItemLink.Params();
|
||||
prm.ItemLinkType = Sbm.ItemLinkType.ItemPrice;
|
||||
prm.ItemTypeFrom = Sbm.ItemType.Asset;
|
||||
prm.ItemIdFrom = Id;
|
||||
List<SbmItemLink> itemLinks = internals.DataItemMgr.GetItemLinkList(prm);
|
||||
if (itemLinks != null)
|
||||
{
|
||||
foreach (SbmItemLink itemLink in itemLinks)
|
||||
{
|
||||
if (itemLink == null) continue;
|
||||
SbmItemPrice itemPrice = new SbmItemPrice(UserContext, itemLink.DataContent);
|
||||
itemPrice.Notes = itemLink.Notes;
|
||||
itemPrice.Changed = false;
|
||||
if (itemPrices == null) itemPrices = new List<SbmItemPrice>();
|
||||
itemPrices.Add(itemPrice);
|
||||
}
|
||||
// Clean-up.
|
||||
itemLinks.Clear();
|
||||
}
|
||||
}
|
||||
// Clone the list.
|
||||
itemPricesCopy = itemPrices.Clone();
|
||||
itemPricesCopy.Sort();
|
||||
return itemPricesCopy;
|
||||
}
|
||||
public override bool SetPrices(List<SbmItemPrice> itemPricesNew)
|
||||
{
|
||||
// Clear the existing list.
|
||||
if (itemPrices != null) itemPrices.Clear();
|
||||
// Copy all items from the specified list.
|
||||
itemPrices = itemPricesNew.Clone();
|
||||
return true;
|
||||
}
|
||||
public override bool CommitPrices()
|
||||
{
|
||||
ClearErrorState();
|
||||
// Do not attempt any updates unless the list has been populated:
|
||||
if (itemPrices != null && SysId.IsValid(Id))
|
||||
{
|
||||
// Build an item link list corresponding to the list of prices.
|
||||
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
||||
foreach (SbmItemPrice itemPrice in itemPrices)
|
||||
{
|
||||
if (itemPrice == null) continue;
|
||||
SbmItemLink itemLink = internals.DataItemMgr.CreateItemLink(Sbm.ItemLinkType.ItemPrice, Sbm.ItemType.Asset, Id, Sbm.ItemType.Unknown, new SysId(0));
|
||||
if (itemLink != null)
|
||||
{
|
||||
itemLink.Seq = (short)itemPrice.CodeSeq;
|
||||
itemLink.DataContent = itemPrice.ToString();
|
||||
itemLink.Notes = itemPrice.Notes;
|
||||
itemLinks.Add(itemLink);
|
||||
itemLink = null; // Now owned by the list.
|
||||
}
|
||||
}
|
||||
// Store these details.
|
||||
if (internals.DataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.ItemPrice, new ItemId((short)Sbm.ItemType.Asset, Id), itemLinks, internals.DbUpdateInfo))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
SetErrorState("Failed to save asset price item links - " + internals.DataItemMgr.ErrorStateMessage);
|
||||
}
|
||||
if (itemLinks != null)
|
||||
itemLinks.Clear();
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
|
||||
@@ -13,118 +13,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// 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)
|
||||
public SbmAssociation_Dbas(SysId id, SysId affiliateIdOwner, Sbm.AssociationType associationType, SysId affiliateIdTarget, ushort flags) :
|
||||
base(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();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -9,30 +9,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmCommodityCustomer_Dbas(SbmInternals internals, SysId commodityId, SysId assocIdCustomer, ushort flags) :
|
||||
base(internals.UserContext, commodityId, assocIdCustomer)
|
||||
public SbmCommodityCustomer_Dbas(SysId commodityId, SysId assocIdCustomer, ushort flags) :
|
||||
base(commodityId, assocIdCustomer)
|
||||
{
|
||||
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.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -9,30 +9,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmCommoditySupplier_Dbas(SbmInternals internals, SysId commodityId, SysId assocIdSupplier, ushort flags) :
|
||||
base(internals.UserContext, commodityId, assocIdSupplier)
|
||||
public SbmCommoditySupplier_Dbas(SysId commodityId, SysId assocIdSupplier, ushort flags) :
|
||||
base(commodityId, assocIdSupplier)
|
||||
{
|
||||
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.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -18,24 +18,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmCommodity_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.CommodityType commodityType, String code, ushort flags) :
|
||||
base(internals.UserContext, id, affiliateIdOwner, commodityType, code)
|
||||
public SbmCommodity_Dbas(SysId id, SysId affiliateIdOwner, Sbm.CommodityType commodityType, String code, ushort flags) :
|
||||
base(id, affiliateIdOwner, commodityType, code)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -11,42 +11,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmConstituent_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, SysId assocId, Sbm.ConstituentType constituentType, ushort flags) :
|
||||
base(internals.UserContext, id, affIdOwner, assocId, constituentType)
|
||||
public SbmConstituent_Dbas(SysId id, SysId affIdOwner, SysId assocId, Sbm.ConstituentType constituentType, ushort flags) :
|
||||
base(id, affIdOwner, assocId, constituentType)
|
||||
{
|
||||
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 HasConstituents()
|
||||
{
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = SbmGlobals.Application.GetBusMgrDatabase(internals.SessionContext);
|
||||
if (db != null)
|
||||
{
|
||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_ConstId) + "=" + Id.ToString();
|
||||
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Constituent), filter) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
|
||||
@@ -9,30 +9,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmContainerItem_Dbas(SbmInternals internals, SysId containerId, Sbm.ItemType itemType, SysId itemId, ushort flags) :
|
||||
base(internals.UserContext, containerId, itemType, itemId)
|
||||
public SbmContainerItem_Dbas(SysId containerId, Sbm.ItemType itemType, SysId itemId, ushort flags) :
|
||||
base(containerId, itemType, itemId)
|
||||
{
|
||||
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 Elements.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -15,84 +15,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmContainer_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.ContainerCategory containerCategory, Sbm.ContainerType containerType, ushort flags) :
|
||||
base(internals.UserContext, id, affiliateIdOwner, containerCategory, containerType)
|
||||
public SbmContainer_Dbas(SysId id, SysId affiliateIdOwner, Sbm.ContainerCategory containerCategory, Sbm.ContainerType containerType, ushort flags) :
|
||||
base(id, affiliateIdOwner, containerCategory, containerType)
|
||||
{
|
||||
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 Elements.
|
||||
public override bool HasItems()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
String tableContainItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.ContainerItem);
|
||||
if (db.TableExists(tableContainItem))
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ContainerItem_ContainerId) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tableContainItem, filter.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HasMovements()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
||||
if (db.TableExists(tableMovement))
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Movement_ItemType) + "=" + ((int)Sbm.ItemType.Container).ToString());
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Movement_ItemId) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tableMovement, filter.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HasActionedMovements()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
||||
if (db.TableExists(tableMovement))
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Movement_ItemType) + "=" + ((int)Sbm.ItemType.Container).ToString());
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Movement_ItemId) + "=" + Id.ToString());
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Movement_Status) + "=" + SacsSystem.GetStatusForCode(SaStatus.Actioned.ToString()) + ":");
|
||||
return db.GetRowCount(tableMovement, filter.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -10,30 +10,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmItemBatch_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, Sbm.ItemBatchType itemBatchType, String reference, ushort flags) :
|
||||
base(internals.UserContext, id, affIdOwner, itemBatchType, reference)
|
||||
public SbmItemBatch_Dbas(SysId id, SysId affIdOwner, Sbm.ItemBatchType itemBatchType, String reference, ushort flags) :
|
||||
base(id, affIdOwner, itemBatchType, reference)
|
||||
{
|
||||
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.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -9,30 +9,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmItemLink_Dbas(SbmInternals internals, SysId id, Sbm.ItemLinkType itemLinkType, Sbm.ItemType itemTypeFrom, SysId itemIdFrom, Sbm.ItemType itemTypeTo, SysId itemIdTo, ushort flags) :
|
||||
base(internals.UserContext, id, itemLinkType, itemTypeFrom, itemIdFrom, itemTypeTo, itemIdTo)
|
||||
public SbmItemLink_Dbas(Sbm.ItemLinkType itemLinkType, Sbm.ItemType itemTypeFrom, SysId itemIdFrom, Sbm.ItemType itemTypeTo, SysId itemIdTo, ushort flags) :
|
||||
base(itemLinkType, itemTypeFrom, itemIdFrom, itemTypeTo, itemIdTo)
|
||||
{
|
||||
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.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -9,27 +9,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmItemProcess_Dbas(SbmInternals internals, Sbm.ItemType itemType, SysId itemId, SysId processId, ushort flags) :
|
||||
base(internals.UserContext, itemType, itemId, processId)
|
||||
public SbmItemProcess_Dbas(Sbm.ItemType itemType, SysId itemId, SysId processId, ushort flags) :
|
||||
base(itemType, itemId, processId)
|
||||
{
|
||||
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.
|
||||
|
||||
@@ -14,64 +14,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmLocation_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.LocationCategory locationCategory, ushort flags) :
|
||||
base(internals.UserContext, id, affiliateIdOwner, locationCategory)
|
||||
public SbmLocation_Dbas(SysId id, SysId affiliateIdOwner, Sbm.LocationCategory locationCategory, ushort flags) :
|
||||
base(id, affiliateIdOwner, locationCategory)
|
||||
{
|
||||
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 Elements.
|
||||
public override bool HaveMovement()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
||||
if (db.TableExists(tableMovement))
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Movement_LocationIdFrom) + "=" + Id.ToString() + "OR" + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Movement_LocationIdTo) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tableMovement, filter.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HaveStockLevel()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
String tableStockLevel = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.StockLevel);
|
||||
if (db.TableExists(tableStockLevel))
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.StockLevel_LocationId) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tableStockLevel, filter.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -9,32 +9,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmMovement_Dbas(SbmInternals internals, SysId id, Sbm.ItemType itemType, SysId itemId, Sbm.MovementType movementType, ushort flags) :
|
||||
base(internals.UserContext, id, itemType, itemId, movementType)
|
||||
public SbmMovement_Dbas(SysId id, Sbm.ItemType itemType, SysId itemId, Sbm.MovementType movementType, ushort flags) :
|
||||
base(id, itemType, itemId, movementType)
|
||||
{
|
||||
this.internals = internals;
|
||||
Id = id;
|
||||
MovementType = movementType;
|
||||
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 Elements.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -16,105 +16,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmPortfolioItem_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.PortfolioItemType portfolioItemType, ushort flags) :
|
||||
base(internals.UserContext, id, affiliateIdOwner, portfolioItemType)
|
||||
public SbmPortfolioItem_Dbas(SysId id, SysId affiliateIdOwner, Sbm.PortfolioItemType portfolioItemType, ushort flags) :
|
||||
base(id, affiliateIdOwner, portfolioItemType)
|
||||
{
|
||||
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 Elements.
|
||||
public override bool HasChildItems()
|
||||
{
|
||||
return GetChildItemCount(Sbm.PortfolioItemType.Unknown) > 0;
|
||||
}
|
||||
public override long GetChildItemCount(Sbm.PortfolioItemType portfolioItemType = Sbm.PortfolioItemType.Unknown)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return 0;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
String tablePortfolioItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.PortfolioItem);
|
||||
if (db.TableExists(tablePortfolioItem))
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.PortfolioItem_ItemIdParent) + "=" + Id.ToString());
|
||||
if (portfolioItemType > 0)
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.PortfolioItem_Type) + "=" + ((int)portfolioItemType).ToString());
|
||||
return db.GetRowCount(tablePortfolioItem, filter.Concat(" AND ", "(", ")"));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public override bool IsReferencedByOtherItems()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
String tablePortfolioItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.PortfolioItem);
|
||||
if (db.TableExists(tablePortfolioItem))
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.PortfolioItem_ItemIdRef) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tablePortfolioItem, filter.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Clear all descendent items.
|
||||
public override bool ClearChildItems()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
using (SbmCommodityMgr commodityMgr = SbmGlobals.System.CreateCommodityMgr(UserContext))
|
||||
{
|
||||
SbmPortfolioItem.Params prmPortfolioItem = new SbmPortfolioItem.Params();
|
||||
prmPortfolioItem.ParentItemId = Id;
|
||||
foreach (SbmPortfolioItem portfolioItem in commodityMgr.GetPortfolioItemList(prmPortfolioItem))
|
||||
{
|
||||
portfolioItem.ClearChildItems();
|
||||
if (!commodityMgr.DeletePortfolioItem(portfolioItem, UserContext.DbUpdateInfo))
|
||||
return SetErrorState(commodityMgr.ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Dependent data should only be cleared when removing a portfolio item.
|
||||
// Data owned by this item is deleted (eg. interface data items & document references).
|
||||
// NB This method does not clear child portfolio items.
|
||||
public override bool ClearDependentData()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
using (SbmDataItemMgr dataItemMgr = SbmGlobals.System.CreateDataItemMgr(UserContext))
|
||||
{
|
||||
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.PortfolioItem, Id))
|
||||
return SetErrorState(dataItemMgr.ErrorStateMessage);
|
||||
}
|
||||
SaItemDocConsole itemDocConsole = internals.ItemDocConsole;
|
||||
if (!itemDocConsole.ClearItemDocs(new ItemId((short)Sbm.ItemType.PortfolioItem, Id), SaItemDocConsole.Category.Unknown, UserContext.DbUpdateInfo))
|
||||
return SetErrorState(itemDocConsole.ErrorStateMessage);
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -15,47 +15,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmPriceSet_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, String reference, Sbm.PriceType priceType, ushort flags) :
|
||||
base(internals.UserContext, id, affiliateIdOwner, reference, priceType)
|
||||
public SbmPriceSet_Dbas(SysId id, SysId affiliateIdOwner, String reference, Sbm.PriceType priceType, ushort flags) :
|
||||
base(id, affiliateIdOwner, reference, priceType)
|
||||
{
|
||||
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 HasPrices()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
String tablePrice = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaPrice);
|
||||
if (db.TableExists(tablePrice))
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaPrice_PriceSetId) + "=" + SysId.ToString(Id));
|
||||
return db.GetRowCount(tablePrice, filter.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -9,30 +9,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmPrice_Dbas(SbmInternals internals, SysId priceSetId, SysId commodityId, Sbm.PriceType priceType, ushort flags) :
|
||||
base(internals.UserContext, priceSetId, commodityId, priceType)
|
||||
public SbmPrice_Dbas(SysId priceSetId, SysId commodityId, Sbm.PriceType priceType, ushort flags) :
|
||||
base(priceSetId, commodityId, priceType)
|
||||
{
|
||||
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.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Sarand.Net.Standard.Base.ItemData;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static Sarand.BusinessMgr.Net.Standard.Base.App.Sbm;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
@@ -16,185 +17,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
private readonly List<TypeCodeDesc> itemDataTypes;
|
||||
private static readonly String codeDelim = ",";
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmProcess_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, Sbm.ProcessCategory processCategory, ushort flags) :
|
||||
base(internals.UserContext, id, affIdOwner, processCategory)
|
||||
public SbmProcess_Dbas(SysId id, SysId affIdOwner, Sbm.ProcessCategory processCategory, ushort flags) :
|
||||
base(id, affIdOwner, processCategory)
|
||||
{
|
||||
this.internals = internals;
|
||||
itemDataTypes = internals.GetSystemCodes(Sbm.SystemCode.ItemDataType);
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// NB Do not dispose the Internals - owned by manager.
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated codes.
|
||||
public override String GetCodeForCostCode(SbmProcessCostCode processCostCode)
|
||||
{
|
||||
switch (processCostCode)
|
||||
{
|
||||
case SbmProcessCostCode.Fixed_Unit: return itemDataTypes.GetCodeForType(Sbm.ItemDataType.Process_FixedCost_Unit);
|
||||
case SbmProcessCostCode.Fixed_Job: return itemDataTypes.GetCodeForType(Sbm.ItemDataType.Process_FixedCost_Job);
|
||||
case SbmProcessCostCode.Labour_Unit: return itemDataTypes.GetCodeForType(Sbm.ItemDataType.Process_LabourCost_Unit);
|
||||
case SbmProcessCostCode.Labour_Job: return itemDataTypes.GetCodeForType(Sbm.ItemDataType.Process_LabourCost_Job);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public override bool HasCostCodes()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
|
||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||
prmItemData.ItemIdsIncluded.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||
prmItemData.DataTypesIncluded.Add(GetCodeForCostCode(SbmProcessCostCode.Fixed_Unit));
|
||||
prmItemData.DataTypesIncluded.Add(GetCodeForCostCode(SbmProcessCostCode.Fixed_Job));
|
||||
prmItemData.DataTypesIncluded.Add(GetCodeForCostCode(SbmProcessCostCode.Labour_Unit));
|
||||
prmItemData.DataTypesIncluded.Add(GetCodeForCostCode(SbmProcessCostCode.Labour_Job));
|
||||
return internals.ItemDataConsole.ItemDataExists(prmItemData);
|
||||
}
|
||||
public override bool HasCostCodes(SbmProcessCostCode processCostCode)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
bool bHas = false;
|
||||
// Identify process code type code.
|
||||
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
||||
if (!StringUtil.IsEmpty(itemDataTypeCode))
|
||||
{
|
||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||
prmItemData.ItemIdsIncluded.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||
prmItemData.DataTypesIncluded.Add(itemDataTypeCode);
|
||||
bHas = internals.ItemDataConsole.ItemDataExists(prmItemData);
|
||||
}
|
||||
return bHas;
|
||||
}
|
||||
public override List<String> GetCostCodes(SbmProcessCostCode processCostCode)
|
||||
{
|
||||
List<String> costCodes = new List<String>();
|
||||
ClearErrorState();
|
||||
// Identify process code type code.
|
||||
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
||||
if (!SysId.IsValid(Id) && !StringUtil.IsEmpty(itemDataTypeCode))
|
||||
{
|
||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||
prmItemData.ItemIdsIncluded.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||
prmItemData.DataTypesIncluded.Add(itemDataTypeCode);
|
||||
List<SaItemData> itemDatas = internals.ItemDataConsole.GetItemDataList(prmItemData);
|
||||
foreach (SaItemData itemData in itemDatas)
|
||||
{
|
||||
if (itemData == null) continue;
|
||||
costCodes.AddRange(StringListUtil.Split(itemData.ItemData, codeDelim));
|
||||
break;
|
||||
}
|
||||
itemDatas.Clear();
|
||||
}
|
||||
return costCodes;
|
||||
}
|
||||
public override bool StoreCostCodes(SbmProcessCostCode processCostCode, List<String> costCodes)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (StringUtil.IsEmpty(costCodes.Concat(codeDelim))) return ClearCostCodes(processCostCode);
|
||||
// Identify process code type code.
|
||||
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
||||
if (!SysId.IsValid(Id) && !StringUtil.IsEmpty(itemDataTypeCode))
|
||||
{
|
||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||
prmItemData.ItemIdsIncluded.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||
prmItemData.DataTypesIncluded.Add(itemDataTypeCode);
|
||||
List<SaItemData> itemDatas = internals.ItemDataConsole.GetItemDataList(prmItemData);
|
||||
// ToDo itemData condition.
|
||||
//itemDatas.GotoStart();
|
||||
SaItemData itemData = null;//itemDatas.Count == 1 ? itemDatas.Remove(1) : null;
|
||||
itemDatas.Clear();
|
||||
if (itemData == null)
|
||||
{
|
||||
// Code type not found - create a new entry.
|
||||
itemData = internals.ItemDataConsole.CreateItemData(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||
itemData.DataType = itemDataTypeCode;
|
||||
}
|
||||
if (itemData != null)
|
||||
{
|
||||
// Populate item data for these codes.
|
||||
itemData.ItemData = costCodes.Concat(codeDelim);
|
||||
if (!internals.ItemDataConsole.Store(itemData, internals.DbUpdateInfo))
|
||||
{
|
||||
SetErrorState(internals.ItemDataConsole.ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
public override bool ClearCostCodes(SbmProcessCostCode processCostCode)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Identify process code type code.
|
||||
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
||||
if (!SysId.IsValid(Id) && !StringUtil.IsEmpty(itemDataTypeCode))
|
||||
{
|
||||
if (!internals.ItemDataConsole.ClearItemData(new ItemId((short)Sbm.ItemType.Process, Id), itemDataTypeCode, internals.DbUpdateInfo))
|
||||
{
|
||||
SetErrorState(internals.ItemDataConsole.ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
public override bool ClearCostCodes()
|
||||
{
|
||||
ClearErrorState();
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
public override bool HasReferences()
|
||||
{
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
if (internals.DataItemMgr.HasItemLinks(Sbm.ItemType.Process, Id)) return true;
|
||||
// Is this process referenced by Constituents.
|
||||
ISacsDatabase db = SbmGlobals.Application.GetBusMgrDatabase(internals.SessionContext); if (db != null) return true;
|
||||
|
||||
// Constituents.
|
||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_Id) + "=" + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_ProcessId) + "=" + Id.ToString();
|
||||
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Constituent), filter) > 0;
|
||||
}
|
||||
public override bool HasItemData()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||
prmItemData.ItemIdsIncluded.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||
return internals.ItemDataConsole.ItemDataExists(prmItemData);
|
||||
}
|
||||
public override bool ClearAssociatedData()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return SetErrorState("item not specified");
|
||||
// Clear Item data records.
|
||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||
prmItemData.ItemIdsIncluded.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||
List<SaItemData> itemDatas = internals.ItemDataConsole.GetItemDataList(prmItemData);
|
||||
foreach (SaItemData itemData in itemDatas)
|
||||
{
|
||||
internals.ItemDataConsole.Remove(itemData, internals.DbUpdateInfo);
|
||||
}
|
||||
itemDatas.Clear();
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -16,317 +16,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
private readonly String statusCancelled = SacsSystem.GetStatusCode(SaStatus.Cancelled);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmRequirement_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, SysId assocId, SysId transId, Sbm.RequirementType requirementType, ushort flags) :
|
||||
base(internals.UserContext, id, affIdOwner, assocId, transId, requirementType)
|
||||
public SbmRequirement_Dbas(SysId id, SysId affIdOwner, SysId assocId, SysId transId, Sbm.RequirementType requirementType, ushort flags) :
|
||||
base(id, affIdOwner, assocId, transId, requirementType)
|
||||
{
|
||||
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.
|
||||
private SbmTransactionMgr TransactionMgr { get { return internals.TransactionMgr; } }
|
||||
private SbmDataItemMgr DataItemMgr { get { return internals.DataItemMgr; } }
|
||||
private SbmProcessMgr ProcessMgr { get { return internals.ProcessMgr; } }
|
||||
private SbmStockMgr StockMgr { get { return internals.StockMgr; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
public override bool HasRequirements()
|
||||
{
|
||||
ClearErrorState();
|
||||
bool hasRequirements = TransactionMgr.RequirementHasAssociatedRequirements(Id);
|
||||
SetErrorState(TransactionMgr.ErrorStateMessage);
|
||||
return hasRequirements;
|
||||
}
|
||||
public override bool HasConstituents(Sbm.ConstituentType constituentType)
|
||||
{
|
||||
ClearErrorState();
|
||||
bool hasConstituents = TransactionMgr.RequirementHasConstituents(Id, constituentType);
|
||||
SetErrorState(TransactionMgr.ErrorStateMessage);
|
||||
return hasConstituents;
|
||||
}
|
||||
public override bool HasStockMovments()
|
||||
{
|
||||
ClearErrorState();
|
||||
bool hasMovements = false;
|
||||
/* ToDo need to have StockMgr for RequirementDbas>HasStockMovments
|
||||
if (SysId.IsValid(Id) && InitStockMgr())
|
||||
{
|
||||
hasMovements = stockMgr.SourceItemHasMovements(Sbm.ItemType.Requirement, Id);
|
||||
}*/
|
||||
return hasMovements;
|
||||
}
|
||||
public override bool HasItemLinks()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (SysId.IsValid(Id))
|
||||
DataItemMgr.HasItemLinks(Sbm.ItemType.Requirement, Id);
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override bool CommitAssociatedData()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (this == null || !SysId.IsValid(Id)) return false;
|
||||
if (!HasErrorState()) CommitCostEstimates();
|
||||
if (!HasErrorState()) CommitProcesses();
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override bool ClearDependentData()
|
||||
{
|
||||
ClearErrorState();
|
||||
TransactionMgr.ClearRequirementDependentData(Id, CommodityId);
|
||||
SetErrorState(TransactionMgr.ErrorStateMessage);
|
||||
return !HasErrorState();
|
||||
}
|
||||
public override bool ClearAssociatedRequirements()
|
||||
{
|
||||
ClearErrorState();
|
||||
TransactionMgr.ClearRequirementAssociatedRequirements(Id);
|
||||
SetErrorState(TransactionMgr.ErrorStateMessage);
|
||||
return !HasErrorState();
|
||||
}
|
||||
public override decimal GetQuantityDispatched(SysId transIdExclude)
|
||||
{
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (SysId.IsValid(Id))
|
||||
{
|
||||
// Build query to sum associated dispatch item quantities.
|
||||
List<String> filters = new List<String>
|
||||
{
|
||||
SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_ReqntIdSource) + "=" + Id.ToString(),
|
||||
SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_Status) + "<>'" + statusCancelled + "'"
|
||||
};
|
||||
// Requirement must belong to a transaction of type 'Dispatch Note'.
|
||||
DbQuery qryTrans = new DbQuery(db.DbmsType);
|
||||
qryTrans.Tables.Add(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Transaction));
|
||||
qryTrans.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Transaction_Id));
|
||||
if (SysId.IsValid(transIdExclude))
|
||||
qryTrans.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Transaction_Id) + "<>" + transIdExclude.ToString());
|
||||
qryTrans.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Transaction_Id) + "=" + SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_TransId));
|
||||
qryTrans.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Transaction_Type) + "=" + Sbm.TransactionType.SalesDispatch.ToString());
|
||||
qryTrans.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Transaction_Status) + "<>'" + statusCancelled + "'");
|
||||
filters.Add("EXISTS (" + qryTrans.BuildQuery() + ")");
|
||||
|
||||
// Retrieve database and perform query.
|
||||
if (db != null)
|
||||
db.GetRowValue(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Requirement), SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_Quantity), filters.Concat(" AND ", "(", ")"), DbGetValueType.eDbValueSum);
|
||||
SetErrorState("Database query failed");
|
||||
}
|
||||
return 0.0m;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override decimal GetQuantityInvoiced(SysId transIdExclude)
|
||||
{
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (SysId.IsValid(Id))
|
||||
{
|
||||
// Build query to sum associated dispatch item quantities.
|
||||
List<String> filter = new List<String>
|
||||
{
|
||||
SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_ReqntIdSource) + "=" + Id.ToString(),
|
||||
SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_Status) + "<>'" + statusCancelled + "'"
|
||||
};
|
||||
// Requirement must belong to a transaction of type 'Invoice' (Sales or Purchase).
|
||||
DbQuery qryTrans = new DbQuery(db.DbmsType);
|
||||
String colTransaction_Id = SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Transaction_Id);
|
||||
String colRequirement_TransId = SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_TransId);
|
||||
String colTransaction_Type = SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Transaction_Type);
|
||||
String colTransaction_Status = SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Transaction_Status);
|
||||
qryTrans.Tables.Add(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Transaction));
|
||||
qryTrans.Columns.Add(colTransaction_Id);
|
||||
if (SysId.IsValid(transIdExclude))
|
||||
qryTrans.Filters.Add(colTransaction_Id + "<>" + transIdExclude.ToString());
|
||||
qryTrans.Filters.Add(colTransaction_Id + "=" + colRequirement_TransId);
|
||||
qryTrans.Filters.Add("(" + colTransaction_Type + "=" + Sbm.TransactionType.SalesInvoice.ToString() + "OR" + colTransaction_Type + "=" + Sbm.TransactionType.PurchaseInvoice + ")".ToString());
|
||||
qryTrans.Filters.Add(colTransaction_Status + "<>'" + statusCancelled + "'");
|
||||
filter.Add("EXISTS (" + qryTrans.BuildQuery() + ")");
|
||||
|
||||
// Retrieve database and perform query.
|
||||
if (db != null)
|
||||
db.GetRowValue(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Requirement), SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_Quantity), filter.Concat(" AND ", "(", ")"), DbGetValueType.eDbValueSum);
|
||||
SetErrorState("Database query failed");
|
||||
}
|
||||
return 0.0m;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// C o s t E s t i m a t e s
|
||||
//-------------------------------------------------------------------
|
||||
public override bool HasCostEstimates()
|
||||
{
|
||||
if (data.CostEstimates != null) return data.CostEstimates.Count > 0;
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
SbmItemLink.Params prmItemLink = new SbmItemLink.Params
|
||||
{
|
||||
ItemLinkType = Sbm.ItemLinkType.Requirement_CostEstimate,
|
||||
ItemTypeFrom = Sbm.ItemType.Requirement,
|
||||
ItemIdFrom = Id
|
||||
};
|
||||
return DataItemMgr.GetItemLinkCount(prmItemLink) > 0;
|
||||
}
|
||||
public override List<SbmCostEstimate> GetCostEstimates()
|
||||
{
|
||||
List<SbmCostEstimate> costEstimatesCopy = null;
|
||||
if (data.CostEstimates == null)
|
||||
data.CostEstimates = TransactionMgr.GetRequirementCostEstimates(GetData());
|
||||
// Clone and sort the list.
|
||||
costEstimatesCopy = data.CostEstimates.Clone();
|
||||
costEstimatesCopy.Sort();
|
||||
return costEstimatesCopy;
|
||||
}
|
||||
public override bool SetCostEstimates(List<SbmCostEstimate> costEstimatesNew)
|
||||
{
|
||||
data.CostEstimates = costEstimatesNew?.Clone() ?? new List<SbmCostEstimate>();
|
||||
return true;
|
||||
}
|
||||
public override bool CommitCostEstimates()
|
||||
{
|
||||
ClearErrorState();
|
||||
// Do not attempt any updates unless the list has been populated.
|
||||
if (data.CostEstimates != null && SysId.IsValid(Id) && DataItemMgr != null)
|
||||
{
|
||||
// Build an item link list corresponding to the list of cost estimates:
|
||||
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
||||
foreach (SbmCostEstimate costEstimate in data.CostEstimates)
|
||||
{
|
||||
if (costEstimate == null) continue;
|
||||
SbmItemLink itemLink = DataItemMgr.CreateItemLink(Sbm.ItemLinkType.Requirement_CostEstimate, Sbm.ItemType.Requirement, Id, Sbm.ItemType.Unknown, new SysId(0));
|
||||
if (itemLink != null)
|
||||
{
|
||||
itemLink.Seq = (short)costEstimate.CodeSeq;
|
||||
itemLink.DataContent = costEstimate.ToString();
|
||||
itemLink.Notes = costEstimate.Notes;
|
||||
itemLinks.Add(itemLink);
|
||||
itemLink = null; // Now owned by the list.
|
||||
}
|
||||
}
|
||||
// Store these details.
|
||||
if (!DataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.Requirement_CostEstimate, new ItemId((short)Sbm.ItemType.Requirement, Id), itemLinks, internals.DbUpdateInfo))
|
||||
SetErrorState("Failed to save cost estimate item links - " + DataItemMgr.ErrorState);
|
||||
if (itemLinks != null)
|
||||
itemLinks.Clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// P r o c e s s e s
|
||||
//-------------------------------------------------------------------
|
||||
public override bool HasProcess()
|
||||
{
|
||||
if (data.Processes != null) return data.Processes.Count > 0;
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
SbmConstituent.Params prmConstituent = new SbmConstituent.Params
|
||||
{
|
||||
ConstituentType = Sbm.ConstituentType.Process,
|
||||
ReqntId = Id
|
||||
};
|
||||
return TransactionMgr.GetConstituentCount(prmConstituent) > 0;
|
||||
}
|
||||
public override List<SbmItemProcess> GetProcesses()
|
||||
{
|
||||
if (data.Processes == null && SysId.IsValid(Id))
|
||||
data.Processes = TransactionMgr.GetRequirementItemProcesses(GetData());
|
||||
// Clone the list:
|
||||
return data.Processes.Clone();
|
||||
}
|
||||
public override bool SetProcesses(List<SbmItemProcess> itemProcessesNew)
|
||||
{
|
||||
data.Processes = itemProcessesNew?.Clone() ?? new List<SbmItemProcess>();
|
||||
return true;
|
||||
}
|
||||
public override bool CommitProcesses()
|
||||
{
|
||||
ClearErrorState();
|
||||
// Do not attempt any updates unless the list has been populated.
|
||||
if (data.Processes == null || !SysId.IsValid(Id)) return true;
|
||||
|
||||
// Make a copy of the process list so that we can track those that have been updated.
|
||||
List<SbmItemProcess> itemProcessesLocal = new List<SbmItemProcess>(data.Processes);
|
||||
// Retrieve the existing processes for this requirement.
|
||||
SbmConstituent.Params prmConstituent = new SbmConstituent.Params();
|
||||
prmConstituent.ConstituentType = Sbm.ConstituentType.Process;
|
||||
prmConstituent.ReqntId = Id;
|
||||
foreach (SbmConstituent constituent in TransactionMgr.GetConstituentList(prmConstituent))
|
||||
{
|
||||
// Does this process still exist in the list.
|
||||
SbmItemProcess itemProcessLocal = itemProcessesLocal.Find(item => item.ProcessId.Equals(constituent.ProcessId));
|
||||
if (itemProcessLocal != null)
|
||||
{
|
||||
if (itemProcessLocal.Changed)
|
||||
{
|
||||
// Update the details.
|
||||
CopyFrom(itemProcessLocal, constituent);
|
||||
if (TransactionMgr.UpdateConstituent(constituent, internals.DbUpdateInfo))
|
||||
itemProcessLocal.Changed = false;
|
||||
else SetErrorState("failed to update process constituent");
|
||||
}
|
||||
// Remove this process from the local copy of the list (without deleting it).
|
||||
itemProcessesLocal.Remove(itemProcessLocal);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Process no longer required.
|
||||
constituent.Status = SaStatus.Cancelled;
|
||||
if (!TransactionMgr.DeleteConstituent(constituent, internals.DbUpdateInfo))
|
||||
SetErrorState("failed to delete process constituent");
|
||||
}
|
||||
}
|
||||
// Any item processes left in the local list need to be created.
|
||||
foreach (SbmItemProcess itemprocess in itemProcessesLocal)
|
||||
{
|
||||
if (itemprocess == null) continue;
|
||||
// Create a constituent to represent this process:
|
||||
SbmConstituent constituent = TransactionMgr.CreateConstituent(AssociationId, Sbm.ConstituentType.Process);
|
||||
if (constituent != null)
|
||||
{
|
||||
// Update the constituent to belong to this requirement.
|
||||
constituent.TransactionId = TransactionId;
|
||||
constituent.RequirementId = Id;
|
||||
CopyFrom(itemprocess, constituent);
|
||||
// Add it to the database:
|
||||
if (TransactionMgr.InsertConstituent(constituent, internals.DbUpdateInfo))
|
||||
itemprocess.Changed = false;
|
||||
else SetErrorState("failed to add constituent - " + TransactionMgr.ErrorState);
|
||||
}
|
||||
else SetErrorState("failed to create constituent - " + TransactionMgr.ErrorState);
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item Process - Constituent Interface.
|
||||
public void CopyFrom(SbmItemProcess itemProcess, SbmConstituent constituent)
|
||||
{
|
||||
if (itemProcess == null || constituent != null) return;
|
||||
constituent.Seq = itemProcess.Seq;
|
||||
constituent.Notes = itemProcess.Notes;
|
||||
constituent.ProcessId = itemProcess.ProcessId;
|
||||
constituent.AssociationIdContractor = itemProcess.AssocIdContractor;
|
||||
constituent.AmountNet = itemProcess.AmountNet;
|
||||
constituent.Completed = itemProcess.Completed;
|
||||
constituent.Notes = itemProcess.Notes;
|
||||
constituent.Status = itemProcess.Status;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SbmStockLevel_Dbas : SbmStockLevel
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmStockLevel_Dbas(SysId id, SysId idCommodity, SysId idLocation, Sbm.StockLevelType type, Sbm.StockLevelSource source, ushort flags) :
|
||||
base(id, idCommodity, idLocation, type, source)
|
||||
{
|
||||
Id = id;
|
||||
Flags = flags;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -10,29 +10,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmSysParam_Dbas(SbmInternals internals, SysId id, Sbm.SysParamCategory category, String name, ushort flags) :
|
||||
base(internals.UserContext, id, category, name)
|
||||
public SbmSysParam_Dbas(SysId id, Sbm.SysParamCategory category, String name, ushort flags) :
|
||||
base(id, category, name)
|
||||
{
|
||||
this.internals = internals;
|
||||
if (this.internals != null) { }
|
||||
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// NB Do not dispose the Internals - owned by manager.
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -9,32 +9,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmSystemAccountUser_Dbas(SbmInternals internals, SysId accountId, SysId userId, ushort flags) :
|
||||
base(internals.UserContext, accountId, userId)
|
||||
public SbmSystemAccountUser_Dbas(SysId accountId, SysId userId, ushort flags) :
|
||||
base(accountId, userId)
|
||||
{
|
||||
this.internals = internals;
|
||||
if (this.internals != null) { }
|
||||
|
||||
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.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -14,47 +14,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmSystemAccount_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, Sbm.SystemAccountType systemAccountType, SysId interfaceId, SysId assocId, ushort flags) :
|
||||
base(internals.UserContext, id, affIdOwner, systemAccountType, interfaceId, assocId)
|
||||
public SbmSystemAccount_Dbas(SysId id, SysId affIdOwner, Sbm.SystemAccountType systemAccountType, SysId interfaceId, SysId assocId, ushort flags) :
|
||||
base(id, affIdOwner, systemAccountType, interfaceId, assocId)
|
||||
{
|
||||
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 HasUsers()
|
||||
{
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
String table = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SystemAccountUser);
|
||||
if (db.TableExists(table))
|
||||
{
|
||||
String column = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SystemAccountUser_AccountId);
|
||||
List<String> filters = new List<String>();
|
||||
filters.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SystemAccountUser_AccountId) + "=" + Id.ToString());
|
||||
return db.GetRowCount(table, /*column,*/ filters.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -9,31 +9,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmSystemUser_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, SysId interfaceId, SysId affiliateId, ushort flags) :
|
||||
base(internals.UserContext, id, affIdOwner, interfaceId, affiliateId)
|
||||
public SbmSystemUser_Dbas(SysId id, SysId affIdOwner, SysId interfaceId, SysId affiliateId, ushort flags) :
|
||||
base(id, affIdOwner, interfaceId, affiliateId)
|
||||
{
|
||||
this.internals = internals;
|
||||
if (this.internals != null) { }
|
||||
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.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -14,463 +14,21 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SbmTransaction_Dbas : SbmTransaction
|
||||
//=======================================================================
|
||||
class SbmTransaction_Dbas : SbmTransaction
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmInternals internals;
|
||||
private List<SbmTransactionPayment> transactionPayments = new List<SbmTransactionPayment>();
|
||||
private readonly List<TypeCodeDesc> transactionTypes;
|
||||
private readonly List<TypeCodeDesc> transactionStatusCats;
|
||||
private readonly List<TypeCodeDesc> requirementStatusCats;
|
||||
private readonly List<TypeCodeDesc> constituentStatusCats;
|
||||
private readonly String statusCancelled = SacsSystem.GetStatusCode(SaStatus.Cancelled);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmTransaction_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, SysId assocId, Sbm.TransactionType transactionType, ushort flags) :
|
||||
base(internals.UserContext, id, affIdOwner, assocId, transactionType)
|
||||
public SbmTransaction_Dbas(SysId id, SysId affIdOwner, SysId assocId, Sbm.TransactionType transactionType, ushort flags) :
|
||||
base(id, affIdOwner, assocId, transactionType)
|
||||
{
|
||||
this.internals = internals;
|
||||
transactionStatusCats = internals.GetSystemCodes(Sbm.SystemCode.TransactionStatusCat);
|
||||
requirementStatusCats = internals.GetSystemCodes(Sbm.SystemCode.RequirementStatusCat);
|
||||
constituentStatusCats = internals.GetSystemCodes(Sbm.SystemCode.ConstituentStatusCat);
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// NB Do not dispose the Internals - owned by manager.
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
public override bool IsReadOnly()
|
||||
{
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
bool bReadOnly = false;
|
||||
|
||||
// Transaction can't be updated after it has been exporetd to an accounts system.
|
||||
if (!bReadOnly)
|
||||
{
|
||||
if (internals.AccountsDfn.IsTransactionTypeManagedByAccounts(TransactionType))
|
||||
bReadOnly = true;
|
||||
}
|
||||
return bReadOnly;
|
||||
}
|
||||
public override bool DetailsAreReadOnly()
|
||||
{
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
if (IsReadOnly()) return true; // If transaction is read only then details must be.
|
||||
bool detailsAreReadOnly = false;
|
||||
|
||||
// User must be allowed to update transactions:
|
||||
if (!detailsAreReadOnly)
|
||||
{
|
||||
// ToDo UserCanUpdateItemType
|
||||
/*if (!pSys->UserCanUpdateItemType(eSapItemTypeTransaction))
|
||||
bDetailsAreReadOnly = true;*/
|
||||
}
|
||||
|
||||
// Closed transactions.
|
||||
if (!detailsAreReadOnly)
|
||||
{
|
||||
if (TransactionStatusCat == SbmTransaction.StatusCat.Closed)
|
||||
{
|
||||
// Once the 'grace' period has passed, only the status can be modified.
|
||||
int graceDaysUpdateClosedTrans = Math.Max(0, internals.GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodDays.UpdateClosedTransaction, 0));
|
||||
DateTime closed = Closed;
|
||||
detailsAreReadOnly = (DateUtil.IsValid(closed) && closed <= DateTime.Today.AddDays(-graceDaysUpdateClosedTrans));
|
||||
}
|
||||
}
|
||||
|
||||
return detailsAreReadOnly;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
public override bool IsReferencedByOtherTransactions()
|
||||
{
|
||||
ClearErrorState();
|
||||
return internals.TransactionMgr.TransactionIsReferencedByOtherTransactions(Id);
|
||||
}
|
||||
public override bool HasRequirements(SbmRequirement.StatusCat requirementStatusCat = SbmRequirement.StatusCat.NotDeleted)
|
||||
{
|
||||
return (GetRequirementCount(requirementStatusCat) > 0);
|
||||
}
|
||||
public override bool HasConstituents(SbmConstituent.StatusCat constituentStatusCat = SbmConstituent.StatusCat.NotDeleted)
|
||||
{
|
||||
ClearErrorState();
|
||||
return internals.TransactionMgr.TransactionHasConstituents(Id, constituentStatusCat);
|
||||
}
|
||||
public override bool HasContainerItems()
|
||||
{
|
||||
ClearErrorState();
|
||||
return internals.TransactionMgr.TransactionHasContainerItems(Id);
|
||||
}
|
||||
public override bool HasStockMovements()
|
||||
{
|
||||
ClearErrorState();
|
||||
return internals.TransactionMgr.TransactionHasStockMovements(Id);
|
||||
}
|
||||
public override bool HasPendingStockMovements()
|
||||
{
|
||||
ClearErrorState();
|
||||
return internals.TransactionMgr.TransactionHasPendingStockMovements(Id);
|
||||
}
|
||||
public override bool HasDiaryLinks()
|
||||
{
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
/*SbmDiaryConsole diaryConsole = SbmGlobals.Application.GetDiaryConsole(SessionContext);
|
||||
if (diaryConsole != null)
|
||||
diaryConsole.DataItemHasLinks((short)Sbm.ItemType.Transaction, Id);*/
|
||||
return false;
|
||||
}
|
||||
//public override void SetDefaults(class SbmRequirement *) const;
|
||||
public override long GetRequirementCount(SbmRequirement.StatusCat requirementStatusCat = SbmRequirement.StatusCat.Any)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return 0;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
filter.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_TransId) + "=" + Id.ToString());
|
||||
if (requirementStatusCat == SbmRequirement.StatusCat.NotCancelled)
|
||||
filter.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_Status) + "<>'" + statusCancelled + "'");
|
||||
else if (requirementStatusCat > 0)
|
||||
filter.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Requirement_StatusCat) + "='" + requirementStatusCats.GetCodeForType(requirementStatusCat) + "'");
|
||||
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Requirement), filter.Concat(" AND ", "(", ")"));
|
||||
}
|
||||
else SetErrorState("database is not available");
|
||||
return 0;
|
||||
}
|
||||
public override List<SbmRequirement> GetRequirements(SbmRequirement.StatusCat requirementStatusCat = SbmRequirement.StatusCat.Any)
|
||||
{
|
||||
if (SysId.IsValid(Id))
|
||||
{
|
||||
// Retrieve the current set of requirements for this transaction.
|
||||
SbmRequirement.Params prmRequirement = new SbmRequirement.Params();
|
||||
//prmRequirement.RequirementStatusCat = requirementStatusCat;
|
||||
prmRequirement.TransactionIdsIncluded.Add(Id);
|
||||
return internals.TransactionMgr.GetRequirementList(prmRequirement);
|
||||
}
|
||||
return new List<SbmRequirement>();
|
||||
}
|
||||
public override bool ItemsRequireJobNumber()
|
||||
{
|
||||
// Check whether Job Number should be allocated.
|
||||
SbmSessionConsole sessionConsole = internals.SessionConsole;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (sessionConsole != null && sessionConsole.AllowOption(Sbm.ConfigOption.SalesOrderItemJobNumber) && SbmGlobals.Application.DbColumnExists(db, SbmDbDfn.ColumnIdx.Requirement_JobNumber))
|
||||
return TransactionType == Sbm.TransactionType.SalesOrder;
|
||||
return false;
|
||||
}
|
||||
public override bool UpdateRequirements(List<SbmRequirement> requirements)
|
||||
{
|
||||
if (this == null) return false;
|
||||
ClearErrorState();
|
||||
SacsDatabase db = internals.BusMgrDatabase as SacsDatabase;
|
||||
if (db == null) return SetErrorState("Database not available");
|
||||
if (!SysId.IsValid(Id)) return SetErrorState("transaction does not exist");
|
||||
// Verify requirements list.
|
||||
if (!HasErrorState())
|
||||
{
|
||||
// Validate the identity of each each requirement in the list.
|
||||
foreach (SbmRequirement requirement in requirements)
|
||||
{
|
||||
if (requirement == null) continue;
|
||||
if (SysId.IsValid(requirement.AssociationId) && requirement.AssociationId != AssociationId)
|
||||
{
|
||||
SetErrorState("Invalid requirement in list: doesn't belong to association.");
|
||||
}
|
||||
else if (SysId.IsValid(requirement.TransactionId) && requirement.TransactionId != Id)
|
||||
{
|
||||
SetErrorState("Invalid requirement in list: doesn't belong to transaction.");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set identity for each requirements in the list.
|
||||
if (!HasErrorState())
|
||||
{
|
||||
// Set the sequence and identity against each requirement in the list.
|
||||
for (int requirementIdx = 0; requirementIdx < requirements.Count; requirementIdx++)
|
||||
{
|
||||
SbmRequirement requirement = requirements[requirementIdx];
|
||||
requirement.Seq = (short)(requirementIdx + 1);
|
||||
requirement.AssociationId = AssociationId;
|
||||
requirement.TransactionId = Id;
|
||||
if (ItemsRequireJobNumber() && StringUtil.IsEmpty(requirement.JobNumber))
|
||||
{
|
||||
String jobNumberNextIdObject = "JobNumber:" + SysId.ToString(internals.UserContext.OrganisationAffiliateId);
|
||||
/*
|
||||
// Check for original Job Number 'NextId' key and convert to organisation specific.
|
||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.NextId_Object) + "='JobNumber'";
|
||||
if (db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.NextId), filter) > 0)
|
||||
{
|
||||
String query =
|
||||
"Begin Transaction;\n" + "Update dbo.NextId Set Object='" + jobNumberNextIdObject + "' Where " + filter + ";\n" + "Commit Transaction;\n";
|
||||
db.ExecuteQuery(query);
|
||||
}
|
||||
*/
|
||||
String jobNumber = SysId.ToString(db.GetNextId(jobNumberNextIdObject, internals.UserContext.DbUpdateInfo, false));
|
||||
requirement.JobNumber = "";
|
||||
}
|
||||
SetDefaults(requirement);
|
||||
}
|
||||
}
|
||||
|
||||
// Make a copy of the list (pointers only) to keep track of those requirements in the list that have not been updated against the database.
|
||||
List<SbmRequirement> requirementsNotUpdated = new List<SbmRequirement>(requirements);
|
||||
// Retrieve each of the requirements currently specified for this transaction in turn.
|
||||
List<SysId> requirementIdsUpdated = new List<SysId>();
|
||||
if (!HasErrorState())
|
||||
{
|
||||
List<ColumnDfn> columnsQuery = new List<ColumnDfn>();
|
||||
String colRequirement_Id = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_Id);
|
||||
SbmRequirement.Params prmRequirement = new SbmRequirement.Params();
|
||||
prmRequirement.TransactionIdsIncluded.Add(Id);
|
||||
using (DbResultSet dbResultSet = internals.TransactionMgr.ExecuteRequirementQuery(columnsQuery, prmRequirement))
|
||||
{
|
||||
while (!HasErrorState() && dbResultSet != null && dbResultSet.NextRecord())
|
||||
{
|
||||
NamedValue.Map values = dbResultSet.GetRecordValues();
|
||||
SysId requirementId = new SysId((int)values.GetValue(colRequirement_Id).AsLong());
|
||||
// Does this requirement exist in the list.
|
||||
if (requirementsNotUpdated.ExistsById(requirementId))
|
||||
{
|
||||
// Requirement still in list - update the details.
|
||||
SbmRequirement requirement = requirementsNotUpdated[0];
|
||||
if (internals.TransactionMgr.UpdateRequirement(requirement, internals.DbUpdateInfo))
|
||||
{
|
||||
if (!requirement.CommitAssociatedData())
|
||||
SetErrorState("Failed to update requirement's data: " + requirement.ErrorStateMessage);
|
||||
}
|
||||
else SetErrorState("Failed to update requirement: " + internals.TransactionMgr.ErrorStateMessage);
|
||||
requirementsNotUpdated.Remove(requirement);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Requirement not in list - remove it.
|
||||
SbmRequirement requirement = internals.TransactionMgr.GetRequirement(prmRequirement);
|
||||
if (requirement != null)
|
||||
{
|
||||
if (!internals.TransactionMgr.DeleteRequirement(requirement, TransactionType, internals.DbUpdateInfo))
|
||||
SetErrorState("Failed to remove requirement: " + internals.TransactionMgr.ErrorStateMessage);
|
||||
}
|
||||
else SetErrorState("Failed to retrieve requirement for deletion: " + internals.TransactionMgr.ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Any requirements left in the 'Not Updated' list must be new.
|
||||
foreach (SbmRequirement requirementNotUpdate in requirementsNotUpdated)
|
||||
{
|
||||
if (requirementNotUpdate != null)
|
||||
{
|
||||
if (!SysId.IsValid(requirementNotUpdate.Id))
|
||||
{
|
||||
// Requirement does not yet exist - create it:
|
||||
if (internals.TransactionMgr.InsertRequirement(requirementNotUpdate, internals.DbUpdateInfo))
|
||||
{
|
||||
if (!requirementNotUpdate.CommitAssociatedData())
|
||||
SetErrorState("Failed to update requirement's data: " + requirementNotUpdate.ErrorStateMessage);
|
||||
}
|
||||
else SetErrorState("Failed to create requirement: " + internals.TransactionMgr.ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
else SetErrorState("null item in list");
|
||||
requirementsNotUpdated = null;
|
||||
}
|
||||
// Clean-up:
|
||||
requirementsNotUpdated.Clear();
|
||||
return !HasErrorState();
|
||||
}
|
||||
public override bool CommitAssociatedData()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (this == null || !SysId.IsValid(Id)) return false;
|
||||
if (!HasErrorState()) CommitPayments();
|
||||
return !HasErrorState();
|
||||
}
|
||||
public override bool ClearDependentData()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = internals.BusMgrDatabase;
|
||||
if (db != null)
|
||||
{
|
||||
if (!HasErrorState())
|
||||
{
|
||||
// Delete interface data items.
|
||||
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||
if (interfaceConsole != null)
|
||||
{
|
||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Transaction, Id), internals.DbUpdateInfo))
|
||||
SetErrorState("Failed to clear interface data items - " + interfaceConsole.ErrorStateMessage);
|
||||
}
|
||||
else SetErrorState("Failed to retrieve interface console");
|
||||
interfaceConsole = null; // Do not delete this global object.
|
||||
}
|
||||
if (!HasErrorState())
|
||||
{
|
||||
/* ToDo itemDocConsole > Remove document references.
|
||||
SaItemDocConsole itemDocConsole = SbmGlobals.Application.GetItemDocConsole(SessionContext);
|
||||
if (itemDocConsole != null)
|
||||
{
|
||||
if (!itemDocConsole.ClearItemDocs(Sbm.ItemType.Transaction, Id))
|
||||
SetErrorState(itemDocConsole.ErrorStateMessage);
|
||||
}
|
||||
else SetErrorState("Failed to retrieve item document console");
|
||||
itemDocConsole = null; // Do not delete this global object.*/
|
||||
}
|
||||
// Delete any associated items links.
|
||||
if (!HasErrorState())
|
||||
{
|
||||
if (!internals.DataItemMgr.ClearDataItem(Sbm.ItemType.Transaction, Id))
|
||||
SetErrorState("failed to clear transaction item links");
|
||||
}
|
||||
// Delete any constituents that belong to this Transaction.
|
||||
if (!HasErrorState())
|
||||
{
|
||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_TransId) + "=" + Id.ToString();
|
||||
if (db.ExecuteDelete(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Constituent), filter) > 0)
|
||||
SetErrorState("failed to clear Transaction constituents");
|
||||
}
|
||||
// Clear requirements.
|
||||
if (!HasErrorState())
|
||||
{
|
||||
List<SbmRequirement> requirements = GetRequirements();
|
||||
if (requirements != null && requirements.Count > 0)
|
||||
{
|
||||
foreach (SbmRequirement requirement in requirements)
|
||||
{
|
||||
if (!internals.TransactionMgr.DeleteRequirement(requirement, TransactionType, internals.DbUpdateInfo))
|
||||
SetErrorState(internals.TransactionMgr.ErrorStateMessage);
|
||||
requirements = null;
|
||||
}
|
||||
}
|
||||
if (requirements != null) requirements.Clear();
|
||||
}
|
||||
// Clear addresses.
|
||||
if (!HasErrorState())
|
||||
{
|
||||
if (!internals.AccountMgr.ClearAddressesFor(Sbm.ItemType.Transaction, new ItemId()))
|
||||
SetErrorState("failed to clear addresses - " + internals.AccountMgr.ErrorStateMessage);
|
||||
}
|
||||
// Clear any references to this transaction from other transactions:
|
||||
if (!HasErrorState())
|
||||
{
|
||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Transaction_TransIdSource) + "=" + Id.ToString();
|
||||
List<StringPair> values = new List<StringPair>();
|
||||
SacsDatabase.AddValuePair(values, SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Transaction_TransIdSource), "0", false);
|
||||
db.ExecuteUpdate(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Transaction), values, filter);
|
||||
if (db.HasErrorState())
|
||||
SetErrorState($"{db.ErrorStateMessage}");
|
||||
}
|
||||
}
|
||||
else SetErrorState("database is unavailable");
|
||||
return !HasErrorState();
|
||||
}
|
||||
public override bool HasPayments()
|
||||
{
|
||||
if (transactionPayments != null) return true;
|
||||
else if (SysId.IsValid(Id))
|
||||
{
|
||||
SbmItemLink.Params prmItemLink = new SbmItemLink.Params
|
||||
{
|
||||
ItemLinkType = Sbm.ItemLinkType.Transaction_Payment,
|
||||
ItemTypeFrom = Sbm.ItemType.Transaction,
|
||||
ItemIdFrom = Id
|
||||
};
|
||||
foreach (SbmItemLink itemLink in internals.DataItemMgr.GetItemLinkList(prmItemLink))
|
||||
if (itemLink != null) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override List<SbmTransactionPayment> GetPayments()
|
||||
{
|
||||
List<SbmTransactionPayment> transactionPaymentsCopy = new List<SbmTransactionPayment>();
|
||||
if (transactionPayments == null && SysId.IsValid(Id))
|
||||
{
|
||||
SbmItemLink.Params prm = new SbmItemLink.Params();
|
||||
prm.ItemLinkType = Sbm.ItemLinkType.Transaction_Payment;
|
||||
prm.ItemTypeFrom = Sbm.ItemType.Transaction;
|
||||
prm.ItemIdFrom = Id;
|
||||
List<SbmItemLink> itemLinks = internals.DataItemMgr.GetItemLinkList(prm);
|
||||
if (itemLinks != null)
|
||||
{
|
||||
foreach (SbmItemLink itemLink in itemLinks)
|
||||
{
|
||||
if (itemLink == null) continue;
|
||||
SbmTransactionPayment transactionPayment = new SbmTransactionPayment(UserContext, itemLink.DataContent);
|
||||
transactionPayment.Notes = itemLink.Notes;
|
||||
transactionPayment.Changed = false;
|
||||
if (transactionPayments == null) transactionPayments = new List<SbmTransactionPayment>();
|
||||
transactionPayments.Add(transactionPayment);
|
||||
}
|
||||
// Clean-up.
|
||||
itemLinks.Clear();
|
||||
}
|
||||
}
|
||||
// Clone the list.
|
||||
transactionPaymentsCopy = transactionPayments.Clone();
|
||||
transactionPaymentsCopy.Sort();
|
||||
return transactionPaymentsCopy;
|
||||
}
|
||||
|
||||
public override bool SetPayments(List<SbmTransactionPayment> transactionPaymentsNew)
|
||||
{
|
||||
// Clear the existing list:
|
||||
if (transactionPayments != null) transactionPayments.Clear();
|
||||
// Copy all items from the specified list:
|
||||
transactionPayments = transactionPaymentsNew.Clone();
|
||||
return true;
|
||||
}
|
||||
public override bool CommitPayments()
|
||||
{
|
||||
ClearErrorState();
|
||||
// Do not attempt any updates unless the list has been populated.
|
||||
if (transactionPayments != null && SysId.IsValid(Id))
|
||||
{
|
||||
// Build an item link list corresponding to the list of payment:
|
||||
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
||||
|
||||
foreach (SbmTransactionPayment transactionPayment in transactionPayments)
|
||||
{
|
||||
if (transactionPayment == null) continue;
|
||||
SbmItemLink itemLink = internals.DataItemMgr.CreateItemLink(Sbm.ItemLinkType.Transaction_Payment, Sbm.ItemType.Transaction, Id, Sbm.ItemType.Unknown, new SysId(0));
|
||||
if (itemLink != null)
|
||||
{
|
||||
itemLink.Seq = (short)transactionPayment.CodeSeq;
|
||||
itemLink.DataContent = transactionPayment.ToString();
|
||||
itemLink.Notes = transactionPayment.Notes;
|
||||
itemLinks.Add(itemLink);
|
||||
itemLink = null; // Now owned by the list.
|
||||
}
|
||||
}
|
||||
// Store these details:
|
||||
if (internals.DataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.Transaction_Payment, new ItemId((short)Sbm.ItemType.Transaction, Id), itemLinks, internals.DbUpdateInfo))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
SetErrorState("Failed to save transaction payment item links - " + internals.DataItemMgr.ErrorStateMessage);
|
||||
}
|
||||
if (itemLinks != null)
|
||||
itemLinks.Clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
return GetVehicleCount() > 0;
|
||||
}
|
||||
public override bool ClearDependentData()
|
||||
public override bool ClearVehicleClassDependentData(DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (this == null || !SysId.IsValid(Id)) return false;
|
||||
@@ -124,7 +124,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
//DbUpdateInfo dbUpdateInfo = userContext.DbUpdateInfo;
|
||||
if (interfaceConsole != null)
|
||||
{
|
||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), internals.DbUpdateInfo))
|
||||
if (!interfaceConsole.ClearInterfaceDataItems(new SbmItemId(Sbm.ItemType.AssetCategory, Id), dbUpdateInfo))
|
||||
SetErrorState(interfaceConsole.ErrorStateMessage);
|
||||
}
|
||||
else SetErrorState("Failed to retrieve interface console");
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
//-------------------------------------------------------------------
|
||||
// O d o m e t e r R e a d i n g
|
||||
//-------------------------------------------------------------------
|
||||
public override bool SetOdometerReading(decimal odometer)
|
||||
public override bool SetOdometerReading(decimal odometer, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
if (SysId.IsValid(Id) || odometer < 1) return false;
|
||||
DateTime todayDate = DateTime.MinValue;
|
||||
@@ -69,7 +69,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
vehicleEventUpdated.StartOn = todayDate;
|
||||
vehicleEventUpdated.FinishOn = todayDate;
|
||||
vehicleEventUpdated.Odometer = odometer;
|
||||
if (internals.AssetMgr.UpdateVehicleEvent(vehicleEventUpdated, internals.DbUpdateInfo))
|
||||
if (internals.AssetMgr.UpdateVehicleEvent(vehicleEventUpdated, dbUpdateInfo))
|
||||
{
|
||||
}
|
||||
#if _DEBUG
|
||||
@@ -85,7 +85,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
vehicleEventUpdated.StartOn = todayDate;
|
||||
vehicleEventUpdated.FinishOn = todayDate;
|
||||
vehicleEventUpdated.Odometer = odometer;
|
||||
if (internals.AssetMgr.InsertVehicleEvent(vehicleEvent, internals.DbUpdateInfo))
|
||||
if (internals.AssetMgr.InsertVehicleEvent(vehicleEvent, dbUpdateInfo))
|
||||
{
|
||||
}
|
||||
#if _DEBUG
|
||||
@@ -99,7 +99,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
// Update this vehicle itself.
|
||||
LatestOdo = odometer;
|
||||
LatestOdoOn = todayDate;
|
||||
internals.AssetMgr.UpdateVehicle(this, internals.DbUpdateInfo);
|
||||
internals.AssetMgr.UpdateVehicle(this, dbUpdateInfo);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||
if (interfaceConsole == null) return false;
|
||||
return interfaceConsole.ItemHasDataItems(new ItemId((short)Sbm.ItemType.Vehicle, Id));
|
||||
return interfaceConsole.ItemHasDataItems(new SbmItemId(Sbm.ItemType.Vehicle, Id));
|
||||
}
|
||||
public override bool HpiCheckCount()
|
||||
{
|
||||
@@ -217,7 +217,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
itemDataConsole != null && itemDataConsole.ItemDataExists(prmData);*/
|
||||
return false;
|
||||
}
|
||||
public override bool ClearDependentData()
|
||||
public override bool ClearVehicleDependentData(DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (this == null || !SysId.IsValid(Id)) return false;
|
||||
@@ -254,7 +254,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||
if (interfaceConsole != null)
|
||||
{
|
||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), internals.DbUpdateInfo))
|
||||
if (!interfaceConsole.ClearInterfaceDataItems(new SbmItemId(Sbm.ItemType.AssetCategory, Id), dbUpdateInfo))
|
||||
SetErrorState(interfaceConsole.ErrorStateMessage);
|
||||
}
|
||||
else SetErrorState("Failed to retrieve interface console");
|
||||
|
||||
Reference in New Issue
Block a user