Example #1
0
        public Reader()
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                Title = "PilavScan";
            });
            BackgroundColor = Color.FromHex("#3498db");
            sPage           = new ZXingScannerPage(new MobileBarcodeScanningOptions
            {
                AutoRotate      = true,
                PossibleFormats = new List <BarcodeFormat>
                {
                    BarcodeFormat.QR_CODE,
                    BarcodeFormat.AZTEC
                },
                UseFrontCameraIfAvailable = false,
                UseNativeScanning         = true
            });

            sPage.ToggleTorch();
            sPage.OnScanResult += SPage_OnScanResult;

            Button scanButton = new Button
            {
                Text            = "Tara",
                TextColor       = Color.FromHex("#bdc3c7"),
                AutomationId    = "scanContinuously",
                BackgroundColor = Color.FromHex("#2c3e50")
            };
            Button generateButton = new Button
            {
                Text            = "Oluştur",
                TextColor       = Color.FromHex("#bdc3c7"),
                AutomationId    = "barcodeGenerator",
                BackgroundColor = Color.FromHex("#2c3e50")
            };
            Label bilgi = new Label
            {
                Text              = "Özhan YILDIZ",
                VerticalOptions   = LayoutOptions.EndAndExpand,
                HorizontalOptions = LayoutOptions.EndAndExpand,
                FontSize          = 25,
                TextColor         = Color.FromHex("#bdc3c7")
            };



            generateButton.Clicked += GenerateButton_Clicked;

            scanButton.Clicked += ScanButton_Clicked;

            var stack = new StackLayout();

            stack.Children.Add(scanButton);
            stack.Children.Add(generateButton);
            stack.Children.Add(bilgi);
            stack.BackgroundColor = Color.FromHex("#34495e");

            Content = stack;
        }
Example #2
0
        /// <summary>
        /// Scan with custom overlay
        /// </summary>
        private async void CustomOverlayButton_Clicked(object sender, EventArgs e)
        {
            // Create our custom overlay
            var customOverlay = new StackLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };
            var torch = new Button
            {
                Text = "Toggle Torch"
            };

            torch.Clicked += delegate {
                scanPage.ToggleTorch();
            };
            customOverlay.Children.Add(torch);

            scanPage = new ZXingScannerPage(new ZXing.Mobile.MobileBarcodeScanningOptions {
                AutoRotate = true
            }, customOverlay: customOverlay);
            scanPage.OnScanResult += (result) => {
                scanPage.IsScanning = false;

                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PopAsync();
                    DisplayAlert("Scanned Barcode", result.Text, "OK");
                });
            };
            await Navigation.PushAsync(scanPage);
        }
Example #3
0
        async void OnButtonClickedCapture(object sender, EventArgs args)
        {
            // Create our custom overlay
            var customOverlay = new StackLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };
            var torch = new Button
            {
                Text = "Toggle Torch"
            };

            customOverlay.Children.Add(torch);

            //setup options
            var options = new MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                UseFrontCameraIfAvailable = false,
                TryHarder       = true,
                PossibleFormats = new List <ZXing.BarcodeFormat>
                {
                    ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
                    //ZXing.BarcodeFormat.CODE_128, ZXing.BarcodeFormat.CODE_39
                }
            };

            //add options and customize page
            var scanPage = new ZXingScannerPage(options)
            {
                DefaultOverlayTopText         = "Align the barcode within the frame",
                DefaultOverlayBottomText      = string.Empty,
                DefaultOverlayShowFlashButton = true
            };

            torch.Clicked += delegate
            {
                scanPage.ToggleTorch();
            };
            scanPage.OnScanResult += (result) =>
            {
                // Stop scanning
                scanPage.IsScanning = false;

                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopModalAsync();
                    await DisplayAlert("Scanned Barcode", result.Text, "OK");
                    model.BarCode = result.Text;
                });
            };
            // Navigate to our scanner page
            await Navigation.PushModalAsync(scanPage);
        }
Example #4
0
        async Task NavigateToScannerpage()
        {
            //setup Scanner options
            MobileBarcodeScanningOptions options = new MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                UseFrontCameraIfAvailable = false,
                TryHarder = true,
                DelayBetweenContinuousScans = 10000,
                DisableAutofocus            = false
            };

            var overlay = new ZXingDefaultOverlay
            {
                ShowFlashButton = true,
                TopText         = "Hold your phone up to the barcode",
                BottomText      = "Scanning will happen automatically"
            };

            overlay.BindingContext = overlay;
            ZXingScannerPage scanPage = new ZXingScannerPage(options, overlay)
            {
                HasTorch  = true,
                IsTorchOn = false
            };

#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
            overlay.FlashButtonClicked += async(sender, e) =>
            {
#pragma warning restore CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
                scanPage.ToggleTorch();
            };

            scanPage.OnScanResult += (result) =>
            {
                // Stop scanning
                scanPage.IsScanning = false;
                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync();

                    if (result != null && !string.IsNullOrWhiteSpace(result.Text))
                    {
                        Process(result.Text);
                        //_application.mqttHelper.PublishMQTT(result.Text, "BarcodeDEMOXacti");
                    }
                });
            };
            // Navigate to our scanner page
            await Navigation.PushAsync(scanPage);
        }
Example #5
0
        async Task NavigateToScannerpage()
        {
            //setup Scanner options
            MobileBarcodeScanningOptions options = new MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                UseFrontCameraIfAvailable = false,
                TryHarder = true,
                DelayBetweenContinuousScans = 10000,
                DisableAutofocus            = false
            };

            var overlay = new ZXingDefaultOverlay
            {
                ShowFlashButton = true,
                TopText         = "Scan Barcode",
                BottomText      = "Scanning will happen automatically",
            };

            overlay.BindingContext = overlay;
            ZXingScannerPage scanPage = new ZXingScannerPage(options, overlay)
            {
                HasTorch  = true,
                IsTorchOn = false
            };

            overlay.FlashButtonClicked += async(sender, e) =>
            {
                scanPage.ToggleTorch();
            };

            scanPage.OnScanResult += (result) =>
            {
                // Stop scanning
                scanPage.IsScanning = false;
                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await _application.MainPage.Navigation.PopAsync();

                    if (result != null && !string.IsNullOrWhiteSpace(result.Text))
                    {
                        Process(result.Text);
                        GlobalVar._listHistoryBox = new List <ListHistoryBox>();
                        await _application.MainPage.Navigation.PushAsync(new HistoryBox(), true);
                    }
                });
            };
            await _application.MainPage.Navigation.PushAsync(scanPage);
        }
Example #6
0
        public async void ScanCustomOverlayAsync()
        {
            var options = new MobileBarcodeScanningOptions
            {
                AutoRotate       = false,
                DisableAutofocus = false,
            };

            options.PossibleFormats.Add(BarcodeFormat.QR_CODE);
            options.PossibleFormats.Add(BarcodeFormat.CODE_128);
            options.PossibleFormats.Add(BarcodeFormat.CODE_93);
            options.PossibleFormats.Add(BarcodeFormat.CODE_39);
            options.PossibleFormats.Add(BarcodeFormat.EAN_13);
            options.PossibleFormats.Add(BarcodeFormat.EAN_8);

            var overlay = new ZXingDefaultOverlay
            {
                ShowFlashButton = true,
                BottomText      = TextsTranslateManager.Translate("ScanTopText"),
                TopText         = TextsTranslateManager.Translate("TurnOnOffFlash")
            };

            overlay.BindingContext = overlay;

            var scanPage = new ZXingScannerPage(options, overlay)
            {
                Title = TextsTranslateManager.Translate("ScannerTitle"),
            };

            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync();
                    await DisplayAlert("Scanned result", result.Text, "OK");
                });
            };
            await Navigation.PushAsync(scanPage);

            overlay.FlashButtonClicked += (s, ed) =>
            {
                scanPage.ToggleTorch();
            };
        }
        public ReaderPage()
        {
            sPage = new ZXingScannerPage(new MobileBarcodeScanningOptions
            {
                AutoRotate      = true,
                PossibleFormats = new List <BarcodeFormat>
                {
                    BarcodeFormat.QR_CODE,
                    BarcodeFormat.AZTEC
                },
                UseFrontCameraIfAvailable = true,
                UseNativeScanning         = true
            });

            sPage.ToggleTorch();
            sPage.OnScanResult += SPage_OnScanResult;

            Button scanButton = new Button
            {
                Text         = "Scan",
                AutomationId = "scanContinuously"
            };
            Button generateButton = new Button
            {
                Text         = "Generate",
                AutomationId = "barcodeGenerator"
            };

            generateButton.Clicked += GenerateButton_Clicked;

            scanButton.Clicked += ScanButton_Clicked;

            var stack = new StackLayout();

            stack.Children.Add(scanButton);
            stack.Children.Add(generateButton);

            Content = stack;
        }
Example #8
0
 public void ToggleTorch() =>
 scannerPage.ToggleTorch();
Example #9
0
        // QRCODE
        async Task ExecuteParkCommand()
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;

            var customOverlay = new StackLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Padding           = new Thickness(20, 30, 20, 30),
                Orientation       = StackOrientation.Horizontal
            };
            var torch = new Button
            {
                Text              = "Torch",
                TextColor         = Color.White,
                FontFamily        = "Avenir",
                VerticalOptions   = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.EndAndExpand,
                BackgroundColor   = Color.FromHex("#FF01A4EF"),
                HeightRequest     = 40,
                WidthRequest      = 80,
                BorderRadius      = 20
            };

            var close = new Button
            {
                Text              = "X",
                TextColor         = Color.White,
                FontFamily        = "Avenir",
                VerticalOptions   = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                BackgroundColor   = Color.FromHex("#FF01A4EF"),
                HeightRequest     = 40,
                WidthRequest      = 40,
                BorderRadius      = 20
            };

            scanPage = new ZXingScannerPage(customOverlay: customOverlay)
            {
                Title   = "Park",
                Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0)
            };

            torch.Clicked += delegate
            {
                scanPage.ToggleTorch();
            };

            close.Clicked += delegate
            {
                Application.Current.MainPage.Navigation.PopModalAsync();
            };

            customOverlay.Children.Add(close);
            customOverlay.Children.Add(torch);


            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    if (String.Equals(result.Text, "ParkingCode"))
                    {
                        try
                        {
                            var carParkTable = await CloudService.GetTableAsync <CarPark>();
                            var listOfSlots  = await carParkTable.ReadAllRoomsAsync();
                            String name      = "";

                            // Get the identity
                            var identity = await CloudService.GetIdentityAsync();
                            if (identity != null)
                            {
                                name = identity.UserClaims.FirstOrDefault(c => c.Type.Equals("urn:microsoftaccount:name")).Value;
                            }
                            CarPark currentSlot = new CarPark();
                            currentSlot.Park    = name;
                            Debug.WriteLine(currentSlot.Park);
                            Debug.WriteLine(name);

                            bool hasParked = false;
                            foreach (var slot in listOfSlots)
                            {
                                if (slot.Park.Equals(currentSlot.Park))
                                {
                                    hasParked   = true;
                                    currentSlot = slot;
                                    break;
                                }
                            }
                            Debug.WriteLine(hasParked);

                            if (hasParked)
                            {
                                await carParkTable.DeleteParkAsync(currentSlot);
                                await Application.Current.MainPage.Navigation.PopModalAsync();
                                MessagingCenter.Send <CarParkViewModel>(this, "ItemsChanged");
                                await App.Current.MainPage.DisplayAlert("Bye, " + name, "QR scanning went successfully", "OK");
                                await CloudService.SyncOfflineCacheAsync();
                            }
                            else
                            {
                                await carParkTable.CreateParkAsync(currentSlot);
                                await Application.Current.MainPage.Navigation.PopModalAsync();
                                MessagingCenter.Send <CarParkViewModel>(this, "ItemsChanged");
                                await App.Current.MainPage.DisplayAlert("Welcome, " + name, "QR scanning went successfully", "OK");
                                await CloudService.SyncOfflineCacheAsync();
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine($"[ScanPage] Error saving items: {ex.Message}");
                        }
                    }
                });
            };

            await Application.Current.MainPage.Navigation.PushModalAsync(scanPage);

            IsBusy = false;
        }
Example #10
0
        public HomePage() : base()
        {
            buttonScanDefaultOverlay = new Button {
                Text         = "Scan with Default Overlay",
                AutomationId = "scanWithDefaultOverlay",
            };
            buttonScanDefaultOverlay.Clicked += async delegate {
                scanPage = new ZXingScannerPage();
                scanPage.OnScanResult += (result) => {
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread(() => {
                        Navigation.PopAsync();
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };

                await Navigation.PushAsync(scanPage);
            };


            buttonScanCustomOverlay = new Button {
                Text         = "Scan with Custom Overlay",
                AutomationId = "scanWithCustomOverlay",
            };
            buttonScanCustomOverlay.Clicked += async delegate {
                // Create our custom overlay
                var customOverlay = new StackLayout {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand
                };
                var torch = new Button {
                    Text = "Toggle Torch"
                };
                torch.Clicked += delegate {
                    scanPage.ToggleTorch();
                };
                customOverlay.Children.Add(torch);

                scanPage = new ZXingScannerPage(customOverlay: customOverlay);
                scanPage.OnScanResult += (result) => {
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopAsync();
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };
                await Navigation.PushAsync(scanPage);
            };


            buttonScanContinuously = new Button {
                Text         = "Scan Continuously",
                AutomationId = "scanContinuously",
            };
            buttonScanContinuously.Clicked += async delegate {
                scanPage = new ZXingScannerPage();
                scanPage.OnScanResult += (result) =>
                                         Device.BeginInvokeOnMainThread(() =>
                                                                        DisplayAlert("Scanned Barcode", result.Text, "OK"));

                await Navigation.PushAsync(scanPage);
            };

            buttonScanCustomPage = new Button {
                Text         = "Scan with Custom Page",
                AutomationId = "scanWithCustomPage",
            };
            buttonScanCustomPage.Clicked += async delegate {
                var customScanPage = new CustomScanPage();
                await Navigation.PushAsync(customScanPage);
            };


            buttonGenerateBarcode = new Button {
                Text         = "Barcode Generator",
                AutomationId = "barcodeGenerator",
            };
            buttonGenerateBarcode.Clicked += async delegate {
                await Navigation.PushAsync(new BarcodePage());
            };

            var stack = new StackLayout();

            stack.Children.Add(buttonScanDefaultOverlay);
            stack.Children.Add(buttonScanCustomOverlay);
            stack.Children.Add(buttonScanContinuously);
            stack.Children.Add(buttonScanCustomPage);
            stack.Children.Add(buttonGenerateBarcode);

            Content = stack;
        }
Example #11
0
        public async void ScanBarcode(ContentPage Context, string ScanPurpose)
        {
            var options = new MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                //PureBarcode = true,
                UseNativeScanning         = true,
                UseFrontCameraIfAvailable = true,
                TryHarder = true,
                DelayBetweenAnalyzingFrames       = Convert.ToInt32(new CommonProcs().GetProperty("ext_DelayBetweenAnalyzingFrames")),
                InitialDelayBeforeAnalyzingFrames = Convert.ToInt32(new CommonProcs().GetProperty("ext_InitialDelayBeforeAnalyzingFrames")),
                DelayBetweenContinuousScans       = Convert.ToInt32(new CommonProcs().GetProperty("ext_DelayBetweenContinuousScans")),
                PossibleFormats = new List <ZXing.BarcodeFormat>(),
            };

            SetUpBarcodeFormats(options);

            switch (ScanPurpose)
            {
            case "SettingsBarcodeScan":
                options.PossibleFormats = new List <ZXing.BarcodeFormat> {
                    ZXing.BarcodeFormat.QR_CODE
                };
                break;

            default:
                break;
            }


            var ScanPage = new ZXingScannerPage()
            {
                DefaultOverlayShowFlashButton = true,
            };

            ScanPage.OnScanResult += (result) =>
            {
                // Stop scanning
                ScanPage.IsScanning = false;
                if (Convert.ToBoolean(new CommonProcs().GetProperty("ext_Torch")) &&
                    Convert.ToInt32(new CommonProcs().GetProperty("ext_ScanHardWare")) == 1)
                {
                    if (IsTorchOn)
                    {
                        ScanPage.ToggleTorch();
                        IsTorchOn = false;
                    }
                }
                SendingNow = false;
                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Context.Navigation.PopAsync();
                    new ScanSupport().BarcodeScanned(result.Text, ScanPurpose);
                });
            };

            await Context.Navigation.PushAsync(ScanPage);

            SendingNow = true;
            if (Convert.ToBoolean(new CommonProcs().GetProperty("ext_Autofocus")))
            {
                TimeSpan ts = new TimeSpan(0, 0, 0, 2, 0);
                Device.StartTimer(ts, () =>
                {
                    if (SendingNow)
                    {
                        if (!IsTorchOn)
                        {
                            if (Convert.ToBoolean(new CommonProcs().GetProperty("ext_Torch")) &&
                                Convert.ToInt32(new CommonProcs().GetProperty("ext_ScanHardWare")) == 1)
                            {
                                ScanPage.ToggleTorch();
                                IsTorchOn = true;
                            }
                        }
                        ScanPage.AutoFocus();
                    }
                    return(true);
                });
            }



            return;
        }
Example #12
0
        public PageZXingDemo() : base()
        {
            // ************ buttonScanDefaultOverlay ************

            buttonScanDefaultOverlay = new Button
            {
                Text         = "Scan with Default Overlay",
                AutomationId = "scanWithDefaultOverlay",
            };

            buttonScanDefaultOverlay.Clicked += async delegate
            {
                scanPage = new ZXingScannerPage();
                scanPage.OnScanResult += (result) =>
                {
                    scanPage.IsScanning = false;
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopAsync();
                        string msg = "扫描内容(Text)\r\n{0}\r\n\r\n条码格式(BarcodeFormat)\r\n{1}".FormatWith(result.Text, result.BarcodeFormat);
                        System.Diagnostics.Debug.WriteLine(msg);

                        // TODO 处理 字符集GB2312 乱码无法识别问题
                        //string msg2 = "{0}".FormatWith(CoreUtil.EncodingUtils.GetString(result.Text));
                        //System.Diagnostics.Debug.WriteLine(msg2);

                        DisplayAlert("扫描成功", msg, "OK");
                    });
                };

                await Navigation.PushAsync(scanPage);
            };

            // ************ buttonScanCustomOverlay ************
            buttonScanCustomOverlay = new Button
            {
                Text         = "Scan with Custom Overlay",
                AutomationId = "scanWithCustomOverlay",
            };

            buttonScanCustomOverlay.Clicked += async delegate
            {
                // Create our custom overlay
                var customOverlay = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand
                };
                var torch = new Button
                {
                    Text = "Toggle Torch"
                };
                torch.Clicked += delegate
                {
                    scanPage.ToggleTorch();
                };
                customOverlay.Children.Add(torch);

                scanPage = new ZXingScannerPage(customOverlay: customOverlay);
                scanPage.OnScanResult += (result) =>
                {
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopAsync();
                        System.Diagnostics.Debug.WriteLine("Scanned Barcode : {0}".FormatWith(result.Text));
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };
                await Navigation.PushAsync(scanPage);
            };

            // ************ buttonScanContinuously ************
            buttonScanContinuously = new Button
            {
                Text         = "Scan Continuously (缺点:镜头不移开一直DisplayAlert结果)",
                AutomationId = "scanContinuously",
            };

            buttonScanContinuously.Clicked += async delegate
            {
                scanPage = new ZXingScannerPage();
                scanPage.OnScanResult += (result) =>
                                         Device.BeginInvokeOnMainThread(() =>
                {
                    System.Diagnostics.Debug.WriteLine("Scanned Barcode : {0}".FormatWith(result.Text));
                    DisplayAlert("Scanned Barcode", result.Text, "OK");
                });

                await Navigation.PushAsync(scanPage);
            };

            // ************ buttonScanCustomPage ************
            buttonScanCustomPage = new Button
            {
                Text         = "Scan with Custom Page",
                AutomationId = "scanWithCustomPage",
            };

            buttonScanCustomPage.Clicked += async delegate
            {
                var customScanPage = new PageZXingScan();
                await Navigation.PushAsync(customScanPage);
            };

            // ************ buttonScanContinuouslyCustomPage ************
            buttonScanContinuouslyCustomPage = new Button
            {
                Text         = "Scan Continuously with Custom Page ( Add By Howe )",
                AutomationId = "scanWithCustomPage",
            };

            buttonScanContinuouslyCustomPage.Clicked += async delegate
            {
                var customScanPage = new PageZXingScan(isScanContinuously: true);
                await Navigation.PushAsync(customScanPage);
            };



            // ************ buttonGenerateBarcode ************
            buttonGenerateBarcode = new Button
            {
                Text         = "Barcode Generator",
                AutomationId = "barcodeGenerator",
            };

            buttonGenerateBarcode.Clicked += async delegate
            {
                await Navigation.PushAsync(new ZXingDemo.PageZXingCreateBarcode());
            };

            var stack = new StackLayout();

            stack.Children.Add(buttonScanDefaultOverlay);
            stack.Children.Add(buttonScanCustomOverlay);
            stack.Children.Add(buttonScanContinuously);
            stack.Children.Add(buttonScanCustomPage);
            stack.Children.Add(buttonScanContinuouslyCustomPage);
            stack.Children.Add(buttonGenerateBarcode);

            Content = stack;
        }
        public ScannerPage() : base()
        {
            InitializeComponent();
            ZXingScannerPage scanPage;
            ScannerPageModel viewModel = new ScannerPageModel();

            // Create our custom overlay


            btnScanDefault.Clicked += async delegate
            {
                try
                {
                    scanPage = new ZXingScannerPage();
                    scanPage.OnScanResult += (result) => {
                        scanPage.IsScanning = false;

                        Device.BeginInvokeOnMainThread(() => {
                            Navigation.PopAsync();
                            if (result != null)
                            {
                                txtBarcode.Text = result.Text;
                            }
                            else
                            {
                                txtBarcode.Text = "No Data Found! Please try again";
                            }
                        });
                    };

                    await Navigation.PushAsync(scanPage);
                }
                catch (Exception ex)
                {
                    txtBarcode.Text = "No Data Found! Please try again";
                }
            };
            btnScan.Clicked += async delegate
            {
                try
                {
                    var customOverlay = new StackLayout
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions   = LayoutOptions.FillAndExpand
                    };
                    var torch = new Button
                    {
                        Text = "Scan the QR Code"
                    };
                    customOverlay.Children.Add(torch);
                    scanPage = new ZXingScannerPage(customOverlay: customOverlay);
                    scanPage.OnScanResult += (result) =>
                    {
                        scanPage.IsScanning = false;
                        scanPage.Title      = "Scan the QR Code";

                        Device.BeginInvokeOnMainThread(() =>
                        {
                            Navigation.PopAsync();
                            if (result != null)
                            {
                                txtBarcode.Text = result.Text;
                                // spanText.Text = result.Text;
                            }
                            else
                            {
                                txtBarcode.Text = "No Data Found! Please try again";
                            }
                        });
                    };
                    torch.Clicked += delegate
                    {
                        scanPage.ToggleTorch();
                    };

                    await Navigation.PushAsync(scanPage);
                }
                catch (Exception ex)
                {
                    txtBarcode.Text = "No Data Found! Please try again";
                }
            }; 

        }
Example #14
0
        public HomePage() : base()
        {
            buttonScanDefaultOverlay = new Button
            {
                Text         = "Scan with Default Overlay",
                AutomationId = "scanWithDefaultOverlay",
            };
            buttonScanDefaultOverlay.Clicked += async delegate
            {
                scanPage = new ZXingScannerPage();
                scanPage.OnScanResult += (result) =>
                {
                    scanPage.IsScanning = false;
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopAsync();
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };

                await Navigation.PushAsync(scanPage);
            };


            buttonScanCustomOverlay = new Button
            {
                Text         = "Scan with Custom Overlay",
                AutomationId = "scanWithCustomOverlay",
            };
            buttonScanCustomOverlay.Clicked += async delegate
            {
                // Create our custom overlay
                var customOverlay = new StackLayout
                {
                    Spacing           = 0,
                    Padding           = 10,
                    BackgroundColor   = Color.Black,
                    Orientation       = StackOrientation.Horizontal,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.Start
                };
                var fotoButton = new Button()
                {
                    Text            = "Foto",
                    WidthRequest    = 150,
                    HeightRequest   = 40,
                    BorderRadius    = 10,
                    TextColor       = Color.White,
                    BackgroundColor = Color.Black,
                    BorderColor     = Color.White
                };
                var QRCodeButton = new Button()
                {
                    WidthRequest    = 150,
                    HeightRequest   = 40,
                    Text            = "QR Code",
                    BorderRadius    = 10,
                    TextColor       = Color.Black,
                    BackgroundColor = Color.White,
                    BorderColor     = Color.White
                };
                var circleButton = new Button();
                var imageGrid    = new Grid();
                fotoButton.Clicked += delegate
                {
                    fotoButton.TextColor       = Color.Black;
                    fotoButton.BackgroundColor = Color.White;

                    QRCodeButton.TextColor       = Color.White;
                    QRCodeButton.BackgroundColor = Color.Black;

                    imageGrid.IsVisible = true;
                    //scanPage.IsScanning = false;
                    //scanPage.IsAnalyzing = false;
                };

                QRCodeButton.Clicked += delegate
                {
                    QRCodeButton.TextColor       = Color.Black;
                    QRCodeButton.BackgroundColor = Color.White;

                    fotoButton.TextColor       = Color.White;
                    fotoButton.BackgroundColor = Color.Black;

                    imageGrid.IsVisible = false;
                    //scanPage.IsScanning = true;
                    //scanPage.IsAnalyzing = true;
                };

                var torch = new Button
                {
                    Text            = "T",
                    WidthRequest    = 40,
                    HeightRequest   = 40,
                    BorderRadius    = 10,
                    TextColor       = Color.White,
                    BackgroundColor = Color.Black,
                };
                torch.Clicked += delegate
                {
                    scanPage.ToggleTorch();
                    if (scanPage.IsTorchOn)
                    {
                        torch.TextColor       = Color.Black;
                        torch.BackgroundColor = Color.White;
                    }
                    else
                    {
                        torch.TextColor       = Color.White;
                        torch.BackgroundColor = Color.Black;
                    }
                };

                customOverlay.Children.Add(fotoButton);
                customOverlay.Children.Add(QRCodeButton);
                customOverlay.Children.Add(torch);

                var rootGrid = new Grid();
                rootGrid.RowSpacing     = 0;
                rootGrid.ColumnSpacing  = 0;
                rootGrid.RowDefinitions = new RowDefinitionCollection()
                {
                    new RowDefinition()
                    {
                        Height = 60
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    new RowDefinition()
                    {
                        Height = 80
                    },
                };

                rootGrid.Children.Add(customOverlay, 0, 0);


                imageGrid.BackgroundColor   = Color.Black;
                imageGrid.IsVisible         = false;
                imageGrid.RowSpacing        = 0;
                imageGrid.ColumnSpacing     = 0;
                imageGrid.ColumnDefinitions = new ColumnDefinitionCollection()
                {
                    new ColumnDefinition()
                    {
                        Width = 60
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                };
                imageGrid.RowDefinitions = new RowDefinitionCollection()
                {
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    }
                };

                image                   = new Image();
                image.Aspect            = Aspect.AspectFill;
                image.HorizontalOptions = LayoutOptions.Center;
                image.VerticalOptions   = LayoutOptions.Center;
                //image.Source = new UriImageSource() { Uri = new Uri("https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/242ce817-97a3-48fe-9acd-b1bf97930b01/09-posterization-opt.jpg") };
                image.WidthRequest  = 50;
                image.HeightRequest = 50;

                image.GestureRecognizers.Add(new TapGestureRecognizer()
                {
                    Command = new Command(async o =>
                    {
                        var cameraStatus  = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
                        var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);

                        if (cameraStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted)
                        {
                            var results   = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera, Permission.Storage });
                            cameraStatus  = results[Permission.Camera];
                            storageStatus = results[Permission.Storage];
                        }

                        if (cameraStatus == PermissionStatus.Granted && storageStatus == PermissionStatus.Granted)
                        {
                            var file = await CrossMedia.Current.PickPhotoAsync();
                        }
                        else
                        {
                            await DisplayAlert("Permissions Denied", "Unable to take photos.", "OK");
                            //On iOS you may want to send your user to the settings screen.
                            //CrossPermissions.Current.OpenAppSettings();
                        }
                    })
                });

                circleButton.HorizontalOptions = LayoutOptions.Center;
                circleButton.VerticalOptions   = LayoutOptions.Center;
                circleButton.WidthRequest      = 60;
                circleButton.HeightRequest     = 60;
                circleButton.BorderRadius      = 30;
                circleButton.BorderColor       = Color.Black;
                circleButton.BackgroundColor   = Color.White;

                var fotoLabel = new Label();
                fotoLabel.Text                    = "FOTO";
                fotoLabel.TextColor               = Color.FromRgb(255, 197, 45);
                fotoLabel.FontSize                = 14;
                fotoLabel.HorizontalOptions       = LayoutOptions.Center;
                fotoLabel.HorizontalTextAlignment = TextAlignment.Center;

                imageGrid.Children.Add(fotoLabel, 0, 0);
                Grid.SetColumnSpan(fotoLabel, 2);

                imageGrid.Children.Add(image, 0, 1);
                imageGrid.Children.Add(circleButton, 0, 1);
                Grid.SetColumnSpan(circleButton, 2);

                circleButton.Command = new Command(() =>
                {
                    scanPage.GetPicture();
                });

                rootGrid.Children.Add(imageGrid, 0, 2);
                //rootGrid.Children.Add(image, 0, 1);


                scanPage = new ZXingScannerPage(new ZXing.Mobile.MobileBarcodeScanningOptions
                {
                    AutoRotate = true,
                    CameraResolutionSelector = resolutions => resolutions.First(),
                }, customOverlay: rootGrid);
                scanPage.OnPictureTaken += OnPictureTaken;
                NavigationPage.SetHasNavigationBar(scanPage, false);
                scanPage.OnScanResult += (result) =>
                {
                    scanPage.IsScanning = false;


                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopAsync();
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };
                await Navigation.PushAsync(scanPage);
            };


            buttonScanContinuously = new Button
            {
                Text         = "Scan Continuously",
                AutomationId = "scanContinuously",
            };
            buttonScanContinuously.Clicked += async delegate
            {
                scanPage = new ZXingScannerPage(new ZXing.Mobile.MobileBarcodeScanningOptions
                {
                    DelayBetweenContinuousScans = 300
                });
                scanPage.OnScanResult += (result) =>
                                         Device.BeginInvokeOnMainThread(() =>
                                                                        DisplayAlert("Scanned Barcode", result.Text, "OK"));
                await Navigation.PushAsync(scanPage);
            };

            buttonScanCustomPage = new Button
            {
                Text         = "Scan with Custom Page",
                AutomationId = "scanWithCustomPage",
            };
            buttonScanCustomPage.Clicked += async delegate
            {
                var customScanPage = new CustomScanPage();
                await Navigation.PushAsync(customScanPage);
            };


            buttonGenerateBarcode = new Button
            {
                Text         = "Barcode Generator",
                AutomationId = "barcodeGenerator",
            };
            buttonGenerateBarcode.Clicked += async delegate
            {
                await Navigation.PushAsync(new BarcodePage());
            };

            var stack = new StackLayout();

            stack.Children.Add(buttonScanDefaultOverlay);
            stack.Children.Add(buttonScanCustomOverlay);
            stack.Children.Add(buttonScanContinuously);
            stack.Children.Add(buttonScanCustomPage);
            stack.Children.Add(buttonGenerateBarcode);

            Content = stack;
        }
Example #15
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            opts = new ZXing.Mobile.MobileBarcodeScanningOptions()
            {
                AutoRotate      = false,
                PossibleFormats = new List <ZXing.BarcodeFormat>()
                {
                    ZXing.BarcodeFormat.CODE_128,
                    ZXing.BarcodeFormat.CODABAR,
                    ZXing.BarcodeFormat.CODE_39,
                }
            };

            opts.TryHarder = true;

            zxing = new ZXingScannerView
            {
                IsScanning   = false,
                IsTorchOn    = false,
                IsAnalyzing  = false,
                AutomationId = "zxingDefaultOverlay",//zxingScannerView
                Opacity      = 22,
                Options      = opts
            };

            var torch = new Switch
            {
            };

            torch.Toggled += delegate
            {
                scanPage.ToggleTorch();
            };

            var grid = new Grid
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
            };

            var Overlay = new ZXingDefaultOverlay
            {
                TopText         = "Włącz latarkę",
                BottomText      = "Skanowanie rozpocznie się automatycznie",
                ShowFlashButton = true,
                AutomationId    = "zxingDefaultOverlay",
            };

            var customOverlay = new StackLayout
            {
                HorizontalOptions = LayoutOptions.EndAndExpand,
                VerticalOptions   = LayoutOptions.EndAndExpand
            };

            grid.Children.Add(Overlay);
            Overlay.Children.Add(torch);
            Overlay.BindingContext = Overlay;

            scanPage = new ZXingScannerPage(opts, customOverlay: Overlay)
            {
                DefaultOverlayTopText = "Zeskanuj kod ",
                //DefaultOverlayBottomText = " Skanuj kod ";
                DefaultOverlayShowFlashButton = true
            };
            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;
                scanPage.AutoFocus();
                Device.BeginInvokeOnMainThread(() =>
                {
                    Device.StartTimer(new TimeSpan(0, 0, 0, 2), () =>
                    {
                        if (scanPage.IsScanning)
                        {
                            scanPage.AutoFocus();
                        }
                        return(true);
                    });
                    Navigation.PopModalAsync();
                    entry_MM.Text = result.Text;
                    viewModel.ExecInsertToBase(result.Text);
                });
            };
            await Navigation.PushModalAsync(scanPage);
        }
Example #16
0
        //public RaportLista_AddTwrKod(DaneMMElem mmka) //edycja
        //{
        //    this.Title = "Dodaj MM";

        //    _MMElement = mmka;


        //    NavigationPage.SetHasNavigationBar(this, false);

        //    StackLayout stackLayout = new StackLayout();
        //    StackLayout stackLayout_gl = new StackLayout();
        //    StackLayout stack_naglowek = new StackLayout();

        //    Label lbl_naglowek = new Label();
        //    lbl_naglowek.HorizontalOptions = LayoutOptions.CenterAndExpand;
        //    lbl_naglowek.VerticalOptions = LayoutOptions.Start;
        //    lbl_naglowek.Text = "Szczegóły pozycji";
        //    lbl_naglowek.FontSize = 20;
        //    lbl_naglowek.TextColor = Color.Bisque;
        //    lbl_naglowek.BackgroundColor = Color.DarkCyan;

        //    stack_naglowek.HorizontalOptions = LayoutOptions.FillAndExpand;
        //    stack_naglowek.VerticalOptions = LayoutOptions.Start;
        //    stack_naglowek.BackgroundColor = Color.DarkCyan;
        //    stack_naglowek.Children.Add(lbl_naglowek);

        //    stackLayout_gl.Children.Add(stack_naglowek);



        //    img_foto = new Image();
        //    img_foto.Source = mmka.Url.Replace("Miniatury/", "");
        //    var tapGestureRecognizer = new TapGestureRecognizer();
        //    tapGestureRecognizer.Tapped += (s, e) =>
        //    {
        //        Launcher.OpenAsync(mmka.Url.Replace("Miniatury/", ""));
        //    };
        //    img_foto.GestureRecognizers.Add(tapGestureRecognizer);
        //    stackLayout.Children.Add(img_foto);
        //    //_gidnumer = mmka.gi;


        //    lbl_stan = new Label();
        //    lbl_stan.HorizontalOptions = LayoutOptions.Center;
        //    lbl_stan.Text = "Ilość : " + mmka.Ilosc + " szt";

        //    stackLayout.Children.Add(lbl_stan);

        //    lbl_twrkod = new Label();
        //    lbl_twrkod.HorizontalOptions = LayoutOptions.Center;
        //    lbl_twrkod.Text = "Kod towaru : " + mmka.Twr_Kod;

        //    lbl_ean = new Label();
        //    lbl_ean.HorizontalOptions = LayoutOptions.Center;
        //    lbl_ean.Text = "Ean : " + mmka.Ean;

        //    entry_kodean = new Entry()
        //    {
        //        HorizontalOptions = LayoutOptions.Center,
        //        Text = "Ean : " + mmka.Ean,

        //    };

        //    //lbl_symbol = new Label();
        //    //lbl_symbol.HorizontalOptions = LayoutOptions.Center;
        //    //lbl_symbol.Text = "Symbol : " + mmka.symbol;

        //    lbl_nazwa = new Label();
        //    lbl_nazwa.HorizontalOptions = LayoutOptions.Center;
        //    lbl_nazwa.Text = "Nazwa : " + mmka.Twr_Nazwa;

        //    lbl_cena = new Label();
        //    lbl_cena.HorizontalOptions = LayoutOptions.Center;
        //    lbl_cena.Text = "Cena : " + mmka.Cena + " Zł";


        //    Button open_url = new Button();
        //    open_url.Text = "Otwórz zdjęcie";
        //    open_url.CornerRadius = 15;

        //    open_url.Clicked += Open_url_Clicked;
        //    //open_url.BackgroundColor = Color.FromHex("#3CB371");
        //    //open_url.VerticalOptions = LayoutOptions.EndAndExpand;
        //    //open_url.Margin = new Thickness(15, 0, 15, 5);


        //    stackLayout.Children.Add(lbl_twrkod);
        //    stackLayout.Children.Add(lbl_nazwa);
        //    //stackLayout.Children.Add(lbl_ean);
        //    stackLayout.Children.Add(entry_kodean);
        //    //stackLayout.Children.Add(lbl_symbol);
        //    stackLayout.Children.Add(lbl_cena);


        //    stackLayout.VerticalOptions = LayoutOptions.Center;
        //    stackLayout.Padding = new Thickness(15, 0, 15, 0);
        //    stackLayout.Spacing = 8;
        //    stackLayout_gl.Children.Add(stackLayout);
        //    //stackLayout_gl.Children.Add(open_url);

        //    Content = stackLayout_gl;
        //    // GetDataFromTwrKod(mmka.twrkod);
        //    //entry_ilosc.Focus();
        //}


        public RaportLista_AddTwrKod(DaneMMElem akcje) //edycja
        {
            this.Title = "Dodaj MM";



            NavigationPage.SetHasNavigationBar(this, false);

            StackLayout stackLayout    = new StackLayout();
            StackLayout stackLayout_gl = new StackLayout();
            StackLayout stack_naglowek = new StackLayout();

            Label lbl_naglowek = new Label();

            lbl_naglowek.HorizontalOptions = LayoutOptions.CenterAndExpand;
            lbl_naglowek.VerticalOptions   = LayoutOptions.Start;
            lbl_naglowek.Text            = "Szczegóły pozycji";
            lbl_naglowek.FontSize        = 20;
            lbl_naglowek.TextColor       = Color.Bisque;
            lbl_naglowek.BackgroundColor = Color.DarkCyan;

            stack_naglowek.HorizontalOptions = LayoutOptions.FillAndExpand;
            stack_naglowek.VerticalOptions   = LayoutOptions.Start;
            stack_naglowek.BackgroundColor   = Color.DarkCyan;
            stack_naglowek.Children.Add(lbl_naglowek);

            stackLayout_gl.Children.Add(stack_naglowek);



            img_foto        = new Image();
            img_foto.Source = akcje.Url.Replace("Miniatury/", "");
            var tapGestureRecognizer = new TapGestureRecognizer();

            tapGestureRecognizer.Tapped += (s, e) =>
            {
                Launcher.OpenAsync(akcje.Url.Replace("Miniatury/", ""));
            };
            img_foto.GestureRecognizers.Add(tapGestureRecognizer);
            stackLayout.Children.Add(img_foto);
            //_gidnumer = mmka.gi;


            lbl_stan = new Label();
            lbl_stan.HorizontalOptions = LayoutOptions.Center;
            lbl_stan.Text           = "Stan : " + akcje.Ilosc + " szt";
            lbl_stan.FontAttributes = FontAttributes.Bold;

            stackLayout.Children.Add(lbl_stan);

            lbl_twrkod = new Label();
            lbl_twrkod.HorizontalOptions = LayoutOptions.Center;
            lbl_twrkod.Text = "Kod towaru : " + akcje.Twr_Kod;

            lbl_ean = new Label();
            lbl_ean.HorizontalOptions = LayoutOptions.Center;
            lbl_ean.Text = akcje.Ean;

            entry_kodean = new Entry()
            {
                HorizontalOptions = LayoutOptions.Center,
                Keyboard          = Keyboard.Numeric,
                Text         = akcje.Ilosc_Skan == 0 ? "" : akcje.Ilosc_Skan.ToString(),
                WidthRequest = 60,
                IsEnabled    = false
            };

            //lbl_symbol = new Label();
            //lbl_symbol.HorizontalOptions = LayoutOptions.Center;
            //lbl_symbol.Text = "Symbol : " + akcje.TwrSymbol;

            lbl_nazwa = new Label();
            lbl_nazwa.HorizontalOptions = LayoutOptions.Center;
            lbl_nazwa.Text = "Nazwa : " + akcje.Twr_Nazwa;

            lbl_cena = new Label();
            lbl_cena.HorizontalOptions = LayoutOptions.Center;
            lbl_cena.Text = "Cena : " + akcje.Cena + " Zł";


            Button open_url = new Button();

            open_url.Text         = "Zacznij skanowanie";
            open_url.CornerRadius = 15;

            //open_url.Clicked += Open_url_Clicked;
            overlay = new ZXingDefaultOverlay
            {
                TopText      = $"Skanowany : {akcje.Twr_Kod}",
                BottomText   = $"Zeskanowanych szt : {ile}",
                AutomationId = "zxingDefaultOverlay",
            };

            var torch = new Switch
            {
            };

            torch.Toggled += delegate
            {
                scanPage.ToggleTorch();
            };

            overlay.Children.Add(torch);
            open_url.Clicked += async delegate
            {
                scanPage = new ZXingScannerPage(
                    new ZXing.Mobile.MobileBarcodeScanningOptions {
                    DelayBetweenContinuousScans = 3000
                }, overlay);
                scanPage.DefaultOverlayShowFlashButton = true;
                scanPage.OnScanResult += (result) =>
                                         Device.BeginInvokeOnMainThread(() =>
                {
                    skanean = result.Text;

                    if (skanean == lbl_ean.Text)
                    {
                        ile += 1;
                        overlay.BottomText = $"Zeskanowanych szt : {ile}";
                        DisplayAlert(null, $"Zeskanowanych szt : {ile}", "OK");

                        entry_kodean.Text = ile.ToString();
                    }
                    else
                    {
                        DisplayAlert(null, "Probujesz zeskanować inny model..", "OK");
                    }
                });
                await Navigation.PushModalAsync(scanPage);
            };
            //open_url.BackgroundColor = Color.FromHex("#3CB371");
            open_url.VerticalOptions = LayoutOptions.EndAndExpand;
            //open_url.Margin = new Thickness(15, 0, 15, 5);


            stackLayout.Children.Add(lbl_twrkod);
            stackLayout.Children.Add(lbl_nazwa);
            stackLayout.Children.Add(lbl_ean);
            stackLayout.Children.Add(entry_kodean);
            stackLayout.Children.Add(lbl_symbol);
            stackLayout.Children.Add(lbl_cena);


            stackLayout.VerticalOptions = LayoutOptions.Center;
            stackLayout.Padding         = new Thickness(15, 0, 15, 0);
            stackLayout.Spacing         = 8;
            stackLayout_gl.Children.Add(stackLayout);
            stackLayout_gl.Children.Add(open_url);

            Content = stackLayout_gl;
            // GetDataFromTwrKod(mmka.twrkod);
            //entry_ilosc.Focus();
        }
Example #17
0
        public QrcodeScanner()
        {
            buttonScanDefaultOverlay = new Button
            {
                Text = "Scan with Default Overlay",
            };

            buttonScanDefaultOverlay.Clicked += async delegate {
                scanPage = new ZXingScannerPage();

                scanPage.OnScanResult += (result) =>
                {
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopAsync();
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };

                await Navigation.PushAsync(scanPage);
            };


            // button scan customOverlay
            buttonScanCustomOverlay = new Button
            {
                Text = "Scan with Custom Overlay"
            };
            buttonScanCustomOverlay.Clicked += async delegate {
                var customOverlay = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand
                };
                var torch = new Button
                {
                    Text = "Toggle Torch"
                };
                torch.Clicked += delegate {
                    scanPage.ToggleTorch();
                };
                customOverlay.Children.Add(torch);

                scanPage = new ZXingScannerPage(customOverlay: customOverlay);
                scanPage.OnScanResult += (result) =>
                {
                    scanPage.IsScanning = false;
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopAsync();
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };

                await Navigation.PushAsync(scanPage);
            };

            var stack = new StackLayout();

            stack.Children.Add(buttonScanDefaultOverlay);
            stack.Children.Add(buttonScanCustomOverlay);

            Content = stack;
        }
        public async void LaunchScanPage(bool isEmprunt)
        {
            try
            {
                var customOverlay = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.Start,
                    VerticalOptions   = LayoutOptions.Start
                };
                var retour = new Button
                {
                    Image           = "return64.png",
                    BackgroundColor = Color.Transparent
                };
                var torch = new Button
                {
                    Text            = "Flash",
                    BackgroundColor = Color.Transparent,
                    FontSize        = Device.GetNamedSize(NamedSize.Large, typeof(Label))
                };

                retour.Clicked += delegate
                {
                    Navigation.PopModalAsync();
                };
                torch.Clicked += delegate {
                    scanPage.ToggleTorch();
                };

                customOverlay.Children.Add(retour);
                customOverlay.Children.Add(torch);

                scanPage = new ZXingScannerPage(customOverlay: customOverlay);

                scanPage.OnScanResult += (result) =>
                {
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopModalAsync();

                        var client  = new RestClient("http://51.254.117.45:3000/");
                        var request = new RestRequest("items/{id}", Method.GET);

                        request.AddHeader("x-access-token", Application.Current.Properties["token"].ToString());
                        request.AddUrlSegment("id", result.Text);
                        IRestResponse response = client.Execute(request);

                        item = JsonConvert.DeserializeObject <Items>(response.Content);

                        if (item._id != null)
                        {
                            Application.Current.Properties["itemId"] = item._id;
                            var client_rendre  = new RestClient("http://51.254.117.45:3000/");
                            var request_rendre = new RestRequest("emprunts/byUserAndItem", Method.POST);

                            request_rendre.AddHeader("x-acces-token", Application.Current.Properties["token"].ToString());
                            request_rendre.AddParameter("user_mail", Application.Current.Properties["user_mail"].ToString());
                            request_rendre.AddParameter("item", result.Text);

                            IRestResponse response_rendre = client_rendre.Execute(request_rendre);
                            emprunt = JsonConvert.DeserializeObject <Emprunt>(response_rendre.Content);

                            if (isEmprunt && emprunt == null)
                            {
                                newEmprunt = true;
                            }
                            else
                            {
                                newEmprunt = false;
                            }

                            if (emprunt != null || isEmprunt)
                            {
                                if (isEmprunt && item.Quantite == "0")
                                {
                                    DisplayAlert("Attention", "Nous ne l'avons plus en stock", "OK");
                                }
                                else
                                {
                                    Navigation.PushModalAsync(new RecapScan());
                                }
                            }
                            else
                            {
                                DisplayAlert("Attention", "Action impossible", "OK");
                            }
                        }
                        else
                        {
                            if (isEmprunt)
                            {
                                DisplayAlert("Attention", "Nous ne retrouvons pas cet item", "OK");
                            }
                            else
                            {
                                DisplayAlert("Attention", "Vous ne pouvez pas rendre puisque vous n'avez rien emprunté", "OK");
                            }
                        }
                    });
                };
                await Navigation.PushModalAsync(scanPage);
            }
            catch (Exception ex)
            {
                await DisplayAlert("Erreur", ex.ToString(), "OK");
            }
        }
      private async void ShowScanner()
      {
          var scanner = new ZXing.Mobile.MobileBarcodeScanner
          {
              FlashButtonText  = "Flash",
              UseCustomOverlay = false,
              CancelButtonText = "Cancel"
          };
          var overlay = new ZXingDefaultOverlay
          {
              TopText         = string.Empty,
              BottomText      = string.Empty,
              ShowFlashButton = _flash,
          };

          var options = new ZXing.Mobile.MobileBarcodeScanningOptions
          {
              AutoRotate = _autorotate,
              TryHarder  = _tryHarder,

              TryInverted       = _tryInverted,
              UseNativeScanning = _NativeScanning,
              PossibleFormats   = new List <ZXing.BarcodeFormat>()
              {
                  ZXing.BarcodeFormat.QR_CODE,
                  ZXing.BarcodeFormat.AZTEC, ZXing.BarcodeFormat.CODE_128, ZXing.BarcodeFormat.CODE_39,
                  ZXing.BarcodeFormat.CODE_93, ZXing.BarcodeFormat.EAN_13, ZXing.BarcodeFormat.EAN_8,
                  ZXing.BarcodeFormat.PDF_417, ZXing.BarcodeFormat.UPC_E
              }
          };

          ScannerPage = new ZXingScannerPage(options, overlay)
          {
              DefaultOverlayShowFlashButton = true,
              HasTorch    = true,
              IsScanning  = true,
              IsAnalyzing = true,
          };

          overlay.FlashButtonClicked += (s, ed) =>
          {
              ScannerPage.ToggleTorch();
          };

          var toolbarItem = new ToolbarItem {
              Text = "Cancel"
          };

          toolbarItem.Clicked += (s, e) =>
          {
              ScannerPage.IsScanning = false;
              Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopModalAsync();
                });
          };

          try
          {
              ScannerPage.AutoFocus();
              ScannerPage.OnScanResult += (result) =>
              {
                  ScannerPage.IsScanning = false;

                  Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        await Navigation.PopModalAsync();
                        if (_scanning)
                        {
                            return;
                        }

                        _scanning = true;

                        if (DateTime.Now.Year < 2019)
                        {
                            return;
                        }

                        if (result != null)
                        {
                            ScannerPage.IsScanning = false;
                            scanResultText.Text    = result.Text;
                        }

                        _scanning = false;
                    });
              };

              var navPage = new NavigationPage(ScannerPage);
              navPage.ToolbarItems.Add(toolbarItem);

              await Navigation.PushModalAsync(navPage);
          }
          catch (Exception ex)
          {
              throw;
          }
      }
        /*
         * Function:  barcodeScanner()
         * --------------------
         *  inputs: object sender, EventArgs args
         *
         *  onClick for barcode scanner button
         */
        private async void barcodeScanner(object sender, EventArgs args)
        {
            // Gets barcode data for converting part number to model number
            // Data stored locally
            var barcodeData = JsonConvert.DeserializeObject <List <Barcode> >(barcodeContent);

            // Config scanner
            var overlay = new ZXingDefaultOverlay
            {
                ShowFlashButton = false, // Show Flash button off
                // Messages shown on top and bottom of scanner
                TopText    = "Scan Part Number Barcode",
                BottomText = "Motor Controller Will Be Selected Once Scanned",
            };

            overlay.BindingContext = overlay; // Declare overlays

            // New scanner page
            var scan = new ZXingScannerPage(null, overlay);

            // Wait for scanner to return, pass it the scanner config
            await Navigation.PushAsync(scan);

            if (Device.RuntimePlatform == Device.iOS)
            {
                scan.AutoFocus(); // Autofocus if iOS
            }
            if (isLightOn == true)
            {
                scan.ToggleTorch(); // Turn torch on if user had it on before
            }

            // On return result
            scan.OnScanResult += (result) =>
            {
                // Begin on main thread
                Device.BeginInvokeOnMainThread(async() =>
                {
                    // Controller and model number result varibales declared
                    string controllerToSelect = "";
                    int scannerResult         = 0;

                    // Await scanner to return
                    await Navigation.PopAsync();

                    try
                    {
                        scannerResult = Int32.Parse(result.Text); // Set scanner result to int if possible
                    }
                    catch (FormatException)
                    {
                        // if not possible, catch error and display invalid barcode popup
                        await DisplayAlert("Invalid Barcode", "Please scan the Part Number Barcode on a Curtis Motor Controller", "OK");
                        scannerResult = 0; // Set scanner result to 0, error
                    }

                    // if result has been read
                    if (scannerResult != 0)
                    {
                        // Iterate through the data
                        for (int i = 0; i < barcodeData.Count(); i++)
                        {
                            // Check for part number
                            if (barcodeData[i].Part == scannerResult)
                            {
                                // if found, set controller to corresponding model number
                                controllerToSelect = barcodeData[i].Model;
                            }
                        }

                        // Iterate through names to find index to set picker to
                        for (int i = 0; i < names.Count(); i++)
                        {
                            // Check for name
                            if (names[i] == controllerToSelect)
                            {
                                // If found, set selectedIndex to index it was found at
                                mcPicker.SelectedIndex = i;

                                // Turn torch off when scanner is turned off and code is found
                                isLightOn = false;
                            }
                        }

                        // if picker is 0 and fault code isn't display error popup
                        if (mcPicker.SelectedIndex == 0 && controllerToSelect != names[0])
                        {
                            await DisplayAlert("Invalid Barcode", "Please scan the Part Number Barcode on a Curtis Motor Controller", "OK");
                        }
                    }
                });
            };
        }
Example #21
0
        public HomePage() : base()
        {
            buttonScanner = new Button
            {
                Text         = "Scan with scanner",
                AutomationId = "scanWithScanner",
            };

            buttonScanner.Clicked += async delegate
            {
                var scanner = new ZXing.Mobile.MobileBarcodeScanner();

                MobileBarcodeScanningOptions scanningOptions = null;

                if (DeviceInfo.Manufacturer == "QUALCOMM" &&
                    DeviceInfo.Model == "p80")
                {
                    scanningOptions = new ZXing.Mobile.MobileBarcodeScanningOptions
                    {
                        AndroidOptions = new AndroidOptions()
                        {
                            ModifyCameraDisplayOrientationDelegate = (rotation) =>
                            {
                                switch (rotation)
                                {
                                case 0:
                                    return(90);

                                case 1:
                                    return(180);

                                case 2:
                                    return(270);

                                case 3:
                                    return(0);

                                default:
                                    return(0);
                                }
                            }
                        }
                    };
                }

                ZXing.Result result = null;

                if (scanningOptions != null)
                {
                    await scanner.Scan(scanningOptions);
                }
                else
                {
                    await scanner.Scan();
                }

                if (result != null && result.Text != null)
                {
                }
            };

            buttonScanDefaultOverlay = new Button
            {
                Text         = "Scan with Default Overlay",
                AutomationId = "scanWithDefaultOverlay",
            };
            buttonScanDefaultOverlay.Clicked += async delegate
            {
                scanPage = new ZXingScannerPage();
                scanPage.OnScanResult += (result) =>
                {
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopAsync();
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };

                await Navigation.PushAsync(scanPage);
            };



            buttonScanCustomOverlay = new Button
            {
                Text         = "Scan with Custom Overlay",
                AutomationId = "scanWithCustomOverlay",
            };
            buttonScanCustomOverlay.Clicked += async delegate
            {
                // Create our custom overlay
                var customOverlay = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand
                };
                var torch = new Button
                {
                    Text = "Toggle Torch"
                };
                torch.Clicked += delegate
                {
                    scanPage.ToggleTorch();
                };
                customOverlay.Children.Add(torch);

                scanPage = new ZXingScannerPage(new ZXing.Mobile.MobileBarcodeScanningOptions {
                    AutoRotate = true
                }, customOverlay: customOverlay);
                scanPage.OnScanResult += (result) =>
                {
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopAsync();
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };
                await Navigation.PushAsync(scanPage);
            };


            buttonScanContinuously = new Button
            {
                Text         = "Scan Continuously",
                AutomationId = "scanContinuously",
            };
            buttonScanContinuously.Clicked += async delegate
            {
                scanPage = new ZXingScannerPage(new ZXing.Mobile.MobileBarcodeScanningOptions {
                    DelayBetweenContinuousScans = 3000
                });
                scanPage.OnScanResult += (result) =>
                                         Device.BeginInvokeOnMainThread(() =>
                                                                        DisplayAlert("Scanned Barcode", result.Text, "OK"));

                await Navigation.PushAsync(scanPage);
            };

            buttonScanCustomPage = new Button
            {
                Text         = "Scan with Custom Page",
                AutomationId = "scanWithCustomPage",
            };
            buttonScanCustomPage.Clicked += async delegate
            {
                var customScanPage = new CustomScanPage();
                await Navigation.PushAsync(customScanPage);
            };


            buttonGenerateBarcode = new Button
            {
                Text         = "Barcode Generator",
                AutomationId = "barcodeGenerator",
            };
            buttonGenerateBarcode.Clicked += async delegate
            {
                await Navigation.PushAsync(new BarcodePage());
            };

            var stack = new StackLayout();

            stack.Children.Add(buttonScanner);
            stack.Children.Add(buttonScanDefaultOverlay);
            stack.Children.Add(buttonScanCustomOverlay);
            stack.Children.Add(buttonScanContinuously);
            stack.Children.Add(buttonScanCustomPage);
            stack.Children.Add(buttonGenerateBarcode);

            Content = stack;
        }
Example #22
0
        private void ButtonScanCustom_Clicked(object sender, EventArgs e)
        {
            var overlay = new AbsoluteLayout
            {
                //WidthRequest = 200,
                //HeightRequest = 200,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
            };
            var stack = new StackLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };

            var grid = new Grid();
            {
                grid.VerticalOptions   = LayoutOptions.FillAndExpand;
                grid.HorizontalOptions = LayoutOptions.FillAndExpand;
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(2, GridUnitType.Star)
                });
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });

                grid.Children.Add(new BoxView
                {
                    VerticalOptions   = LayoutOptions.Fill,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Black,
                    Opacity           = 0.7,
                }, 0, 0);
                grid.Children.Add(new BoxView
                {
                    VerticalOptions   = LayoutOptions.Fill,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Black,
                    Opacity           = 0.7,
                }, 0, 2);
                grid.Children.Add(new BoxView
                {
                    VerticalOptions   = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    HeightRequest     = 3,
                    BackgroundColor   = Color.FromHex("#1976D2"),
                    Opacity           = 0.6,
                }, 0, 1);
            }



            var torch = new Button
            {
                //Text = "Let there be light!",
                Text = "Torch",
                // Enable "Material" Visual on C#
                Visual = VisualMarker.Material,
                //Source = "sculpturetorch.png",
                //HorizontalOptions = LayoutOptions.Start,
                //VerticalOptions = LayoutOptions.End,
                //WidthRequest = 80,
                //HeightRequest = 80,
                //Opacity = 1,
                BackgroundColor = Color.FromHex("#2E7ACE"),
                //Image = "torch.img",
            };

            AbsoluteLayout.SetLayoutFlags(stack,
                                          AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(stack,
                                           new Rectangle(0f, 0f, 1f, 1f));
            AbsoluteLayout.SetLayoutFlags(torch,
                                          AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(torch,
                                           new Rectangle(0, 1, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
            overlay.Children.Add(stack);
            overlay.Children.Add(torch);
            stack.Children.Add(grid);
            //Content = stack;


            var batteryLevel = CrossBattery.Current.RemainingChargePercent;
            var status       = CrossBattery.Current.Status;

            torch.Clicked += async delegate
            {
                if (batteryLevel > 40 || status == Plugin.Battery.Abstractions.BatteryStatus.Charging)
                {
                    scanPage.ToggleTorch();
                }
                if (status == Plugin.Battery.Abstractions.BatteryStatus.NotCharging || batteryLevel < 40)
                {
                    var notificator    = DependencyService.Get <IToastNotificator>();
                    var androidOptions = new AndroidOptions
                    {
                        DismissText = ""
                    };
                    var options = new NotificationOptions()
                    {
                        Title          = "BatteryLow",
                        AndroidOptions = androidOptions
                    };
                    await notificator.Notify(options);
                }
            };


            //scanPage = new ZXingScannerPage(new MobileBarcodeScanningOptions
            //{ AutoRotate = false, TryHarder = true}, customOverlay: customOverlay);
            //Not using customoverlay
            scanPage = new ZXingScannerPage(new MobileBarcodeScanningOptions
            {
                AutoRotate = false, TryHarder = true
            }, customOverlay: overlay);

            //scanPage = new ZXingScannerView
            //{
            //    HorizontalOptions = LayoutOptions.FillAndExpand,
            //    VerticalOptions = LayoutOptions.FillAndExpand,
            //    AutomationId = "zxingScannerView",
            //};
            Navigation.PushModalAsync(scanPage);
            // Work with the result
            scanPage.OnScanResult += (result) =>
            {
                var clipshit = result.Text;
                Clipboard.SetTextAsync(result.Text);
                Clipboard.GetTextAsync();
                scanPage.IsScanning = false;
                // Action starts
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopModalAsync();
                    //if (clipshit != null)
                    //if (result.Text.StartsWith("http"))
                    string input = result.Text;
                    //Regex regex = new Regex(@"https?://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+");
                    Match match = Regex.Match(input, @"https?://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+");
                    //return regex.Matches(strInput);
                    if (match.Success)
                    {
                        var result2 = await DisplayAlert("URL detected.", "Wanna Open Browser?", "yes", "no");
                        if (result2 == true)
                        {
                            //var intent = new Intent(Intent.ActionMain);
                            //intent.SetComponent(new ComponentName("com.catchingnow.tinyclipboardmanager", "com.catchingnow.tinyclipboardmanager.MainActivity"));
                            //StartActivity(intent);
                            Device.OpenUri(new Uri(result.Text));
                        }
                        if (result2 == false)
                        {
                            //await Navigation.PopAsync();
                            //await DisplayAlert("みじっそう", "です", "さーせん");
                            var notificator    = DependencyService.Get <IToastNotificator>();
                            var androidOptions = new AndroidOptions
                            {
                                DismissText = "Cancel"
                            };
                            var options = new NotificationOptions()
                            {
                                Title          = "Launching Share",
                                AndroidOptions = androidOptions,
                            };
                            var resultt = await notificator.Notify(options);
                            if (!(resultt.Action == NotificationAction.Dismissed))
                            {
                                await Share.RequestAsync(new ShareTextRequest(result.Text));
                            }
                            else
                            {
                                Android.Widget.Toast.MakeText(Android.App.Application.Context,
                                                              "Cancelled", Android.Widget.ToastLength.Short).Show();
                            }
                            //DependencyService.Get<IDeviceService>().PlayVibrate();
                            //var duration = TimeSpan.FromSeconds(1);
                            //Vibration.Vibrate(duration);
                        }
                    }
                    else
                    {
                        //await Navigation.PopAsync();
                        var result3 = await DisplayAlert("Seems like it's not URL", "Share result?", "Yes", "No");
                        if (result3 == true)
                        {
                            await Share.RequestAsync(new ShareTextRequest(result.Text));
                        }
                        if (result3 == false)
                        {
                            Android.Widget.Toast.MakeText(Android.App.Application.Context,
                                                          "Result copied to Clipboard", Android.Widget.ToastLength.Short).Show();
                        }
                    }
                    //DependencyService.Get<IDeviceService>().PlayVibrate();
                });
            };
        }
Example #23
0
        bool EnteredQtyBool   = false;    //tells us if we have entered quantity to scan.

        public ScanPage(OrderItem scannableItem, IList <OrderItem> list)
        {
            InitializeComponent();              //calling content formed in ScanPage.xaml
            OIList             = list;
            this.scannableItem = scannableItem; //Taking the OrderItem from OrderListView.
            remainingScans     = (int)scannableItem.QtyOrdered;

            itemLabel.Text = "Item to be scanned: " + scannableItem.Name; //sets our label with the name of the item in case of mis tap.

            /**
             *  var "options" allows you to choose what options you want your scanner to
             * allow. Currently using it to AutoRotate. Another option, "TryHarder",
             * gets or sets a flag which cause a deeper look into the bitmap.This
             * just makes it so the camera focuses on the barcode quicker, though it
             * does add room for misscans.
             */
            var options = new MobileBarcodeScanningOptions
            {
                AutoRotate = true,
                UseFrontCameraIfAvailable = false,
                TryHarder = false
            };

            Button EnterQtyToScan = new Button
            {
                IsVisible   = true,
                BorderColor = Color.DarkGray,
                Text        = "Enter Amount",
            };

            /*
             * Overlay sets our top and bottom texts, these texts will change once we scan items.
             */
            var overlay = new ZXingDefaultOverlay
            {
                TopText    = "Quantity scanned: " + qtyScanned.ToString() + "\t" + "Quantity remaining: " + scannableItem.QtyOrdered.ToString(),
                BottomText = "Item Scanning: " + scannableItem.Name + "\r" + "Located in Section: " + scannableItem.LocationQOH.Replace(Environment.NewLine, " ") + "\r" + " You can enter amount up to one less than quantity remaining."
            };
            //Removes red line across screen
            var redLine = overlay.Children.First(x => x.BackgroundColor == Color.Red);

            overlay.Children.Remove(redLine);

            //Removes top background color
            var topLine = overlay.Children.First();

            overlay.Children.Remove(topLine);

            //Adding a clear lines to have more space to scan.
            var clearLine = overlay.Children[2];

            overlay.Children.AddVertical(clearLine);

            overlay.Children.AddVertical(clearLine);

            //Removes bottom background color
            var bottomLine = overlay.Children.First();

            overlay.Children.Remove(bottomLine);

            //Setting our elements for our button on the scanner page
            EnterQtyToScan.Scale             = 1;
            EnterQtyToScan.HorizontalOptions = LayoutOptions.Center;
            EnterQtyToScan.Margin            = 20;
            EnterQtyToScan.BackgroundColor   = Color.Gray;

            overlay.Children.AddVertical(EnterQtyToScan); //adding our "Enter Amount" button to our overlay
            //Once button is clicked, create a new scanPage with the options and overlay set above
            btnScan.Clicked += async(a, s) =>
            {
                scanPage = new ZXingScannerPage(options, overlay);

                overlay.FlashButtonClicked += (t, ed) => //Can be removed if target device has no flash capability
                {
                    scanPage.ToggleTorch();              //If flash button is clicked it will toggle on/off.
                };

                EnterQtyToScan.Clicked += async(w, q) =>
                {
                    EnteredQtyBool = true;                                                          //we pressed the "enter quantity to scan" button
                    while (tempEnteredAmount > scannableItem.QtyOrdered || tempEnteredAmount == -1) //while the amount we entered is greater than qtyOrdered or has not been entered yet.
                    {
                        //Prompt that will have us enter the quantity we wish to scan at once
                        string EnteredAmountToScan = await DisplayPromptAsync(scannableItem.Name, "How many of this item do you intend to pack?", "accept", "cancel", maxLength : 4, keyboard : Keyboard.Numeric);

                        if (EnteredAmountToScan == null)
                        {
                            EnterQtyToScan.Unfocus(); //Cancel button pressed we unfocus the prompt.
                            EnteredQtyBool = false;
                            return;
                        }
                        try
                        {
                            //tempEnteredAmount must be a valid number (0-one less than remainingScans) otherwise you will get an Error message.
                            tempEnteredAmount = Int32.Parse(EnteredAmountToScan); //try and set our global var
                            if (tempEnteredAmount > remainingScans)               //if it exceeds our qty ordered we must display an error
                            {
                                await DisplayAlert("Error", "Amount entered exceeds quantity ordered.", "OK");

                                tempEnteredAmount = -1;
                            }
                            if (tempEnteredAmount < 0) //if it is negative we must display an error
                            {
                                await DisplayAlert("Error", "Amount must be a positive number.", "OK");

                                tempEnteredAmount = -1;
                            }
                            if (tempEnteredAmount == remainingScans) //if it equals our qty ordered we must display an error
                            {
                                await DisplayAlert("Error", "Amount entered must be at least one less than quantity ordered.", "OK");

                                tempEnteredAmount = -1;
                            }
                        }
                        catch
                        {
                            //If the number is a decimal we display an Error message.
                            await DisplayAlert("Error", "Invalid entry: entry must be a whole number.", "OK");
                        }
                    }
                    RemainingScans();                                                                                                                   //After we leave our while loop we call our method to update our variables.
                    overlay.TopText   = "Quantity scanned: " + qtyScanned.ToString() + "\r\n\r\n" + "Quantity remaining: " + remainingScans.ToString(); //overlay to represent how many scans remain after we enter our amount.
                    tempEnteredAmount = -1;                                                                                                             //allows us to reenter our loop if we press the button again.
                };
                //Once we capture a barcode we "BeginInvokeOnMainThread" to check what we scanned
                scanPage.OnScanResult += (result) =>
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (_isScanning)
                        {
                            _isScanning          = false;                                                                                                         //bool to stop _isScanning from allowing us to enter if() statement.
                            scanPage.IsAnalyzing = false;                                                                                                         //stops scanning barcodes once this is implemented.
                            barCodeRead          = result.Text;                                                                                                   //sets barcode scanned in as a string
                            if (barCodeMatcher())                                                                                                                 //If the scan matches the barcode from the OrderItem list, display the "Barcode Matches" alert.
                            {
                                RemainingScans();                                                                                                                 //tells us how many more scan we have
                                overlay.TopText = "Quantity scanned: " + qtyScanned.ToString() + "\r\n\r\n" + "Quantity remaining: " + remainingScans.ToString(); //overlay to represent how many scans remain.
                                await DisplayAlert("Barcode Matches", result.Text + " , " + " Remaining Scans: " + remainingScans.ToString() + " , " + "QtyScanned: " + qtyScanned.ToString(), "OK");
                                if (doneScanning)
                                {
                                    await Navigation.PopModalAsync();                                                       //Takes us back to the page with the scan button to know we are done.
                                    await DisplayAlert("Finished Scanning: ", scannableItem.Name + " is completed.", "OK"); //Alert to know we are done scanning an item.
                                    await Navigation.PopAsync();                                                            //Takes us back to the page where we choose which item we are about to scan.
                                    OIList[OIList.IndexOf(scannableItem)].IsPacked = true;                                  //sets our binding property to true
                                }
                            }
                            else
                            {
                                await DisplayAlert("Scanned Barcode", result.Text + " , " + result.BarcodeFormat + " ," + result.ResultPoints[0].ToString() + " , " + " Barcode does NOT match that of the selected item.", "OK"); //Every barcode scanned that does not match will display as an alert.
                            }
                            scanPage.IsAnalyzing = true;                                                                                                                                                                           //Allows us to scan again once we "ok" the popup.
                            _isScanning          = true;                                                                                                                                                                           //Allows us to be able to reenter our if() statement.
                        }
                    });
                };
                await Navigation.PushModalAsync(scanPage); //Takes us to the page where we see what the camera is picking up
            };
            //If the wrong item is clicked hit the back button to get back to the list of items to be scanned.
            btnBack.Clicked += async(a, s) =>
            {
                await Navigation.PopAsync(); //Takes us back to the page where we choose which item we are about to scan.
            };
            this.Content = Content;          //sets our content from the .xaml
        }