DynamicFormControlGrid.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using InABox.Clients;
  5. using InABox.Core;
  6. namespace InABox.DynamicGrid
  7. {
  8. public class FormControlGrid<T> : DynamicGrid<T> where T : DFLayoutControl, new()
  9. {
  10. public FormControlGrid()
  11. {
  12. Items = new List<T>();
  13. }
  14. protected override void Init()
  15. {
  16. }
  17. protected override void DoReconfigure(DynamicGridOptions options)
  18. {
  19. options.RecordCount = 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(Filters<T> criteria, Columns<T> columns, ref SortOrder<T>? sort, Action<CoreTable?, Exception?> action)
  34. {
  35. var table = new CoreTable();
  36. table.LoadColumns(typeof(T));
  37. table.LoadRows(Items.OrderBy(x => x.Sequence));
  38. action?.Invoke(table, null);
  39. }
  40. public override void SaveItem(T item)
  41. {
  42. if (!Items.Contains(item))
  43. Items.Add(item);
  44. }
  45. }
  46. }