123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Controls;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop;
- public class DataEntryHistorySettings : IUserConfigurationSettings
- {
- [Obsolete]
- private CoreFilterDefinition? _currentFilter;
- [Obsolete]
- public CoreFilterDefinition? CurrentFilter
- {
- get => _currentFilter;
- set
- {
- if (value is not null)
- {
- Filters = new DynamicGridSelectedFilterSettings(new List<CoreFilterDefinition> { value }, false, null);
- }
- }
- }
- public DynamicGridSelectedFilterSettings Filters { get; set; } = new();
- }
- public class DataEntryHistory : DynamicDataGrid<DataEntryDocument>
- {
- private DataEntryHistorySettings _settings;
- public DataEntryHistory()
- {
- _settings = new UserConfiguration<DataEntryHistorySettings>().Load();
- FilterComponent.SetSettings(_settings.Filters, false);
- FilterComponent.OnFiltersSelected += FilterComponent_OnFilterSelected;
-
- HiddenColumns.Add(x => x.Tag.ID);
- HiddenColumns.Add(x => x.Tag.AppliesTo);
- HiddenColumns.Add(x => x.Document.ID);
- HiddenColumns.Add(x=>x.EntityID);
- HiddenColumns.Add(x=>x.Archived);
- ActionColumns.Add(new DynamicImageColumn(LinkedImage) { Position = DynamicActionColumnPosition.Start });
-
- AddButton("Re-Open", PRSDesktop.Resources.refresh.AsBitmapImage(), ReopenClick);
-
- }
-
- private static readonly BitmapImage link = PRSDesktop.Resources.link.AsBitmapImage();
-
- private BitmapImage? LinkedImage(CoreRow? arg)
- {
- return arg == null
- ? link
- : arg.Get<DataEntryDocument, Guid>(x => x.EntityID) != Guid.Empty
- ? link
- : null;
- }
- private void FilterComponent_OnFilterSelected(DynamicGridSelectedFilterSettings settings)
- {
- _settings.Filters = settings;
- new UserConfiguration<DataEntryHistorySettings>().Save(_settings);
- }
- private bool ReopenClick(Button sender, CoreRow[] rows)
- {
- DoReopen();
- return false;
- }
- public void DoReopen()
- {
- if (SelectedRows?.Any() != true)
- return;
-
- var updates = SelectedRows.Select(x => x.ToObject<DataEntryDocument>()).ToArray();
- foreach (var update in updates)
- update.Archived = DateTime.MinValue;
- new Client<DataEntryDocument>().Save(updates, "Re-opened from Data Entry Screen");
- Refresh(false,true);
- }
-
- protected override void DoReconfigure(FluentList<DynamicGridOption> options)
- {
- base.DoReconfigure(options);
- options
- .BeginUpdate()
- .Clear()
- .Add(DynamicGridOption.ShowHelp)
- .Add(DynamicGridOption.Print)
- .Add(DynamicGridOption.MultiSelect)
- .Add(DynamicGridOption.RecordCount)
- .Add(DynamicGridOption.SelectColumns)
- .Add(DynamicGridOption.FilterRows)
- .EndUpdate();
-
- }
- protected override void Reload(Filters<DataEntryDocument> criteria, Columns<DataEntryDocument> columns, ref SortOrder<DataEntryDocument>? sort, Action<CoreTable?, Exception?> action)
- {
- criteria.Add(new Filter<DataEntryDocument>(x => x.Archived).IsNotEqualTo(DateTime.MinValue));
- base.Reload(criteria, columns, ref sort, action);
- }
- }
|