123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- 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<string, Guid> fileNameIDs = new Dictionary<string, Guid>();
- //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<Equipment>(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<Kanban>().Query(
- // new Filter<Kanban>(x => x.Equipment.ID).IsEqualTo(Equipment.ID).
- // And(x => x.Closed).IsEqualTo(DateTime.MinValue),
- // new Columns<Kanban>(
- // 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<object> 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<EquipmentDocument>().Query
- // (
- // new Filter<EquipmentDocument>(x => x.EntityLink.ID).IsEqualTo(Equipment.ID),
- // new Columns<EquipmentDocument>(x => x.DocumentLink.ID, x => x.DocumentLink.FileName)
- // );
- // if (table.Rows.Any())
- // {
- // foreach (CoreRow row in table.Rows)
- // {
- // List<object> 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<String,Guid> filenames = new Dictionary<string, Guid>();
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- filenames = new Client<EquipmentDocument>().Query
- (
- new Filter<EquipmentDocument>(x => x.EntityLink.ID).IsEqualTo(DataModel.Items[0].ID),
- new Columns<EquipmentDocument>(x => x.DocumentLink.ID, x => x.DocumentLink.FileName)
- ).ToDictionary<EquipmentDocument, String, Guid>(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<KanbanForm>().Query(new Filter<KanbanForm>(x => x.Parent.ID).IsEqualTo(kanbanid));
- if (formTable.Rows.Any())
- {
- form = formTable.Rows.FirstOrDefault().ToObject<KanbanForm>();
- }
- if (form.ID == Guid.Empty)
- {
- DisplayAlert("Error", "No form found for this task - please check the task", "Cancel");
- return;
- }
- CoreTable table2 = new Client<DigitalFormLayout>().Query(
- new Filter<DigitalFormLayout>(x => x.Type).IsEqualTo(DFLayoutType.Mobile).And(x => x.Active).IsEqualTo(true).And(x => x.Form.Description).IsEqualTo(form.Form.Description),
- new Columns<DigitalFormLayout>(x => x.Description, x => x.ID, x => x.Code, x => x.Form.AppliesTo, x => x.Form.ID, x => x.Layout),
- new SortOrder<DigitalFormLayout>(x => x.Description)
- );
- if (table2.Rows.Any())
- {
- CoreRow row = table2.Rows.FirstOrDefault();
- DigitalFormLayout layout = row.ToObject<DigitalFormLayout>();
- }
- }
- }
- 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");
-
- }
- }
- }
|