272 lines
8.4 KiB
C#
272 lines
8.4 KiB
C#
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using static Sarand.Net.Standard.Base.Bus.SacsHierarchyItem;
|
|
|
|
namespace Saxonite.Net.Standard.Base.Bus.Support
|
|
{
|
|
//=======================================================================
|
|
// UserReport.
|
|
//=======================================================================
|
|
public abstract class SaxUserReport : SacsHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Pos,
|
|
Id,
|
|
UserAccountId,
|
|
ReportType,
|
|
ReportType_Desc,
|
|
Title,
|
|
Report,
|
|
RecordedOn,
|
|
// Associated data.
|
|
// Common.
|
|
Notes,
|
|
Flags,
|
|
Status,
|
|
Status_Desc,
|
|
Status_Ind,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public SysId UserAccountId { get; set; }
|
|
public Sax.UserReportType ReportType { get; set; }
|
|
public String Title { get; set; } = String.Empty;
|
|
public String Report { get; set; } = String.Empty;
|
|
public DateTime RecordedOn { get; set; }
|
|
public String ReportData { get; set; } = String.Empty;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
// Properties.
|
|
public SysId UserAccountId
|
|
{
|
|
get { return data.UserAccountId; }
|
|
set { CheckChanged(data.UserAccountId, value); data.UserAccountId = value; }
|
|
}
|
|
public Sax.UserReportType ReportType
|
|
{
|
|
get { return data.ReportType; }
|
|
set { CheckChanged((short)data.ReportType, (short)value); data.ReportType = value; }
|
|
}
|
|
public String Title
|
|
{
|
|
get { return data.Title; }
|
|
set { CheckChanged(data.Title, value); data.Title = value; }
|
|
}
|
|
public String Report
|
|
{
|
|
get { return data.Report; }
|
|
set { CheckChanged(data.Report, value); data.Report = value; }
|
|
}
|
|
public DateTime RecordedOn
|
|
{
|
|
get { return data.RecordedOn; }
|
|
set { CheckChanged(data.RecordedOn, value); data.RecordedOn = value; }
|
|
}
|
|
public String ReportData
|
|
{
|
|
get { return data.ReportData; }
|
|
set { CheckChanged(data.ReportData, value); data.ReportData = value; }
|
|
}
|
|
// Population.
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
UserAccountId = data.UserAccountId;
|
|
ReportType = data.ReportType;
|
|
Title = data.Title;
|
|
Report = data.Report;
|
|
RecordedOn = data.RecordedOn;
|
|
ReportData = data.ReportData;
|
|
base.PopulateFrom(data);
|
|
}
|
|
public Data Clone()
|
|
{
|
|
Data data = new Data();
|
|
data.PopulateFrom(this);
|
|
return data;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Error field - identify properties with validation error.
|
|
public new class ErrField : SacsHierarchyItem.ErrField
|
|
{
|
|
// Identifies the field that has invalid data.
|
|
public ValidValue UserAccountId { get; set; } = ValidValue.Valid;
|
|
public ValidValue ReportType { get; set; } = ValidValue.Valid;
|
|
public ValidValue Title { get; set; } = ValidValue.Valid;
|
|
public ValidValue Report { get; set; } = ValidValue.Valid;
|
|
public ValidValue RecordedOn { get; set; } = ValidValue.Valid;
|
|
public ValidValue ReportData { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SaxUserReport(SysId id, SysId userAccountId) : base(id)
|
|
{
|
|
base.SetData(data);
|
|
this.UserAccountId = userAccountId;
|
|
Status = DefaultStatus;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Status.
|
|
private static readonly List<SaStatus> validStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Preparation,
|
|
SaStatus.InProgress,
|
|
SaStatus.Cancelled,
|
|
SaStatus.Closed,
|
|
SaStatus.Deleted,
|
|
};
|
|
public static SaStatus DefaultStatus { get { return SaStatus.Preparation; } }
|
|
public static List<SaStatus> ValidStatuses { get { return new List<SaStatus>(validStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
|
{
|
|
if (status == SaStatus.Preparation) return DataValue.TriStateType.Yellow;
|
|
if (status == SaStatus.InProgress) return DataValue.TriStateType.Green;
|
|
if (status == SaStatus.Completed) return DataValue.TriStateType.Blue;
|
|
if (status == SaStatus.Cancelled) return DataValue.TriStateType.Red;
|
|
if (status == SaStatus.Deleted) return DataValue.TriStateType.Purple;
|
|
return DataValue.TriStateType.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
public ItemId GetItemId()
|
|
{
|
|
return new ItemId((short)Sax.DataItemType.UserReport, 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");
|
|
if (SysId.IsValid(UserAccountId) && SysId.ToInt(UserAccountId) != SysId.ToInt(data.UserAccountId))
|
|
throw new NotSupportedException($"{SysUtil.Fn} UserAccountId cannot be changed");
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
public SysId UserAccountId
|
|
{
|
|
get { return data.UserAccountId; }
|
|
protected set { data.UserAccountId = value; }
|
|
}
|
|
public Sax.UserReportType ReportType
|
|
{
|
|
get { return data.ReportType; }
|
|
set { data.ReportType = value; }
|
|
}
|
|
public String Title
|
|
{
|
|
get { return data.Title; }
|
|
set { data.Title = value; }
|
|
}
|
|
public String Report
|
|
{
|
|
get { return data.Report; }
|
|
set { data.Report = value; }
|
|
}
|
|
public DateTime RecordedOn
|
|
{
|
|
get { return data.RecordedOn; }
|
|
set { data.RecordedOn = value; }
|
|
}
|
|
public String ReportData
|
|
{
|
|
get { return data.ReportData; }
|
|
set { data.ReportData = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Flags - positions 1-16 available.
|
|
|
|
//-------------------------------------------------------------------
|
|
// A s s o c i a t e d D a t a
|
|
//-------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------
|
|
// P a r a m s
|
|
//-------------------------------------------------------------------
|
|
// List parameters.
|
|
public enum StatusCat
|
|
{
|
|
Any,
|
|
Preparation,
|
|
Open,
|
|
Completed,
|
|
Cancelled,
|
|
Closed,
|
|
NotDeleted,
|
|
Deleted,
|
|
}
|
|
/// <summary>
|
|
/// Item list parameters.
|
|
/// </summary>
|
|
public new class Params : SacsHierarchyItem.Params
|
|
{
|
|
// List filtering.
|
|
public List<SysId> IdsIncluded { get; } = new List<SysId>();
|
|
public List<SysId> IdsExcluded { get; } = new List<SysId>();
|
|
public List<SysId> UserAccountIdsIncluded { get; } = new List<SysId>();
|
|
public List<Sax.UserReportType> ReportTypesIncluded { get; } = new List<Sax.UserReportType>();
|
|
/// <summary>Generic filter - caption, report, or other matching value (tbd).</summary>
|
|
public String UserReportFilter { get; set; }
|
|
public String TitlePartial { get; set; }
|
|
public String ReportPartial { get; set; }
|
|
// Common properties.
|
|
public String NotesPartial { get; set; }
|
|
public StatusCat StatusCat { get; set; } = StatusCat.Open;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// Item list extension methods.
|
|
public static class SaxUserReportList
|
|
{
|
|
//-------------------------------------------------------------------
|
|
public static SaxUserReport GetUserReportById(this IEnumerable<SaxUserReport> values, SysId userReportId)
|
|
{
|
|
if (!SysId.IsValid(userReportId)) return null;
|
|
foreach (SaxUserReport userReport in values)
|
|
if (userReport.Id.Equals(userReportId)) return userReport;
|
|
return null;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|