| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class QualificationList
- {
- List<EmployeeQualificationShell> shells = new List<EmployeeQualificationShell>();
- public QualificationList()
- {
- InitializeComponent();
- NavigationPage.SetHasBackButton(this, false);
- }
- protected override void OnAppearing()
- {
- LoadList();
- base.OnAppearing();
- }
- async void LoadList()
- {
- try
- {
- await Task.Run(() =>
- {
- shells.Clear();
- CoreTable table = new Client<EmployeeQualification>().Query
- (
- new Filter<EmployeeQualification>(x => x.Employee.ID).IsEqualTo(App.Data.Me.ID),
- new Columns<EmployeeQualification>
- (
- x => x.ID, //0
- x => x.Qualification.Description, //1
- x => x.Qualified, //2
- x => x.Expiry, //3
- x => x.Verified, //4
- x => x.FrontPhoto.ID, //5
- x => x.BackPhoto.ID, //6
- x => x.Qualification.Renewal, //7
- x => x.QualificationNumber //8
- ),
- new SortOrder<EmployeeQualification>(x => x.Qualification.Description)
- );
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- List<object> list = row.Values;
- if (list[0] == null) { list[0] = Guid.Empty; } //0
- if (list[1] == null) { list[1] = ""; } //1
- if (list[2] == null) { list[2] = DateTime.MinValue; } //2
- if (list[3] == null) { list[3] = DateTime.MinValue; } //3
- if (list[4] == null) { list[4] = DateTime.MinValue; } //4
- if (list[5] == null) { list[5] = Guid.Empty; } //5
- if (list[6] == null) { list[6] = Guid.Empty; } //6
- if (list[8] == null) { list[8] = ""; } //7
- EmployeeQualificationShell shell = new EmployeeQualificationShell
- {
- ID = Guid.Parse(list[0].ToString()),
- Description = list[1].ToString(),
- Qualified = DateTime.Parse(list[2].ToString()),
- Expiry = DateTime.Parse(list[3].ToString()),
- Verified = DateTime.Parse(list[4].ToString()),
- FrontPhotoID = Guid.Parse(list[5].ToString()),
- BackPhotoID = Guid.Parse(list[6].ToString()),
- Renewal = list[7].ToString(),
- Number = "Number: " + list[8].ToString(),
- };
- shell = SetDisplayProperties(shell);
- shells.Add(shell);
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- qualificationsDisplayList.ItemsSource = null;
- qualificationsDisplayList.ItemsSource = shells;
- if (!string.IsNullOrWhiteSpace(searchEnt.Text))
- {
- RunSearch();
- }
- });
- }
- });
- }
- catch { }
- }
- EmployeeQualificationShell SetDisplayProperties(EmployeeQualificationShell shell)
- {
- if (shell.Verified == DateTime.MinValue)
- {
- shell.DisplayVerified = "Unverified";
- shell.VerifiedColor = Color.Orange;
- }
- else
- {
- shell.DisplayVerified = "Verified: " + shell.Verified.ToString("dd MMM yy");
- }
- if (shell.Expiry == DateTime.MinValue)
- {
- shell.DisplayExpiry = "Expiry: ";
- }
- else
- {
- shell.DisplayExpiry = "Expiry: " + shell.Expiry.ToString("dd MMM yy");
- }
- if (shell.Renewal == "Permanent")
- {
- shell.DisplayExpiry = "Does not expire";
- }
- if (shell.Qualified == DateTime.MinValue)
- {
- shell.DisplayQualified = "Qualified: ";
- }
- else
- {
- shell.DisplayQualified = "Qualified: " + shell.Qualified.ToString("dd MMM yy");
- }
- int count = 0;
- if (shell.FrontPhotoID != Guid.Empty)
- {
- count++;
- }
- if (shell.BackPhotoID != Guid.Empty)
- {
- count++;
- }
- shell.DisplayPhotoCount = "Photos: " + count;
- if (count == 0)
- shell.PhotoCountColor = Color.FromHex("#f08080"); //light coral / red
- if (shell.Expiry != DateTime.MinValue)
- {
- if (shell.Expiry >= DateTime.Today)
- {
- if (shell.Expiry <= DateTime.Today.AddDays(30))
- {
- shell.ExpiryColor = Color.Orange;
- }
- else
- {
- shell.ExpiryColor = Color.Default;
- }
- }
- else
- {
- shell.ExpiryColor = Color.FromHex("#f08080"); //light coral / red
- }
- }
-
- return shell;
- }
- void Qualification_Tapped(object sender, EventArgs e)
- {
- EmployeeQualificationShell shell = qualificationsDisplayList.SelectedItem as EmployeeQualificationShell;
- AddEditQualification page = new AddEditQualification(shell.ID);
- Navigation.PushAsync(page);
- }
- void ExitBtn_Clicked(object sender, EventArgs e)
- {
- Navigation.PopAsync();
- }
- void AddBtn_Clicked(object sender, EventArgs e)
- {
- AddEditQualification page = new AddEditQualification(Guid.Empty);
- Navigation.PushAsync(page);
- }
- void SearchEnt_Changed(object sender, EventArgs e)
- {
- RunSearch();
- }
- void RunSearch()
- {
- if (string.IsNullOrEmpty(searchEnt.Text))
- {
- qualificationsDisplayList.ItemsSource = shells;
- }
- else
- {
- qualificationsDisplayList.ItemsSource = shells.Where(x =>
- x.Description.Contains(searchEnt.Text) || x.Description.Contains(UpperCaseFirst(searchEnt.Text))
- || x.Description.Contains(searchEnt.Text.ToUpper()) || x.Description.Contains(searchEnt.Text.ToLower())
- );
- }
- }
- static String UpperCaseFirst(string s)
- {
- char[] a = s.ToCharArray();
- a[0] = char.ToUpper(a[0]);
- return new string(a);
- }
- }
- public class EmployeeQualificationShell
- {
- public Guid ID { get; set; }
- public String Description { get; set; }
- public DateTime Qualified { get; set; }
- public string DisplayQualified { get; set; }
- public DateTime Expiry { get; set; }
- public string DisplayExpiry { get; set; }
- public Color ExpiryColor { get; set; }
- public DateTime Verified { get; set; }
- public Color VerifiedColor { get; set; }
- public string DisplayVerified { get; set; }
- public string DisplayPhotoCount { get; set; }
- public Color PhotoCountColor { get; set; }
- public Guid FrontPhotoID { get; set; }
- public Guid BackPhotoID { get; set; }
- public Guid QualificationID { get; set; }
- public String Renewal { get; set; }
- public string Number { get; set; }
- public EmployeeQualificationShell()
- {
- ID = Guid.Empty;
- Description = "";
- Qualified = DateTime.MinValue;
- DisplayQualified = "";
- Expiry = DateTime.MinValue;
- DisplayExpiry = "";
- ExpiryColor = Color.Default;
- Verified = DateTime.MinValue;
- DisplayVerified = "";
- DisplayPhotoCount = "";
- PhotoCountColor = Color.Default;
- FrontPhotoID = Guid.Empty;
- BackPhotoID = Guid.Empty;
- VerifiedColor = Color.Default;
- QualificationID = Guid.Empty;
- Renewal = "";
- Number = "";
- }
- }
- }
|