JobDocumentSetMileStone.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using InABox.Core;
  5. namespace Comal.Classes
  6. {
  7. public class JobDocumentSetMileStoneKanbanCount : CoreAggregate<JobDocumentSetMileStone, JobDocumentSetMileStoneKanban, Guid>
  8. {
  9. public override Expression<Func<JobDocumentSetMileStoneKanban, Guid>> Aggregate => x => x.ID;
  10. public override AggregateCalculation Calculation => AggregateCalculation.Count;
  11. public override Dictionary<Expression<Func<JobDocumentSetMileStoneKanban, object>>, Expression<Func<JobDocumentSetMileStone, object>>> Links =>
  12. new Dictionary<Expression<Func<JobDocumentSetMileStoneKanban, object>>, Expression<Func<JobDocumentSetMileStone, object>>>()
  13. {
  14. { JobDocumentSetMileStoneFile => JobDocumentSetMileStoneFile.Entity.ID, JobDocumentSetMileStone => JobDocumentSetMileStone.ID }
  15. };
  16. public override Filter<JobDocumentSetMileStoneKanban>? Filter =>
  17. new Filter<JobDocumentSetMileStoneKanban>(x => x.Kanban.Completed).IsEqualTo(DateTime.MinValue);
  18. }
  19. public class JobDocumentSetMileStoneFileCount : CoreAggregate<JobDocumentSetMileStone, JobDocumentSetMileStoneFile, Guid>
  20. {
  21. public override Expression<Func<JobDocumentSetMileStoneFile, Guid>> Aggregate => x => x.ID;
  22. public override AggregateCalculation Calculation => AggregateCalculation.Count;
  23. public override Dictionary<Expression<Func<JobDocumentSetMileStoneFile, object>>, Expression<Func<JobDocumentSetMileStone, object>>> Links =>
  24. new Dictionary<Expression<Func<JobDocumentSetMileStoneFile, object>>, Expression<Func<JobDocumentSetMileStone, object>>>()
  25. {
  26. { JobDocumentSetMileStoneFile => JobDocumentSetMileStoneFile.EntityLink.ID, JobDocumentSetMileStone => JobDocumentSetMileStone.ID }
  27. };
  28. }
  29. [Caption("Milestones")]
  30. public class JobDocumentSetMileStone : Entity, IRemotable, IPersistent,
  31. IOneToMany<JobDocumentSet>,
  32. IJobDocumentSetMileStone,
  33. ILicense<ProjectManagementLicense>
  34. {
  35. [EntityRelationship(DeleteAction.Cascade)]
  36. [NullEditor]
  37. public JobDocumentSetLink DocumentSet { get; set; }
  38. [EntityRelationship(DeleteAction.Cascade)]
  39. [NullEditor]
  40. [EditorSequence(1)]
  41. public JobDocumentSetMileStoneTypelink Type { get; set; }
  42. [CodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  43. [EditorSequence(2)]
  44. public String Revision { get; set; }
  45. [EditorSequence(3)]
  46. public EmployeeLink Employee { get; set; }
  47. [EnumLookupEditor(typeof(JobDocumentSetMileStoneStatus))]
  48. [EditorSequence(4)]
  49. public JobDocumentSetMileStoneStatus Status { get; set; } = JobDocumentSetMileStoneStatus.NotStarted;
  50. [NotesEditor]
  51. [EditorSequence(5)]
  52. public String[] Notes { get; set; }
  53. [TextBoxEditor]
  54. [EditorSequence(6)]
  55. public String Watermark { get; set; }
  56. [DateTimeEditor(Editable = Editable.Enabled)]
  57. [EditorSequence(7)]
  58. public DateTime Due { get; set; }
  59. [Obsolete("Replaced with Submitted", true)]
  60. public DateTime Issued { get; set; }
  61. [DateTimeEditor(Editable = Editable.Disabled)]
  62. [EditorSequence(8)]
  63. public DateTime Submitted { get; set; }
  64. [DateTimeEditor(Editable = Editable.Enabled)]
  65. [EditorSequence(9)]
  66. public DateTime Expected { get; set; }
  67. [DateTimeEditor(Editable = Editable.Disabled)]
  68. [EditorSequence(10)]
  69. public DateTime Closed { get; set; }
  70. [NullEditor]
  71. [Aggregate(typeof(JobDocumentSetMileStoneFileCount))]
  72. public int Attachments { get; set; }
  73. [NullEditor]
  74. [Aggregate(typeof(JobDocumentSetMileStoneKanbanCount))]
  75. public int Kanbans { get; set; }
  76. [NullEditor]
  77. public DateTime DataEntered { get; set; }
  78. protected override void DoPropertyChanged(string name, object? before, object? after)
  79. {
  80. base.DoPropertyChanged(name, before, after);
  81. if (String.Equals(name, "Status"))
  82. {
  83. JobDocumentSetMileStoneStatus status = (JobDocumentSetMileStoneStatus)after;
  84. switch (status)
  85. {
  86. case JobDocumentSetMileStoneStatus.InProgress:
  87. case JobDocumentSetMileStoneStatus.OnHold:
  88. case JobDocumentSetMileStoneStatus.InfoRequired:
  89. Submitted = DateTime.MinValue;
  90. Closed = DateTime.MinValue;
  91. break;
  92. case JobDocumentSetMileStoneStatus.Submitted:
  93. Submitted = Submitted.IsEmpty() ? DateTime.Now : Submitted;
  94. Closed = DateTime.MinValue;
  95. break;
  96. case JobDocumentSetMileStoneStatus.Approved:
  97. case JobDocumentSetMileStoneStatus.Rejected:
  98. case JobDocumentSetMileStoneStatus.Cancelled:
  99. Submitted = Submitted.IsEmpty() ? DateTime.Now : Submitted;
  100. Closed = Closed.IsEmpty() ? DateTime.Now : Closed;
  101. break;
  102. }
  103. }
  104. }
  105. }
  106. }