EntityForm.cs 3.7 KB

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