BaseEntityForm.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 BaseEntityForm<TParent, TParentLink, TThis> : Entity, IRemotable, IPersistent, ISequenceable, IStringAutoIncrement<TThis>,
  12. IEntityForm,
  13. IDigitalFormInstance<TParentLink>, ILicense<DigitalFormsLicense>
  14. where TThis : BaseEntityForm<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. public int AutoIncrementDefault() => 1;
  23. [EditorSequence(1)]
  24. [CodeEditor(Editable = Editable.Disabled)]
  25. public String Number { get; set; }
  26. [EditorSequence(2)]
  27. public string Description { get; set; } = "";
  28. public abstract TParentLink Parent { get; }
  29. [NullEditor]
  30. [Obsolete("Being Replaced by Form")]
  31. public QAFormLink QAForm => InitializeField(ref _qAForm, nameof(QAForm));
  32. private QAFormLink _qAForm;
  33. [EditorSequence(1)]
  34. [EntityRelationship(DeleteAction.Cascade)]
  35. public DigitalFormLink Form => InitializeField(ref _form, nameof(Form));
  36. private DigitalFormLink _form;
  37. [NullEditor]
  38. [Obsolete("Being Replaced by FormData", true)]
  39. public string QAData { get; set; }
  40. [NullEditor]
  41. public string FormData { get; set; }
  42. [NullEditor]
  43. public string? BlobData { get; set; }
  44. [NullEditor]
  45. [Obsolete("Being Replaced by FormCompleted", true)]
  46. public DateTime QACompleted { get; set; }
  47. [EditorSequence(2)]
  48. [Caption("Started")]
  49. [DateTimeEditor]
  50. public DateTime FormStarted { get; set; } = DateTime.MinValue;
  51. [EditorSequence(3)]
  52. [Caption("Completed")]
  53. [DateTimeEditor]
  54. public DateTime FormCompleted { get; set; }
  55. [EditorSequence(4)]
  56. [Caption("Processed")]
  57. [DateTimeEditor]
  58. public DateTime FormProcessed { get; set; }
  59. [EditorSequence(5)]
  60. [Caption("Cancelled")]
  61. [DateTimeEditor]
  62. public DateTime FormCancelled { get; set; }
  63. [NullEditor]
  64. [Obsolete("Being Replaced by FormCompletedBy")]
  65. public UserLink QACompletedBy => InitializeField(ref _qACompletedBy, nameof(QACompletedBy));
  66. private UserLink _qACompletedBy;
  67. [EditorSequence(3)]
  68. [Caption("User")]
  69. public UserLink FormCompletedBy => InitializeField(ref _formCompletedBy, nameof(FormCompletedBy));
  70. private UserLink _formCompletedBy;
  71. [NullEditor]
  72. [Obsolete("Replaced with Status", true)]
  73. public bool Processed { get; set; } = false;
  74. [NullEditor]
  75. public Location Location => InitializeField(ref _location, nameof(Location));
  76. private Location _location;
  77. public IDigitalFormDataModel CreateDataModel(DigitalFormVariable[] variables, Entity? parent = null)
  78. {
  79. var t = typeof(DigitalFormDataModel<,,>).MakeGenericType(typeof(TParent), typeof(TParentLink), GetType());
  80. if (parent != null)
  81. return (Activator.CreateInstance(t, parent, this, variables) as IDigitalFormDataModel)!;
  82. return (Activator.CreateInstance(t, Parent.ID, ID, variables) as IDigitalFormDataModel)!;
  83. }
  84. public Guid ParentID()
  85. {
  86. return Parent.ID;
  87. }
  88. public Type ParentType() => typeof(TParent);
  89. [DurationEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  90. public TimeSpan FormOpen { get; set; } = TimeSpan.Zero;
  91. [NullEditor]
  92. public long Sequence { get; set; }
  93. }
  94. // The only difference between this "standard" EntityForm and the "MovableEntityForm" below is that the Parent
  95. // here is disabled, effectively locking the digital form to its parent. A MovableEntityForm (currently only used
  96. // for Job Forms) allows the form to be swicthed between different parents.
  97. public abstract class FixedEntityForm<TParent, TParentLink, TThis> : BaseEntityForm<TParent, TParentLink, TThis>
  98. where TThis : BaseEntityForm<TParent,TParentLink, TThis>
  99. where TParent : Entity
  100. where TParentLink : BaseObject, IEntityLink<TParent>, new()
  101. {
  102. [NullEditor]
  103. [EntityRelationship(DeleteAction.Cascade)]
  104. public override TParentLink Parent => InitializeField(ref _tParentLink, nameof(TParentLink));
  105. private TParentLink _tParentLink;
  106. }
  107. public abstract class MovableEntityForm<TParent, TParentLink, TThis> : BaseEntityForm<TParent, TParentLink, TThis>
  108. where TThis : BaseEntityForm<TParent,TParentLink, TThis>
  109. where TParent : Entity
  110. where TParentLink : BaseObject, IEntityLink<TParent>, new()
  111. {
  112. [EntityRelationship(DeleteAction.Cascade)]
  113. public override TParentLink Parent => InitializeField(ref _tParentLink, nameof(TParentLink));
  114. private TParentLink _tParentLink;
  115. }
  116. }