Beispiel #1
0
        public ItemSearchPage()
        {
            BackgroundColor = Color.White;
            Title = "Search";

            SearchBar searchEntry = new SearchBar {
                VerticalOptions = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor = Color.FromHex("#044A0C")
            };

            searchEntry.SearchButtonPressed += OnSearchBarButtonPressed;

            listView = new ListView ();
            listView.ItemTemplate = new DataTemplate
                    (typeof (SearchPageCell));
            listView.ItemSelected += (sender, e) => {
                var todoItem = (TapandGo.Data.ItemsData)e.SelectedItem;
                var todoPage = new TapandGo.Views.ItemDetailPage();
                todoPage.BindingContext = todoItem;

                ((App)App.Current).ResumeAtTodoId = todoItem.ID;
                Debug.WriteLine("setting ResumeAtTodoId = " + todoItem.ID);

                Navigation.PushAsync(todoPage);
            };

            var layout = new StackLayout();
            layout.Children.Add(searchEntry);
            layout.Children.Add(listView);
            layout.VerticalOptions = LayoutOptions.FillAndExpand;
            Content = layout;
        }
        public ShoppingCart()
        {
            InitializeComponent();

            this.BindingContext = new TapandGo.ViewModel.ShoppingCartModel();

            Title = "North Lakes";
            BackgroundColor = Color.White;


            Label topLabel = new Label {
                Text = "Current Basket",
                FontSize = 20,
                VerticalOptions = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.Start,
                TextColor = Color.Black
            };



            SearchBar searchEntry = new SearchBar {
                Text = "Search for items",
                VerticalOptions = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor = Color.FromHex("#044A0C")

            };
            searchEntry.Focused += OnsearchBarChanged;

            listView = new ListView();
            listView.IsPullToRefreshEnabled = true;
            listView.ItemTemplate = new DataTemplate
                    (typeof(BasketPageCell));

             totalPrice = new Label {
               TextColor = Color.Red,
               FontSize = 20,
               HorizontalOptions = LayoutOptions.Center
            };

             var totalPriceLayout = new StackLayout {
                 Padding = new Thickness(20, 0, 0, 0),
                 Children = {totalPrice}
             };
            

            var checkoutButton = new Button { Text = "CheckOut", BackgroundColor = Color.FromHex("#044A0C") };
            checkoutButton.Clicked += (sender, e) =>
            {
                var checkoutB = new NavigationPage(new CheckOutPage());
                this.Navigation.PushModalAsync(checkoutB, false);

            };

            var scanItemButton = new Button { Text = "Scan Item", BackgroundColor = Color.FromHex("#044A0C") };
            scanItemButton.Clicked += async (sender, args) =>
            {
                var scanResult = await Acr.BarCodes.BarCodes.Instance.Read();
                if (!scanResult.Success)
                {
                    await this.DisplayAlert("Alert ! ", "Sorry ! \n Failed to read the Barcode !", "OK");
                }
                else
                {
                    
                    long result = long.Parse(scanResult.Code);
                    var todoItem = TapandGo.Database.Database.GetDatabase().GetBarCodeItem(result);
                    var todopage = new TapandGo.Views.ItemDetailPage();



                    if (todoItem == null)
                    {
                        //Print error message
                       await DisplayAlert("Alert", "Item not found. Please try again.", "OK");
                       
                    }
                    else {
                       
                        todopage.BindingContext = todoItem;
                        ((App)App.Current).ResumeAtTodoId = todoItem.ID;
                      
                        await Navigation.PushAsync(todopage);
                    }


                }
            };

            var layout = new StackLayout();
            layout.Children.Add(searchEntry);
            layout.Children.Add(topLabel);
            layout.Children.Add(listView);
            layout.Children.Add(totalPriceLayout);
            layout.Children.Add(scanItemButton);
            layout.Children.Add(checkoutButton);
            layout.VerticalOptions = LayoutOptions.FillAndExpand;
            Content = layout;

        }