ProductGroupTreeView.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Comal.Classes;
  2. using InABox.Clients;
  3. using InABox.Core;
  4. using InABox.DynamicGrid;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Linq.Expressions;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace PRSDesktop;
  12. public class ProductGroupTreeView : DynamicTreeView<ProductGroup>
  13. {
  14. protected override Expression<Func<ProductGroup, Guid>> ID => x => x.ID;
  15. protected override Expression<Func<ProductGroup, Guid>> ParentID => x => x.Parent.ID;
  16. protected override Expression<Func<ProductGroup, string>> Description => x => x.Description;
  17. public Columns<ProductGroup> AdditionalColumns { get; } = new Columns<ProductGroup>();
  18. protected override void DoRefresh(Action<CoreTable?, Exception?> action)
  19. {
  20. Client.Query(
  21. null,
  22. new Columns<ProductGroup>(x => x.ID)
  23. .Add(x => x.Description)
  24. .Add(x => x.Parent.ID)
  25. .Add(AdditionalColumns),
  26. null,
  27. action);
  28. }
  29. protected override ProductGroup? DoLoadItem(Guid id)
  30. {
  31. return Client.Query(
  32. new Filter<ProductGroup>(x => x.ID).IsEqualTo(id),
  33. DynamicGridUtils.LoadEditorColumns(new Columns<ProductGroup>(x => x.ID)))
  34. .ToObjects<ProductGroup>().FirstOrDefault();
  35. }
  36. protected override void DoSaveItem(ProductGroup item)
  37. {
  38. Client.Save(item, "Edited by user.");
  39. }
  40. protected override bool DoDeleteItem(Guid id)
  41. {
  42. Client.Delete(new ProductGroup() { ID = id }, "Deleted by User");
  43. return true;
  44. }
  45. }