EntityForm.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. 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. [NullEditor]
  29. [EntityRelationship(DeleteAction.Cascade)]
  30. public virtual TParentLink Parent => InitializeField(ref _tParentLink, nameof(TParentLink));
  31. private TParentLink _tParentLink;
  32. [NullEditor]
  33. [Obsolete("Being Replaced by Form")]
  34. public QAFormLink QAForm => InitializeField(ref _qAForm, nameof(QAForm));
  35. private QAFormLink _qAForm;
  36. [EditorSequence(1)]
  37. [EntityRelationship(DeleteAction.Cascade)]
  38. public DigitalFormLink Form => InitializeField(ref _form, nameof(Form));
  39. private DigitalFormLink _form;
  40. [NullEditor]
  41. [Obsolete("Being Replaced by FormData", true)]
  42. public string QAData { get; set; }
  43. [NullEditor]
  44. public string FormData { get; set; }
  45. [NullEditor]
  46. public string? BlobData { get; set; }
  47. [NullEditor]
  48. [Obsolete("Being Replaced by FormCompleted", true)]
  49. public DateTime QACompleted { get; set; }
  50. [EditorSequence(2)]
  51. [Caption("Started")]
  52. [DateTimeEditor]
  53. public DateTime FormStarted { get; set; } = DateTime.MinValue;
  54. [EditorSequence(3)]
  55. [Caption("Completed")]
  56. [DateTimeEditor]
  57. public DateTime FormCompleted { get; set; }
  58. [EditorSequence(4)]
  59. [Caption("Processed")]
  60. [DateTimeEditor]
  61. public DateTime FormProcessed { get; set; }
  62. [EditorSequence(5)]
  63. [Caption("Cancelled")]
  64. [DateTimeEditor]
  65. public DateTime FormCancelled { get; set; }
  66. [NullEditor]
  67. [Obsolete("Being Replaced by FormCompletedBy")]
  68. public UserLink QACompletedBy => InitializeField(ref _qACompletedBy, nameof(QACompletedBy));
  69. private UserLink _qACompletedBy;
  70. [EditorSequence(3)]
  71. [Caption("User")]
  72. public UserLink FormCompletedBy => InitializeField(ref _formCompletedBy, nameof(FormCompletedBy));
  73. private UserLink _formCompletedBy;
  74. [NullEditor]
  75. [Obsolete("Replaced with Status", true)]
  76. public bool Processed { get; set; } = false;
  77. [NullEditor]
  78. public Location Location => InitializeField(ref _location, nameof(Location));
  79. private Location _location;
  80. public IDigitalFormDataModel CreateDataModel(DigitalFormVariable[] variables, Entity? parent = null)
  81. {
  82. var t = typeof(DigitalFormDataModel<,,>).MakeGenericType(typeof(TParent), typeof(TParentLink), GetType());
  83. if (parent != null)
  84. return (Activator.CreateInstance(t, parent, this, variables) as IDigitalFormDataModel)!;
  85. return (Activator.CreateInstance(t, Parent.ID, ID, variables) as IDigitalFormDataModel)!;
  86. }
  87. public Guid ParentID()
  88. {
  89. return Parent.ID;
  90. }
  91. public Type ParentType() => typeof(TParent);
  92. [DurationEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  93. public TimeSpan FormOpen { get; set; } = TimeSpan.Zero;
  94. [NullEditor]
  95. public long Sequence { get; set; }
  96. }
  97. }