MyTimesheets.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using InABox.Mobile;
  2. using Xamarin.Forms;
  3. using Xamarin.Forms.Xaml;
  4. namespace PRS.Mobile
  5. {
  6. [XamlCompilation(XamlCompilationOptions.Compile)]
  7. public partial class MyTimesheets
  8. {
  9. public MyTimesheets()
  10. {
  11. InitializeComponent();
  12. TimeSheets.Columns
  13. .BeginUpdate()
  14. .Clear()
  15. .Add(new MobileGridDateColumn<TimeSheetShell>()
  16. { Column = x => x.Date, Format = "dd/MM/yy", Width = 80 })
  17. .Add(new MobileGridDateColumn<TimeSheetShell>()
  18. { Column = x => x.Date, Format = "dddd", Width = GridLength.Star })
  19. .Add(new MobileGridTimeColumn<TimeSheetShell>()
  20. { Column = x => x.Start, Width = GridLength.Auto })
  21. .Add(new MobileGridTimeColumn<TimeSheetShell>()
  22. { Column = x => x.Finish, Width = GridLength.Auto })
  23. .Add(new MobileGridImageColumn<TimeSheetShell>() { Column = x => x.Approved, Width = 30, Header=ImageSource.FromFile("tick"), Margin=6 })
  24. .EndUpdate();
  25. RefreshData(false,true);
  26. }
  27. private void RefreshData(bool force, bool async)
  28. {
  29. if (async)
  30. App.Data.TimeSheets.Refresh(force, () => Device.BeginInvokeOnMainThread(RefreshList));
  31. else
  32. {
  33. App.Data.TimeSheets.Refresh(force);
  34. RefreshList();
  35. }
  36. }
  37. private void RefreshList()
  38. {
  39. TimeSheets.ItemsSource ??= App.Data.TimeSheets.Items;
  40. }
  41. private void TimeSheets_OnRefreshRequested(object sender, MobileGridRefreshRequestArgs args)
  42. {
  43. RefreshData(true,false);
  44. }
  45. }
  46. }