254 lines
8.0 KiB
C#
254 lines
8.0 KiB
C#
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
using NPOI.SS.Formula.Functions;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static Sarand.Net.Standard.Base.Bus.SacsHierarchyItem;
|
|
|
|
namespace Saxonite.Net.Standard.Base.Bus.Reference
|
|
{
|
|
//=======================================================================
|
|
// Golf - USGA Country.
|
|
//=======================================================================
|
|
public abstract class SaxGolfUsgaCountry : SacsHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Pos,
|
|
Id,
|
|
CountryCode,
|
|
EntCountryCode,
|
|
CountryName,
|
|
ProvincesUpdateAt_Date,
|
|
// Associated data.
|
|
ProvinceCount_All,
|
|
ProvinceCount_Active,
|
|
FacilityCount_All,
|
|
FacilityCount_Active,
|
|
/// <summary>Facility population %.</summary>
|
|
FacilityPercent,
|
|
// Common.
|
|
Notes,
|
|
Flags,
|
|
Status,
|
|
Status_Desc,
|
|
Status_Ind,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public String CountryCode { get; set; } = String.Empty;
|
|
public String EntCountryCode { get; set; } = String.Empty;
|
|
public String CountryName { get; set; } = String.Empty;
|
|
public DateTime? ProvincesUpdateAt { get; set; } = null;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
// Properties.
|
|
public String CountryCode
|
|
{
|
|
get { return data.CountryCode; }
|
|
set { CheckChanged(data.CountryCode, value); data.CountryCode = value; }
|
|
}
|
|
public String EntCountryCode
|
|
{
|
|
get { return data.EntCountryCode; }
|
|
set { CheckChanged(data.EntCountryCode, value); data.EntCountryCode = value; }
|
|
}
|
|
public String CountryName
|
|
{
|
|
get { return data.CountryName; }
|
|
set { CheckChanged(data.CountryName, value); data.CountryName = value; }
|
|
}
|
|
public DateTime? ProvincesUpdateAt
|
|
{
|
|
get { return data.ProvincesUpdateAt; }
|
|
set { CheckChangedNullable(data.ProvincesUpdateAt, value); data.ProvincesUpdateAt = value; }
|
|
}
|
|
// Population.
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
CountryCode = data.CountryCode;
|
|
EntCountryCode = data.EntCountryCode;
|
|
CountryName = data.CountryName;
|
|
ProvincesUpdateAt = data.ProvincesUpdateAt;
|
|
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 CountryCode { get; set; } = ValidValue.Valid;
|
|
public ValidValue EntCountryCode { get; set; } = ValidValue.Valid;
|
|
public ValidValue CountryName { get; set; } = ValidValue.Valid;
|
|
public ValidValue ProvincesUpdateAt { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SaxGolfUsgaCountry(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.Golf_UsgaCountry, Id);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
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");
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
public String CountryCode
|
|
{
|
|
get { return data.CountryCode; }
|
|
set { data.CountryCode = value; }
|
|
}
|
|
public String EntCountryCode
|
|
{
|
|
get { return data.EntCountryCode; }
|
|
set { data.EntCountryCode = value; }
|
|
}
|
|
public String CountryName
|
|
{
|
|
get { return data.CountryName; }
|
|
set { data.CountryName = value; }
|
|
}
|
|
public DateTime? ProvincesUpdateAt
|
|
{
|
|
get { return data.ProvincesUpdateAt; }
|
|
set { data.ProvincesUpdateAt = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Flags - positions 1-16 available.
|
|
public const byte Flag_Priority = 0x01;
|
|
public bool Priority
|
|
{
|
|
get { return GetFlag(Flag_Priority); }
|
|
set { SetFlag(Flag_Priority, value); }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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
|
|
{
|
|
NotDeleted = 0,
|
|
ActiveOnly,
|
|
InactiveOnly,
|
|
Any,
|
|
DeletedOnly,
|
|
}
|
|
/// <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>();
|
|
/// <summary>Generic filter - partial country code or name.</summary>
|
|
public String CountryFilter { get; set; }
|
|
/// <summary>Restrict the results by code.</summary>
|
|
public HashSet<String> CountryCodesIncluded { get; } = new HashSet<String>(StringComparer.OrdinalIgnoreCase);
|
|
public String CountryNameFull { get; set; }
|
|
public String CountryNamePartial { get; set; }
|
|
// Flags.
|
|
public FlagState PriorityFlagState { get; set; } = FlagState.Either;
|
|
// Associated data.
|
|
public BoolState HasProvinces { get; set; } = BoolState.Either;
|
|
// Common properties.
|
|
public String NotesPartial { get; set; }
|
|
public StatusCat StatusCat { get; set; } = StatusCat.ActiveOnly;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// Item list extension methods.
|
|
public static class SaxGolfUsgaCountryList
|
|
{
|
|
//-------------------------------------------------------------------
|
|
public static SaxGolfUsgaCountry GetCountryById(this IEnumerable<SaxGolfUsgaCountry> values, SysId countryId)
|
|
{
|
|
if (!SysId.IsValid(countryId)) return null;
|
|
foreach (SaxGolfUsgaCountry country in values)
|
|
if (country.Id.Equals(countryId)) return country;
|
|
return null;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|