Files
BusinessMgr-2019/SaBusMgrStandardBase/Base/Bus/SbmCommodityCustomer.cs
T

283 lines
9.3 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 SbmCommodityCustomer : SbmHierarchyItem
{
//-------------------------------------------------------------------
// Columns.
public enum Column
{
Hidden,
Pos,
Id,
// General Commodity.
Commodity_Id, Commodity_Code, Commodity_DescBrief,
Commodity_CategoryCode, Commodity_CategoryDesc,
Commodity_Status, Commodity_StatusDesc, Commodity_StatusInd,
// CommodityCustomer details.
AssocIdCustomer, Customer_Code, Customer_Name,
ProductCode,
AmountRetail, AmountRetail_Fmt, // Formatted currency amount.
CurrencyIdRetail, CurrencyIdRetail_Code, CurrencyIdRetail_Symbol,
PromotionCode, PromotionDesc,
// Common properties.
Notes,
Flag,
Status,
Status_Desc,
Status_Ind,
CreateOn_Date,
UpdateOn_Date,
}
//-------------------------------------------------------------------
/// <summary>Properties other than common.</summary>
public class DataProperties
{
public SysId CommodityId { get; set; } = new SysId();
public SysId AssocIdCustomer { get; set; } = new SysId();
public String ProductCode { get; set; } = "";
public decimal AmountRetail { get; set; } = 0.0m;
public SysId CurrencyIdRetail { get; set; } = new SysId();
public String PromotionCode { get; set; } = "";
}
// Data.
public new class Data : SacsHierarchyItem.Data
{
// Data members.
private readonly DataProperties data = new DataProperties();
// Construction.
public Data()
{
Status = DefaultStatus;
}
public SysId CommodityId
{
get { return data.CommodityId; }
set { CheckChanged(data.CommodityId, value); data.CommodityId = value; }
}
public SysId AssocIdCustomer
{
get { return data.AssocIdCustomer; }
set { CheckChanged(data.AssocIdCustomer, value); data.AssocIdCustomer = value; }
}
public String ProductCode
{
get { return data.ProductCode; }
set { CheckChanged(data.ProductCode, value); data.ProductCode = value; }
}
public decimal AmountRetail
{
get { return data.AmountRetail; }
set { CheckChanged(data.AmountRetail, value); data.AmountRetail = value; }
}
public SysId CurrencyIdRetail
{
get { return data.CurrencyIdRetail; }
set { CheckChanged(data.CurrencyIdRetail, value); data.CurrencyIdRetail = value; }
}
public String PromotionCode
{
get { return data.PromotionCode; }
set { CheckChanged(data.PromotionCode, value); data.PromotionCode = value; }
}
internal void PopulateFrom(Data data)
{
CommodityId = data.CommodityId;
AssocIdCustomer = data.AssocIdCustomer;
ProductCode = data.ProductCode;
AmountRetail = data.AmountRetail;
CurrencyIdRetail = data.CurrencyIdRetail;
PromotionCode = data.PromotionCode;
}
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 CommodityId { get; set; } = ValidValue.Valid;
public ValidValue AssocIdCustomer { get; set; } = ValidValue.Valid;
public ValidValue ProductCode { get; set; } = ValidValue.Valid;
public ValidValue AmountRetail { get; set; } = ValidValue.Valid;
public ValidValue CurrencyIdRetail { get; set; } = ValidValue.Valid;
public ValidValue PromotionCode { get; set; } = ValidValue.Valid;
}
//-------------------------------------------------------------------
// Data members.
private readonly Data data = new Data();
//-------------------------------------------------------------------
// Construction.
protected SbmCommodityCustomer(ISbmUserContext_Core userContext, SysId commodityId, SysId assocIdCustomer) : base(userContext)
{
base.SetData(data);
CommodityId = commodityId;
AssocIdCustomer = assocIdCustomer;
Status = DefaultStatus;
}
//-------------------------------------------------------------------
// CommodityCustomer status.
private static readonly List<SaStatus> commodityCustomerStatuses = 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> CommodityCustomerStatuses { get { return new List<SaStatus>(commodityCustomerStatuses); } }
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
{
switch (status)
{
case SaStatus.Current:
return DataValue.TriStateType.Green;
case SaStatus.OnHold:
return DataValue.TriStateType.Amber;
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 SysId CommodityId
{
get { return data.CommodityId; }
set { data.CommodityId = value; }
}
public SysId AssocIdCustomer
{
get { return data.AssocIdCustomer; }
set { data.AssocIdCustomer = value; }
}
public String ProductCode
{
get { return data.ProductCode; }
set { data.ProductCode = value; }
}
public decimal AmountRetail
{
get { return data.AmountRetail; }
set { data.AmountRetail = value; }
}
public SysId CurrencyIdRetail
{
get { return data.CurrencyIdRetail; }
set { data.CurrencyIdRetail = value; }
}
public String PromotionCode
{
get { return data.PromotionCode; }
set { data.PromotionCode = value; }
}
//-------------------------------------------------------------------
// A s s o c i a t e d D a t a E l e m e n t s
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// P a r a m s
//-------------------------------------------------------------------
/// <summary>Parameters - used to define the filters that should be applied to a List of Commodity Customers</summary>
// List parameters.
public enum StatusCat
{
Any,
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>();
// CommodityCustomer.
public SysId CommodityId { get; set; }
public SysId AssocIdCustomer { get; set; }
public String CommodityPartial { get; set; }
public String CustomerPartial { get; set; }
public String ProductCode { get; set; }
public String ProductCodePartial { get; set; }
public bool RestrictToActive { get; set; } = true;
/// <summary>Commodity Customer status.</summary>
public StatusCat StatusCat { get; set; } = StatusCat.NotDeleted;
// Utilities.
public List<StringPair> GetDisplayValues()
{
List<StringPair> values = new List<StringPair>();
return values;
}
}
//-------------------------------------------------------------------
}
//=======================================================================
// C o m m o d i t y C u s t o m e r D a t a L i s t
//=======================================================================
public static class SbmCommodityCustomerList
{
/// <summary>Check whether currency exists/locate in list with specified Id.</summary>
public static bool Find(this List<SbmCommodityCustomer> values, SbmCommodityCustomer commodityCustomer)
{
if (commodityCustomer == null) return false;
return (values.Find(item => item == commodityCustomer) != null);
}
public static bool FindByCommodity(this List<SbmCommodityCustomer> values, SysId commodityId)
{
if (!SysId.IsValid(commodityId)) return false;
return (values.Find(item => item.CommodityId.Equals(commodityId)) != null);
}
public static bool FindByCustomer(this List<SbmCommodityCustomer> values, SysId customerId)
{
if (!SysId.IsValid(customerId)) return false;
return (values.Find(item => item.AssocIdCustomer.Equals(customerId)) != null);
}
public static bool FindByProductCode(this List<SbmCommodityCustomer> values, String productCode)
{
if (StringUtil.IsEmpty(productCode)) return false;
return (values.Find(item => item.ProductCode.Equals(productCode)) != null);
}
}
//=======================================================================
}