JobSelectionPage.xaml.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 delegate void JobNumberChanged(string jobnumber);
  86. public event JobIDChanged OnJobIDChanged;
  87. public event JobNumberChanged OnJobNumberChanged;
  88. private Guid id;
  89. private string jobnumber;
  90. public Guid ID
  91. {
  92. get => id;
  93. set
  94. {
  95. id = value;
  96. OnJobIDChanged?.Invoke(value);
  97. }
  98. }
  99. public string Name { get; set; }
  100. public string JobNumber
  101. {
  102. get => jobnumber;
  103. set
  104. {
  105. jobnumber = value;
  106. OnJobNumberChanged?.Invoke(value);
  107. }
  108. }
  109. public string DisplayName { get; set; }
  110. public Color Color { get; set; }
  111. public string JobStatusDescription { get; set; }
  112. public JobShell()
  113. {
  114. ID = Guid.Empty;
  115. Name = "";
  116. JobNumber = "";
  117. DisplayName = "";
  118. JobStatusDescription = "";
  119. Color = Color.LightGray;
  120. }
  121. }
  122. }