瀏覽代碼

Added WaitCursor() when loading documents to database

Frank van den Bos 2 年之前
父節點
當前提交
b0caced755

+ 16 - 9
inabox.wpf/DynamicGrid/Editors/DocumentEditor/DocumentConfirm.xaml.cs

@@ -5,6 +5,7 @@ using System;
 using System.IO;
 using System.Reactive;
 using System.Windows;
+using InABox.WPF;
 
 namespace InABox.DynamicGrid
 {
@@ -67,7 +68,11 @@ namespace InABox.DynamicGrid
 
         public static Document? CheckDocument(Document newDocument, Func<string, Document?>? findDocument, out bool shouldSave)
         {
-            var existing = findDocument?.Invoke(newDocument.FileName);
+            Document existing = null;
+            
+            using (new WaitCursor())
+                existing = findDocument?.Invoke(newDocument.FileName);
+            
             if (existing != null)
             {
                 if ((existing.TimeStamp == DateTime.MinValue || existing.TimeStamp.ToString("yyyy-MM-ddThh:mm.ss.fff")
@@ -112,16 +117,18 @@ namespace InABox.DynamicGrid
                         }
                         else if (confirm.Result == DocumentAction.MakeCopy)
                         {
-                            var basefilename = Path.GetFileNameWithoutExtension(newDocument.FileName);
-                            var ext = Path.GetExtension(newDocument.FileName);
-                            var i = 0;
-                            while (existing is not null)
+                            using (new WaitCursor())
                             {
-                                i++;
-                                newDocument.FileName = Path.ChangeExtension(string.Format("{0} ({1})", basefilename, i), ext);
-                                existing = findDocument?.Invoke(newDocument.FileName);
+                                var basefilename = Path.GetFileNameWithoutExtension(newDocument.FileName);
+                                var ext = Path.GetExtension(newDocument.FileName);
+                                var i = 0;
+                                while (existing is not null)
+                                {
+                                    i++;
+                                    newDocument.FileName = Path.ChangeExtension(string.Format("{0} ({1})", basefilename, i), ext);
+                                    existing = findDocument?.Invoke(newDocument.FileName);
+                                }
                             }
-
                             shouldSave = true;
                             return newDocument;
                         }

+ 8 - 78
inabox.wpf/DynamicGrid/Editors/DocumentEditor/DocumentEditorControl.cs

@@ -6,6 +6,7 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
 using InABox.Core;
+using InABox.WPF;
 using Microsoft.Win32;
 
 namespace InABox.DynamicGrid
@@ -127,86 +128,13 @@ namespace InABox.DynamicGrid
             dlg.Filter = Filter;
             if (dlg.ShowDialog() == true)
             {
+                byte[] data = null;
                 var filename = Path.GetFileName(dlg.FileName).ToLower();
                 var timestamp = new FileInfo(dlg.FileName).LastWriteTime;
-                var data = File.ReadAllBytes(dlg.FileName);
+                using (new WaitCursor())
+                    data = File.ReadAllBytes(dlg.FileName);
                 var crc = CoreUtils.CalculateCRC(data);
-
-                //var existing = OnFindDocument?.Invoke(filename);
-                //if (existing != null)
-                //{
-                //    if ((existing.TimeStamp == DateTime.MinValue || existing.TimeStamp.ToString("yyyy-MM-ddThh:mm.ss.fff")
-                //            .Equals(timestamp.ToString("yyyy-MM-ddThh:mm.ss.fff"))) && existing.CRC.Equals(crc))
-                //    {
-                //        if (existing.TimeStamp == DateTime.MinValue)
-                //        {
-                //            existing.TimeStamp = timestamp;
-                //            OnSaveDocument?.Invoke(existing);
-                //        }
-
-                //        _document = existing;
-                //    }
-                //    else
-                //    {
-                //        var confirm = new DocumentConfirm
-                //        {
-                //            FileName = filename,
-                //            LocalSize = data.Length,
-                //            RemoteSize = existing.Data.Length,
-                //            LocalTimeStamp = timestamp,
-                //            RemoteTimeStamp = existing.TimeStamp
-                //        };
-                //        if (confirm.ShowDialog() == true)
-                //        {
-                //            if (confirm.Result == DocumentAction.Replace)
-                //            {
-                //                existing.Data = data;
-                //                existing.TimeStamp = timestamp;
-                //                existing.CRC = crc;
-                //                OnSaveDocument?.Invoke(existing);
-                //                _document = existing;
-                //            }
-                //            else if (confirm.Result == DocumentAction.UseExisting)
-                //            {
-                //                _document = existing;
-                //            }
-                //            else if (confirm.Result == DocumentAction.MakeCopy)
-                //            {
-                //                var basefilename = Path.GetFileNameWithoutExtension(filename);
-                //                var ext = Path.GetExtension(filename);
-                //                var i = 0;
-                //                while (existing is not null)
-                //                {
-                //                    i++;
-                //                    filename = Path.ChangeExtension(string.Format("{0} ({1})", basefilename, i), ext);
-                //                    existing = OnFindDocument?.Invoke(filename);
-                //                }
-
-                //                var document = new Document
-                //                {
-                //                    FileName = filename,
-                //                    Data = data,
-                //                    TimeStamp = timestamp,
-                //                    CRC = crc
-                //                };
-                //                OnSaveDocument?.Invoke(document);
-                //                _document = document;
-                //            }
-                //        }
-                //    }
-                //}
-                //else
-                //{
-                //    _document = new Document
-                //    {
-                //        FileName = filename,
-                //        Data = data,
-                //        TimeStamp = timestamp,
-                //        CRC = crc
-                //    };
-                //    OnSaveDocument?.Invoke(_document);
-                //}
-
+                
                 var newDocument = DocumentConfirm.CheckDocument(new Document
                 {
                     FileName = filename,
@@ -214,12 +142,14 @@ namespace InABox.DynamicGrid
                     Data = data,
                     CRC = crc
                 }, Host.FindDocument, out var shouldSave);
+                
                 if(newDocument != null)
                 {
                     _document = newDocument;
                     if (shouldSave)
                     {
-                        Host.SaveDocument(newDocument);
+                        using (new WaitCursor())
+                            Host.SaveDocument(newDocument);
                     }
                 }
 

+ 8 - 0
inabox.wpf/DynamicGrid/PDF/DocumentEditor.xaml.cs

@@ -102,6 +102,14 @@ namespace InABox.DynamicGrid
                         {
                             editor = new ImageEditorControl();
                         }
+                        else if (extension.Equals(".xls") || extension.Equals(".xlsx"))
+                        {
+                            editor = new SpreadsheetEditorControl();
+                        }
+                        else if (extension.Equals(".doc") || extension.Equals(".docx")  || extension.Equals(".rtf")  || extension.Equals(".html")  || extension.Equals(".htm")  || extension.Equals(".txt"))
+                        {
+                            editor = new RTFEditorControl();
+                        }
 
                         if (editor != null)
                         {