Files
BusinessMgr-2019/SaBusMgrStandardBase/Base/Bus/SbmPriceSet.cs
T
2024-11-19 09:47:00 +00:00

263 lines
7.8 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;
namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
{
//=======================================================================
public abstract class SbmPriceSet : SbmHierarchyItem
{
//-------------------------------------------------------------------
// Columns.
public enum Column
{
Pos,
Id,
// PriceSet.
PriceType,
PriceType_Desc,
Reference,
Name,
CurrencyId,
Currency_Code,
Currency_Name,
HasStaticPrices_Y,
HasStaticPrices_Tick,
// Derived.
PriceCount,
// Common properties.
Notes,
Status,
Status_Desc,
Status_Ind,
CreateOn_Date,
UpdateOn_Date,
}
//-------------------------------------------------------------------
/// <summary>Properties other than common.</summary>
public class DataProperties
{
public SysId AffiliateIdOwner { get; set; } = new SysId();
public String Reference { get; set; } = "";
public Sbm.PriceType PriceType { get; set; } = Sbm.PriceType.Unknown;
public String Name { get; set; } = "";
public SysId CurrencyId { get; set; } = new SysId();
}
//-------------------------------------------------------------------
// Data.
public new class Data : SacsHierarchyItem.Data
{
// Data members.
private readonly DataProperties data = new DataProperties();
// Construction.
public Data()
{
Status = DefaultStatus;
}
// Properties.
public SysId AffiliateIdOwner
{
get { return data.AffiliateIdOwner; }
set { CheckChanged(data.AffiliateIdOwner, value); data.AffiliateIdOwner = value; }
}
public String Reference
{
get { return data.Reference; }
set { CheckChanged(data.Reference, value); data.Reference = value; }
}
public Sbm.PriceType PriceType
{
get { return data.PriceType; }
set { CheckChanged((int)data.PriceType, (int)value); data.PriceType = value; }
}
public String Name
{
get { return data.Name; }
set { CheckChanged(data.Name, value); data.Name = value; }
}
public SysId CurrencyId
{
get { return data.CurrencyId; }
set { CheckChanged(data.CurrencyId, value); data.CurrencyId = value; }
}
// Population.
internal void PopulateFrom(Data data)
{
AffiliateIdOwner = data.AffiliateIdOwner;
PriceType = data.PriceType;
Reference = data.Reference;
Name = data.Name;
CurrencyId = data.CurrencyId;
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 Reference { get; set; } = ValidValue.Valid;
public ValidValue PriceType { get; set; } = ValidValue.Valid;
public ValidValue Name { get; set; } = ValidValue.Valid;
public ValidValue CurrencyId { get; set; } = ValidValue.Valid;
}
//-------------------------------------------------------------------
// Data members.
private readonly Data data = new Data();
public static readonly Byte Flag_HasStaticPrices = 0x01;
//-------------------------------------------------------------------
// Construction.
protected SbmPriceSet(ISbmUserContext_Core userContext, SysId id, SysId affiliateIdOwner, String reference, Sbm.PriceType priceType) : base(userContext, id)
{
base.SetData(data);
AffiliateIdOwner = affiliateIdOwner;
Reference = reference;
PriceType = priceType;
Status = DefaultStatus;
}
//-------------------------------------------------------------------
// PriceSet status.
private static readonly List<SaStatus> priceSetStatuses = new List<SaStatus>()
{
SaStatus.Active,
SaStatus.Disabled,
};
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
public static List<SaStatus> ValidStatuses { get { return new List<SaStatus>(priceSetStatuses); } }
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.Cancelled:
return DataValue.TriStateType.Red;
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);
}
//-------------------------------------------------------------------
// Properties.
public SysId AffiliateIdOwner
{
get { return data.AffiliateIdOwner; }
protected set { data.AffiliateIdOwner = value; }
}
public String Reference
{
get { return data.Reference; }
protected set { data.Reference = value; }
}
public Sbm.PriceType PriceType
{
get { return data.PriceType; }
set { data.PriceType = value; }
}
public String Name
{
get { return data.Name; }
set { data.Name = value; }
}
public SysId CurrencyId
{
get { return data.CurrencyId; }
set { data.CurrencyId = value; }
}
//-------------------------------------------------------------------
// Flags.
public bool HasStaticPrices
{
get { return GetFlag(Flag_HasStaticPrices); }
set { SetFlag(Flag_HasStaticPrices, 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 bool HasPrices();
//-------------------------------------------------------------------
// P a r a m s
//-------------------------------------------------------------------
/// <summary>Parameters - used to define the filters that should be applied to a List of Price Sets</summary>
// List parameters.
public enum StatusCat
{
Any,
ActiveOnly,
NotDeleted,
DeletedOnly
}
/// <summary>
/// Item list parameters.
/// </summary>
public new class Params : SacsHierarchyItem.Params
{
// Item Ids.
public List<SysId> IdsIncluded { get; } = new List<SysId>();
public List<SysId> IdsExcluded { get; } = new List<SysId>();
// Item properties.
public Sbm.PriceType PriceType { get; set; }
public String Reference { get; set; }
public String ReferencePartial { get; set; }
public String Name { get; set; }
public String NamePartial { get; set; }
/// <summary>Price Set status.</summary>
public StatusCat StatusCat { get; set; } = StatusCat.NotDeleted;
// Utilities.
public List<StringPair> GetDisplayValues()
{
List<StringPair> values = new List<StringPair>();
return values;
}
}
//-------------------------------------------------------------------
}
//=======================================================================
// P r i c e S e t L i s t
//=======================================================================
public static class SbmSaPriceSetList
{
}
//=======================================================================
}