DataEntryHistory.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Windows.Controls;
  6. using System.Windows.Media.Imaging;
  7. using Comal.Classes;
  8. using InABox.Clients;
  9. using InABox.Configuration;
  10. using InABox.Core;
  11. using InABox.DynamicGrid;
  12. using InABox.WPF;
  13. namespace PRSDesktop;
  14. public class DataEntryHistorySettings : IUserConfigurationSettings
  15. {
  16. [Obsolete]
  17. private CoreFilterDefinition? _currentFilter;
  18. [Obsolete]
  19. public CoreFilterDefinition? CurrentFilter
  20. {
  21. get => _currentFilter;
  22. set
  23. {
  24. if (value is not null)
  25. {
  26. Filters = new DynamicGridSelectedFilterSettings(new List<ICoreFilterDefinition> { value }, false, null);
  27. }
  28. }
  29. }
  30. public DynamicGridSelectedFilterSettings Filters { get; set; } = new();
  31. }
  32. public class DataEntryHistory : DynamicDataGrid<DataEntryDocument>
  33. {
  34. private DataEntryHistorySettings _settings;
  35. public DataEntryHistory()
  36. {
  37. _settings = new UserConfiguration<DataEntryHistorySettings>().Load();
  38. FilterComponent.SetSettings(_settings.Filters, false);
  39. FilterComponent.OnFiltersSelected += FilterComponent_OnFilterSelected;
  40. HiddenColumns.Add(x => x.Tag.ID);
  41. HiddenColumns.Add(x => x.Tag.AppliesTo);
  42. HiddenColumns.Add(x => x.Document.ID);
  43. HiddenColumns.Add(x=>x.EntityID);
  44. HiddenColumns.Add(x=>x.Archived);
  45. ActionColumns.Add(new DynamicImageColumn(LinkedImage) { Position = DynamicActionColumnPosition.Start });
  46. AddButton("Re-Open", PRSDesktop.Resources.refresh.AsBitmapImage(), ReopenClick);
  47. }
  48. private static readonly BitmapImage link = PRSDesktop.Resources.link.AsBitmapImage();
  49. private BitmapImage? LinkedImage(CoreRow? arg)
  50. {
  51. return arg == null
  52. ? link
  53. : arg.Get<DataEntryDocument, Guid>(x => x.EntityID) != Guid.Empty
  54. ? link
  55. : null;
  56. }
  57. private void FilterComponent_OnFilterSelected(DynamicGridSelectedFilterSettings settings)
  58. {
  59. _settings.Filters = settings;
  60. new UserConfiguration<DataEntryHistorySettings>().Save(_settings);
  61. }
  62. private bool ReopenClick(Button sender, CoreRow[] rows)
  63. {
  64. DoReopen();
  65. return false;
  66. }
  67. public void DoReopen()
  68. {
  69. if (SelectedRows?.Any() != true)
  70. return;
  71. var updates = SelectedRows.Select(x => x.ToObject<DataEntryDocument>()).ToArray();
  72. foreach (var update in updates)
  73. update.Archived = DateTime.MinValue;
  74. new Client<DataEntryDocument>().Save(updates, "Re-opened from Data Entry Screen");
  75. Refresh(false,true);
  76. }
  77. protected override void DoReconfigure(DynamicGridOptions options)
  78. {
  79. base.DoReconfigure(options);
  80. options.Clear();
  81. options.ShowHelp = true;
  82. options.Print = true;
  83. options.MultiSelect = true;
  84. options.RecordCount = true;
  85. options.SelectColumns = true;
  86. options.FilterRows = true;
  87. }
  88. protected override void Reload(
  89. Filters<DataEntryDocument> criteria, Columns<DataEntryDocument> columns, ref SortOrder<DataEntryDocument>? sort,
  90. CancellationToken token, Action<CoreTable?, Exception?> action)
  91. {
  92. criteria.Add(new Filter<DataEntryDocument>(x => x.Archived).IsNotEqualTo(DateTime.MinValue));
  93. base.Reload(criteria, columns, ref sort, token, action);
  94. }
  95. }