JobFormGrid.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using InABox.DynamicGrid;
  6. using InABox.WPF;
  7. using InABox.Wpf;
  8. using System.Threading;
  9. namespace PRSDesktop
  10. {
  11. public class JobFormGrid : DynamicEntityFormGrid<JobForm, Job, JobLink>, IMasterDetailControl<Job,JobForm>, IDataModelSource
  12. {
  13. protected override Job Entity { get => Master; set => Master = value; }
  14. public Job? Master { get; set; }
  15. public Filter<JobForm> MasterDetailFilter => (Master?.ID ?? Guid.Empty) != Guid.Empty
  16. ? new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(Master.ID)
  17. : new Filter<JobForm>().None();
  18. public event DataModelUpdateEvent? OnUpdateDataModel;
  19. public string SectionName => "Job Forms";
  20. public DataModel DataModel(Selection selection)
  21. {
  22. var ids = ExtractValues(x => x.ID, selection).ToArray();
  23. return new AutoDataModel<JobForm>(new Filter<JobForm>(x => x.ID).InList(ids));
  24. }
  25. public JobFormGrid()
  26. {
  27. }
  28. protected override void DoReconfigure(DynamicGridOptions options)
  29. {
  30. base.DoReconfigure(options);
  31. options.SelectColumns = true;
  32. options.FilterRows = true;
  33. }
  34. protected override void Reload(
  35. Filters<JobForm> criteria, Columns<JobForm> columns, ref SortOrder<JobForm>? sort,
  36. CancellationToken token, Action<CoreTable?, Exception?> action)
  37. {
  38. criteria.Add(MasterDetailFilter);
  39. base.Reload(criteria, columns, ref sort, token, action);
  40. }
  41. protected override bool CanCreateItems()
  42. {
  43. return base.CanCreateItems() && Master != null;
  44. }
  45. protected override void OnFormCreated(JobForm form)
  46. {
  47. base.OnFormCreated(form);
  48. if (DynamicFormEditWindow.EditDigitalForm(form, out var dataModel))
  49. {
  50. dataModel.Update(null);
  51. }
  52. }
  53. public override JobForm CreateItem()
  54. {
  55. var result = base.CreateItem();
  56. result.Parent.ID = Master?.ID ?? Guid.Empty;
  57. result.Parent.Synchronise(Master ?? new Job());
  58. return result;
  59. }
  60. }
  61. }