EquipmentDetailsPage.xaml.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using Comal.Classes;
  2. using InABox.Clients;
  3. using InABox.Core;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using Xamarin.Forms;
  8. using Xamarin.Forms.Xaml;
  9. using XF.Material.Forms.UI.Dialogs;
  10. namespace comal.timesheets
  11. {
  12. [XamlCompilation(XamlCompilationOptions.Compile)]
  13. public partial class EquipmentDetailsPage : BasePage
  14. {
  15. private EquipmentDetailModel _model = null;
  16. public EquipmentDetailsPage(Guid equipmentid)
  17. {
  18. InitializeComponent();
  19. _model = new EquipmentDetailModel(App.Data,
  20. () => new Filter<Equipment>(x => x.ID).IsEqualTo(equipmentid)
  21. , $"{equipmentid}.equipment");
  22. _model.Load(() => BindingContext = _model);
  23. }
  24. public EquipmentDetailsPage(EquipmentDetailModel model)
  25. {
  26. _model = model;
  27. InitializeComponent();
  28. BindingContext = model;
  29. }
  30. protected override void OnAppearing()
  31. {
  32. base.OnAppearing();
  33. App.Bluetooth.Disabled = true;
  34. }
  35. protected override void OnDisappearing()
  36. {
  37. App.Bluetooth.Disabled = false;
  38. base.OnDisappearing();
  39. }
  40. #region Button Presses
  41. private void ViewSpecificationSheet_Clicked(object sender, EventArgs e)
  42. {
  43. ImageViewer viewer = new ImageViewer(_model.Item.SpecificationSheet);
  44. Navigation.PushAsync(viewer);
  45. }
  46. private void ViewDocsBtn_Clicked(object sender, EventArgs e)
  47. {
  48. PDFList list = new PDFList() { Documents = _model.Documents, AllowPrintShare = true};
  49. Navigation.PushAsync(list);
  50. }
  51. private void ViewTasksBtn_Clicked(object sender, EventArgs e)
  52. {
  53. EquipmentTasksList equipmentTasksList = new EquipmentTasksList()
  54. {
  55. Equipment = _model
  56. };
  57. Navigation.PushAsync(equipmentTasksList);
  58. }
  59. private async void EditOpenTask_Click(object sender, EventArgs e)
  60. {
  61. Guid? kanbanid = ((sender as Button)?.CommandParameter as EquipmentKanbanShell)?.KanbanID;
  62. if (!kanbanid.HasValue)
  63. {
  64. await DisplayAlert("Error", "Cannot Find Kanban ID", "OK");
  65. return;
  66. }
  67. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  68. {
  69. KanbanForm form = new KanbanForm();
  70. CoreTable formTable = new Client<KanbanForm>().Query(new Filter<KanbanForm>(x => x.Parent.ID).IsEqualTo(kanbanid));
  71. if (formTable.Rows.Any())
  72. {
  73. form = formTable.Rows.FirstOrDefault().ToObject<KanbanForm>();
  74. }
  75. if (form.ID == Guid.Empty)
  76. {
  77. DisplayAlert("Error", "No form found for this task - please check the task", "Cancel");
  78. return;
  79. }
  80. CoreTable table2 = new Client<DigitalFormLayout>().Query(
  81. new Filter<DigitalFormLayout>(x => x.Type).IsEqualTo(DFLayoutType.Mobile).And(x => x.Active).IsEqualTo(true).And(x => x.Form.Description).IsEqualTo(form.Form.Description),
  82. new Columns<DigitalFormLayout>(x => x.Description, x => x.ID, x => x.Code, x => x.Form.AppliesTo, x => x.Form.ID, x => x.Layout),
  83. new SortOrder<DigitalFormLayout>(x => x.Description)
  84. );
  85. if (table2.Rows.Any())
  86. {
  87. CoreRow row = table2.Rows.FirstOrDefault();
  88. DigitalFormLayout layout = row.ToObject<DigitalFormLayout>();
  89. }
  90. }
  91. }
  92. #endregion
  93. private async void UnlockKey()
  94. {
  95. String error = "";
  96. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Please Wait..."))
  97. {
  98. String macaddress = "84:CC:A8:2E:95:8A";
  99. Guid service = Guid.Parse("7555408C-9414-EB46-C0AC-A72EB4CD80D8");
  100. Guid characteristic = Guid.Parse("432B917A-EB17-289B-285A-2657419B46C7");
  101. String key = "9ffe2145-f6c7-4f84-8908-d7003f237fe5";
  102. try
  103. {
  104. await App.Bluetooth.UnlockDigitalKey(
  105. macaddress,
  106. service,
  107. characteristic,
  108. key
  109. );
  110. }
  111. catch (Exception e)
  112. {
  113. error = e.Message;
  114. }
  115. }
  116. if (!String.IsNullOrWhiteSpace(error))
  117. await DisplayAlert("Error Unlocking Device!", error, "OK");
  118. }
  119. private async void DigitalKey_Tapped(object sender, EventArgs e)
  120. {
  121. UnlockKey();
  122. }
  123. }
  124. }