MasterDetailGridPage.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections.Generic;
  2. using InABox.Core;
  3. using InABox.DynamicGrid;
  4. namespace InABox.Wpf;
  5. public abstract class MasterDetailGridPage<TMaster, TGrid, TDetail> : MasterDetailPage<TMaster>
  6. where TGrid : DynamicGrid<TDetail>, IDataModelSource, IMasterDetailControl<TMaster,TDetail>, new()
  7. where TDetail : BaseObject, new()
  8. {
  9. public TGrid? Grid { get; set; }
  10. public MasterDetailGridPage(DynamicTabItem tab) : base(tab)
  11. {
  12. }
  13. public override Dictionary<string, object[]>? Selected()
  14. {
  15. return Grid is not null
  16. ? new Dictionary<string, object[]>
  17. {
  18. { typeof(TDetail).EntityName(), Grid.SelectedRows }
  19. }
  20. : null;
  21. }
  22. protected abstract void DoRefresh(TGrid grid, bool columns);
  23. public override IDataModelSource DataModelSource() => CheckGrid();
  24. private IDataModelSource CheckGrid()
  25. {
  26. if (Grid == null)
  27. {
  28. Grid = new TGrid();
  29. Tab.Content = Grid;
  30. }
  31. return Grid;
  32. }
  33. protected override IDataModelSource Refresh()
  34. {
  35. bool bFirst = Grid == null;
  36. CheckGrid();
  37. Grid.Master = Master;
  38. DoRefresh(Grid,bFirst);
  39. return Grid;
  40. }
  41. }