EntityForm.cs 3.4 KB

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