TimeSheetNotePage.xaml.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using InABox.Core;
  4. using Xamarin.Forms;
  5. using InABox.Clients;
  6. using Comal.Classes;
  7. using System.Threading.Tasks;
  8. using System.Linq;
  9. using InABox.Mobile;
  10. namespace PRS.Mobile
  11. {
  12. public partial class TimeSheetNotePage
  13. {
  14. TimeSheet timeSheet = new TimeSheet();
  15. protected void SaveTimeSheetCallback(TimeSheet entity, Exception e)
  16. {
  17. if (e != null)
  18. Device.BeginInvokeOnMainThread(() => { DisplayAlert("Error Adding Note", "Unable to Save Note\n\n" + e.Message, "OK"); });
  19. }
  20. public TimeSheetNotePage(TimeSheet _timeSheet)
  21. {
  22. InitializeComponent();
  23. timeSheet = _timeSheet;
  24. notesLbl.Text = _timeSheet.Notes;
  25. notesLbl.IsVisible = !String.IsNullOrWhiteSpace(_timeSheet.Notes);
  26. notesSeparator.IsVisible = !String.IsNullOrWhiteSpace(_timeSheet.Notes);
  27. }
  28. private void SaveNewNotes()
  29. {
  30. try
  31. {
  32. string prevNotes = String.IsNullOrWhiteSpace(notesLbl.Text)
  33. ? ""
  34. : notesLbl.Text.EndsWith("\n")
  35. ? notesLbl.Text
  36. : $"{notesLbl.Text}\n";
  37. if (!string.IsNullOrWhiteSpace(notesEdt.Text))
  38. {
  39. timeSheet.Notes =
  40. $"{prevNotes}{DateTime.Now:yy-MM-dd HH:mm} {App.Data.Me.Code}: {notesEdt.Text}";
  41. new Client<TimeSheet>().Save(timeSheet, "Updated Note from Mobile");
  42. DisplayAlert("Success", "Note Saved", "OK");
  43. }
  44. }
  45. catch { }
  46. }
  47. private void Save_Clicked(object sender, MobileMenuButtonClickedEventArgs args)
  48. {
  49. SaveNewNotes();
  50. Navigation.PopAsync();
  51. }
  52. }
  53. }