BTInfoPage.xaml.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Xamarin.Forms;
  5. using Comal.Classes;
  6. using InABox.Core;
  7. using InABox.Clients;
  8. using System.Threading.Tasks;
  9. using XF.Material.Forms.UI.Dialogs;
  10. namespace comal.timesheets
  11. {
  12. public class EquipmentModel
  13. {
  14. public string ID { get; set; }
  15. public String Description { get; set; }
  16. }
  17. public partial class BTInfoPage : ContentPage
  18. {
  19. public BTInfoPage()
  20. {
  21. InitializeComponent();
  22. NavigationPage.SetHasBackButton(this, false);
  23. ToolbarItems.Clear();
  24. ToolbarItems.Add(new ToolbarItem("Back", "", () =>
  25. {
  26. Navigation.PopAsync();
  27. }));
  28. Title = "Site Equipment";
  29. TimeStamp.Text = String.Format("{0:dd/MM/yy hh:mm:ss tt}", App.Bluetooth,TimeStamp);
  30. }
  31. protected override async void OnAppearing()
  32. {
  33. base.OnAppearing();
  34. await LoadData();
  35. }
  36. private async Task LoadData()
  37. {
  38. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading Data"))
  39. {
  40. List<EquipmentModel> equipmodels = new List<EquipmentModel>();
  41. CoreTable trackers = new Client<GPSTracker>().Query(null, new Columns<GPSTracker>(x => x.ID, x => x.DeviceID), null);
  42. CoreTable equip = new Client<Equipment>().Query(
  43. new Filter<Equipment>(x => x.TrackerLink.ID).IsNotEqualTo(Guid.Empty),
  44. new Columns<Equipment>(x => x.TrackerLink.ID, x => x.Code, x => x.Description),
  45. new SortOrder<Equipment>(x => x.Code)
  46. );
  47. if (App.Bluetooth.Devices != null)
  48. {
  49. foreach (String id in App.Bluetooth.Devices)
  50. //foreach (DataRow tracker in trackers.Rows)
  51. {
  52. CoreRow tracker = trackers.Rows.FirstOrDefault(r => r.Get<GPSTrackerLocation, String>(x => x.DeviceID) == id);
  53. if (tracker != null)
  54. {
  55. EquipmentModel model = new EquipmentModel()
  56. {
  57. ID = id,
  58. Description = "Unallocated"
  59. };
  60. CoreRow equiprow = equip.Rows.FirstOrDefault(r => r.Get<Equipment, Guid>(x => x.TrackerLink.ID) == tracker.Get<GPSTracker, Guid>(x => x.ID));
  61. if (equiprow != null)
  62. model.Description = equiprow.Get<Equipment, String>(x => x.Description);
  63. equipmodels.Add(model);
  64. }
  65. }
  66. }
  67. Device.BeginInvokeOnMainThread(
  68. () =>
  69. {
  70. EquipList.ItemsSource = null;
  71. EquipList.ItemsSource = equipmodels;
  72. }
  73. );
  74. }
  75. }
  76. }
  77. }