using Comal.Classes; using InABox.Clients; using InABox.Core; using System; using System.Collections.Generic; using System.Linq; using Xamarin.Forms; using Xamarin.Forms.Xaml; using XF.Material.Forms.UI.Dialogs; namespace comal.timesheets { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class EquipmentDetailsPage : BasePage { private EquipmentDetailModel _model = null; public EquipmentDetailsPage(Guid equipmentid) { InitializeComponent(); _model = new EquipmentDetailModel(App.Data, () => new Filter(x => x.ID).IsEqualTo(equipmentid) , $"{equipmentid}.equipment"); _model.Load(() => BindingContext = _model); } public EquipmentDetailsPage(EquipmentDetailModel model) { _model = model; InitializeComponent(); BindingContext = model; } protected override void OnAppearing() { base.OnAppearing(); App.Bluetooth.Disabled = true; } protected override void OnDisappearing() { App.Bluetooth.Disabled = false; base.OnDisappearing(); } #region Button Presses private void ViewSpecificationSheet_Clicked(object sender, EventArgs e) { ImageViewer viewer = new ImageViewer(_model.Item.SpecificationSheet); Navigation.PushAsync(viewer); } private void ViewDocsBtn_Clicked(object sender, EventArgs e) { PDFList list = new PDFList() { Documents = _model.Documents, AllowPrintShare = true}; Navigation.PushAsync(list); } private void ViewTasksBtn_Clicked(object sender, EventArgs e) { EquipmentTasksList equipmentTasksList = new EquipmentTasksList() { Equipment = _model }; Navigation.PushAsync(equipmentTasksList); } private async void EditOpenTask_Click(object sender, EventArgs e) { Guid? kanbanid = ((sender as Button)?.CommandParameter as EquipmentKanbanShell)?.KanbanID; if (!kanbanid.HasValue) { await DisplayAlert("Error", "Cannot Find Kanban ID", "OK"); return; } using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading")) { KanbanForm form = new KanbanForm(); CoreTable formTable = new Client().Query(new Filter(x => x.Parent.ID).IsEqualTo(kanbanid)); if (formTable.Rows.Any()) { form = formTable.Rows.FirstOrDefault().ToObject(); } if (form.ID == Guid.Empty) { DisplayAlert("Error", "No form found for this task - please check the task", "Cancel"); return; } CoreTable table2 = new Client().Query( new Filter(x => x.Type).IsEqualTo(DFLayoutType.Mobile).And(x => x.Active).IsEqualTo(true).And(x => x.Form.Description).IsEqualTo(form.Form.Description), new Columns(x => x.Description, x => x.ID, x => x.Code, x => x.Form.AppliesTo, x => x.Form.ID, x => x.Layout), new SortOrder(x => x.Description) ); if (table2.Rows.Any()) { CoreRow row = table2.Rows.FirstOrDefault(); DigitalFormLayout layout = row.ToObject(); } } } #endregion private async void UnlockKey() { String error = ""; using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Please Wait...")) { String macaddress = "84:CC:A8:2E:95:8A"; Guid service = Guid.Parse("7555408C-9414-EB46-C0AC-A72EB4CD80D8"); Guid characteristic = Guid.Parse("432B917A-EB17-289B-285A-2657419B46C7"); String key = "9ffe2145-f6c7-4f84-8908-d7003f237fe5"; try { await App.Bluetooth.UnlockDigitalKey( macaddress, service, characteristic, key ); } catch (Exception e) { error = e.Message; } } if (!String.IsNullOrWhiteSpace(error)) await DisplayAlert("Error Unlocking Device!", error, "OK"); } private async void DigitalKey_Tapped(object sender, EventArgs e) { UnlockKey(); } } }