123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861 |
- using Comal.Classes;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.DynamicGrid;
- using System.Diagnostics;
- using System.IO;
- using InABox.WPF;
- using System.ComponentModel;
- using InABox.Scripting;
- using System.Reflection;
- using System.Collections.Immutable;
- using FastReport.Data;
- using Microsoft.Xaml.Behaviors.Core;
- namespace PRSDesktop
- {
- [Caption("Staging Panel Settings")]
- public class StagingPanellSettings : BaseObject, IGlobalConfigurationSettings
- {
- [Caption("PDF Markup Program Pathway", IncludePath = false)]
- [FileNameEditor]
- public string MarkupPathway { get; set; }
- [FolderEditor(Environment.SpecialFolder.CommonDocuments)]
- public string SetoutsFolder { get; set; }
- [ScriptEditor]
- public string? Script { get; set; }
- public StagingPanellSettings()
- {
- MarkupPathway = "";
- SetoutsFolder = "";
- Script = null;
- }
- public string DefaultScript()
- {
- return @"
- using PRSDesktop;
- using InABox.Core;
- using System.Collections.Generic;
- public class Module
- {
- /*public void CustomiseSetouts(CustomiseSetoutsArgs args)
- {
- // Perform customisation on the setouts when they are added to the 'Staged Documents' grid.
- }*/
- }";
- }
- }
- public class CustomiseSetoutsArgs
- {
- public IReadOnlyList<Tuple<StagingSetout, Document>> Setouts;
- public CustomiseSetoutsArgs(IReadOnlyList<Tuple<StagingSetout, Document>> setouts)
- {
- Setouts = setouts;
- }
- }
- /// <summary>
- /// Interaction logic for StagingPanel.xaml
- /// </summary>
- public partial class StagingPanel : UserControl, IPanel<StagingSetout>
- {
- private StagingPanellSettings _settings = new StagingPanellSettings();
-
- /// <summary>
- /// The currently selected setout.
- /// </summary>
- private StagingSetout? selectedSetout;
- /// <summary>
- /// All currently selected setouts; <see cref="selectedSetout"/> will be a member of this list.
- /// </summary>
- private List<StagingSetout> selectedSetouts = new();
- private CoreTable? _templateGroups = null;
- #region Script Stuff
- private MethodInfo? _customiseSetoutsMethod;
- private MethodInfo? CustomiseSetoutsMethod
- {
- get
- {
- EnsureScript();
- return _customiseSetoutsMethod;
- }
- }
- private object? _scriptObject;
- private object? ScriptObject
- {
- get
- {
- EnsureScript();
- return _scriptObject;
- }
- }
- private ScriptDocument? _script;
- private ScriptDocument? Script
- {
- get
- {
- EnsureScript();
- return _script;
- }
- }
- private void EnsureScript()
- {
- if (_script is null && !_settings.Script.IsNullOrWhiteSpace())
- {
- _script = new ScriptDocument(_settings.Script);
- if (!_script.Compile())
- {
- throw new Exception("Script in Staging Panel Settings failed to compile!");
- }
- _scriptObject = _script?.GetObject();
- _customiseSetoutsMethod = _script?.GetMethod(methodName: "CustomiseSetouts");
- }
- }
- #endregion
- public StagingPanel()
- {
- InitializeComponent();
- SectionName = nameof(StagingPanel);
-
- }
- public void Setup()
- {
- _settings = new GlobalConfiguration<StagingPanellSettings>().Load();
-
- _templateGroups = new Client<ManufacturingTemplateGroup>().Query();
-
- 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;
- ProcessButton.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 && !Document.Approved;
- ProcessButton.IsEnabled = Document != null && Document.Approved;
- RejectButton.IsEnabled = Document != null && !Document.Approved;
- ApproveButton.IsEnabled = Document != null;
- }
- else if (_mode == DocumentMode.Complete)
- {
- MarkUpButton.Content = "Complete";
- MarkUpButton.IsEnabled = Document != null;
- ProcessButton.IsEnabled = false;
- RejectButton.IsEnabled = false;
- ApproveButton.IsEnabled = false;
- }
- else if (_mode == DocumentMode.Locked)
- {
- MarkUpButton.Content = "Locked";
- MarkUpButton.IsEnabled = false;
- ProcessButton.IsEnabled = false;
- RejectButton.IsEnabled = false;
- ApproveButton.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 ProcessButton_Click(object sender, RoutedEventArgs e)
- {
- bool bulkApprove = false;
- if (selectedSetouts.Count > 1)
- {
- if (MessageBox.Show("Bulk approve? (Skip individual setout approval)", "Continue?", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
- {
- bulkApprove = true;
- Progress.Show("Approving Setouts..");
- }
- }
- if(selectedSetouts.Any(x => x.UnapprovedDocuments > 0))
- {
- MessageBox.Show("Cannot process setouts with unapproved documents.");
- Progress.Close();
- return;
- }
- else if(selectedSetouts.Any(x => x.Packets == 0))
- {
- if(MessageBox.Show("Warning: some setouts do not have any manufacturing packets: are you sure you wish to proceed?", "Warning", MessageBoxButton.YesNoCancel) != MessageBoxResult.Yes)
- {
- Progress.Close();
- return;
- }
- }
- string message = "Result: " + Environment.NewLine;
- foreach (var item in selectedSetouts)
- {
- 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();
- new Client<StagingSetout>().Save(selectedSetouts, "Updated from staging screen");
- selectedSetout = null;
- Refresh();
-
- MessageBox.Show(message);
- MainPanel.View = DynamicSplitPanelView.Combined;
- NestedPanel.View = DynamicSplitPanelView.Master;
- }
- private string ApproveSetout(StagingSetout item, bool bulkapprove)
- {
- 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 "";
- }
- else
- {
- MessageBox.Show(message + ", please assign a group!");
- return "";
- }
- }
- var setoutDocument = 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))
- .ToObjects<StagingSetoutDocument>().FirstOrDefault();
- if (setoutDocument is null)
- return "";
- var setout = new Client<Setout>()
- .Query(
- new Filter<Setout>(x => x.Number).IsEqualTo(item.Number),
- 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)
- {
- if (!bulkapprove)
- if (MessageBox.Show("Supercede existing documents?", "Proceed?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
- return "";
- setout.Group.ID = item.Group.ID;
- item.Setout.ID = setout.ID;
- var setoutdoc = new SetoutDocument();
- setoutdoc.EntityLink.ID = setout.ID;
- setoutdoc.DocumentLink.ID = setoutDocument.DocumentLink.ID;
- var setoutdocs = new List<SetoutDocument>
- {
- setoutdoc
- };
- CoreTable oldDocsTable = new Client<SetoutDocument>().Query(
- new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo((Guid)setout.ID)
- .And(x => x.DocumentLink.ID).IsNotEqualTo(item.Group.OptimizationDocument.ID)
- );
- foreach (var row in oldDocsTable.Rows)
- {
- var oldDoc = row.ToObject<SetoutDocument>();
- if (oldDoc.Superceded == DateTime.MinValue)
- {
- oldDoc.Superceded = DateTime.Now;
- setoutdocs.Add(oldDoc);
- }
- }
- new Client<SetoutDocument>().Save(setoutdocs, "Updated from Staging Screen");
- new Client<Setout>().Save((Setout)setout, "Updated from Staging Screen");
- result = item.Number + " Superceded";
- }
- //no setout for this pdf - create new
- else
- {
- setout = new 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) =>
- {
- CreateSetoutDocument(setout, item, setoutDocument);
- };
- if (!bulkapprove)
- {
- if (!editor.EditItems(new[] { setout }))
- {
- MessageBox.Show("Setout Creation Cancelled");
- return "";
- }
- else
- result = item.Number + " Created";
- }
- else
- {
- new Client<Setout>().Save(setout, "Added from staging screen");
- CreateSetoutDocument(setout, item, setoutDocument);
- result = item.Number + " Created";
- }
- }
- var packets = new List<Tuple<ManufacturingPacket, StagingManufacturingPacket>>();
- var stagingPackets = new Client<StagingManufacturingPacket>()
- .Query(
- new Filter<StagingManufacturingPacket>(x => x.StagingSetout.ID).IsEqualTo(item.ID),
- new Columns<StagingManufacturingPacket>(x => x.ID)
- .Add(x => x.Serial)
- .Add(x => x.Title)
- .Add(x => x.Quantity)
- .Add(x => x.BarcodeQuantity)
- .Add(x => x.Watermark.ID)
- .Add(x => x.Location)
- .Add(x => x.ITP.ID)
- .Add(x => x.Job.ID)
- .Add(x => x.Template.ID));
- foreach(var stagingPacket in stagingPackets.ToObjects<StagingManufacturingPacket>())
- {
- 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)
- {
- 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 RejectButton_Click(object sender, RoutedEventArgs e)
- {
- if (selectedSetout is null || Document is null)
- {
- MessageBox.Show("Please select a setout");
- return;
- }
- //dont create setout - setout.id remains blank
- //create kanban and populate task.id - this prevents it from appearing on the stagingsetout grid, and allows a new staging setout to be created when the file is saved to the folder again
- //attach the document to the task for reference
- var task = new Kanban
- {
- Title = "Setout Review Task (setout rejected)",
- Description = "Please review the attached document for setout " + selectedSetout.Number
- };
- task.ManagerLink.ID = App.EmployeeID;
- var page = new KanbanGrid();
- page.MyID = App.EmployeeID;
- if (page.EditItems(new[] { task }))
- {
- var doc = new KanbanDocument();
- doc.EntityLink.ID = task.ID;
- doc.DocumentLink.ID = Document.DocumentLink.ID;
- new Client<KanbanDocument>().Save(doc, "Created from staging screen");
- selectedSetout.Task.ID = task.ID;
- new Client<StagingSetout>().Save(selectedSetout, "Updated from staging screen");
- MessageBox.Show("Success - Task Created for Document " + selectedSetout.Number + " (Task no. " + task.Number + " assigned to " + task.EmployeeLink.Name + ")");
- selectedSetout = null;
- Document = null;
- stagingSetoutGrid.Refresh(false, true);
- }
- else
- {
- MessageBox.Show("Task creation cancelled - setout not rejected");
- }
- }
- private void MarkUpButton_Click(object sender, RoutedEventArgs e)
- {
- if (Mode == DocumentMode.Markup)
- {
- 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 ApproveButton_Click(object sender, RoutedEventArgs e)
- {
- if (Document is null || selectedSetout is null)
- {
- MessageBox.Show("Please select a setout first.");
- return;
- }
- Document.Approved = !Document.Approved;
- new Client<StagingSetoutDocument>().Save(Document, "");
- stagingSetoutGrid.Refresh(false, true);
- }
- 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();
- foreach (var row in e.Rows ?? Enumerable.Empty<CoreRow>())
- selectedSetouts.Add(row.ToObject<StagingSetout>());
- selectedSetout = selectedSetouts.FirstOrDefault();
- AddPacketButton.IsEnabled = selectedSetout is not null;
- if(selectedSetout is null)
- {
- Document = null;
- ManufacturingPacketList.Setout = null;
- CollapsePacketsButton.IsEnabled = false;
- return;
- }
- var doc = new Client<StagingSetoutDocument>()
- .Query(
- new Filter<StagingSetoutDocument>(x => x.EntityLink.ID).IsEqualTo(selectedSetout.ID),
- new Columns<StagingSetoutDocument>(x => x.ID, x => x.DocumentLink.ID, x => x.DocumentLink.FileName, x => x.Approved))
- .ToObjects<StagingSetoutDocument>().FirstOrDefault();
- if(doc is null)
- {
- MessageBox.Show("No document found for this setout.");
- Document = null;
- ManufacturingPacketList.Setout = null;
- CollapsePacketsButton.IsEnabled = false;
- return;
- }
- Document = doc;
- if(MainPanel.View != DynamicSplitPanelView.Master && NestedPanel.View != DynamicSplitPanelView.Master)
- {
- ManufacturingPacketList.Setout = selectedSetout;
- }
- CollapsePacketsButton.IsEnabled = true;
- Mode =
- selectedSetout.Locked == DateTime.MinValue ?
- DocumentMode.Markup :
- selectedSetout.LockedBy.ID == App.EmployeeID ?
- DocumentMode.Complete :
- DocumentMode.Locked;
- ApproveButton.Content = Document.Approved ? "Unapprove" : "Approve";
-
- }
- public bool IsReady { get; set; }
- public string SectionName { get; }
- public event DataModelUpdateEvent? OnUpdateDataModel;
- #region Settings
- public void CreateToolbarButtons(IPanelHost host)
- {
- host.CreateSetupAction(
- new PanelAction()
- {
- Caption = "Setouts Configuration",
- Image = PRSDesktop.Resources.specifications,
- OnExecute = ConfigSettingsClick
- }
- );
-
- host.CreateSetupAction(
- new PanelAction()
- {
- Caption = "Template Products",
- Image = PRSDesktop.Resources.specifications,
- OnExecute =
- action =>
- {
- var list = new MasterList(typeof(ManufacturingTemplateGroupProducts));
- list.ShowDialog();
- }
- }
- );
- }
- private void ConfigSettingsClick(PanelAction obj)
- {
- var pages = new DynamicEditorPages();
- var propertyEditor = new DynamicEditorForm(typeof(StagingPanellSettings), pages);
- propertyEditor.OnDefineLookups += sender =>
- {
- var editor = sender.EditorDefinition as ILookupEditor;
- var colname = sender.ColumnName;
- var values = editor.Values(colname, new[] { _settings });
- sender.LoadLookups(values);
- };
- propertyEditor.OnEditorValueChanged += (sender, name, value) =>
- {
- CoreUtils.SetPropertyValue(_settings, name, value);
- return new Dictionary<string, object?>();
- };
- propertyEditor.OnFormCustomiseEditor += Settings_OnFormCustomiseEditor;
- propertyEditor.Items = new BaseObject[] { _settings };
- if (propertyEditor.ShowDialog() == true)
- {
- new GlobalConfiguration<StagingPanellSettings>().Save(_settings);
- _script = null;
- }
- }
- private void Settings_OnFormCustomiseEditor(IDynamicEditorForm sender, object[] items, DynamicGridColumn column, BaseEditor editor)
- {
- if (items?.FirstOrDefault() is not StagingPanellSettings settings) return;
- if (column.ColumnName == nameof(StagingPanellSettings.Script) && editor is ScriptEditor scriptEditor)
- {
- scriptEditor.Type = ScriptEditorType.TemplateEditor;
- scriptEditor.OnEditorClicked += () =>
- {
- var script = settings.Script.NotWhiteSpaceOr()
- ?? settings.DefaultScript();
- var editor = new ScriptEditorWindow(script, SyntaxLanguage.CSharp);
- if (editor.ShowDialog() == true)
- {
- sender.SetEditorValue(column.ColumnName, editor.Script);
- settings.Script = editor.Script;
- }
- };
- }
- }
- #endregion
- public void Heartbeat(TimeSpan time)
- {
- }
- public void Refresh()
- {
- //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
- stagingSetoutGrid.Refresh(false, true);
- Document = null;
- ManufacturingPacketList.Setout = null;
- CalculateTime();
- }
- public Dictionary<string, object[]> Selected()
- {
- return new();
- }
- public void Shutdown(CancelEventArgs? cancel)
- {
- }
- public DataModel DataModel(Selection selection)
- {
- return new AutoDataModel<StagingSetout>(new Filter<StagingSetout>().All());
- }
- private void AddPacketButton_Click(object sender, RoutedEventArgs e)
- {
- if (_templateGroups.Rows.Any())
- {
- ContextMenu menu = new ContextMenu();
- foreach (var row in _templateGroups.Rows)
- {
- MenuItem item = new MenuItem()
- {
- Header =
- $"{row.Get<ManufacturingTemplateGroup, String>(x => x.Code)}: {row.Get<ManufacturingTemplateGroup, String>(x => x.Description)}",
- Command = new ActionCommand((obj) =>
- {
- ManufacturingPacketList.Add(row.ToObject<ManufacturingTemplateGroup>());
- stagingSetoutGrid.Refresh(false, true);
- })
- };
- menu.Items.Add(item);
- }
- menu.Items.Add(new Separator());
- MenuItem misc = new MenuItem()
- {
- Header = "Miscellaneous Item",
- Command = new ActionCommand((obj) =>
- {
- ManufacturingPacketList.Add(null);
- stagingSetoutGrid.Refresh(false, true);
- })
- };
- menu.Items.Add(misc);
- menu.IsOpen = true;
- }
- else
- {
- ManufacturingPacketList.Add(null);
- stagingSetoutGrid.Refresh(false, true);
- }
- }
-
- private void CollapsePacketsButton_Click(object sender, RoutedEventArgs e)
- {
- if (ManufacturingPacketList.Collapsed())
- {
- ManufacturingPacketList.Uncollapse();
- }
- else
- {
- ManufacturingPacketList.Collapse();
- }
- }
- private void ManufacturingPacketList_OnCollapsed(bool collapsed)
- {
- if (collapsed)
- {
- CollapsePacketsButton.Content = "Expand";
- }
- else
- {
- CollapsePacketsButton.Content = "Collapse";
- }
- }
- private void stagingSetoutGrid_OnCustomiseSetouts(IReadOnlyList<StagingSetoutGrid.SetoutDocument> setouts)
- {
- if(CustomiseSetoutsMethod != null && ScriptObject != null)
- {
- CustomiseSetoutsMethod?.Invoke(ScriptObject, new object?[]
- {
- new CustomiseSetoutsArgs(setouts.Select(x => new Tuple<StagingSetout, Document>(x.Setout, x.Document)).ToImmutableList())
- });
- }
- }
- private void StagingSetoutGrid_OnOnDoubleClick(object sender, HandledEventArgs args)
- {
- ManufacturingPacketList.Setout = selectedSetout;
- MainPanel.View = DynamicSplitPanelView.Detail;
- NestedPanel.View = DynamicSplitPanelView.Combined;
- args.Handled = true;
- }
- private void CalculateTime()
- {
- if (selectedSetout != null)
- {
- var time = ManufacturingPacketList.TimeRequired();
- TimeRequired.Content = $"{time.TotalHours:F2} hours";
- }
- else
- TimeRequired.Content = "N/A";
- }
- private void ManufacturingPacketList_OnChanged(object? sender, EventArgs e)
- {
- CalculateTime();
- }
- }
- }
|