EntityForm.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Linq.Expressions;
  3. namespace InABox.Core
  4. {
  5. // EntityForm no longer is an IOneToMany, so any subclasses must add this if they want to.
  6. public interface IEntityForm
  7. {
  8. string Description { get; set; }
  9. }
  10. [Caption("Digital Forms")]
  11. public abstract class EntityForm<TParent, TParentLink, TThis> : Entity, IRemotable, IPersistent, ISequenceable, IStringAutoIncrement<TThis>,
  12. IEntityForm,
  13. IDigitalFormInstance<TParentLink>, ILicense<DigitalFormsLicense>
  14. where TThis : EntityForm<TParent,TParentLink, TThis>
  15. where TParent : Entity
  16. where TParentLink : BaseObject, IEntityLink<TParent>, new()
  17. {
  18. public Expression<Func<TThis, string>> AutoIncrementField() => x => x.Number;
  19. public abstract string AutoIncrementPrefix();
  20. public virtual string AutoIncrementFormat() => "{0:D6}";
  21. public Filter<TThis>? AutoIncrementFilter() => null;
  22. [EditorSequence(1)]
  23. [CodeEditor(Editable = Editable.Disabled)]
  24. public String Number { get; set; }
  25. [EditorSequence(2)]
  26. public string Description { get; set; } = "";
  27. [NullEditor]
  28. [EntityRelationship(DeleteAction.Cascade)]
  29. public virtual TParentLink Parent => InitializeField(ref _tParentLink, nameof(TParentLink));
  30. private TParentLink _tParentLink;
  31. [NullEditor]
  32. [Obsolete("Being Replaced by Form")]
  33. public QAFormLink QAForm => InitializeField(ref _qAForm, nameof(QAForm));
  34. private QAFormLink _qAForm;
  35. [EditorSequence(1)]
  36. [EntityRelationship(DeleteAction.Cascade)]
  37. public DigitalFormLink Form => InitializeField(ref _form, nameof(Form));
  38. private DigitalFormLink _form;
  39. [NullEditor]
  40. [Obsolete("Being Replaced by FormData", true)]
  41. public string QAData { get; set; }
  42. [NullEditor]
  43. public string FormData { get; set; }
  44. [NullEditor]
  45. public string? BlobData { get; set; }
  46. [NullEditor]
  47. [Obsolete("Being Replaced by FormCompleted", true)]
  48. public DateTime QACompleted { get; set; }
  49. [EditorSequence(2)]
  50. [Caption("Started")]
  51. [DateTimeEditor]
  52. public DateTime FormStarted { get; set; } = DateTime.MinValue;
  53. [EditorSequence(3)]
  54. [Caption("Completed")]
  55. [DateTimeEditor]
  56. public DateTime FormCompleted { get; set; }
  57. [EditorSequence(4)]
  58. [Caption("Processed")]
  59. [DateTimeEditor]
  60. public DateTime FormProcessed { get; set; }
  61. [EditorSequence(5)]
  62. [Caption("Cancelled")]
  63. [DateTimeEditor]
  64. public DateTime FormCancelled { get; set; }
  65. [NullEditor]
  66. [Obsolete("Being Replaced by FormCompletedBy")]
  67. public UserLink QACompletedBy => InitializeField(ref _qACompletedBy, nameof(QACompletedBy));
  68. private UserLink _qACompletedBy;
  69. [EditorSequence(3)]
  70. [Caption("User")]
  71. public UserLink FormCompletedBy => InitializeField(ref _formCompletedBy, nameof(FormCompletedBy));
  72. private UserLink _formCompletedBy;
  73. [NullEditor]
  74. [Obsolete("Replaced with Status", true)]
  75. public bool Processed { get; set; } = false;
  76. [NullEditor]
  77. public Location Location => InitializeField(ref _location, nameof(Location));
  78. private Location _location;
  79. public IDigitalFormDataModel CreateDataModel(DigitalFormVariable[] variables, Entity? parent = null)
  80. {
  81. var t = typeof(DigitalFormDataModel<,,>).MakeGenericType(typeof(TParent), typeof(TParentLink), GetType());
  82. if (parent != null)
  83. return (Activator.CreateInstance(t, parent, this, variables) as IDigitalFormDataModel)!;
  84. return (Activator.CreateInstance(t, Parent.ID, ID, variables) as IDigitalFormDataModel)!;
  85. }
  86. public Guid ParentID()
  87. {
  88. return Parent.ID;
  89. }
  90. public Type ParentType() => typeof(TParent);
  91. [DurationEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  92. public TimeSpan FormOpen { get; set; } = TimeSpan.Zero;
  93. [NullEditor]
  94. public long Sequence { get; set; }
  95. }
  96. }