private async void btnOrderClick(object sender, EventArgs e)
        {
            DateTime dt = new DateTime(pkDatePicker.Picker.Date.Year, pkDatePicker.Picker.Date.Month, pkDatePicker.Picker.Date.Day,
                                       pkTime.Picker.Time.Hours, pkTime.Picker.Time.Minutes, pkTime.Picker.Time.Seconds);

            var order = await viewModel.OrderTable(dt, quantityPeople.Quantity);

            if (order == null)
            {
                await MultiContentPages.Instance.DisplayAlert("Thông báo", "Order không thành công?", "Không");
            }
            else
            {
                contentQrCode.Children.Add(GenerateQR("ORDER" + order.code));
            }
            var res = await MultiContentPages.Instance.DisplayAlert("Thông báo", "Bạn có muốn đặt món trước không?", "Có", "Không");

            if (res == true)
            {
                BackgroundWorker wk = new BackgroundWorker();
                wk.DoWork += (s, z) =>
                {
                    z.Result = new MenuFood.MenuPage(true);
                };
                MultiContentPages.Instance.PushPage(wk);
            }

            qrCode.IsVisible = true;
        }
示例#2
0
        public async void Scan()
        {
            try
            {
                var options = new MobileBarcodeScanningOptions
                {
                    AutoRotate = false,
                    UseFrontCameraIfAvailable = false,
                    TryHarder = true,
                };

                var overlay = new ZXingDefaultOverlay
                {
                    TopText    = "Please scan QR code",
                    BottomText = "Align the QR code within the frame"
                };
                var           grid = new Grid();
                RowDefinition row1 = new RowDefinition()
                {
                    Height = 100
                };
                RowDefinition row2 = new RowDefinition();
                RowDefinition row3 = new RowDefinition()
                {
                    Height = 150
                };

                grid.RowDefinitions.Add(row1);
                grid.RowDefinitions.Add(row2);
                grid.RowDefinitions.Add(row3);
                Label edit = new Label()
                {
                    Text     = "Đặt mã QR vào khung hình",
                    FontSize = 24,
                    HorizontalTextAlignment = TextAlignment.Center,
                    HorizontalOptions       = LayoutOptions.CenterAndExpand,
                    VerticalTextAlignment   = TextAlignment.Center,
                    VerticalOptions         = LayoutOptions.CenterAndExpand,
                    TextColor = Color.Red,
                };
                Grid grid1 = new Grid()
                {
                    BackgroundColor = Color.Black, Opacity = 0.4f, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand
                };
                grid1.Children.Add(edit);
                Grid.SetRow(grid1, 0);
                grid.Children.Add(grid1);

                var QRScanner = new ZXingScannerPage(options, grid);

                await Navigation.PushModalAsync(QRScanner);

                QRScanner.OnScanResult += (result) =>
                {
                    // Stop scanning
                    QRScanner.IsScanning = false;

                    // Pop the page and show the result
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        TableOrderViewModel model = new TableOrderViewModel();
                        try
                        {
                            await Navigation.PopModalAsync(false);
                            if (result.Text.Contains("TABLE"))
                            {
                                IRES_Global.GlobalInfo.TableCode = result.Text;
                                string s = result.Text.Replace("TABLE", "");
                                var res  = await model.OrderTable(int.Parse(s), DateTime.Now);
                                BtnMenu_Clicked(null, null);
                            }
                            else if (result.Text.Contains("ORDER"))
                            {
                                string z = result.Text.Replace("ORDER", "");
                                model.getOrderByCode(z);
                            }
                        }
                        catch
                        {
                            await Navigation.PopModalAsync(false);
                            if (result.Text.Contains("TABLE"))
                            {
                                IRES_Global.GlobalInfo.TableCode = result.Text;
                                string s = result.Text.Replace("TABLE", "");
                                var res  = await model.OrderTable(int.Parse(s), DateTime.Now);
                                BtnMenu_Clicked(null, null);
                            }
                            else if (result.Text.Contains("ORDER"))
                            {
                                string z = result.Text.Replace("ORDER", "");
                                model.getOrderByCode(z);
                            }
                        }
                    });
                };
            }
            catch (Exception ex)
            {
                // GlobalScript.SeptemberDebugMessages("ERROR", "BtnScanQR_Clicked", "Opening ZXing Failed: " + ex);
                Device.BeginInvokeOnMainThread(() => {
                    // DisplayAlert("Scanned Barcode", ex.ToString(), "OK");
                });
            }
        }