EmployeeJobGrid.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. public override DynamicGridColumns GenerateColumns()
  21. {
  22. var columns = new DynamicGridColumns();
  23. columns.Add<JobEmployee, String>(x => x.JobLink.JobNumber, 70, "Job", "", Alignment.MiddleCenter);
  24. columns.Add<JobEmployee, String>(x => x.JobLink.Name, 0, "Job Name", "", Alignment.MiddleLeft);
  25. columns.Add<JobEmployee, DateTime>(x => x.Inducted, 70, "Inducted", "dd MMM yy", Alignment.MiddleCenter);
  26. columns.Add<JobEmployee, bool>(x => x.Active, 25, "Act", "", Alignment.MiddleCenter);
  27. return columns;
  28. }
  29. private bool ToggleActive(Button arg1, CoreRow[] arg2)
  30. {
  31. _activeonly = !_activeonly;
  32. UpdateButton(_status,null,_activeonly ? "Show All" : "Active Only");
  33. return true;
  34. }
  35. protected override void Reload(Filters<JobEmployee> criteria, Columns<JobEmployee> columns, ref SortOrder<JobEmployee>? sort, Action<CoreTable?, Exception?> action)
  36. {
  37. if (_activeonly)
  38. criteria.Add(new Filter<JobEmployee>(x => x.Active).IsEqualTo(true).And(x=>x.JobLink.JobStatus.Active).IsEqualTo(true));
  39. base.Reload(criteria, columns, ref sort, action);
  40. }
  41. }
  42. }