JobSelectionPage.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Xamarin.Forms;
  7. using Xamarin.Forms.Xaml;
  8. namespace comal.timesheets.CustomControls
  9. {
  10. [XamlCompilation(XamlCompilationOptions.Compile)]
  11. public partial class JobSelectionPage : ContentPage
  12. {
  13. public event ItemSelectedEvent OnItemSelected;
  14. bool bFirstPage = false;
  15. public JobShell Job { get; set; }
  16. public JobSelectionPage(bool firstpage = false)
  17. {
  18. Title = "Select Job";
  19. InitializeComponent();
  20. bFirstPage = firstpage;
  21. jobListView.ItemsSource = GlobalVariables.JobShells.Where(x => x.JobStatusDescription == "Active");
  22. searchEdt.IsEnabled = true;
  23. LoadButtons();
  24. }
  25. private void LoadButtons()
  26. {
  27. try
  28. {
  29. List<string> descriptions = new List<string>();
  30. List<Button> buttons = new List<Button>();
  31. foreach (JobShell job in GlobalVariables.JobShells)
  32. {
  33. if (!descriptions.Contains(job.JobStatusDescription))
  34. {
  35. if (!string.IsNullOrWhiteSpace(job.JobStatusDescription))
  36. descriptions.Add(job.JobStatusDescription);
  37. }
  38. }
  39. List<string> options = new List<string>();
  40. foreach (string s in descriptions)
  41. {
  42. options.Add(s);
  43. }
  44. filterOptionsControl.Options = options;
  45. filterOptionsControl.CreateRadioButtonsAndSetDefault("Active");
  46. filterOptionsControl.OnFilterOptionChanged += FilterOptionsControl_OnFilterOptionChanged;
  47. }
  48. catch { }
  49. }
  50. private void FilterOptionsControl_OnFilterOptionChanged(string filterOption)
  51. {
  52. if (filterOption == filterOptionsControl.CurrentOption)
  53. return;
  54. jobListView.ItemsSource = GlobalVariables.JobShells.Where(x => x.JobStatusDescription.Equals(filterOption));
  55. filterOptionsControl.CurrentOption = filterOption;
  56. }
  57. private void Job_Clicked(object sender, EventArgs e)
  58. {
  59. Job = jobListView.SelectedItem as JobShell;
  60. OnItemSelected?.Invoke();
  61. if (!bFirstPage)
  62. Navigation.PopAsync();
  63. }
  64. private void SearchEdt_Changed(object sender, EventArgs e)
  65. {
  66. jobListView.ItemsSource = GlobalVariables.JobShells.Where
  67. (
  68. x => x.Name.Contains(searchEdt.Text) || x.Name.Contains(UpperCaseFirst(searchEdt.Text))
  69. || x.Name.Contains(searchEdt.Text.ToUpper()) || x.Name.Contains(searchEdt.Text.ToLower())
  70. || x.JobNumber.Contains(searchEdt.Text) || x.JobNumber.Contains(UpperCaseFirst(searchEdt.Text))
  71. || x.Name.Contains(searchEdt.Text.ToUpper()) || x.JobNumber.Contains(searchEdt.Text.ToLower())
  72. );
  73. }
  74. static String UpperCaseFirst(string s)
  75. {
  76. char[] a = s.ToCharArray();
  77. a[0] = char.ToUpper(a[0]);
  78. return new string(a);
  79. }
  80. }
  81. public class JobShell
  82. {
  83. public Guid ID { get; set; }
  84. public string Name { get; set; }
  85. public string JobNumber { get; set; }
  86. public string DisplayName { get; set; }
  87. public Color Color { get; set; }
  88. public string JobStatusDescription { get; set; }
  89. public JobShell()
  90. {
  91. ID = Guid.Empty;
  92. Name = "";
  93. JobNumber = "";
  94. DisplayName = "";
  95. JobStatusDescription = "";
  96. Color = Color.LightGray;
  97. }
  98. }
  99. }