ManufacturingTemplateGrid.cs 2.7 KB

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