ManufacturingList.xaml.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using InABox.Configuration;
  5. using InABox.Mobile;
  6. using Xamarin.Forms;
  7. using Xamarin.Forms.Xaml;
  8. namespace PRS.Mobile
  9. {
  10. public class MobileManufacturingSettings : ILocalConfigurationSettings
  11. {
  12. public Guid FactoryID { get; set; }
  13. public Guid JobID { get; set; }
  14. }
  15. [XamlCompilation(XamlCompilationOptions.Compile)]
  16. public partial class ManufacturingList
  17. {
  18. private MobileManufacturingSettings _settings;
  19. public ManufacturingList()
  20. {
  21. var _setup = new Task[]
  22. {
  23. Task.Run(() => _settings = new LocalConfiguration<MobileManufacturingSettings>().Load()),
  24. Task.Run(() => App.Data.Jobs.Refresh(false)),
  25. Task.Run(() => App.Data.ManufacturingFactories.Refresh(false))
  26. };
  27. InitializeComponent();
  28. Task.WaitAll(_setup);
  29. UpdateJobButton();
  30. UpdateFactoryButton();
  31. _items.JobID = _settings.JobID;
  32. _items.FactoryID = _settings.FactoryID;
  33. _items.RefreshData(false,true);
  34. }
  35. private void UpdateJobButton()
  36. {
  37. var job = App.Data.Jobs.FirstOrDefault(x => x.ID == _settings.JobID);
  38. _selectjob.Text = job != null
  39. ? job.DisplayName
  40. : "All Jobs";
  41. }
  42. private void UpdateFactoryButton()
  43. {
  44. var factory = App.Data.ManufacturingFactories.FirstOrDefault(x => x.ID == _settings.FactoryID);
  45. _factory.Text = factory != null
  46. ? factory.Name
  47. : "All Factories";
  48. }
  49. private void _selectjob_OnClicked(object sender, MobileButtonClickEventArgs args)
  50. {
  51. var selection = CreateJobSelection("Select Job", (joblookupshell) =>
  52. {
  53. _settings.JobID = joblookupshell?.ID ?? Guid.Empty;
  54. new LocalConfiguration<MobileManufacturingSettings>().Save(_settings);
  55. UpdateJobButton();
  56. _items.JobID = _settings.JobID;
  57. _items.RefreshData(false,true);
  58. });
  59. ShowPopup(() => selection);
  60. }
  61. private View CreateJobSelection(String caption, Action<JobShell> selected)
  62. {
  63. SelectionView selection = new SelectionView
  64. {
  65. VerticalOptions = LayoutOptions.Fill,
  66. HorizontalOptions = LayoutOptions.Fill,
  67. CanSearch = true
  68. };
  69. selection.Configure += (sender, args) =>
  70. {
  71. args.Columns
  72. .BeginUpdate()
  73. .Clear()
  74. .Add(new MobileGridTextColumn<JobShell>() { Column = x=>x.JobNumber, Width = GridLength.Auto, Caption = "Job #"})
  75. .Add(new MobileGridTextColumn<JobShell>() { Column = x=>x.Name, Width = GridLength.Star, Caption = caption})
  76. .EndUpdate();
  77. args.Filters.AddRange(App.Data.Jobs.AvailableFilters().Select(x=>x.Name));
  78. };
  79. selection.Refresh += (sender, args) => App.Data.Jobs.Refresh(false);
  80. selection.SelectionChanged += (sender, args) =>
  81. {
  82. selected(args.SelectedItems.FirstOrDefault() as JobShell);
  83. DismissPopup();
  84. };
  85. selection.AddButton("All Jobs", () =>
  86. {
  87. selected(null);
  88. DismissPopup();
  89. });
  90. selection.Load();
  91. return selection;
  92. }
  93. private View CreateFactorySelection(String caption, Action<ManufacturingFactoryShell> selected)
  94. {
  95. SelectionView selection = new SelectionView
  96. {
  97. VerticalOptions = LayoutOptions.Fill,
  98. HorizontalOptions = LayoutOptions.Fill,
  99. CanSearch = false
  100. };
  101. selection.Configure += (sender, args) =>
  102. {
  103. args.Columns
  104. .BeginUpdate()
  105. .Clear()
  106. .Add(new MobileGridTextColumn<ManufacturingFactoryShell>() { Column = x=>x.Name, Width = GridLength.Star, Caption = caption})
  107. .EndUpdate();
  108. };
  109. selection.Refresh += (sender, args) => App.Data.ManufacturingFactories.Refresh(false);
  110. selection.SelectionChanged += (sender, args) =>
  111. {
  112. selected(args.SelectedItems.FirstOrDefault() as ManufacturingFactoryShell);
  113. DismissPopup();
  114. };
  115. selection.AddButton("All Factories", () =>
  116. {
  117. selected(null);
  118. DismissPopup();
  119. });
  120. selection.Load();
  121. return selection;
  122. }
  123. private void _selectfactory_OnClicked(object sender, MobileButtonClickEventArgs args)
  124. {
  125. var selection = CreateFactorySelection("Select Factory", (factory) =>
  126. {
  127. _settings.FactoryID = factory?.ID ?? Guid.Empty;
  128. new LocalConfiguration<MobileManufacturingSettings>().Save(_settings);
  129. UpdateFactoryButton();
  130. _items.FactoryID = _settings.FactoryID;
  131. _items.RefreshData(false,true);
  132. });
  133. ShowPopup(() => selection);
  134. }
  135. }
  136. }