EmployeeRosterTemplateItem.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using InABox.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Comal.Classes
  7. {
  8. [Caption("Roster Items")]
  9. public class EmployeeRosterTemplateItem : Entity, IEmployeeRosterItem, IOneToMany<EmployeeRoster>, ILicense<CoreLicense>, IRemotable, IPersistent
  10. {
  11. private static readonly Dictionary<string, Func<EmployeeRosterTemplateItem, TimeSpan>> times = new Dictionary<string, Func<EmployeeRosterTemplateItem, TimeSpan>>()
  12. {
  13. { "Start", x => x.Start },
  14. { "Finish", x => x.Finish },
  15. { "Break", x => x.Break },
  16. { "Start2", x => x.Start2 },
  17. { "Finish2", x => x.Finish2 },
  18. { "Break2", x => x.Break2 }
  19. };
  20. public EmployeeRosterLink Roster { get; set; }
  21. [IntegerEditor(Alignment = Alignment.MiddleCenter, Editable = Editable.Hidden, Visible = Visible.Hidden)]
  22. [EditorSequence(1)]
  23. [Caption("Day")]
  24. public int Day { get; set; }
  25. [TextBoxEditor(Alignment = Alignment.MiddleCenter, Editable = Editable.Disabled)]
  26. [EditorSequence(2)]
  27. public string Description { get; set; }
  28. [CheckBoxEditor]
  29. [EditorSequence(3)]
  30. [Caption("Rostered On?")]
  31. public bool Enabled { get; set; }
  32. [TimeOfDayEditor(Format = "hh:mm", Width = 70)]
  33. [EditorSequence(4)]
  34. public TimeSpan Start { get; set; }
  35. [TimeOfDayEditor(Format = "hh:mm", Width = 70)]
  36. [EditorSequence(5)]
  37. public TimeSpan Finish { get; set; }
  38. [DurationEditor(Format = "hh:mm", Visible = Visible.Default, Editable = Editable.Enabled, Width = 70)]
  39. [EditorSequence(6)]
  40. public TimeSpan Break { get; set; }
  41. [CheckBoxEditor]
  42. [EditorSequence(7)]
  43. [Caption("Split")]
  44. public bool SplitShift { get; set; }
  45. [TimeOfDayEditor(Format = "hh:mm", Width = 70)]
  46. [EditorSequence(8)]
  47. [Caption("Start 2")]
  48. public TimeSpan Start2 { get; set; }
  49. [TimeOfDayEditor(Format = "hh:mm", Width = 70)]
  50. [EditorSequence(9)]
  51. [Caption("Finish 2")]
  52. public TimeSpan Finish2 { get; set; }
  53. [DurationEditor(Format = "hh:mm", Visible = Visible.Default, Editable = Editable.Enabled, Width = 70)]
  54. [EditorSequence(10)]
  55. [Caption("Break 2")]
  56. public TimeSpan Break2 { get; set; }
  57. [DoubleEditor(Format = "F2", Visible = Visible.Default, Editable = Editable.Disabled, Summary = Summary.Sum, Width = 70,
  58. Alignment = Alignment.MiddleCenter)]
  59. [EditorSequence(12)]
  60. [Caption("Total")]
  61. public double Duration { get; set; }
  62. public OvertimeLink Overtime { get; set; }
  63. protected override void DoPropertyChanged(string name, object? before, object? after)
  64. {
  65. if (String.Equals(name, nameof(Day)))
  66. Description = $"Day {after}";
  67. base.DoPropertyChanged(name, before, after);
  68. (this as IEmployeeRosterItem).DoPropertyChanged(name, before, after);
  69. }
  70. public EmployeeRosterItem ToEmployeeRosterItem(IEmployee employee)
  71. {
  72. var newItem = new EmployeeRosterItem
  73. {
  74. Day = Day,
  75. Description = Description,
  76. Enabled = Enabled,
  77. Start = Start,
  78. Finish = Finish,
  79. Break = Break,
  80. SplitShift = SplitShift,
  81. Start2 = Start2,
  82. Finish2 = Finish2,
  83. Break2 = Break2,
  84. Duration = Duration
  85. };
  86. newItem.Employee.ID = employee.ID;
  87. newItem.Employee.Synchronise(employee);
  88. newItem.Overtime.ID = Overtime.ID;
  89. newItem.Overtime.Synchronise(Overtime);
  90. return newItem;
  91. }
  92. }
  93. }