EquipmentDetailsPage.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. using comal.timesheets.QAForms;
  2. using Comal.Classes;
  3. using InABox.Clients;
  4. using InABox.Core;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using InABox.Mobile;
  11. using Xamarin.Forms;
  12. using Xamarin.Forms.Xaml;
  13. using XF.Material.Forms.UI.Dialogs;
  14. namespace comal.timesheets
  15. {
  16. [XamlCompilation(XamlCompilationOptions.Compile)]
  17. public partial class EquipmentDetailsPage : ContentPage
  18. {
  19. //Equipment Equipment = new Equipment();
  20. //Dictionary<string, Guid> fileNameIDs = new Dictionary<string, Guid>();
  21. //int kanbanCount = 0;
  22. //bool bIsPreStartEquipment = false;
  23. //bool bPrestartRequired = false;
  24. //DateTime preStartDone = DateTime.MinValue;
  25. //Guid PreStartKanbanID = Guid.Empty;
  26. public EquipmentDetailsPage(Guid equipmentid)
  27. {
  28. InitializeComponent();
  29. NavigationPage.SetHasBackButton(this, false);
  30. DataModel.Load(
  31. new Filter<Equipment>(x => x.ID).IsEqualTo(equipmentid)
  32. );
  33. //RefreshScreen();
  34. //CheckDocuments();
  35. //CheckTasks();
  36. var keytapper = new TapGestureRecognizer();
  37. keytapper.Tapped += async (s, e) =>
  38. {
  39. UnlockKey();
  40. };
  41. DigitalKey.GestureRecognizers.Add(keytapper);
  42. }
  43. protected override void OnAppearing()
  44. {
  45. base.OnAppearing();
  46. App.Bluetooth.Disabled = true;
  47. }
  48. protected override void OnDisappearing()
  49. {
  50. App.Bluetooth.Disabled = false;
  51. base.OnDisappearing();
  52. }
  53. private void BackBtn_Clicked(object sender, EventArgs e)
  54. {
  55. Navigation.PopAsync();
  56. }
  57. // private void RefreshScreen()
  58. // {
  59. // Device.BeginInvokeOnMainThread(() =>
  60. // {
  61. // //groupLbl.Text = Equipment.GroupLink.Description;
  62. // //descriptionLbl.Text = Equipment.Description;
  63. // //notesEdt.Text = Equipment.Notes;
  64. // //if (Equipment.SpecificationSheet.ID != Guid.Empty)
  65. // // specSheetBtn.IsEnabled = true;
  66. //
  67. // // {
  68. // // docsBtn.IsEnabled = true;
  69. // // docsBtn.Text = "View Documents (" + fileNameIDs.Count + ")";
  70. // // }
  71. // // if (kanbanCount != 0)
  72. // // {
  73. // // viewTasksBtn.IsEnabled = true;
  74. // // }
  75. // // viewTasksBtn.Text = "View Tasks / History (" + kanbanCount + ")";
  76. //
  77. // // if (bIsPreStartEquipment)
  78. // // {
  79. // // if (bPrestartRequired)
  80. // // {
  81. // // preStartBtn.IsEnabled = true;
  82. // // preStartBtn.Text = "Do Pre Start";
  83. // // }
  84. // // else
  85. // // {
  86. // // preStartBtn.Text = "Pre Start Complete " + preStartDone.ToString("dd MMM yy");
  87. // // preStartBtn.IsEnabled = false;
  88. // // }
  89. // // }
  90. // // else
  91. // // preStartFrame.IsEnabled = false;
  92. //
  93. // ForceLayout();
  94. //
  95. // });
  96. // }
  97. // private void CheckTasks()
  98. // {
  99. // Task.Run(() =>
  100. // {
  101. // CoreTable table = new Client<Kanban>().Query(
  102. // new Filter<Kanban>(x => x.Equipment.ID).IsEqualTo(Equipment.ID).
  103. // And(x => x.Closed).IsEqualTo(DateTime.MinValue),
  104. // new Columns<Kanban>(
  105. // x => x.ID,
  106. // x => x.Type.ID,
  107. // x => x.Completed
  108. // ));
  109. // if (table.Rows.Any())
  110. // {
  111. // kanbanCount = table.Rows.Count;
  112. // foreach (CoreRow row in table.Rows)
  113. // {
  114. // List<object> list = row.Values;
  115. // if (list[0] == null) list[0] = Guid.Empty;
  116. // if (list[1] == null) list[1] = Guid.Empty;
  117. // if (list[2] == null) list[2] = DateTime.MinValue;
  118. //
  119. // if (Guid.Parse(list[1].ToString()) != Guid.Empty)
  120. // {
  121. // if (Guid.Parse(list[1].ToString()) == Guid.Parse("b8608b60-4afc-4b5b-8d94-e740a0c86f7c")) //PRE-START type task is present
  122. // {
  123. // bIsPreStartEquipment = true;
  124. // if (DateTime.Parse(list[2].ToString()) == DateTime.MinValue)
  125. // {
  126. // bPrestartRequired = true;
  127. // PreStartKanbanID = Guid.Parse(list[0].ToString());
  128. // }
  129. // else if (DateTime.Parse(list[2].ToString()) > preStartDone)
  130. // {
  131. // preStartDone = DateTime.Parse(list[2].ToString());
  132. // }
  133. // }
  134. // }
  135. // }
  136. // RefreshScreen();
  137. // }
  138. // });
  139. // }
  140. //
  141. // private void CheckDocuments()
  142. // {
  143. // Task.Run(() =>
  144. // {
  145. // CoreTable table = new Client<EquipmentDocument>().Query
  146. // (
  147. // new Filter<EquipmentDocument>(x => x.EntityLink.ID).IsEqualTo(Equipment.ID),
  148. // new Columns<EquipmentDocument>(x => x.DocumentLink.ID, x => x.DocumentLink.FileName)
  149. // );
  150. // if (table.Rows.Any())
  151. // {
  152. // foreach (CoreRow row in table.Rows)
  153. // {
  154. // List<object> list = row.Values;
  155. // if (list[0] == null) list[0] = Guid.Empty;
  156. // if (list[1] == null) list[1] = "";
  157. // Guid id = Guid.Parse(list[0].ToString());
  158. // string filename = list[1].ToString();
  159. // if (!string.IsNullOrWhiteSpace(filename) && id != Guid.Empty)
  160. // {
  161. // if (!fileNameIDs.ContainsKey(filename))
  162. // fileNameIDs.Add(filename, id);
  163. // }
  164. // }
  165. // RefreshScreen();
  166. // }
  167. // });
  168. // }
  169. #region Button Presses
  170. private void ViewSpecSheetBtn_Clicked(object sender, EventArgs e)
  171. {
  172. PDFViewer viewer = new PDFViewer(DataModel.Items[0].SpecificationSheetID, true);
  173. Navigation.PushAsync(viewer);
  174. }
  175. private async void ViewDocsBtn_Clicked(object sender, EventArgs e)
  176. {
  177. Dictionary<String,Guid> filenames = new Dictionary<string, Guid>();
  178. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  179. {
  180. filenames = new Client<EquipmentDocument>().Query
  181. (
  182. new Filter<EquipmentDocument>(x => x.EntityLink.ID).IsEqualTo(DataModel.Items[0].ID),
  183. new Columns<EquipmentDocument>(x => x.DocumentLink.ID, x => x.DocumentLink.FileName)
  184. ).ToDictionary<EquipmentDocument, String, Guid>(x => x.DocumentLink.FileName, x => x.DocumentLink.ID);
  185. }
  186. if (!filenames.Any())
  187. {
  188. await DisplayAlert("Error", "No Documents Available", "OK");
  189. return;
  190. }
  191. PDFList list = new PDFList(filenames, true);
  192. Navigation.PushAsync(list);
  193. }
  194. private void ViewTasksBtn_Clicked(object sender, EventArgs e)
  195. {
  196. EquipmentTasksList equipmentTasksList = new EquipmentTasksList(DataModel.Items[0].ID);
  197. Navigation.PushAsync(equipmentTasksList);
  198. }
  199. private async void EditOpenTask_Click(object sender, EventArgs e)
  200. {
  201. Guid? kanbanid = ((sender as Button)?.CommandParameter as EquipmentKanbanDataModelItem)?.ID;
  202. if (!kanbanid.HasValue)
  203. {
  204. await DisplayAlert("Error", "Cannot Find Kanban ID", "OK");
  205. return;
  206. }
  207. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  208. {
  209. KanbanForm form = new KanbanForm();
  210. CoreTable formTable = new Client<KanbanForm>().Query(new Filter<KanbanForm>(x => x.Parent.ID).IsEqualTo(kanbanid));
  211. if (formTable.Rows.Any())
  212. {
  213. form = formTable.Rows.FirstOrDefault().ToObject<KanbanForm>();
  214. }
  215. if (form.ID == Guid.Empty)
  216. {
  217. DisplayAlert("Error", "No form found for this task - please check the task", "Cancel");
  218. return;
  219. }
  220. CoreTable table2 = new Client<DigitalFormLayout>().Query(
  221. new Filter<DigitalFormLayout>(x => x.Type).IsEqualTo(DFLayoutType.Mobile).And(x => x.Active).IsEqualTo(true).And(x => x.Form.Description).IsEqualTo(form.Form.Description),
  222. new Columns<DigitalFormLayout>(x => x.Description, x => x.ID, x => x.Code, x => x.Form.AppliesTo, x => x.Form.ID, x => x.Layout),
  223. new SortOrder<DigitalFormLayout>(x => x.Description)
  224. );
  225. if (table2.Rows.Any())
  226. {
  227. CoreRow row = table2.Rows.FirstOrDefault();
  228. DigitalFormLayout layout = row.ToObject<DigitalFormLayout>();
  229. }
  230. }
  231. }
  232. private void DigitalFormsBtn_Clicked(object sender, EventArgs e)
  233. {
  234. }
  235. #endregion
  236. private async void UnlockKey()
  237. {
  238. String error = "";
  239. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Please Wait..."))
  240. {
  241. String macaddress = "84:CC:A8:2E:95:8A";
  242. Guid service = Guid.Parse("7555408C-9414-EB46-C0AC-A72EB4CD80D8");
  243. Guid characteristic = Guid.Parse("432B917A-EB17-289B-285A-2657419B46C7");
  244. String key = "9ffe2145-f6c7-4f84-8908-d7003f237fe5";
  245. try
  246. {
  247. await App.Bluetooth.UnlockDigitalKey(
  248. macaddress,
  249. service,
  250. characteristic,
  251. key
  252. );
  253. }
  254. catch (Exception e)
  255. {
  256. error = e.Message;
  257. }
  258. }
  259. if (!String.IsNullOrWhiteSpace(error))
  260. await DisplayAlert("Error Unlocking Device!", error, "OK");
  261. }
  262. }
  263. }