Browse Source

PRS DESKTOP - fix to job doc milestone files not updating thumbnail when replacing file

Nick-PRSDigital@bitbucket.org 2 years ago
parent
commit
ce7b978441
1 changed files with 22 additions and 9 deletions
  1. 22 9
      prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetTree.xaml.cs

+ 22 - 9
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetTree.xaml.cs

@@ -1,7 +1,5 @@
 using System;
 using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
@@ -11,21 +9,17 @@ using System.Windows.Documents;
 using System.Windows.Forms;
 using System.Windows.Input;
 using System.Windows.Media;
-using com.sun.tools.javac.file;
 using Comal.Classes;
 using InABox.Clients;
 using InABox.Configuration;
 using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.WPF;
-using net.sf.mpxj.phoenix.schema.phoenix5;
-using org.omg.CORBA;
 using Syncfusion.Compression.Zip;
 using Syncfusion.Data.Extensions;
 using Syncfusion.UI.Xaml.Grid;
 using Syncfusion.UI.Xaml.TreeGrid;
 using Syncfusion.UI.Xaml.TreeGrid.Helpers;
-using Syncfusion.Windows.Controls.Grid;
 using Syncfusion.XlsIO;
 using Color = System.Drawing.Color;
 using Environment = System.Environment;
@@ -1008,11 +1002,17 @@ namespace PRSDesktop
                 }
 
                 var milestoneids = rows.Select(r => r.Get<JobDocumentSetMileStone, Guid>(c => c.ID)).ToArray();
-                var currentfiles = new Client<JobDocumentSetMileStoneFile>().Query(
+                var table = new Client<JobDocumentSetMileStoneFile>().Query(
                     new Filter<JobDocumentSetMileStoneFile>(x => x.EntityLink.ID).InList(milestoneids),
-                    new Columns<JobDocumentSetMileStoneFile>(x => x.DocumentLink.ID)
+                    new Columns<JobDocumentSetMileStoneFile>(x => x.ID, x => x.DocumentLink.ID)
                         .Add(x => x.DocumentLink.FileName)
-                ).ToDictionary<JobDocumentSetMileStoneFile, String, Guid>(x => x.DocumentLink.FileName, x => x.DocumentLink.ID);
+                );
+                List<JobDocumentSetMileStoneFile> jobdocsetfiles = new List<JobDocumentSetMileStoneFile>();
+                foreach (var row in table.Rows)
+                { 
+                    jobdocsetfiles.Add(row.ToObject<JobDocumentSetMileStoneFile>());
+                }
+                var currentfiles = table.ToDictionary<JobDocumentSetMileStoneFile, String, Guid>(x => x.DocumentLink.FileName, x => x.DocumentLink.ID);
                 var matched = filenames.Where(filename => currentfiles.Keys.Any(key => Path.GetFileName(filename).ToLower().StartsWith(key.ToLower())));
                 bool replace = false;
                 if (matched.Any())
@@ -1030,6 +1030,7 @@ namespace PRSDesktop
                 Progress.ShowModal("Uploading Files", (progress) =>
                 {
                     List<Document> documents = new List<Document>();
+                    List<JobDocumentSetMileStoneFile> linked = new List<JobDocumentSetMileStoneFile>();
                     foreach (var file in filenames)
                     {
                         if (!matched.Contains(file) || replace)
@@ -1044,11 +1045,23 @@ namespace PRSDesktop
                             doc.CRC = CoreUtils.CalculateCRC(doc.Data);
                             doc.TimeStamp = new FileInfo(file).LastWriteTime;
                             documents.Add(doc);
+
+                            if (doc.ID != Guid.Empty)
+                            {
+                                var linkedfile = jobdocsetfiles.FirstOrDefault(x => x.DocumentLink.ID == doc.ID);
+                                linkedfile.DocumentLink.ID = Guid.Empty;
+                                linkedfile.CommitChanges();
+                                linkedfile.DocumentLink.ID = doc.ID;
+                                linked.Add(linkedfile);
+                            }                           
                         }
                     }
                     if (documents.Any())
                         new Client<Document>().Save(documents.ToArray(), "Uploaded by User");
 
+                    if (linked.Any())
+                        new Client<JobDocumentSetMileStoneFile>().Save(linked, "Uploaded by User");
+
                     progress.Report("Updating Links");
                     List<JobDocumentSetMileStoneFile> links = new List<JobDocumentSetMileStoneFile>();
                     foreach (var document in documents)