Exemplo n.º 1
0
        private async void Page_AdvPageOnScanResult(object sender, ZXing.Result result)
        {
            FullScreenScanPage page = (FullScreenScanPage)sender;

            page.AdvPageOnScanResult -= Page_AdvPageOnScanResult;

            if (result == null || _viewModel == null)
            {
                return;
            }

            int placeId = 0;

            try
            {
                placeId = int.Parse(result.Text);
            }
            catch (Exception)
            {
                await DisplayAlert("Inforamtion", "Incorrect format of the bar code or qr code", "Cancel");

                return;
            }

            if (_viewModel.LoadItemsByPlaceIdCommand.CanExecute(placeId))
            {
                _viewModel.WarehousePlaceId = placeId;
                _viewModel.LoadItemsByPlaceIdCommand.Execute(placeId);
            }
        }
        async void ScanPlaceId(object sender, EventArgs e)
        {
            var btn = sender as Button;

            btn.IsEnabled = false;
            FullScreenScanPage page = new FullScreenScanPage(EnumScanType.WarehousePlace);

            page.AdvPageOnScanResult += Page_AdvPageOnScanResult;;
            await Navigation.PushModalAsync(page);

            btn.IsEnabled = true;
        }
        private async void Page_AdvPageOnScanResult(object sender, ZXing.Result result)
        {
            FullScreenScanPage page = (FullScreenScanPage)sender;

            page.AdvPageOnScanResult -= Page_AdvPageOnScanResult;

            if (result == null || _viewModel == null)
            {
                return;
            }

            long id = 0;

            try
            {
                id = int.Parse(result.Text);
            }
            catch (Exception)
            {
                await DisplayAlert("Inforamtion", "Incorrect format of the bar code or qr code", "Cancel");

                return;
            }

            switch (page.ScanType)
            {
            case EnumScanType.Item:
                _viewModel.ItemId = id;
                if (_viewModel.LoadItemCommand.CanExecute(id))
                {
                    _viewModel.LoadItemCommand.Execute(id);
                }
                break;

            case EnumScanType.WarehousePlace:
                _viewModel.PlaceId = id;
                if (_viewModel.LoadPlaceCommand.CanExecute(id))
                {
                    _viewModel.LoadPlaceCommand.Execute(id);
                }
                break;
            }
        }