Parcourir la source

DESKTOP - staging panel improvements

Nick-PRSDigital@bitbucket.org il y a 1 an
Parent
commit
b4beaab878

+ 3 - 1
prs.desktop/Panels/Staging/Setouts/StagingSetoutGrid.cs

@@ -166,7 +166,9 @@ namespace PRSDesktop
         {
             var job = _jobs.FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0,4)));
             if (job == null)  
-                job = _jobs.FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0, 5)));           
+                job = _jobs.FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0, 5)));
+            if (job == null)
+                job = _jobs.FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0, 6)));
             if (job == null)
                 return Guid.Empty;
 

+ 53 - 23
prs.desktop/Panels/Staging/StagingPanel.xaml.cs

@@ -38,6 +38,8 @@ namespace PRSDesktop
 
         StagingSetout _item = new StagingSetout();
 
+        List<StagingSetout> _items = new List<StagingSetout>();
+
         DynamicDataGrid<Document> _materialDocs;
         public StagingPanel()
         {
@@ -47,22 +49,49 @@ namespace PRSDesktop
 
         private void DocumentPreviewer_OnApproved(IEntityDocument stagingsetoutdocument)
         {
-            if (_item.Group.ID == Guid.Empty)
+            string message = "";
+
+            foreach (var item in _items)
+            {
+                var returnstring = ApproveSetout(item);
+                if (!string.IsNullOrWhiteSpace(returnstring))
+                    message = message + returnstring + Environment.NewLine;
+
+            }
+
+            foreach (var item in _items)
+                DeleteAndRefresh(item);
+
+            MessageBox.Show(message);
+        }
+
+        private string ApproveSetout(StagingSetout item)
+        {
+            if (item.Group.ID == Guid.Empty)
             {
                 var message = "Setout has no group assigned";
                 if (Security.IsAllowed<CanApproveSetoutsWithoutGroup>())
                 {
                     if (MessageBox.Show(message + ", continue?", "Continue?", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
-                        return;
+                        return "";
                 }
                 else
                 {
                     MessageBox.Show(message + ", please assign a group!");
-                    return;
+                    return "";
                 }
             }
 
-            var table = new Client<Setout>().Query(new Filter<Setout>(x => x.Number).IsEqualTo(_item.Number),
+            var setoutdoctable = new Client<StagingSetoutDocument>().Query(
+                new Filter<StagingSetoutDocument>(x => x.EntityLink.ID).IsEqualTo(item.ID),
+                new Columns<StagingSetoutDocument>(x => x.ID, x => x.DocumentLink.ID, x => x.DocumentLink.FileName));
+
+            if (!setoutdoctable.Rows.Any())
+                return "";
+
+            var stagingsetoutdocument = setoutdoctable.Rows.FirstOrDefault().ToObject<SetoutDocument>();
+
+            var table = new Client<Setout>().Query(new Filter<Setout>(x => x.Number).IsEqualTo(item.Number),
                 new Columns<Setout>(x => x.ID));
 
             var setout = new Setout();
@@ -70,13 +99,13 @@ namespace PRSDesktop
             if (table.Rows.Any())
             {
                 if (MessageBox.Show("Supercede existing documents?", "Proceed?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
-                    return;
+                    return "";
 
                 setout = table.Rows.FirstOrDefault().ToObject<Setout>();
 
-                setout.Group.ID = _item.Group.ID;
+                setout.Group.ID = item.Group.ID;
 
-                _item.Setout.ID = setout.ID;
+                item.Setout.ID = setout.ID;
 
                 var setoutdoc = new SetoutDocument();
                 setoutdoc.EntityLink.ID = setout.ID;
@@ -89,7 +118,7 @@ namespace PRSDesktop
 
                 CoreTable oldDocsTable = new Client<SetoutDocument>().Query(
                     new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setout.ID)
-                    .And(x => x.DocumentLink.ID).IsNotEqualTo(_item.Group.OptimizationDocument.ID)
+                    .And(x => x.DocumentLink.ID).IsNotEqualTo(item.Group.OptimizationDocument.ID)
                     );
                 foreach (var row in oldDocsTable.Rows)
                 {
@@ -103,39 +132,35 @@ namespace PRSDesktop
                 new Client<SetoutDocument>().Save(setoutdocs, "Updated from Staging Screen");
                 new Client<Setout>().Save(setout, "Updated from Staging Screen");
 
-                MessageBox.Show("Documents for setout " + _item.Number + " superceded.", "Success");
-
-                DeleteAndRefresh(stagingsetoutdocument);
+                return item.Number + " Superceded";
             }
 
             //no setout for this pdf - create new
             else
             {
-                setout.Number = _item.Number;
-                setout.JobLink.ID = _item.JobLink.ID;
-                setout.Group.ID = _item.Group.ID;
+                setout.Number = item.Number;
+                setout.JobLink.ID = item.JobLink.ID;
+                setout.Group.ID = item.Group.ID;
 
                 var editor = new DynamicDataGrid<Setout>();
                 editor.OnAfterSave += (editor, items) =>
                 {
-                    _item.Setout.ID = setout.ID;
+                    item.Setout.ID = setout.ID;
 
                     var setoutdoc = new SetoutDocument();
                     setoutdoc.EntityLink.ID = setout.ID;
                     setoutdoc.DocumentLink.ID = stagingsetoutdocument.DocumentLink.ID;
 
                     new Client<SetoutDocument>().Save(setoutdoc, "Added from staging screen");
-
-                    MessageBox.Show("Setout created for document " + _item.Number, "Success");
-
-                    DeleteAndRefresh(stagingsetoutdocument);
                 };
 
                 if (!editor.EditItems(new[] { setout }))
                 {
                     MessageBox.Show("Setout Creation Cancelled");
-                    return;
+                    return "";
                 }
+                else
+                    return item.Number + " Created";
             }
 
             //currently not creating packets due to temporary change in requirements - to uncomment and check for validity when required
@@ -254,9 +279,9 @@ namespace PRSDesktop
             return stages;
         }
 
-        private void DeleteAndRefresh(IEntityDocument stagingsetoutdocument)
+        private void DeleteAndRefresh(StagingSetout item)
         {
-            new Client<StagingSetout>().Save(_item, "Updated from staging screen");
+            new Client<StagingSetout>().Save(item, "Updated from staging screen");
             _item = new StagingSetout();
 
             documentPreviewer.Document = new StagingSetoutDocument();
@@ -302,6 +327,11 @@ namespace PRSDesktop
 
         private void StagingSetoutGrid_OnSelectItem(object sender, InABox.DynamicGrid.DynamicGridSelectionEventArgs e)
         {
+            _items.Clear();
+
+            foreach (var row in stagingSetoutGrid.SelectedRows)
+                _items.Add(row.ToObject<StagingSetout>());
+
             _item = stagingSetoutGrid.SelectedRows.FirstOrDefault().ToObject<StagingSetout>();
 
             var doc = new Client<StagingSetoutDocument>().Query(
@@ -377,7 +407,7 @@ namespace PRSDesktop
         public void Refresh()
         {
             //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
-            stagingSetoutGrid.Refresh(false, true);        
+            stagingSetoutGrid.Refresh(false, true);
 
             manufacturingControl.StagingSetout = new StagingSetout();
             manufacturingControl.Refresh();

+ 23 - 18
prs.stores/SetoutStore.cs

@@ -16,28 +16,33 @@ namespace Comal.Stores
         {
             if (entity.Group.ID != Guid.Empty)
             {
-                var table = Provider.Query<SetoutGroup>(new Filter<SetoutGroup>(x => x.ID).IsEqualTo(entity.Group.ID),
+                var table = Provider.Query<SetoutGroup>(new Filter<SetoutGroup>(x => x.ID).IsEqualTo(entity.Group.ID)
+                    .And(x => x.OptimizationDocument.ID).IsNotEqualTo(Guid.Empty),
                     new Columns<SetoutGroup>(x => x.OptimizationDocument.ID));
-                if (table.Rows.Any())
-                {
-                    var docID = table.Rows.FirstOrDefault().Get<SetoutGroup, Guid>(x => x.OptimizationDocument.ID);
-                    List<Guid> ids = new List<Guid>();
-                    var docsTable = Provider.Query<SetoutDocument>(
-                        new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(entity.ID),
-                        new Columns<SetoutDocument>(x => x.DocumentLink.ID)
-                        );
-                    foreach (var row in docsTable.Rows)
-                        ids.Add(row.Get<SetoutDocument, Guid>(x => x.DocumentLink.ID));
+                if (!table.Rows.Any())
+                    return;
+
+                var docID = table.Rows.FirstOrDefault().Get<SetoutGroup, Guid>(x => x.OptimizationDocument.ID);
+                if (docID == Guid.Empty)
+                    return;
 
-                    if (!ids.Contains(docID))
-                    {
-                        var setoutdoc = new SetoutDocument();
-                        setoutdoc.EntityLink.ID = entity.ID;
-                        setoutdoc.DocumentLink.ID = docID;
+                List<Guid> ids = new List<Guid>();
+                var docsTable = Provider.Query<SetoutDocument>(
+                    new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(entity.ID),
+                    new Columns<SetoutDocument>(x => x.DocumentLink.ID)
+                    );
+                foreach (var row in docsTable.Rows)
+                    ids.Add(row.Get<SetoutDocument, Guid>(x => x.DocumentLink.ID));
 
-                        FindSubStore<SetoutDocument>().Save(setoutdoc, "Added optimsation document from Group");
-                    }
+                if (!ids.Contains(docID))
+                {
+                    var setoutdoc = new SetoutDocument();
+                    setoutdoc.EntityLink.ID = entity.ID;
+                    setoutdoc.DocumentLink.ID = docID;
+
+                    FindSubStore<SetoutDocument>().Save(setoutdoc, "Added optimsation document from Group");
                 }
+
             }
             base.AfterSave(entity);
         }