Files
BusinessMgr-2019/SaBusMgrStandardBase/Base/App/SbmOrganisationConfig.cs
T

182 lines
8.5 KiB
C#

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<TypeCodeDesc> assocOptions;
private List<TypeCodeDesc> contextValues;
private List<TypeCodeDesc> contextFolders;
private List<TypeCodeDesc> contextAllowOptions;
private List<TypeCodeDesc> contextCaptions;
private List<TypeCodeDesc> contextShowColumns;
private List<TypeCodeDesc> contextShowFields;
private List<TypeCodeDesc> contextFieldLabels;
private List<TypeCodeDesc> contextMinutes;
private List<TypeCodeDesc> contextPeriodDays;
private List<TypeCodeDesc> contextPeriodWeeks;
private List<TypeCodeDesc> contextNumericDecimals;
private List<TypeCodeDesc> contextCommodityTypes;
private List<TypeCodeDesc> commodityTypes;
private List<TypeCodeDesc> 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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.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.ApplicationCode.OrgOption_CommodityType);
if (commodityTypes == null) commodityTypes = SbmSystem.GetSystemCodes(Sbm.ApplicationCode.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.ApplicationCode.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;
}
//-------------------------------------------------------------------
}
//=======================================================================
}