ProductGroup.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using InABox.Clients;
  5. using InABox.Core;
  6. namespace Comal.Classes
  7. {
  8. [UserTracking(typeof(Product))]
  9. public class ProductGroup : Entity, IRemotable, IPersistent, ILicense<ProductManagementLicense>, IExportable, IImportable, IMergeable
  10. {
  11. [EditorSequence(1)]
  12. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  13. public string Code { get; set; }
  14. [EditorSequence(2)]
  15. [TextBoxEditor]
  16. public string Description { get; set; }
  17. private class ProductGroupLookup : LookupDefinitionGenerator<ProductGroup, ProductGroup>
  18. {
  19. public override Filter<ProductGroup> DefineFilter(ProductGroup[] items)
  20. {
  21. if (items?.Any() != true || items.All(x => x.ID == Guid.Empty))
  22. return LookupFactory.DefineFilter<ProductGroup>();
  23. var data = Client.Query(
  24. null,
  25. Columns.None<ProductGroup>().Add(x => x.ID).Add(x => x.Parent.ID));
  26. var nodes = new CoreTreeNodes();
  27. nodes.Load<ProductGroup>(data, x => x.ID, x => x.Parent.ID);
  28. var exclusions = items.SelectMany(x => nodes.GetChildren(x.ID)).ToArray();
  29. var ids = exclusions.Select(x => x.ID).ToArray();
  30. return new Filter<ProductGroup>(x => x.ID).NotInList(ids);
  31. }
  32. public override Columns<ProductGroup> DefineFilterColumns()
  33. => Columns.None<ProductGroup>().Add(x => x.ID).Add(x => x.Parent.ID).Add(x => x.Code);
  34. }
  35. [LookupDefinition(typeof(ProductGroupLookup))]
  36. [EditorSequence(3)]
  37. public ProductGroupLink Parent { get; set; }
  38. public override string ToString()
  39. {
  40. return string.Format("{0}: {1}", Code, Description);
  41. }
  42. }
  43. }