EmployeeJobGrid.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Linq.Expressions;
  3. using System.Threading;
  4. using System.Windows.Controls;
  5. using Comal.Classes;
  6. using InABox.Core;
  7. using InABox.DynamicGrid;
  8. namespace PRSDesktop
  9. {
  10. public class EmployeeJobGrid : DynamicCrossJoinGrid<JobEmployee,Employee>
  11. {
  12. public override Expression<Func<JobEmployee, Guid>> LeftMapping => x => x.EmployeeLink.ID;
  13. public override Expression<Func<Employee, Guid>> LeftProperty => x => x.ID;
  14. private Button _status;
  15. private bool _activeonly = true;
  16. public EmployeeJobGrid()
  17. {
  18. _status = AddButton("Show All", null, ToggleActive);
  19. _status.Width = 80;
  20. }
  21. public override DynamicGridColumns GenerateColumns()
  22. {
  23. var columns = new DynamicGridColumns();
  24. columns.Add<JobEmployee>(x => x.JobLink.JobNumber, 70, "Job", "", Alignment.MiddleCenter);
  25. columns.Add<JobEmployee>(x => x.JobLink.Name, 0, "Job Name", "", Alignment.MiddleLeft);
  26. columns.Add<JobEmployee>(x => x.Inducted, 70, "Inducted", "dd MMM yy", Alignment.MiddleCenter);
  27. columns.Add<JobEmployee>(x => x.Active, 25, "Act", "", Alignment.MiddleCenter);
  28. return columns;
  29. }
  30. private bool ToggleActive(Button arg1, CoreRow[] arg2)
  31. {
  32. _activeonly = !_activeonly;
  33. UpdateButton(_status,null,_activeonly ? "Show All" : "Active Only");
  34. return true;
  35. }
  36. protected override void Reload(
  37. Filters<JobEmployee> criteria, Columns<JobEmployee> columns, ref SortOrder<JobEmployee>? sort,
  38. CancellationToken token, Action<CoreTable?, Exception?> action)
  39. {
  40. if (_activeonly)
  41. criteria.Add(new Filter<JobEmployee>(x => x.Active).IsEqualTo(true).And(x=>x.JobLink.JobStatus.Active).IsEqualTo(true));
  42. base.Reload(criteria, columns, ref sort, token, action);
  43. }
  44. }
  45. }