Session Console and Internals.

This commit is contained in:
Andy Howard
2025-01-16 13:19:58 +00:00
parent ee988b1f76
commit 61ecd59794
187 changed files with 4681 additions and 3647 deletions
+99 -70
View File
@@ -20,28 +20,9 @@ using System.Linq;
namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
{
//=======================================================================
public abstract class SbmCoreMgr : SbmItemMgr
//=======================================================================
public abstract class SbmCoreMgr : SbmItemMgr
{
//-------------------------------------------------------------------
// System code cache.
/// <summary>Central repository for system codes used by manager.</summary>
private class SystemCodeCache
{
public SystemCodeCache(ISbmUserContext_Core userContext)
{
this.userContext = userContext;
}
private readonly ISbmUserContext_Core userContext;
private Dictionary<Sbm.SystemCode, List<TypeCodeDesc>> systemCodes = new Dictionary<Sbm.SystemCode, List<TypeCodeDesc>>();
public List<TypeCodeDesc> GetCodesOfType(Sbm.SystemCode systemCode)
{
if (!systemCodes.ContainsKey(systemCode))
systemCodes[systemCode] = SbmSystem.GetCodesOfType(userContext, systemCode);
return new List<TypeCodeDesc>(systemCodes.GetValue(systemCode, new List<TypeCodeDesc>()));
}
}
//-------------------------------------------------------------------
// Code type cache.
public class CodeTypeCache
@@ -90,14 +71,29 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
//-------------------------------------------------------------------
// Data members.
private SbmInternals internals;
private readonly SystemCodeCache systemCodeCache;
private readonly List<TypeCodeDesc> currencyCodes;
private List<SaCurrency> currencies;
private List<SaLanguage> languages;
private List<SaRegion> regions;
private List<SaTaxCode> taxCodes;
private List<SaUnitMeasure> unitsOfMeasure;
private class Members
{
// Externally supplied Internals - disposed elsewhere.
public SbmInternals internalsSupplied;
// Internally constructed Internals - disposed here.
public SbmInternals internals;
// Numeric control values.
public bool numericControlValuesInitialised = false;
public int weightDecimals;
public int lengthDecimals;
public int volumeDecimals;
public int densityDecimals;
public int boxQuantityDecimals;
public int orderQuantityDecimals;
// Reference data.
public List<TypeCodeDesc> currencyCodes;
public List<SaCurrency> currencies;
public List<SaLanguage> languages;
public List<SaRegion> regions;
public List<SaTaxCode> taxCodes;
public List<SaUnitMeasure> unitsOfMeasure;
}
private readonly Members mbr = new Members();
//-------------------------------------------------------------------
// Static initialisation.
@@ -107,30 +103,50 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
//-------------------------------------------------------------------
// Construction.
protected SbmCoreMgr(ISbmUserContext_Core userContext)
protected SbmCoreMgr(SbmInternals internals)
{
if (internals == null)
throw new NotSupportedException("SbmItemMgr Internals must be supplied");
mbr.internalsSupplied = internals;
UserContext = internals.UserContext;
Initialise();
}
protected SbmCoreMgr(ISbmUserOrganisationContext userContext)
{
if (userContext == null)
throw new NotSupportedException("SbmItemMgr User context must be supplied");
UserContext = userContext;
systemCodeCache = new SystemCodeCache(userContext);
// Numeric formatting values.
WeightDecimals = UserContext.GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals.CommodityWeight);
LengthDecimals = UserContext.GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals.CommodityLength);
VolumeDecimals = UserContext.GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals.CommodityVolume);
DensityDecimals = UserContext.GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals.CommodityDensity);
BoxQuantityDecimals = 0;
// Reference data.
currencyCodes = SaReferenceDataConsole.GetReferenceDataCodes(ReferenceDataSystemCode.CurrencyCode);
mbr.internalsSupplied = null;
this.UserContext = userContext;
Initialise();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (internals != null) internals.Dispose();
if (mbr.internals != null) mbr.internals.Dispose();
}
base.Dispose(disposing);
}
//-------------------------------------------------------------------
// Initialisation.
private void Initialise()
{
}
private void InitialiseNumericControlValues()
{
if (mbr.numericControlValuesInitialised) return;
mbr.numericControlValuesInitialised = true;
// Numeric formatting values.
mbr.weightDecimals = Internals.GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals.CommodityWeight);
mbr.lengthDecimals = Internals.GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals.CommodityLength);
mbr.volumeDecimals = Internals.GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals.CommodityVolume);
mbr.densityDecimals = Internals.GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals.CommodityDensity);
mbr.boxQuantityDecimals = 0;
mbr.orderQuantityDecimals = Internals.GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals.OrderQuantity);
}
//-------------------------------------------------------------------
// Async initialisation.
public async void InitialiseCodeTypesAsync()
@@ -151,26 +167,31 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
protected List<TypeCodeDesc> ItemTypes { get { return GetCodesOfType(Sbm.SystemCode.ItemType); } }
protected List<TypeCodeDesc> InterfaceOptionCodes { get { return GetCodesOfType(Sbm.SystemCode.InterfaceOption); } }
// Numeric control values.
protected int WeightDecimals { get; set; } = 0;
protected int LengthDecimals { get; set; } = 0;
protected int VolumeDecimals { get; set; } = 0;
protected int DensityDecimals { get; set; } = 0;
protected int BoxQuantityDecimals { get; set; } = 0;
protected int OrderQuantityDecimals { get; set; } = 0;
// Session.
protected ISbmUserContext_Core UserContext { get; }
protected SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
protected int WeightDecimals { get { InitialiseNumericControlValues(); return mbr.weightDecimals; } }
protected int LengthDecimals { get { InitialiseNumericControlValues(); return mbr.lengthDecimals; } }
protected int VolumeDecimals { get { InitialiseNumericControlValues(); return mbr.volumeDecimals; } }
protected int DensityDecimals { get { InitialiseNumericControlValues(); return mbr.densityDecimals; } }
protected int BoxQuantityDecimals { get { InitialiseNumericControlValues(); return mbr.boxQuantityDecimals; } }
protected int OrderQuantityDecimals { get { InitialiseNumericControlValues(); return mbr.orderQuantityDecimals; } }
// Internals.
protected SbmInternals Internals
{
get
{
if (internals == null) internals = new SbmInternals(UserContext);
return internals;
if (mbr.internalsSupplied != null) return mbr.internalsSupplied;
if (mbr.internals == null) mbr.internals = new SbmInternals(UserContext);
return mbr.internals;
}
}
// Session.
protected ISbmUserOrganisationContext UserContext { get; }
protected SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
public SysId AffiliateId_Owner { get { return UserContext.OrganisationAffiliateId; } }
protected SbmAccountsDfn AccountsDfn { get { return Internals.AccountsDfn; } }
protected DbUpdateInfo DbUpdateInfo { get { return Internals.DbUpdateInfo; } }
// User security profile.
public bool UserCanViewCommoditySalesFinancials() { return UserContext.SecurityProfile_Core.UserCanViewFinancials(Sbm.FinancialType.CommoditySales); }
public bool UserCanViewCommoditySupplyFinancials() { return UserContext.SecurityProfile_Core.UserCanViewFinancials(Sbm.FinancialType.CommoditySupply); }
// Managers.
protected SbmAccountMgr AccountMgr { get { return Internals.AccountMgr; } }
protected SbmCommodityMgr CommodityMgr { get { return Internals.CommodityMgr; } }
@@ -192,7 +213,15 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
protected SbmStockControlConfig StockControlConfig { get { return Internals.StockControlConfig; } }
protected SbmRequirementCostingConfig RequirementCostingConfig { get { return Internals.RequirementCostingConfig; } }
// Currencies.
protected List<TypeCodeDesc> CurrencyCodes { get { return new List<TypeCodeDesc>(currencyCodes); } }
protected List<TypeCodeDesc> CurrencyCodes
{
get
{
if (mbr.currencyCodes == null)
mbr.currencyCodes = SaReferenceDataConsole.GetReferenceDataCodes(ReferenceDataSystemCode.CurrencyCode);
return new List<TypeCodeDesc>(mbr.currencyCodes);
}
}
protected List<SaCurrency> GetCurrencies()
{
return Internals.GetCurrencies();
@@ -215,7 +244,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
// Utilities.
public List<TypeCodeDesc> GetCodesOfType(Sbm.SystemCode systemCode)
{
return systemCodeCache.GetCodesOfType(systemCode);
return Internals.GetSystemCodes(systemCode);
}
// Database utilities.
public bool TableExists(SbmDbDfn.TableIdx tableIdx)
@@ -240,7 +269,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
}
//-------------------------------------------------------------------
// Configuration console utilities.
// Session console utilities.
public bool AllowConfigOption(Sbm.ConfigOption configOption)
{
return SessionConsole.AllowOption(configOption);
@@ -320,71 +349,71 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
// Currencies.
private void PopulateCurrencies()
{
if (currencies != null) return;
if (mbr.currencies != null) return;
SaCurrency.Params prmCurrency = new SaCurrency.Params();
prmCurrency.StatusCat = SaCurrency.StatusCat.Any;
currencies = ReferenceDataConsole.GetCurrencyList(prmCurrency);
mbr.currencies = ReferenceDataConsole.GetCurrencyList(prmCurrency);
}
public SaCurrency GetDefaultCurrency()
{
PopulateCurrencies();
String currencyCode = CurrencyCodes.GetCodeForType(SaCurrencyCode.Sterling);
return currencies.Find(item => item.Code.EqualsCI(currencyCode));
return mbr.currencies.Find(item => item.Code.EqualsCI(currencyCode));
}
public SaCurrency GetCurrency(SysId currencyId)
{
PopulateCurrencies();
return currencies.Find(item => item.Id.Equals(currencyId));
return mbr.currencies.Find(item => item.Id.Equals(currencyId));
}
//-------------------------------------------------------------------
// Regions.
private void PopulateRegions()
{
if (regions != null) return;
if (mbr.regions != null) return;
SaRegion.Params prmRegion = new SaRegion.Params();
regions = ReferenceDataConsole.GetRegionList(prmRegion);
mbr.regions = ReferenceDataConsole.GetRegionList(prmRegion);
}
public SaRegion FindRegionById(SysId regionId)
{
PopulateRegions();
return regions.FindById(regionId);
return mbr.regions.FindById(regionId);
}
//-------------------------------------------------------------------
// Tax codes.
private void PopulateTaxCodes()
{
if (taxCodes != null) return;
if (mbr.taxCodes != null) return;
SaTaxCode.Params prmTaxCode = new SaTaxCode.Params();
taxCodes = ReferenceDataConsole.GetTaxCodeList(prmTaxCode);
mbr.taxCodes = ReferenceDataConsole.GetTaxCodeList(prmTaxCode);
}
public SaTaxCode FindTaxCodeById(SysId taxCodeId)
{
PopulateTaxCodes();
return taxCodes.Find(item => item.Id.Equals(taxCodeId));
return mbr.taxCodes.Find(item => item.Id.Equals(taxCodeId));
}
public SaTaxCode FindTaxCodeEffectiveOn(String taxCode, DateTime effectiveOn)
{
PopulateTaxCodes();
return taxCodes.FindByCodeEffectiveOn(taxCode, effectiveOn);
return mbr.taxCodes.FindByCodeEffectiveOn(taxCode, effectiveOn);
}
//-------------------------------------------------------------------
// Units of measure.
private void PopulateUnitsOfMeasure()
{
if (taxCodes != null) return;
if (mbr.unitsOfMeasure != null) return;
SaUnitMeasure.Params prmUnitOfMeasure = new SaUnitMeasure.Params();
prmUnitOfMeasure.StatusCat = SaUnitMeasure.StatusCat.Any;
unitsOfMeasure = ReferenceDataConsole.GetUnitMeasureList(prmUnitOfMeasure);
mbr.unitsOfMeasure = ReferenceDataConsole.GetUnitMeasureList(prmUnitOfMeasure);
}
public SaUnitMeasure FindUnitOfMeasureById(SysId uomId)
{
PopulateUnitsOfMeasure();
return unitsOfMeasure.FindById(uomId);
return mbr.unitsOfMeasure.FindById(uomId);
}
public List<SaUnitMeasure> FindUnitsOfMeasureByCategory(SaUomCategory uomCategory)
{
PopulateUnitsOfMeasure();
return unitsOfMeasure.FindAll(item => item.Category == uomCategory);
return mbr.unitsOfMeasure.FindAll(item => item.Category == uomCategory);
}
//-------------------------------------------------------------------