JobScopePanel.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Windows.Controls;
  6. using System.Windows.Threading;
  7. using Comal.Classes;
  8. using InABox.Core;
  9. using InABox.DynamicGrid;
  10. namespace PRSDesktop;
  11. public partial class JobScopePanel : UserControl, IPanel<JobScope>, IJobControl
  12. {
  13. private enum PageIndex
  14. {
  15. RequisitionItems = 00,
  16. ManufacturingPackets,
  17. DeliveryItems,
  18. Assignments,
  19. Documents
  20. }
  21. private int _currentPage = -1;
  22. private JobScopeRequisitionItemGrid? _requisitionItemsGrid;
  23. private JobScopeAssignmentGrid? _assignmentGrid;
  24. private JobScopeDocumentGrid? _documentGrid;
  25. public JobScopePanel()
  26. {
  27. InitializeComponent();
  28. }
  29. public Job Job
  30. {
  31. get => _scopes.Job;
  32. set
  33. {
  34. _scopes.Job = value;
  35. }
  36. }
  37. public JobPanelSettings Settings { get; set; }
  38. public bool IsReady { get; set; }
  39. public event DataModelUpdateEvent? OnUpdateDataModel;
  40. public void CreateToolbarButtons(IPanelHost host)
  41. {
  42. }
  43. public void Setup()
  44. {
  45. _scopes.Refresh(true, false);
  46. }
  47. public void Shutdown(CancelEventArgs? cancel)
  48. {
  49. }
  50. public void Refresh()
  51. {
  52. _scopes.Refresh(false, true);
  53. RefreshPage();
  54. }
  55. private void RefreshPage()
  56. {
  57. var scope = _scopes.SelectedRows.FirstOrDefault()?.ToObject<JobScope>();
  58. var page = (PageIndex)_pages.SelectedIndex;
  59. switch (page)
  60. {
  61. case PageIndex.RequisitionItems :
  62. RefreshGrid(_requisitionItems, ref _requisitionItemsGrid, scope);
  63. break;
  64. case PageIndex.ManufacturingPackets :
  65. break;
  66. case PageIndex.DeliveryItems :
  67. break;
  68. case PageIndex.Assignments :
  69. RefreshGrid(_assignments, ref _assignmentGrid, scope);
  70. break;
  71. case PageIndex.Documents:
  72. RefreshGrid(_documents, ref _documentGrid, scope);
  73. break;
  74. }
  75. }
  76. public string SectionName => "Job Scopes";
  77. public DataModel DataModel(Selection selection)
  78. {
  79. var ids = _scopes.ExtractValues(x => x.ID, selection).ToArray();
  80. return new AutoDataModel<JobScope>(new Filter<JobScope>(c => c.ID).InList(ids));
  81. }
  82. public Dictionary<string, object[]> Selected()
  83. {
  84. return new Dictionary<string, object[]> { { typeof(JobScope).EntityName(), _scopes.Data.Rows.ToArray<object>() } };
  85. }
  86. public void Heartbeat(TimeSpan time)
  87. {
  88. }
  89. private void _scopes_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  90. {
  91. RefreshPage();
  92. }
  93. private void RefreshGrid<T>(TabItem container, ref T? grid, JobScope? scope) where T : IDynamicGrid, IJobScopeGrid, new()
  94. {
  95. var bInitialised = grid != null;
  96. if (!bInitialised)
  97. {
  98. grid = new T();
  99. container.Content = grid;
  100. }
  101. grid.Scope = scope;
  102. grid.Refresh(!bInitialised, true);
  103. }
  104. private void _pages_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
  105. {
  106. RefreshPage();
  107. }
  108. }