| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using InABox.Core;
- using Comal.Classes;
- using InABox.Clients;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace comal.timesheets.CustomControls
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class EmployeeSelectionPage : ContentPage
- {
- public event ItemSelectedEvent OnItemSelected;
- public EmployeeShell employee { get; set; }
- string currentButton = "";
- public List<EmployeeGroupDisplayList> employeeGroupDisplayLists { get; set; }
- bool Multiselect = false;
- List<EmployeeShell> selectedList = new List<EmployeeShell>();
- public EmployeeSelectionPage(bool multiselect = false)
- {
- InitializeComponent();
- NavigationPage.SetHasBackButton(this, false);
- employeeGroupDisplayLists = new List<EmployeeGroupDisplayList>();
- foreach (EmployeeShell employee in GlobalVariables.EmployeeShells)
- {
- char c = employee.Name.FirstOrDefault();
- var group = employeeGroupDisplayLists.Find(x => x.Heading.Equals(c.ToString()));
- if (group == null)
- {
- EmployeeGroupDisplayList newGroupList = new EmployeeGroupDisplayList() { Heading = c.ToString() };
- newGroupList.Add(employee);
- employeeGroupDisplayLists.Add(newGroupList);
- }
- else
- {
- employeeGroupDisplayLists.Remove(group);
- group.Add(employee);
- employeeGroupDisplayLists.Add(group);
- }
- }
- currentButton = "All Staff";
- employeeListView.ItemsSource = employeeGroupDisplayLists;
- searchEdt.IsEnabled = true;
- List<string> options = new List<string>();
- foreach (string s in GlobalVariables.TeamNames)
- {
- options.Add(s);
- }
- filterOptionsControl.Options = options;
- filterOptionsControl.CreateRadioButtonsAndSetDefault("All Staff");
- filterOptionsControl.OnFilterOptionChanged += FilterOptionsControl_OnFilterOptionChanged;
- }
- private void Exit(object sender, EventArgs e)
- {
- Navigation.PopAsync();
- }
- private void FilterOptionsControl_OnFilterOptionChanged(string filterOption)
- {
- if (filterOption == filterOptionsControl.CurrentOption)
- return;
- if (filterOption.Equals("All Staff"))
- {
- employeeListView.IsGroupingEnabled = true;
- employeeListView.ItemsSource = employeeGroupDisplayLists;
- }
- else
- {
- employeeListView.IsGroupingEnabled = false;
- employeeListView.ItemsSource = GlobalVariables.TeamEmployeeShells.Where(x => x.TeamName == filterOption);
- }
- currentButton = filterOption;
- filterOptionsControl.CurrentOption = filterOption;
- }
- private void SearchEdt_Changed(object sender, EventArgs e)
- {
- if (string.IsNullOrWhiteSpace(searchEdt.Text))
- {
- if (currentButton.Equals("All Staff"))
- {
- employeeListView.IsGroupingEnabled = true;
- employeeListView.ItemsSource = employeeGroupDisplayLists;
- }
- else
- employeeListView.ItemsSource = GlobalVariables.TeamEmployeeShells.Where(x => x.TeamName == currentButton);
- }
- else
- {
- employeeListView.IsGroupingEnabled = false;
- employeeListView.ItemsSource = GlobalVariables.EmployeeShells.Where
- (
- x => x.Name.Contains(searchEdt.Text) || x.Name.Contains(UpperCaseFirst(searchEdt.Text))
- || x.Name.Contains(searchEdt.Text.ToUpper()) || x.Name.Contains(searchEdt.Text.ToLower())
- );
- }
- }
- static String UpperCaseFirst(string s)
- {
- char[] a = s.ToCharArray();
- a[0] = char.ToUpper(a[0]);
- return new string(a);
- }
- private void Employee_Clicked(object sender, EventArgs e)
- {
- employee = employeeListView.SelectedItem as EmployeeShell;
- OnItemSelected?.Invoke();
- Navigation.PopAsync();
- }
- }
- public class EmployeeGroupDisplayList : List<EmployeeShell>
- {
- public string Heading { get; set; }
- public List<EmployeeShell> employeeShells;
- }
- public delegate void ItemSelectedEvent();
- }
|