|
@@ -10,390 +10,415 @@ using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Media;
|
|
|
using InABox.Configuration;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
|
|
|
-namespace PRSDesktop
|
|
|
+namespace PRSDesktop;
|
|
|
+
|
|
|
+
|
|
|
+public class DataEntryPanelSettings : BaseObject, IUserConfigurationSettings
|
|
|
{
|
|
|
+ private static readonly double DefaultCacheAge = 7;
|
|
|
|
|
|
- public class DataEntryPanelSettings : IUserConfigurationSettings
|
|
|
- {
|
|
|
- public double PreviewWidth { get; set; }
|
|
|
-
|
|
|
- }
|
|
|
+ [NullEditor]
|
|
|
+ public double PreviewWidth { get; set; }
|
|
|
+
|
|
|
+ [DoubleEditor(ToolTip = "Age of cached documents before they are deleted (days)")]
|
|
|
+ public double CacheAge { get; set; } = DefaultCacheAge;
|
|
|
+}
|
|
|
+
|
|
|
+/// <summary>
|
|
|
+/// Interaction logic for DataEntryPanel.xaml
|
|
|
+/// </summary>
|
|
|
+/// <remarks>
|
|
|
+/// This is a host because it has a singular code popup editor
|
|
|
+/// </remarks>
|
|
|
+public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHost
|
|
|
+{
|
|
|
+ private DataEntryPanelSettings _settings;
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Interaction logic for DataEntryPanel.xaml
|
|
|
- /// </summary>
|
|
|
- /// <remarks>
|
|
|
- /// This is a host because it has a singular code popup editor
|
|
|
- /// </remarks>
|
|
|
- public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHost
|
|
|
- {
|
|
|
- private DataEntryPanelSettings _settings;
|
|
|
-
|
|
|
- //IPopupEditorControl? _popup;
|
|
|
- private IDynamicDataGrid? _grid;
|
|
|
-
|
|
|
- private Type? _selectedType;
|
|
|
- private Guid _entityID;
|
|
|
- private Guid _originalID;
|
|
|
- private bool _processenabled;
|
|
|
+ //IPopupEditorControl? _popup;
|
|
|
+ private IDynamicDataGrid? _grid;
|
|
|
+
|
|
|
+ private Type? _selectedType;
|
|
|
+ private Guid _entityID;
|
|
|
+ private Guid _originalID;
|
|
|
+ private bool _processenabled;
|
|
|
|
|
|
- private Entity? _entity;
|
|
|
+ private Entity? _entity;
|
|
|
|
|
|
- private Button? _process;
|
|
|
+ private Button? _process;
|
|
|
|
|
|
- private bool _isChanged;
|
|
|
- private bool IsChanged
|
|
|
+ private bool _isChanged;
|
|
|
+ private bool IsChanged
|
|
|
+ {
|
|
|
+ get => _isChanged;
|
|
|
+ set
|
|
|
{
|
|
|
- get => _isChanged;
|
|
|
- set
|
|
|
+ if(_isChanged != value)
|
|
|
{
|
|
|
- if(_isChanged != value)
|
|
|
- {
|
|
|
- _isChanged = value;
|
|
|
- Editor.HideButtons = !value;// (_entity?.IsChanged() != true) && (_originalID == _entityID);
|
|
|
- if (_process != null)
|
|
|
- _process.IsEnabled = value;// ((_entity?.ID ?? Guid.Empty) != Guid.Empty) || (_entity?.IsChanged() != false);
|
|
|
- _documents._dataEntryGrid.IsEnabled = !value;// (_entity?.IsChanged() != true) && (_originalID == _entityID);
|
|
|
- }
|
|
|
+ _isChanged = value;
|
|
|
+ Editor.HideButtons = !value;// (_entity?.IsChanged() != true) && (_originalID == _entityID);
|
|
|
+ if (_process != null)
|
|
|
+ _process.IsEnabled = value;// ((_entity?.ID ?? Guid.Empty) != Guid.Empty) || (_entity?.IsChanged() != false);
|
|
|
+ _documents._dataEntryGrid.IsEnabled = !value;// (_entity?.IsChanged() != true) && (_originalID == _entityID);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Select(Type? type, Guid id)
|
|
|
+ {
|
|
|
+ ClearEditor();
|
|
|
|
|
|
- public void Select(Type? type, Guid id)
|
|
|
+ _selectedType = type;
|
|
|
+ _entityID = id;
|
|
|
+
|
|
|
+ if (_selectedType != null)
|
|
|
{
|
|
|
ClearEditor();
|
|
|
+ CreateEditor();
|
|
|
+ PopulateEditor();
|
|
|
+ //LoadPopup();
|
|
|
+ }
|
|
|
|
|
|
- _selectedType = type;
|
|
|
- _entityID = id;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ScanPanel_OnSelectScan(string appliesto, Guid entityid, bool processenabled)
|
|
|
+ {
|
|
|
+ _processenabled = processenabled;
|
|
|
+ _originalID = entityid;
|
|
|
+ Select(
|
|
|
+ CoreUtils.GetEntityOrNull(appliesto),
|
|
|
+ entityid
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public DataEntryPanel()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ LoadSettings();
|
|
|
+ }
|
|
|
|
|
|
- if (_selectedType != null)
|
|
|
- {
|
|
|
- ClearEditor();
|
|
|
- CreateEditor();
|
|
|
- PopulateEditor();
|
|
|
- //LoadPopup();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void ScanPanel_OnSelectScan(string appliesto, Guid entityid, bool processenabled)
|
|
|
- {
|
|
|
- _processenabled = processenabled;
|
|
|
- _originalID = entityid;
|
|
|
- Select(
|
|
|
- CoreUtils.GetEntityOrNull(appliesto),
|
|
|
- entityid
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- public DataEntryPanel()
|
|
|
- {
|
|
|
- _settings = new UserConfiguration<DataEntryPanelSettings>().Load();
|
|
|
- InitializeComponent();
|
|
|
- _panel.AnchorWidth = _settings.PreviewWidth > 0.0F
|
|
|
- ? _settings.PreviewWidth
|
|
|
- : 500F;
|
|
|
- }
|
|
|
+ private void LoadSettings()
|
|
|
+ {
|
|
|
+ _settings = new UserConfiguration<DataEntryPanelSettings>().Load();
|
|
|
+ _panel.AnchorWidth = _settings.PreviewWidth > 0.0F
|
|
|
+ ? _settings.PreviewWidth
|
|
|
+ : 500F;
|
|
|
+ }
|
|
|
|
|
|
- public void Setup()
|
|
|
- {
|
|
|
- _documents.Setup();
|
|
|
+ public void Setup()
|
|
|
+ {
|
|
|
+ _documents.Setup();
|
|
|
|
|
|
- IsChanged = false;
|
|
|
- }
|
|
|
-
|
|
|
- public void Refresh()
|
|
|
+ IsChanged = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Refresh()
|
|
|
+ {
|
|
|
+ if (CheckSaved())
|
|
|
{
|
|
|
- if (CheckSaved())
|
|
|
- {
|
|
|
- _documents.Refresh();
|
|
|
- IsChanged = false;
|
|
|
- }
|
|
|
+ _documents.Refresh();
|
|
|
+ IsChanged = false;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- public bool IsReady { get; set; }
|
|
|
+ public bool IsReady { get; set; }
|
|
|
|
|
|
- public string SectionName => "Data Entry";
|
|
|
+ public string SectionName => "Data Entry";
|
|
|
|
|
|
- public DataModel DataModel(Selection selection)
|
|
|
- {
|
|
|
- return new EmptyDataModel();
|
|
|
- }
|
|
|
+ public DataModel DataModel(Selection selection)
|
|
|
+ {
|
|
|
+ return new EmptyDataModel();
|
|
|
+ }
|
|
|
|
|
|
- public event DataModelUpdateEvent? OnUpdateDataModel;
|
|
|
+ public event DataModelUpdateEvent? OnUpdateDataModel;
|
|
|
|
|
|
- public void CreateToolbarButtons(IPanelHost host)
|
|
|
+ public void CreateToolbarButtons(IPanelHost host)
|
|
|
+ {
|
|
|
+ if (Security.IsAllowed<CanSetupDataEntryTags>())
|
|
|
{
|
|
|
- if (Security.IsAllowed<CanSetupDataEntryTags>())
|
|
|
+ host.CreateSetupAction(new PanelAction
|
|
|
+ {
|
|
|
+ Caption = "Data Entry Tags",
|
|
|
+ OnExecute = (action) =>
|
|
|
+ {
|
|
|
+ var list = new MasterList(typeof(DataEntryTag));
|
|
|
+ list.ShowDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ host.CreateSetupAction(new PanelAction
|
|
|
{
|
|
|
- host.CreateSetupAction(new PanelAction
|
|
|
+ Caption = "Settings",
|
|
|
+ OnExecute = (action) =>
|
|
|
{
|
|
|
- Caption = "Data Entry Tags",
|
|
|
- OnExecute = (action) =>
|
|
|
+ var settings = new UserConfiguration<DataEntryPanelSettings>().Load();
|
|
|
+
|
|
|
+ var grid = new DynamicItemsListGrid<DataEntryPanelSettings>();
|
|
|
+ if (grid.EditItems(new DataEntryPanelSettings[] { settings }))
|
|
|
{
|
|
|
- var list = new MasterList(typeof(DataEntryTag));
|
|
|
- list.ShowDialog();
|
|
|
+ new UserConfiguration<DataEntryPanelSettings>().Save(settings);
|
|
|
+ LoadSettings();
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- public void Heartbeat(TimeSpan time)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public Dictionary<string, object[]> Selected()
|
|
|
+ public void Heartbeat(TimeSpan time)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public Dictionary<string, object[]> Selected()
|
|
|
+ {
|
|
|
+ return new Dictionary<string, object[]>();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CheckSaved(CancelEventArgs cancel)
|
|
|
+ {
|
|
|
+ if (!_isChanged)
|
|
|
{
|
|
|
- return new Dictionary<string, object[]>();
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
- private void CheckSaved(CancelEventArgs cancel)
|
|
|
+ var result = MessageBox.Show("You have changes that have not been saved; do you wish to save these changes?", "Save Changes?", MessageBoxButton.YesNoCancel);
|
|
|
+ if (result == MessageBoxResult.Yes)
|
|
|
{
|
|
|
- if (!_isChanged)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- var result = MessageBox.Show("You have changes that have not been saved; do you wish to save these changes?", "Save Changes?", MessageBoxButton.YesNoCancel);
|
|
|
- if (result == MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- DoSave(false);
|
|
|
- if (!cancel.Cancel)
|
|
|
- MessageBox.Show("Item saved.");
|
|
|
- }
|
|
|
- else if (result == MessageBoxResult.Cancel)
|
|
|
- {
|
|
|
- cancel.Cancel = true;
|
|
|
- }
|
|
|
+ DoSave(false);
|
|
|
+ if (!cancel.Cancel)
|
|
|
+ MessageBox.Show("Item saved.");
|
|
|
}
|
|
|
- private bool CheckSaved()
|
|
|
+ else if (result == MessageBoxResult.Cancel)
|
|
|
{
|
|
|
- var cancel = new CancelEventArgs();
|
|
|
- CheckSaved(cancel);
|
|
|
- return !cancel.Cancel;
|
|
|
+ cancel.Cancel = true;
|
|
|
}
|
|
|
+ }
|
|
|
+ private bool CheckSaved()
|
|
|
+ {
|
|
|
+ var cancel = new CancelEventArgs();
|
|
|
+ CheckSaved(cancel);
|
|
|
+ return !cancel.Cancel;
|
|
|
+ }
|
|
|
|
|
|
- public void Shutdown(CancelEventArgs? cancel)
|
|
|
- {
|
|
|
- if (cancel != null)
|
|
|
- CheckSaved(cancel);
|
|
|
- if (cancel?.Cancel != true)
|
|
|
- _documents.Shutdown(cancel);
|
|
|
- }
|
|
|
+ public void Shutdown(CancelEventArgs? cancel)
|
|
|
+ {
|
|
|
+ if (cancel != null)
|
|
|
+ CheckSaved(cancel);
|
|
|
+ if (cancel?.Cancel != true)
|
|
|
+ _documents.Shutdown(cancel);
|
|
|
+ }
|
|
|
|
|
|
- #region Host
|
|
|
+ #region Host
|
|
|
|
|
|
-
|
|
|
- public DynamicGridColumns Columns { get; set; } = new();
|
|
|
+
|
|
|
+ public DynamicGridColumns Columns { get; set; } = new();
|
|
|
|
|
|
- IEnumerable<DynamicGridColumn> IDynamicEditorHost.Columns => Columns;
|
|
|
+ IEnumerable<DynamicGridColumn> IDynamicEditorHost.Columns => Columns;
|
|
|
|
|
|
- public void LoadColumns(string column, Dictionary<string, string> columns)
|
|
|
- {
|
|
|
- if (_selectedType is null)
|
|
|
- return;
|
|
|
+ public void LoadColumns(string column, Dictionary<string, string> columns)
|
|
|
+ {
|
|
|
+ if (_selectedType is null)
|
|
|
+ return;
|
|
|
|
|
|
- columns.Clear();
|
|
|
+ columns.Clear();
|
|
|
|
|
|
- foreach (var c in LookupFactory.DefineColumns(_selectedType).ColumnNames().Where(x => x != "ID"))
|
|
|
- columns.Add(c, c);
|
|
|
-
|
|
|
- //if (_popup?.EditorDefinition is CodePopupEditorControl codePopup && !columns.ContainsKey(codePopup.CodeColumn))
|
|
|
- // columns.Add(codePopup.CodeColumn, codePopup.CodeColumn);
|
|
|
- }
|
|
|
+ foreach (var c in LookupFactory.DefineColumns(_selectedType).ColumnNames().Where(x => x != "ID"))
|
|
|
+ columns.Add(c, c);
|
|
|
+
|
|
|
+ //if (_popup?.EditorDefinition is CodePopupEditorControl codePopup && !columns.ContainsKey(codePopup.CodeColumn))
|
|
|
+ // columns.Add(codePopup.CodeColumn, codePopup.CodeColumn);
|
|
|
+ }
|
|
|
|
|
|
- public IFilter? DefineFilter(Type type) => LookupFactory.DefineFilter(type);
|
|
|
+ public IFilter? DefineFilter(Type type) => LookupFactory.DefineFilter(type);
|
|
|
|
|
|
- public void LoadLookups(ILookupEditorControl sender)
|
|
|
- {
|
|
|
- var editor = sender.EditorDefinition as ILookupEditor;
|
|
|
- var colname = sender.ColumnName;
|
|
|
+ public void LoadLookups(ILookupEditorControl sender)
|
|
|
+ {
|
|
|
+ var editor = sender.EditorDefinition as ILookupEditor;
|
|
|
+ var colname = sender.ColumnName;
|
|
|
|
|
|
- var values = editor.Values(colname, Editor.Items);
|
|
|
- sender.LoadLookups(values);
|
|
|
- }
|
|
|
+ var values = editor.Values(colname, Editor.Items);
|
|
|
+ sender.LoadLookups(values);
|
|
|
+ }
|
|
|
|
|
|
- object?[] IDynamicEditorHost.GetItems() => Editor.Items;
|
|
|
+ object?[] IDynamicEditorHost.GetItems() => Editor.Items;
|
|
|
|
|
|
- public BaseEditor? GetEditor(DynamicGridColumn column) => column.Editor.CloneEditor();
|
|
|
+ public BaseEditor? GetEditor(DynamicGridColumn column) => column.Editor.CloneEditor();
|
|
|
|
|
|
- #endregion
|
|
|
+ #endregion
|
|
|
|
|
|
- private void ClearEditor()
|
|
|
- {
|
|
|
+ private void ClearEditor()
|
|
|
+ {
|
|
|
|
|
|
- DetailBorder.Child = null;
|
|
|
- IsChanged = false;
|
|
|
-
|
|
|
- //if (_popup is UIElement element)
|
|
|
- // DetailHeader.Children.Remove(element);
|
|
|
- }
|
|
|
+ DetailBorder.Child = null;
|
|
|
+ IsChanged = false;
|
|
|
|
|
|
+ //if (_popup is UIElement element)
|
|
|
+ // DetailHeader.Children.Remove(element);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- private void CreateEditor()
|
|
|
+ private void CreateEditor()
|
|
|
+ {
|
|
|
+ if (_selectedType == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ Editor = new EmbeddedDynamicEditorForm();
|
|
|
+ Editor.SetLayoutType<VerticalDynamicEditorGridLayout>();
|
|
|
+ Editor.HighlightButtons = true;
|
|
|
+ Editor.HideButtons = true;
|
|
|
+ Editor.SetValue(Grid.RowProperty, 1);
|
|
|
+ Editor.SetValue(Grid.ColumnProperty, 0);
|
|
|
+ Editor.SetValue(Grid.ColumnSpanProperty, 4);
|
|
|
+
|
|
|
+ Editor.OnAfterEditorValueChanged += (sender, args) =>
|
|
|
{
|
|
|
- if (_selectedType == null)
|
|
|
- return;
|
|
|
-
|
|
|
- Editor = new EmbeddedDynamicEditorForm();
|
|
|
- Editor.SetLayoutType<VerticalDynamicEditorGridLayout>();
|
|
|
- Editor.HighlightButtons = true;
|
|
|
- Editor.HideButtons = true;
|
|
|
- Editor.SetValue(Grid.RowProperty, 1);
|
|
|
- Editor.SetValue(Grid.ColumnProperty, 0);
|
|
|
- Editor.SetValue(Grid.ColumnSpanProperty, 4);
|
|
|
-
|
|
|
- Editor.OnAfterEditorValueChanged += (sender, args) =>
|
|
|
- {
|
|
|
- IsChanged = IsChanged || (_entity?.IsChanged() == true || _originalID != _entityID);
|
|
|
- return null;
|
|
|
- };
|
|
|
+ IsChanged = IsChanged || (_entity?.IsChanged() == true || _originalID != _entityID);
|
|
|
+ return null;
|
|
|
+ };
|
|
|
|
|
|
- Editor.OnOK += () => { DoSave(false); };
|
|
|
- Editor.OnCancel += () =>
|
|
|
- {
|
|
|
- _entityID = _originalID;
|
|
|
- Select(_selectedType,_entityID);
|
|
|
- };
|
|
|
- Editor.OnChanged += (sender, args) => IsChanged = true;
|
|
|
- Editor.OnFormCustomiseEditor += (sender, items, column, editor) =>
|
|
|
+ Editor.OnOK += () => { DoSave(false); };
|
|
|
+ Editor.OnCancel += () =>
|
|
|
+ {
|
|
|
+ _entityID = _originalID;
|
|
|
+ Select(_selectedType,_entityID);
|
|
|
+ };
|
|
|
+ Editor.OnChanged += (sender, args) => IsChanged = true;
|
|
|
+ Editor.OnFormCustomiseEditor += (sender, items, column, editor) =>
|
|
|
+ {
|
|
|
+ if ((editor is BaseCodeEditor be) && editor.Editable.EditorVisible())
|
|
|
{
|
|
|
- if ((editor is BaseCodeEditor be) && editor.Editable.EditorVisible())
|
|
|
+ be.Buttons = new[]
|
|
|
{
|
|
|
- be.Buttons = new[]
|
|
|
- {
|
|
|
- new EditorButton(null, "..", 30, DoLookup, false)
|
|
|
- };
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- DetailBorder.Child = Editor;
|
|
|
- _grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), _selectedType) as IDynamicDataGrid;
|
|
|
-
|
|
|
- }
|
|
|
+ new EditorButton(null, "..", 30, DoLookup, false)
|
|
|
+ };
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ DetailBorder.Child = Editor;
|
|
|
+ _grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), _selectedType) as IDynamicDataGrid;
|
|
|
|
|
|
- private void DoLookup(object editor, object? item)
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DoLookup(object editor, object? item)
|
|
|
+ {
|
|
|
+ if (editor is CodeEditorControl ce)
|
|
|
{
|
|
|
- if (editor is CodeEditorControl ce)
|
|
|
+
|
|
|
+ Dictionary<string, string>? filter = null;
|
|
|
+ if (ce.Value != null)
|
|
|
{
|
|
|
-
|
|
|
- Dictionary<string, string>? filter = null;
|
|
|
- if (ce.Value != null)
|
|
|
- {
|
|
|
- filter = new Dictionary<string, string>();
|
|
|
- filter[ce.ColumnName] = ce.Value;
|
|
|
- }
|
|
|
+ filter = new Dictionary<string, string>();
|
|
|
+ filter[ce.ColumnName] = ce.Value;
|
|
|
+ }
|
|
|
|
|
|
- var popup = new PopupList(_selectedType, _entityID, new String[] { }, filter);
|
|
|
- popup.OnDefineFilter += type => LookupFactory.DefineFilter(type);
|
|
|
- if (popup.ShowDialog() == true)
|
|
|
- {
|
|
|
- _entityID = popup.ID;
|
|
|
- Select(_selectedType, _entityID);
|
|
|
- }
|
|
|
+ var popup = new PopupList(_selectedType, _entityID, new String[] { }, filter);
|
|
|
+ popup.OnDefineFilter += type => LookupFactory.DefineFilter(type);
|
|
|
+ if (popup.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ _entityID = popup.ID;
|
|
|
+ Select(_selectedType, _entityID);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- private void SaveDocument(DataEntryDocument dataEntryDocument)
|
|
|
- {
|
|
|
- var linktype = CoreUtils.TypeList(x =>
|
|
|
- x.GetInterfaces().Contains(typeof(IEntityLink))
|
|
|
- && x.BaseType != null
|
|
|
- && x.BaseType.IsGenericType
|
|
|
- && x.BaseType.GenericTypeArguments.FirstOrDefault() == _selectedType
|
|
|
- ).FirstOrDefault();
|
|
|
- if (linktype == null)
|
|
|
- return;
|
|
|
-
|
|
|
- var doctype = CoreUtils.TypeList(x =>
|
|
|
- x.GetInterfaces().Contains(typeof(IEntityDocument))
|
|
|
- && x.BaseType != null
|
|
|
- && x.BaseType.IsGenericType
|
|
|
- && x.BaseType.GenericTypeArguments.FirstOrDefault() == linktype
|
|
|
- ).FirstOrDefault();
|
|
|
- if (doctype == null)
|
|
|
- return;
|
|
|
-
|
|
|
- var doc = (IEntityDocument)Activator.CreateInstance(doctype)!;
|
|
|
- CoreUtils.SetPropertyValue(doc,"EntityLink.ID",_entityID);
|
|
|
- doc.DocumentLink.ID = dataEntryDocument.Document.ID;
|
|
|
- doc.Thumbnail = dataEntryDocument.Thumbnail;
|
|
|
- ClientFactory.CreateClient(doctype).Save(doc,"Added from Data Entry Screen");
|
|
|
+ private void SaveDocument(DataEntryDocument dataEntryDocument)
|
|
|
+ {
|
|
|
+ var linktype = CoreUtils.TypeList(x =>
|
|
|
+ x.GetInterfaces().Contains(typeof(IEntityLink))
|
|
|
+ && x.BaseType != null
|
|
|
+ && x.BaseType.IsGenericType
|
|
|
+ && x.BaseType.GenericTypeArguments.FirstOrDefault() == _selectedType
|
|
|
+ ).FirstOrDefault();
|
|
|
+ if (linktype == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ var doctype = CoreUtils.TypeList(x =>
|
|
|
+ x.GetInterfaces().Contains(typeof(IEntityDocument))
|
|
|
+ && x.BaseType != null
|
|
|
+ && x.BaseType.IsGenericType
|
|
|
+ && x.BaseType.GenericTypeArguments.FirstOrDefault() == linktype
|
|
|
+ ).FirstOrDefault();
|
|
|
+ if (doctype == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ var doc = (IEntityDocument)Activator.CreateInstance(doctype)!;
|
|
|
+ CoreUtils.SetPropertyValue(doc,"EntityLink.ID",_entityID);
|
|
|
+ doc.DocumentLink.ID = dataEntryDocument.Document.ID;
|
|
|
+ doc.Thumbnail = dataEntryDocument.Thumbnail;
|
|
|
+ ClientFactory.CreateClient(doctype).Save(doc,"Added from Data Entry Screen");
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- private void DoSave(bool markasprocessed)
|
|
|
- {
|
|
|
- var cancel = new System.ComponentModel.CancelEventArgs();
|
|
|
- if (markasprocessed && (_entity is IDataEntryInstance scannable))
|
|
|
- scannable.DataEntered = DateTime.Now;
|
|
|
- Editor.SaveItem(cancel);
|
|
|
+ private void DoSave(bool markasprocessed)
|
|
|
+ {
|
|
|
+ var cancel = new System.ComponentModel.CancelEventArgs();
|
|
|
+ if (markasprocessed && (_entity is IDataEntryInstance scannable))
|
|
|
+ scannable.DataEntered = DateTime.Now;
|
|
|
+ Editor.SaveItem(cancel);
|
|
|
|
|
|
- if (!cancel.Cancel)
|
|
|
+ if (!cancel.Cancel)
|
|
|
+ {
|
|
|
+ _originalID = _entityID;
|
|
|
+ IsChanged = false;
|
|
|
+ var row = _documents._dataEntryGrid.SelectedRows.FirstOrDefault();
|
|
|
+ if (row != null)
|
|
|
{
|
|
|
- _originalID = _entityID;
|
|
|
- IsChanged = false;
|
|
|
- var row = _documents._dataEntryGrid.SelectedRows.FirstOrDefault();
|
|
|
- if (row != null)
|
|
|
+ var scan = row?.ToObject<DataEntryDocument>();
|
|
|
+ scan.EntityID = _entity.ID;
|
|
|
+ if (markasprocessed)
|
|
|
{
|
|
|
- var scan = row?.ToObject<DataEntryDocument>();
|
|
|
- scan.EntityID = _entity.ID;
|
|
|
- if (markasprocessed)
|
|
|
- {
|
|
|
- SaveDocument(scan);
|
|
|
- scan.Archived = DateTime.Now;
|
|
|
- }
|
|
|
+ SaveDocument(scan);
|
|
|
+ scan.Archived = DateTime.Now;
|
|
|
+ }
|
|
|
|
|
|
- if (scan.IsChanged())
|
|
|
- {
|
|
|
- new Client<DataEntryDocument>().Save(scan, "Updated from Data Entry Screen");
|
|
|
- _documents.Refresh();
|
|
|
- }
|
|
|
-
|
|
|
+ if (scan.IsChanged())
|
|
|
+ {
|
|
|
+ new Client<DataEntryDocument>().Save(scan, "Updated from Data Entry Screen");
|
|
|
+ _documents.Refresh();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private void PopulateEditor()
|
|
|
- {
|
|
|
- if (_selectedType == null)
|
|
|
- return;
|
|
|
-
|
|
|
- _entity = null;
|
|
|
- if (_entityID != Guid.Empty)
|
|
|
- {
|
|
|
- _entity = Client.Create(_selectedType)
|
|
|
- .Query(
|
|
|
- Filter.Create<Entity>(_selectedType, x => x.ID).IsEqualTo(_entityID),
|
|
|
- _grid.LoadEditorColumns()
|
|
|
- )
|
|
|
- .ToObjects(_selectedType)
|
|
|
- .OfType<Entity>()
|
|
|
- .FirstOrDefault();
|
|
|
- }
|
|
|
- _entity ??= Activator.CreateInstance(_selectedType) as Entity;
|
|
|
- if (_entity == null)
|
|
|
- return;
|
|
|
- _grid?.InitialiseEditorForm(Editor, new object[] { _entity }, null, true);
|
|
|
-
|
|
|
- _process = new Button()
|
|
|
- {
|
|
|
- Content = "Mark as Processed",
|
|
|
- BorderBrush = new SolidColorBrush(Colors.DarkBlue),
|
|
|
- Background = new SolidColorBrush(Colors.DodgerBlue),
|
|
|
- Margin = new Thickness(5, 5, 0, 5),
|
|
|
- Padding = new Thickness(10, 0, 10, 0),
|
|
|
- IsEnabled = _processenabled
|
|
|
- };
|
|
|
- _process.Click += (sender, args) => DoSave(true);
|
|
|
- Editor.AddButton(_process);
|
|
|
- IsChanged = false;
|
|
|
- }
|
|
|
+ private void PopulateEditor()
|
|
|
+ {
|
|
|
+ if (_selectedType == null)
|
|
|
+ return;
|
|
|
|
|
|
- private void _panel_OnOnChanged(object sender, DynamicSplitPanelSettings e)
|
|
|
+ _entity = null;
|
|
|
+ if (_entityID != Guid.Empty)
|
|
|
{
|
|
|
- _settings.PreviewWidth = e.AnchorWidth;
|
|
|
- new UserConfiguration<DataEntryPanelSettings>().Save(_settings);
|
|
|
+ _entity = Client.Create(_selectedType)
|
|
|
+ .Query(
|
|
|
+ Filter.Create<Entity>(_selectedType, x => x.ID).IsEqualTo(_entityID),
|
|
|
+ _grid.LoadEditorColumns()
|
|
|
+ )
|
|
|
+ .ToObjects(_selectedType)
|
|
|
+ .OfType<Entity>()
|
|
|
+ .FirstOrDefault();
|
|
|
}
|
|
|
+ _entity ??= Activator.CreateInstance(_selectedType) as Entity;
|
|
|
+ if (_entity == null)
|
|
|
+ return;
|
|
|
+ _grid?.InitialiseEditorForm(Editor, new object[] { _entity }, null, true);
|
|
|
+
|
|
|
+ _process = new Button()
|
|
|
+ {
|
|
|
+ Content = "Mark as Processed",
|
|
|
+ BorderBrush = new SolidColorBrush(Colors.DarkBlue),
|
|
|
+ Background = new SolidColorBrush(Colors.DodgerBlue),
|
|
|
+ Margin = new Thickness(5, 5, 0, 5),
|
|
|
+ Padding = new Thickness(10, 0, 10, 0),
|
|
|
+ IsEnabled = _processenabled
|
|
|
+ };
|
|
|
+ _process.Click += (sender, args) => DoSave(true);
|
|
|
+ Editor.AddButton(_process);
|
|
|
+ IsChanged = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void _panel_OnOnChanged(object sender, DynamicSplitPanelSettings e)
|
|
|
+ {
|
|
|
+ _settings.PreviewWidth = e.AnchorWidth;
|
|
|
+ new UserConfiguration<DataEntryPanelSettings>().Save(_settings);
|
|
|
}
|
|
|
}
|