JobTimesheetGrid.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Linq;
  3. using System.Windows;
  4. using Comal.Classes;
  5. using InABox.Core;
  6. using InABox.DynamicGrid;
  7. namespace PRSDesktop
  8. {
  9. public class JobTimesheetGrid : TimesheetGrid, IJobControl, IDataModelSource
  10. {
  11. public JobTimesheetGrid()
  12. {
  13. Options.AddRange(
  14. DynamicGridOption.RecordCount,
  15. DynamicGridOption.FilterRows,
  16. DynamicGridOption.MultiSelect,
  17. DynamicGridOption.EditRows
  18. );
  19. }
  20. public event DataModelUpdateEvent OnUpdateDataModel;
  21. public string SectionName => "Job Timesheets";
  22. public DataModel DataModel(Selection selection)
  23. {
  24. var ids = ExtractValues(x => x.ID, selection).ToArray();
  25. return new BaseDataModel<TimeSheet>(new Filter<TimeSheet>(x => x.ID).InList(ids));
  26. }
  27. public Guid JobID { get; set; }
  28. protected override void DoAdd()
  29. {
  30. if (JobID.Equals(Guid.Empty) || JobID.Equals(CoreUtils.FullGuid))
  31. MessageBox.Show("Please select a Job first!");
  32. else
  33. base.DoAdd();
  34. }
  35. protected override TimeSheet CreateItem()
  36. {
  37. var result = base.CreateItem();
  38. result.JobLink.ID = JobID;
  39. return result;
  40. }
  41. protected override void Reload(Filters<TimeSheet> criteria, Columns<TimeSheet> columns, ref SortOrder<TimeSheet> sort,
  42. Action<CoreTable, Exception> action)
  43. {
  44. criteria.Add(new Filter<TimeSheet>(x => x.JobLink.ID).IsEqualTo(JobID));
  45. base.Reload(criteria, columns, ref sort, action);
  46. }
  47. }
  48. }