255 lines
8.2 KiB
C#
255 lines
8.2 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
|
|
{
|
|
//=======================================================================
|
|
// ItemSport.
|
|
//=======================================================================
|
|
public abstract class SaxItemAssociation : SacsHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Pos,
|
|
Id,
|
|
// Item From.
|
|
ItemTypeFrom,
|
|
ItemTypeFrom_Code,
|
|
ItemTypeFrom_Desc,
|
|
ItemIdFrom,
|
|
ItemFrom_Caption,
|
|
// Item To.
|
|
ItemTypeTo,
|
|
ItemTypeTo_Code,
|
|
ItemTypeTo_Desc,
|
|
ItemIdTo,
|
|
ItemTo_Caption,
|
|
// Association type.
|
|
AssociationType,
|
|
AssociationType_Code,
|
|
AssociationType_Desc,
|
|
// Associated data.
|
|
// Common.
|
|
Notes,
|
|
Flags,
|
|
Status,
|
|
Status_Desc,
|
|
Status_Ind,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public ItemId ItemIdFrom { get; set; } = new ItemId();
|
|
public ItemId ItemIdTo { get; set; } = new ItemId();
|
|
public Sax.AssociationType AssociationType { get; set; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
// Properties.
|
|
public ItemId ItemIdFrom
|
|
{
|
|
get { return data.ItemIdFrom; }
|
|
set { value = ItemId.InvalidOnNull(value); CheckChanged(data.ItemIdFrom, value); data.ItemIdFrom = value; }
|
|
}
|
|
public ItemId ItemIdTo
|
|
{
|
|
get { return data.ItemIdTo; }
|
|
set { value = ItemId.InvalidOnNull(value); CheckChanged(data.ItemIdTo, value); data.ItemIdTo = value; }
|
|
}
|
|
public Sax.AssociationType AssociationType
|
|
{
|
|
get { return data.AssociationType; }
|
|
set { CheckChanged((int)data.AssociationType, (int)value); data.AssociationType = value; }
|
|
}
|
|
// Population.
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
ItemIdFrom = data.ItemIdFrom;
|
|
ItemIdTo = data.ItemIdTo;
|
|
AssociationType = data.AssociationType;
|
|
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 ItemIdFrom { get; set; } = ValidValue.Valid;
|
|
public ValidValue ItemIdTo { get; set; } = ValidValue.Valid;
|
|
public ValidValue AssociationType { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SaxItemAssociation(SysId id, ItemId itemIdFrom, ItemId itemIdTo, Sax.AssociationType associationType) : base(id)
|
|
{
|
|
base.SetData(data);
|
|
ItemIdFrom = itemIdFrom;
|
|
ItemIdTo = itemIdTo;
|
|
AssociationType = associationType;
|
|
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.ItemAssociation, Id);
|
|
}
|
|
/// <summary>Valid 'From' item types for Association type.</summary>
|
|
public static List<Sax.DataItemType> GetValidFromItemTypesForAssociation(Sax.AssociationType associationType)
|
|
{
|
|
List<Sax.DataItemType> itemTypes = new List<Sax.DataItemType>();
|
|
switch (associationType)
|
|
{
|
|
case Sax.AssociationType.Affiliate:
|
|
case Sax.AssociationType.Partner:
|
|
itemTypes.Add(Sax.DataItemType.Organisation);
|
|
break;
|
|
}
|
|
return itemTypes;
|
|
}
|
|
/// <summary>Valid 'To' item types for Association type.</summary>
|
|
public static List<Sax.DataItemType> GetValidToItemTypesForAssociation(Sax.AssociationType associationType)
|
|
{
|
|
List<Sax.DataItemType> itemTypes = new List<Sax.DataItemType>();
|
|
switch (associationType)
|
|
{
|
|
case Sax.AssociationType.Affiliate:
|
|
case Sax.AssociationType.Partner:
|
|
itemTypes.Add(Sax.DataItemType.Organisation);
|
|
break;
|
|
}
|
|
return itemTypes;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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");
|
|
if (ItemId.IsValid(ItemIdFrom) && ItemIdFrom.Type != data.ItemIdFrom.Type && SysId.ToInt(ItemIdFrom.Id) != SysId.ToInt(data.ItemIdFrom.Id))
|
|
throw new NotSupportedException(fn + " From Item Id cannot be changed");
|
|
if (ItemId.IsValid(ItemIdTo) && ItemIdTo.Type != data.ItemIdTo.Type && SysId.ToInt(ItemIdTo.Id) != SysId.ToInt(data.ItemIdTo.Id))
|
|
throw new NotSupportedException(fn + " To Item Id cannot be changed");
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
public ItemId ItemIdFrom
|
|
{
|
|
get { return data.ItemIdFrom; }
|
|
protected set { data.ItemIdFrom = value; }
|
|
}
|
|
public ItemId ItemIdTo
|
|
{
|
|
get { return data.ItemIdTo; }
|
|
protected set { data.ItemIdTo = value; }
|
|
}
|
|
public Sax.AssociationType AssociationType
|
|
{
|
|
get { return data.AssociationType; }
|
|
protected set { data.AssociationType = 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,
|
|
ActiveOnly,
|
|
InactiveOnly,
|
|
NotDeleted,
|
|
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>Items that can be eitehr 'From' or 'To'.</summary>
|
|
public List<ItemId> ItemIdsIncluded { get; } = new List<ItemId>();
|
|
/// <summary>Items that can only be the 'From' item.</summary>
|
|
public List<ItemId> ItemIdsFromIncluded { get; } = new List<ItemId>();
|
|
/// <summary>Items that can only be the 'To' item.</summary>
|
|
public List<ItemId> ItemIdsToIncluded { get; } = new List<ItemId>();
|
|
public List<Sax.AssociationType> AssociationTypesIncluded { get; } = new List<Sax.AssociationType>();
|
|
// Common properties.
|
|
public StatusCat StatusCat { get; set; } = StatusCat.NotDeleted;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// Item list extension methods.
|
|
public static class SaxAssociationList
|
|
{
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|