HumanResourcesModule.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using Comal.Classes.SecurityDescriptors;
  5. using InABox.Core;
  6. using InABox.Mobile;
  7. using Xamarin.Forms.Xaml;
  8. namespace PRS.Mobile
  9. {
  10. [XamlCompilation(XamlCompilationOptions.Compile)]
  11. public partial class HumanResourcesModule
  12. {
  13. private CancellationTokenSource _pollingToken;
  14. public HumanResourcesModule()
  15. {
  16. InitializeComponent();
  17. MyDetails.IsVisible = Security.IsAllowed<ViewMobileEmployeeDetailsModule>();
  18. DigitalForms.IsVisible = Security.IsAllowed<ViewMobileEmployeeFormsModule>();
  19. LeaveRequests.IsVisible = Security.IsAllowed<ViewMobileLeaveRequestsModule>();
  20. Qualifications.IsVisible = Security.IsAllowed<ViewMobileQualificationsModule>();
  21. TimeSheets.IsVisible = Security.IsAllowed<ViewMobileTimesheetsModule>();
  22. }
  23. protected override void OnAppearing()
  24. {
  25. _pollingToken = new CancellationTokenSource();
  26. StartMonitoringQualifications();
  27. StartMonitoringForms();
  28. base.OnAppearing();
  29. }
  30. protected override void OnDisappearing()
  31. {
  32. base.OnDisappearing();
  33. _pollingToken.Cancel();
  34. }
  35. private void StartMonitoringQualifications()
  36. {
  37. var token = _pollingToken.Token;
  38. Task.Run(() =>
  39. {
  40. while (!_pollingToken.Token.IsCancellationRequested)
  41. {
  42. App.Data.EmployeeQualifications.Refresh(true);
  43. Dispatcher.BeginInvokeOnMainThread(() =>
  44. {
  45. Qualifications.Alert = App.Data.EmployeeQualifications.NeedsAttention > 0
  46. ? App.Data.EmployeeQualifications.NeedsAttention.ToString()
  47. : "";
  48. });
  49. Task.Delay(TimeSpan.FromSeconds(30), token)
  50. .Wait(token);
  51. }
  52. },
  53. token
  54. );
  55. }
  56. private void StartMonitoringForms()
  57. {
  58. var token = _pollingToken.Token;
  59. Task.Run(() =>
  60. {
  61. while (!_pollingToken.Token.IsCancellationRequested)
  62. {
  63. App.Data.EmployeeForms.Refresh(true);
  64. Dispatcher.BeginInvokeOnMainThread(() =>
  65. {
  66. DigitalForms.Alert = App.Data.EmployeeForms.NeedsAttention > 0
  67. ? App.Data.EmployeeForms.NeedsAttention.ToString()
  68. : "";
  69. });
  70. Task.Delay(TimeSpan.FromSeconds(30), token)
  71. .Wait(token);
  72. }
  73. },
  74. token
  75. );
  76. }
  77. private void MyDetails_OnTapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
  78. {
  79. Navigation.PushAsync(new MyDetailsPage());
  80. }
  81. private void QualificationsBtn_Tapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
  82. {
  83. Navigation.PushAsync(new EmployeeQualificationList());
  84. }
  85. private void EmployeeFormsBtn_Tapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
  86. {
  87. Navigation.PushAsync(new EmployeeForms());
  88. }
  89. private void LeaveBtn_Tapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
  90. {
  91. Navigation.PushAsync(new LeaveRequestList());
  92. }
  93. private void TimesheetsBtn_Tapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
  94. {
  95. Navigation.PushAsync(new MyTimesheets());
  96. }
  97. }
  98. }