JobSelectionPage.xaml.cs 4.1 KB

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