浏览代码

Added max doc size to staging panel

Kenric Nugteren 1 年之前
父节点
当前提交
329e015f79

+ 21 - 0
prs.desktop/Panels/Staging/Setouts/StagingSetoutGrid.cs

@@ -25,6 +25,7 @@ using System.Windows.Media.Imaging;
 using InABox.Configuration;
 using NPOI.HSSF.Util;
 using System.Reactive.Linq;
+using InABox.Wpf;
 
 namespace PRSDesktop
 {
@@ -96,6 +97,8 @@ namespace PRSDesktop
         private Button PastePacketsButton;
         private StagingSetout? CopyPacketsSource;
 
+        public StagingPanellSettings PanelSettings { get; set; } = new StagingPanellSettings();
+
         public StagingSetoutGrid()
         {
             HiddenColumns.Add(x => x.Setout.ID);
@@ -494,6 +497,24 @@ namespace PRSDesktop
 
             var cancel = new CancelEventArgs();
 
+            // Convert MB to B
+            var maximum = PanelSettings.MaximumDocumentSize * 1000 * 1000;
+            if(maximum > 0)
+            {
+                var tooLarge = fileNames.Where(x =>
+                {
+                    var fileSize = new FileInfo(x).Length;
+                    return fileSize > maximum;
+                }).ToList();
+                if(tooLarge.Count > 0)
+                {
+                    if(!MessageWindow.ShowYesNo($"The following files are larger than {PanelSettings.MaximumDocumentSize} MB. Are you sure you wish to continue?\n\n{string.Join('\n', tooLarge)}", "Large files"))
+                    {
+                        return;
+                    }
+                }
+            }
+
             var newDocuments = fileNames.Select(x =>
             {
                 var file = ReadFile(x);

+ 6 - 0
prs.desktop/Panels/Staging/StagingPanel.xaml.cs

@@ -17,6 +17,7 @@ using System.Reflection;
 using System.Collections.Immutable;
 using StagingManufacturingPacketComponent = Comal.Classes.StagingManufacturingPacketComponent;
 using System.Threading.Tasks;
+using NPOI.SS.Formula.Functions;
 
 namespace PRSDesktop
 {
@@ -33,11 +34,15 @@ namespace PRSDesktop
         [ScriptEditor]
         public string? Script { get; set; }
 
+        [IntegerEditor(Caption = "Maximum Document Size (MB)", ToolTip = "The user will be warned when uploading documents which are larger than this size in megabytes. Set to zero for no maximum.")]
+        public int MaximumDocumentSize { get; set; }
+
         public StagingPanellSettings()
         {
             MarkupPathway = "";
             SetoutsFolder = "";
             Script = null;
+            MaximumDocumentSize = 0;
         }
 
         public string DefaultScript()
@@ -149,6 +154,7 @@ public class Module
             ProcessButton.Visibility = Security.IsAllowed<CanApproveSetouts>() ? Visibility.Visible : Visibility.Hidden;
 
             //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
+            stagingSetoutGrid.PanelSettings = _settings;
             stagingSetoutGrid.Refresh(true, false);
             SetoutComponentGrid.Refresh(true, false);