|
@@ -4,6 +4,7 @@ using InABox.Configuration;
|
|
using InABox.Core;
|
|
using InABox.Core;
|
|
using InABox.DynamicGrid;
|
|
using InABox.DynamicGrid;
|
|
using InABox.WPF;
|
|
using InABox.WPF;
|
|
|
|
+using PRSDesktop.Panels.DataEntry;
|
|
using Syncfusion.Pdf;
|
|
using Syncfusion.Pdf;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
@@ -158,6 +159,7 @@ public class DataEntryGrid : DynamicDataGrid<DataEntryDocument>
|
|
HiddenColumns.Add(x => x.Tag.ID);
|
|
HiddenColumns.Add(x => x.Tag.ID);
|
|
HiddenColumns.Add(x => x.Tag.AppliesTo);
|
|
HiddenColumns.Add(x => x.Tag.AppliesTo);
|
|
HiddenColumns.Add(x => x.Document.ID);
|
|
HiddenColumns.Add(x => x.Document.ID);
|
|
|
|
+ HiddenColumns.Add(x => x.Document.FileName);
|
|
HiddenColumns.Add(x => x.EntityID);
|
|
HiddenColumns.Add(x => x.EntityID);
|
|
HiddenColumns.Add(x => x.Archived);
|
|
HiddenColumns.Add(x => x.Archived);
|
|
HiddenColumns.Add(x => x.Note);
|
|
HiddenColumns.Add(x => x.Note);
|
|
@@ -231,10 +233,14 @@ public class DataEntryGrid : DynamicDataGrid<DataEntryDocument>
|
|
_tags ??= GetVisibleTagList();
|
|
_tags ??= GetVisibleTagList();
|
|
return _tags;
|
|
return _tags;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void DoExplode()
|
|
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets the currently selected tag ID, if all selected rows belong to the same tag.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ private Guid GetSelectedTagID()
|
|
{
|
|
{
|
|
- Guid tagID = Guid.Empty;
|
|
|
|
|
|
+ var tagID = Guid.Empty;
|
|
foreach (var row in SelectedRows)
|
|
foreach (var row in SelectedRows)
|
|
{
|
|
{
|
|
var rowTag = row.Get<DataEntryDocument, Guid>(x => x.Tag.ID);
|
|
var rowTag = row.Get<DataEntryDocument, Guid>(x => x.Tag.ID);
|
|
@@ -244,35 +250,75 @@ public class DataEntryGrid : DynamicDataGrid<DataEntryDocument>
|
|
}
|
|
}
|
|
else if (rowTag != tagID)
|
|
else if (rowTag != tagID)
|
|
{
|
|
{
|
|
- tagID = Guid.Empty;
|
|
|
|
- break;
|
|
|
|
|
|
+ return Guid.Empty;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ return tagID;
|
|
|
|
+ }
|
|
|
|
|
|
- var docIDs = SelectedRows.Select(r => r.Get<DataEntryDocument, Guid>(c => c.Document.ID)).ToArray();
|
|
|
|
|
|
+ private IEnumerable<Tuple<DataEntryDocument, List<DataEntryReGroupWindow.Page>>> ExplodeDocuments()
|
|
|
|
+ {
|
|
|
|
+ var dataEntryDocs = SelectedRows.ToArray<DataEntryDocument>();
|
|
|
|
+ var docIDs = dataEntryDocs.Select(r => r.Document.ID).ToArray();
|
|
var docs = new Client<Document>()
|
|
var docs = new Client<Document>()
|
|
.Query(
|
|
.Query(
|
|
new Filter<Document>(x => x.ID).InList(docIDs),
|
|
new Filter<Document>(x => x.ID).InList(docIDs),
|
|
Columns.None<Document>().Add(x => x.ID).Add(x => x.Data).Add(x => x.FileName))
|
|
Columns.None<Document>().Add(x => x.ID).Add(x => x.Data).Add(x => x.FileName))
|
|
.ToObjects<Document>().ToDictionary(x => x.ID, x => x);
|
|
.ToObjects<Document>().ToDictionary(x => x.ID, x => x);
|
|
|
|
|
|
- var pages = new List<DataEntryReGroupWindow.Page>();
|
|
|
|
- string filename = "";
|
|
|
|
- foreach (var docID in docIDs)
|
|
|
|
|
|
+ foreach (var dataEntryDoc in dataEntryDocs)
|
|
{
|
|
{
|
|
- if (docs.TryGetValue(docID, out var doc))
|
|
|
|
|
|
+ if (docs.TryGetValue(dataEntryDoc.Document.ID, out var doc))
|
|
{
|
|
{
|
|
- filename = doc.FileName;
|
|
|
|
var ms = new MemoryStream(doc.Data);
|
|
var ms = new MemoryStream(doc.Data);
|
|
var pdfDoc = DataEntryReGroupWindow.RenderToPDF(doc.FileName, ms);
|
|
var pdfDoc = DataEntryReGroupWindow.RenderToPDF(doc.FileName, ms);
|
|
- foreach (var page in DataEntryReGroupWindow.SplitIntoPages(doc.FileName, pdfDoc))
|
|
|
|
|
|
+ yield return new(dataEntryDoc, DataEntryReGroupWindow.SplitIntoPages(doc.FileName, pdfDoc).ToList());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void DoExplodeAll()
|
|
|
|
+ {
|
|
|
|
+ var pages = ExplodeDocuments();
|
|
|
|
+
|
|
|
|
+ var groups = new List<DocumentGroup>();
|
|
|
|
+ foreach(var (doc, docPages) in pages)
|
|
|
|
+ {
|
|
|
|
+ if(docPages.Count == 1)
|
|
|
|
+ {
|
|
|
|
+ groups.Add(new DocumentGroup(doc.Document.FileName, docPages, doc.Tag.ID));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var extension = Path.GetExtension(doc.Document.FileName) ?? "";
|
|
|
|
+ var stem = Path.GetFileNameWithoutExtension(doc.Document.FileName);
|
|
|
|
+
|
|
|
|
+ foreach(var (i, page) in docPages.WithIndex())
|
|
{
|
|
{
|
|
- pages.Add(page);
|
|
|
|
|
|
+ var group = new DocumentGroup($"{stem} - {i + 1}{extension}", [page], doc.Tag.ID);
|
|
|
|
+ groups.Add(group);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ SavePageGroups(groups);
|
|
|
|
|
|
- if (ShowDocumentWindow(pages, filename, tagID))
|
|
|
|
|
|
+ DeleteItems(SelectedRows);
|
|
|
|
+ Refresh(false,true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void DoExplode()
|
|
|
|
+ {
|
|
|
|
+ var tagID = GetSelectedTagID();
|
|
|
|
+ var pages = ExplodeDocuments();
|
|
|
|
+ var filename = "";
|
|
|
|
+ var allPages = new List<DataEntryReGroupWindow.Page>();
|
|
|
|
+ foreach(var (doc, docPages) in pages)
|
|
|
|
+ {
|
|
|
|
+ filename = doc.Document.FileName;
|
|
|
|
+ allPages.AddRange(docPages);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ShowDocumentWindow(allPages, filename, tagID))
|
|
{
|
|
{
|
|
// ShowDocumentWindow already saves new scans, so we just need to get rid of the old ones.
|
|
// ShowDocumentWindow already saves new scans, so we just need to get rid of the old ones.
|
|
DeleteItems(SelectedRows);
|
|
DeleteItems(SelectedRows);
|
|
@@ -391,28 +437,33 @@ public class DataEntryGrid : DynamicDataGrid<DataEntryDocument>
|
|
return document;
|
|
return document;
|
|
}
|
|
}
|
|
|
|
|
|
- public bool ShowDocumentWindow(List<DataEntryReGroupWindow.Page> pages, string filename, Guid tagID)
|
|
|
|
|
|
+ private void SavePageGroups(IEnumerable<DocumentGroup> groups)
|
|
{
|
|
{
|
|
- var window = new DataEntryReGroupWindow(pages, filename, tagID);
|
|
|
|
- if (window.ShowDialog() == true)
|
|
|
|
|
|
+ Progress.ShowModal("Uploading Files", (progress) =>
|
|
{
|
|
{
|
|
- Progress.ShowModal("Uploading Files", (progress) =>
|
|
|
|
|
|
+ foreach (var group in groups)
|
|
{
|
|
{
|
|
- foreach (var group in window.Groups)
|
|
|
|
|
|
+ progress.Report($"Uploading '{group.FileName}'");
|
|
|
|
+ var doc = CombinePages(group.Pages);
|
|
|
|
+
|
|
|
|
+ byte[] data;
|
|
|
|
+ using (var ms = new MemoryStream())
|
|
{
|
|
{
|
|
- progress.Report($"Uploading '{group.FileName}'");
|
|
|
|
- var doc = CombinePages(group.Pages);
|
|
|
|
|
|
+ doc.Save(ms);
|
|
|
|
+ data = ms.ToArray();
|
|
|
|
+ }
|
|
|
|
|
|
- byte[] data;
|
|
|
|
- using (var ms = new MemoryStream())
|
|
|
|
- {
|
|
|
|
- doc.Save(ms);
|
|
|
|
- data = ms.ToArray();
|
|
|
|
- }
|
|
|
|
|
|
+ UploadDocument(group.FileName, data, group.TagID);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
- UploadDocument(group.FileName, data, group.TagID);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ public bool ShowDocumentWindow(List<DataEntryReGroupWindow.Page> pages, string filename, Guid tagID)
|
|
|
|
+ {
|
|
|
|
+ var window = new DataEntryReGroupWindow(pages, filename, tagID);
|
|
|
|
+ if (window.ShowDialog() == true)
|
|
|
|
+ {
|
|
|
|
+ SavePageGroups(window.Groups);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|