123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using Comal.Classes;
- using InABox.Core;
- using Rb.Forms.Barcode.Pcl;
- using Xamarin.Forms;
- namespace comal.timesheets
- {
- public partial class BarcodeForm : ContentPage
- {
- public Guid JobID { get; set; }
- public double Latitude { get; set; }
- public double Longitude { get; set; }
- private DataTable Jobs = null;
- public BarcodeForm(DataTable jobs)
- {
- InitializeComponent();
- Jobs = jobs;
- MessagingCenter.Subscribe<App>(this, App.MessageOnSleep, disableScanner);
- MessagingCenter.Subscribe<App>(this, App.MessageOnResume, enableScanner);
- barcodeScanner.BarcodeChanged += animateFlash;
- }
- protected override void OnAppearing()
- {
- base.OnAppearing();
- enableScanner(this);
- }
- protected override void OnDisappearing()
- {
- disableScanner(this);
- base.OnDisappearing();
- }
- //public void DisableScanner()
- //{
- // disableScanner(null);
- //}
- private void disableScanner(object sender)
- {
- barcodeScanner.IsEnabled = false;
- }
- private void enableScanner(object sender)
- {
- barcodeScanner.IsEnabled = true;
- }
- private async Task ProcessBarcode(String barcode)
- {
- disableScanner(this);
- JobID = Guid.Empty;
- foreach (DataRow row in Jobs.Rows)
- {
- Guid jobid = row.Get<Job, Guid>(X => X.ID);
- if (jobid.ToString().Equals(barcode))
- {
- JobID = jobid;
- Latitude = row.Get<Job, double>(X => X.SiteAddress.Location.Latitude);
- Longitude = row.Get<Job, double>(X => X.SiteAddress.Location.Longitude);
- break;
- }
- }
- if (JobID != Guid.Empty)
- Navigation.PopAsync();
- else
- enableScanner(this);
- }
- private async void animateFlash(object sender, BarcodeEventArgs e)
- {
- Device.BeginInvokeOnMainThread(async () =>
- {
- await flash.FadeTo(1, 150, Easing.CubicInOut);
- flash.Opacity = 0;
- await ProcessBarcode(e.Barcode.Result);
- });
- }
- ~BarcodeForm()
- {
- disableScanner(this);
- MessagingCenter.Unsubscribe<App>(this, App.MessageOnSleep);
- MessagingCenter.Unsubscribe<App>(this, App.MessageOnResume);
- barcodeScanner.BarcodeChanged -= animateFlash;
- }
- }
- }
|