DynamicFormControlGrid.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using InABox.Clients;
  6. using InABox.Core;
  7. namespace InABox.DynamicGrid
  8. {
  9. public class FormControlGrid<T> : DynamicGrid<T> where T : DFLayoutControl, new()
  10. {
  11. public FormControlGrid()
  12. {
  13. Items = new List<T>();
  14. }
  15. protected override void Init()
  16. {
  17. }
  18. protected override void DoReconfigure(DynamicGridOptions options)
  19. {
  20. options.RecordCount = true;
  21. }
  22. public List<T> Items { get; set; }
  23. public override void DeleteItems(params CoreRow[] rows)
  24. {
  25. var items = new List<DFLayoutControl>();
  26. foreach (var row in rows)
  27. items.Add(Items[row.Index]);
  28. Items.RemoveAll(x => items.Contains(x));
  29. }
  30. public override T LoadItem(CoreRow row)
  31. {
  32. return Items[row.Index];
  33. }
  34. protected override void Reload(
  35. Filters<T> criteria, Columns<T> columns, ref SortOrder<T>? sort,
  36. CancellationToken token, Action<CoreTable?, Exception?> action)
  37. {
  38. var table = new CoreTable();
  39. table.LoadColumns(typeof(T));
  40. table.LoadRows(Items.OrderBy(x => x.Sequence));
  41. action?.Invoke(table, null);
  42. }
  43. public override void SaveItem(T item)
  44. {
  45. if (!Items.Contains(item))
  46. Items.Add(item);
  47. }
  48. }
  49. }