EmployeeJobGrid.cs 1.8 KB

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