NewForms.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 InABox.Mobile;
  8. using Xamarin.Forms;
  9. using Xamarin.Forms.Xaml;
  10. using XF.Material.Forms.UI;
  11. using XF.Material.Forms.UI.Dialogs;
  12. namespace PRS.Mobile
  13. {
  14. public class NewFormSelectedArgs : EventArgs
  15. {
  16. public DigitalFormShell Form { get; private set; }
  17. public NewFormSelectedArgs(DigitalFormShell form)
  18. {
  19. Form = form;
  20. }
  21. }
  22. public delegate void NewFormSelectedEvent(object sender, NewFormSelectedArgs args);
  23. [XamlCompilation(XamlCompilationOptions.Compile)]
  24. public partial class NewForms
  25. {
  26. private String _appliesTo = "";
  27. public String AppliesTo
  28. {
  29. get => _appliesTo;
  30. set
  31. {
  32. _appliesTo = value;
  33. RefreshData(false, true);
  34. }
  35. }
  36. public event NewFormSelectedEvent ItemSelected;
  37. private String _currentfilter = "";
  38. public NewForms()
  39. {
  40. InitializeComponent();
  41. }
  42. public void RefreshData(bool force, bool async)
  43. {
  44. if (async)
  45. App.Data.DigitalForms.Refresh(force, Refresh);
  46. else
  47. {
  48. App.Data.DigitalForms.Refresh(true);
  49. Refresh();
  50. }
  51. }
  52. private void Refresh()
  53. {
  54. App.Data.DigitalForms.Search((shell) => String.Equals(shell.AppliesTo, AppliesTo) && FilterShell(shell) );
  55. Dispatcher.BeginInvokeOnMainThread(
  56. () =>
  57. {
  58. _digitalforms.ItemsSource = App.Data.DigitalForms.Items;
  59. }
  60. );
  61. }
  62. private bool FilterShell(DigitalFormShell shell)
  63. {
  64. if (String.IsNullOrWhiteSpace(_currentfilter))
  65. return true;
  66. return shell.Code.ToUpper().Contains(_currentfilter.ToUpper())
  67. || shell.Description.ToUpper().Contains(_currentfilter.ToUpper());
  68. }
  69. private void _search_OnTextChanged(object sender, MobileSearchBarTextChangedArgs args)
  70. {
  71. _currentfilter = args.Text;
  72. Refresh();
  73. }
  74. private void _digitalforms_OnRefresh(object sender, MobileListRefreshEventArgs args)
  75. {
  76. RefreshData(true,false);
  77. }
  78. private void Form_Clicked(object sender, EventArgs e)
  79. {
  80. var shell = (sender as MobileCard)?.BindingContext as DigitalFormShell;
  81. ItemSelected?.Invoke(this, new NewFormSelectedArgs(shell));
  82. Navigation.PopAsync();
  83. }
  84. }
  85. }