IDynamicGrid.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #define scrolling
  2. //#define newgrid
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq.Expressions;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Imaging;
  10. using InABox.Core;
  11. using Syncfusion.Data;
  12. namespace InABox.DynamicGrid;
  13. public enum DynamicGridButtonPosition
  14. {
  15. Left,
  16. Right
  17. }
  18. public interface IBaseDynamicGrid
  19. {
  20. bool IsReady { get; }
  21. Thickness Margin { get; set; }
  22. DynamicGridColumns VisibleColumns { get; }
  23. DynamicActionColumns ActionColumns { get; }
  24. IList<DynamicColumnBase> ColumnList { get; }
  25. CoreTable Data { get; set; }
  26. CoreRow[] SelectedRows { get; set; }
  27. double RowHeight { get; set; }
  28. double HeaderHeight { get; set; }
  29. double FontSize { get; set; }
  30. void Refresh(bool columns, bool data);
  31. /// <summary>
  32. /// To be called when the grid is no longer needed.
  33. /// </summary>
  34. /// <remarks>
  35. /// <b>Note:</b> There is no requirement to call this method, it just allows the grid to decide to stop loading data.
  36. /// </remarks>
  37. void Shutdown();
  38. void DoChanged();
  39. event OnFilterRecord OnFilterRecord;
  40. event OnDoubleClick? OnDoubleClick;
  41. delegate void ReconfigureEvent(DynamicGridOptions options);
  42. event ReconfigureEvent? OnReconfigure;
  43. public abstract void Reconfigure();
  44. /// <summary>
  45. /// Add <paramref name="onReconfigure"/> to <see cref="OnReconfigure"/>, and then call <see cref="Reconfigure"/>.
  46. /// </summary>
  47. /// <remarks>
  48. /// Probably should only be called once per grid, otherwise there will be multiple event handlers bound.<br/>
  49. /// If you want to reconfigure without specifiying
  50. /// a new reconfigure event, use <see cref="Reconfigure"/>.
  51. /// </remarks>
  52. /// <param name="onReconfigure"></param>
  53. public void Reconfigure(ReconfigureEvent onReconfigure);
  54. public DynamicGridOptions Options { get; }
  55. void AddVisualFilter(string column, string value, FilterType filtertype = FilterType.Contains);
  56. Button AddButton(string? caption, ImageSource? image, string? tooltip, DynamicGridButtonClickEvent action, DynamicGridButtonPosition position = DynamicGridButtonPosition.Left);
  57. Button AddButton(string? caption, ImageSource? image, DynamicGridButtonClickEvent action, DynamicGridButtonPosition position = DynamicGridButtonPosition.Left);
  58. void UpdateButton(Button button, ImageSource? image, string? text, string? tooltip = null);
  59. event OnPrintData OnPrintData;
  60. event BeforeRefreshEventHandler BeforeRefresh;
  61. event AfterRefreshEventHandler AfterRefresh;
  62. int DesiredWidth();
  63. void UpdateRow<TType>(CoreRow row, string column, TType value, bool refresh = true);
  64. void UpdateRow<T, TType>(CoreRow row, Expression<Func<T, TType>> column, TType value, bool refresh = true);
  65. void InvalidateRow(CoreRow row);
  66. object? GetData(CoreRow row, DynamicColumnBase column);
  67. IDynamicGridColumnFilter? GetColumnFilter(DynamicColumnBase column);
  68. CoreRow GetVisibleRow(int index);
  69. }
  70. public interface IDynamicGrid : IBaseDynamicGrid
  71. {
  72. event OnCreateItem OnCreateItem;
  73. event EntitySaveEvent? OnAfterSave;
  74. event EntitySaveEvent? OnBeforeSave;
  75. event GenerateColumnsEvent? OnGenerateColumns;
  76. event SaveColumnsEvent? OnSaveColumns;
  77. event GetAvailableColumnsEvent? GetAvailableColumns;
  78. event OnDefineFilter OnDefineFilter;
  79. event OnCustomiseEditor? OnCustomiseEditor;
  80. event OnAfterEditorValueChanged? OnAfterEditorValueChangedEvent;
  81. DynamicGridColumns MasterColumns { get; }
  82. void AddHiddenColumn(string column);
  83. void InitialiseEditorForm(IDynamicEditorForm editor, object[] items, Func<Type, CoreTable>? pageDataHandler = null, bool preloadPages = false);
  84. bool EditItems(object[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false);
  85. DynamicGridColumns ExtractColumns(IColumns columns);
  86. }
  87. public interface IDynamicGrid<T> : IDynamicGrid
  88. where T : BaseObject, new()
  89. {
  90. event OnCustomiseEditor<T>? OnCustomiseEditor;
  91. T CreateItem();
  92. T LoadItem(CoreRow row);
  93. void SaveItem(T item);
  94. void SaveItems(IEnumerable<T> items);
  95. void DeleteItems(CoreRow[] rows);
  96. bool EditItems(T[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false);
  97. /// <summary>
  98. /// Update/sync the data in <paramref name="rows"/> with that of <paramref name="objs"/>.
  99. /// </summary>
  100. void UpdateRows(CoreRow[] rows, T[] objs, bool invalidateRows = true);
  101. }