290 lines
8.9 KiB
C#
290 lines
8.9 KiB
C#
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Saxonite.Net.Standard.Base.Bus
|
|
{
|
|
//=======================================================================
|
|
// Region.
|
|
//=======================================================================
|
|
public abstract class SaxRegion : SacsHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Pos,
|
|
Id,
|
|
RegionType,
|
|
RegionType_Desc,
|
|
CountryIso2Code,
|
|
Name,
|
|
// Parent region.
|
|
RegionIdParent,
|
|
Parent_Name,
|
|
Parent_RegionType,
|
|
Parent_RegionType_Desc,
|
|
// Associated data.
|
|
ChildRegionCount,
|
|
// Common.
|
|
Notes,
|
|
Flags,
|
|
Status,
|
|
Status_Desc,
|
|
Status_Ind,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public Sax.RegionType RegionType { get; set; } = Sax.RegionType.Unknown;
|
|
public String CountryIso2Code { get; set; } = String.Empty;
|
|
public String Name { get; set; } = String.Empty;
|
|
public Decimal Latitude { get; set; }
|
|
public Decimal Longitude { get; set; }
|
|
public SysId RegionIdParent { get; set; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
// Properties.
|
|
public Sax.RegionType RegionType
|
|
{
|
|
get { return data.RegionType; }
|
|
set { CheckChangedEnum(data.RegionType, value); data.RegionType = value; }
|
|
}
|
|
public String CountryIso2Code
|
|
{
|
|
get { return data.CountryIso2Code; }
|
|
set { CheckChanged(data.CountryIso2Code, value); data.CountryIso2Code = value; }
|
|
}
|
|
public String Name
|
|
{
|
|
get { return data.Name; }
|
|
set { CheckChanged(data.Name, value); data.Name = value; }
|
|
}
|
|
public Decimal Latitude
|
|
{
|
|
get { return data.Latitude; }
|
|
set { CheckChanged(data.Latitude, value); data.Latitude = value; }
|
|
}
|
|
public Decimal Longitude
|
|
{
|
|
get { return data.Longitude; }
|
|
set { CheckChanged(data.Longitude, value); data.Longitude = value; }
|
|
}
|
|
public SysId RegionIdParent
|
|
{
|
|
get { return data.RegionIdParent; }
|
|
set { CheckChanged(data.RegionIdParent, value); data.RegionIdParent = value; }
|
|
}
|
|
// Population.
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
RegionType = data.RegionType;
|
|
CountryIso2Code = data.CountryIso2Code;
|
|
Name = data.Name;
|
|
Latitude = data.Latitude;
|
|
Longitude = data.Longitude;
|
|
RegionIdParent = data.RegionIdParent;
|
|
base.PopulateFrom(data);
|
|
}
|
|
public Data Clone()
|
|
{
|
|
Data data = new Data();
|
|
data.PopulateFrom(this);
|
|
return data;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Error field - identify properties with validation error.
|
|
public new class ErrField : SacsHierarchyItem.ErrField
|
|
{
|
|
// Identifies the field that has invalid data.
|
|
public ValidValue RegionType { get; set; } = ValidValue.Valid;
|
|
public ValidValue CountryIso2Code { get; set; } = ValidValue.Valid;
|
|
public ValidValue Name { get; set; } = ValidValue.Valid;
|
|
public ValidValue Latitude { get; set; } = ValidValue.Valid;
|
|
public ValidValue Longitude { get; set; } = ValidValue.Valid;
|
|
public ValidValue RegionIdParent { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SaxRegion(SysId id) : base(id)
|
|
{
|
|
base.SetData(data);
|
|
Status = DefaultStatus;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Status.
|
|
private static readonly List<SaStatus> validStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Active,
|
|
SaStatus.Inactive,
|
|
SaStatus.Deleted,
|
|
};
|
|
public static SaStatus DefaultStatus { get { return SaStatus.Active; } }
|
|
public static List<SaStatus> ValidStatuses { get { return new List<SaStatus>(validStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
|
{
|
|
if (status == SaStatus.Active) return DataValue.TriStateType.Green;
|
|
if (status == SaStatus.Inactive) return DataValue.TriStateType.Red;
|
|
if (status == SaStatus.Deleted) return DataValue.TriStateType.Purple;
|
|
return DataValue.TriStateType.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
public ItemId GetItemId()
|
|
{
|
|
return new ItemId((short)Sax.DataItemType.Region, Id);
|
|
}
|
|
public static List<Sax.RegionType> GetValidParentRegionTypes(Sax.RegionType regionType)
|
|
{
|
|
List<Sax.RegionType> parentRegionTypes = new List<Sax.RegionType>();
|
|
switch (regionType)
|
|
{
|
|
case Sax.RegionType.Continent:
|
|
break;
|
|
case Sax.RegionType.SubContinent:
|
|
parentRegionTypes.Add(Sax.RegionType.Continent);
|
|
break;
|
|
case Sax.RegionType.Country:
|
|
parentRegionTypes.Add(Sax.RegionType.Continent);
|
|
parentRegionTypes.Add(Sax.RegionType.SubContinent);
|
|
break;
|
|
}
|
|
return parentRegionTypes;
|
|
}
|
|
public static bool IsValidParentRegionType(Sax.RegionType regionType, Sax.RegionType parentRegionType)
|
|
{
|
|
return GetValidParentRegionTypes(regionType).Contains(parentRegionType);
|
|
}
|
|
public bool IsValidParentRegionType(Sax.RegionType parentRegionType)
|
|
{
|
|
return IsValidParentRegionType(RegionType, parentRegionType);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public Data GetData() { return data.Clone(); }
|
|
public void SetData(Data data)
|
|
{
|
|
String fn = GetType().Name + ".SetData";
|
|
// Properties that cannot be changed if previously specified.
|
|
if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id))
|
|
throw new NotSupportedException(fn + " Id cannot be changed");
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
public Sax.RegionType RegionType
|
|
{
|
|
get { return data.RegionType; }
|
|
set { data.RegionType = value; }
|
|
}
|
|
public String CountryIso2Code
|
|
{
|
|
get { return data.CountryIso2Code; }
|
|
set { data.CountryIso2Code = value; }
|
|
}
|
|
public String Name
|
|
{
|
|
get { return data.Name; }
|
|
set { data.Name = value; }
|
|
}
|
|
public Decimal Latitude
|
|
{
|
|
get { return data.Latitude; }
|
|
set { data.Latitude = value; }
|
|
}
|
|
public Decimal Longitude
|
|
{
|
|
get { return data.Longitude; }
|
|
set { data.Longitude = value; }
|
|
}
|
|
public SysId RegionIdParent
|
|
{
|
|
get { return data.RegionIdParent; }
|
|
set { data.RegionIdParent = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Flags - positions 1-16 available.
|
|
|
|
//-------------------------------------------------------------------
|
|
// A s s o c i a t e d D a t a
|
|
//-------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------
|
|
// P a r a m s
|
|
//-------------------------------------------------------------------
|
|
// List parameters.
|
|
public enum StatusCat
|
|
{
|
|
Any,
|
|
NotDeleted,
|
|
ActiveOnly,
|
|
InctiveOnly,
|
|
}
|
|
/// <summary>
|
|
/// Item list parameters.
|
|
/// </summary>
|
|
public new class Params : SacsHierarchyItem.Params
|
|
{
|
|
// List filtering.
|
|
public List<SysId> IdsIncluded { get; } = new List<SysId>();
|
|
public List<SysId> IdsExcluded { get; } = new List<SysId>();
|
|
public List<SysId> ParentRegionIdsIncluded { get; } = new List<SysId>();
|
|
public Sax.RegionType RegionType { get; set; }
|
|
public List<String> CountryIso2CodesIncluded { get; } = new List<String>();
|
|
public List<String> CountryIso2CodesExcluded { get; } = new List<String>();
|
|
/// <summary>Generic filter - partial region name, iso2 code or other matching value (tbd).</summary>
|
|
public String RegionFilter { get; set; }
|
|
public String NameFull { get; set; }
|
|
public String NamePartial { get; set; }
|
|
public String NotesPartial { get; set; }
|
|
public StatusCat StatusCat { get; set; } = StatusCat.ActiveOnly;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// Item list extension methods.
|
|
public static class SaxRegionList
|
|
{
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Extract the first Region in list with the specified Id.
|
|
/// </summary>
|
|
public static SaxRegion GetRegionById(this List<SaxRegion> values, SysId regionId)
|
|
{
|
|
return values.Find(item => item.Id.Equals(regionId));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|