Extract paired business object projects
This commit is contained in:
@@ -0,0 +1,301 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
|
||||
namespace Sarand.Net.Standard.Base.ReferenceData
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SaCurrency : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Hidden,
|
||||
Pos,
|
||||
Id,
|
||||
// Currency.
|
||||
Code,
|
||||
Name,
|
||||
PrimaryCurrencyId,
|
||||
PrimaryCurrency_Code,
|
||||
PrimaryCurrency_Name,
|
||||
Division,
|
||||
RegionId,
|
||||
Region_Name,
|
||||
Symbol,
|
||||
SuffixSymbol_Y,
|
||||
SuffixSymbol_Tick,
|
||||
IncludeSpace_Y,
|
||||
IncludeSpace_Tick,
|
||||
Decimals,
|
||||
// Common properties.
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Properties other than common.</summary>
|
||||
public class DataProperties
|
||||
{
|
||||
public String Code { get; set; } = "";
|
||||
public String Name { get; set; } = "";
|
||||
public SysId CurrencyIdPrimary { get; set; } = new SysId();
|
||||
public String Division { get; set; } = "";
|
||||
public SysId RegionId { get; set; } = new SysId();
|
||||
public String Symbol { get; set; } = "";
|
||||
public bool SuffixSymbol { get; set; } = false;
|
||||
public bool IncludeSpace { get; set; } = false;
|
||||
public ushort Decimals { get; set; } = 0;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
// Data members.
|
||||
private readonly DataProperties data = new DataProperties();
|
||||
// Construction.
|
||||
public Data ()
|
||||
{
|
||||
// Currency has no status.
|
||||
}
|
||||
// Properties.
|
||||
public String Code
|
||||
{
|
||||
get { return data.Code; }
|
||||
set { CheckChanged(data.Code, value); data.Code = value; }
|
||||
}
|
||||
public String Name
|
||||
{
|
||||
get { return data.Name; }
|
||||
set { CheckChanged(data.Name, value); data.Name = value; }
|
||||
}
|
||||
public SysId CurrencyIdPrimary
|
||||
{
|
||||
get { return data.CurrencyIdPrimary; }
|
||||
set { CheckChanged(data.CurrencyIdPrimary, value); data.CurrencyIdPrimary = value; }
|
||||
}
|
||||
public String Division
|
||||
{
|
||||
get { return data.Division; }
|
||||
set { CheckChanged(data.Division, value); data.Division = value; }
|
||||
}
|
||||
public SysId RegionId
|
||||
{
|
||||
get { return data.RegionId; }
|
||||
set { CheckChanged(data.RegionId, value); data.RegionId = value; }
|
||||
}
|
||||
public String Symbol
|
||||
{
|
||||
get { return data.Symbol; }
|
||||
set { CheckChanged(data.Symbol, value); data.Symbol = value; }
|
||||
}
|
||||
public bool SuffixSymbol
|
||||
{
|
||||
get { return data.SuffixSymbol; }
|
||||
set { CheckChanged(data.SuffixSymbol, value); data.SuffixSymbol = value; }
|
||||
}
|
||||
public bool IncludeSpace
|
||||
{
|
||||
get { return data.IncludeSpace; }
|
||||
set { CheckChanged(data.IncludeSpace, value); data.IncludeSpace = value; }
|
||||
}
|
||||
public ushort Decimals
|
||||
{
|
||||
get { return data.Decimals; }
|
||||
set { CheckChanged(data.Decimals, value); data.Decimals = value; }
|
||||
}
|
||||
|
||||
internal void PopulateFrom (Data data)
|
||||
{
|
||||
Code = data.Code;
|
||||
Name = data.Name;
|
||||
CurrencyIdPrimary = data.CurrencyIdPrimary;
|
||||
Division = data.Division;
|
||||
RegionId = data.RegionId;
|
||||
Symbol = data.Symbol;
|
||||
SuffixSymbol = data.SuffixSymbol;
|
||||
IncludeSpace = data.IncludeSpace;
|
||||
Decimals = data.Decimals;
|
||||
base.PopulateFrom(data);
|
||||
}
|
||||
public Data Clone ()
|
||||
{
|
||||
Data data = new Data();
|
||||
data.PopulateFrom(this);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public new class ErrField : SacsHierarchyItem.ErrField
|
||||
{
|
||||
// Identifies the field that has invalid data.
|
||||
public ValidValue Code { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Name { get; set; } = ValidValue.Valid;
|
||||
public ValidValue CurrencyIdPrimary { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Division { get; set; } = ValidValue.Valid;
|
||||
public ValidValue RegionId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Symbol { get; set; } = ValidValue.Valid;
|
||||
public ValidValue SuffixSymbol { get; set; } = ValidValue.Valid;
|
||||
public ValidValue IncludeSpace { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Decimals { get; set; } = ValidValue.Valid;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Static construction.
|
||||
static SaCurrency ()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SaCurrency (SysId id) : base(id)
|
||||
{
|
||||
base.SetData(data);
|
||||
// Currency has no status.
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Statuses - not applicable for currencies.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
public String FormatAmount (decimal amount)
|
||||
{
|
||||
return FormatAmount(Symbol, SuffixSymbol, IncludeSpace, amount, Decimals);
|
||||
}
|
||||
public static String FormatAmount (String symbol, bool suffix, bool includeSpace, decimal amount, ushort decimals)
|
||||
{
|
||||
String format = "N" + Math.Max(0, Math.Min(4, (int)decimals));
|
||||
String amountFmt = amount.ToString(format);
|
||||
if (suffix) amountFmt += (includeSpace ? " " : "") + symbol;
|
||||
else amountFmt = symbol + (includeSpace ? " " : "") + amountFmt;
|
||||
return amountFmt;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data.
|
||||
public Data GetData () { return data.Clone(); }
|
||||
public void SetData (Data data)
|
||||
{
|
||||
// Properties that cannot be changed if previously specified.
|
||||
if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id))
|
||||
throw new NotSupportedException($"{SysUtil.Fn} Id cannot be changed");
|
||||
// Populate individual properties to ensure that 'Changed' indicator is kept up to date.
|
||||
this.data.PopulateFrom(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public String Code
|
||||
{
|
||||
get { return data.Code; }
|
||||
set { data.Code = value; }
|
||||
}
|
||||
public String Name
|
||||
{
|
||||
get { return data.Name; }
|
||||
set { data.Name = value; }
|
||||
}
|
||||
public SysId CurrencyIdPrimary
|
||||
{
|
||||
get { return data.CurrencyIdPrimary; }
|
||||
set { data.CurrencyIdPrimary = value; }
|
||||
}
|
||||
public String Division
|
||||
{
|
||||
get { return data.Division; }
|
||||
set { data.Division = value; }
|
||||
}
|
||||
public SysId RegionId
|
||||
{
|
||||
get { return data.RegionId; }
|
||||
set { data.RegionId = value; }
|
||||
}
|
||||
public String Symbol
|
||||
{
|
||||
get { return data.Symbol; }
|
||||
set { data.Symbol = value; }
|
||||
}
|
||||
public bool SuffixSymbol
|
||||
{
|
||||
get { return data.SuffixSymbol; }
|
||||
set { data.SuffixSymbol = value; }
|
||||
}
|
||||
public bool IncludeSpace
|
||||
{
|
||||
get { return data.IncludeSpace; }
|
||||
set { data.IncludeSpace = value; }
|
||||
}
|
||||
public ushort Decimals
|
||||
{
|
||||
get { return data.Decimals; }
|
||||
set { data.Decimals = value; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// A s s o c i a t e d D a t a E l e m e n t s
|
||||
//-------------------------------------------------------------------
|
||||
public abstract bool HasDependentCurrencies ();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// P a r a m s
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Parameters - used to define the filters that should be applied to a List of Currencies
|
||||
/// </summary>
|
||||
// List parameters.
|
||||
public enum StatusCat
|
||||
{
|
||||
Any,
|
||||
}
|
||||
/// <summary>
|
||||
/// Item list parameters.
|
||||
/// </summary>
|
||||
public new class Params : SacsHierarchyItem.Params
|
||||
{
|
||||
// List filtering.
|
||||
public HashSet<SysId> IdsIncluded { get; } = new HashSet<SysId>();
|
||||
public HashSet<SysId> IdsExcluded { get; } = new HashSet<SysId>();
|
||||
// Currency.
|
||||
public String Code { get; set; }
|
||||
public String CodePartial { get; set; }
|
||||
public String Name { get; set; }
|
||||
public String NamePartial { get; set; }
|
||||
public SysId RegionId { get; set; }
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// C u r r e n c y D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SaCurrencyList
|
||||
{
|
||||
public static SaCurrency FindById (this List<SaCurrency> values, SysId currencyId)
|
||||
{
|
||||
if (!SysId.IsValid(currencyId)) return null;
|
||||
return values.Find(item => item.Id.Equals(currencyId));
|
||||
}
|
||||
public static SaCurrency FindByCode (this List<SaCurrency> values, String currencyCode)
|
||||
{
|
||||
if (StringUtil.IsEmpty(currencyCode)) return null;
|
||||
return values.Find(item => item.Code.EqualsCI(currencyCode));
|
||||
}
|
||||
public static SaCurrency FindBySymbol (this List<SaCurrency> values, String currencySymbol)
|
||||
{
|
||||
if (StringUtil.IsEmpty(currencySymbol)) return null;
|
||||
return values.Find(item => item.Symbol.EqualsCI(currencySymbol));
|
||||
}
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user