Pārlūkot izejas kodu

PRS DESKTOP / CLASSES - Upgrades to Staging Setouts for locking files

Nick-PRSDigital@bitbucket.org 1 gadu atpakaļ
vecāks
revīzija
e2c9043f05

+ 1 - 1
prs.classes/Entities/Setout/SetoutGroupLink.cs

@@ -7,7 +7,7 @@ namespace Comal.Classes
 {
     public class SetoutGroupLink : EntityLink<SetoutGroup>
     {
-        [LookupEditor(typeof(SetoutGroup))]
+        [CodePopupEditor(typeof(SetoutGroup), CodeColumn = "Name")]
         public override Guid ID { get; set; }
 
         public string Name { get; set; }

+ 21 - 0
prs.classes/Entities/Staging/Manufacturing/StagingMaterialList.cs

@@ -0,0 +1,21 @@
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Comal.Classes
+{
+    public class StagingMaterialList : Entity, IPersistent, IRemotable, ILicense<ManufacturingLicense>
+    {
+        public string Name { get; set; }
+
+        public DateTime Archived { get; set; }
+
+        protected override void Init()
+        {
+            Name = "";
+            Archived = DateTime.MinValue;
+            base.Init();
+        }
+    }
+}

+ 12 - 2
prs.classes/Entities/Staging/Setout/StagingSetout.cs

@@ -15,7 +15,7 @@ namespace Comal.Classes
         [NullEditor]
         public SetoutLink Setout { get; set; }
 
-        [DateTimeEditor(Editable =Editable.Disabled)]
+        [DateTimeEditor(Editable = Editable.Disabled)]
         public DateTime Archived { get; set; }
 
         [NullEditor]
@@ -23,7 +23,13 @@ namespace Comal.Classes
 
         public SetoutGroupLink Group { get; set; }
 
-    
+        public string SavePath { get; set; }
+
+        public DateTime Locked { get; set; }
+
+        [Caption("Locked By")]
+        public EmployeeLink LockedBy { get; set; }
+
         protected override void Init()
         {
             Number = "";
@@ -31,6 +37,10 @@ namespace Comal.Classes
             Setout = new SetoutLink();
             Task = new KanbanLink();
             Group = new SetoutGroupLink();
+            SavePath = "";
+            Locked = DateTime.MinValue;
+            Archived = DateTime.MinValue;
+            LockedBy = new EmployeeLink();
             base.Init();
         }
     }

+ 1 - 1
prs.classes/Entities/Staging/Setout/StagingSetoutDocument.cs

@@ -5,7 +5,7 @@ using System.Text;
 
 namespace Comal.Classes
 {
-    public class StagingSetoutDocument : EntityDocument<StagingSetoutLink>, IManyToMany<StagingSetout, Document>, ILicense<ManufacturingLicense>
+    public class StagingSetoutDocument : EntityDocument<StagingSetoutLink>, ILicense<ManufacturingLicense>, IOneToMany<StagingSetout>
     {
     }
 }

+ 11 - 0
prs.classes/StagingMaterialListDocument.cs

@@ -0,0 +1,11 @@
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Comal.Classes
+{
+    public class StagingMaterialListDocument : EntityDocument<StagingMaterialListLink>, ILicense<ManufacturingLicense>
+    {
+    }
+}

+ 20 - 0
prs.classes/StagingMaterialListLink.cs

@@ -0,0 +1,20 @@
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Comal.Classes
+{
+    public class StagingMaterialListLink : EntityLink<StagingMaterialList>
+    {
+        public override Guid ID { get; set; }
+
+        public string Name { get; set; }
+
+        protected override void Init()
+        {
+            Name = "";
+            base.Init();
+        }
+    }
+}

+ 10 - 0
prs.desktop/MainWindow.xaml.cs

@@ -794,6 +794,8 @@ namespace PRSDesktop
                         AddSetupSeparator(ProjectsTab);
                         AddSetupAction(ProjectsTab, "Manufacturing Watermarks", ViewWaterMarks, PRSDesktop.Resources.design,
                             Security.IsAllowed<CanConfigureFactoryFloor>());
+                        AddSetupAction(ProjectsTab, "Setout Groups", ViewSetoutGroups, PRSDesktop.Resources.draw,
+                            Security.IsAllowed<CanConfigureFactoryFloor>());
 
                         AddSetupModulesAndReports(ProjectsTab);
 
@@ -1238,6 +1240,7 @@ namespace PRSDesktop
             );
         }
 
+
         private void ViewSpreadsheetTemplates<TEntity>() where TEntity : Entity
         {
             SpreadsheetTemplateGrid grid = new SpreadsheetTemplateGrid();
@@ -2187,6 +2190,13 @@ namespace PRSDesktop
         }
 
 
+        private void ViewSetoutGroups()
+        {
+            var list = new MasterList(typeof(SetoutGroup));
+            list.ShowDialog();
+        }
+
+
         private void RolesSetup_Click()
         {
             var list = new MasterList(typeof(Role));

+ 93 - 73
prs.desktop/Panels/Staging/Setouts/StagingSetoutGrid.cs

@@ -4,15 +4,21 @@ using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
 using javax.print.attribute.standard;
+using Microsoft.Exchange.WebServices.Data;
+using Microsoft.Win32;
+using Syncfusion.Pdf.Parsing;
 using Syncfusion.UI.Xaml.Grid;
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
+using System.Drawing.Imaging;
+using net.sf.mpxj.common;
 
 namespace PRSDesktop
 {
@@ -20,13 +26,16 @@ namespace PRSDesktop
     {
         List<string> _existingFileNames = new List<string>();
         List<Job> _jobs = new List<Job>();
-        string _setoutsFolder = "";
 
         public StagingSetoutGrid()
         {
             HiddenColumns.Add(x => x.Setout.ID);
             HiddenColumns.Add(x => x.JobLink.ID);
             HiddenColumns.Add(x => x.Group.ID);
+            HiddenColumns.Add(x => x.Group.OptimizationDocument.ID);
+            HiddenColumns.Add(x => x.Locked);
+            HiddenColumns.Add(x => x.SavePath);
+            HiddenColumns.Add(x => x.LockedBy.ID);
             Options.Add(DynamicGridOption.FilterRows);
             Options.Add(DynamicGridOption.SelectColumns);
             Options.Add(DynamicGridOption.RecordCount);
@@ -61,10 +70,10 @@ namespace PRSDesktop
 
             var group = new SetoutGroup();
             var page = new DynamicDataGrid<SetoutGroup>();
-            page.OnAfterSave += (editor, items) => 
+            page.OnAfterSave += (editor, items) =>
             {
                 foreach (var staging in list)
-                { 
+                {
                     staging.Group.ID = group.ID;
                 }
                 new Client<StagingSetout>().Save(list, "Updated group");
@@ -73,9 +82,13 @@ namespace PRSDesktop
             return page.EditItems(new[] { group });
         }
 
-        private void Page_OnAfterSave(IDynamicEditorForm editor, BaseObject[] items)
+        protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
         {
-           
+            var dlg = new OpenFileDialog();
+            dlg.Multiselect = true;
+            dlg.Title = "Add Staging Files"; ;
+            if (dlg.ShowDialog() == true)
+                ScanFiles(dlg);
         }
 
         private void LoadJobs()
@@ -86,30 +99,24 @@ namespace PRSDesktop
                     _jobs.Add(row.ToObject<Job>());
         }
 
-        public void ScanFiles(string setoutsfolder)
+        public void ScanFiles(OpenFileDialog dlg)
         {
-            _setoutsFolder = setoutsfolder;
-
-            if (!Directory.Exists(_setoutsFolder))
-            {
-                MessageBox.Show("Invalid Setouts Folder - please configure settings");
-                return;
-            }
-
-            IEnumerable<FileInfo> files = GetFiles();
-
+            //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>();
 
-            foreach (var file in files)
+            foreach (var file in dlg.FileNames)
             {
-                if (!file.FullName.EndsWith(".pdf"))
+                if (!Path.GetExtension(file).Equals(".pdf"))
                     continue;
 
-                if (CheckStagingSetoutExists(file))
+                if (CheckStagingSetoutExists(Path.GetFileNameWithoutExtension(file)))
+                {
+                    //UpdateStagingDocument(file);
                     continue;
+                }
 
                 documents.Add(ReadFile(file));
             }
@@ -120,8 +127,8 @@ namespace PRSDesktop
             foreach (var doc in documents)
             {
                 var stagingsetout = new StagingSetout();
-                stagingsetout.Number = doc.FileName.Substring(0, doc.FileName.Length - 4);
-                stagingsetout.JobLink.ID = FindJob(doc.FileName.Substring(0, 4));
+                stagingsetout.Number = Path.GetFileNameWithoutExtension(doc.FileName);
+                stagingsetout.JobLink.ID = TryFindJob(doc.FileName);
                 new Client<StagingSetout>().Save(stagingsetout, "Created from sync setout function");
 
                 var stagingsetoutdoc = new StagingSetoutDocument();
@@ -137,11 +144,29 @@ namespace PRSDesktop
                 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);
         }
 
-        private Guid FindJob(string filePreFix)
+        private void UpdateStagingDocument(string file)
         {
-            var job = _jobs.FirstOrDefault(x => x.JobNumber.Equals(filePreFix));
+            CoreTable 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 doc = ReadFile(file);
+                new Client<Document>().Save(doc, "Created from Staging Setout Screen");
+                stagingSetoutDoc.DocumentLink.ID = doc.ID;
+                new Client<StagingSetoutDocument>().Save(stagingSetoutDoc, "Updated from Staging Setout Screen");
+            }
+        }
+
+        private Guid TryFindJob(string filePreFix)
+        {
+            var job = _jobs.FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0,4)));
+            if (job == null)  
+                job = _jobs.FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0, 5)));           
             if (job == null)
                 return Guid.Empty;
 
@@ -149,46 +174,28 @@ namespace PRSDesktop
                 return job.ID;
         }
 
-        private Document ReadFile(FileInfo file)
+        /// <summary>
+        /// Requires the fully qualified file name
+        /// </summary>
+        /// <param name="file"></param>
+        /// <returns></returns>
+        private Document ReadFile(string file)
         {
             Document doc = new Document();
-            doc.FileName = file.Name;
+            doc.FileName = Path.GetFileName(file);
             doc.Data = GetData(file);
             return doc;
         }
 
-        private byte[] GetData(FileInfo file)
+        private byte[] GetData(string file)
         {
-            Stream stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
+            Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
             byte[] pdfData = new byte[stream.Length];
             stream.Read(pdfData, 0, Convert.ToInt32(pdfData.Length));
             stream.Dispose();
             return pdfData;
         }
 
-        private IEnumerable<FileInfo> GetFiles()
-        {
-            string folder = _setoutsFolder;
-            var dir = new DirectoryInfo(folder);
-            return dir.GetFiles();
-        }
-
-        public void ReloadFile(IEntityDocument document)
-        {
-            var files = GetFiles();
-            foreach (var file in files)
-            {
-                if (file.Name == document.DocumentLink.FileName)
-                {
-                    CoreTable table = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(document.DocumentLink.ID));
-                    var doc = table.Rows.FirstOrDefault().ToObject<Document>();
-                    doc.Data = GetData(file);
-                    new Client<Document>().Save(doc, "Reloaded Marked up Document");
-                    return;
-                }
-            }
-        }
-
         private void LoadExistingStaging()
         {
             CoreTable stagingseouttable = new Client<StagingSetout>().Query(
@@ -199,42 +206,55 @@ namespace PRSDesktop
                 _existingFileNames.Add(row.Get<StagingSetout, string>(x => x.Number));
         }
 
-        private bool CheckStagingSetoutExists(FileInfo file)
+        private bool CheckStagingSetoutExists(string file)
         {
             foreach (var existing in _existingFileNames)
             {
-                if (file.Name.Substring(0, file.Name.Length - 4).Equals(existing))
+                if (file.Equals(existing))
                     return true;
             }
 
             return false;
         }
 
-        protected override void Reload(Filters<StagingSetout> criteria, Columns<StagingSetout> columns, ref SortOrder<StagingSetout>? sort, Action<CoreTable?, Exception?> action)
+        public void ReloadFile(StagingSetout stagingSetout)
         {
-            criteria.Add(new Filter<StagingSetout>(x => x.Archived).IsEqualTo(DateTime.MinValue));
-            base.Reload(criteria, columns, ref sort, action);
-        }
+            if (string.IsNullOrWhiteSpace(stagingSetout.SavePath))
+                return;
 
-        public void DeleteFile(IEntityDocument document)
-        {
-            var file = GetFiles().FirstOrDefault(x => x.Name == document.DocumentLink.FileName);
-            if (file.Exists)
+            CoreTable table = new Client<StagingSetoutDocument>().Query(
+                new Filter<StagingSetoutDocument>(x => x.EntityLink.ID).IsEqualTo(stagingSetout.ID),
+                new Columns<StagingSetoutDocument>(x => x.DocumentLink.ID)
+                );
+            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()
+                .ToObject<Document>();
+
+            FileInfo file = new FileInfo(stagingSetout.SavePath);
+            try
             {
-                try
-                {
-                    file.Attributes = FileAttributes.Normal;
-                    file.Delete();
-                }
-                catch (Exception ex)
-                {
-                    MessageBox.Show("If your file is currently open in another program, please close it now and press OK to try again", "Error deleting file", MessageBoxButton.OK);
-                    file.Attributes = FileAttributes.Normal;
-                    file.Delete();
-                }
+                doc.Data = GetData(stagingSetout.SavePath);
+                stagingSetout.SavePath = "";
+                stagingSetout.LockedBy.ID = Guid.Empty;
+                file.Attributes = FileAttributes.Normal;
+                file.Delete();
+                MultiSave save = new MultiSave();
+                save.Add(typeof(Document), doc);
+                save.Add(typeof(StagingSetout), stagingSetout);
+                save.Save(null, "Reloaded / Unlocked staging setout");
             }
-            else
-                MessageBox.Show("Could not find file!");
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message);
+            }
+        }
+
+        protected override void Reload(Filters<StagingSetout> criteria, Columns<StagingSetout> columns, ref SortOrder<StagingSetout>? sort, Action<CoreTable?, Exception?> action)
+        {
+            criteria.Add(new Filter<StagingSetout>(x => x.Archived).IsEqualTo(DateTime.MinValue));
+            base.Reload(criteria, columns, ref sort, action);
         }
     }
 }

+ 8 - 1
prs.desktop/Panels/Staging/StagingPanel.xaml

@@ -11,7 +11,14 @@
     <dynamicgrid:DynamicSplitPanel x:Name="mainPanel" View="Combined" MasterCaption="Setouts Folder" AnchorWidth="500">
 
         <dynamicgrid:DynamicSplitPanel.Master>
-            <local:StagingSetoutGrid Grid.Column="0" x:Name="stagingSetoutGrid"/>
+            <Grid x:Name="masterGrid">
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="2*"/>
+                    <RowDefinition Height="*"/>
+                </Grid.RowDefinitions>
+                <local:StagingSetoutGrid Grid.Row="0" x:Name="stagingSetoutGrid" Margin="2.5"/>
+                <local:StagingMaterialListGrid Grid.Row="1" x:Name="stagingMaterialListGrid" Margin="2.5"/>
+            </Grid>
         </dynamicgrid:DynamicSplitPanel.Master>
             
         <dynamicgrid:DynamicSplitPanel.Detail>

+ 32 - 15
prs.desktop/Panels/Staging/StagingPanel.xaml.cs

@@ -9,6 +9,7 @@ using InABox.Clients;
 using InABox.Configuration;
 using InABox.DynamicGrid;
 using System.Diagnostics;
+using System.IO;
 
 namespace PRSDesktop
 {
@@ -36,17 +37,14 @@ namespace PRSDesktop
         private StagingPanellSettings _settings = new StagingPanellSettings();
 
         StagingSetout _item = new StagingSetout();
+
+        DynamicDataGrid<Document> _materialDocs;
         public StagingPanel()
         {
             InitializeComponent();
             SectionName = nameof(StagingPanel);
         }
 
-        private void DocumentPreviewer_OnMarkupComplete(IEntityDocument document)
-        {
-            stagingSetoutGrid.ReloadFile(document);
-            stagingSetoutGrid.Refresh(false, true);
-        }
         private void DocumentPreviewer_OnApproved(IEntityDocument stagingsetoutdocument)
         {
             if (_item.Group.ID == Guid.Empty)
@@ -85,11 +83,14 @@ namespace PRSDesktop
                 setoutdoc.DocumentLink.ID = stagingsetoutdocument.DocumentLink.ID;
 
                 List<SetoutDocument> setoutdocs = new List<SetoutDocument>
-                    {
+                {
                         setoutdoc
-                    };
+                };
 
-                CoreTable oldDocsTable = new Client<SetoutDocument>().Query(new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setout.ID));
+                CoreTable oldDocsTable = new Client<SetoutDocument>().Query(
+                    new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setout.ID)
+                    .And(x => x.DocumentLink.ID).IsNotEqualTo(_item.Group.OptimizationDocument.ID)
+                    );
                 foreach (var row in oldDocsTable.Rows)
                 {
                     var oldDoc = row.ToObject<SetoutDocument>();
@@ -102,7 +103,7 @@ namespace PRSDesktop
                 new Client<SetoutDocument>().Save(setoutdocs, "Updated from Staging Screen");
                 new Client<Setout>().Save(setout, "Updated from Staging Screen");
 
-                MessageBox.Show("Document for setout " + _item.Number + " superceded.", "Success");
+                MessageBox.Show("Documents for setout " + _item.Number + " superceded.", "Success");
 
                 DeleteAndRefresh(stagingsetoutdocument);
             }
@@ -258,7 +259,6 @@ namespace PRSDesktop
             new Client<StagingSetout>().Save(_item, "Updated from staging screen");
             _item = new StagingSetout();
 
-            stagingSetoutGrid.DeleteFile(stagingsetoutdocument);
             documentPreviewer.Document = new StagingSetoutDocument();
             Refresh();
         }
@@ -292,7 +292,6 @@ namespace PRSDesktop
                 MessageBox.Show("Success - Task Created for Document " + _item.Number + " (Task no. " + savedTask.Number + " assigned to " + savedTask.EmployeeLink.Name + ")");
                 _item = new StagingSetout();
 
-                stagingSetoutGrid.DeleteFile(stagingsetoutdocument);
                 documentPreviewer.Document = new StagingSetoutDocument();
                 stagingSetoutGrid.Refresh(false, true);
             };
@@ -313,6 +312,11 @@ namespace PRSDesktop
 
             documentPreviewer.Document = doc;
             manufacturingControl.StagingSetout = _item;
+            documentPreviewer.Mode =
+                _item.Locked == DateTime.MinValue ? InABox.Wpf.DocumentApprovalControl.ControlMode.Markup :
+                _item.Locked != DateTime.MinValue && _item.LockedBy.ID == App.EmployeeID ? InABox.Wpf.DocumentApprovalControl.ControlMode.Complete :
+                _item.Locked != DateTime.MinValue && _item.LockedBy.ID != App.EmployeeID ? InABox.Wpf.DocumentApprovalControl.ControlMode.Locked :
+               InABox.Wpf.DocumentApprovalControl.ControlMode.Markup;
         }
 
         public bool IsReady { get; set; }
@@ -372,8 +376,8 @@ namespace PRSDesktop
 
         public void Refresh()
         {
-            stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
-            stagingSetoutGrid.Refresh(false, true);
+            //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
+            stagingSetoutGrid.Refresh(false, true);        
 
             manufacturingControl.StagingSetout = new StagingSetout();
             manufacturingControl.Refresh();
@@ -398,7 +402,7 @@ namespace PRSDesktop
             documentPreviewer.OnRejected += DocumentPreviewer_OnRejected;
             documentPreviewer.OnApproved += DocumentPreviewer_OnApproved;
 
-            stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
+            //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
             stagingSetoutGrid.Refresh(true, true);
             stagingSetoutGrid.OnSelectItem += StagingSetoutGrid_OnSelectItem;
         }
@@ -406,17 +410,30 @@ namespace PRSDesktop
 
         private void DocumentPreviewer_OnMarkupSelected(IEntityDocument document)
         {
+            var doc = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(document.DocumentLink.ID)).Rows.FirstOrDefault().ToObject<Document>();
+            var tempdocpath = Path.GetTempPath() + @"\" + doc.FileName;
+            _item.SavePath = tempdocpath;
+            _item.LockedBy.ID = App.EmployeeID;
+            new Client<StagingSetout>().Save(_item, "Locked from Staging Screen");
+            File.WriteAllBytes(tempdocpath, doc.Data);
             using (Process p = new Process())
             {
                 p.StartInfo = new ProcessStartInfo()
                 {
                     UseShellExecute = true,
-                    FileName = _settings.SetoutsFolder + @"\" + document.DocumentLink.FileName
+                    FileName = tempdocpath
                 };
 
                 p.Start();
             }
+            stagingSetoutGrid.Refresh(false, true);
         }
+        private void DocumentPreviewer_OnMarkupComplete(IEntityDocument document)
+        {
+            stagingSetoutGrid.ReloadFile(_item);
+            stagingSetoutGrid.Refresh(false, true);
+        }
+
 
         public void Shutdown()
         {

+ 79 - 0
prs.desktop/StagingMaterialListGrid.cs

@@ -0,0 +1,79 @@
+using com.sun.security.ntlm;
+using Comal.Classes;
+using InABox.Clients;
+using InABox.Core;
+using InABox.DynamicGrid;
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PRSDesktop
+{
+    public class StagingMaterialListGrid : DynamicDataGrid<StagingMaterialList>
+    {
+        public StagingMaterialListGrid()
+        {
+            Options.Remove(DynamicGridOption.ImportData);
+            Options.Remove(DynamicGridOption.ExportData);
+        }
+
+        protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
+        {
+            var dlg = new OpenFileDialog();
+            dlg.Multiselect = true;
+            dlg.Title = "Add Staging Files"; ;
+            if (dlg.ShowDialog() == true)
+            {
+                List<Document> documents = new List<Document>();
+                foreach (var file in dlg.FileNames)
+                    documents.Add(ReadFile(file));
+
+                new Client<Document>().Save(documents, "Created from Staging Screen");
+
+                foreach (var document in documents)
+                {
+                    var materiallist = new StagingMaterialList();
+                    materiallist.Name = Path.GetFileNameWithoutExtension(document.FileName);
+
+                    new Client<StagingMaterialList>().Save(materiallist, "Created from Staging Screen");
+
+                    var materiallistdoc = new StagingMaterialListDocument();
+                    materiallistdoc.EntityLink.ID = materiallist.ID;
+                    materiallistdoc.DocumentLink.ID = document.ID;
+
+                    new Client<StagingMaterialListDocument>().Save(materiallistdoc, "Created from Staging Screen");
+
+                    Refresh(false, true);
+                }
+            }
+            base.DoAdd(OpenEditorOnDirectEdit);
+        }
+
+        private Document ReadFile(string file)
+        {
+            Document doc = new Document();
+            doc.FileName = Path.GetFileName(file);
+            doc.Data = GetData(file);
+            return doc;
+        }
+
+        private byte[] GetData(string file)
+        {
+            Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
+            byte[] pdfData = new byte[stream.Length];
+            stream.Read(pdfData, 0, Convert.ToInt32(pdfData.Length));
+            stream.Dispose();
+            return pdfData;
+        }
+
+        protected override void Reload(Filters<StagingMaterialList> criteria, Columns<StagingMaterialList> columns, ref SortOrder<StagingMaterialList>? sort, Action<CoreTable?, Exception?> action)
+        {
+            criteria.Add(new Filter<StagingMaterialList>(x => x.Archived).IsEqualTo(DateTime.MinValue));
+            base.Reload(criteria, columns, ref sort, action);
+        }
+    }
+}

+ 18 - 17
prs.stores/EntityDocumentStore.cs

@@ -22,9 +22,7 @@ namespace PRSStores
         }
 
         private void SaveThumbnail(TEntityDocument entity)
-        {
-            var stopwatch = new System.Diagnostics.Stopwatch();
-            stopwatch.Start();
+        {         
             if (entity.DocumentLink.ID == Guid.Empty)
                 return;
 
@@ -38,22 +36,25 @@ namespace PRSStores
             if (!doc.FileName.ToLower().EndsWith("pdf"))
                 return;
 
-            PdfLoadedDocument loadeddoc = new PdfLoadedDocument(doc.Data);
-            Bitmap image = loadeddoc.ExportAsImage(0, new SizeF(256, 256), true);
-            MemoryStream stream = new MemoryStream();
-            image.Save(stream, ImageFormat.Jpeg);
-            entity.Thumbnail = stream.ToArray();
-            stopwatch.Stop();
-            Logger.Send(LogType.Information, UserID, "Time taken to compress thumbnail " + stopwatch.ElapsedMilliseconds + " milliseconds");
+            try
+            {
+                PdfLoadedDocument loadeddoc = new PdfLoadedDocument(doc.Data);
+                Bitmap image = loadeddoc.ExportAsImage(0, new SizeF(256, 256), true);
+                MemoryStream stream = new MemoryStream();
+                image.Save(stream, ImageFormat.Jpeg);
+                entity.Thumbnail = stream.ToArray();
+            }
+            catch (Exception ex) 
+            {
+                Logger.Send(LogType.Information, UserID, ex.Message);
+            }
         }
     }
 
     //In order to have BeforeSave active for a specific EntityDocument, it has to be concretized as below
-    public class JobDocumentSetSetMileStoneFileStore : EntityDocumentStore<JobDocumentSetMileStoneFile, JobDocumentSetMileStone, JobDocumentSetMileStoneLink>
-    {
-    }
-    
-    public class MeetingItemDocumentStore : EntityDocumentStore<MeetingItemDocument, MeetingItem, MeetingItemLink>
-    {
-    }
+    public class JobDocumentSetSetMileStoneFileStore : EntityDocumentStore<JobDocumentSetMileStoneFile, JobDocumentSetMileStone, JobDocumentSetMileStoneLink> { }
+
+    public class MeetingItemDocumentStore : EntityDocumentStore<MeetingItemDocument, MeetingItem, MeetingItemLink> { }
+
+    public class SetoutDocumentStore : EntityDocumentStore<SetoutDocument, Setout, SetoutLink> { }
 }

+ 4 - 0
prs.stores/SetoutStore.cs

@@ -3,6 +3,10 @@ using System;
 using InABox.Core;
 using System.Collections.Generic;
 using System.Linq;
+using Syncfusion.Pdf.Parsing;
+using System.Drawing;
+using System.IO;
+using System.Drawing.Imaging;
 
 namespace Comal.Stores
 {

+ 5 - 0
prs.stores/StagingSetoutStore.cs

@@ -15,6 +15,11 @@ namespace PRSStores
             if ((entity.Setout.ID != Guid.Empty || entity.Task.ID != Guid.Empty) && entity.Archived == DateTime.MinValue)
                 entity.Archived = DateTime.Now;
 
+            if (!string.IsNullOrWhiteSpace(entity.SavePath) && entity.Locked == DateTime.MinValue)
+                entity.Locked = DateTime.Now;
+            else if (string.IsNullOrWhiteSpace(entity.SavePath) && entity.Locked != DateTime.MinValue)
+                entity.Locked = DateTime.MinValue;
+
             base.BeforeSave(entity);
         }
     }