|
|
@@ -31,6 +31,7 @@ using LogikalDrawingFormat = Comal.Classes.LogikalDrawingFormat;
|
|
|
using PdfGraphics = InABox.Dxf.PdfGraphics;
|
|
|
using PRSDimensionUtils;
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
+using InABox.Wpf.Editors;
|
|
|
|
|
|
namespace PRSDesktop;
|
|
|
|
|
|
@@ -1146,14 +1147,19 @@ public class StagingSetoutGrid : DynamicDataGrid<Setout>
|
|
|
}
|
|
|
|
|
|
private void ImportDesignFiles()
|
|
|
+ {
|
|
|
+ ImportDesignFiles(allowComponents: true, AddDocuments, doRefresh: true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ImportDesignFiles(bool allowComponents, Action<IEnumerable<Tuple<string, Document>>> addAction, bool doRefresh)
|
|
|
{
|
|
|
var dlg = new OpenFileDialog
|
|
|
{
|
|
|
Multiselect = true,
|
|
|
Title = "Add Staging Files",
|
|
|
- Filter = "PDF and Component Files (*.pdf;*.xls;*.xlsx;*.csv;*.txt)|*.pdf;*.xls;*.xlsx;*.csv;*.txt|" +
|
|
|
+ Filter = (allowComponents ? "PDF and Component Files (*.pdf;*.xls;*.xlsx;*.csv;*.txt)|*.pdf;*.xls;*.xlsx;*.csv;*.txt|" : "") +
|
|
|
"PDF Files (*.pdf)|*.pdf|" +
|
|
|
- "Component Files (*.xls;*.xlsx;*.csv;*.txt)|*.xls;*.xlsx;*.csv;*.txt|" +
|
|
|
+ (allowComponents ? "Component Files (*.xls;*.xlsx;*.csv;*.txt)|*.xls;*.xlsx;*.csv;*.txt|" : "") +
|
|
|
"Image Files (*.bmp;*.png;*.jpg;*.jpeg)|*.bmp;*.png;*.jpg;*.jpeg|" +
|
|
|
"DXF Files (*.dxf)|*.dxf|" +
|
|
|
"All Files (*.*)|*.*"
|
|
|
@@ -1185,16 +1191,22 @@ public class StagingSetoutGrid : DynamicDataGrid<Setout>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- AddPDFFiles(pdfs, doRefresh: false);
|
|
|
- AddImageFiles(images, doRefresh: false);
|
|
|
- AddDXFFiles(dxfs, doRefresh: false);
|
|
|
- AddComponentFiles(components, Guid.Empty);
|
|
|
+ AddPDFFiles(pdfs, addAction);
|
|
|
+ AddImageFiles(images, addAction);
|
|
|
+ AddDXFFiles(dxfs, addAction);
|
|
|
+ if (allowComponents)
|
|
|
+ {
|
|
|
+ AddComponentFiles(components, Guid.Empty);
|
|
|
+ }
|
|
|
|
|
|
- Refresh(false, true);
|
|
|
+ if (doRefresh)
|
|
|
+ {
|
|
|
+ Refresh(false, true);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void AddDocuments(IEnumerable<Tuple<string, Document>> documents, bool doRefresh)
|
|
|
+ private void AddDocuments(IEnumerable<Tuple<string, Document>> documents)
|
|
|
{
|
|
|
if (!documents.Any())
|
|
|
return;
|
|
|
@@ -1285,16 +1297,11 @@ public class StagingSetoutGrid : DynamicDataGrid<Setout>
|
|
|
{
|
|
|
Client.Delete(setoutsToDelete, "Replaced by new setout");
|
|
|
}
|
|
|
-
|
|
|
- if (doRefresh)
|
|
|
- {
|
|
|
- Refresh(false, true);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- public void AddDXFFiles(IEnumerable<string> fileNames, bool doRefresh = true)
|
|
|
+ public void AddDXFFiles(IEnumerable<string> fileNames, Action<IEnumerable<Tuple<string, Document>>> addAction)
|
|
|
{
|
|
|
- AddDocuments(fileNames.Select(x =>
|
|
|
+ addAction(fileNames.Select(x =>
|
|
|
{
|
|
|
var dxf = DxfUtils.LoadDxf(x);
|
|
|
var pdf = DxfUtils.ProcessPdf(dxf);
|
|
|
@@ -1308,10 +1315,10 @@ public class StagingSetoutGrid : DynamicDataGrid<Setout>
|
|
|
CRC = CoreUtils.CalculateCRC(data),
|
|
|
TimeStamp = new FileInfo(x).LastWriteTime
|
|
|
});
|
|
|
- }), doRefresh: doRefresh);
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
- public void AddPDFFiles(IEnumerable<string> fileNames, bool doRefresh = true)
|
|
|
+ public void AddPDFFiles(IEnumerable<string> fileNames, Action<IEnumerable<Tuple<string, Document>>> addAction)
|
|
|
{
|
|
|
var cancel = new CancelEventArgs();
|
|
|
|
|
|
@@ -1333,15 +1340,15 @@ public class StagingSetoutGrid : DynamicDataGrid<Setout>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- AddDocuments(fileNames.Select(x =>
|
|
|
+ addAction(fileNames.Select(x =>
|
|
|
{
|
|
|
return new Tuple<string, Document>(x, Document.FromFile(x));
|
|
|
- }), doRefresh: doRefresh);
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
- public void AddImageFiles(IEnumerable<string> fileNames, bool doRefresh = true)
|
|
|
+ public void AddImageFiles(IEnumerable<string> fileNames, Action<IEnumerable<Tuple<string, Document>>> addAction)
|
|
|
{
|
|
|
- AddDocuments(fileNames.Select(x =>
|
|
|
+ addAction(fileNames.Select(x =>
|
|
|
{
|
|
|
var pdf = DataEntryReGroupWindow.RenderToPDF(x);
|
|
|
var data = pdf.SaveToBytes();
|
|
|
@@ -1354,7 +1361,7 @@ public class StagingSetoutGrid : DynamicDataGrid<Setout>
|
|
|
CRC = CoreUtils.CalculateCRC(data),
|
|
|
TimeStamp = new FileInfo(x).LastWriteTime
|
|
|
});
|
|
|
- }), doRefresh: doRefresh);
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
public void AddComponentFiles(IEnumerable<string> fileNames, Guid setoutID)
|
|
|
@@ -1365,22 +1372,6 @@ public class StagingSetoutGrid : DynamicDataGrid<Setout>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Requires the fully qualified file name
|
|
|
- /// </summary>
|
|
|
- /// <param name="file"></param>
|
|
|
- /// <returns></returns>
|
|
|
- private static Document ReadFile(string file)
|
|
|
- {
|
|
|
- var doc = new Document
|
|
|
- {
|
|
|
- FileName = Path.GetFileName(file),
|
|
|
- Data = GetData(file)
|
|
|
- };
|
|
|
- doc.CRC = CoreUtils.CalculateCRC(doc.Data);
|
|
|
- return doc;
|
|
|
- }
|
|
|
-
|
|
|
private static byte[] GetData(string file)
|
|
|
{
|
|
|
Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
|
@@ -1390,6 +1381,70 @@ public class StagingSetoutGrid : DynamicDataGrid<Setout>
|
|
|
return pdfData;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Upload a bunch of documents, and return unsaved <see cref="SetoutDocument"/>s, that will need to be linked to a setout.
|
|
|
+ /// </summary>
|
|
|
+ public IList<SetoutDocument> UploadNew()
|
|
|
+ {
|
|
|
+ var docs = new List<Tuple<string, Document>>();
|
|
|
+ ImportDesignFiles(allowComponents: false, doRefresh: false, addAction: docs.AddRange);
|
|
|
+
|
|
|
+ Client.Save(docs.Select(x => x.Item2), "Uploaded to setout");
|
|
|
+
|
|
|
+ return docs.ToArray(doc =>
|
|
|
+ {
|
|
|
+ var newDoc = new SetoutDocument();
|
|
|
+ newDoc.DocumentLink.CopyFrom(doc.Item2);
|
|
|
+ newDoc.Staging.OriginalPath = doc.Item1;
|
|
|
+ newDoc.Staging.OriginalCRC = doc.Item2.CRC;
|
|
|
+ return newDoc;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void SupercedeFile(SetoutDocument setoutDocument, Setout setout)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(setoutDocument.Staging.SavePath))
|
|
|
+ return;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var file = new FileInfo(setoutDocument.Staging.SavePath);
|
|
|
+ var doc = Document.FromFile(setoutDocument.Staging.SavePath);
|
|
|
+
|
|
|
+ var filename = $"{Path.GetFileNameWithoutExtension(doc.FileName)}_Revision{Path.GetExtension(doc.FileName)}";
|
|
|
+ if(TextEdit.Execute("New filename: ", ref filename))
|
|
|
+ {
|
|
|
+ doc.FileName = filename;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageWindow.ShowMessage("Process cancelled.", "Cancelled");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ setoutDocument.Staging.SavePath = "";
|
|
|
+ setoutDocument.Staging.LockedBy.CopyFrom(new Employee());
|
|
|
+ setoutDocument.Superceded = DateTime.Now;
|
|
|
+
|
|
|
+ var newSetoutDocument = new SetoutDocument();
|
|
|
+ newSetoutDocument.EntityLink.CopyFrom(setout);
|
|
|
+ newSetoutDocument.Staging.OriginalPath = setoutDocument.Staging.OriginalPath;
|
|
|
+ newSetoutDocument.Staging.OriginalCRC = setoutDocument.Staging.OriginalCRC;
|
|
|
+
|
|
|
+ file.Attributes = FileAttributes.Normal;
|
|
|
+ file.Delete();
|
|
|
+
|
|
|
+ Client.Save(doc, "Superceded staging setout");
|
|
|
+
|
|
|
+ newSetoutDocument.DocumentLink.CopyFrom(doc);
|
|
|
+ Client.Save([newSetoutDocument, setoutDocument], "Superceded staging setout");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageWindow.ShowError("Error superceding document", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static void ReloadFile(SetoutDocument setoutDocument)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(setoutDocument.Staging.SavePath))
|