258 lines
7.3 KiB
C#
258 lines
7.3 KiB
C#
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static Sarand.BusinessMgr.Net.Standard.Base.App.SbmSysParamCache;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Bus.Control
|
|
{
|
|
//=======================================================================
|
|
public class SbmcItemParam : SbmcHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Hidden,
|
|
Pos,
|
|
Id,
|
|
// Item.
|
|
ItemType,
|
|
ItemType_Caption,
|
|
ItemId,
|
|
Item_Caption,
|
|
// Param.
|
|
Context,
|
|
Name,
|
|
Value,
|
|
// Common.
|
|
Notes,
|
|
Flags,
|
|
Flag,
|
|
Status,
|
|
Status_Ind,
|
|
Status_Desc,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public ItemId ItemId { get; set; } = new ItemId();
|
|
public String Context { get; set; } = "";
|
|
public String Name { get; set; } = "";
|
|
public String Value { get; set; } = "";
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = SbmcItemParam.DefaultStatus;
|
|
}
|
|
public ItemId ItemId
|
|
{
|
|
get { return data.ItemId; }
|
|
set { CheckChanged(data.ItemId, value); data.ItemId = value ?? new ItemId(); }
|
|
}
|
|
public String Context
|
|
{
|
|
get { return data.Context; }
|
|
set { CheckChanged(data.Context, value); data.Context = value; }
|
|
}
|
|
public String Name
|
|
{
|
|
get { return data.Name; }
|
|
set { CheckChanged(data.Name, value); data.Name = value; }
|
|
}
|
|
public String Value
|
|
{
|
|
get { return data.Value; }
|
|
set { CheckChanged(data.Value, value); data.Value = value; }
|
|
}
|
|
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
this.ItemId = data.ItemId;
|
|
Context = data.Context;
|
|
Name = data.Name;
|
|
Value = data.Value;
|
|
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 ItemId { get; set; } = ValidValue.Valid;
|
|
public ValidValue Name { get; set; } = ValidValue.Valid;
|
|
public ValidValue Context { get; set; } = ValidValue.Valid;
|
|
public ValidValue Value { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
public static readonly Byte Flag_Password = 0x01;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SbmcItemParam(SysId id, ItemId itemId) : base(id)
|
|
{
|
|
base.SetData(data);
|
|
ItemId = itemId;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item status.
|
|
private static readonly List<SaStatus> ownerStatuses = 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>(ownerStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case SaStatus.Active:
|
|
return DataValue.TriStateType.Green;
|
|
case SaStatus.OnHold:
|
|
return DataValue.TriStateType.Amber;
|
|
case SaStatus.Inactive:
|
|
return DataValue.TriStateType.Red;
|
|
case SaStatus.Deleted:
|
|
return DataValue.TriStateType.Purple;
|
|
}
|
|
return DataValue.TriStateType.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
public static List<SbmcHierarchyItem.ItemType> ValidItemTypes =>
|
|
new List<ItemType>()
|
|
{
|
|
ItemType.Owner,
|
|
ItemType.Repository
|
|
};
|
|
|
|
public static bool IsPasswordValue(String paramContext, String paramName, ushort flags)
|
|
{
|
|
if (GetFlag(flags, Flag_Password)) return true;
|
|
if (paramContext.ContainsCI("password") || paramName.ContainsCI("password")) return true;
|
|
if (paramContext.ContainsCI("pword") || paramName.ContainsCI("pword")) return true;
|
|
if (paramContext.ContainsCI("secret") || paramName.ContainsCI("secret")) return true;
|
|
return false;
|
|
}
|
|
public bool IsPasswordValue()
|
|
{
|
|
return IsPasswordValue(Context, Name, Flags);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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 (ItemId.IsValid(ItemId) && (ItemId.Type != data.ItemId.Type || SysId.ToInt(ItemId.Id) != SysId.ToInt(data.ItemId.Id)))
|
|
throw new NotSupportedException($"{SysUtil.Fn} Item Id cannot be changed");
|
|
// Populate individual properties to ensure that 'Changed' indicator is kept up to date.
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
|
|
// ItemParam.
|
|
|
|
public ItemId ItemId
|
|
{
|
|
get { return data.ItemId; }
|
|
protected set { data.ItemId = value; }
|
|
}
|
|
public String Context
|
|
{
|
|
get { return data.Context; }
|
|
set { data.Context = value; }
|
|
}
|
|
public String Name
|
|
{
|
|
get { return data.Name; }
|
|
set { data.Name = value; }
|
|
}
|
|
public String Value
|
|
{
|
|
get { return data.Value; }
|
|
set { data.Value = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Flags.
|
|
public bool IsPrimary
|
|
{
|
|
get { return GetFlag(Flag_Password); }
|
|
set { SetFlag(Flag_Password, value); }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Associated data.
|
|
|
|
//-------------------------------------------------------------------
|
|
// List parameters.
|
|
|
|
/// <summary> Status filter options.</summary>
|
|
public enum StatusCat
|
|
{
|
|
Any,
|
|
ActiveOnly,
|
|
InactiveOnly,
|
|
NotDeleted,
|
|
DeletedOnly,
|
|
}
|
|
|
|
/// <summary>Parameters - used to define the filters that should be applied to a list of items.</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>();
|
|
public HashSet<ItemId> ItemIdsIncluded { get; } = new HashSet<ItemId>();
|
|
/// <summary>Generic search value - name, contact, email, phone etc.</summary>
|
|
public String Search { get; set; }
|
|
public String NotesPartial { get; set; }
|
|
/// <summary>Contact status.</summary>
|
|
public StatusCat StatusCat { get; set; } = StatusCat.NotDeleted;
|
|
// Table aliases.
|
|
public String Alias_Item_Owner { get; set; }
|
|
public String Alias_Item_Repository { get; set; }
|
|
}
|
|
}
|
|
//=======================================================================
|
|
// Item list.
|
|
public static class SbmcItemParamList
|
|
{
|
|
}
|
|
//=======================================================================
|
|
}
|