287 lines
9.7 KiB
C#
287 lines
9.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
|
|
namespace Sarand.Net.Standard.Base.Interfaces
|
|
{
|
|
//=======================================================================
|
|
public class SaInterface : SacsHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Pos = 0,
|
|
// Interface.
|
|
Id,
|
|
Context,
|
|
Category,
|
|
Category_Desc,
|
|
Type,
|
|
Type_Desc,
|
|
Code,
|
|
Caption,
|
|
Active_Y,
|
|
Active_TickCross,
|
|
Active_Ind,
|
|
// Derived properties.
|
|
Process_Count,
|
|
DataItem_Count,
|
|
// Common properties.
|
|
Notes,
|
|
Status,
|
|
Status_Desc,
|
|
Status_Ind,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public String Context { get; set; } = String.Empty;
|
|
public SaInterfaceCategory Category { get; set; } = SaInterfaceCategory.Unknown;
|
|
public short Type { get; set; } = 0;
|
|
public String Code { get; set; } = String.Empty;
|
|
public String Caption { get; set; } = String.Empty;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data ()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
// Properties.
|
|
public String Context
|
|
{
|
|
get { return data.Context; }
|
|
set { CheckChanged(data.Context, value); data.Context = value; }
|
|
}
|
|
public SaInterfaceCategory Category
|
|
{
|
|
get { return data.Category; }
|
|
set { CheckChanged((int)data.Category, (int)value); data.Category = value; }
|
|
}
|
|
public short Type
|
|
{
|
|
get { return data.Type; }
|
|
set { CheckChanged(data.Type, value); data.Type = value; }
|
|
}
|
|
public String Code
|
|
{
|
|
get { return data.Code; }
|
|
set { CheckChanged(data.Code, value); data.Code = value; }
|
|
}
|
|
public String Caption
|
|
{
|
|
get { return data.Caption; }
|
|
set { CheckChanged(data.Caption, value); data.Caption = value; }
|
|
}
|
|
// Flags.
|
|
public bool Active
|
|
{
|
|
get { return GetFlag(Flag_Active); }
|
|
set { SetFlag(Flag_Active, value); }
|
|
}
|
|
// Population.
|
|
internal void PopulateFrom (Data data)
|
|
{
|
|
Context = data.Context;
|
|
Category = data.Category;
|
|
Type = data.Type;
|
|
Code = data.Code;
|
|
Caption = data.Caption;
|
|
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 Context { get; set; } = ValidValue.Valid;
|
|
public ValidValue Category { get; set; } = ValidValue.Valid;
|
|
public ValidValue Type { get; set; } = ValidValue.Valid;
|
|
public ValidValue Code { get; set; } = ValidValue.Valid;
|
|
public ValidValue Caption { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
// Flags.
|
|
public static readonly Byte Flag_Active = 0x01;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SaInterface (SysId id, String context, SaInterfaceCategory category, short type) :
|
|
base(id)
|
|
{
|
|
base.SetData(data);
|
|
Context = context;
|
|
Category = category;
|
|
Type = type;
|
|
Status = DefaultStatus;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Statuses.
|
|
private static readonly List<SaStatus> validStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Active,
|
|
};
|
|
public static SaStatus DefaultStatus { get { return ActiveStatus; } }
|
|
public static SaStatus ActiveStatus { get { return SaStatus.Active; } }
|
|
public static List<SaStatus> ValidStatuses { get { return new List<SaStatus>(validStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState (SaStatus status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case SaStatus.Active:
|
|
return Core.DataValue.TriStateType.Green;
|
|
case SaStatus.Deleted:
|
|
return Core.DataValue.TriStateType.Purple;
|
|
}
|
|
return Core.DataValue.TriStateType.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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");
|
|
if (!StringUtil.IsEmpty(Context) && !Context.Equals(data.Context))
|
|
throw new NotSupportedException($"{SysUtil.Fn} Context cannot be changed");
|
|
if ((int)Category >= 0 && (int)Category != (int)data.Category)
|
|
throw new NotSupportedException($"{SysUtil.Fn} Category cannot be changed");
|
|
if (Type >= 0 && Type != data.Type)
|
|
throw new NotSupportedException($"{SysUtil.Fn} Type cannot be changed");
|
|
// Populate individual properties to ensure that 'Changed' indicator is kept up to date.
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
public String Context
|
|
{
|
|
get { return data.Context; }
|
|
protected set { data.Context = value; }
|
|
}
|
|
public SaInterfaceCategory Category
|
|
{
|
|
get { return data.Category; }
|
|
protected set { data.Category = value; }
|
|
}
|
|
public short Type
|
|
{
|
|
get { return data.Type; }
|
|
protected set { data.Type = value; }
|
|
}
|
|
public String Code
|
|
{
|
|
get { return data.Code; }
|
|
set { data.Code = value; }
|
|
}
|
|
public String Caption
|
|
{
|
|
get { return data.Caption; }
|
|
set { data.Caption = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Flags.
|
|
public bool Active
|
|
{
|
|
get { return GetFlag(Flag_Active); }
|
|
set { SetFlag(Flag_Active, value); }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// List parameters.
|
|
public enum StatusCat
|
|
{
|
|
Any,
|
|
/// <summary>NB Interface activity controlled by flag rather than status.</summary>
|
|
ActiveOnly,
|
|
}
|
|
/// <summary>
|
|
/// Item list parameters.
|
|
/// </summary>
|
|
public new class Params : SacsHierarchyItem.Params
|
|
{
|
|
public List<SysId> IncludedIds { get; } = new List<SysId>();
|
|
public List<SysId> ExcludedIds { get; } = new List<SysId>();
|
|
public String Context { get; set; }
|
|
public SaInterfaceCategory InterfaceCategory { get; set; } = SaInterfaceCategory.Unknown;
|
|
public List<short> IncludedInterfaceTypes { get; } = new List<short>();
|
|
/// <summary>Exact code match</summary>
|
|
public String Code { get; set; }
|
|
public String CaptionPartial { get; set; }
|
|
/// <summary>Text to parially match code or caption</summary>
|
|
public String InterfaceText { get; set; }
|
|
/// <summary>Active flag</summary>
|
|
public bool ActiveOnly { get; set; } = true;
|
|
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// L i s t
|
|
//=======================================================================
|
|
public static class SaInterfaceList
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// E x i s t s
|
|
//-------------------------------------------------------------------
|
|
public static bool ExistsByContextCategoryType (this List<SaInterface> interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType)
|
|
{
|
|
return interfaces.Exists(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory && item.Type == interfaceType);
|
|
}
|
|
public static bool ExistsByContextCategoryType (this List<SaInterface.Data> interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType)
|
|
{
|
|
return interfaces.Exists(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory && item.Type == interfaceType);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// F i n d A l l
|
|
//-------------------------------------------------------------------
|
|
public static List<SaInterface> FindAllByContextCategory (this List<SaInterface> interfaces, String context, SaInterfaceCategory interfaceCategory)
|
|
{
|
|
return interfaces.FindAll(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory);
|
|
}
|
|
public static List<SaInterface.Data> FindAllByContextCategory (this List<SaInterface.Data> interfaces, String context, SaInterfaceCategory interfaceCategory)
|
|
{
|
|
return interfaces.FindAll(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory);
|
|
}
|
|
public static List<SaInterface> FindAllByContextCategoryType (this List<SaInterface> interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType)
|
|
{
|
|
return interfaces.FindAll(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory && item.Type == interfaceType);
|
|
}
|
|
public static List<SaInterface.Data> FindAllByContextCategoryType (this List<SaInterface.Data> interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType)
|
|
{
|
|
return interfaces.FindAll(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory && item.Type == interfaceType);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|