Beispiel #1
0
        void ProcessScanResults(ScanSession session)
        {
            if (session == null)
            {
                return;
            }

            if (session.NewlyRecognizedCodes != null && session.NewlyRecognizedCodes.Any())
            {
                var firstCode = session.NewlyRecognizedCodes.First();

                session.StopScanning();

                // Because this event handler is called from an scanner-internal thread,
                // you must make sure to dispatch to the main thread for any UI work.
                Device.BeginInvokeOnMainThread(async() =>
                {
                    ScanditService.BarcodePicker.DidScan -= ProcessScanResults;
                    if (firstCode != null)
                    {
                        // This delay is needed because the app will crash if we too quickly transition to another page when the scanner is closing
                        // This gives time for this page to load before going to item details page
                        await Task.Delay(200);

                        await ScanSearch(firstCode);
                    }
                });
            }
            else
            {
                session.StopScanning();
            }
        }
Beispiel #2
0
        private async void OnCodesScanned(ScanSession session)
        {
            session.StopScanning();


            var firstCode = session.NewlyRecognizedCodes.First();
            var text      = String.Format("{0} ({1})", firstCode.Data, firstCode.SymbologyString.ToUpper());

            //if (await Application.Current.MainPage.DisplayAlert("Are you sure to include it in the collection", $"You have scanned {text}", "Yes", "No"))
            //{
            if (!Products.Any(p => p.BarCode == text))
            {
                Products.Insert(0, new Product()
                {
                    BarCode = text, Units = 1
                });
            }
            else
            {
                var product = _products.Single(p => p.BarCode == text);
                _products.Remove(product);
                product.Units++;
                Products.Insert(0, product);
            }
            //}

            //await ScanditService.BarcodePicker.StartScanningAsync(false);
        }
        void OnDidScan(ScanSession session)
        {
            // guaranteed to always have at least one element, so we don't have to
            // check the size of the NewlyRecognizedCodes array.
            var firstCode = session.NewlyRecognizedCodes.First();
            var message   = string.Format("Code Scanned:\n {0}\n({1})", firstCode.Data, firstCode.SymbologyString.ToUpper());

            // Because this event handler is called from an scanner-internal thread,
            // you must make sure to dispatch to the main thread for any UI work.
            Device.BeginInvokeOnMainThread(() => this.ResultLabel.Text = message);
            session.StopScanning();
        }
Beispiel #4
0
        void OnDidScan(ScanSession session)
        {
            var firstCode = session.NewlyRecognizedCodes.First();
            var message   = "";

            if (session.NewlyRecognizedCodes.Count() == 1)
            {
                message = string.Format("Code Scanned:\n {0}\n({1})", firstCode.Data,
                                        firstCode.SymbologyString.ToUpper());
            }
            else if (session.NewlyRecognizedCodes.Count() > 1)
            {
                var secondCode = session.NewlyRecognizedCodes.ElementAt(1);
                message = string.Format("Codes Scanned:\n {0}\n({1})\n {2}\n({3})",
                                        firstCode.Data,
                                        firstCode.SymbologyString.ToUpper(),
                                        secondCode.Data,
                                        secondCode.SymbologyString.ToUpper());
            }
            // Because this event handler is called from an scanner-internal thread,
            // you must make sure to dispatch to the main thread for any UI work.
            Device.BeginInvokeOnMainThread(() => this.ResultLabel.Text = message);
            session.StopScanning();
        }