DynamicItemsListGrid.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using InABox.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace InABox.DynamicGrid
  8. {
  9. public interface IDynamicItemsListGrid
  10. {
  11. }
  12. public class DynamicItemsListGrid<T> : DynamicGrid<T>, IDynamicItemsListGrid
  13. where T : BaseObject, new()
  14. {
  15. public List<T> Items { get; set; }
  16. public DynamicItemsListGrid() : this(new()) { }
  17. public DynamicItemsListGrid(List<T> items) : base()
  18. {
  19. Items = items;
  20. }
  21. protected override void DeleteItems(params CoreRow[] rows)
  22. {
  23. foreach (var row in rows.OrderByDescending(x => x.Index))
  24. {
  25. Items.RemoveAt(_recordmap[row].Index);
  26. }
  27. }
  28. protected override T LoadItem(CoreRow row)
  29. {
  30. return Items[_recordmap[row].Index];
  31. }
  32. protected override void Reload(Filters<T> criteria, Columns<T> columns, ref SortOrder<T>? sort, Action<CoreTable?, Exception?> action)
  33. {
  34. var result = new CoreTable();
  35. result.LoadColumns(typeof(T));
  36. result.LoadRows(Items);
  37. action.Invoke(result, null);
  38. }
  39. public override void SaveItem(T item)
  40. {
  41. if (!Items.Contains(item))
  42. {
  43. Items.Add(item);
  44. }
  45. }
  46. }
  47. }