DynamicFormControlGrid.cs 1.3 KB

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