Преглед на файлове

Started work on Staging Stuff (DON"T MERGE YET)

Kenric Nugteren преди 2 години
родител
ревизия
023ff0e962

+ 0 - 34
prs.desktop/Panels/Staging/Manufacturing/ManufacturingPacketApprovalControl.xaml

@@ -1,34 +0,0 @@
-<UserControl x:Class="PRSDesktop.ManufacturingPacketApprovalControl"
-             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:PRSDesktop"
-             xmlns:dynamicgrid="clr-namespace:InABox.DynamicGrid;assembly=InABox.Wpf"
-             xmlns:wpf="clr-namespace:InABox.Wpf;assembly=InABox.Wpf" xmlns:local1="clr-namespace:PRSDesktop.Panels.Staging"
-             mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800">
-
-    <Grid>
-        <Grid.RowDefinitions>
-            <RowDefinition Height="*"/>
-            <RowDefinition Height="*"/>
-        </Grid.RowDefinitions>
-
-        <Border Grid.Row="0" BorderBrush="Gray" BorderThickness="0.5">
-            <local1:StagingManufacturingPacketGrid Grid.Row="1" x:Name="packetGrid"/>
-        </Border>
-
-        <Border Grid.Row="1">
-            <Grid>
-                <Grid.RowDefinitions>
-                    <RowDefinition Height="auto"/>
-                    <RowDefinition Height="*"/>
-                </Grid.RowDefinitions>
-                <Label Grid.Row="0" Content="Components" HorizontalAlignment="Center" FontWeight="DemiBold"/>
-                <local:StagingManufacturingPacketComponentGrid Grid.Row="1" x:Name="componentsGrid"/>
-            </Grid>
-        </Border>
-
-    </Grid>
-</UserControl>

+ 0 - 72
prs.desktop/Panels/Staging/Manufacturing/ManufacturingPacketApprovalControl.xaml.cs

@@ -1,72 +0,0 @@
-using Comal.Classes;
-using InABox.Core;
-using PRSDesktop.Panels.Staging;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-
-namespace PRSDesktop
-{
-    /// <summary>
-    /// Interaction logic for ManufacturingPacketApprovalControl.xaml
-    /// </summary>
-    public partial class ManufacturingPacketApprovalControl : UserControl
-    {
-        private StagingSetout stagingsetout;
-        public StagingSetout StagingSetout
-        {
-            get => stagingsetout;
-            set
-            {
-                stagingsetout = value;
-                packetGrid.StagingSetout = value;
-                componentsGrid.StagingPacket = new StagingManufacturingPacket();
-            }
-        }
-
-        public CoreTable Data => packetGrid.Data;
-
-        public void Refresh()
-        {
-            if (StagingSetout != null)
-                if (StagingSetout.ID != Guid.Empty)
-                {
-                    packetGrid.Refresh(false, true);
-                    componentsGrid.StagingPacket = new StagingManufacturingPacket();
-                }
-        }
-
-        public ManufacturingPacketApprovalControl()
-        {
-            InitializeComponent();
-            packetGrid.OnSelectItem += PacketGrid_OnSelectItem;
-        }
-
-        private void PacketGrid_OnSelectItem(object sender, InABox.DynamicGrid.DynamicGridSelectionEventArgs e)
-        {
-            componentsGrid.StagingPacket = packetGrid.SelectedRows.FirstOrDefault().ToObject<StagingManufacturingPacket>();
-        }
-
-        private void CreatePacketButton_Click(object sender, RoutedEventArgs e)
-        {
-            var packet = new StagingManufacturingPacket();
-            packet.StagingSetout.ID = stagingsetout.ID;
-            packet.Job.ID = stagingsetout.JobLink.ID;
-
-            var page = new StagingManufacturingPacketGrid();
-            if (page.EditItems(new[] { packet }))
-                packetGrid.Refresh(false, true);
-        }
-    }
-}

+ 1 - 1
prs.desktop/Panels/Staging/Manufacturing/StagingManufacturingPacketGrid.cs

@@ -10,7 +10,7 @@ namespace PRSDesktop.Panels.Staging
 {
     public class StagingManufacturingPacketGrid : DynamicDataGrid<StagingManufacturingPacket>
     {
-        private StagingSetout stagingsetout;
+        private StagingSetout stagingsetout = new StagingSetout();
 
         public StagingSetout StagingSetout
         {

+ 65 - 48
prs.desktop/Panels/Staging/Setouts/StagingSetoutGrid.cs

@@ -19,13 +19,18 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Drawing.Imaging;
 using net.sf.mpxj.common;
+using System.ComponentModel;
 
 namespace PRSDesktop
 {
     public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
     {
-        List<string> _existingFileNames = new List<string>();
-        List<Job> _jobs = new List<Job>();
+        public delegate void CustomiseSetoutsEvent(IReadOnlyList<StagingSetout> setouts);
+
+        public event CustomiseSetoutsEvent? OnCustomiseSetouts;
+
+        private List<Document> _existingFiles = new();
+        private Job[]? _jobs = null;
 
         public StagingSetoutGrid()
         {
@@ -37,8 +42,6 @@ namespace PRSDesktop
             HiddenColumns.Add(x => x.SavePath);
             HiddenColumns.Add(x => x.LockedBy.ID);
 
-            LoadJobs();
-
             AddButton("Create Group", null, CreateGroup);
         }
         protected override void DoReconfigure(FluentList<DynamicGridOption> options)
@@ -93,63 +96,62 @@ namespace PRSDesktop
         {
             var dlg = new OpenFileDialog();
             dlg.Multiselect = true;
-            dlg.Title = "Add Staging Files"; ;
+            dlg.Title = "Add Staging Files";
+            dlg.Filter = "PDF Files (*.pdf)|*.pdf";
             if (dlg.ShowDialog() == true)
-                ScanFiles(dlg);
+                AddFiles(dlg.FileNames);
         }
 
-        private void LoadJobs()
+        private Job[] GetJobs()
         {
-            CoreTable table = new Client<Job>().Query(null, new Columns<Job>(x => x.ID, x => x.JobNumber, x => x.Name));
-            if (table.Rows.Any())
-                foreach (CoreRow row in table.Rows)
-                    _jobs.Add(row.ToObject<Job>());
+            _jobs ??= new Client<Job>().Query(null, new Columns<Job>(x => x.ID, x => x.JobNumber, x => x.Name))
+                .ToObjects<Job>().ToArray();
+            return _jobs;
         }
 
-        public void ScanFiles(OpenFileDialog dlg)
+        public void AddFiles(string[] fileNames)
         {
-            //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>();
+            var documents = new List<Document>();
+            var stagingdocs = new List<StagingSetoutDocument>();
 
-            foreach (var file in dlg.FileNames)
+            var cancel = new CancelEventArgs();
+            foreach (var file in fileNames)
             {
-                if (!Path.GetExtension(file).Equals(".pdf"))
-                    continue;
-
-                if (CheckStagingSetoutExists(Path.GetFileNameWithoutExtension(file)))
+                var document = ReadFile(file);
+                if (!CheckSetoutClash(document, cancel))
                 {
-                    //UpdateStagingDocument(file);
-                    continue;
+                    if (cancel.Cancel)
+                    {
+                        return;
+                    }
+                    else
+                    {
+                        continue;
+                    }
                 }
 
-                documents.Add(ReadFile(file));
+                documents.Add(document);
             }
 
             new Client<Document>().Save(documents, "Created from sync setout function");
 
-            var messages = new List<string>();
-            foreach (var doc in documents)
+            var stagingSetouts = documents.Select(x => new StagingSetout
             {
-                var stagingsetout = new StagingSetout();
-                stagingsetout.Number = Path.GetFileNameWithoutExtension(doc.FileName);
-                stagingsetout.JobLink.ID = TryFindJob(doc.FileName);
-                new Client<StagingSetout>().Save(stagingsetout, "Created from sync setout function");
+                Number = x.FileName
+            }).ToArray();
+
+            OnCustomiseSetouts?.Invoke(stagingSetouts);
+            new Client<StagingSetout>().Save(stagingSetouts, "Created from sync setout function");
 
+            for(int i = 0; i < documents.Count; ++i)
+            {
                 var stagingsetoutdoc = new StagingSetoutDocument();
-                stagingsetoutdoc.EntityLink.ID = stagingsetout.ID;
-                stagingsetoutdoc.DocumentLink.ID = doc.ID;
+                stagingsetoutdoc.EntityLink.ID = stagingSetouts[i].ID;
+                stagingsetoutdoc.DocumentLink.ID = documents[i].ID;
                 stagingdocs.Add(stagingsetoutdoc);
-
-                if (stagingsetout.JobLink.ID == Guid.Empty)
-                    messages.Add(doc.FileName);
             }
-
-            if (messages.Any())
-                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);
@@ -157,10 +159,11 @@ namespace PRSDesktop
 
         private void UpdateStagingDocument(string file)
         {
-            CoreTable table = new Client<StagingSetoutDocument>().Query(new Filter<StagingSetoutDocument>(x => x.DocumentLink.FileName).IsEqualTo(Path.GetFileName(file)));
+            var 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 stagingSetoutDoc = table.Rows.First().ToObject<StagingSetoutDocument>();
 
                 var doc = ReadFile(file);
                 new Client<Document>().Save(doc, "Created from Staging Setout Screen");
@@ -171,7 +174,7 @@ namespace PRSDesktop
 
         private Guid TryFindJob(string filePreFix)
         {
-            var job = _jobs.FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0, 4)) || x.JobNumber.Equals(filePreFix.Substring(0, 5)) || x.JobNumber.Equals(filePreFix.Substring(0, 6)));
+            var job = GetJobs().FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0, 4)) || x.JobNumber.Equals(filePreFix.Substring(0, 5)) || x.JobNumber.Equals(filePreFix.Substring(0, 6)));
             return job == null ? Guid.Empty : job.ID;
         }
 
@@ -185,6 +188,7 @@ namespace PRSDesktop
             Document doc = new Document();
             doc.FileName = Path.GetFileName(file);
             doc.Data = GetData(file);
+            doc.CRC = CoreUtils.CalculateCRC(doc.Data);
             return doc;
         }
 
@@ -207,15 +211,28 @@ namespace PRSDesktop
                 _existingFileNames.Add(row.Get<StagingSetout, string>(x => x.Number));
         }
 
-        private bool CheckStagingSetoutExists(string file)
+        private bool CheckSetoutClash(Document document, CancelEventArgs args)
         {
-            foreach (var existing in _existingFileNames)
+            foreach (var existing in _existingFiles)
             {
-                if (file.Equals(existing))
-                    return true;
+                if (document.FileName.Equals(existing.FileName))
+                {
+                    if(document.CRC != existing.CRC)
+                    {
+                        var result = MessageBox.Show($"A different file with the filename '{document.FileName}' already exists? Do you wish to replace the existing file with the new one?", "Replace Existing", MessageBoxButton.YesNoCancel);
+                        if(result == MessageBoxResult.No)
+                        {
+                            return false;
+                        }
+                        else if(result == MessageBoxResult.Cancel)
+                        {
+                            args.Cancel = true;
+                            return false;
+                        }
+                    }
+                }
             }
-
-            return false;
+            return true;
         }
 
         public void ReloadFile(StagingSetout stagingSetout)
@@ -230,7 +247,7 @@ namespace PRSDesktop
             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()
+                .Rows.First()
                 .ToObject<Document>();
 
             FileInfo file = new FileInfo(stagingSetout.SavePath);

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

@@ -4,11 +4,17 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:dynamicgrid="clr-namespace:InABox.DynamicGrid;assembly=InABox.Wpf"
-             xmlns:local="clr-namespace:PRSDesktop" xmlns:wpf="clr-namespace:InABox.Wpf;assembly=InABox.Wpf"
+             xmlns:local="clr-namespace:PRSDesktop"
+             xmlns:wpf="clr-namespace:InABox.Wpf;assembly=InABox.Wpf"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
 
     <dynamicgrid:DynamicSplitPanel x:Name="mainPanel" View="Combined" MasterCaption="Setouts Folder" AnchorWidth="500">
+        <dynamicgrid:DynamicSplitPanel.Header>
+            <Border BorderBrush="Gray" BorderThickness="0.75">
+                <Label Content="Setout Files" HorizontalContentAlignment="Center"/>
+            </Border>
+        </dynamicgrid:DynamicSplitPanel.Header>
 
         <dynamicgrid:DynamicSplitPanel.Master>
             <Grid x:Name="masterGrid">
@@ -33,7 +39,7 @@
                             <Border Grid.Row="0" BorderBrush="Gray" BorderThickness="0.5">
                                 <Label Content="Document Viewer" HorizontalAlignment="Center" FontWeight="DemiBold"/>
                             </Border>
-                            <wpf:DocumentApprovalControl x:Name="documentPreviewer" Width="1000" Grid.Row="1"/>
+                            <wpf:DocumentApprovalControl x:Name="documentPreviewer" Grid.Row="1"/>
                         </Grid>
                     </Border>
                 </dynamicgrid:DynamicSplitPanel.Master>
@@ -46,7 +52,6 @@
                                 <RowDefinition Height="*"/>
                             </Grid.RowDefinitions>
                             <Label Grid.Row="0" Content="Manufacturing Packets" FontWeight="DemiBold" HorizontalAlignment="Center" Visibility="Hidden"/>
-                            <local:ManufacturingPacketApprovalControl Grid.Row="1" x:Name="manufacturingControl" Visibility="Hidden"/>
                         </Grid>
                     </Border>
                 </dynamicgrid:DynamicSplitPanel.Detail>