|
@@ -15,7 +15,6 @@ using System.ComponentModel;
|
|
|
using InABox.Scripting;
|
|
|
using System.Reflection;
|
|
|
using System.Collections.Immutable;
|
|
|
-using com.sun.istack.@internal.localization;
|
|
|
|
|
|
namespace PRSDesktop
|
|
|
{
|
|
@@ -83,6 +82,8 @@ public class Module
|
|
|
/// </summary>
|
|
|
private List<StagingSetout> selectedSetouts = new();
|
|
|
|
|
|
+ #region Script Stuff
|
|
|
+
|
|
|
private MethodInfo? _customiseSetoutsMethod;
|
|
|
private MethodInfo? CustomiseSetoutsMethod
|
|
|
{
|
|
@@ -124,13 +125,115 @@ public class Module
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ #endregion
|
|
|
+
|
|
|
public StagingPanel()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
SectionName = nameof(StagingPanel);
|
|
|
}
|
|
|
|
|
|
- private void DocumentPreviewer_OnApproved(IEntityDocument? stagingsetoutdocument)
|
|
|
+ public void Setup()
|
|
|
+ {
|
|
|
+ _settings = new GlobalConfiguration<StagingPanellSettings>().Load();
|
|
|
+
|
|
|
+ MarkUpButton.Visibility = Security.IsAllowed<CanMarkUpSetouts>() ? Visibility.Visible : Visibility.Hidden;
|
|
|
+ RejectButton.Visibility = Security.IsAllowed<CanApproveSetouts>() ? Visibility.Visible : Visibility.Hidden;
|
|
|
+ ApproveButton.Visibility = Security.IsAllowed<CanApproveSetouts>() ? Visibility.Visible : Visibility.Hidden;
|
|
|
+
|
|
|
+ //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
|
|
|
+ stagingSetoutGrid.Refresh(true, true);
|
|
|
+ stagingSetoutGrid.OnSelectItem += StagingSetoutGrid_OnSelectItem;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void NestedPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
|
|
|
+ {
|
|
|
+ if(e.View != DynamicSplitPanelView.Master && ManufacturingPacketList.Setout != selectedSetout)
|
|
|
+ {
|
|
|
+ ManufacturingPacketList.Setout = selectedSetout;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #region Document Viewer
|
|
|
+
|
|
|
+ public enum DocumentMode
|
|
|
+ {
|
|
|
+ Markup,
|
|
|
+ Complete,
|
|
|
+ Locked
|
|
|
+ }
|
|
|
+ private DocumentMode _mode;
|
|
|
+ private DocumentMode Mode
|
|
|
+ {
|
|
|
+ get => _mode;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ _mode = value;
|
|
|
+ if (_mode == DocumentMode.Markup)
|
|
|
+ {
|
|
|
+ MarkUpButton.Content = "Mark Up";
|
|
|
+ MarkUpButton.IsEnabled = Document != null;
|
|
|
+ ApproveButton.IsEnabled = Document != null;
|
|
|
+ RejectButton.IsEnabled = Document != null;
|
|
|
+ }
|
|
|
+ else if (_mode == DocumentMode.Complete)
|
|
|
+ {
|
|
|
+ MarkUpButton.Content = "Complete";
|
|
|
+ MarkUpButton.IsEnabled = Document != null;
|
|
|
+ ApproveButton.IsEnabled = false;
|
|
|
+ RejectButton.IsEnabled = false;
|
|
|
+ }
|
|
|
+ else if (_mode == DocumentMode.Locked)
|
|
|
+ {
|
|
|
+ MarkUpButton.Content = "Locked";
|
|
|
+ MarkUpButton.IsEnabled = false;
|
|
|
+ ApproveButton.IsEnabled = false;
|
|
|
+ RejectButton.IsEnabled = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private StagingSetoutDocument? _document;
|
|
|
+ private StagingSetoutDocument? Document
|
|
|
+ {
|
|
|
+ get => _document;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ if(_document != value)
|
|
|
+ {
|
|
|
+ _document = value;
|
|
|
+ RenderDocument(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RenderDocument(StagingSetoutDocument? document)
|
|
|
+ {
|
|
|
+ DocumentViewer.Children.Clear();
|
|
|
+ if (document is null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var table = new Client<Document>().Query(
|
|
|
+ new Filter<Document>(x => x.ID).IsEqualTo(document.DocumentLink.ID),
|
|
|
+ new Columns<Document>(x => x.Data));
|
|
|
+ var first = table.Rows.FirstOrDefault();
|
|
|
+ if (first is null)
|
|
|
+ return;
|
|
|
+ var data = first.Get<Document, byte[]>(x => x.Data);
|
|
|
+ var images = ImageUtils.RenderPDFToImages(data);
|
|
|
+ foreach (var image in images)
|
|
|
+ {
|
|
|
+ DocumentViewer.Children.Add(new Image
|
|
|
+ {
|
|
|
+ Source = ImageUtils.LoadImage(image),
|
|
|
+ Margin = new Thickness(0, 0, 0, 20)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ApproveButton_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
bool bulkApprove = false;
|
|
|
if (selectedSetouts.Count > 1)
|
|
@@ -139,9 +242,9 @@ public class Module
|
|
|
{
|
|
|
bulkApprove = true;
|
|
|
Progress.Show("Approving Setouts..");
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
string message = "Result: " + Environment.NewLine;
|
|
|
|
|
|
foreach (var item in selectedSetouts)
|
|
@@ -153,7 +256,7 @@ public class Module
|
|
|
message = message + returnstring + Environment.NewLine;
|
|
|
}
|
|
|
|
|
|
- if(bulkApprove)
|
|
|
+ if (bulkApprove)
|
|
|
Progress.Close();
|
|
|
|
|
|
new Client<StagingSetout>().Save(selectedSetouts, "Updated from staging screen");
|
|
@@ -163,7 +266,7 @@ public class Module
|
|
|
MessageBox.Show(message);
|
|
|
}
|
|
|
|
|
|
- private static string ApproveSetout(StagingSetout item, bool bulkapprove)
|
|
|
+ private string ApproveSetout(StagingSetout item, bool bulkapprove)
|
|
|
{
|
|
|
if (item.Group.ID == Guid.Empty)
|
|
|
{
|
|
@@ -195,6 +298,7 @@ public class Module
|
|
|
new Columns<Setout>(x => x.ID))
|
|
|
.ToObjects<Setout>().FirstOrDefault();
|
|
|
|
|
|
+ string result;
|
|
|
//setout already exists - create new setoutdoc and supercede old ones
|
|
|
if (setout is not null)
|
|
|
{
|
|
@@ -231,7 +335,7 @@ public class Module
|
|
|
new Client<SetoutDocument>().Save(setoutdocs, "Updated from Staging Screen");
|
|
|
new Client<Setout>().Save((Setout)setout, "Updated from Staging Screen");
|
|
|
|
|
|
- return item.Number + " Superceded";
|
|
|
+ result = item.Number + " Superceded";
|
|
|
}
|
|
|
//no setout for this pdf - create new
|
|
|
else
|
|
@@ -257,18 +361,65 @@ public class Module
|
|
|
return "";
|
|
|
}
|
|
|
else
|
|
|
- return item.Number + " Created";
|
|
|
+ result = item.Number + " Created";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
new Client<Setout>().Save(setout, "Added from staging screen");
|
|
|
CreateSetoutDocument(setout, item, setoutDocument);
|
|
|
- return item.Number + " Created";
|
|
|
+ result = item.Number + " Created";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var packets = new List<Tuple<ManufacturingPacket, StagingManufacturingPacket>>();
|
|
|
+ foreach(var stagingPacket in ManufacturingPacketList.GetPackets())
|
|
|
+ {
|
|
|
+ if(stagingPacket.ManufacturingPacket.ID != Guid.Empty)
|
|
|
+ {
|
|
|
+ MessageBox.Show($"A manufacturing packet already exists for {stagingPacket.Serial}; skipping packet.");
|
|
|
+ continue;
|
|
|
}
|
|
|
+
|
|
|
+ var packet = new ManufacturingPacket
|
|
|
+ {
|
|
|
+ Serial = stagingPacket.Serial,
|
|
|
+ Title = stagingPacket.Title,
|
|
|
+ Quantity = stagingPacket.Quantity,
|
|
|
+ BarcodeQty = stagingPacket.BarcodeQuantity != 0 ? stagingPacket.BarcodeQuantity : stagingPacket.Quantity,
|
|
|
+ WaterMark = stagingPacket.Watermark.ToString(),
|
|
|
+ Location = stagingPacket.Location
|
|
|
+ };
|
|
|
+ packet.SetoutLink.ID = setout.ID;
|
|
|
+ packet.ITP.ID = stagingPacket.ITP.ID;
|
|
|
+ packet.JobLink.ID = stagingPacket.Job.ID;
|
|
|
+ packet.ManufacturingTemplateLink.ID = stagingPacket.Template.ID;
|
|
|
+
|
|
|
+ packets.Add(new(packet, stagingPacket));
|
|
|
}
|
|
|
+ new Client<ManufacturingPacket>().Save(packets.Select(x => x.Item1), "Created from Design Management Panel");
|
|
|
+
|
|
|
+ var newStages = new List<ManufacturingPacketStage>();
|
|
|
+ foreach(var (packet, stagingPacket) in packets)
|
|
|
+ {
|
|
|
+ stagingPacket.ManufacturingPacket.ID = packet.ID;
|
|
|
+ var stages = new Client<StagingManufacturingPacketStage>()
|
|
|
+ .Query(
|
|
|
+ new Filter<StagingManufacturingPacketStage>(x => x.Packet.ID).IsEqualTo(stagingPacket.ID),
|
|
|
+ IManufacturingPacketGeneratorExtensions.GetPacketGeneratorRequiredColumns<StagingManufacturingPacketStage>());
|
|
|
+ newStages.AddRange(stages.ToObjects<StagingManufacturingPacketStage>()
|
|
|
+ .Select(x =>
|
|
|
+ {
|
|
|
+ var stage = x.CreateManufacturingPacketStage();
|
|
|
+ stage.Parent.ID = packet.ID;
|
|
|
+ return stage;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ new Client<ManufacturingPacketStage>().Save(newStages, "Created from Design Management");
|
|
|
+ new Client<StagingManufacturingPacket>().Save(packets.Select(x => x.Item2), "Created from Design Management");
|
|
|
|
|
|
//currently not creating packets due to temporary change in requirements - to uncomment and check for validity when required
|
|
|
//CreatePackets(setout);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
private static void CreateSetoutDocument(Setout setout, StagingSetout item, StagingSetoutDocument stagingsetoutdocument)
|
|
@@ -282,9 +433,9 @@ public class Module
|
|
|
new Client<SetoutDocument>().Save(setoutdoc, "Added from staging screen");
|
|
|
}
|
|
|
|
|
|
- private void DocumentPreviewer_OnRejected(IEntityDocument? stagingsetoutdocument)
|
|
|
+ private void RejectButton_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if(selectedSetout is null || stagingsetoutdocument is null)
|
|
|
+ if (selectedSetout is null || Document is null)
|
|
|
{
|
|
|
MessageBox.Show("Please select a setout");
|
|
|
return;
|
|
@@ -307,7 +458,7 @@ public class Module
|
|
|
{
|
|
|
var doc = new KanbanDocument();
|
|
|
doc.EntityLink.ID = task.ID;
|
|
|
- doc.DocumentLink.ID = stagingsetoutdocument.DocumentLink.ID;
|
|
|
+ doc.DocumentLink.ID = Document.DocumentLink.ID;
|
|
|
new Client<KanbanDocument>().Save(doc, "Created from staging screen");
|
|
|
|
|
|
selectedSetout.Task.ID = task.ID;
|
|
@@ -316,7 +467,7 @@ public class Module
|
|
|
MessageBox.Show("Success - Task Created for Document " + selectedSetout.Number + " (Task no. " + task.Number + " assigned to " + task.EmployeeLink.Name + ")");
|
|
|
selectedSetout = null;
|
|
|
|
|
|
- documentPreviewer.Document = null;
|
|
|
+ Document = null;
|
|
|
stagingSetoutGrid.Refresh(false, true);
|
|
|
}
|
|
|
else
|
|
@@ -325,14 +476,71 @@ public class Module
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void nestedPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
|
|
|
+ private void MarkUpButton_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if(e.View != DynamicSplitPanelView.Master && ManufacturingPacketList.Setout != selectedSetout)
|
|
|
+ if (Mode == DocumentMode.Markup)
|
|
|
{
|
|
|
- ManufacturingPacketList.Setout = selectedSetout;
|
|
|
+ Mode = DocumentMode.Complete;
|
|
|
+ MessageBox.Show("IMPORTANT - press save in your document editor, then press the Complete Button in PRS");
|
|
|
+ OnMarkupSelected();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ OnMarkupComplete();
|
|
|
+ Mode = DocumentMode.Markup;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnMarkupSelected()
|
|
|
+ {
|
|
|
+ if (Document is null || selectedSetout is null)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Please select a setout first.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var doc = new Client<Document>()
|
|
|
+ .Query(
|
|
|
+ new Filter<Document>(x => x.ID).IsEqualTo(Document.DocumentLink.ID))
|
|
|
+ .ToObjects<Document>().FirstOrDefault();
|
|
|
+ if (doc is null)
|
|
|
+ {
|
|
|
+ Logger.Send(LogType.Error, "", $"Document with ID {Document.DocumentLink.ID} could not be found.");
|
|
|
+ MessageBox.Show("Error: the selected document could not be found in the database.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var tempdocpath = Path.Combine(Path.GetTempPath(), doc.FileName);
|
|
|
+ selectedSetout.SavePath = tempdocpath;
|
|
|
+ selectedSetout.Locked = DateTime.Now;
|
|
|
+ selectedSetout.LockedBy.ID = App.EmployeeID;
|
|
|
+ new Client<StagingSetout>().Save(selectedSetout, "Locked from Staging Screen");
|
|
|
+ File.WriteAllBytes(tempdocpath, doc.Data);
|
|
|
+ using (var p = new Process())
|
|
|
+ {
|
|
|
+ p.StartInfo = new ProcessStartInfo()
|
|
|
+ {
|
|
|
+ UseShellExecute = true,
|
|
|
+ FileName = tempdocpath
|
|
|
+ };
|
|
|
+
|
|
|
+ p.Start();
|
|
|
+ }
|
|
|
+ stagingSetoutGrid.Refresh(false, true);
|
|
|
+ }
|
|
|
+ private void OnMarkupComplete()
|
|
|
+ {
|
|
|
+ if (selectedSetout is null)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Please select a setout first.");
|
|
|
+ return;
|
|
|
}
|
|
|
+ StagingSetoutGrid.ReloadFile(selectedSetout);
|
|
|
+ stagingSetoutGrid.Refresh(false, true);
|
|
|
}
|
|
|
|
|
|
+ #endregion
|
|
|
+
|
|
|
private void StagingSetoutGrid_OnSelectItem(object sender, InABox.DynamicGrid.DynamicGridSelectionEventArgs e)
|
|
|
{
|
|
|
selectedSetouts.Clear();
|
|
@@ -344,7 +552,7 @@ public class Module
|
|
|
AddPacketButton.IsEnabled = selectedSetout is not null;
|
|
|
if(selectedSetout is null)
|
|
|
{
|
|
|
- documentPreviewer.Document = null;
|
|
|
+ Document = null;
|
|
|
ManufacturingPacketList.Setout = null;
|
|
|
CollapsePacketsButton.IsEnabled = false;
|
|
|
return;
|
|
@@ -358,22 +566,22 @@ public class Module
|
|
|
if(doc is null)
|
|
|
{
|
|
|
MessageBox.Show("No document found for this setout.");
|
|
|
- documentPreviewer.Document = null;
|
|
|
+ Document = null;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- documentPreviewer.Document = doc;
|
|
|
- if(mainPanel.View != DynamicSplitPanelView.Master && nestedPanel.View != DynamicSplitPanelView.Master)
|
|
|
+ Document = doc;
|
|
|
+ if(MainPanel.View != DynamicSplitPanelView.Master && NestedPanel.View != DynamicSplitPanelView.Master)
|
|
|
{
|
|
|
ManufacturingPacketList.Setout = selectedSetout;
|
|
|
}
|
|
|
CollapsePacketsButton.IsEnabled = true;
|
|
|
- //manufacturingControl.StagingSetout = _item;
|
|
|
- documentPreviewer.Mode =
|
|
|
- selectedSetout.Locked == DateTime.MinValue ? InABox.Wpf.DocumentApprovalControl.ControlMode.Markup :
|
|
|
- selectedSetout.Locked != DateTime.MinValue && selectedSetout.LockedBy.ID == App.EmployeeID ? InABox.Wpf.DocumentApprovalControl.ControlMode.Complete :
|
|
|
- selectedSetout.Locked != DateTime.MinValue && selectedSetout.LockedBy.ID != App.EmployeeID ? InABox.Wpf.DocumentApprovalControl.ControlMode.Locked :
|
|
|
- InABox.Wpf.DocumentApprovalControl.ControlMode.Markup;
|
|
|
+ Mode =
|
|
|
+ selectedSetout.Locked == DateTime.MinValue ?
|
|
|
+ DocumentMode.Markup :
|
|
|
+ selectedSetout.LockedBy.ID == App.EmployeeID ?
|
|
|
+ DocumentMode.Complete :
|
|
|
+ DocumentMode.Locked;
|
|
|
}
|
|
|
|
|
|
public bool IsReady { get; set; }
|
|
@@ -383,6 +591,8 @@ public class Module
|
|
|
|
|
|
public event DataModelUpdateEvent? OnUpdateDataModel;
|
|
|
|
|
|
+ #region Settings
|
|
|
+
|
|
|
public void CreateToolbarButtons(IPanelHost host)
|
|
|
{
|
|
|
host.CreateSetupAction(new PanelAction() { Caption = "Setouts Configuration", Image = PRSDesktop.Resources.specifications, OnExecute = ConfigSettingsClick });
|
|
@@ -437,6 +647,8 @@ public class Module
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ #endregion
|
|
|
+
|
|
|
public void Heartbeat(TimeSpan time)
|
|
|
{
|
|
|
|
|
@@ -446,11 +658,9 @@ public class Module
|
|
|
{
|
|
|
//stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
|
|
|
stagingSetoutGrid.Refresh(false, true);
|
|
|
- documentPreviewer.Document = null;
|
|
|
+ Document = null;
|
|
|
|
|
|
ManufacturingPacketList.Setout = null;
|
|
|
- //manufacturingControl.StagingSetout = new StagingSetout();
|
|
|
- //manufacturingControl.Refresh();
|
|
|
}
|
|
|
|
|
|
public Dictionary<string, object[]> Selected()
|
|
@@ -458,73 +668,6 @@ public class Module
|
|
|
return new();
|
|
|
}
|
|
|
|
|
|
- public void Setup()
|
|
|
- {
|
|
|
- _settings = new GlobalConfiguration<StagingPanellSettings>().Load();
|
|
|
-
|
|
|
- documentPreviewer.SetupButtons(
|
|
|
- markupVisible: Security.IsAllowed<CanMarkUpSetouts>(),
|
|
|
- rejectVisible: Security.IsAllowed<CanApproveSetouts>(),
|
|
|
- approveVisible: Security.IsAllowed<CanApproveSetouts>()
|
|
|
- );
|
|
|
- documentPreviewer.OnMarkupSelected += DocumentPreviewer_OnMarkupSelected;
|
|
|
- documentPreviewer.OnMarkupComplete += DocumentPreviewer_OnMarkupComplete;
|
|
|
- documentPreviewer.OnRejected += DocumentPreviewer_OnRejected;
|
|
|
- documentPreviewer.OnApproved += DocumentPreviewer_OnApproved;
|
|
|
-
|
|
|
- //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
|
|
|
- stagingSetoutGrid.Refresh(true, true);
|
|
|
- stagingSetoutGrid.OnSelectItem += StagingSetoutGrid_OnSelectItem;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void DocumentPreviewer_OnMarkupSelected(IEntityDocument? document)
|
|
|
- {
|
|
|
- if(document is null || selectedSetout is null)
|
|
|
- {
|
|
|
- MessageBox.Show("Please select a setout first.");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- var doc = new Client<Document>()
|
|
|
- .Query(
|
|
|
- new Filter<Document>(x => x.ID).IsEqualTo(document.DocumentLink.ID))
|
|
|
- .ToObjects<Document>().FirstOrDefault();
|
|
|
- if (doc is null)
|
|
|
- {
|
|
|
- Logger.Send(LogType.Error, "", $"Document with ID {document.DocumentLink.ID} could not be found.");
|
|
|
- MessageBox.Show("Error: the selected document could not be found in the database.");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- var tempdocpath = Path.GetTempPath() + @"\" + doc.FileName;
|
|
|
- selectedSetout.SavePath = tempdocpath;
|
|
|
- selectedSetout.LockedBy.ID = App.EmployeeID;
|
|
|
- new Client<StagingSetout>().Save(selectedSetout, "Locked from Staging Screen");
|
|
|
- File.WriteAllBytes(tempdocpath, doc.Data);
|
|
|
- using (var p = new Process())
|
|
|
- {
|
|
|
- p.StartInfo = new ProcessStartInfo()
|
|
|
- {
|
|
|
- UseShellExecute = true,
|
|
|
- FileName = tempdocpath
|
|
|
- };
|
|
|
-
|
|
|
- p.Start();
|
|
|
- }
|
|
|
- stagingSetoutGrid.Refresh(false, true);
|
|
|
- }
|
|
|
- private void DocumentPreviewer_OnMarkupComplete(IEntityDocument? document)
|
|
|
- {
|
|
|
- if (selectedSetout is null)
|
|
|
- {
|
|
|
- MessageBox.Show("Please select a setout first.");
|
|
|
- return;
|
|
|
- }
|
|
|
- StagingSetoutGrid.ReloadFile(selectedSetout);
|
|
|
- stagingSetoutGrid.Refresh(false, true);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
public void Shutdown(CancelEventArgs? cancel)
|
|
|
{
|