AssignmentModel.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Windows.Media;
  4. using Comal.Classes;
  5. using InABox.Core;
  6. using InABox.WPF;
  7. namespace PRSDesktop
  8. {
  9. public class AssignmentModel : Model<AssignmentModel,Assignment>
  10. {
  11. public Guid EmployeeID { get; }
  12. public int Number { get; set; }
  13. public String? Subject { get; set; }
  14. public String? Notes { get; set; }
  15. public DateTime Completed { get; set; }
  16. public DateTime Date { get; }
  17. public TimeSpan BookedStart { get; set; }
  18. public TimeSpan BookedFinish { get; set; }
  19. public TimeSpan BookedDuration { get; }
  20. public TimeSpan ActualStart { get; set; }
  21. public TimeSpan ActualDuration { get; set; }
  22. public TimeSpan ActualFinish { get; set; }
  23. public static TimeSpan EffectiveTime(TimeSpan actual, TimeSpan booked) => actual.Ticks != 0L ? actual : booked;
  24. public TimeSpan EffectiveStart()
  25. {
  26. return EffectiveTime(ActualStart, BookedStart);
  27. }
  28. public TimeSpan EffectiveFinish()
  29. {
  30. // If we have an actual finish, always use that
  31. // otherwise use EffectiveStart() + booked.duration
  32. return EffectiveTime(
  33. ActualFinish,
  34. EffectiveTime(ActualStart, BookedStart)
  35. .Add(BookedDuration)
  36. );
  37. }
  38. public Guid JobID { get; }
  39. public string? JobNumber { get; }
  40. public string? JobName { get; }
  41. public Guid ActivityID { get; set; }
  42. public string? ActivityCode { get; }
  43. public string? ActivityDescription { get; }
  44. public string? Color { get; }
  45. public Guid ItpID { get; set; }
  46. public string? ItpCode { get; set; }
  47. public string? ItpDescription { get; set; }
  48. public Guid DeliveryID { get; set; }
  49. public string? DeliveryNotes { get; set; }
  50. public Guid TaskID { get; set; }
  51. public int TaskNumber { get; set; }
  52. public Guid MeetingID { get; set; }
  53. public int MeetingNumber { get; set; }
  54. public AssignmentModel(CoreRow row) : base(row)
  55. {
  56. EmployeeID = Get(x=>x.EmployeeLink.ID);
  57. Number = Get(x => x.Number);
  58. Subject = Get(x => x.Title);
  59. Notes = Get(x => x.Description);
  60. Completed = Get(x => x.Completed);
  61. Date = Get(x=>x.Date);
  62. BookedDuration = Get(x => x.Booked.Duration);
  63. BookedStart = Get(x => x.Booked.Start);
  64. BookedFinish = Get(x => x.Booked.Finish);
  65. ActualStart = Get(x => x.Actual.Start);
  66. ActualDuration = Get(x => x.Actual.Duration);
  67. ActualFinish = Get(x => x.Actual.Finish);
  68. JobID = Get(x => x.JobLink.ID);
  69. JobNumber = Get(x => x.JobLink.JobNumber);
  70. JobName = Get(x => x.JobLink.Name);
  71. ActivityID = Get(x => x.ActivityLink.ID);
  72. ActivityCode = Get(x => x.ActivityLink.Code);
  73. ActivityDescription = Get(x => x.ActivityLink.Description);
  74. Color = Get(x => x.ActivityLink.Color);
  75. ItpID = Get(x => x.ITP.ID);
  76. ItpCode = Get(x => x.ITP.Code);
  77. ItpDescription = Get(x => x.ITP.Description);
  78. DeliveryID = Get(x => x.Delivery.ID);
  79. DeliveryNotes = Get(x => x.Delivery.Notes);
  80. TaskID = Get(x => x.Task.ID);
  81. TaskNumber = Get(x => x.Task.Number);
  82. MeetingID = Get(x => x.Meeting.Link.ID);
  83. MeetingNumber = Get(x => x.Meeting.Link.Number);
  84. }
  85. public override Columns<Assignment> GetColumns()
  86. {
  87. return new Columns<Assignment>(x => x.ID)
  88. .Add(x => x.EmployeeLink.ID)
  89. .Add(x => x.Number)
  90. .Add(x => x.Title)
  91. .Add(x => x.Description)
  92. .Add(x => x.Completed)
  93. .Add(x => x.Date)
  94. .Add(x => x.Booked.Start)
  95. .Add(x => x.Booked.Duration)
  96. .Add(x => x.Booked.Finish)
  97. .Add(x => x.Actual.Start)
  98. .Add(x => x.Actual.Duration)
  99. .Add(x => x.Actual.Finish)
  100. .Add(x => x.JobLink.ID)
  101. .Add(x => x.JobLink.JobNumber)
  102. .Add(x => x.JobLink.Name)
  103. .Add(x => x.ActivityLink.ID)
  104. .Add(x => x.ActivityLink.Code)
  105. .Add(x => x.ActivityLink.Description)
  106. .Add(x => x.ActivityLink.Color)
  107. .Add(x => x.ITP.ID)
  108. .Add(x => x.ITP.Code)
  109. .Add(x => x.ITP.Description)
  110. .Add(x => x.Delivery.ID)
  111. .Add(x => x.Delivery.Notes)
  112. .Add(x => x.Task.ID)
  113. .Add(x => x.Task.Number)
  114. .Add(x => x.Meeting.Link.ID)
  115. .Add(x => x.Meeting.Link.Number);
  116. }
  117. }
  118. }