JobTimesheetGrid.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 ParentID { get; set; }
  28. public JobPanelSettings Settings { get; set; }
  29. protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
  30. {
  31. if (ParentID.Equals(Guid.Empty) || ParentID.Equals(CoreUtils.FullGuid))
  32. MessageBox.Show("Please select a Job first!");
  33. else
  34. base.DoAdd();
  35. }
  36. protected override TimeSheet CreateItem()
  37. {
  38. var result = base.CreateItem();
  39. result.JobLink.ID = ParentID;
  40. return result;
  41. }
  42. protected override void Reload(Filters<TimeSheet> criteria, Columns<TimeSheet> columns, ref SortOrder<TimeSheet> sort,
  43. Action<CoreTable, Exception> action)
  44. {
  45. criteria.Add(new Filter<TimeSheet>(x => x.JobLink.ID).IsEqualTo(ParentID));
  46. base.Reload(criteria, columns, ref sort, action);
  47. }
  48. }
  49. }