IDynamicGrid.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.Imaging;
  9. using InABox.Core;
  10. using Syncfusion.Data;
  11. namespace InABox.DynamicGrid;
  12. public enum DynamicGridButtonPosition
  13. {
  14. Left,
  15. Right
  16. }
  17. public interface IDynamicGrid
  18. {
  19. bool IsReady { get; }
  20. Thickness Margin { get; set; }
  21. DynamicGridColumns MasterColumns { get; }
  22. DynamicGridColumns VisibleColumns { get; }
  23. DynamicActionColumns ActionColumns { get; }
  24. CoreTable Data { get; set; }
  25. CoreRow[] SelectedRows { get; set; }
  26. double RowHeight { get; set; }
  27. double HeaderHeight { get; set; }
  28. double FontSize { get; set; }
  29. void Refresh(bool columns, bool data);
  30. /// <summary>
  31. /// To be called when the grid is no longer needed.
  32. /// </summary>
  33. /// <remarks>
  34. /// <b>Note:</b> There is no requirement to call this method, it just allows the grid to decide to stop loading data.
  35. /// </remarks>
  36. void Shutdown();
  37. void DoChanged();
  38. void InitialiseEditorForm(IDynamicEditorForm editor, object[] items, Func<Type, CoreTable>? pageDataHandler = null, bool preloadPages = false);
  39. bool EditItems(object[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false);
  40. //bool DirectEdit(CoreTable data);
  41. event OnFilterRecord OnFilterRecord;
  42. event OnCreateItem OnCreateItem;
  43. event OnDoubleClick? OnDoubleClick;
  44. delegate void ReconfigureEvent(DynamicGridOptions options);
  45. event ReconfigureEvent? OnReconfigure;
  46. public abstract void Reconfigure();
  47. /// <summary>
  48. /// Add <paramref name="onReconfigure"/> to <see cref="OnReconfigure"/>, and then call <see cref="Reconfigure"/>.
  49. /// </summary>
  50. /// <remarks>
  51. /// Probably should only be called once per grid, otherwise there will be multiple event handlers bound.<br/>
  52. /// If you want to reconfigure without specifiying
  53. /// a new reconfigure event, use <see cref="Reconfigure"/>.
  54. /// </remarks>
  55. /// <param name="onReconfigure"></param>
  56. public void Reconfigure(ReconfigureEvent onReconfigure);
  57. public DynamicGridOptions Options { get; }
  58. void AddVisualFilter(string column, string value, FilterType filtertype = FilterType.Contains);
  59. Button AddButton(string? caption, BitmapImage? image, string? tooltip, DynamicGridButtonClickEvent action, DynamicGridButtonPosition position = DynamicGridButtonPosition.Left);
  60. Button AddButton(string? caption, BitmapImage? image, DynamicGridButtonClickEvent action, DynamicGridButtonPosition position = DynamicGridButtonPosition.Left);
  61. void UpdateButton(Button button, BitmapImage? image, string? text, string? tooltip = null);
  62. event OnDefineFilter OnDefineFilter;
  63. event OnPrintData OnPrintData;
  64. event BeforeRefreshEventHandler BeforeRefresh;
  65. event AfterRefreshEventHandler AfterRefresh;
  66. event EntitySaveEvent? OnAfterSave;
  67. event EntitySaveEvent? OnBeforeSave;
  68. int DesiredWidth();
  69. void AddHiddenColumn(string column);
  70. void UpdateRow<TType>(CoreRow row, string column, TType value, bool refresh = true);
  71. void UpdateRow<T, TType>(CoreRow row, Expression<Func<T, TType>> column, TType value, bool refresh = true);
  72. void InvalidateRow(CoreRow row);
  73. }
  74. public interface IDynamicGrid<T> : IDynamicGrid
  75. where T : BaseObject, new()
  76. {
  77. T CreateItem();
  78. T LoadItem(CoreRow row);
  79. void SaveItem(T item);
  80. void SaveItems(T[] items);
  81. void DeleteItems(CoreRow[] rows);
  82. bool EditItems(T[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false);
  83. }