IDynamicGrid.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. void DoChanged();
  31. void InitialiseEditorForm(IDynamicEditorForm editor, object[] items, Func<Type, CoreTable>? pageDataHandler = null, bool preloadPages = false);
  32. bool EditItems(object[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false);
  33. //bool DirectEdit(CoreTable data);
  34. event OnFilterRecord OnFilterRecord;
  35. event OnCreateItem OnCreateItem;
  36. event OnDoubleClick? OnDoubleClick;
  37. delegate void ReconfigureEvent(FluentList<DynamicGridOption> options);
  38. event ReconfigureEvent? OnReconfigure;
  39. public abstract void Reconfigure();
  40. /// <summary>
  41. /// Add <paramref name="onReconfigure"/> to <see cref="OnReconfigure"/>, and then call <see cref="Reconfigure"/>.
  42. /// </summary>
  43. /// <remarks>
  44. /// Probably should only be called once per grid, otherwise there will be multiple event handlers bound.<br/>
  45. /// If you want to reconfigure without specifiying
  46. /// a new reconfigure event, use <see cref="Reconfigure"/>.
  47. /// </remarks>
  48. /// <param name="onReconfigure"></param>
  49. public void Reconfigure(ReconfigureEvent onReconfigure);
  50. public bool HasOption(DynamicGridOption option);
  51. void AddVisualFilter(string column, string value, FilterType filtertype = FilterType.Contains);
  52. Button AddButton(string? caption, BitmapImage? image, string? tooltip, DynamicGridButtonClickEvent action, DynamicGridButtonPosition position = DynamicGridButtonPosition.Left);
  53. Button AddButton(string? caption, BitmapImage? image, DynamicGridButtonClickEvent action, DynamicGridButtonPosition position = DynamicGridButtonPosition.Left);
  54. void UpdateButton(Button button, BitmapImage? image, string? text, string? tooltip = null);
  55. event OnDefineFilter OnDefineFilter;
  56. event OnPrintData OnPrintData;
  57. event OnCustomiseColumns OnCustomiseColumns;
  58. event BeforeRefreshEventHandler BeforeRefresh;
  59. event AfterRefreshEventHandler AfterRefresh;
  60. event EntitySaveEvent? OnAfterSave;
  61. event EntitySaveEvent? OnBeforeSave;
  62. int DesiredWidth();
  63. void ConfigureColumns(DynamicGridColumns columns /*, bool dolookups */);
  64. void AddHiddenColumn(string column);
  65. void UpdateRow<TType>(CoreRow row, string column, TType value, bool refresh = true);
  66. void UpdateRow<T, TType>(CoreRow row, Expression<Func<T, TType>> column, TType value, bool refresh = true);
  67. }
  68. public interface IDynamicGrid<T> : IDynamicGrid
  69. where T : BaseObject, new()
  70. {
  71. T CreateItem();
  72. T LoadItem(CoreRow row);
  73. void SaveItem(T item);
  74. void SaveItems(T[] items);
  75. void DeleteItems(CoreRow[] rows);
  76. bool EditItems(T[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false);
  77. }