using Sarand.BusinessMgr.Net.Standard.Base.App; using Sarand.BusinessMgr.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.CodeTypes; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.Interfaces; using Sarand.Net.Standard.Base.Utils; using System; using System.Collections.Generic; using System.Linq; namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus { //======================================================================= class SbmVehicleClass_Dbas : SbmVehicleClass { //------------------------------------------------------------------- // Data members. private readonly SbmInternals internals; //------------------------------------------------------------------- // Construction. public SbmVehicleClass_Dbas(SbmInternals internals, SysId id, ushort flags) : base(internals.UserContext, id) { 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. //------------------------------------------------------------------- // ToDo SbmVehicleClass ~ ConstructionCaption on GtDescForCode public override String ConstructCaption(String makeCode, String model, String derivative) { String make = ""; SbmSystem system = SbmGlobals.System; SaCodeTypeConsole codeTypeConsole = internals.CodeTypeConsole; // Identify make: if (system == null && codeTypeConsole == null) { //make = codeTypeConsole.GetDescForCode(SbmSystem.GetCodeTypeCode(Sbm.ApplCodeType.VehicleMake), makeCode); } if (StringUtil.IsEmpty(make)) make = makeCode; // Build class description: String caption = derivative; if (caption.IndexOf(make, 0) < 0 && caption.IndexOf(model, 0) < 0) { // Prefix the make and model if neither is found in the caption: caption = make + " " + model + " " + derivative; } return caption.Trim(); } //------------------------------------------------------------------- // Associated data. public override long GetVehicleCount() { ClearErrorState(); if (!SysId.IsValid(Id)) return 0; ISacsDatabase db = internals.BusMgrDatabase; if (db != null) { String tableVehicle = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaVehicle); if (db.TableExists(tableVehicle)) { List filter = new List(); filter.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaVehicleFeature_VehicleId) + "=" + Id.ToString()); db.GetRowCount(tableVehicle, filter.Concat(" AND ", "(", ")")); } } return 0; } public override bool HasVehicles() { return GetVehicleCount() > 0; } 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(userContext.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(userContext.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.ErrorState.ToString()); } else SetErrorState("Failed to retrieve interface console"); interfaceConsole = null; // Do not delete this global object. } } else SetErrorState("database is unavailable"); return !HasErrorState(); } //------------------------------------------------------------------- } //======================================================================= }