Преглед изворни кода

Fix un-authenticated not logging user out; added explode button for scans

Kenric Nugteren пре 2 година
родитељ
комит
25d44de369

+ 76 - 14
prs.desktop/MainWindow.xaml.cs

@@ -144,12 +144,13 @@ namespace PRSDesktop
         {
             NotificationsWatchDog = new DispatcherTimer { IsEnabled = false };
             NotificationsWatchDog.Tick += Notifications_Tick;
-            NotificationsWatchDog.Interval = new TimeSpan(0, 1, 0);
+            NotificationsWatchDog.Interval = new TimeSpan(0, 2, 0);
 
             ClientFactory.Notifications.AddHandler<Notification>(ReceiveNotification);
             ClientFactory.RegisterMailer(EmailType.IMAP, typeof(IMAPMailer));
             ClientFactory.RegisterMailer(EmailType.Exchange, typeof(ExchangeMailer));
             ClientFactory.OnLog += (_, message) => { Logger.Send(LogType.Information, ClientFactory.UserID, message); };
+            ClientFactory.OnRequestError += ClientFactory_OnRequestError;
 
             HotKeyManager.Initialize();
             HotKeyManager.RegisterHotKey(Key.F1, ShowHelp);
@@ -326,6 +327,42 @@ namespace PRSDesktop
             });
         }
 
+        private bool _loggingOut = false;
+
+        private void ClientFactory_OnRequestError(RequestException e)
+        {
+            if(e.Status == StatusCode.Unauthenticated)
+            {
+                switch (e.Method)
+                {
+                    case RequestMethod.Query:
+                    case RequestMethod.Save:
+                    case RequestMethod.Delete:
+                    case RequestMethod.MultiQuery:
+                    case RequestMethod.MultiSave:
+                    case RequestMethod.MultiDelete:
+                        if (!_loggingOut)
+                        {
+                            Dispatcher.InvokeAsync(() =>
+                            {
+                                _loggingOut = true;
+                                try
+                                {
+                                    Logout(null, true);
+                                }
+                                finally
+                                {
+                                    _loggingOut = false;
+                                }
+                            });
+                        }
+                        break;
+                    default:
+                        break;
+                }
+            }
+        }
+
         private void ApplyColorScheme()
         {
             
@@ -1443,20 +1480,45 @@ namespace PRSDesktop
         /// Logs the user out and unloads windows
         /// </summary>
         /// <param name="message">A message to display as the reason for logging out, or <c>null</c> for no message.</param>
-        private bool Logout(string? message = null)
+        private bool Logout(string? message = null, bool force = false)
         {
-            FinalizeAutoTimesheet();
+            // I really don't like all these try-catch blocks; unfortunately, if we are trying to log out and invalidate due to an unauthenticated user,
+            // all the queries that get called here will throw exceptions and thus break our system, failing to log out.
+            try
+            {
+                FinalizeAutoTimesheet();
+            }
+            catch
+            {
+                if (!force) throw;
+            }
 
-            UnloadWindow();
-            if (DatabaseType == DatabaseType.Standalone && !CoreUtils.GetVersion().Equals("???"))
-                scheduler.Stop();
+            // Try to unload the window;
+            try
+            {
+                UnloadWindow();
+                if (DatabaseType == DatabaseType.Standalone && !CoreUtils.GetVersion().Equals("???"))
+                    scheduler.Stop();
+            }
+            catch
+            {
+                if (!force) throw;
+            }
 
-            if (!CoreUtils.GetVersion().Equals("???"))
-                if (station.ID != Guid.Empty)
-                {
-                    ExecuteLogout();
-                }
-            ClearTrackingKanban();
+            // Next, try to set things to being empty
+            try
+            {
+                if (!CoreUtils.GetVersion().Equals("???"))
+                    if (station.ID != Guid.Empty)
+                    {
+                        ExecuteLogout();
+                    }
+                ClearTrackingKanban();
+            }
+            catch
+            {
+                if (!force) throw;
+            }
 
             ClientFactory.InvalidateUser();
             ConfigureMainScreen();
@@ -2824,10 +2886,10 @@ namespace PRSDesktop
         {
             //Task.Run(() =>
             //{
-            bool IsClockedOn = this.IsClockedOn();
-            
             try
             {
+                bool IsClockedOn = this.IsClockedOn();
+
                 if (IsClockedOn)
                 {
 

+ 20 - 11
prs.desktop/Panels/DataEntry/DocumentManipulationWindow.xaml

@@ -24,17 +24,17 @@
         <DockPanel Grid.Row="0" Grid.Column="1">
             <Label Content="Groups" FontWeight="Bold"/>
         </DockPanel>
-        <ScrollViewer Grid.Row="1" Grid.Column="0"
-                      Margin="5" 
-                      VerticalScrollBarVisibility="Auto"
-                      BorderBrush="Gray"
-                      BorderThickness="1">
-            <WrapPanel Name="Documents"
-                       Background="DimGray"
-                       AllowDrop="True"
-                       PreviewDragOver="Documents_DragOver"
-                       Drop="Documents_Drop"/>
-        </ScrollViewer>
+        <Border Grid.Row="1" Grid.Column="0"
+                BorderBrush="Gray" BorderThickness="1"
+                Margin="5">
+            <ScrollViewer VerticalScrollBarVisibility="Auto">
+                <WrapPanel Name="Documents"
+                           Background="DimGray"
+                           AllowDrop="True"
+                           PreviewDragOver="Documents_DragOver"
+                           Drop="Documents_Drop"/>
+            </ScrollViewer>
+        </Border>
         <ListBox x:Name="GroupList" ItemsSource="{Binding ElementName=Window,Path=Groups}"
                  Grid.Row="1" Grid.Column="1"
                  HorizontalContentAlignment="Stretch"
@@ -63,6 +63,15 @@
                     Width="70"
                     IsEnabled="False"
                     Click="Group_Click"/>
+            <ComboBox Name="TagBox"
+                      DockPanel.Dock="Right"
+                      Margin="0,5,5,5"
+                      VerticalContentAlignment="Center"
+                      Width="150"/>
+            <Label Content="Tag"
+                   DockPanel.Dock="Right"
+                   Margin="0,5,5,5"
+                   VerticalContentAlignment="Center"/>
             <TextBox x:Name="GroupName" Background="LightYellow"
                      DockPanel.Dock="Left"
                      VerticalContentAlignment="Center"

+ 122 - 48
prs.desktop/Panels/DataEntry/DocumentManipulationWindow.xaml.cs

@@ -1,4 +1,5 @@
-using InABox.Core;
+using Comal.Classes;
+using InABox.Core;
 using InABox.WPF;
 using Microsoft.Office.Interop.Outlook;
 using Motorola.Snapi.Attributes;
@@ -10,6 +11,7 @@ using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
 using System.Drawing;
 using System.IO;
 using System.Linq;
@@ -25,6 +27,7 @@ using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using DocumentPage = PRSDesktop.Panels.DataEntry.DocumentPage;
+using Exception = System.Exception;
 using Image = System.Windows.Controls.Image;
 
 namespace PRSDesktop
@@ -37,10 +40,13 @@ namespace PRSDesktop
 
             public List<DocumentManipulationWindow.Page> Pages { get; set; }
 
-            public DocumentGroup(string fileName, List<DocumentManipulationWindow.Page> pages)
+            public Guid TagID { get; set; }
+
+            public DocumentGroup(string fileName, List<DocumentManipulationWindow.Page> pages, Guid tagID)
             {
                 FileName = fileName;
                 Pages = pages;
+                TagID = tagID;
             }
         }
     }
@@ -54,6 +60,8 @@ namespace PRSDesktop
         public List<Page> Pages { get; set; }
         public ObservableCollection<DocumentGroup> Groups { get; set; }
 
+        private ScanTag? SelectedTag => TagBox.SelectedItem as ScanTag;
+
         public class Page
         {
             public string FileName { get; set; }
@@ -72,7 +80,7 @@ namespace PRSDesktop
             }
         }
 
-        public DocumentManipulationWindow(List<Page> pages, string filename)
+        public DocumentManipulationWindow(List<Page> pages, string filename, Guid tagID)
         {
             InitializeComponent();
 
@@ -80,6 +88,14 @@ namespace PRSDesktop
             GroupName.Text = Path.ChangeExtension(filename, ".pdf");
             Pages = pages;
             ReloadPages();
+
+            var tags = ScanGrid.GetVisibleScanTagList();
+            TagBox.ItemsSource = tags;
+            if (tagID != Guid.Empty)
+            {
+                TagBox.SelectedItem = tags.FirstOrDefault(x => x.ID == tagID);
+            }
+            TagBox.DisplayMemberPath = "Name";
         }
 
         private void ReloadPages()
@@ -87,7 +103,7 @@ namespace PRSDesktop
             Documents.Children.Clear();
             foreach (var page in Pages)
             {
-                page.Thumbnail ??= page.Pdf.ToLoadedDocument().ExportAsImage(page.PageIndex).AsBitmapImage(false);
+                page.Thumbnail ??= page.Pdf.AsLoadedDocument().ExportAsImage(page.PageIndex).AsBitmapImage(false);
 
                 var width = page.Thumbnail.Width;
                 var height = page.Thumbnail.Height;
@@ -136,7 +152,7 @@ namespace PRSDesktop
                     var filename = Path.ChangeExtension(GroupName.Text, ".pdf");
                     if(MessageBox.Show($"You still have ungrouped pages. Do you wish to combine them into a document called \"{filename}\"?", "Combine remaining?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                     {
-                        var group = new DocumentGroup(filename, Pages.ToList());
+                        var group = new DocumentGroup(filename, Pages.ToList(), SelectedTag?.ID ?? Guid.Empty);
                         Pages.Clear();
                         Groups.Add(group);
                     }
@@ -169,7 +185,7 @@ namespace PRSDesktop
                 Documents.Children.Remove(page);
                 Pages.Remove(page.Page);
             }
-            var group = new DocumentGroup(filename, selected.Select(x => x.Page).ToList());
+            var group = new DocumentGroup(filename, selected.Select(x => x.Page).ToList(), SelectedTag?.ID ?? Guid.Empty);
             Groups.Add(group);
             GroupList.ItemsSource = Groups;
             GroupName.Text = "";
@@ -193,22 +209,28 @@ namespace PRSDesktop
 
         #region Drag & Drop
 
-        private static PdfDocumentBase RenderToPDF(string filename, Stream stream)
+        private static bool TryRenderPDF(Stream stream, [NotNullWhen(true)] out PdfDocumentBase? doc)
         {
-            PdfDocumentBase pdf;
-
-            var extension = Path.GetExtension(filename).ToLower();
-            if (extension == ".pdf")
+            try
             {
-                pdf = new PdfLoadedDocument(stream);
+                doc = new PdfLoadedDocument(stream);
+                return true;
             }
-            else if (extension == ".jpg" || extension == ".jpeg" || extension == ".png" || extension == ".bmp")
+            catch (Exception)
+            {
+            }
+            doc = null;
+            return false;
+        }
+        private static bool TryRenderImage(Stream stream, [NotNullWhen(true)] out PdfDocumentBase? doc)
+        {
+            try
             {
                 var image = new PdfBitmap(stream);
 
-                var doc = new PdfDocument();
+                var pdfDoc = new PdfDocument();
 
-                var section = doc.Sections.Add();
+                var section = pdfDoc.Sections.Add();
                 section.PageSettings.Margins.All = 0;
                 section.PageSettings.Width = image.Width;
                 section.PageSettings.Height = image.Height;
@@ -216,16 +238,25 @@ namespace PRSDesktop
                 var page = section.Pages.Add();
                 page.Graphics.DrawImage(image, 0, 0, page.Size.Width, page.Size.Height);
 
-                pdf = doc;
+                doc = pdfDoc;
+                return true;
             }
-            else
+            catch(Exception)
+            {
+            }
+            doc = null;
+            return false;
+        }
+        private static bool TryRenderText(Stream stream, [NotNullWhen(true)] out PdfDocumentBase? doc)
+        {
+            try
             {
                 var bytes = new byte[stream.Length];
                 stream.Read(bytes, 0, bytes.Length);
                 var text = Encoding.UTF8.GetString(bytes);
 
-                var doc = new PdfDocument();
-                var page = doc.Pages.Add();
+                var pdfDoc = new PdfDocument();
+                var page = pdfDoc.Pages.Add();
 
                 var font = new PdfStandardFont(PdfFontFamily.Courier, 14);
                 var textElement = new PdfTextElement(text, font);
@@ -237,9 +268,47 @@ namespace PRSDesktop
 
                 textElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), layoutFormat);
 
-                pdf = doc;
+                doc = pdfDoc;
+                return true;
+            }
+            catch (Exception)
+            {
+            }
+            doc = null;
+            return false;
+        }
+
+        public static PdfDocumentBase RenderToPDF(string filename, Stream stream)
+        {
+            var extension = Path.GetExtension(filename).ToLower();
+            if (extension == ".pdf")
+            {
+                if(TryRenderPDF(stream, out var pdf)
+                    || TryRenderImage(stream, out pdf)
+                    || TryRenderText(stream, out pdf))
+                {
+                    return pdf;
+                }
             }
-            return pdf;
+            else if (extension == ".jpg" || extension == ".jpeg" || extension == ".png" || extension == ".bmp")
+            {
+                if (TryRenderImage(stream, out var pdf)
+                    || TryRenderPDF(stream, out pdf)
+                    || TryRenderText(stream, out pdf))
+                {
+                    return pdf;
+                }
+            }
+            else
+            {
+                if (TryRenderText(stream, out var pdf)
+                    || TryRenderImage(stream, out pdf)
+                    || TryRenderPDF(stream, out pdf))
+                {
+                    return pdf;
+                }
+            }
+            throw new Exception("Could not render file to PDF");
         }
 
         private static PdfDocumentBase RenderToPDF(string filename)
@@ -248,7 +317,7 @@ namespace PRSDesktop
             return RenderToPDF(filename, stream);
         }
 
-        public static List<Page>? HandleFileDrop(DragEventArgs e, out string fileName)
+        public static List<Tuple<string, PdfDocumentBase>>? HandleFileDrop(DragEventArgs e)
         {
             var dataObject = new OutlookDataObject(e.Data);
 
@@ -258,64 +327,69 @@ namespace PRSDesktop
 
             if (desc is not null)
             {
-                var pages = new List<DocumentManipulationWindow.Page>();
+                var docs = new List<Tuple<string, PdfDocumentBase>>();
                 var filenames = (string[])dataObject.GetData(desc);
                 var filestreams = (MemoryStream[])dataObject.GetData("FileContents");
-                fileName = "";
                 for (var i = 0; i < filenames.Length; i++)
                 {
                     var filename = filenames[i];
-                    fileName = filename;
                     var filestream = filestreams[i];
                     var doc = RenderToPDF(filename, filestream);
-                    var loaded = doc.ToLoadedDocument();
-                    for (int j = 0; j < loaded.PageCount(); ++j)
-                    {
-                        pages.Add(new(filename, loaded, j));
-                    }
+                    docs.Add(new(filename, doc));
                 }
-                return pages;
+                return docs;
             }
             else if (dataObject.GetDataPresent(DataFormats.FileDrop))
             {
-                var pages = new List<Page>();
-                fileName = "";
+                var docs = new List<Tuple<string, PdfDocumentBase>>();
                 foreach (var filename in (string[])dataObject.GetData(DataFormats.FileDrop))
                 {
                     if (File.Exists(filename))
                     {
-                        fileName = filename;
                         var doc = RenderToPDF(filename);
-                        var loaded = doc.ToLoadedDocument();
-                        for (int i = 0; i < loaded.PageCount(); ++i)
-                        {
-                            pages.Add(new(filename, loaded, i));
-                        }
+                        docs.Add(new(filename, doc));
                     }
                 }
-                return pages;
+                return docs;
             }
-            fileName = "";
             return null;
         }
 
+        public static List<Page> SplitIntoPages(string filename, PdfDocumentBase doc)
+        {
+            var pages = new List<Page>();
+            var loaded = doc.AsLoadedDocument();
+
+            for(int i = 0; i < loaded.PageCount(); ++i)
+            {
+                pages.Add(new(filename, loaded, i));
+            }
+            return pages;
+        }
+
         private void Documents_Drop(object sender, DragEventArgs e)
         {
             Task.Run(() =>
             {
-                var pages = HandleFileDrop(e, out var filename);
-                if (pages is not null)
+                var docs = HandleFileDrop(e);
+                if (docs is not null)
                 {
                     Dispatcher.Invoke(() =>
                     {
-                        foreach (var page in pages)
+                        var groupName = "";
+
+                        foreach (var (filename, doc) in docs)
                         {
-                            Pages.Add(page);
-                            ReloadPages();
+                            groupName = filename;
+                            foreach(var page in SplitIntoPages(filename, doc))
+                            {
+                                Pages.Add(page);
+                            }
                         }
-                        if (string.IsNullOrWhiteSpace(GroupName.Text))
+                        ReloadPages();
+                        if (string.IsNullOrWhiteSpace(GroupName.Text) && !string.IsNullOrWhiteSpace(groupName))
                         {
-                            GroupName.Text = Path.ChangeExtension(filename, ".pdf");
+                            GroupName.Text = Path.ChangeExtension(groupName, ".pdf");
                         }
                     });
                 }

+ 98 - 25
prs.desktop/Panels/DataEntry/ScanGrid.cs

@@ -3,7 +3,6 @@ using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.WPF;
-using NPOI.SS.Formula.Functions;
 using Syncfusion.Pdf;
 using System;
 using System.Collections.Generic;
@@ -11,13 +10,15 @@ using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using System.Windows.Forms;
+using System.Windows;
+using System.Windows.Controls;
 
 namespace PRSDesktop
 {
     public class ScanGrid : DynamicDataGrid<Scan>
     {
         private List<ScanTag>? _tags;
+        private Button? ExplodeBtn;
 
         public ScanGrid()
         {
@@ -30,35 +31,104 @@ namespace PRSDesktop
             {
                 ActionColumns.Add(new DynamicMenuColumn(MenuBuild, null));
             }
+            if (Security.CanEdit<Scan>())
+            {
+                ExplodeBtn = AddButton("Explode", null, Explode_Click);
+            }
+
+            if (Security.IsAllowed<CanSetupScanTags>())
+            {
+                AddButton("Setup Tags", null, SetupTags_Click);
+            }
 
             HiddenColumns.Add(x => x.Tag.ID);
+            HiddenColumns.Add(x => x.Document.ID);
         }
 
-        private List<ScanTag> GetVisibleTags()
+        private bool Explode_Click(Button button, CoreRow[] rows)
         {
-            if(_tags is null)
+            Guid tagID = Guid.Empty;
+            foreach(var row in rows)
             {
-                var tags =  new Client<ScanTag>().Query().ToList<ScanTag>();
+                var rowTag = row.Get<Scan, Guid>(x => x.Tag.ID);
+                if (tagID == Guid.Empty)
+                {
+                    tagID = rowTag;
+                }
+                else if(rowTag != tagID)
+                {
+                    tagID = Guid.Empty;
+                    break;
+                }
+            }
+
+            var docIDs = rows.Select(x => x.Get<Scan, Guid>(x => x.Document.ID)).ToArray();
+            var docs = new Client<Document>()
+                .Query(
+                    new Filter<Document>(x => x.ID).InList(docIDs),
+                    new Columns<Document>(x => x.ID).Add(x => x.Data).Add(x => x.FileName))
+                .ToObjects<Document>().ToDictionary(x => x.ID, x => x);
 
-                _tags = new List<ScanTag>();
-                foreach(var tag in tags)
+            var pages = new List<DocumentManipulationWindow.Page>();
+            string filename = "";
+            foreach(var docID in docIDs)
+            {
+                if(docs.TryGetValue(docID, out var doc))
                 {
-                    var entity = CoreUtils.GetEntityOrNull(tag.AppliesTo);
-                    if(entity is null || Security.CanView(entity))
+                    filename = doc.FileName;
+                    var ms = new MemoryStream(doc.Data);
+                    var pdfDoc = DocumentManipulationWindow.RenderToPDF(doc.FileName, ms);
+                    foreach(var page in DocumentManipulationWindow.SplitIntoPages(doc.FileName, pdfDoc))
                     {
-                        var tagHasEmployee = new Client<ScanTagDistributionEmployee>()
-                            .Query(
-                                new Filter<ScanTagDistributionEmployee>(x => x.Tag.ID).IsEqualTo(tag.ID)
-                                    .And(x => x.Employee.ID).IsEqualTo(App.EmployeeID),
-                                new Columns<ScanTagDistributionEmployee>(x => x.ID))
-                            .Rows.Any();
-                        if (tagHasEmployee)
-                        {
-                            _tags.Add(tag);
-                        }
+                        pages.Add(page);
                     }
                 }
             }
+            if(ShowDocumentWindow(pages, filename, tagID))
+            {
+                // ShowDocumentWindow already saves new scans, so we just need to get rid of the old ones.
+                DeleteItems(rows);
+                return true;
+            }
+            return false;
+        }
+
+        private bool SetupTags_Click(System.Windows.Controls.Button button, CoreRow[] rows)
+        {
+            var list = new MasterList(typeof(ScanTag));
+            if (list.ShowDialog() == true)
+                return true;
+            return false;
+        }
+
+        public static List<ScanTag> GetVisibleScanTagList()
+        {
+            var tags = new Client<ScanTag>().Query().ToList<ScanTag>();
+
+            var tagsList = new List<ScanTag>();
+            foreach (var tag in tags)
+            {
+                var entity = CoreUtils.GetEntityOrNull(tag.AppliesTo);
+                if (entity is null || Security.CanView(entity))
+                {
+                    var tagHasEmployee = new Client<ScanTagDistributionEmployee>()
+                        .Query(
+                            new Filter<ScanTagDistributionEmployee>(x => x.Tag.ID).IsEqualTo(tag.ID)
+                                .And(x => x.Employee.ID).IsEqualTo(App.EmployeeID),
+                            new Columns<ScanTagDistributionEmployee>(x => x.ID))
+                        .Rows.Any();
+                    if (tagHasEmployee)
+                    {
+                        tagsList.Add(tag);
+                    }
+                }
+            }
+            return tagsList;
+        }
+
+        private List<ScanTag> GetVisibleTags()
+        {
+            _tags ??= GetVisibleScanTagList();
             return _tags;
         }
 
@@ -96,7 +166,7 @@ namespace PRSDesktop
 
             var scan = row.ToObject<Scan>();
 
-            if (!scan.Processed && MessageBox.Show("Doing this will remove this scan from the list. Do you wish to continue?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes)
+            if (!scan.Processed && MessageBox.Show("Doing this will remove this scan from the list. Do you wish to continue?", "Confirm", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
             {
                 return;
             }
@@ -121,7 +191,7 @@ namespace PRSDesktop
             DragTable(typeof(Document), table);
         }
 
-        private void UploadDocument(string filename, byte[] data)
+        public void UploadDocument(string filename, byte[] data, Guid tagID)
         {
             var document = new Document
             {
@@ -135,6 +205,7 @@ namespace PRSDesktop
 
             var scan = new Scan();
             scan.Document.ID = document.ID;
+            scan.Tag.ID = tagID;
             new Client<Scan>().Save(scan, "");
 
             Dispatcher.Invoke(() =>
@@ -153,9 +224,9 @@ namespace PRSDesktop
             return document;
         }
 
-        public void ShowDocumentWindow(List<DocumentManipulationWindow.Page> pages, string filename)
+        public bool ShowDocumentWindow(List<DocumentManipulationWindow.Page> pages, string filename, Guid tagID)
         {
-            var window = new DocumentManipulationWindow(pages, filename);
+            var window = new DocumentManipulationWindow(pages, filename, tagID);
             if (window.ShowDialog() == true)
             {
                 Progress.ShowModal("Uploading Files", (progress) =>
@@ -172,15 +243,17 @@ namespace PRSDesktop
                             data = ms.ToArray();
                         }
 
-                        UploadDocument(group.FileName, data);
+                        UploadDocument(group.FileName, data, group.TagID);
                     }
                 });
+                return true;
             }
+            return false;
         }
 
         protected override void DoAdd()
         {
-            ShowDocumentWindow(new(), "");
+            ShowDocumentWindow(new(), "", Guid.Empty);
         }
 
         protected override void GenerateColumns(DynamicGridColumns columns)

+ 17 - 5
prs.desktop/Panels/DataEntry/ScanPanel.xaml.cs

@@ -28,6 +28,7 @@ using Path = System.IO.Path;
 using Image = System.Windows.Controls.Image;
 using com.sun.tools.doclets.@internal.toolkit.util;
 using Syncfusion.Windows.PdfViewer;
+using javax.xml.crypto;
 
 namespace PRSDesktop
 {
@@ -57,7 +58,7 @@ namespace PRSDesktop
                 return pdfDoc.Pages.Count;
             throw new Exception($"Unsupported PDF Document type {doc.GetType()}");
         }
-        public static PdfLoadedDocument ToLoadedDocument(this PdfDocumentBase doc)
+        public static PdfLoadedDocument AsLoadedDocument(this PdfDocumentBase doc)
         {
             if (doc is PdfLoadedDocument lDoc)
                 return lDoc;
@@ -70,6 +71,13 @@ namespace PRSDesktop
             }
             throw new Exception($"Unsupported PDF Document type {doc.GetType()}");
         }
+
+        public static byte[] SaveToBytes(this PdfDocumentBase doc)
+        {
+            using var ms = new MemoryStream();
+            doc.Save(ms);
+            return ms.ToArray();
+        }
     }
 
     /// <summary>
@@ -242,13 +250,17 @@ namespace PRSDesktop
         {
             Task.Run(() =>
             {
-                var pages = DocumentManipulationWindow.HandleFileDrop(e, out var filename);
-                if (pages is not null)
+                var docs = DocumentManipulationWindow.HandleFileDrop(e);
+                if (docs is not null)
                 {
-                    Dispatcher.Invoke(() =>
+                    foreach(var (filename, doc) in docs)
+                    {
+                        ScanGrid.UploadDocument(Path.ChangeExtension(filename, ".pdf"), doc.SaveToBytes(), Guid.Empty);
+                    }
+                    /*Dispatcher.Invoke(() =>
                     {
                         ScanGrid.ShowDocumentWindow(pages, filename);
-                    });
+                    });*/
                 }
             });
         }

+ 12 - 8
prs.desktop/Panels/DeliveryItems/ReadyToGoGrid.cs

@@ -66,20 +66,22 @@ namespace PRSDesktop
 
         public Guid JobID { get; set; }
 
-        private BitmapImage BarcodeImage(CoreRow arg)
+        private BitmapImage BarcodeImage(CoreRow? arg)
         {
             return barcode;
         }
 
-        private BitmapImage? SetoutImage(CoreRow arg)
+        private BitmapImage? SetoutImage(CoreRow? arg)
         {
             if (arg == null)
                 return null;
             return arg.IsEntityLinkValid<DeliveryItem, ManufacturingPacketLink>(x => x.ManufacturingPacketLink) ? setout : null;
         }
 
-        private bool SetoutClick(CoreRow arg)
+        private bool SetoutClick(CoreRow? arg)
         {
+            if (arg is null) return false;
+
             var setoutid = arg.EntityLinkID<DeliveryItem, SetoutLink>(x => x.ManufacturingPacketLink.SetoutLink) ?? Guid.Empty;
             if (setoutid != Guid.Empty)
             {
@@ -106,7 +108,7 @@ namespace PRSDesktop
             var date = DateTime.Today;
             if (DateEdit.Execute("Enter Delivered Date", ref date))
             {
-                Filter<DeliveryItem> filter = null;
+                Filter<DeliveryItem>? filter = null;
                 foreach (var row in rows)
                 {
                     var id = row.Get<DeliveryItem, Guid>(x => x.ID);
@@ -129,8 +131,10 @@ namespace PRSDesktop
             return false;
         }
 
-        private bool BarcodeClick(CoreRow arg)
+        private bool BarcodeClick(CoreRow? arg)
         {
+            if (arg is null) return false;
+
             var id = arg.Get<DeliveryItem, Guid>(x => x.ID);
             var group = arg.Get<DeliveryItem, string>(x => x.ManufacturingPacketLink.ManufacturingTemplateLink.Factory.Name);
             var ReportName = "Print Bar Codes" + (!string.IsNullOrWhiteSpace(group) ? " - " + group : "");
@@ -177,7 +181,7 @@ namespace PRSDesktop
             return true;
         }
 
-        private BitmapImage DeliveredImage(CoreRow arg)
+        private BitmapImage? DeliveredImage(CoreRow arg)
         {
             if (arg == null)
                 return Truck;
@@ -185,8 +189,8 @@ namespace PRSDesktop
             return date.IsEmpty() ? null : Tick;
         }
 
-        protected override void Reload(Filters<DeliveryItem> criteria, Columns<DeliveryItem> columns, ref SortOrder<DeliveryItem> sort,
-            Action<CoreTable, Exception> action)
+        protected override void Reload(Filters<DeliveryItem> criteria, Columns<DeliveryItem> columns, ref SortOrder<DeliveryItem>? sort,
+            Action<CoreTable?, Exception?> action)
         {
             var filter = new Filter<DeliveryItem>(x => x.DeliveredDate).IsEqualTo(DateTime.MinValue)
                 .And(x => x.ManufacturingPacketLink.Completed).IsGreaterThan(DateTime.MinValue.AddDays(1));

+ 1 - 0
prs.server/Engines/GPS/SigfoxListener.cs

@@ -16,6 +16,7 @@ using System.Net;
 using System.Security.Cryptography.X509Certificates;
 using System.Text;
 using System.Threading.Tasks;
+using RequestMethod = GenHTTP.Api.Protocol.RequestMethod;
 
 namespace PRSServer.Engines
 {

+ 1 - 0
prs.server/Engines/WebEngine/WebListener.cs

@@ -27,6 +27,7 @@ using RazorEngine.Configuration;
 using RazorEngine.Templating;
 using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
 using Cookie = GenHTTP.Api.Protocol.Cookie;
+using RequestMethod = GenHTTP.Api.Protocol.RequestMethod;
 
 namespace PRSServer
 {