BaseEntityForm.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. [ObsoleteProperty(nameof(Form))]
  32. public QAFormLink QAForm => InitializeField(ref _qAForm, nameof(QAForm));
  33. private QAFormLink _qAForm;
  34. [EditorSequence(1)]
  35. [EntityRelationship(DeleteAction.Cascade)]
  36. public DigitalFormLink Form => InitializeField(ref _form, nameof(Form));
  37. private DigitalFormLink _form;
  38. [NullEditor]
  39. [Obsolete("Being Replaced by FormData", true)]
  40. public string QAData { get; set; }
  41. [NullEditor]
  42. public string FormData { get; set; }
  43. [NullEditor]
  44. public string? BlobData { get; set; }
  45. [NullEditor]
  46. [Obsolete("Being Replaced by FormCompleted", true)]
  47. public DateTime QACompleted { get; set; }
  48. [EditorSequence(2)]
  49. [Caption("Started")]
  50. [DateTimeEditor]
  51. public DateTime FormStarted { get; set; } = DateTime.MinValue;
  52. [EditorSequence(3)]
  53. [Caption("Completed")]
  54. [DateTimeEditor]
  55. public DateTime FormCompleted { get; set; }
  56. [EditorSequence(4)]
  57. [Caption("Processed")]
  58. [DateTimeEditor]
  59. public DateTime FormProcessed { get; set; }
  60. [EditorSequence(5)]
  61. [Caption("Cancelled")]
  62. [DateTimeEditor]
  63. public DateTime FormCancelled { get; set; }
  64. [NullEditor]
  65. [Obsolete("Being Replaced by FormCompletedBy")]
  66. [ObsoleteProperty(nameof(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. // The only difference between this "standard" EntityForm and the "MovableEntityForm" below is that the Parent
  97. // here is disabled, effectively locking the digital form to its parent. A MovableEntityForm (currently only used
  98. // for Job Forms) allows the form to be swicthed between different parents.
  99. public abstract class FixedEntityForm<TParent, TParentLink, TThis> : BaseEntityForm<TParent, TParentLink, TThis>
  100. where TThis : BaseEntityForm<TParent,TParentLink, TThis>
  101. where TParent : Entity
  102. where TParentLink : BaseObject, IEntityLink<TParent>, new()
  103. {
  104. [NullEditor]
  105. [EntityRelationship(DeleteAction.Cascade)]
  106. public override TParentLink Parent => InitializeField(ref _tParentLink, nameof(TParentLink));
  107. private TParentLink _tParentLink;
  108. }
  109. public abstract class MovableEntityForm<TParent, TParentLink, TThis> : BaseEntityForm<TParent, TParentLink, TThis>
  110. where TThis : BaseEntityForm<TParent,TParentLink, TThis>
  111. where TParent : Entity
  112. where TParentLink : BaseObject, IEntityLink<TParent>, new()
  113. {
  114. [EntityRelationship(DeleteAction.Cascade)]
  115. public override TParentLink Parent => InitializeField(ref _tParentLink, nameof(TParentLink));
  116. private TParentLink _tParentLink;
  117. }
  118. }