OvertimeIntervalGrid.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Comal.Classes;
  2. using InABox.DynamicGrid;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace PRSDesktop.Grids
  9. {
  10. public class OvertimeIntervalGrid : DynamicOneToManyGrid<Overtime, OvertimeInterval>
  11. {
  12. protected override void Init()
  13. {
  14. base.Init();
  15. HiddenColumns.Add(x => x.IntervalType);
  16. }
  17. protected override void DoReconfigureEditors(DynamicEditorGrid grid, OvertimeInterval[] items)
  18. {
  19. base.DoReconfigureEditors(grid, items);
  20. var intervalEditor = grid.FindEditor(nameof(OvertimeInterval.Interval));
  21. intervalEditor?.SetEnabled(!items.Any(x => x.IntervalType == OvertimeIntervalType.RemainingTime));
  22. }
  23. // EditorPage BeforeSave
  24. public override void BeforeSave(object item)
  25. {
  26. base.BeforeSave(item);
  27. if (Items.Count == 0)
  28. {
  29. throw new Exception("There must be at least one overtime interval.");
  30. }
  31. else if (Items.SkipLast(1).Any(x => x.IntervalType == OvertimeIntervalType.RemainingTime))
  32. {
  33. throw new Exception($"Only the last interval may have [IntervalType] = '{OvertimeIntervalType.RemainingTime}'");
  34. }
  35. else if (Items.Last().IntervalType != OvertimeIntervalType.RemainingTime)
  36. {
  37. throw new Exception($"The last overtime interval must have [IntervalType] = '{OvertimeIntervalType.RemainingTime}'");
  38. }
  39. }
  40. }
  41. }