| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- using Comal.Classes;
- using InABox.Core;
- using System;
- using System.Linq;
- using InABox.Mobile;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace PRS.Mobile
- {
- public class QualificationExpiryConverter : AbstractConverter<EmployeeQualificationShell, String>
- {
- protected override string Convert(EmployeeQualificationShell value, object? parameter = null)
- {
- return value?.Qualified.IsEmpty() == true
- ? ""
- : value.Expiry.IsEmpty()
- ? "Permanent"
- : $"Expires {value.Expiry:dd MMM yy}";
- }
- }
-
- public class QualificationNumberConverter : AbstractConverter<EmployeeQualificationShell, String>
- {
- protected override string Convert(EmployeeQualificationShell value, object? parameter = null)
- {
- return String.IsNullOrWhiteSpace(value?.Number)
- ? "Not Provided"
- : $"ID: {value.Number}";
- }
- }
-
- public class QualificationColorConverter : AbstractConverter<EmployeeQualificationShell, Color>
- {
- protected override Color Convert(EmployeeQualificationShell value, object? parameter = null)
- {
- return value?.Verified.IsEmpty() == true
- ? Color.LightYellow
- : !value.Expiry.IsEmpty() && value.Expiry <= DateTime.Today
- ? Color.LightSalmon
- : Color.LightGreen;
- }
- }
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class EmployeeQualificationList
- {
- // private readonly QualificationModel _lookups = new QualificationModel(App.Data,
- // LookupFactory.DefineFilter<Qualification>
- // );
-
- public EmployeeQualificationList()
- {
- InitializeComponent();
-
- // _lookups.Refresh(true, () =>
- // {
- // Dispatcher.BeginInvokeOnMainThread(() =>
- // {
- // foreach (var lookup in _lookups.Items)
- // {
- // MobileMenuItem item = new MobileMenuItem
- // {
- // BindingContext = lookup,
- // Text = lookup.Description
- // };
- // item.Clicked += AddQualification;
- // _add.Items.Add(item);
- // }
- //
- // _add.IsVisible = _lookups.Any();
- // });
- // });
-
- RefreshData(false,true);
-
- }
-
- private void _qualification_Refresh(object sender, MobileListRefreshEventArgs args)
- {
- RefreshData(true,false);
- }
- private void RefreshData(bool force, bool async)
- {
- if (async)
- App.Data.EmployeeQualifications.Refresh(force,() => Device.BeginInvokeOnMainThread(RefreshList));
- else
- {
- App.Data.EmployeeQualifications.Refresh(force);
- RefreshList();
- }
- }
-
- private void RefreshList()
- {
- _qualifications.LastUpdated = App.Data.EmployeeQualifications.LastUpdated;
- App.Data.EmployeeQualifications.Search(FilterShell);
- _qualifications.ItemsSource = null;
- _qualifications.ItemsSource ??= App.Data.EmployeeQualifications.Items.ToList();
- }
-
- private bool FilterShell(EmployeeQualificationShell shell)
- {
- var bOK = String.IsNullOrWhiteSpace(_currentfilter)
- || shell.Description.ToUpper().Contains(_currentfilter)
- || shell.Number.ToUpper().Contains(_currentfilter);
- return bOK;
- }
- private String _currentfilter = "";
-
- private void _search_OnTextChanged(object sender, MobileSearchBarTextChangedArgs args)
- {
- _currentfilter = args.Text?.ToUpper() ?? string.Empty;
- RefreshList();
- }
-
-
- #region Add / Edit Qualifications
-
- private EmployeeQualificationShell _newshell;
-
- protected override void OnAppearing()
- {
- base.OnAppearing();
- if ((_newshell != null) && (_newshell.ID != Guid.Empty))
- {
- App.Data.EmployeeQualifications.CommitItem(_newshell);
- RefreshList();
- }
- _newshell = null;
- }
-
- // private void AddQualification(object sender, EventArgs e)
- // {
- // if ((sender as MobileMenuItem)?.BindingContext is QualificationShell shell)
- // {
- // _newshell = App.Data.EmployeeQualifications.CreateItem();
- // _newshell.QualificationID = shell.ID;
- // _newshell.EmployeeID = App.Data.Me.ID;
- // _newshell.Description = shell.Description;
- // EmployeeQualificationEditPage page = new EmployeeQualificationEditPage() { Item = _newshell };
- // Navigation.PushAsync(page);
- // }
- // }
-
- private void _qualification_Tapped(object sender, EventArgs e)
- {
- EmployeeQualificationShell shell = (sender as Frame)?.BindingContext as EmployeeQualificationShell;
- if (shell == null)
- return;
-
- EmployeeQualificationEditPage page = new EmployeeQualificationEditPage() { Item = shell };
- Navigation.PushAsync(page);
- }
-
- #endregion
- private void _add_OnClicked(object sender, MobileMenuButtonClickedEventArgs args)
- {
-
- ShowPopup(() => CreateQualificationSelection("Select Qualification", (shell) =>
- {
- _newshell = App.Data.EmployeeQualifications.CreateItem();
- _newshell.QualificationID = shell.ID;
- _newshell.EmployeeID = App.Data.Me.ID;
- _newshell.Description = shell.Description;
- EmployeeQualificationEditPage page = new EmployeeQualificationEditPage() { Item = _newshell };
- Navigation.PushAsync(page);
- }));
-
- }
-
-
- private View CreateQualificationSelection(String caption, Action<QualificationShell> selected)
- {
-
- QualificationModel _lookups = new QualificationModel(App.Data,
- LookupFactory.DefineFilter<Qualification>
- );
-
- SelectionView selection = new SelectionView
- {
- VerticalOptions = LayoutOptions.Fill,
- HorizontalOptions = LayoutOptions.Fill,
- CanSearch = true
- };
- selection.Configure += (sender, args) =>
- {
- args.Columns
- .BeginUpdate()
- .Clear()
- .Add(new MobileGridTextColumn<QualificationShell>() { Column = x=>x.Description, Width = GridLength.Star, Caption = caption, Alignment = TextAlignment.Center})
- .EndUpdate();
- args.Filters.AddRange(_lookups.AvailableFilters().Select(x=>x.Name));
- };
- selection.Refresh += (sender, args) => _lookups.Refresh(false);
- selection.SelectionChanged += (sender, args) =>
- {
- selected(args.SelectedItems.FirstOrDefault() as QualificationShell);
- DismissPopup();
- };
- selection.Load();
- return selection;
- }
-
- }
- }
|