StagingPanel.xaml.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. using Comal.Classes;
  2. using InABox.Core;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using InABox.Clients;
  9. using InABox.Configuration;
  10. using InABox.DynamicGrid;
  11. using System.Diagnostics;
  12. using System.IO;
  13. using InABox.WPF;
  14. using System.ComponentModel;
  15. using InABox.Scripting;
  16. using System.Reflection;
  17. using System.Collections.Immutable;
  18. namespace PRSDesktop
  19. {
  20. [Caption("Staging Panel Settings")]
  21. public class StagingPanellSettings : BaseObject, IGlobalConfigurationSettings
  22. {
  23. [Caption("PDF Markup Program Pathway", IncludePath = false)]
  24. [FileNameEditor]
  25. public string MarkupPathway { get; set; }
  26. [FolderEditor(Environment.SpecialFolder.CommonDocuments)]
  27. public string SetoutsFolder { get; set; }
  28. [ScriptEditor]
  29. public string? Script { get; set; }
  30. public StagingPanellSettings()
  31. {
  32. MarkupPathway = "";
  33. SetoutsFolder = "";
  34. Script = null;
  35. }
  36. public string DefaultScript()
  37. {
  38. return @"
  39. using PRSDesktop;
  40. using InABox.Core;
  41. using System.Collections.Generic;
  42. public class Module
  43. {
  44. /*public void CustomiseSetouts(CustomiseSetoutsArgs args)
  45. {
  46. // Perform customisation on the setouts when they are added to the 'Staged Documents' grid.
  47. }*/
  48. }";
  49. }
  50. }
  51. public class CustomiseSetoutsArgs
  52. {
  53. public IReadOnlyList<Tuple<StagingSetout, Document>> Setouts;
  54. public CustomiseSetoutsArgs(IReadOnlyList<Tuple<StagingSetout, Document>> setouts)
  55. {
  56. Setouts = setouts;
  57. }
  58. }
  59. /// <summary>
  60. /// Interaction logic for StagingPanel.xaml
  61. /// </summary>
  62. public partial class StagingPanel : UserControl, IPanel<StagingSetout>
  63. {
  64. private StagingPanellSettings _settings = new StagingPanellSettings();
  65. /// <summary>
  66. /// The currently selected setout.
  67. /// </summary>
  68. private StagingSetout? selectedSetout;
  69. /// <summary>
  70. /// All currently selected setouts; <see cref="selectedSetout"/> will be a member of this list.
  71. /// </summary>
  72. private List<StagingSetout> selectedSetouts = new();
  73. #region Script Stuff
  74. private MethodInfo? _customiseSetoutsMethod;
  75. private MethodInfo? CustomiseSetoutsMethod
  76. {
  77. get
  78. {
  79. EnsureScript();
  80. return _customiseSetoutsMethod;
  81. }
  82. }
  83. private object? _scriptObject;
  84. private object? ScriptObject
  85. {
  86. get
  87. {
  88. EnsureScript();
  89. return _scriptObject;
  90. }
  91. }
  92. private ScriptDocument? _script;
  93. private ScriptDocument? Script
  94. {
  95. get
  96. {
  97. EnsureScript();
  98. return _script;
  99. }
  100. }
  101. private void EnsureScript()
  102. {
  103. if (_script is null && !_settings.Script.IsNullOrWhiteSpace())
  104. {
  105. _script = new ScriptDocument(_settings.Script);
  106. if (!_script.Compile())
  107. {
  108. throw new Exception("Script in Staging Panel Settings failed to compile!");
  109. }
  110. _scriptObject = _script?.GetObject();
  111. _customiseSetoutsMethod = _script?.GetMethod(methodName: "CustomiseSetouts");
  112. }
  113. }
  114. #endregion
  115. public StagingPanel()
  116. {
  117. InitializeComponent();
  118. SectionName = nameof(StagingPanel);
  119. }
  120. public void Setup()
  121. {
  122. _settings = new GlobalConfiguration<StagingPanellSettings>().Load();
  123. MarkUpButton.Visibility = Security.IsAllowed<CanMarkUpSetouts>() ? Visibility.Visible : Visibility.Hidden;
  124. RejectButton.Visibility = Security.IsAllowed<CanApproveSetouts>() ? Visibility.Visible : Visibility.Hidden;
  125. ApproveButton.Visibility = Security.IsAllowed<CanApproveSetouts>() ? Visibility.Visible : Visibility.Hidden;
  126. //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
  127. stagingSetoutGrid.Refresh(true, true);
  128. stagingSetoutGrid.OnSelectItem += StagingSetoutGrid_OnSelectItem;
  129. }
  130. private void NestedPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
  131. {
  132. if(e.View != DynamicSplitPanelView.Master && ManufacturingPacketList.Setout != selectedSetout)
  133. {
  134. ManufacturingPacketList.Setout = selectedSetout;
  135. }
  136. }
  137. #region Document Viewer
  138. public enum DocumentMode
  139. {
  140. Markup,
  141. Complete,
  142. Locked
  143. }
  144. private DocumentMode _mode;
  145. private DocumentMode Mode
  146. {
  147. get => _mode;
  148. set
  149. {
  150. _mode = value;
  151. if (_mode == DocumentMode.Markup)
  152. {
  153. MarkUpButton.Content = "Mark Up";
  154. MarkUpButton.IsEnabled = Document != null;
  155. ApproveButton.IsEnabled = Document != null;
  156. RejectButton.IsEnabled = Document != null;
  157. }
  158. else if (_mode == DocumentMode.Complete)
  159. {
  160. MarkUpButton.Content = "Complete";
  161. MarkUpButton.IsEnabled = Document != null;
  162. ApproveButton.IsEnabled = false;
  163. RejectButton.IsEnabled = false;
  164. }
  165. else if (_mode == DocumentMode.Locked)
  166. {
  167. MarkUpButton.Content = "Locked";
  168. MarkUpButton.IsEnabled = false;
  169. ApproveButton.IsEnabled = false;
  170. RejectButton.IsEnabled = false;
  171. }
  172. }
  173. }
  174. private StagingSetoutDocument? _document;
  175. private StagingSetoutDocument? Document
  176. {
  177. get => _document;
  178. set
  179. {
  180. if(_document != value)
  181. {
  182. _document = value;
  183. RenderDocument(value);
  184. }
  185. }
  186. }
  187. private void RenderDocument(StagingSetoutDocument? document)
  188. {
  189. DocumentViewer.Children.Clear();
  190. if (document is null)
  191. {
  192. return;
  193. }
  194. var table = new Client<Document>().Query(
  195. new Filter<Document>(x => x.ID).IsEqualTo(document.DocumentLink.ID),
  196. new Columns<Document>(x => x.Data));
  197. var first = table.Rows.FirstOrDefault();
  198. if (first is null)
  199. return;
  200. var data = first.Get<Document, byte[]>(x => x.Data);
  201. var images = ImageUtils.RenderPDFToImages(data);
  202. foreach (var image in images)
  203. {
  204. DocumentViewer.Children.Add(new Image
  205. {
  206. Source = ImageUtils.LoadImage(image),
  207. Margin = new Thickness(0, 0, 0, 20)
  208. });
  209. }
  210. }
  211. private void ApproveButton_Click(object sender, RoutedEventArgs e)
  212. {
  213. bool bulkApprove = false;
  214. if (selectedSetouts.Count > 1)
  215. {
  216. if (MessageBox.Show("Bulk approve? (Skip individual setout approval)", "Continue?", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  217. {
  218. bulkApprove = true;
  219. Progress.Show("Approving Setouts..");
  220. }
  221. }
  222. string message = "Result: " + Environment.NewLine;
  223. foreach (var item in selectedSetouts)
  224. {
  225. if (bulkApprove)
  226. Progress.Show("Working on " + item.Number);
  227. var returnstring = ApproveSetout(item, bulkApprove);
  228. if (!string.IsNullOrWhiteSpace(returnstring))
  229. message = message + returnstring + Environment.NewLine;
  230. }
  231. if (bulkApprove)
  232. Progress.Close();
  233. new Client<StagingSetout>().Save(selectedSetouts, "Updated from staging screen");
  234. selectedSetout = null;
  235. Refresh();
  236. MessageBox.Show(message);
  237. }
  238. private string ApproveSetout(StagingSetout item, bool bulkapprove)
  239. {
  240. if (item.Group.ID == Guid.Empty)
  241. {
  242. var message = "Setout has no group assigned";
  243. if (Security.IsAllowed<CanApproveSetoutsWithoutGroup>())
  244. {
  245. if (MessageBox.Show(message + ", continue?", "Continue?", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
  246. return "";
  247. }
  248. else
  249. {
  250. MessageBox.Show(message + ", please assign a group!");
  251. return "";
  252. }
  253. }
  254. var setoutDocument = new Client<StagingSetoutDocument>()
  255. .Query(
  256. new Filter<StagingSetoutDocument>(x => x.EntityLink.ID).IsEqualTo(item.ID),
  257. new Columns<StagingSetoutDocument>(x => x.ID, x => x.DocumentLink.ID, x => x.DocumentLink.FileName))
  258. .ToObjects<StagingSetoutDocument>().FirstOrDefault();
  259. if (setoutDocument is null)
  260. return "";
  261. var setout = new Client<Setout>()
  262. .Query(
  263. new Filter<Setout>(x => x.Number).IsEqualTo(item.Number),
  264. new Columns<Setout>(x => x.ID))
  265. .ToObjects<Setout>().FirstOrDefault();
  266. string result;
  267. //setout already exists - create new setoutdoc and supercede old ones
  268. if (setout is not null)
  269. {
  270. if (!bulkapprove)
  271. if (MessageBox.Show("Supercede existing documents?", "Proceed?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
  272. return "";
  273. setout.Group.ID = item.Group.ID;
  274. item.Setout.ID = setout.ID;
  275. var setoutdoc = new SetoutDocument();
  276. setoutdoc.EntityLink.ID = setout.ID;
  277. setoutdoc.DocumentLink.ID = setoutDocument.DocumentLink.ID;
  278. var setoutdocs = new List<SetoutDocument>
  279. {
  280. setoutdoc
  281. };
  282. CoreTable oldDocsTable = new Client<SetoutDocument>().Query(
  283. new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo((Guid)setout.ID)
  284. .And(x => x.DocumentLink.ID).IsNotEqualTo(item.Group.OptimizationDocument.ID)
  285. );
  286. foreach (var row in oldDocsTable.Rows)
  287. {
  288. var oldDoc = row.ToObject<SetoutDocument>();
  289. if (oldDoc.Superceded == DateTime.MinValue)
  290. {
  291. oldDoc.Superceded = DateTime.Now;
  292. setoutdocs.Add(oldDoc);
  293. }
  294. }
  295. new Client<SetoutDocument>().Save(setoutdocs, "Updated from Staging Screen");
  296. new Client<Setout>().Save((Setout)setout, "Updated from Staging Screen");
  297. result = item.Number + " Superceded";
  298. }
  299. //no setout for this pdf - create new
  300. else
  301. {
  302. setout = new Setout
  303. {
  304. Number = item.Number
  305. };
  306. setout.JobLink.ID = item.JobLink.ID;
  307. setout.Group.ID = item.Group.ID;
  308. var editor = new DynamicDataGrid<Setout>();
  309. editor.OnAfterSave += (editor, items) =>
  310. {
  311. CreateSetoutDocument(setout, item, setoutDocument);
  312. };
  313. if (!bulkapprove)
  314. {
  315. if (!editor.EditItems(new[] { setout }))
  316. {
  317. MessageBox.Show("Setout Creation Cancelled");
  318. return "";
  319. }
  320. else
  321. result = item.Number + " Created";
  322. }
  323. else
  324. {
  325. new Client<Setout>().Save(setout, "Added from staging screen");
  326. CreateSetoutDocument(setout, item, setoutDocument);
  327. result = item.Number + " Created";
  328. }
  329. }
  330. var packets = new List<Tuple<ManufacturingPacket, StagingManufacturingPacket>>();
  331. foreach(var stagingPacket in ManufacturingPacketList.GetPackets())
  332. {
  333. if(stagingPacket.ManufacturingPacket.ID != Guid.Empty)
  334. {
  335. MessageBox.Show($"A manufacturing packet already exists for {stagingPacket.Serial}; skipping packet.");
  336. continue;
  337. }
  338. var packet = new ManufacturingPacket
  339. {
  340. Serial = stagingPacket.Serial,
  341. Title = stagingPacket.Title,
  342. Quantity = stagingPacket.Quantity,
  343. BarcodeQty = stagingPacket.BarcodeQuantity != 0 ? stagingPacket.BarcodeQuantity : stagingPacket.Quantity,
  344. WaterMark = stagingPacket.Watermark.ToString(),
  345. Location = stagingPacket.Location
  346. };
  347. packet.SetoutLink.ID = setout.ID;
  348. packet.ITP.ID = stagingPacket.ITP.ID;
  349. packet.JobLink.ID = stagingPacket.Job.ID;
  350. packet.ManufacturingTemplateLink.ID = stagingPacket.Template.ID;
  351. packets.Add(new(packet, stagingPacket));
  352. }
  353. new Client<ManufacturingPacket>().Save(packets.Select(x => x.Item1), "Created from Design Management Panel");
  354. var newStages = new List<ManufacturingPacketStage>();
  355. foreach(var (packet, stagingPacket) in packets)
  356. {
  357. stagingPacket.ManufacturingPacket.ID = packet.ID;
  358. var stages = new Client<StagingManufacturingPacketStage>()
  359. .Query(
  360. new Filter<StagingManufacturingPacketStage>(x => x.Packet.ID).IsEqualTo(stagingPacket.ID),
  361. IManufacturingPacketGeneratorExtensions.GetPacketGeneratorRequiredColumns<StagingManufacturingPacketStage>());
  362. newStages.AddRange(stages.ToObjects<StagingManufacturingPacketStage>()
  363. .Select(x =>
  364. {
  365. var stage = x.CreateManufacturingPacketStage();
  366. stage.Parent.ID = packet.ID;
  367. return stage;
  368. }));
  369. }
  370. new Client<ManufacturingPacketStage>().Save(newStages, "Created from Design Management");
  371. new Client<StagingManufacturingPacket>().Save(packets.Select(x => x.Item2), "Created from Design Management");
  372. //currently not creating packets due to temporary change in requirements - to uncomment and check for validity when required
  373. //CreatePackets(setout);
  374. return result;
  375. }
  376. private static void CreateSetoutDocument(Setout setout, StagingSetout item, StagingSetoutDocument stagingsetoutdocument)
  377. {
  378. item.Setout.ID = setout.ID;
  379. var setoutdoc = new SetoutDocument();
  380. setoutdoc.EntityLink.ID = setout.ID;
  381. setoutdoc.DocumentLink.ID = stagingsetoutdocument.DocumentLink.ID;
  382. new Client<SetoutDocument>().Save(setoutdoc, "Added from staging screen");
  383. }
  384. private void RejectButton_Click(object sender, RoutedEventArgs e)
  385. {
  386. if (selectedSetout is null || Document is null)
  387. {
  388. MessageBox.Show("Please select a setout");
  389. return;
  390. }
  391. //dont create setout - setout.id remains blank
  392. //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
  393. //attach the document to the task for reference
  394. var task = new Kanban
  395. {
  396. Title = "Setout Review Task (setout rejected)",
  397. Description = "Please review the attached document for setout " + selectedSetout.Number
  398. };
  399. task.ManagerLink.ID = App.EmployeeID;
  400. var page = new KanbanGrid();
  401. page.MyID = App.EmployeeID;
  402. if (page.EditItems(new[] { task }))
  403. {
  404. var doc = new KanbanDocument();
  405. doc.EntityLink.ID = task.ID;
  406. doc.DocumentLink.ID = Document.DocumentLink.ID;
  407. new Client<KanbanDocument>().Save(doc, "Created from staging screen");
  408. selectedSetout.Task.ID = task.ID;
  409. new Client<StagingSetout>().Save(selectedSetout, "Updated from staging screen");
  410. MessageBox.Show("Success - Task Created for Document " + selectedSetout.Number + " (Task no. " + task.Number + " assigned to " + task.EmployeeLink.Name + ")");
  411. selectedSetout = null;
  412. Document = null;
  413. stagingSetoutGrid.Refresh(false, true);
  414. }
  415. else
  416. {
  417. MessageBox.Show("Task creation cancelled - setout not rejected");
  418. }
  419. }
  420. private void MarkUpButton_Click(object sender, RoutedEventArgs e)
  421. {
  422. if (Mode == DocumentMode.Markup)
  423. {
  424. Mode = DocumentMode.Complete;
  425. MessageBox.Show("IMPORTANT - press save in your document editor, then press the Complete Button in PRS");
  426. OnMarkupSelected();
  427. }
  428. else
  429. {
  430. OnMarkupComplete();
  431. Mode = DocumentMode.Markup;
  432. }
  433. }
  434. private void OnMarkupSelected()
  435. {
  436. if (Document is null || selectedSetout is null)
  437. {
  438. MessageBox.Show("Please select a setout first.");
  439. return;
  440. }
  441. var doc = new Client<Document>()
  442. .Query(
  443. new Filter<Document>(x => x.ID).IsEqualTo(Document.DocumentLink.ID))
  444. .ToObjects<Document>().FirstOrDefault();
  445. if (doc is null)
  446. {
  447. Logger.Send(LogType.Error, "", $"Document with ID {Document.DocumentLink.ID} could not be found.");
  448. MessageBox.Show("Error: the selected document could not be found in the database.");
  449. return;
  450. }
  451. var tempdocpath = Path.Combine(Path.GetTempPath(), doc.FileName);
  452. selectedSetout.SavePath = tempdocpath;
  453. selectedSetout.Locked = DateTime.Now;
  454. selectedSetout.LockedBy.ID = App.EmployeeID;
  455. new Client<StagingSetout>().Save(selectedSetout, "Locked from Staging Screen");
  456. File.WriteAllBytes(tempdocpath, doc.Data);
  457. using (var p = new Process())
  458. {
  459. p.StartInfo = new ProcessStartInfo()
  460. {
  461. UseShellExecute = true,
  462. FileName = tempdocpath
  463. };
  464. p.Start();
  465. }
  466. stagingSetoutGrid.Refresh(false, true);
  467. }
  468. private void OnMarkupComplete()
  469. {
  470. if (selectedSetout is null)
  471. {
  472. MessageBox.Show("Please select a setout first.");
  473. return;
  474. }
  475. StagingSetoutGrid.ReloadFile(selectedSetout);
  476. stagingSetoutGrid.Refresh(false, true);
  477. }
  478. #endregion
  479. private void StagingSetoutGrid_OnSelectItem(object sender, InABox.DynamicGrid.DynamicGridSelectionEventArgs e)
  480. {
  481. selectedSetouts.Clear();
  482. foreach (var row in e.Rows ?? Enumerable.Empty<CoreRow>())
  483. selectedSetouts.Add(row.ToObject<StagingSetout>());
  484. selectedSetout = selectedSetouts.FirstOrDefault();
  485. AddPacketButton.IsEnabled = selectedSetout is not null;
  486. if(selectedSetout is null)
  487. {
  488. Document = null;
  489. ManufacturingPacketList.Setout = null;
  490. CollapsePacketsButton.IsEnabled = false;
  491. return;
  492. }
  493. var doc = new Client<StagingSetoutDocument>()
  494. .Query(
  495. new Filter<StagingSetoutDocument>(x => x.EntityLink.ID).IsEqualTo(selectedSetout.ID),
  496. new Columns<StagingSetoutDocument>(x => x.ID, x => x.DocumentLink.ID, x => x.DocumentLink.FileName))
  497. .ToObjects<StagingSetoutDocument>().FirstOrDefault();
  498. if(doc is null)
  499. {
  500. MessageBox.Show("No document found for this setout.");
  501. Document = null;
  502. return;
  503. }
  504. Document = doc;
  505. if(MainPanel.View != DynamicSplitPanelView.Master && NestedPanel.View != DynamicSplitPanelView.Master)
  506. {
  507. ManufacturingPacketList.Setout = selectedSetout;
  508. }
  509. CollapsePacketsButton.IsEnabled = true;
  510. Mode =
  511. selectedSetout.Locked == DateTime.MinValue ?
  512. DocumentMode.Markup :
  513. selectedSetout.LockedBy.ID == App.EmployeeID ?
  514. DocumentMode.Complete :
  515. DocumentMode.Locked;
  516. }
  517. public bool IsReady { get; set; }
  518. public string SectionName { get; }
  519. public event DataModelUpdateEvent? OnUpdateDataModel;
  520. #region Settings
  521. public void CreateToolbarButtons(IPanelHost host)
  522. {
  523. host.CreateSetupAction(new PanelAction() { Caption = "Setouts Configuration", Image = PRSDesktop.Resources.specifications, OnExecute = ConfigSettingsClick });
  524. }
  525. private void ConfigSettingsClick(PanelAction obj)
  526. {
  527. var pages = new DynamicEditorPages();
  528. var propertyEditor = new DynamicEditorForm(typeof(StagingPanellSettings), pages);
  529. propertyEditor.OnDefineLookups += sender =>
  530. {
  531. var editor = sender.EditorDefinition as ILookupEditor;
  532. var colname = sender.ColumnName;
  533. var values = editor.Values(colname, new[] { _settings });
  534. sender.LoadLookups(values);
  535. };
  536. propertyEditor.OnEditorValueChanged += (sender, name, value) =>
  537. {
  538. CoreUtils.SetPropertyValue(_settings, name, value);
  539. return new Dictionary<string, object?>();
  540. };
  541. propertyEditor.OnFormCustomiseEditor += Settings_OnFormCustomiseEditor;
  542. propertyEditor.Items = new BaseObject[] { _settings };
  543. if (propertyEditor.ShowDialog() == true)
  544. {
  545. new GlobalConfiguration<StagingPanellSettings>().Save(_settings);
  546. _script = null;
  547. }
  548. }
  549. private void Settings_OnFormCustomiseEditor(IDynamicEditorForm sender, object[] items, DynamicGridColumn column, BaseEditor editor)
  550. {
  551. if (items?.FirstOrDefault() is not StagingPanellSettings settings) return;
  552. if (column.ColumnName == nameof(StagingPanellSettings.Script) && editor is ScriptEditor scriptEditor)
  553. {
  554. scriptEditor.Type = ScriptEditorType.TemplateEditor;
  555. scriptEditor.OnEditorClicked += () =>
  556. {
  557. var script = settings.Script.NotWhiteSpaceOr()
  558. ?? settings.DefaultScript();
  559. var editor = new ScriptEditorWindow(script, SyntaxLanguage.CSharp);
  560. if (editor.ShowDialog() == true)
  561. {
  562. sender.SetEditorValue(column.ColumnName, editor.Script);
  563. settings.Script = editor.Script;
  564. }
  565. };
  566. }
  567. }
  568. #endregion
  569. public void Heartbeat(TimeSpan time)
  570. {
  571. }
  572. public void Refresh()
  573. {
  574. //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
  575. stagingSetoutGrid.Refresh(false, true);
  576. Document = null;
  577. ManufacturingPacketList.Setout = null;
  578. }
  579. public Dictionary<string, object[]> Selected()
  580. {
  581. return new();
  582. }
  583. public void Shutdown(CancelEventArgs? cancel)
  584. {
  585. }
  586. public DataModel DataModel(Selection selection)
  587. {
  588. return new AutoDataModel<StagingSetout>(new Filter<StagingSetout>().All());
  589. }
  590. private void AddPacketButton_Click(object sender, RoutedEventArgs e)
  591. {
  592. ManufacturingPacketList.Add();
  593. }
  594. private void CollapsePacketsButton_Click(object sender, RoutedEventArgs e)
  595. {
  596. if (ManufacturingPacketList.Collapsed())
  597. {
  598. ManufacturingPacketList.Uncollapse();
  599. }
  600. else
  601. {
  602. ManufacturingPacketList.Collapse();
  603. }
  604. }
  605. private void ManufacturingPacketList_OnCollapsed(bool collapsed)
  606. {
  607. if (collapsed)
  608. {
  609. CollapsePacketsButton.Content = "Expand";
  610. }
  611. else
  612. {
  613. CollapsePacketsButton.Content = "Collapse";
  614. }
  615. }
  616. private void stagingSetoutGrid_OnCustomiseSetouts(IReadOnlyList<StagingSetoutGrid.SetoutDocument> setouts)
  617. {
  618. if(CustomiseSetoutsMethod != null && ScriptObject != null)
  619. {
  620. CustomiseSetoutsMethod?.Invoke(ScriptObject, new object?[]
  621. {
  622. new CustomiseSetoutsArgs(setouts.Select(x => new Tuple<StagingSetout, Document>(x.Setout, x.Document)).ToImmutableList())
  623. });
  624. }
  625. }
  626. }
  627. }