348 lines
11 KiB
C#
348 lines
11 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
|
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;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
|
|
{
|
|
//=======================================================================
|
|
public abstract class SbmContainer : SbmHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Hidden,
|
|
Pos,
|
|
Id,
|
|
// Container.
|
|
//OwnerName,
|
|
Category_Desc,
|
|
Type_Desc,
|
|
Reference,
|
|
DescBrief,
|
|
TagId,
|
|
AssIdSupplier,
|
|
Supplier_Name,
|
|
AssIdCustomer,
|
|
Customer_Name,
|
|
Expected,
|
|
CreateOn,
|
|
UpdateOn,
|
|
ItemCount,
|
|
MovementCount,
|
|
// Common properties.
|
|
Notes,
|
|
Flags,
|
|
Status,
|
|
Status_Ind,
|
|
Status_Desc,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public SysId AffiliateIdOwner { get; set; } = new SysId();
|
|
public Sbm.ContainerCategory ContainerCategory { get; set; } = Sbm.ContainerCategory.Unknown;
|
|
public Sbm.ContainerType ContainerType { get; set; } = Sbm.ContainerType.Unknown;
|
|
public String Reference { get; set; } = "";
|
|
public String DescBrief { get; set; } = "";
|
|
public String TagId { get; set; } = "";
|
|
public SysId AssIdSupplier { get; set; } = new SysId();
|
|
public SysId AssIdCustomer { get; set; } = new SysId();
|
|
public DateTime Expected { get; set; } = DateTime.MinValue;
|
|
}
|
|
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
public SysId AffiliateIdOwner
|
|
{
|
|
get { return data.AffiliateIdOwner; }
|
|
set { CheckChanged(data.AffiliateIdOwner, value); data.AffiliateIdOwner = value; }
|
|
}
|
|
public Sbm.ContainerCategory ContainerCategory
|
|
{
|
|
get { return data.ContainerCategory; }
|
|
set { CheckChanged((int)data.ContainerCategory, (int)value); data.ContainerCategory = value; }
|
|
}
|
|
public Sbm.ContainerType ContainerType
|
|
{
|
|
get { return data.ContainerType; }
|
|
set { CheckChanged((int)data.ContainerType, (int)value); data.ContainerType = value; }
|
|
}
|
|
public String Reference
|
|
{
|
|
get { return data.Reference; }
|
|
set { CheckChanged(data.Reference, value); data.Reference = value; }
|
|
}
|
|
public String DescBrief
|
|
{
|
|
get { return data.DescBrief; }
|
|
set { CheckChanged(data.DescBrief, value); data.DescBrief = value; }
|
|
}
|
|
public String TagId
|
|
{
|
|
get { return data.TagId; }
|
|
set { CheckChanged(data.TagId, value); data.TagId = value; }
|
|
}
|
|
public SysId AssIdSupplier
|
|
{
|
|
get { return data.AssIdSupplier; }
|
|
set { CheckChanged(data.AssIdSupplier, value); data.AssIdSupplier = value; }
|
|
}
|
|
public SysId AssIdCustomer
|
|
{
|
|
get { return data.AssIdCustomer; }
|
|
set { CheckChanged(data.AssIdCustomer, value); data.AssIdCustomer = value; }
|
|
}
|
|
public DateTime Expected
|
|
{
|
|
get { return data.Expected; }
|
|
set { CheckChanged(data.Expected, value); data.Expected = value; }
|
|
}
|
|
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
AffiliateIdOwner = data.AffiliateIdOwner;
|
|
ContainerCategory = data.ContainerCategory;
|
|
ContainerType = data.ContainerType;
|
|
Reference = data.Reference;
|
|
DescBrief = data.DescBrief;
|
|
TagId = data.TagId;
|
|
AssIdSupplier = data.AssIdSupplier;
|
|
AssIdCustomer = data.AssIdCustomer;
|
|
Expected = data.Expected;
|
|
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 AffiliateIdOwner { get; set; } = ValidValue.Valid;
|
|
public ValidValue ContainerCategory { get; set; } = ValidValue.Valid;
|
|
public ValidValue ContainerType { get; set; } = ValidValue.Valid;
|
|
public ValidValue Reference { get; set; } = ValidValue.Valid;
|
|
public ValidValue DescBrief { get; set; } = ValidValue.Valid;
|
|
public ValidValue TagId { get; set; } = ValidValue.Valid;
|
|
public ValidValue AssIdSupplier { get; set; } = ValidValue.Valid;
|
|
public ValidValue AssIdCustomer { get; set; } = ValidValue.Valid;
|
|
public ValidValue Expected { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SbmContainer(SysId id, SysId affiliateIdOwner, Sbm.ContainerCategory containerCategory, Sbm.ContainerType containerType) : base(id)
|
|
{
|
|
base.SetData(data);
|
|
AffiliateIdOwner = affiliateIdOwner;
|
|
ContainerCategory = containerCategory;
|
|
ContainerType = containerType;
|
|
Status = DefaultStatus;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Container status.
|
|
private static readonly List<SaStatus> containerStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Provisional,
|
|
SaStatus.Awaiting,
|
|
SaStatus.Active,
|
|
SaStatus.Actioned,
|
|
SaStatus.Cancelled,
|
|
};
|
|
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
|
public static List<SaStatus> ContainerStatuses { get { return new List<SaStatus>(containerStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case SaStatus.Actioned:
|
|
return DataValue.TriStateType.Green;
|
|
case SaStatus.Provisional:
|
|
return DataValue.TriStateType.Amber;
|
|
case SaStatus.Awaiting:
|
|
return DataValue.TriStateType.Amber;
|
|
case SaStatus.Cancelled:
|
|
return DataValue.TriStateType.Red;
|
|
case SaStatus.Deleted:
|
|
return DataValue.TriStateType.Purple;
|
|
}
|
|
return DataValue.TriStateType.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
public SbmItemId GetItemId()
|
|
{
|
|
return new SbmItemId(Sbm.ItemType.Container, 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");
|
|
// Populate individual properties to ensure that 'Changed' indicator is kept up to date.
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Attributes.
|
|
public SysId AffiliateIdOwner
|
|
{
|
|
get { return data.AffiliateIdOwner; }
|
|
set { data.AffiliateIdOwner = value; }
|
|
}
|
|
public Sbm.ContainerCategory ContainerCategory
|
|
{
|
|
get { return data.ContainerCategory; }
|
|
set { data.ContainerCategory = value; }
|
|
}
|
|
public Sbm.ContainerType ContainerType
|
|
{
|
|
get { return data.ContainerType; }
|
|
set { data.ContainerType = value; }
|
|
}
|
|
public String Reference
|
|
{
|
|
get { return data.Reference; }
|
|
set { data.Reference = value; }
|
|
}
|
|
public String DescBrief
|
|
{
|
|
get { return data.DescBrief; }
|
|
set { data.DescBrief = value; }
|
|
}
|
|
public String TagId
|
|
{
|
|
get { return data.TagId; }
|
|
set { data.TagId = value; }
|
|
}
|
|
public SysId AssIdSupplier
|
|
{
|
|
get { return data.AssIdSupplier; }
|
|
set { data.AssIdSupplier = value; }
|
|
}
|
|
public SysId AssIdCustomer
|
|
{
|
|
get { return data.AssIdCustomer; }
|
|
set { data.AssIdCustomer = value; }
|
|
}
|
|
public DateTime Expected
|
|
{
|
|
get { return data.Expected; }
|
|
set { data.Expected = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// P a r a m s
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Parameters - used to define the filters that should be applied to a List of Container</summary>
|
|
// List parameters.
|
|
public enum StatusCat
|
|
{
|
|
Any,
|
|
ActiveOnly,
|
|
InactiveOnly,
|
|
NotDeleted,
|
|
DeletedOnly
|
|
}
|
|
/// <summary>
|
|
/// Item list parameters.
|
|
/// </summary>
|
|
public new class Params : SacsHierarchyItem.Params
|
|
{
|
|
// Construction.
|
|
public Params() { }
|
|
public Params(SbmContainerItem.Params prmContainerItem)
|
|
{
|
|
IdsIncluded = prmContainerItem.IdsIncluded;
|
|
IdsExcluded = prmContainerItem.IdsExcluded;
|
|
ContainerCategory = prmContainerItem.ContainerCategory;
|
|
ContainerType = prmContainerItem.ContainerType;
|
|
Reference = prmContainerItem.ContainerReference;
|
|
TagId = prmContainerItem.ContainerTagId;
|
|
ReferencePartial = prmContainerItem.ContainerReferencePartial;
|
|
TagIdPartial = prmContainerItem.ContainerTagIdPartial;
|
|
ProductCodePartial = prmContainerItem.ProductCodePartial;
|
|
ExpectedFrom = prmContainerItem.ContainerExpectedFrom;
|
|
ExpectedTo = prmContainerItem.ContainerExpectedTo;
|
|
ContainerStatus = prmContainerItem.ContainerStatus;
|
|
HasItems = prmContainerItem.ContainerHasItems;
|
|
}
|
|
// List filtering.
|
|
public HashSet<SysId> IdsIncluded { get; } = new HashSet<SysId>();
|
|
public HashSet<SysId> IdsExcluded { get; } = new HashSet<SysId>();
|
|
// Container.
|
|
//public SysId AffiliateIdOwner { get; set; }
|
|
public Sbm.ContainerCategory ContainerCategory { get; set; } = Sbm.ContainerCategory.Any;
|
|
public Sbm.ContainerType ContainerType { get; set; } = Sbm.ContainerType.Any;
|
|
public String Reference { get; set; }
|
|
public String ReferencePartial { get; set; }
|
|
//public String DescBrief { get; set; }
|
|
public String TagId { get; set; }
|
|
public String TagIdPartial { get; set; }
|
|
public SysId AssIdSupplier { get; set; }
|
|
public String SupplierName { get; set; }
|
|
public SysId AssIdCustomer { get; set; }
|
|
public String CustomerName { get; set; }
|
|
public String ProductCode { get; set; }
|
|
public String ProductCodePartial { get; set; }
|
|
public DateTime ExpectedFrom { get; set; }
|
|
public DateTime ExpectedTo { get; set; }
|
|
public bool HasItems { get; set; }
|
|
public SaStatus ContainerStatus { get; set; }
|
|
/// <summary>Container status.</summary>
|
|
public StatusCat StatusCat { get; set; } = StatusCat.NotDeleted;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// C o n t a i n e r D a t a L i s t
|
|
//=======================================================================
|
|
public static class SbmContainerList
|
|
{
|
|
/// <summary>Check whether item exists/locate in list with specified Id.</summary>
|
|
public static bool Find(this List<SbmContainer> values, SbmContainer container)
|
|
{
|
|
if (container == null) return false;
|
|
return values.Any(item => item == container);
|
|
}
|
|
public static bool FindById(this List<SbmContainer> values, SysId containerId)
|
|
{
|
|
if (!SysId.IsValid(containerId)) return false;
|
|
return values.Any(item => item.Id.Equals(containerId));
|
|
}
|
|
}
|
|
//=======================================================================
|
|
} |