DynamicGrid.cs 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Globalization;
  7. using System.Linq;
  8. using System.Linq.Expressions;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Animation;
  16. using System.Windows.Media.Imaging;
  17. using InABox.Clients;
  18. using InABox.Core;
  19. using InABox.Wpf;
  20. using InABox.WPF;
  21. using Syncfusion.Data;
  22. using Syncfusion.UI.Xaml.Grid;
  23. using Syncfusion.UI.Xaml.Grid.Helpers;
  24. using static InABox.DynamicGrid.IDynamicGrid;
  25. using Color = System.Drawing.Color;
  26. using Columns = InABox.Core.Columns;
  27. using Image = System.Windows.Controls.Image;
  28. using RowColumnIndex = Syncfusion.UI.Xaml.ScrollAxis.RowColumnIndex;
  29. using SolidColorBrush = System.Windows.Media.SolidColorBrush;
  30. using String = System.String;
  31. using VerticalAlignment = System.Windows.VerticalAlignment;
  32. using VirtualizingCellsControl = Syncfusion.UI.Xaml.Grid.VirtualizingCellsControl;
  33. using System.Threading;
  34. using System.Diagnostics.CodeAnalysis;
  35. namespace InABox.DynamicGrid;
  36. public abstract class DynamicGrid<T> : BaseDynamicGrid, IDynamicGridUIComponentParent<T>, IDynamicGrid<T>,
  37. IImportDynamicGrid, IExportDynamicGrid, IDuplicateDynamicGrid, IHelpDynamicGrid
  38. where T : BaseObject, new()
  39. {
  40. #region Events
  41. public ValidateEvent<T>? OnValidate { get; set; }
  42. public event OnDefineFilter? OnDefineFilter;
  43. public event OnCreateItem? OnCreateItem;
  44. public event OnAfterCreateItem? OnAfterCreateItem;
  45. public event EditorValueChangedHandler? OnEditorValueChanged;
  46. public event OnCustomiseEditor<T>? OnCustomiseEditor;
  47. public event EntitySaveEvent? OnBeforeSave;
  48. public event EntitySaveEvent? OnAfterSave;
  49. public delegate void EditorLoaded(IDynamicEditorForm editor, T[] items);
  50. public event EditorLoaded? OnEditorLoaded;
  51. public event OnLoadEditorButtons<T>? OnLoadEditorButtons;
  52. #endregion
  53. protected virtual string HelpSlug()
  54. {
  55. return typeof(T).Name.Split('.').Last().SplitCamelCase().Replace(" ", "_");
  56. }
  57. string IHelpDynamicGrid.HelpSlug() => HelpSlug();
  58. protected override bool CanDuplicate => typeof(T).IsAssignableTo(typeof(IDuplicatable));
  59. public DynamicGrid() : base()
  60. {
  61. }
  62. protected sealed override void PreInit()
  63. {
  64. MasterColumns = new DynamicGridColumns();
  65. MasterColumns.ExtractColumns(typeof(T));
  66. HiddenColumns = new HiddenColumnsList();
  67. if (typeof(T).IsAssignableTo(typeof(ISequenceable)))
  68. {
  69. HiddenColumns.Add(x => (x as ISequenceable)!.Sequence);
  70. }
  71. }
  72. protected override void Init()
  73. {
  74. }
  75. #region IDynamicGridUIComponentParent
  76. protected override IDynamicGridUIComponent CreateUIComponent()
  77. {
  78. return new DynamicGridGridUIComponent<T>
  79. {
  80. Parent = this
  81. };
  82. }
  83. T IDynamicGrid<T>.LoadItem(CoreRow row) => LoadItem(row);
  84. void IDynamicGridUIComponentParent<T>.EntityChanged(T obj, CoreRow row, string changedColumn, Dictionary<string, object?> changes)
  85. => EntityChanged(obj, row, changedColumn, changes);
  86. void IDynamicGridUIComponentParent<T>.UpdateData(T obj, CoreRow row, string changedColumn, Dictionary<CoreColumn, object?> updates)
  87. {
  88. var result = new Dictionary<string, object?>();
  89. foreach (var (col, value) in updates)
  90. {
  91. UpdateRow(row, col.ColumnName, value, refresh: false);
  92. DynamicGridUtils.UpdateEditorValue(new BaseObject[] { obj }, col.ColumnName, value, result);
  93. }
  94. EntityChanged(obj, row, changedColumn, result);
  95. }
  96. #endregion
  97. protected override DynamicGridRowStyleSelector GetRowStyleSelector()
  98. {
  99. return new DynamicGridRowStyleSelector<T, DynamicGridRowStyle>();
  100. }
  101. public DynamicGridColumns MasterColumns { get; protected set; }
  102. public class HiddenColumnsList
  103. {
  104. private List<string> Columns { get; set; } = new();
  105. public IEnumerable<string> ColumnNames => Columns;
  106. public void Add(Expression<Func<T, object?>> column) => Add(CoreUtils.GetFullPropertyName(column, "."));
  107. public void Add(IColumn column) => Add(column.Property);
  108. public void Add(string column)
  109. {
  110. if (!Contains(column))
  111. Columns.Add(column);
  112. }
  113. public bool Contains(string column) => Columns.Contains(column);
  114. }
  115. public void AddHiddenColumn(string column) => HiddenColumns.Add(column);
  116. public HiddenColumnsList HiddenColumns { get; private set; }
  117. private static bool IsSequenced => typeof(T).GetInterfaces().Any(x => x.Equals(typeof(ISequenceable)));
  118. #region Options
  119. protected override void DoReconfigure(DynamicGridOptions options)
  120. {
  121. options.ReorderRows = IsSequenced;
  122. }
  123. #endregion
  124. private void EntityChanged(T obj, CoreRow row, string changedColumn, Dictionary<string, object?> changes)
  125. {
  126. OnAfterEditorValueChanged(null, [obj], new AfterEditorValueChangedArgs(changedColumn, changes), changes);
  127. SaveItem(obj);
  128. foreach (var (key, value) in changes)
  129. {
  130. row[key] = value;
  131. }
  132. GetUIComponent().UpdateRow(row);
  133. }
  134. #region Column Handling
  135. /// <summary>
  136. /// Create a set of <see cref="DynamicGridColumns"/> according to the natural default sizes and formats and captions, based on the contents of <paramref name="columns"/>.
  137. /// </summary>
  138. /// <param name="columns"></param>
  139. /// <returns></returns>
  140. protected DynamicGridColumns ExtractColumns(Columns<T> columns)
  141. {
  142. var cols = new DynamicGridColumns();
  143. foreach (var col in columns)
  144. {
  145. var mc = MasterColumns.FirstOrDefault(x => x.ColumnName.Equals(col.Property));
  146. if (mc != null && mc.Editor is not NullEditor && mc.Editor.Visible != Visible.Hidden)
  147. cols.Add(mc);
  148. }
  149. return cols;
  150. }
  151. DynamicGridColumns IDynamicGrid.ExtractColumns(IColumns columns)
  152. {
  153. var cols = new DynamicGridColumns();
  154. foreach (var col in columns)
  155. {
  156. var mc = MasterColumns.FirstOrDefault(x => x.ColumnName.Equals(col.Property));
  157. if (mc != null && mc.Editor is not NullEditor && mc.Editor.Visible != Visible.Hidden)
  158. cols.Add(mc);
  159. }
  160. return cols;
  161. }
  162. public override DynamicGridColumns GenerateColumns()
  163. {
  164. var cols = IsDirectEditMode()
  165. ? new Columns<T>(ColumnTypeFlags.IncludeVisible | ColumnTypeFlags.IncludeForeignKeys)
  166. : new Columns<T>(ColumnTypeFlags.IncludeVisible | ColumnTypeFlags.IncludeLinked);
  167. var columns = ExtractColumns(cols);
  168. OnGenerateColumns?.Invoke(this, new GenerateColumnsEventArgs(columns));
  169. return columns;
  170. }
  171. public event GenerateColumnsEvent? OnGenerateColumns;
  172. public event SaveColumnsEvent? OnSaveColumns;
  173. public event GetAvailableColumnsEvent? GetAvailableColumns;
  174. protected override void SaveColumns(DynamicGridColumns columns)
  175. {
  176. OnSaveColumns?.Invoke(this, new(columns));
  177. }
  178. #endregion
  179. #region Refresh / Reload
  180. protected abstract void Reload(
  181. Filters<T> criteria, Columns<T> columns, ref SortOrder<T>? sort,
  182. CancellationToken token, Action<CoreTable?, Exception?> action);
  183. public Filter<T>? DefineFilter()
  184. {
  185. if (OnDefineFilter is null)
  186. return null;
  187. var result = OnDefineFilter.Invoke(typeof(T)) as Filter<T>;
  188. return result;
  189. }
  190. public IEnumerable<TType> ExtractValues<TType>(Expression<Func<T, TType>> column, Selection selection)
  191. {
  192. var result = selection == Selection.None
  193. ? Enumerable.Empty<TType>()
  194. : selection == Selection.Selected
  195. ? SelectedRows.Select(r => r.Get(column))
  196. : Data.ExtractValues(column);
  197. return result;
  198. }
  199. protected override void ReloadData(CancellationToken token, Action<CoreTable?, Exception?> action)
  200. {
  201. _lookupcache.Clear();
  202. var criteria = new Filters<T>();
  203. var filter = DefineFilter();
  204. if (filter != null)
  205. criteria.Add(filter);
  206. var columns = DataColumns();
  207. var sort = LookupFactory.DefineSort<T>();
  208. if (sort == null && IsSequenced)
  209. sort = new SortOrder<T>("Sequence");
  210. Reload(criteria, columns, ref sort, token, action);
  211. }
  212. public Columns<T> DataColumns()
  213. {
  214. var columns = Columns.None<T>();
  215. foreach (var column in VisibleColumns)
  216. columns.Add(column.ColumnName);
  217. foreach (var column in HiddenColumns.ColumnNames)
  218. columns.Add(new Column<T>(column));
  219. if (!Options.ReadOnly)
  220. {
  221. foreach (var column in LookupFactory.RequiredColumns<T>())
  222. {
  223. columns.Add(column);
  224. }
  225. }
  226. return columns;
  227. }
  228. public void UpdateRow(CoreRow row, T obj, bool invalidateRow = true)
  229. {
  230. ObjectToRow(obj, row);
  231. ObjectToRow(obj, _recordmap[row]);
  232. if (invalidateRow)
  233. {
  234. InvalidateRow(row);
  235. }
  236. }
  237. public void UpdateRows(CoreRow[] rows, T[] objs, bool invalidateRows = true)
  238. {
  239. for(var i = 0; i < objs.Length; ++i)
  240. {
  241. UpdateRow(rows[i], objs[i], invalidateRow: invalidateRows);
  242. }
  243. }
  244. public void AddRow(T data)
  245. {
  246. if (MasterData is null) return;
  247. MasterData.LoadRow(data);
  248. Refresh(false, false);
  249. }
  250. #endregion
  251. #region Item Manipulation
  252. #region Load/Save/Delete
  253. public virtual T[] LoadItems(IList<CoreRow> rows)
  254. {
  255. return rows.ToArray(LoadItem);
  256. }
  257. public abstract T LoadItem(CoreRow row);
  258. public abstract void SaveItem(T item);
  259. public virtual void SaveItems(IEnumerable<T> items)
  260. {
  261. foreach (var item in items)
  262. SaveItem(item);
  263. }
  264. protected virtual bool CanDeleteItems(params CoreRow[] rows)
  265. {
  266. return true;
  267. }
  268. public abstract void DeleteItems(params CoreRow[] rows);
  269. protected override bool CanDeleteRows(params CoreRow[] rows) => CanDeleteItems(rows);
  270. public override void DeleteRows(params CoreRow[] rows) => DeleteItems(rows);
  271. #endregion
  272. #region Edit
  273. protected override void NewRow()
  274. {
  275. CreateItems(null);
  276. }
  277. protected void CreateItems(Func<IEnumerable<T>>? create)
  278. {
  279. var newRows = new List<CoreRow>();
  280. var items = create?.Invoke() ?? CoreUtils.One(CreateItem());
  281. foreach (var item in items)
  282. {
  283. if (!AfterCreate(item))
  284. return;
  285. SaveItem(item);
  286. var datarow = Data.NewRow();
  287. ObjectToRow(item, datarow);
  288. Data.Rows.Add(datarow);
  289. newRows.Add(datarow);
  290. var masterrow = MasterData.NewRow();
  291. ObjectToRow(item, masterrow);
  292. MasterData.Rows.Add(masterrow);
  293. _recordmap[datarow] = masterrow;
  294. }
  295. InvalidateGrid();
  296. SelectedRows = newRows.ToArray();
  297. DoChanged();
  298. }
  299. public virtual DynamicEditorPages LoadEditorPages(T item)
  300. {
  301. DynamicEditorPages pages = new DynamicEditorPages();
  302. DynamicGridUtils.LoadOneToManyPages(typeof(T), pages);
  303. DynamicGridUtils.LoadEnclosedListPages(typeof(T), pages);
  304. DynamicGridUtils.LoadManyToManyPages(typeof(T), pages);
  305. DynamicGridUtils.LoadCustomEditorPages(typeof(T), pages);
  306. pages.RemoveAll(x => !x.Visible);
  307. foreach (var page in pages)
  308. page.Ready = false;
  309. return pages;
  310. }
  311. public virtual void LoadEditorButtons(T item, DynamicEditorButtons buttons)
  312. {
  313. buttons.Clear();
  314. buttons.Add(
  315. "",
  316. Wpf.Resources.help.AsBitmapImage(),
  317. item,
  318. (f, i) =>
  319. {
  320. Process.Start(new ProcessStartInfo("https://prsdigital.com.au/wiki/index.php/" + typeof(T).Name.SplitCamelCase().Replace(" ", "_"))
  321. { UseShellExecute = true });
  322. }
  323. );
  324. OnLoadEditorButtons?.Invoke(item, buttons);
  325. }
  326. protected virtual void BeforeLoad(IDynamicEditorForm form, T[] items)
  327. {
  328. form.BeforeLoad();
  329. }
  330. void IDynamicGrid.InitialiseEditorForm(IDynamicEditorForm editor, object[] items, Func<Type, CoreTable>? pageDataHandler, bool preloadPages)
  331. {
  332. InitialiseEditorForm(editor, items.Cast<T>().ToArray(), pageDataHandler, preloadPages);
  333. }
  334. public virtual bool EditItems(object[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false)
  335. {
  336. var values = items.Cast<T>().ToArray();
  337. return EditItems(values, PageDataHandler, PreloadPages);
  338. }
  339. public virtual void InitialiseEditorForm(IDynamicEditorForm editor, T[] items, Func<Type, CoreTable?>? pageDataHandler = null, bool preloadPages = false)
  340. {
  341. var pages = items.Length == 1 ? LoadEditorPages(items.First()) : new DynamicEditorPages();
  342. var buttons = new DynamicEditorButtons();
  343. if (items.Length == 1)
  344. LoadEditorButtons(items.First(), buttons);
  345. editor.Setup(items.Any() ? items.First().GetType() : typeof(T), pages, buttons, pageDataHandler, preloadPages);
  346. editor.OnCustomiseColumns = (sender, columns) =>
  347. {
  348. columns.Clear();
  349. columns.AddRange(MasterColumns);
  350. };
  351. editor.OnDefineEditor = (o, c) =>
  352. {
  353. var result = GetEditor(o, c);
  354. if (result != null)
  355. result = result.CloneEditor();
  356. return result;
  357. };
  358. editor.OnFormCustomiseEditor += DoCustomiseEditor;
  359. editor.OnDefineFilter = (type, column) => { return DefineLookupFilter(type, column, items); };
  360. //editor.OnDefineFilter += (o, e) => { return DefineFilter(items, e); };
  361. editor.OnDefineLookups = editor => DefineLookups(editor, items);
  362. editor.OnEditorValueChanged += (s, n, v) => EditorValueChanged(editor, items, n, v);
  363. editor.OnAfterEditorValueChanged += (g, args) => AfterEditorValueChanged(g, items, args);
  364. editor.OnReconfigureEditors = g => DoReconfigureEditors(g, items);
  365. editor.OnValidateData += (o, i) => ValidateData(items);
  366. editor.OnSelectPage += SelectPage;
  367. editor.OnSaveItem = (o, e) =>
  368. {
  369. try
  370. {
  371. using var Wait = new WaitCursor();
  372. DoBeforeSave(editor, items);
  373. if (items.Length == 1)
  374. editor.UnloadEditorPages(false);
  375. foreach (var item in items)
  376. SaveItem(item);
  377. if (items.Length == 1)
  378. editor.UnloadEditorPages(true);
  379. DoAfterSave(editor, items);
  380. }
  381. catch (Exception err)
  382. {
  383. MessageBox.Show(err.Message);
  384. e.Cancel = true;
  385. }
  386. };
  387. BeforeLoad(editor, items);
  388. editor.Items = items;
  389. AfterLoad(editor, items);
  390. }
  391. private void DoCustomiseEditor(IDynamicEditorForm sender, object[] items, DynamicGridColumn column, BaseEditor editor)
  392. {
  393. CustomiseEditor(sender, (T[])items, column, editor);
  394. OnCustomiseEditor?.Invoke(sender, (T[])items, column, editor);
  395. }
  396. protected virtual void CustomiseEditor(IDynamicEditorForm form, T[] items, DynamicGridColumn column, BaseEditor editor)
  397. {
  398. }
  399. protected virtual void DoAfterSave(IDynamicEditorForm editor, T[] items)
  400. {
  401. OnAfterSave?.Invoke(editor, items);
  402. }
  403. protected virtual void DoBeforeSave(IDynamicEditorForm editor, T[] items)
  404. {
  405. OnBeforeSave?.Invoke(editor, items);
  406. }
  407. /// <summary>
  408. /// Edit the <paramref name="items"/> with a non-modal editor window, attaching them to the <paramref name="host"/> provided.
  409. /// </summary>
  410. /// <param name="items">List of objects to edit.</param>
  411. /// <param name="callback">A callback for when the items are finished being edited.</param>
  412. public virtual void EditItemsNonModal(ISubPanelHost host, T[] items, Action<T[], bool> callback, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false)
  413. {
  414. if (!DynamicGridUtils.TryEdit(items, out var editLock))
  415. {
  416. if(editLock.Panel is Window window)
  417. {
  418. Task.Delay(100).ContinueWith(task =>
  419. {
  420. window.WindowState = WindowState.Normal;
  421. window.Activate();
  422. }, TaskScheduler.FromCurrentSynchronizationContext());
  423. }
  424. else
  425. {
  426. MessageWindow.ShowMessage("One or more items are already being edited in an open window. You cannot edit the same entity multiple times simultaneously.", "Simultaneous edit.");
  427. }
  428. return;
  429. }
  430. DynamicEditorForm editor;
  431. using (var cursor = new WaitCursor())
  432. {
  433. editor = new DynamicEditorForm();
  434. editor.SetValue(Panel.ZIndexProperty, 999);
  435. editor.Form.DisableOKIfUnchanged = true;
  436. InitialiseEditorForm(editor, items, PageDataHandler, PreloadPages);
  437. OnEditorLoaded?.Invoke(editor, items);
  438. }
  439. editLock.Panel = editor;
  440. host.AddSubPanel(editor);
  441. editor.SubPanelClosed += o =>
  442. {
  443. try
  444. {
  445. DynamicGridUtils.FinishEdit(items);
  446. callback(items, editor.Result == true);
  447. }
  448. catch(Exception e)
  449. {
  450. MessageWindow.ShowError("Error occurred while closing editor.", e);
  451. }
  452. };
  453. editor.Show();
  454. }
  455. /// <summary>
  456. /// Edit the <paramref name="items"/> with a modal editor window.
  457. /// </summary>
  458. /// <param name="items">List of objects to edit.</param>
  459. /// <returns><see langword="true"/> if the items were saved.</returns>
  460. public virtual bool EditItems(T[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false)
  461. {
  462. DynamicEditorForm editor;
  463. using (var cursor = new WaitCursor())
  464. {
  465. editor = new DynamicEditorForm()
  466. {
  467. WindowStartupLocation = WindowStartupLocation.CenterScreen
  468. };
  469. editor.SetValue(Panel.ZIndexProperty, 999);
  470. InitialiseEditorForm(editor, items, PageDataHandler, PreloadPages);
  471. OnEditorLoaded?.Invoke(editor, items);
  472. }
  473. return editor.ShowDialog() == true;
  474. }
  475. private Dictionary<String, object?> AfterEditorValueChanged(DynamicEditorGrid grid, T[] items, AfterEditorValueChangedArgs args)
  476. {
  477. var changes = new Dictionary<string, object?>();
  478. OnAfterEditorValueChanged(grid, items, args, changes);
  479. return changes;
  480. }
  481. protected virtual void OnAfterEditorValueChanged(DynamicEditorGrid? grid, T[] items, AfterEditorValueChangedArgs args, Dictionary<String, object?> changes)
  482. {
  483. }
  484. protected virtual void DoReconfigureEditors(DynamicEditorGrid grid, T[] items)
  485. {
  486. /*if (items.First() is IDimensioned dimensioned)
  487. {
  488. UpdateEditor(grid, x => x.Dimensions.Quantity, dimensioned.Dimensions.GetUnit().HasQuantity);
  489. UpdateEditor(grid, x => x.Dimensions.Length, dimensioned.Dimensions.GetUnit().HasLength);
  490. UpdateEditor(grid, x => x.Dimensions.Width, dimensioned.Dimensions.GetUnit().HasWidth);
  491. UpdateEditor(grid, x => x.Dimensions.Height, dimensioned.Dimensions.GetUnit().HasHeight);
  492. UpdateEditor(grid, x => x.Dimensions.Weight, dimensioned.Dimensions.GetUnit().HasWeight);
  493. }*/
  494. }
  495. private List<string>? ValidateData(T[] items)
  496. {
  497. var errors = new List<string>();
  498. DoValidate(items, errors);
  499. OnValidate?.Invoke(this, items, errors);
  500. return errors.Count != 0 ? errors : null;
  501. }
  502. protected virtual void DoValidate(T[] items, List<string> errors)
  503. {
  504. }
  505. protected virtual void AfterLoad(IDynamicEditorForm editor, T[] items)
  506. {
  507. editor.AfterLoad();
  508. }
  509. protected virtual void SelectPage(object sender, BaseObject[]? items)
  510. {
  511. }
  512. protected virtual Dictionary<string, object?> EditorValueChanged(IDynamicEditorForm editor, T[] items, string name, object value)
  513. {
  514. var result = DynamicGridUtils.UpdateEditorValue(items, name, value);
  515. if (OnEditorValueChanged != null)
  516. {
  517. var newchanges = OnEditorValueChanged(editor, name, value);
  518. foreach (var key in newchanges.Keys)
  519. result[key] = newchanges[key];
  520. }
  521. return result;
  522. }
  523. private readonly Dictionary<Tuple<Type, Type>, Dictionary<object, object>> _lookupcache = new();
  524. protected virtual void DefineLookups(ILookupEditorControl sender, T[] items, bool async = true)
  525. {
  526. if (sender.EditorDefinition is not ILookupEditor editor)
  527. return;
  528. var colname = sender.ColumnName;
  529. if (async)
  530. {
  531. Task.Run(() =>
  532. {
  533. try
  534. {
  535. var values = editor.Values(colname, items);
  536. Dispatcher.Invoke(
  537. () =>
  538. {
  539. try
  540. {
  541. //Logger.Send(LogType.Information, typeof(T).Name, "Dispatching Results" + colname);
  542. sender.LoadLookups(values);
  543. }
  544. catch (Exception e2)
  545. {
  546. Logger.Send(LogType.Information, typeof(T).Name,
  547. "Exception (2) in LoadLookups: " + e2.Message + "\n" + e2.StackTrace);
  548. }
  549. }
  550. );
  551. }
  552. catch (Exception e)
  553. {
  554. Logger.Send(LogType.Information, typeof(T).Name,
  555. "Exception (1) in LoadLookups: " + e.Message + "\n" + e.StackTrace);
  556. }
  557. });
  558. }
  559. else
  560. {
  561. var values = editor.Values(colname, items);
  562. sender.LoadLookups(values);
  563. }
  564. }
  565. /// <summary>
  566. /// Retrieves an editor to display for the given column of <paramref name="item"/>.
  567. /// </summary>
  568. /// <param name="item">The object being edited.</param>
  569. /// <param name="column">The column of the editor.</param>
  570. /// <returns>A new editor, or <see langword="null"/> if no editor defined and no sensible default exists.</returns>
  571. protected virtual BaseEditor? GetEditor(object item, DynamicGridColumn column)
  572. {
  573. return column.Editor ?? DatabaseSchema.Property(item.GetType(), column.ColumnName)?.Editor;
  574. }
  575. protected IFilter? DefineLookupFilter(Type type, string column, T[] items)
  576. {
  577. return LookupFactory.DefineLookupFilter(typeof(T), type, column, items);
  578. }
  579. protected virtual void SetEditorValue(object item, string name, object value)
  580. {
  581. try
  582. {
  583. CoreUtils.SetPropertyValue(item, name, value);
  584. }
  585. catch (Exception e)
  586. {
  587. Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
  588. }
  589. }
  590. protected virtual object? GetEditorValue(object item, string name)
  591. {
  592. return CoreUtils.GetPropertyValue(item, name);
  593. }
  594. protected override bool CanCreateRows() => CanCreateItems();
  595. protected virtual bool CanCreateItems()
  596. {
  597. return true;
  598. }
  599. protected override bool EditRows(CoreRow[]? rows)
  600. {
  601. if(rows is null)
  602. {
  603. if (!CanCreateItems())
  604. return false;
  605. var item = CreateItem();
  606. if (!AfterCreate(item))
  607. return false;
  608. if(Options.NonModalEditorHost is not null)
  609. {
  610. EditItemsNonModal(Options.NonModalEditorHost, [item], (items, result) =>
  611. {
  612. if (result)
  613. {
  614. var row = Data.NewRow();
  615. ObjectToRow(item, row);
  616. Data.Rows.Add(row);
  617. var masterrow = MasterData.NewRow();
  618. ObjectToRow(item, masterrow);
  619. MasterData.Rows.Add(masterrow);
  620. _recordmap[row] = masterrow;
  621. InvalidateGrid();
  622. SelectedRows = [row];
  623. DoChanged();
  624. }
  625. });
  626. return false;
  627. }
  628. else
  629. {
  630. if (EditItems([item]))
  631. {
  632. //_CurrentRow = Data.Rows.Count;
  633. var row = Data.NewRow();
  634. ObjectToRow(item, row);
  635. Data.Rows.Add(row);
  636. var masterrow = MasterData.NewRow();
  637. ObjectToRow(item, masterrow);
  638. MasterData.Rows.Add(masterrow);
  639. _recordmap[row] = masterrow;
  640. InvalidateGrid();
  641. SelectedRows = [row];
  642. DoChanged();
  643. return true;
  644. }
  645. return false;
  646. }
  647. }
  648. else
  649. {
  650. var items = Array.Empty<T>();
  651. using (new WaitCursor())
  652. {
  653. Stopwatch sw = new Stopwatch();
  654. sw.Start();
  655. items = LoadItems(rows);
  656. //Logger.Send(LogType.Information, "DG:LoadItems", String.Format("Loaded Items: {0}ms", sw.ElapsedMilliseconds));
  657. sw.Stop();
  658. }
  659. if (items.Length != 0)
  660. {
  661. var snaps = items.ToArray(x => x.TakeSnapshot());
  662. if(Options.NonModalEditorHost is not null)
  663. {
  664. EditItemsNonModal(Options.NonModalEditorHost, items, (items, result) =>
  665. {
  666. if (result)
  667. {
  668. var sel = SelectedRows;
  669. UpdateRows(rows, items, invalidateRows: false);
  670. InvalidateGrid();
  671. SelectedRows = sel;
  672. DoChanged();
  673. }
  674. else
  675. {
  676. foreach(var snap in snaps)
  677. {
  678. snap.ResetObject();
  679. }
  680. }
  681. });
  682. return false;
  683. }
  684. else
  685. {
  686. if (EditItems(items))
  687. {
  688. var sel = SelectedRows;
  689. UpdateRows(rows, items, invalidateRows: false);
  690. InvalidateGrid();
  691. SelectedRows = sel;
  692. DoChanged();
  693. return true;
  694. }
  695. else
  696. {
  697. foreach(var snap in snaps)
  698. {
  699. snap.ResetObject();
  700. }
  701. }
  702. }
  703. return false;
  704. }
  705. return false;
  706. }
  707. }
  708. #endregion
  709. #region Duplicate
  710. protected virtual IEnumerable<T> LoadDuplicatorItems(CoreRow[] rows)
  711. {
  712. return LoadItems(rows);
  713. }
  714. bool IDuplicateDynamicGrid.DoDuplicate(CoreRow[] rows) => DoDuplicate(rows);
  715. protected virtual bool DoDuplicate(CoreRow[] rows)
  716. {
  717. if (rows.Length == 0)
  718. {
  719. MessageBox.Show("Please select at least one record to duplicate!");
  720. return false;
  721. }
  722. /*var ids = ExtractValues(x => x.ID, Selection.Selected).ToArray();
  723. if (!ids.Any())
  724. {
  725. MessageBox.Show("Please select at least one record to duplicate!");
  726. return false;
  727. }*/
  728. var duplicator = (new T() as IDuplicatable)?.GetDuplicator();
  729. if (duplicator is null)
  730. {
  731. MessageBox.Show($"Cannot duplicate {typeof(T)}");
  732. return false;
  733. }
  734. duplicator.Duplicate(LoadDuplicatorItems(rows));// new Filter<T>(x => x.ID).InList(ids));
  735. return true;
  736. }
  737. #endregion
  738. public virtual T CreateItem()
  739. {
  740. var result = new T();
  741. OnCreateItem?.Invoke(this, result);
  742. return result;
  743. }
  744. public virtual bool AfterCreate(T item)
  745. {
  746. return OnAfterCreateItem?.Invoke(this, item) ?? true;
  747. }
  748. protected void ReloadForms<TTargetType, TTargetForm, TSourceForm>(IDynamicEditorForm editor, TTargetType item,
  749. Expression<Func<TSourceForm, object?>> sourcekey, Guid sourceid)
  750. where TTargetType : Entity, new()
  751. where TTargetForm : Entity, IRemotable, IPersistent, IDigitalFormInstance, new()
  752. where TSourceForm : Entity, IRemotable, IPersistent, IDigitalForm<TTargetType>, new()
  753. {
  754. var type = typeof(IDynamicOneToManyGrid<,>).MakeGenericType(typeof(TTargetType), typeof(TTargetForm));
  755. var page =
  756. editor.Pages?.FirstOrDefault(x => x.GetType().GetInterfaces().Contains(type)) as IDynamicOneToManyGrid<TTargetType, TTargetForm>;
  757. if (page != null && item != null)
  758. {
  759. if (!page.Ready)
  760. page.Load(item, null);
  761. CoreTable table;
  762. if (sourceid == Guid.Empty)
  763. {
  764. table = new CoreTable();
  765. table.LoadColumns(typeof(TSourceForm));
  766. }
  767. else
  768. {
  769. table = new Client<TSourceForm>().Query(
  770. new Filter<TSourceForm>(sourcekey).IsEqualTo(sourceid).And(x => x.Form.AppliesTo)
  771. .IsEqualTo(typeof(TTargetType).EntityName().Split('.').Last())
  772. );
  773. }
  774. var newforms = new List<TTargetForm>();
  775. foreach (var row in table.Rows)
  776. {
  777. var sourceform = row.ToObject<TSourceForm>();
  778. var targetform = new TTargetForm();
  779. targetform.Form.ID = sourceform.Form.ID;
  780. targetform.Form.Synchronise(sourceform.Form);
  781. newforms.Add(targetform);
  782. }
  783. page.Items.Clear();
  784. page.LoadItems(newforms.ToArray());
  785. }
  786. }
  787. #region ClipBuffer
  788. protected virtual bool BeforeCopy(IList<T> items)
  789. {
  790. return true;
  791. }
  792. protected override void MoveRows(CoreRow[] rows, int index, bool isCopy = false)
  793. {
  794. if (!Options.ReorderRows || !IsSequenced) return;
  795. var items = LoadItems(rows);
  796. if (isCopy)
  797. {
  798. if (!BeforeCopy(items))
  799. {
  800. return;
  801. }
  802. }
  803. var sequence = index < Data.Rows.Count
  804. ? Data.Rows[index].Get<ISequenceable, long>(x => x.Sequence)
  805. : Data.Rows[^1].Get<ISequenceable, long>(x => x.Sequence) + 1;
  806. var postRows = Data.Rows.Where(r => !rows.Contains(r) && r.Get<ISequenceable, long>(x => x.Sequence) >= sequence);
  807. var updates = items.Concatenate(LoadItems(postRows.ToArray()));
  808. foreach (var update in updates)
  809. {
  810. ((ISequenceable)update).Sequence = sequence;
  811. sequence++;
  812. }
  813. if (updates.Length != 0)
  814. {
  815. SaveItems(updates);
  816. DoChanged();
  817. Refresh(false, true);
  818. }
  819. }
  820. #endregion
  821. protected virtual void ObjectToRow(T obj, CoreRow row)
  822. {
  823. row.Table.FillRow(row, obj);
  824. }
  825. #region Import / Export
  826. protected virtual CoreTable LoadImportKeys(String[] fields)
  827. {
  828. var result = new CoreTable();
  829. result.LoadColumns(Columns.None<T>().Add(fields));
  830. return result;
  831. }
  832. protected virtual Guid GetImportID()
  833. {
  834. return Guid.Empty;
  835. }
  836. protected virtual bool CustomiseImportItem(T item)
  837. {
  838. if (IsSequenced)
  839. ((ISequenceable)item).Sequence = CoreUtils.GenerateSequence();
  840. return true;
  841. }
  842. protected virtual string CustomiseImportFileName(string filename)
  843. {
  844. return filename;
  845. }
  846. void IImportDynamicGrid.DoImport() => DoImport();
  847. protected virtual void DoImport()
  848. {
  849. var list = new DynamicImportList(
  850. typeof(T),
  851. GetImportID()
  852. );
  853. list.OnImportItem += o => { return CustomiseImportItem((T)o); };
  854. list.OnCustomiseImport += (o, args) => { args.FileName = CustomiseImportFileName(args.FileName); };
  855. list.OnSave += (sender, entity) => SaveItem(entity as T);
  856. list.OnLoad += (sender, type, fields, id) => LoadImportKeys(fields);
  857. list.ShowDialog();
  858. Refresh(false, true);
  859. }
  860. protected virtual void CustomiseExportColumns(List<string> columnnames)
  861. {
  862. }
  863. protected virtual string CustomiseExportFileName(string filename)
  864. {
  865. return filename;
  866. }
  867. protected virtual void CustomiseExportFilters(Filters<T> filters, CoreRow[] visiblerows)
  868. {
  869. }
  870. protected virtual void ApplyExportFilter(CoreTable table, object data)
  871. {
  872. }
  873. void IExportDynamicGrid.DoExport() => DoExport();
  874. protected virtual void DoExport()
  875. {
  876. var columnnames = VisibleColumns.Select(x => x.ColumnName).ToList();
  877. CustomiseExportColumns(columnnames);
  878. var form = new DynamicExportForm(typeof(T), columnnames);
  879. if (form.ShowDialog() != true)
  880. return;
  881. var filters = new Filters<T>();
  882. filters.Add(DefineFilter());
  883. var predicates = GetUIComponent().GetFilterPredicates();
  884. var visiblerows = GetVisibleRows();
  885. CustomiseExportFilters(filters, visiblerows);
  886. var columns = Columns.None<T>().Add(form.Fields);
  887. var otherColumns = form.GetChildFields()
  888. .Select(x => new Tuple<Type, IColumns>(
  889. x.Key,
  890. Columns.None(x.Key).Add(x.Value)))
  891. .Where(x => x.Item2.ColumnNames().Any()).ToList();
  892. var reloadColumns = Columns.None<T>();
  893. foreach (var column in columns)
  894. {
  895. reloadColumns.Add(column);
  896. }
  897. foreach (var column in HiddenColumns.ColumnNames)
  898. {
  899. reloadColumns.Add(column);
  900. }
  901. foreach (var column in LookupFactory.RequiredColumns<T>())
  902. {
  903. columns.Add(column);
  904. }
  905. foreach (var (column, _) in predicates)
  906. {
  907. reloadColumns.Add(column);
  908. }
  909. CoreTable? data = null;
  910. void LoadExport()
  911. {
  912. var newData = new CoreTable();
  913. newData.LoadColumns(columns);
  914. FilterRows(data.Rows, newData, filter: row =>
  915. {
  916. foreach(var (_, predicate) in predicates)
  917. {
  918. if (!predicate(row))
  919. {
  920. return false;
  921. }
  922. }
  923. return true;
  924. });
  925. var list = new List<Tuple<Type?, CoreTable>>() { new(typeof(T), newData) };
  926. list.AddRange(LoadExportTables(filters, otherColumns));
  927. DoExportTables(list);
  928. }
  929. var sort = LookupFactory.DefineSort<T>();
  930. Reload(filters, reloadColumns, ref sort, CancellationToken.None, (table, err) =>
  931. {
  932. if (table is not null)
  933. {
  934. if (table.Offset == 0 || data is null)
  935. {
  936. data = table;
  937. if (!IsPaging)
  938. {
  939. Dispatcher.Invoke(LoadExport);
  940. }
  941. }
  942. else
  943. {
  944. data.AddPage(table);
  945. if (!IsPaging)
  946. {
  947. Dispatcher.Invoke(LoadExport);
  948. }
  949. }
  950. }
  951. else if (err is not null)
  952. {
  953. Dispatcher.Invoke(() =>
  954. {
  955. MessageWindow.ShowError("Error in export.", err);
  956. });
  957. }
  958. });
  959. }
  960. /// <summary>
  961. /// Loads the child tables for an export, based on the filter of the parent table.
  962. /// </summary>
  963. /// <remarks>
  964. /// If not overriden, defaults to creating empty tables with no records.
  965. /// </remarks>
  966. /// <param name="filter">Filter for the parent table.</param>
  967. /// <param name="tableColumns">A list of the child table types, with columns to load for each</param>
  968. /// <returns>A list of tables, in the same order as they came in <paramref name="tableColumns"/></returns>
  969. protected virtual IEnumerable<Tuple<Type?, CoreTable>> LoadExportTables(Filters<T> filter, IEnumerable<Tuple<Type, IColumns>> tableColumns)
  970. {
  971. return tableColumns.Select(x =>
  972. {
  973. var table = new CoreTable();
  974. table.LoadColumns(x.Item2);
  975. return new Tuple<Type?, CoreTable>(x.Item1, table);
  976. });
  977. }
  978. private void DoExportTables(List<Tuple<Type?, CoreTable>> data)
  979. {
  980. var filename = CustomiseExportFileName(typeof(T).EntityName().Split('.').Last());
  981. ExcelExporter.DoExport(data, filename);
  982. }
  983. #endregion
  984. #endregion
  985. #region Header Actions
  986. protected override bool SelectColumns([NotNullWhen(true)] out DynamicGridColumns? columns)
  987. {
  988. var schema = new DynamicGridObjectColumnSchema(typeof(T));
  989. var editor = new DynamicGridColumnsEditor(schema, typeof(T)) { WindowStartupLocation = WindowStartupLocation.CenterScreen };
  990. editor.DirectEdit = IsDirectEditMode();
  991. editor.Columns.AddRange(VisibleColumns);
  992. schema.OnProcessColumns += args =>
  993. {
  994. GetAvailableColumns?.Invoke(args);
  995. };
  996. if (editor.ShowDialog().Equals(true))
  997. {
  998. columns = editor.Columns;
  999. return true;
  1000. }
  1001. else
  1002. {
  1003. columns = null;
  1004. return false;
  1005. }
  1006. }
  1007. #endregion
  1008. #region Drag + Drop
  1009. protected DragDropEffects DragTable(Type entity, CoreTable table)
  1010. {
  1011. Logger.Send(LogType.Information, "", "DragTable");
  1012. var data = new DataObject();
  1013. data.SetData(DynamicGridUtils.DragFormat, new DynamicGridDragFormat(table.ToDataTable(), entity));
  1014. var effect = DragDrop.DoDragDrop(this, data, DragDropEffects.All);
  1015. return effect;
  1016. }
  1017. protected override DragDropEffects OnRowsDragStart(CoreRow[] rows)
  1018. {
  1019. Logger.Send(LogType.Information, "", "OnRowsDragStart");
  1020. var table = new CoreTable();
  1021. table.LoadColumns(Data.Columns);
  1022. table.LoadRows(rows);
  1023. return DragTable(typeof(T), table);
  1024. }
  1025. #endregion
  1026. }
  1027. #region Styling
  1028. public class DynamicGridRowStyle : DynamicGridStyle<VirtualizingCellsControl>
  1029. {
  1030. public DynamicGridRowStyle() : base(null)
  1031. {
  1032. }
  1033. public DynamicGridRowStyle(IDynamicGridStyle source) : base(source)
  1034. {
  1035. }
  1036. public override DependencyProperty FontSizeProperty => Control.FontSizeProperty;
  1037. public override DependencyProperty FontStyleProperty => Control.FontStyleProperty;
  1038. public override DependencyProperty FontWeightProperty => Control.FontWeightProperty;
  1039. public override DependencyProperty BackgroundProperty => Control.BackgroundProperty;
  1040. public override DependencyProperty ForegroundProperty => Control.ForegroundProperty;
  1041. }
  1042. public class DynamicGridCellStyle : DynamicGridStyle<Control>
  1043. {
  1044. public DynamicGridCellStyle() : base(null)
  1045. {
  1046. }
  1047. public DynamicGridCellStyle(IDynamicGridStyle source) : base(source)
  1048. {
  1049. }
  1050. public override DependencyProperty FontSizeProperty => Control.FontSizeProperty;
  1051. public override DependencyProperty FontStyleProperty => Control.FontStyleProperty;
  1052. public override DependencyProperty FontWeightProperty => Control.FontWeightProperty;
  1053. public override DependencyProperty BackgroundProperty => Control.BackgroundProperty;
  1054. public override DependencyProperty ForegroundProperty => Control.ForegroundProperty;
  1055. }
  1056. // Used to render boolean columns (the default "false" value shows what appears to be an intermediate state, which is ugly
  1057. // This should show nothing for false, and a tick in a box for true
  1058. public class BoolToImageConverter : AbstractConverter<bool, ImageSource?>
  1059. {
  1060. public ImageSource TrueValue { get; set; }
  1061. public ImageSource? FalseValue { get; set; }
  1062. public BoolToImageConverter()
  1063. {
  1064. TrueValue = Wpf.Resources.Bullet_Tick.AsBitmapImage();
  1065. }
  1066. public override ImageSource? Convert(bool value)
  1067. {
  1068. return value ? TrueValue : FalseValue;
  1069. }
  1070. public override bool Deconvert(ImageSource? value)
  1071. {
  1072. return ImageUtils.IsEqual(value as BitmapImage, TrueValue as BitmapImage);
  1073. }
  1074. }
  1075. public class StringToColorImageConverter : IValueConverter
  1076. {
  1077. private readonly int _height = 50;
  1078. private readonly int _width = 25;
  1079. private readonly Dictionary<string, BitmapImage> cache = new();
  1080. public StringToColorImageConverter(int width, int height)
  1081. {
  1082. _width = width;
  1083. _height = height;
  1084. }
  1085. public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
  1086. {
  1087. var str = value?.ToString();
  1088. if (str is null)
  1089. return null;
  1090. var colorcode = str.TrimStart('#');
  1091. if (!cache.ContainsKey(colorcode))
  1092. {
  1093. var col = ImageUtils.StringToColor(colorcode);
  1094. var bmp = ImageUtils.BitmapFromColor(col, _width, _height, Color.Black);
  1095. cache[colorcode] = bmp.AsBitmapImage();
  1096. }
  1097. var result = cache[colorcode];
  1098. return result;
  1099. }
  1100. public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  1101. {
  1102. return null;
  1103. }
  1104. }
  1105. public class StringArrayConverter : IValueConverter
  1106. {
  1107. object? IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
  1108. {
  1109. if (value is string[] strArray)
  1110. {
  1111. return string.Join("\n", strArray);
  1112. }
  1113. Logger.Send(LogType.Error, "", $"Attempt to convert an object which is not a string array: {value}.");
  1114. return null;
  1115. }
  1116. object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  1117. {
  1118. return value;
  1119. }
  1120. }
  1121. #endregion
  1122. [Serializable]
  1123. class DynamicGridDragFormat
  1124. {
  1125. private string entity;
  1126. public DataTable Table { get; set; }
  1127. public Type Entity
  1128. {
  1129. get => CoreUtils.GetEntity(entity);
  1130. [MemberNotNull(nameof(entity))]
  1131. set => entity = value.EntityName();
  1132. }
  1133. public DynamicGridDragFormat(DataTable table, Type entity)
  1134. {
  1135. Table = table;
  1136. Entity = entity;
  1137. }
  1138. }