NewForms.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Windows.Input;
  7. using Xamarin.Forms;
  8. using Xamarin.Forms.Xaml;
  9. using XF.Material.Forms.UI.Dialogs;
  10. namespace comal.timesheets
  11. {
  12. public class NewFormSelectedArgs : EventArgs
  13. {
  14. }
  15. public delegate void NewFormSelectedEvent(object sender, NewFormSelectedArgs args);
  16. [XamlCompilation(XamlCompilationOptions.Compile)]
  17. public partial class NewForms
  18. {
  19. private String _appliesTo = "";
  20. public String AppliesTo
  21. {
  22. get => _appliesTo;
  23. set
  24. {
  25. _appliesTo = value;
  26. RefreshData(false, true);
  27. }
  28. }
  29. public event NewFormSelectedEvent ItemSelected;
  30. private String _currentfilter = "";
  31. public NewForms()
  32. {
  33. InitializeComponent();
  34. }
  35. public void RefreshData(bool force, bool async)
  36. {
  37. if (async)
  38. App.Data.DigitalForms.Refresh(force, Refresh);
  39. else
  40. {
  41. App.Data.DigitalForms.Refresh(true);
  42. Refresh();
  43. }
  44. }
  45. private void Refresh()
  46. {
  47. App.Data.DigitalForms.Search((shell) => String.Equals(shell.AppliesTo, AppliesTo) && FilterShell(shell) );
  48. _digitalforms.ItemsSource = App.Data.DigitalForms.Items;
  49. }
  50. private bool FilterShell(DigitalFormShell shell)
  51. {
  52. if (String.IsNullOrWhiteSpace(_currentfilter))
  53. return true;
  54. return shell.Code.ToUpper().Contains(_currentfilter.ToUpper())
  55. || shell.Description.ToUpper().Contains(_currentfilter.ToUpper());
  56. }
  57. private void _search_OnTextChanged(object sender, MobileSearchBarTextChangedArgs args)
  58. {
  59. _currentfilter = args.Text;
  60. Refresh();
  61. }
  62. private void _digitalforms_OnRefresh(object sender, MobileListRefreshEventArgs args)
  63. {
  64. RefreshData(true,false);
  65. }
  66. private async void _digitalforms_OnItemTapped(object sender, MobileListItemTappedEventArgs args)
  67. {
  68. ItemSelected?.Invoke(this, new NewFormSelectedArgs());
  69. Navigation.PopAsync();
  70. }
  71. }
  72. }