Browse Source

DESKTOP - added PDF viewer in additional window from Factory Panel, improvements to staging setout screen

Nick-PRSDigital@bitbucket.org 1 year ago
parent
commit
86e5583714

+ 3 - 3
prs.desktop/Panels/Factory/FactoryPanel.xaml

@@ -366,9 +366,9 @@
                     Margin="5,5,0,0" Click="UpdateButtonClick" IsEnabled="False" />
             <Button Grid.Column="6" x:Name="BarcodesButton" Tag="100" Grid.Row="0" Content="Print Barcodes" Width="100"
                     Margin="0,5,0,0" Click="BarcodesButton_Click" IsEnabled="False" />
-            <!--<Button Grid.Column="8" x:Name="OrderButton" Tag="100" Grid.Row="0" Width="100" Margin="0,5,0,0" Click="OrderButton_Click"  IsEnabled="False">
-                <TextBlock TextWrapping="Wrap" Text="Send For Treatment" VerticalAlignment="Center" />
-            </Button>-->
+            <Button Grid.Column="8" x:Name="TearOffButton" Tag="100" Grid.Row="0" Width="120" Margin="0,5,0,0" Click="TearOffButton_Click"  IsEnabled="False">
+                <TextBlock TextWrapping="Wrap" Text="Open In New Window" VerticalAlignment="Center" TextAlignment="Center"/>
+            </Button>
             <Button Grid.Column="10" x:Name="CompleteButton" Grid.Row="0" Content="Finish" Width="100" Margin="0,5,0,0"
                     Click="CompleteButton_Click" IsEnabled="False" />
         </Grid>

+ 30 - 11
prs.desktop/Panels/Factory/FactoryPanel.xaml.cs

@@ -27,6 +27,7 @@ using org.apache.commons.io.comparator;
 using BarcodeType = Comal.Classes.BarcodeType;
 using Color = System.Drawing.Color;
 using Image = System.Windows.Controls.Image;
+using InABox.Wpf;
 
 namespace PRSDesktop
 {
@@ -1133,19 +1134,23 @@ namespace PRSDesktop
                     var qadata = stage.Get<ManufacturingPacketStage, string>(c => c.FormData);
                     var questions = LoadQAQuestions(packet, true, true);
 
-                    var answers = string.IsNullOrWhiteSpace(qadata)
-                        ? new Dictionary<Guid, object>()
-                        : Serialization.Deserialize<Dictionary<Guid, object>>(qadata);
-
-                    foreach (var question in questions)
+                    if (questions != null)
                     {
-                        var parameters = question.ParseParameters();
-                        var bAnswerRequired = question.Answer != QAAnswer.Comment &&
-                                              (!parameters.ContainsKey("Default") || string.IsNullOrWhiteSpace(parameters["Default"]));
-                        if (bAnswerRequired && (!answers.ContainsKey(question.ID) || answers[question.ID] == null))
+
+                        var answers = string.IsNullOrWhiteSpace(qadata)
+                            ? new Dictionary<Guid, object>()
+                            : Serialization.Deserialize<Dictionary<Guid, object>>(qadata);
+
+                        foreach (var question in questions)
                         {
-                            qacomplete = false;
-                            break;
+                            var parameters = question.ParseParameters();
+                            var bAnswerRequired = question.Answer != QAAnswer.Comment &&
+                                                  (!parameters.ContainsKey("Default") || string.IsNullOrWhiteSpace(parameters["Default"]));
+                            if (bAnswerRequired && (!answers.ContainsKey(question.ID) || answers[question.ID] == null))
+                            {
+                                qacomplete = false;
+                                break;
+                            }
                         }
                     }
                 }
@@ -1296,6 +1301,17 @@ namespace PRSDesktop
             Progress.Close();
         }
 
+        private void TearOffButton_Click(object sender, RoutedEventArgs e)
+        {
+            var doc = PDFEditor.Document;
+            var window = new ThemableWindow();
+            var editor = new PDFEditorControl();
+            editor.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
+            editor.Document = doc;
+            window.Content = editor;
+            window.Show();
+        }
+
         private void BarcodesButton_Click(object sender, RoutedEventArgs e)
         {
             //List<ManufacturingPacket> updates = new List<ManufacturingPacket>();
@@ -2444,6 +2460,9 @@ namespace PRSDesktop
                 r.Get<ManufacturingTemplateStage, Guid>(c => c.Template.ID).Equals(packet.ManufacturingTemplateLink.ID) &&
                 r.Get<ManufacturingTemplateStage, Guid>(c => c.Section.ID).Equals(CurrentSection.ID));
 
+            if (tstage == null)
+                return null;
+
             IEnumerable<CoreRow> rows = null;
             if (section && !template)
                 rows = Questions.Rows.Where(r => r.Get<QAQuestion, Guid>(c => c.QAForm.ID).Equals(CurrentSection.QAForm.ID));

+ 2 - 10
prs.desktop/Panels/Staging/Setouts/StagingSetoutGrid.cs

@@ -164,16 +164,8 @@ namespace PRSDesktop
 
         private Guid TryFindJob(string filePreFix)
         {
-            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)));
-            if (job == null)
-                job = _jobs.FirstOrDefault(x => x.JobNumber.Equals(filePreFix.Substring(0, 6)));
-            if (job == null)
-                return Guid.Empty;
-
-            else
-                return job.ID;
+            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)));
+            return job == null ? Guid.Empty : job.ID;
         }
 
         /// <summary>

+ 48 - 17
prs.desktop/Panels/Staging/StagingPanel.xaml.cs

@@ -10,6 +10,7 @@ using InABox.Configuration;
 using InABox.DynamicGrid;
 using System.Diagnostics;
 using System.IO;
+using InABox.WPF;
 
 namespace PRSDesktop
 {
@@ -49,23 +50,37 @@ namespace PRSDesktop
 
         private void DocumentPreviewer_OnApproved(IEntityDocument stagingsetoutdocument)
         {
-            string message = "";
+            bool bulkApprove = false;
+            if (_items.Count > 1)
+            {
+                if (MessageBox.Show("Bulk approve? (Skip individual setout approval)", "Continue?", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
+                {
+                    bulkApprove = true;
+                    Progress.Show("Approving Setouts..");
+                }                  
+            }
+            
+            string message = "Result: " + Environment.NewLine;
 
             foreach (var item in _items)
             {
-                var returnstring = ApproveSetout(item);
+                if (bulkApprove)
+                    Progress.Show("Working on " + item.Number);
+                var returnstring = ApproveSetout(item, bulkApprove);
                 if (!string.IsNullOrWhiteSpace(returnstring))
                     message = message + returnstring + Environment.NewLine;
-
             }
 
+            if(bulkApprove)
+                Progress.Close();
+
             foreach (var item in _items)
                 DeleteAndRefresh(item);
 
             MessageBox.Show(message);
         }
 
-        private string ApproveSetout(StagingSetout item)
+        private string ApproveSetout(StagingSetout item, bool bulkapprove)
         {
             if (item.Group.ID == Guid.Empty)
             {
@@ -89,7 +104,7 @@ namespace PRSDesktop
             if (!setoutdoctable.Rows.Any())
                 return "";
 
-            var stagingsetoutdocument = setoutdoctable.Rows.FirstOrDefault().ToObject<SetoutDocument>();
+            var stagingsetoutdocument = setoutdoctable.Rows.FirstOrDefault().ToObject<StagingSetoutDocument>();
 
             var table = new Client<Setout>().Query(new Filter<Setout>(x => x.Number).IsEqualTo(item.Number),
                 new Columns<Setout>(x => x.ID));
@@ -98,8 +113,9 @@ namespace PRSDesktop
             //setout already exists - create new setoutdoc and supercede old ones
             if (table.Rows.Any())
             {
-                if (MessageBox.Show("Supercede existing documents?", "Proceed?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
-                    return "";
+                if (!bulkapprove)
+                    if (MessageBox.Show("Supercede existing documents?", "Proceed?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
+                        return "";
 
                 setout = table.Rows.FirstOrDefault().ToObject<Setout>();
 
@@ -145,28 +161,42 @@ namespace PRSDesktop
                 var editor = new DynamicDataGrid<Setout>();
                 editor.OnAfterSave += (editor, items) =>
                 {
-                    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");
+                    CreateSetoutDocument(setout, item, stagingsetoutdocument);
                 };
 
-                if (!editor.EditItems(new[] { setout }))
+                if (!bulkapprove)
                 {
-                    MessageBox.Show("Setout Creation Cancelled");
-                    return "";
+                    if (!editor.EditItems(new[] { setout }))
+                    {
+                        MessageBox.Show("Setout Creation Cancelled");
+                        return "";
+                    }
+                    else
+                        return item.Number + " Created";
                 }
                 else
+                {
+                    new Client<Setout>().Save(setout, "Added from staging screen");
+                    CreateSetoutDocument(setout, item, stagingsetoutdocument);
                     return item.Number + " Created";
+                }
             }
 
             //currently not creating packets due to temporary change in requirements - to uncomment and check for validity when required
             //CreatePackets(setout);
         }
 
+        private void CreateSetoutDocument(Setout setout, StagingSetout item, StagingSetoutDocument stagingsetoutdocument)
+        {
+            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");
+        }
+
         private void CreatePackets(Setout setout)
         {
             List<ManufacturingPacket> packets = new List<ManufacturingPacket>();
@@ -408,6 +438,7 @@ namespace PRSDesktop
         {
             //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
             stagingSetoutGrid.Refresh(false, true);
+            documentPreviewer.Document = new StagingSetoutDocument();
 
             manufacturingControl.StagingSetout = new StagingSetout();
             manufacturingControl.Refresh();