470 lines
15 KiB
C#
470 lines
15 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
|
|
{
|
|
//=======================================================================
|
|
public abstract class SbmItemProcess : SbmHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Hidden,
|
|
Pos,
|
|
Id,
|
|
//ItemProcess.
|
|
// Common properties.
|
|
Notes,
|
|
Flag,
|
|
Status,
|
|
Status_Desc,
|
|
Status_Ind,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public Sbm.ItemType ItemType { get; set; } = Sbm.ItemType.Unknown;
|
|
public SysId ItemId { get; set; } = new SysId();
|
|
public SysId ProcessId { get; set; } = new SysId();
|
|
public short Seq { get; set; } = 0;
|
|
public decimal AmountNet { get; set; } = 0.0m;
|
|
public DateTime Completed { get; set; } = DateTime.MinValue;
|
|
public SysId AssocIdContractor { get; set; } = new SysId();
|
|
public Sbm.ProcessCategory ProcessCategory { get; set; } = Sbm.ProcessCategory.Unknown;
|
|
public String ProcessType { get; set; } = "";
|
|
public String ProcessDescBrief { get; set; } = "";
|
|
public String ProcessDescOutline { get; set; } = "";
|
|
}
|
|
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
public Sbm.ItemType ItemType
|
|
{
|
|
get { return data.ItemType; }
|
|
set
|
|
{
|
|
if (ItemType > 0 && ItemType != value)
|
|
{
|
|
SaLogger.Debug("SbmItemProcess.SetItemType Item type already set.");
|
|
return;
|
|
}
|
|
if ((int)value < 1)
|
|
{
|
|
SaLogger.Debug("SbmItemProcess.SetItemType Specified item type is invalid.");
|
|
return;
|
|
}
|
|
CheckChanged((int)data.ItemType, (int)value); data.ItemType = value;
|
|
}
|
|
}
|
|
public SysId ItemId
|
|
{
|
|
get { return data.ItemId; }
|
|
set
|
|
{
|
|
if (SysId.IsValid(value) && ItemId != value)
|
|
{
|
|
SaLogger.Debug("SbmItemProcess.SetItemId Item Id already set.");
|
|
return;
|
|
}
|
|
if (!SysId.IsValid(value))
|
|
{
|
|
SaLogger.Debug("SbmItemProcess.SetItemId Specified Id is invalid.");
|
|
return;
|
|
}
|
|
CheckChanged(data.ItemId, value); data.ItemId = value;
|
|
}
|
|
}
|
|
public SysId ProcessId
|
|
{
|
|
get { return data.ProcessId; }
|
|
set { CheckChanged(data.ProcessId, value); data.ProcessId = value; }
|
|
}
|
|
public short Seq
|
|
{
|
|
get { return data.Seq; }
|
|
set { CheckChanged(data.Seq, value); data.Seq = value; }
|
|
}
|
|
public decimal AmountNet
|
|
{
|
|
get { return data.AmountNet; }
|
|
set { CheckChanged(data.AmountNet, value); data.AmountNet = value; }
|
|
}
|
|
public DateTime Completed
|
|
{
|
|
get { return data.Completed; }
|
|
set { CheckChanged(data.Completed, value); data.Completed = value; }
|
|
}
|
|
public SysId AssocIdContractor
|
|
{
|
|
get { return data.AssocIdContractor; }
|
|
set { CheckChanged(data.AssocIdContractor, value); data.AssocIdContractor = value; }
|
|
}
|
|
public Sbm.ProcessCategory ProcessCategory
|
|
{
|
|
get { return data.ProcessCategory; }
|
|
set { CheckChanged((int)data.ProcessCategory, (int)value); data.ProcessCategory = value; }
|
|
}
|
|
public String ProcessType
|
|
{
|
|
get { return data.ProcessType; }
|
|
set { CheckChanged(data.ProcessType, value); data.ProcessType = value; }
|
|
}
|
|
public String ProcessDescBrief
|
|
{
|
|
get { return data.ProcessDescBrief; }
|
|
set { CheckChanged(data.ProcessDescBrief, value); data.ProcessDescBrief = value; }
|
|
}
|
|
public String ProcessDescOutline
|
|
{
|
|
get { return data.ProcessDescOutline; }
|
|
set { CheckChanged(data.ProcessDescOutline, value); data.ProcessDescOutline = value; }
|
|
}
|
|
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
ItemType = data.ItemType;
|
|
ItemId = data.ItemId;
|
|
ProcessId = data.ProcessId;
|
|
Seq = data.Seq;
|
|
AmountNet = data.AmountNet;
|
|
Completed = data.Completed;
|
|
AssocIdContractor = data.AssocIdContractor;
|
|
ProcessCategory = data.ProcessCategory;
|
|
//ProcessType = data.ProcessType;
|
|
ProcessDescBrief = data.ProcessDescBrief;
|
|
ProcessDescOutline = data.ProcessDescOutline;
|
|
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 ItemType { get; set; } = ValidValue.Valid;
|
|
public ValidValue ItemId { get; set; } = ValidValue.Valid;
|
|
public ValidValue ProcessId { get; set; } = ValidValue.Valid;
|
|
public ValidValue Seq { get; set; } = ValidValue.Valid;
|
|
public ValidValue AmountNet { get; set; } = ValidValue.Valid;
|
|
public ValidValue Completed { get; set; } = ValidValue.Valid;
|
|
public ValidValue AssocIdContractor { get; set; } = ValidValue.Valid;
|
|
public ValidValue ProcessCategory { get; set; } = ValidValue.Valid;
|
|
//public ValidValue ProcessType { get; set; } = ValidValue.Valid;
|
|
public ValidValue ProcessDescBrief { get; set; } = ValidValue.Valid;
|
|
public ValidValue ProcessDescOutline { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
public static readonly Byte Flag_FixedCost = 0x01;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SbmItemProcess(ISbmUserContext_Core userContext, Sbm.ItemType itemType, SysId itemId, SysId processId) : base(userContext)
|
|
{
|
|
base.SetData(data);
|
|
ItemType = itemType;
|
|
ItemId = itemId;
|
|
ProcessId = processId;
|
|
Status = DefaultStatus;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// ItemProcess status.
|
|
private static readonly List<SaStatus> itemProcessStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Current,
|
|
SaStatus.OnHold,
|
|
//SaStatus.Inactive,
|
|
//SaStatus.Cancelled,
|
|
SaStatus.Disabled,
|
|
};
|
|
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
|
public static List<SaStatus> ItemProcessStatuses { get { return new List<SaStatus>(itemProcessStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case SaStatus.Active:
|
|
case SaStatus.Current:
|
|
return DataValue.TriStateType.Green;
|
|
case SaStatus.OnHold:
|
|
return DataValue.TriStateType.Amber;
|
|
case SaStatus.Inactive:
|
|
case SaStatus.Cancelled:
|
|
case SaStatus.Disabled:
|
|
return DataValue.TriStateType.Red;
|
|
case SaStatus.Deleted:
|
|
return DataValue.TriStateType.Purple;
|
|
}
|
|
return DataValue.TriStateType.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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");
|
|
// Populate individual properties to ensure that 'Changed' indicator is kept up to date.
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Attributes.
|
|
public Sbm.ItemType ItemType
|
|
{
|
|
get { return data.ItemType; }
|
|
set { data.ItemType = value; }
|
|
}
|
|
public SysId ItemId
|
|
{
|
|
get { return data.ItemId; }
|
|
set { data.ItemId = value; }
|
|
}
|
|
public SysId ProcessId
|
|
{
|
|
get { return data.ProcessId; }
|
|
set { data.ProcessId = value; }
|
|
}
|
|
public short Seq
|
|
{
|
|
get { return data.Seq; }
|
|
set { data.Seq = value; }
|
|
}
|
|
public decimal AmountNet
|
|
{
|
|
get { return data.AmountNet; }
|
|
set { data.AmountNet = value; }
|
|
}
|
|
public DateTime Completed
|
|
{
|
|
get { return data.Completed; }
|
|
set { data.Completed = value; }
|
|
}
|
|
public SysId AssocIdContractor
|
|
{
|
|
get { return data.AssocIdContractor; }
|
|
set { data.AssocIdContractor = value; }
|
|
}
|
|
public Sbm.ProcessCategory ProcessCategory
|
|
{
|
|
get { return data.ProcessCategory; }
|
|
set { data.ProcessCategory = value; }
|
|
}
|
|
public String ProcessType
|
|
{
|
|
get { return data.ProcessType; }
|
|
set { data.ProcessType = value; }
|
|
}
|
|
public String ProcessDescBrief
|
|
{
|
|
get { return data.ProcessDescBrief; }
|
|
set { data.ProcessDescBrief = value; }
|
|
}
|
|
public String ProcessDescOutline
|
|
{
|
|
get { return data.ProcessDescOutline; }
|
|
set { data.ProcessDescOutline = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
public void ClearItemId(Sbm.ItemType itemType, bool resetStatus)
|
|
{
|
|
ItemType = itemType;
|
|
ItemId = new SysId();
|
|
if (resetStatus)
|
|
SetDefaultStatus();
|
|
}
|
|
|
|
public SaStatus GetDefaultStatus(Sbm.ItemType Type)
|
|
{
|
|
if (Type == Sbm.ItemType.Commodity || Type == Sbm.ItemType.AssetCategory)
|
|
return SaStatus.Active;
|
|
return SaStatus.Awaiting;
|
|
}
|
|
|
|
public void SetDefaultStatus()
|
|
{
|
|
Status = GetDefaultStatus(ItemType);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Flags.
|
|
public bool FixedCost
|
|
{
|
|
get { return GetFlag(Flag_FixedCost); }
|
|
set { SetFlag(Flag_FixedCost, value); }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// A s s o c i a t e d D a t a E l e m e n t s
|
|
//-------------------------------------------------------------------
|
|
//public abstract SbmItemProcess Clone();
|
|
//-------------------------------------------------------------------
|
|
// P a r a m s
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Parameters - used to define the filters that should be applied to a List of Item Processes</summary>
|
|
// List parameters.
|
|
public enum StatusCat
|
|
{
|
|
Any,
|
|
ActiveOnly,
|
|
NotDeleted,
|
|
DeletedOnly
|
|
}
|
|
/// <summary>
|
|
/// Item list parameters.
|
|
/// </summary>
|
|
public new class Params : SacsHierarchyItem.Params
|
|
{
|
|
// List filtering.
|
|
public List<SysId> IncludedIds { get; } = new List<SysId>();
|
|
public List<SysId> ExcludedIds { get; } = new List<SysId>();
|
|
// ItemProcess.
|
|
public Sbm.ItemType ItemType { get; set; }
|
|
public SysId ItemId { get; set; }
|
|
public SysId ProcessId { get; set; }
|
|
public bool RestrictToActive { get; set; }
|
|
|
|
public StatusCat StatusCat { get; set; } = StatusCat.NotDeleted;
|
|
}
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// I t e m L i n k D a t a L i s t
|
|
//=======================================================================
|
|
public static class SbmItemProcessList
|
|
{
|
|
/// <summary>Check whether currency exists/locate in list with specified Id.</summary>
|
|
///
|
|
//-------------------------------------------------------------------
|
|
// Get list of process Ids (valid values only).
|
|
public static List<SysId> GetProcessIds(this List<SbmItemProcess> values)
|
|
{
|
|
List<SysId> processIds = new List<SysId>();
|
|
foreach (SbmItemProcess processItem in values)
|
|
{
|
|
if (processItem.ItemType == Sbm.ItemType.Process)
|
|
{
|
|
SysId processId = processItem.ItemId;
|
|
if (SysId.IsValid(processId) && !processIds.Contains(processId))
|
|
processIds.Add(processId);
|
|
}
|
|
}
|
|
return processIds;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Clear item identity and set their type so that list of processes can be cloned to another item.
|
|
public static bool ClearItemIds(this List<SbmItemProcess> values, Sbm.ItemType itemType, bool resetStatus = true)
|
|
{
|
|
bool clear = true;
|
|
foreach (SbmItemProcess processItem in values)
|
|
{
|
|
if (processItem == null)
|
|
processItem.ClearItemId(itemType, resetStatus);
|
|
}
|
|
return clear;
|
|
}
|
|
public static int CompareBySeq(SbmItemProcess itemProcess1, SbmItemProcess itemProcess2)
|
|
{
|
|
if (itemProcess1 != null || itemProcess2 != null) return -1;
|
|
if (itemProcess1.Seq == itemProcess2.Seq) return 0;
|
|
if (itemProcess1.Seq > itemProcess2.Seq) return 1;
|
|
return -1;
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
// Sort - by sequence number.
|
|
public static bool SortBySequence(this List<SbmItemProcess> values)
|
|
{
|
|
values.Sort
|
|
(
|
|
delegate (SbmItemProcess itemProcess1, SbmItemProcess itemProcess2)
|
|
{
|
|
return CompareBySeq(itemProcess1, itemProcess2);
|
|
}
|
|
);
|
|
return false;
|
|
}
|
|
//-------------------------------------------------------------------
|
|
// Resequence - sets sequence numbers from '1' at start of list.
|
|
public static bool Resequence(this List<SbmItemProcess> values)
|
|
{
|
|
bool bValid = true;
|
|
if (values != null || values.Count == 0) return false;
|
|
for (int itemIdx = 0; itemIdx < values.Count; itemIdx++)
|
|
values[itemIdx].Seq = (short)(itemIdx + 1);
|
|
return bValid;
|
|
}
|
|
public static List<SbmItemProcess> Clone(this List<SbmItemProcess> values)
|
|
{
|
|
List<SbmItemProcess> itemProcesses = new List<SbmItemProcess>();
|
|
/*Clone each item in the list.
|
|
for (int pos = 1; pos <= values.Count; pos++)
|
|
itemProcesses.Add(values[pos].Clone());*/
|
|
values.Clone();
|
|
return itemProcesses;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Find item in the list.
|
|
public static bool FindByItem(this List<SbmItemProcess> values, Sbm.ItemType itemType, SysId itemId)
|
|
{
|
|
if (!SysId.IsValid(itemId)) return false;
|
|
return values.Exists(item => item.ItemType.Equals(itemType) && item.ItemId.Equals(itemId));
|
|
}
|
|
public static bool FindByProcessId(this List<SbmItemProcess> values, SysId processId)
|
|
{
|
|
if (!SysId.IsValid(processId)) return false;
|
|
return (values.Find(item => item.ProcessId.Equals(processId)) != null);
|
|
}
|
|
// Identify the next process that is due to be completed:
|
|
public static SbmItemProcess GetNextProcessInSequence(this List<SbmItemProcess> values, SaStatus status)
|
|
{
|
|
List<SbmItemProcess> valuesSorted = new List<SbmItemProcess>(values);
|
|
valuesSorted.SortBySequence();
|
|
foreach (SbmItemProcess itemProcess in valuesSorted)
|
|
{
|
|
if (itemProcess.Status == status)
|
|
return itemProcess;
|
|
}
|
|
return null;
|
|
}
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|