JobFormGrid.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using InABox.DynamicGrid;
  6. using InABox.WPF;
  7. namespace PRSDesktop
  8. {
  9. public class JobFormGrid : DynamicDataGrid<JobForm>, IJobControl, IDataModelSource
  10. {
  11. public event DataModelUpdateEvent? OnUpdateDataModel;
  12. public string SectionName => "Job Forms";
  13. public DataModel DataModel(Selection selection)
  14. {
  15. var ids = ExtractValues(x => x.ID, selection).ToArray();
  16. return new AutoDataModel<JobForm>(new Filter<JobForm>(x => x.ID).InList(ids));
  17. }
  18. public JobFormGrid()
  19. {
  20. ActionColumns.Add(new DynamicImageColumn(PRSDesktop.Resources.pencil.AsBitmapImage(), EditAction));
  21. }
  22. protected override void DoReconfigure(FluentList<DynamicGridOption> options)
  23. {
  24. base.DoReconfigure(options);
  25. options
  26. .BeginUpdate()
  27. .Add(DynamicGridOption.SelectColumns)
  28. .Add(DynamicGridOption.FilterRows)
  29. .EndUpdate();
  30. }
  31. public Job Job { get; set; }
  32. public JobPanelSettings Settings { get; set; }
  33. private bool EditAction(CoreRow? row)
  34. {
  35. if (row == null) return false;
  36. if(DynamicFormEditWindow.EditDigitalForm<JobForm>(row.Get<JobForm, Guid>(x => x.ID), out var dataModel))
  37. {
  38. dataModel.Update(null);
  39. return true;
  40. }
  41. return false;
  42. }
  43. protected override void Reload(Filters<JobForm> criteria, Columns<JobForm> columns, ref SortOrder<JobForm>? sort,
  44. Action<CoreTable?, Exception?> action)
  45. {
  46. criteria.Add(new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(Job.ID));
  47. base.Reload(criteria, columns, ref sort, action);
  48. }
  49. protected override JobForm CreateItem()
  50. {
  51. var result = base.CreateItem();
  52. result.Parent.ID = Job.ID;
  53. result.Parent.Synchronise(Job.ID);
  54. return result;
  55. }
  56. }
  57. }