|
|
@@ -19,13 +19,18 @@ using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Drawing.Imaging;
|
|
|
using net.sf.mpxj.common;
|
|
|
+using System.ComponentModel;
|
|
|
|
|
|
namespace PRSDesktop
|
|
|
{
|
|
|
public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
|
|
|
{
|
|
|
- List<string> _existingFileNames = new List<string>();
|
|
|
- List<Job> _jobs = new List<Job>();
|
|
|
+ public delegate void CustomiseSetoutsEvent(IReadOnlyList<StagingSetout> setouts);
|
|
|
+
|
|
|
+ public event CustomiseSetoutsEvent? OnCustomiseSetouts;
|
|
|
+
|
|
|
+ private List<Document> _existingFiles = new();
|
|
|
+ private Job[]? _jobs = null;
|
|
|
|
|
|
public StagingSetoutGrid()
|
|
|
{
|
|
|
@@ -37,8 +42,6 @@ namespace PRSDesktop
|
|
|
HiddenColumns.Add(x => x.SavePath);
|
|
|
HiddenColumns.Add(x => x.LockedBy.ID);
|
|
|
|
|
|
- LoadJobs();
|
|
|
-
|
|
|
AddButton("Create Group", null, CreateGroup);
|
|
|
}
|
|
|
protected override void DoReconfigure(FluentList<DynamicGridOption> options)
|
|
|
@@ -93,63 +96,62 @@ namespace PRSDesktop
|
|
|
{
|
|
|
var dlg = new OpenFileDialog();
|
|
|
dlg.Multiselect = true;
|
|
|
- dlg.Title = "Add Staging Files"; ;
|
|
|
+ dlg.Title = "Add Staging Files";
|
|
|
+ dlg.Filter = "PDF Files (*.pdf)|*.pdf";
|
|
|
if (dlg.ShowDialog() == true)
|
|
|
- ScanFiles(dlg);
|
|
|
+ AddFiles(dlg.FileNames);
|
|
|
}
|
|
|
|
|
|
- private void LoadJobs()
|
|
|
+ private Job[] GetJobs()
|
|
|
{
|
|
|
- CoreTable table = new Client<Job>().Query(null, new Columns<Job>(x => x.ID, x => x.JobNumber, x => x.Name));
|
|
|
- if (table.Rows.Any())
|
|
|
- foreach (CoreRow row in table.Rows)
|
|
|
- _jobs.Add(row.ToObject<Job>());
|
|
|
+ _jobs ??= new Client<Job>().Query(null, new Columns<Job>(x => x.ID, x => x.JobNumber, x => x.Name))
|
|
|
+ .ToObjects<Job>().ToArray();
|
|
|
+ return _jobs;
|
|
|
}
|
|
|
|
|
|
- public void ScanFiles(OpenFileDialog dlg)
|
|
|
+ public void AddFiles(string[] fileNames)
|
|
|
{
|
|
|
- //this will load any which are not archived yet to compare with the files being added
|
|
|
LoadExistingStaging();
|
|
|
|
|
|
- List<Document> documents = new List<Document>();
|
|
|
- List<StagingSetoutDocument> stagingdocs = new List<StagingSetoutDocument>();
|
|
|
+ var documents = new List<Document>();
|
|
|
+ var stagingdocs = new List<StagingSetoutDocument>();
|
|
|
|
|
|
- foreach (var file in dlg.FileNames)
|
|
|
+ var cancel = new CancelEventArgs();
|
|
|
+ foreach (var file in fileNames)
|
|
|
{
|
|
|
- if (!Path.GetExtension(file).Equals(".pdf"))
|
|
|
- continue;
|
|
|
-
|
|
|
- if (CheckStagingSetoutExists(Path.GetFileNameWithoutExtension(file)))
|
|
|
+ var document = ReadFile(file);
|
|
|
+ if (!CheckSetoutClash(document, cancel))
|
|
|
{
|
|
|
- //UpdateStagingDocument(file);
|
|
|
- continue;
|
|
|
+ if (cancel.Cancel)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- documents.Add(ReadFile(file));
|
|
|
+ documents.Add(document);
|
|
|
}
|
|
|
|
|
|
new Client<Document>().Save(documents, "Created from sync setout function");
|
|
|
|
|
|
- var messages = new List<string>();
|
|
|
- foreach (var doc in documents)
|
|
|
+ var stagingSetouts = documents.Select(x => new StagingSetout
|
|
|
{
|
|
|
- var stagingsetout = new StagingSetout();
|
|
|
- stagingsetout.Number = Path.GetFileNameWithoutExtension(doc.FileName);
|
|
|
- stagingsetout.JobLink.ID = TryFindJob(doc.FileName);
|
|
|
- new Client<StagingSetout>().Save(stagingsetout, "Created from sync setout function");
|
|
|
+ Number = x.FileName
|
|
|
+ }).ToArray();
|
|
|
+
|
|
|
+ OnCustomiseSetouts?.Invoke(stagingSetouts);
|
|
|
+ new Client<StagingSetout>().Save(stagingSetouts, "Created from sync setout function");
|
|
|
|
|
|
+ for(int i = 0; i < documents.Count; ++i)
|
|
|
+ {
|
|
|
var stagingsetoutdoc = new StagingSetoutDocument();
|
|
|
- stagingsetoutdoc.EntityLink.ID = stagingsetout.ID;
|
|
|
- stagingsetoutdoc.DocumentLink.ID = doc.ID;
|
|
|
+ stagingsetoutdoc.EntityLink.ID = stagingSetouts[i].ID;
|
|
|
+ stagingsetoutdoc.DocumentLink.ID = documents[i].ID;
|
|
|
stagingdocs.Add(stagingsetoutdoc);
|
|
|
-
|
|
|
- if (stagingsetout.JobLink.ID == Guid.Empty)
|
|
|
- messages.Add(doc.FileName);
|
|
|
}
|
|
|
-
|
|
|
- if (messages.Any())
|
|
|
- MessageBox.Show("Job(s) not found for the following document(s): " + string.Join("," + Environment.NewLine, messages), "Warning");
|
|
|
-
|
|
|
new Client<StagingSetoutDocument>().Save(stagingdocs, "Created from sync setout function");
|
|
|
|
|
|
Refresh(false, true);
|
|
|
@@ -157,10 +159,11 @@ namespace PRSDesktop
|
|
|
|
|
|
private void UpdateStagingDocument(string file)
|
|
|
{
|
|
|
- CoreTable table = new Client<StagingSetoutDocument>().Query(new Filter<StagingSetoutDocument>(x => x.DocumentLink.FileName).IsEqualTo(Path.GetFileName(file)));
|
|
|
+ var table = new Client<StagingSetoutDocument>()
|
|
|
+ .Query(new Filter<StagingSetoutDocument>(x => x.DocumentLink.FileName).IsEqualTo(Path.GetFileName(file)));
|
|
|
if (table.Rows.Any())
|
|
|
{
|
|
|
- var stagingSetoutDoc = table.Rows.FirstOrDefault().ToObject<StagingSetoutDocument>();
|
|
|
+ var stagingSetoutDoc = table.Rows.First().ToObject<StagingSetoutDocument>();
|
|
|
|
|
|
var doc = ReadFile(file);
|
|
|
new Client<Document>().Save(doc, "Created from Staging Setout Screen");
|
|
|
@@ -171,7 +174,7 @@ namespace PRSDesktop
|
|
|
|
|
|
private Guid TryFindJob(string filePreFix)
|
|
|
{
|
|
|
- var job = _jobs.FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0, 4)) || x.JobNumber.Equals(filePreFix.Substring(0, 5)) || x.JobNumber.Equals(filePreFix.Substring(0, 6)));
|
|
|
+ var job = GetJobs().FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0, 4)) || x.JobNumber.Equals(filePreFix.Substring(0, 5)) || x.JobNumber.Equals(filePreFix.Substring(0, 6)));
|
|
|
return job == null ? Guid.Empty : job.ID;
|
|
|
}
|
|
|
|
|
|
@@ -185,6 +188,7 @@ namespace PRSDesktop
|
|
|
Document doc = new Document();
|
|
|
doc.FileName = Path.GetFileName(file);
|
|
|
doc.Data = GetData(file);
|
|
|
+ doc.CRC = CoreUtils.CalculateCRC(doc.Data);
|
|
|
return doc;
|
|
|
}
|
|
|
|
|
|
@@ -207,15 +211,28 @@ namespace PRSDesktop
|
|
|
_existingFileNames.Add(row.Get<StagingSetout, string>(x => x.Number));
|
|
|
}
|
|
|
|
|
|
- private bool CheckStagingSetoutExists(string file)
|
|
|
+ private bool CheckSetoutClash(Document document, CancelEventArgs args)
|
|
|
{
|
|
|
- foreach (var existing in _existingFileNames)
|
|
|
+ foreach (var existing in _existingFiles)
|
|
|
{
|
|
|
- if (file.Equals(existing))
|
|
|
- return true;
|
|
|
+ if (document.FileName.Equals(existing.FileName))
|
|
|
+ {
|
|
|
+ if(document.CRC != existing.CRC)
|
|
|
+ {
|
|
|
+ var result = MessageBox.Show($"A different file with the filename '{document.FileName}' already exists? Do you wish to replace the existing file with the new one?", "Replace Existing", MessageBoxButton.YesNoCancel);
|
|
|
+ if(result == MessageBoxResult.No)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else if(result == MessageBoxResult.Cancel)
|
|
|
+ {
|
|
|
+ args.Cancel = true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- return false;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
public void ReloadFile(StagingSetout stagingSetout)
|
|
|
@@ -230,7 +247,7 @@ namespace PRSDesktop
|
|
|
var doc = new Client<Document>().Query(
|
|
|
new Filter<Document>(x => x.ID).IsEqualTo(
|
|
|
table.Rows.FirstOrDefault().Get<StagingSetoutDocument, Guid>(x => x.DocumentLink.ID)))
|
|
|
- .Rows.FirstOrDefault()
|
|
|
+ .Rows.First()
|
|
|
.ToObject<Document>();
|
|
|
|
|
|
FileInfo file = new FileInfo(stagingSetout.SavePath);
|