JobFormGrid.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. EditOnAdd = true;
  34. }
  35. protected override void Reload(
  36. Filters<JobForm> criteria, Columns<JobForm> columns, ref SortOrder<JobForm>? sort,
  37. CancellationToken token, Action<CoreTable?, Exception?> action)
  38. {
  39. criteria.Add(MasterDetailFilter);
  40. base.Reload(criteria, columns, ref sort, token, action);
  41. }
  42. protected override bool CanCreateItems()
  43. {
  44. return base.CanCreateItems() && Master != null;
  45. }
  46. public override JobForm CreateItem()
  47. {
  48. var result = base.CreateItem();
  49. result.Parent.ID = Master?.ID ?? Guid.Empty;
  50. result.Parent.Synchronise(Master ?? new Job());
  51. return result;
  52. }
  53. }
  54. }