DynamicFormControlGrid.cs 1.5 KB

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