JobBillOfMaterialsPanel.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. /// <summary>
  11. /// Interaction logic for JobBillOfMaterialsPanel.xaml
  12. /// </summary>
  13. public partial class JobBillOfMaterialsPanel : UserControl, IBasePanel, IJobControl, IDataModelSource
  14. {
  15. private Guid _jobid = Guid.Empty;
  16. public JobBillOfMaterialsPanel()
  17. {
  18. InitializeComponent();
  19. }
  20. public CoreRow[] SelectedRows => BillsOfMaterials.SelectedRows;
  21. public event DataModelUpdateEvent OnUpdateDataModel;
  22. public string SectionName => "Job Bill of Materials";
  23. public DataModel DataModel(Selection selection)
  24. {
  25. BaseDataModel<JobBillOfMaterials> model = null;
  26. if (selection == Selection.Selected)
  27. {
  28. var bomid = BillsOfMaterials.SelectedRows.Any()
  29. ? BillsOfMaterials.SelectedRows.First().Get<JobBillOfMaterials, Guid>(x => x.ID)
  30. : CoreUtils.FullGuid;
  31. model = new BaseDataModel<JobBillOfMaterials>(new Filter<JobBillOfMaterials>(x => x.ID).IsEqualTo(bomid));
  32. }
  33. else
  34. model = new BaseDataModel<JobBillOfMaterials>(new Filter<JobBillOfMaterials>(x => x.Job.ID).IsEqualTo(ParentID));
  35. var jobfilter = ((ParentID == Guid.Empty) || (ParentID == CoreUtils.FullGuid))
  36. ? new Filter<Job>().None()
  37. : new Filter<Job>(x => x.ID).IsEqualTo(ParentID);
  38. model.AddTable<Job>(jobfilter, null, true, "Job", true);
  39. return model;
  40. }
  41. public void CreateToolbarButtons(IPanelHost host)
  42. {
  43. }
  44. public void Setup()
  45. {
  46. BillsOfMaterials.Refresh(true, false);
  47. BillOfMaterialsItems.Refresh(true, false);
  48. }
  49. public void Shutdown()
  50. {
  51. }
  52. public void Refresh()
  53. {
  54. BillsOfMaterials.Refresh(false, true);
  55. }
  56. public Dictionary<string, object[]> Selected()
  57. {
  58. var jobfilter = ((ParentID == Guid.Empty) || (ParentID == CoreUtils.FullGuid))
  59. ? new Filter<Job>().None()
  60. : new Filter<Job>(x => x.ID).IsEqualTo(ParentID);
  61. return new Dictionary<string, object[]>
  62. {
  63. { typeof(Job).EntityName(), new Client<Job>().Query(jobfilter).Rows.ToArray() },
  64. { typeof(JobBillOfMaterials).EntityName(), BillsOfMaterials.SelectedRows },
  65. { typeof(JobBillOfMaterialsItem).EntityName(), BillOfMaterialsItems.SelectedRows }
  66. };
  67. }
  68. public void Heartbeat(TimeSpan time)
  69. {
  70. }
  71. public bool IsReady { get; set; }
  72. public Guid ParentID
  73. {
  74. get => _jobid;
  75. set
  76. {
  77. _jobid = value;
  78. BillsOfMaterials.ParentID = value;
  79. BillOfMaterialsItems.JobID = value;
  80. }
  81. }
  82. public JobPanelSettings Settings { get; set; }
  83. private void BillsOfMaterials_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  84. {
  85. BillOfMaterialsItems.JobID = ParentID;
  86. BillOfMaterialsItems.BillOfMaterialsID =
  87. e.Rows?.Any() == true ? e.Rows.First().Get<JobBillOfMaterials, Guid>(x => x.ID) : CoreUtils.FullGuid;
  88. BillOfMaterialsItems.Refresh(false, true);
  89. }
  90. }