using Sarand.BusinessMgr.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.ItemOptions; using Sarand.Net.Standard.Base.Utils; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sarand.BusinessMgr.Net.Standard.Base.App { //======================================================================= public abstract class SbmOrganisationConfig : SacsDisposable, ISbmOrganisationConfig { //------------------------------------------------------------------- // Data members. private List assocOptions; private List contextValues; private List contextFolders; private List contextAllowOptions; private List contextCaptions; private List contextShowColumns; private List contextShowFields; private List contextFieldLabels; private List contextMinutes; private List contextPeriodDays; private List contextPeriodWeeks; private List contextNumericDecimals; private List contextCommodityTypes; private List commodityTypes; private List contextSalesLocations; //------------------------------------------------------------------- // Construction. protected SbmOrganisationConfig() { } protected override void Dispose(bool disposing) { } //------------------------------------------------------------------- // Properties. protected abstract ISbmUserOrganisationContext UserContext { get; } protected abstract SbmInstanceDataCache InstanceDataCache { get; } //------------------------------------------------------------------- // Organisation configuration. public String GetOrganisationOption(Sbm.OrganisationOption option, String context) { if (assocOptions == null) assocOptions = SbmSystem.GetSystemCodes(Sbm.SystemCode.AssociationOption); String optionName = assocOptions.GetCodeForType(option); return GetOrganisationOption(optionName, context); } public String GetOrganisationOption(String optionName, String context) { // Retrieve the requested value from the cache. return InstanceDataCache.GetOwnerOptions(UserContext).GetOptionValue(optionName, context); } public String GetOwnerOption_Value(Sbm.OrgOption_Value value) { if (contextValues == null) contextValues = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_Value); String context = contextValues.GetCodeForType(value); return GetOrganisationOption(Sbm.OrganisationOption.Value, context).Trim(); } public String GetOwnerOption_Folder(Sbm.OrgOption_Folder folder) { if (contextFolders == null) contextFolders = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_Folder); String context = contextFolders.GetCodeForType(folder); return GetOrganisationOption(Sbm.OrganisationOption.Folder, context).Trim(); } public bool GetOwnerOption_AllowOption(Sbm.OrgOption_AllowOption option) { if (contextAllowOptions == null) contextAllowOptions = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_AllowOption); String context = contextAllowOptions.GetCodeForType(option); String value = GetOrganisationOption(Sbm.OrganisationOption.AllowOption, context).Trim(); return StringUtil.ToBool(value); } public String GetOwnerOption_Caption(Sbm.OrgOption_Caption caption, String defaultValue) { if (contextCaptions == null) contextCaptions = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_Caption); String context = contextCaptions.GetCodeForType(caption); String value = GetOrganisationOption(Sbm.OrganisationOption.Caption, context).Trim(); return (!value.IsEmpty() ? value : defaultValue); } public bool GetOwnerOption_ShowField(SbmDbDfn.ColumnIdx column) { if (contextShowFields == null) contextShowFields = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_ShowField); String context = contextShowFields.GetCodeForType(column); if (context.IsEmpty()) return true; // Automatically show fields that are not in the 'Show Field' list. String value = GetOrganisationOption(Sbm.OrganisationOption.ShowField, context).Trim(); return StringUtil.ToBool(value); } public bool GetOwnerOption_ShowColumn(Sbm.OrgOption_ShowColumn column) { if (contextShowColumns == null) contextShowColumns = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_ShowColumn); String context = contextShowColumns.GetCodeForType(column); String value = GetOrganisationOption(Sbm.OrganisationOption.ShowColumn, context).Trim(); return StringUtil.ToBool(value); } public String GetOwnerOption_FieldLabel(SbmDbDfn.ColumnIdx column, String defautValue) { if (contextFieldLabels == null) contextFieldLabels = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_FieldLabel); String context = contextFieldLabels.GetCodeForType(column); String value = GetOrganisationOption(Sbm.OrganisationOption.FieldLabel, context).Trim(); return (!value.IsEmpty() ? value : defautValue); // Return default if no label defined. } public int GetOwnerOption_Minutes(Sbm.OrgOption_Minutes limit, int defautValue) { if (contextMinutes == null) contextMinutes = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_Minutes); String context = contextMinutes.GetCodeForType(limit); String value = GetOrganisationOption(Sbm.OrganisationOption.Minutes, context).Trim(); if (!value.IsEmpty()) { int iUpdateLimit = value.ToShort(); if (iUpdateLimit > 0) return iUpdateLimit; } return defautValue; } public int GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodDays limit, int defautValue) { if (contextPeriodDays == null) contextPeriodDays = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_PeriodDays); String context = contextPeriodDays.GetCodeForType(limit); String value = GetOrganisationOption(Sbm.OrganisationOption.PeriodDays, context).Trim(); if (!value.IsEmpty()) { int iUpdateLimit = value.ToShort(); if (iUpdateLimit > 0) return iUpdateLimit; } return defautValue; } public int GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodWeeks limit, int defautValue) { if (contextPeriodWeeks == null) contextPeriodWeeks = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_PeriodWeeks); String context = contextPeriodWeeks.GetCodeForType(limit); String value = GetOrganisationOption(Sbm.OrganisationOption.PeriodWeeks, context).Trim(); if (!value.IsEmpty()) { int iUpdateLimit = value.ToShort(); if (iUpdateLimit > 0) return iUpdateLimit; } return defautValue; } public int GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals decimals, int defautValue = 2) { if (contextNumericDecimals == null) contextNumericDecimals = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_NumericDecimals); String context = contextNumericDecimals.GetCodeForType(decimals); String value = GetOrganisationOption(Sbm.OrganisationOption.NumericDecimals, context).Trim(); int iNumDecimals = defautValue; if (!value.IsEmpty()) iNumDecimals = value.ToShort(); iNumDecimals = Math.Min(4, Math.Max(0, iNumDecimals)); return iNumDecimals; } public Sbm.CommodityType GetOwnerOption_CommodityType(Sbm.OrgOption_CommodityType commodityType) { if (contextCommodityTypes == null) contextCommodityTypes = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_CommodityType); if (commodityTypes == null) commodityTypes = SbmSystem.GetSystemCodes(Sbm.SystemCode.CommodityType); String context = contextCommodityTypes.GetCodeForType(commodityType); String value = GetOrganisationOption(Sbm.OrganisationOption.CommodityType, context).Trim(); Sbm.CommodityType eCmdType = (Sbm.CommodityType)commodityTypes.GetTypeForCode(value); return eCmdType; } public SysId GetOwnerOption_StockLocation(Sbm.OrgOption_StockLocation stockLocation) { if (contextSalesLocations == null) contextSalesLocations = SbmSystem.GetSystemCodes(Sbm.SystemCode.OrgOption_StockLocation); String context = contextSalesLocations.GetCodeForType(stockLocation); String value = GetOrganisationOption(Sbm.OrganisationOption.SalesLocation, context).Trim(); SysId idLoc = new SysId(); if (!StringUtil.IsEmpty(value)) idLoc = new SysId(StringUtil.ToInt(value)); return idLoc; } //------------------------------------------------------------------- } //======================================================================= }