StockSummaryProductGroupTree.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Comal.Classes;
  2. using InABox.Core;
  3. using InABox.DynamicGrid;
  4. using InABox.WPF;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Media.Imaging;
  11. namespace PRSDesktop;
  12. public class StockSummaryProductGroupTree : DynamicSelectorGrid<ProductGroup>, ISpecificGrid
  13. {
  14. public StockSummaryProductGroupTree() : base(DynamicActionColumnPosition.End)
  15. {
  16. ColumnsTag = "StockSummaryProductGroupSelector";
  17. }
  18. public override DynamicGridColumns GenerateColumns()
  19. {
  20. var columns = new DynamicGridColumns();
  21. columns.Add<ProductGroup, string>(x => x.Description, 0, "Description", "", Alignment.MiddleLeft);
  22. return columns;
  23. }
  24. public IEnumerable<Guid> GetSelectedGroups(bool recursive) =>
  25. recursive
  26. ? SelectedIDs.SelectMany(x => UIComponent.GetChildren(x).Select(x => x.Get<ProductGroup, Guid>(x => x.ID)))
  27. : SelectedIDs;
  28. private DynamicGridTreeUIComponent<ProductGroup>? _uiComponent;
  29. private DynamicGridTreeUIComponent<ProductGroup> UIComponent
  30. {
  31. get
  32. {
  33. if(_uiComponent is null)
  34. {
  35. _uiComponent = new DynamicGridTreeUIComponent<ProductGroup>(
  36. x => x.ID,
  37. x => x.Parent.ID)
  38. {
  39. Parent = this,
  40. ExpandMode = DynamicTreeGridExpandMode.All
  41. };
  42. }
  43. return _uiComponent;
  44. }
  45. }
  46. protected override IDynamicGridUIComponent<ProductGroup> CreateUIComponent()
  47. {
  48. return UIComponent;
  49. }
  50. }