using comal.timesheets.QAForms; using Comal.Classes; using InABox.Clients; using InABox.Core; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using InABox.Mobile; using Xamarin.Forms; using Xamarin.Forms.Xaml; using XF.Material.Forms.UI.Dialogs; namespace comal.timesheets { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class EquipmentDetailsPage : ContentPage { //Equipment Equipment = new Equipment(); //Dictionary fileNameIDs = new Dictionary(); //int kanbanCount = 0; //bool bIsPreStartEquipment = false; //bool bPrestartRequired = false; //DateTime preStartDone = DateTime.MinValue; //Guid PreStartKanbanID = Guid.Empty; public EquipmentDetailsPage(Guid equipmentid) { InitializeComponent(); NavigationPage.SetHasBackButton(this, false); DataModel.Load( new Filter(x => x.ID).IsEqualTo(equipmentid) ); //RefreshScreen(); //CheckDocuments(); //CheckTasks(); var keytapper = new TapGestureRecognizer(); keytapper.Tapped += async (s, e) => { UnlockKey(); }; DigitalKey.GestureRecognizers.Add(keytapper); } protected override void OnAppearing() { base.OnAppearing(); App.Bluetooth.Disabled = true; } protected override void OnDisappearing() { App.Bluetooth.Disabled = false; base.OnDisappearing(); } private void BackBtn_Clicked(object sender, EventArgs e) { Navigation.PopAsync(); } // private void RefreshScreen() // { // Device.BeginInvokeOnMainThread(() => // { // //groupLbl.Text = Equipment.GroupLink.Description; // //descriptionLbl.Text = Equipment.Description; // //notesEdt.Text = Equipment.Notes; // //if (Equipment.SpecificationSheet.ID != Guid.Empty) // // specSheetBtn.IsEnabled = true; // // // { // // docsBtn.IsEnabled = true; // // docsBtn.Text = "View Documents (" + fileNameIDs.Count + ")"; // // } // // if (kanbanCount != 0) // // { // // viewTasksBtn.IsEnabled = true; // // } // // viewTasksBtn.Text = "View Tasks / History (" + kanbanCount + ")"; // // // if (bIsPreStartEquipment) // // { // // if (bPrestartRequired) // // { // // preStartBtn.IsEnabled = true; // // preStartBtn.Text = "Do Pre Start"; // // } // // else // // { // // preStartBtn.Text = "Pre Start Complete " + preStartDone.ToString("dd MMM yy"); // // preStartBtn.IsEnabled = false; // // } // // } // // else // // preStartFrame.IsEnabled = false; // // ForceLayout(); // // }); // } // private void CheckTasks() // { // Task.Run(() => // { // CoreTable table = new Client().Query( // new Filter(x => x.Equipment.ID).IsEqualTo(Equipment.ID). // And(x => x.Closed).IsEqualTo(DateTime.MinValue), // new Columns( // x => x.ID, // x => x.Type.ID, // x => x.Completed // )); // if (table.Rows.Any()) // { // kanbanCount = table.Rows.Count; // foreach (CoreRow row in table.Rows) // { // List list = row.Values; // if (list[0] == null) list[0] = Guid.Empty; // if (list[1] == null) list[1] = Guid.Empty; // if (list[2] == null) list[2] = DateTime.MinValue; // // if (Guid.Parse(list[1].ToString()) != Guid.Empty) // { // if (Guid.Parse(list[1].ToString()) == Guid.Parse("b8608b60-4afc-4b5b-8d94-e740a0c86f7c")) //PRE-START type task is present // { // bIsPreStartEquipment = true; // if (DateTime.Parse(list[2].ToString()) == DateTime.MinValue) // { // bPrestartRequired = true; // PreStartKanbanID = Guid.Parse(list[0].ToString()); // } // else if (DateTime.Parse(list[2].ToString()) > preStartDone) // { // preStartDone = DateTime.Parse(list[2].ToString()); // } // } // } // } // RefreshScreen(); // } // }); // } // // private void CheckDocuments() // { // Task.Run(() => // { // CoreTable table = new Client().Query // ( // new Filter(x => x.EntityLink.ID).IsEqualTo(Equipment.ID), // new Columns(x => x.DocumentLink.ID, x => x.DocumentLink.FileName) // ); // if (table.Rows.Any()) // { // foreach (CoreRow row in table.Rows) // { // List list = row.Values; // if (list[0] == null) list[0] = Guid.Empty; // if (list[1] == null) list[1] = ""; // Guid id = Guid.Parse(list[0].ToString()); // string filename = list[1].ToString(); // if (!string.IsNullOrWhiteSpace(filename) && id != Guid.Empty) // { // if (!fileNameIDs.ContainsKey(filename)) // fileNameIDs.Add(filename, id); // } // } // RefreshScreen(); // } // }); // } #region Button Presses private void ViewSpecSheetBtn_Clicked(object sender, EventArgs e) { PDFViewer viewer = new PDFViewer(DataModel.Items[0].SpecificationSheetID, true); Navigation.PushAsync(viewer); } private async void ViewDocsBtn_Clicked(object sender, EventArgs e) { Dictionary filenames = new Dictionary(); using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading")) { filenames = new Client().Query ( new Filter(x => x.EntityLink.ID).IsEqualTo(DataModel.Items[0].ID), new Columns(x => x.DocumentLink.ID, x => x.DocumentLink.FileName) ).ToDictionary(x => x.DocumentLink.FileName, x => x.DocumentLink.ID); } if (!filenames.Any()) { await DisplayAlert("Error", "No Documents Available", "OK"); return; } PDFList list = new PDFList(filenames, true); Navigation.PushAsync(list); } private void ViewTasksBtn_Clicked(object sender, EventArgs e) { EquipmentTasksList equipmentTasksList = new EquipmentTasksList(DataModel.Items[0].ID); Navigation.PushAsync(equipmentTasksList); } private async void EditOpenTask_Click(object sender, EventArgs e) { Guid? kanbanid = ((sender as Button)?.CommandParameter as EquipmentKanbanDataModelItem)?.ID; 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(); } } } private void DigitalFormsBtn_Clicked(object sender, EventArgs e) { } #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"); } } }