|
@@ -30,6 +30,9 @@ using DragEventArgs = System.Windows.DragEventArgs;
|
|
|
using MessageBox = System.Windows.MessageBox;
|
|
|
using UserControl = System.Windows.Controls.UserControl;
|
|
|
using InABox.Wpf;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
+using System.Windows.Data;
|
|
|
+using PRSDesktop.Panels.DataEntry;
|
|
|
|
|
|
namespace PRSDesktop;
|
|
|
|
|
@@ -91,9 +94,16 @@ public partial class DataEntryList : UserControl, ICorePanel, IDockPanel
|
|
|
public delegate void DateEntrySelectionHandler(String appliesTo, Guid entityID, bool allowprocess);
|
|
|
|
|
|
public event DateEntrySelectionHandler? SelectionChanged;
|
|
|
+
|
|
|
+ private readonly object _viewListLock = new object();
|
|
|
+ public ObservableCollection<ImageSource> ViewList { get; init; } = new();
|
|
|
+
|
|
|
+ private List<DataEntryDocumentWindow> OpenWindows = new();
|
|
|
|
|
|
public DataEntryList()
|
|
|
{
|
|
|
+ BindingOperations.EnableCollectionSynchronization(ViewList, _viewListLock);
|
|
|
+
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
|
|
@@ -117,6 +127,7 @@ public partial class DataEntryList : UserControl, ICorePanel, IDockPanel
|
|
|
|
|
|
public void Shutdown(CancelEventArgs? cancel)
|
|
|
{
|
|
|
+ CloseImageWindows();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
@@ -165,25 +176,21 @@ public partial class DataEntryList : UserControl, ICorePanel, IDockPanel
|
|
|
var selected = _dataEntryGrid.SelectedRows.Select(x => x.ToObject<DataEntryDocument>()).ToList();
|
|
|
if (selected.Count == SelectedScans.Count && !selected.Any(x => SelectedScans.All(y => x.ID != y.ID)))
|
|
|
return;
|
|
|
-
|
|
|
+
|
|
|
SelectedScans = selected;
|
|
|
- ViewListPanel.Children.Clear();
|
|
|
+ ViewList.Clear();
|
|
|
|
|
|
Task.Run(() =>
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- var docs = DataEntryCache.Cache.LoadDocuments(SelectedScans.Select(x => x.Document.ID).Distinct(), checkTimestamp: true);
|
|
|
- LoadDocuments(docs);
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
+ var docs = DataEntryCache.Cache.LoadDocuments(SelectedScans.Select(x => x.Document.ID).Distinct(), checkTimestamp: true);
|
|
|
+ LoadDocuments(docs);
|
|
|
+ }).ContinueWith((task) =>
|
|
|
+ {
|
|
|
+ if(task.Exception is not null)
|
|
|
{
|
|
|
- Dispatcher.BeginInvoke(() =>
|
|
|
- {
|
|
|
- MessageWindow.ShowError("An error occurred while loading the documents", e);
|
|
|
- });
|
|
|
+ MessageWindow.ShowError("An error occurred while loading the documents", task.Exception);
|
|
|
}
|
|
|
- });
|
|
|
+ }, TaskScheduler.FromCurrentSynchronizationContext());
|
|
|
}
|
|
|
|
|
|
private void LoadDocuments(IEnumerable<Document> documents)
|
|
@@ -242,26 +249,20 @@ public partial class DataEntryList : UserControl, ICorePanel, IDockPanel
|
|
|
list.Add(image);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- Dispatcher.Invoke(() =>
|
|
|
+ lock (_viewListLock)
|
|
|
{
|
|
|
+ ViewList.Clear();
|
|
|
foreach (var scan in SelectedScans)
|
|
|
{
|
|
|
if (bitmaps.TryGetValue(scan.Document.ID, out var list))
|
|
|
{
|
|
|
foreach (var bitmap in list)
|
|
|
{
|
|
|
- var image = new Image
|
|
|
- {
|
|
|
- Source = bitmap,
|
|
|
- Margin = new Thickness(0, 0, 0, 20),
|
|
|
- ContextMenu = ViewListPanel.ContextMenu
|
|
|
- };
|
|
|
- ViewListPanel.Children.Add(image);
|
|
|
+ ViewList.Add(bitmap);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
@@ -364,13 +365,59 @@ public partial class DataEntryList : UserControl, ICorePanel, IDockPanel
|
|
|
? rows[0].Get<DataEntryDocument, DateTime>(x => x.Archived)
|
|
|
: DateTime.MinValue;
|
|
|
SelectionChanged?.Invoke(appliesTo, entityid, archived.IsEmpty());
|
|
|
+
|
|
|
+ CloseImageWindows();
|
|
|
}
|
|
|
|
|
|
private void _historyGrid_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
|
|
|
{
|
|
|
DoSelect(e.Rows);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ private void CloseImageWindows()
|
|
|
+ {
|
|
|
+ while (OpenWindows.Count > 0)
|
|
|
+ {
|
|
|
+ var win = OpenWindows.Last();
|
|
|
+ OpenWindows.RemoveAt(OpenWindows.Count - 1);
|
|
|
+ win.Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void OpenImageWindow(ImageSource image)
|
|
|
+ {
|
|
|
+ var window = OpenWindows.FirstOrDefault(x => x.Images.Contains(image));
|
|
|
+ if (window is not null)
|
|
|
+ {
|
|
|
+ window.Activate();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ window = new DataEntryDocumentWindow();
|
|
|
+ window.Topmost = true;
|
|
|
+ window.Images.Add(image);
|
|
|
+ OpenWindows.Add(window);
|
|
|
+ window.Closed += OpenWindow_Closed;
|
|
|
+ window.Show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Image_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is not Image image) return;
|
|
|
+
|
|
|
+ if(e.ClickCount >= 2)
|
|
|
+ {
|
|
|
+ OpenImageWindow(image.Source);
|
|
|
+ e.Handled = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OpenWindow_Closed(object? sender, EventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is not DataEntryDocumentWindow window) return;
|
|
|
+ OpenWindows.Remove(window);
|
|
|
+ }
|
|
|
+
|
|
|
private void _Explode_OnClick(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
_dataEntryGrid.DoExplode();
|
|
@@ -536,4 +583,11 @@ public partial class DataEntryList : UserControl, ICorePanel, IDockPanel
|
|
|
{
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private void _ShowImage_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is not MenuItem item || item.Tag is not ImageSource image) return;
|
|
|
+
|
|
|
+ OpenImageWindow(image);
|
|
|
+ }
|
|
|
}
|