EntityForm.cs 3.8 KB

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