Browse Source

Merge remote-tracking branch 'origin/nick' into kenric

Kenric Nugteren 2 years ago
parent
commit
f0b5eff189

+ 23 - 4
inabox.wpf/DynamicGrid/PDF/DocumentEditor.xaml.cs

@@ -1,5 +1,7 @@
-using System.ComponentModel;
+using System.Collections.Generic;
+using System.ComponentModel;
 using System.IO;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using InABox.Core;
@@ -21,6 +23,26 @@ namespace InABox.DynamicGrid
             SaveAllowed = false;
             InitializeComponent();
             _documents = documents;
+
+            CreateTabs(CheckSuperceded(documents));
+
+            bReady = true;
+
+            Documents.SelectedIndex = -1;
+        }
+
+        private List<IEntityDocument> CheckSuperceded(IEntityDocument[] documents)
+        {
+            var docs = documents.ToList();
+            if (docs.Count() > 1)
+            {              
+                docs.Sort((x, y) => x.Superceded.CompareTo(y.Superceded)); //ascending
+            }
+            return docs;
+        }
+
+        private void CreateTabs(List<IEntityDocument> documents)
+        {
             foreach (var doc in documents)
             {
                 var tab = new DynamicTabItem();
@@ -29,9 +51,6 @@ namespace InABox.DynamicGrid
                 Documents.Items.Add(tab);
             }
 
-            bReady = true;
-
-            Documents.SelectedIndex = -1;
         }
 
         //public bool PrintAllowed { get; set; }

+ 10 - 7
inabox.wpf/DynamicGrid/PDF/PDFEditorControl.xaml.cs

@@ -259,7 +259,10 @@ namespace InABox.DynamicGrid
                 return true;
             if (!String.Equals(entry.Get<Document, string>(x => x.CRC),index[id]))
             {
-                MessageBox.Show("This PDF has been revised, and will now refresh.\n\nPlease check the drawing for any applicable changes.");
+                Dispatcher.BeginInvoke(() => 
+                { 
+                    MessageBox.Show("This PDF has been revised, and will now refresh.\n\nPlease check the drawing for any applicable changes."); 
+                });                
                 return true;
             }
 
@@ -279,12 +282,13 @@ namespace InABox.DynamicGrid
             {
                 if (DownloadNeeded(_document.DocumentLink.ID))
                 {
-                    var dbdoc = new Client<Document>().Load(new Filter<Document>(x => x.ID).IsEqualTo(_document.DocumentLink.ID)).FirstOrDefault();
-                    if (dbdoc == null)
+                    CoreTable table = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(_document.DocumentLink.ID));
+                    if (!table.Rows.Any())
                     {
                         MessageBox.Show("Unable to Load File!");
                         return;
                     }
+                    var dbdoc = table.Rows.FirstOrDefault().ToObject<Document>();
 
                     var indexfile = Path.Combine(CoreUtils.GetPath(), "pdfindex.json");
                     var index = new Dictionary<Guid, string>();
@@ -306,7 +310,7 @@ namespace InABox.DynamicGrid
                     }
                     catch (Exception eGhostscript)
                     {
-                        Logger.Send(LogType.Error, "", "Ghostscript Error: "+eGhostscript.Message + "\n" + eGhostscript.StackTrace);
+                        Logger.Send(LogType.Information, "", "Ghostscript: " + eGhostscript.Message + "\n" + eGhostscript.StackTrace);
                     }
 
                     try
@@ -315,7 +319,7 @@ namespace InABox.DynamicGrid
                     }
                     catch (Exception eFlatten)
                     {
-                        Logger.Send(LogType.Error, "", "Flatten Error: "+eFlatten.Message + "\n" + eFlatten.StackTrace);
+                        Logger.Send(LogType.Error, "", "Flatten Error: " + eFlatten.Message + "\n" + eFlatten.StackTrace);
                     }
 
                     try
@@ -325,7 +329,7 @@ namespace InABox.DynamicGrid
                     }
                     catch (Exception eRasterize)
                     {
-                        Logger.Send(LogType.Error, "", "Rasterize Error: "+eRasterize.Message + "\n" + eRasterize.StackTrace);
+                        Logger.Send(LogType.Error, "", "Rasterize Error: " + eRasterize.Message + "\n" + eRasterize.StackTrace);
 
                     }
 
@@ -336,7 +340,6 @@ namespace InABox.DynamicGrid
                     pdfdocument = File.ReadAllBytes(cachefile);
                 }
 
-
                 var doc = new PdfLoadedDocument(pdfdocument);
 
                 currentAnnotations.Clear();