using System; using System.Linq.Expressions; namespace InABox.Core { // EntityForm no longer is an IOneToMany, so any subclasses must add this if they want to. public interface IEntityForm { string Description { get; set; } } [Caption("Digital Forms")] public abstract class EntityForm : Entity, IRemotable, IPersistent, ISequenceable, IStringAutoIncrement, IEntityForm, IDigitalFormInstance, ILicense where TThis : EntityForm where TParent : Entity where TParentLink : IEntityLink, new() { public Expression> AutoIncrementField() => x => x.Number; public abstract string AutoIncrementPrefix(); public virtual string AutoIncrementFormat() => "{0:D6}"; public Filter? AutoIncrementFilter() => null; [EditorSequence(1)] [CodeEditor(Editable = Editable.Disabled)] public String Number { get; set; } [EditorSequence(2)] public string Description { get; set; } = ""; [NullEditor] [EntityRelationship(DeleteAction.Cascade)] public virtual TParentLink Parent { get; set; } [NullEditor] [Obsolete("Being Replaced by Form")] public QAFormLink QAForm { get; set; } [EditorSequence(1)] [EntityRelationship(DeleteAction.Cascade)] public DigitalFormLink Form { get; set; } [NullEditor] [Obsolete("Being Replaced by FormData", true)] public string QAData { get; set; } [NullEditor] public string FormData { get; set; } [NullEditor] public string? BlobData { get; set; } [NullEditor] [Obsolete("Being Replaced by FormCompleted", true)] public DateTime QACompleted { get; set; } [EditorSequence(2)] [Caption("Started")] [DateTimeEditor] public DateTime FormStarted { get; set; } = DateTime.MinValue; [EditorSequence(3)] [Caption("Completed")] [DateTimeEditor] public DateTime FormCompleted { get; set; } [EditorSequence(4)] [Caption("Processed")] [DateTimeEditor] public DateTime FormProcessed { get; set; } [EditorSequence(5)] [Caption("Cancelled")] [DateTimeEditor] public DateTime FormCancelled { get; set; } [NullEditor] [Obsolete("Being Replaced by FormCompletedBy")] public UserLink QACompletedBy { get; set; } [EditorSequence(3)] [Caption("User")] public UserLink FormCompletedBy { get; set; } [NullEditor] [Obsolete("Replaced with Status", true)] public bool Processed { get; set; } = false; [NullEditor] public Location Location { get; set; } public IDigitalFormDataModel CreateDataModel(Entity? parent = null) { var t = typeof(DigitalFormDataModel<,,>).MakeGenericType(typeof(TParent), typeof(TParentLink), GetType()); if (parent != null) return (Activator.CreateInstance(t, parent, this) as IDigitalFormDataModel)!; return (Activator.CreateInstance(t, Parent.ID, ID) as IDigitalFormDataModel)!; } public Guid ParentID() { return Parent.ID; } public Type ParentType() => typeof(TParent); [DurationEditor(Visible = Visible.Optional, Editable = Editable.Hidden)] public TimeSpan FormOpen { get; set; } = TimeSpan.Zero; [NullEditor] public long Sequence { get; set; } } }