JobGrid.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Clients;
  5. using InABox.Core;
  6. using InABox.DynamicGrid;
  7. namespace PRSDesktop
  8. {
  9. public class JobGrid : DynamicDataGrid<Job>
  10. {
  11. private Guid _statusid = Guid.Empty;
  12. public JobGrid()
  13. {
  14. Options.AddRange(
  15. DynamicGridOption.RecordCount,
  16. DynamicGridOption.SelectColumns,
  17. DynamicGridOption.FilterRows
  18. );
  19. HiddenColumns.Add(x => x.Customer.ID);
  20. HiddenColumns.Add(x => x.ID);
  21. HiddenColumns.Add(x => x.JobStatus.Active);
  22. ActionColumns.Add(new DynamicMapColumn<Job>(this, x => x.SiteAddress.Location));
  23. }
  24. public Guid StatusID
  25. {
  26. get => _statusid;
  27. set
  28. {
  29. _statusid = value;
  30. Refresh(false, true);
  31. }
  32. }
  33. protected override void Reload(Filters<Job> criteria, Columns<Job> columns, ref SortOrder<Job> sort, Action<CoreTable, Exception> action)
  34. {
  35. if (_statusid != Guid.Empty)
  36. criteria.Add(new Filter<Job>(x => x.JobStatus.ID).IsEqualTo(_statusid));
  37. sort = new SortOrder<Job>(x => x.JobNumber, SortDirection.Descending);
  38. base.Reload(criteria, columns, ref sort, action);
  39. }
  40. public override DynamicEditorPages LoadEditorPages(Job item)
  41. {
  42. var pages = new DynamicEditorPages(new IDynamicEditorPage[]
  43. {
  44. new DynamicManyToManyGrid<JobDocument,Job>(),
  45. new DynamicManyToManyGrid<JobStyle,Job>(),
  46. new DynamicOneToManyGrid<Job,JobDocumentSetTag>(),
  47. new JobFormDefinitionGrid()
  48. });
  49. return pages;
  50. }
  51. protected override Job CreateItem()
  52. {
  53. var result = base.CreateItem();
  54. var defstatus = new Client<JobStatus>().Query(new Filter<JobStatus>(x => x.Default).IsEqualTo(true));
  55. if (defstatus.Rows.Any())
  56. result.JobStatus.ID = defstatus.Rows.First().Get<JobStatus, Guid>(x => x.ID);
  57. return result;
  58. }
  59. }
  60. }