DynamicFormControlGrid.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 DoReconfigure(DynamicGridOptions options)
  16. {
  17. base.DoReconfigure(options);
  18. options.RecordCount = true;
  19. }
  20. public List<T> Items { get; set; }
  21. public override void DeleteItems(params CoreRow[] rows)
  22. {
  23. var items = new List<DFLayoutControl>();
  24. foreach (var row in rows)
  25. items.Add(Items[row.Index]);
  26. Items.RemoveAll(x => items.Contains(x));
  27. }
  28. public override T LoadItem(CoreRow row)
  29. {
  30. return Items[row.Index];
  31. }
  32. protected override void Reload(
  33. Filters<T> criteria, Columns<T> columns, ref SortOrder<T>? sort,
  34. CancellationToken token, Action<CoreTable?, Exception?> action)
  35. {
  36. var table = new CoreTable();
  37. table.LoadColumns(typeof(T));
  38. table.LoadRows(Items.OrderBy(x => x.Sequence));
  39. action?.Invoke(table, null);
  40. }
  41. public override void SaveItem(T item)
  42. {
  43. if (!Items.Contains(item))
  44. Items.Add(item);
  45. }
  46. }
  47. }