ManufacturingTemplateGrid.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Windows.Controls;
  6. using Comal.Classes;
  7. using InABox.Clients;
  8. using InABox.Core;
  9. using InABox.DynamicGrid;
  10. namespace PRSDesktop
  11. {
  12. public class ManufacturingTemplateGrid : DynamicDataGrid<ManufacturingTemplate>
  13. {
  14. private bool bShowAll;
  15. public ManufacturingTemplateGrid()
  16. {
  17. AddButton("Show All", null, ShowAllClick);
  18. }
  19. private bool ShowAllClick(Button arg1, CoreRow[] arg2)
  20. {
  21. bShowAll = !bShowAll;
  22. UpdateButton(arg1, null, bShowAll ? "Active Only" : "Show All");
  23. return true;
  24. }
  25. protected override void Reload(
  26. Filters<ManufacturingTemplate> criteria, Columns<ManufacturingTemplate> columns, ref SortOrder<ManufacturingTemplate>? sort,
  27. CancellationToken token, Action<CoreTable?, Exception?> action)
  28. {
  29. if (!bShowAll)
  30. criteria.Add(new Filter<ManufacturingTemplate>(x => x.Active).IsEqualTo(true));
  31. base.Reload(criteria, columns, ref sort, token, action);
  32. }
  33. protected override Dictionary<string, object?> EditorValueChanged(IDynamicEditorForm editor, ManufacturingTemplate[] items, string name,
  34. object value)
  35. {
  36. var result = base.EditorValueChanged(editor, items, name, value);
  37. if (name == "Factory.ID")
  38. {
  39. var type = typeof(IDynamicOneToManyGrid<,>).MakeGenericType(typeof(ManufacturingTemplate), typeof(ManufacturingTemplateStage));
  40. var page = editor.Pages.FirstOrDefault(x => x.GetType().GetInterface(type.Name) != null);
  41. if (page != null)
  42. {
  43. var sections = new Client<ManufacturingSection>().Load(new Filter<ManufacturingSection>(x => x.Factory.ID).IsEqualTo(value));
  44. var stages = new List<ManufacturingTemplateStage>();
  45. foreach (var section in sections)
  46. {
  47. var stage = new ManufacturingTemplateStage
  48. {
  49. SequenceType = SequenceType.Link,
  50. Time = new TimeSpan(0, 0, 0),
  51. QualityChecks = "",
  52. Sequence = section.Sequence
  53. };
  54. stage.Section.ID = section.ID;
  55. stage.Section.Synchronise(section);
  56. stages.Add(stage);
  57. }
  58. var load = page.GetType().GetMethod("LoadItems");
  59. load.Invoke(page, new object[] { stages.ToArray() });
  60. }
  61. }
  62. return result;
  63. }
  64. }
  65. }