AssignmentShell.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Drawing;
  4. using Comal.Classes;
  5. using InABox.Core;
  6. using InABox.Mobile;
  7. using Color = Xamarin.Forms.Color;
  8. namespace PRS.Mobile
  9. {
  10. public class AssignmentShell : Shell<AssignmentModel, Assignment>
  11. {
  12. protected override void ConfigureColumns(ShellColumns<AssignmentModel, Assignment> columns)
  13. {
  14. columns
  15. .Map(nameof(EmployeeID), x => x.EmployeeLink.ID)
  16. .Map(nameof(Number), x => x.Number)
  17. .Map(nameof(Title), x => x.Title)
  18. .Map(nameof(Description), x => x.Description)
  19. .Map(nameof(Date), x => x.Date)
  20. .Map(nameof(BookedStart), x => x.Booked.Start)
  21. .Map(nameof(BookedDuration), x => x.Booked.Duration)
  22. .Map(nameof(BookedFinish), x => x.Booked.Finish)
  23. .Map(nameof(ActualStart), x => x.Actual.Start)
  24. .Map(nameof(ActualDuration), x => x.Actual.Duration)
  25. .Map(nameof(ActualFinish), x => x.Actual.Finish)
  26. .Map(nameof(Completed), x => x.Completed)
  27. .Map(nameof(JobID), x => x.JobLink.ID)
  28. .Map(nameof(JobNumber), x => x.JobLink.JobNumber)
  29. .Map(nameof(JobName), x => x.JobLink.Name)
  30. .Map(nameof(Latitude), x => x.JobLink.SiteAddress.Location.Latitude)
  31. .Map(nameof(Longitude), x => x.JobLink.SiteAddress.Location.Longitude)
  32. .Map(nameof(TaskID), x => x.Task.ID)
  33. .Map(nameof(TaskNumber), x => x.Task.Number)
  34. .Map(nameof(TaskName), x => x.Task.Title)
  35. .Map(nameof(ActivityID), x => x.ActivityLink.ID)
  36. .Map(nameof(ActivityCode), x => x.ActivityLink.Code)
  37. .Map(nameof(ActivityDescription), x => x.ActivityLink.Description)
  38. .Map(nameof(ActivityColor), x => x.ActivityLink.Color)
  39. .Map(nameof(DeliveryID), x => x.Delivery.ID);
  40. }
  41. public String Title
  42. {
  43. get => Get<String>();
  44. set => Set(value);
  45. }
  46. public Guid EmployeeID
  47. {
  48. get => Get<Guid>();
  49. set => Set(value);
  50. }
  51. public int Number
  52. {
  53. get => Get<int>();
  54. set => Set(value);
  55. }
  56. public String Description
  57. {
  58. get => Get<String>();
  59. set => Set(value);
  60. }
  61. public double Latitude
  62. {
  63. get => Get<double>();
  64. set => Set(value);
  65. }
  66. public double Longitude
  67. {
  68. get => Get<double>();
  69. set => Set(value);
  70. }
  71. public DateTime Completed
  72. {
  73. get => Get<DateTime>();
  74. set => Set(value);
  75. }
  76. public Guid DeliveryID
  77. => Get<Guid>();
  78. #region Date & Time
  79. public DateTime Date
  80. {
  81. get => Get<DateTime>();
  82. set => Set(value);
  83. }
  84. public TimeSpan ActualStart
  85. {
  86. get => Get<TimeSpan>();
  87. set => Set(value);
  88. }
  89. public TimeSpan ActualDuration
  90. {
  91. get => Get<TimeSpan>();
  92. set => Set(value);
  93. }
  94. public TimeSpan ActualFinish
  95. {
  96. get => Get<TimeSpan>();
  97. set => Set(value);
  98. }
  99. public TimeSpan BookedStart
  100. {
  101. get => Get<TimeSpan>();
  102. set => Set(value);
  103. }
  104. public TimeSpan BookedDuration
  105. {
  106. get => Get<TimeSpan>();
  107. set => Set(value);
  108. }
  109. public TimeSpan BookedFinish
  110. {
  111. get => Get<TimeSpan>();
  112. set => Set(value);
  113. }
  114. #endregion
  115. #region Job Settings
  116. public Guid JobID
  117. {
  118. get => Get<Guid>();
  119. set => Set(value);
  120. }
  121. public String JobNumber
  122. {
  123. get => Get<String>();
  124. set
  125. {
  126. Set(value,false);
  127. DoPropertyChanged(nameof(JobDisplay));
  128. }
  129. }
  130. public String JobName
  131. {
  132. get => Get<String>();
  133. set
  134. {
  135. Set(value,false);
  136. DoPropertyChanged(nameof(JobDisplay));
  137. }
  138. }
  139. #endregion
  140. #region Task Settings
  141. public Guid TaskID
  142. {
  143. get => Get<Guid>();
  144. set => Set(value);
  145. }
  146. public int TaskNumber
  147. {
  148. get => Get<int>();
  149. set
  150. {
  151. Set(value,false);
  152. DoPropertyChanged(nameof(TaskDisplay));
  153. }
  154. }
  155. public String TaskName
  156. {
  157. get => Get<String>();
  158. set
  159. {
  160. Set(value,false);
  161. DoPropertyChanged(nameof(TaskDisplay));
  162. }
  163. }
  164. #endregion
  165. #region Activity Code
  166. public Guid ActivityID
  167. {
  168. get => Get<Guid>();
  169. set => Set(value);
  170. }
  171. public String ActivityCode
  172. {
  173. get => Get<String>();
  174. set
  175. {
  176. Set(value,false);
  177. DoPropertyChanged(nameof(ActivityDisplay));
  178. }
  179. }
  180. public String ActivityDescription
  181. {
  182. get => Get<String>();
  183. set
  184. {
  185. Set(value,false);
  186. DoPropertyChanged(nameof(ActivityDisplay));
  187. }
  188. }
  189. public String ActivityColor
  190. {
  191. get => Get<String>();
  192. set
  193. {
  194. Set(value,false);
  195. DoPropertyChanged(nameof(ActivityDisplay));
  196. }
  197. }
  198. #endregion
  199. #region Calculated Fields
  200. public String JobDisplay => JobID != Guid.Empty
  201. ? $"{JobNumber}: {JobName}"
  202. : "(No Job Selected)";
  203. public String ActivityDisplay => ActivityID != Guid.Empty
  204. ? $"{ActivityCode}: {ActivityDescription}"
  205. : "(No Activity Selected)";
  206. public String TaskDisplay => TaskID != Guid.Empty
  207. ? $"{TaskNumber}: {TaskName}"
  208. : "(No Task Selected)";
  209. public String Subject => string.Format("{0}{1} {2}",
  210. Number,
  211. JobID != Guid.Empty ? $"({JobNumber})" : "",
  212. Title
  213. );
  214. public bool IsCompleted => !Completed.IsEmpty();
  215. public DateTime StartTime => Date.Add(Assignment.EffectiveTime(ActualStart, BookedStart).Floor(TimeSpan.FromMinutes(5)));
  216. public DateTime EndTime => Date.Add(Assignment.EffectiveTime(ActualFinish, BookedFinish).Ceiling(TimeSpan.FromMinutes(5)));
  217. public Color BackgroundColor => !String.IsNullOrWhiteSpace(ActivityColor)
  218. ? Color.FromHex(ActivityColor)
  219. : Color.Silver;
  220. public Color TextColor => Color.Black;
  221. public ObservableCollection<object> ResourceIds => new ObservableCollection<object>() { EmployeeID };
  222. public PointF Coordinates => new PointF(
  223. (float)(Longitude),
  224. (float)(Latitude)
  225. );
  226. #endregion
  227. }
  228. }