private async void btnAdd_Click(object sender, RoutedEventArgs e) { List <Topping> Toppings = new List <Topping>(); foreach (CheckBox topping in this.Toppings) { if ((bool)topping.IsChecked) { Toppings.Add(new Topping(topping.Content.ToString(), float.Parse(topping.Tag.ToString()), 1)); } } Pizza pizza = new Pizza(globalProperties.SelectedPizzaName, (cbxSize.SelectedItem as ComboBoxItem).Content.ToString(), (cbxDough.SelectedItem as ComboBoxItem).Content.ToString(), (cbxSauce.SelectedItem as ComboBoxItem).Content.ToString(), (cbxCheese.SelectedItem as ComboBoxItem).Content.ToString(), Toppings); var dlg = new ConfirmItemDialog(pizza.PricedString()); MainPage.ReplaceDialog(dlg, sender); try { var result = await dlg.ShowAsync(); if (result == ContentDialogResult.Primary) { Cart.Items.Add(pizza); ContentFrame.Navigate(typeof(PizzaPage)); } } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } }
private async void btnDelete_Click(object sender, RoutedEventArgs e) { string ItemSummary = (sender as Button).Tag.ToString(); foreach (Item item in Cart.Items) { if (item.Summary.Equals(ItemSummary)) { var dlg = new ContentDialog { Title = "Remove Item", Content = "Confirm removing:\n" + item.Summary, PrimaryButtonText = "Remove", CloseButtonText = "Cancel" }; MainPage.ReplaceDialog(dlg, sender); try { var result = await dlg.ShowAsync(); if (result == ContentDialogResult.Primary) { Cart.Items.Remove(item); ContentFrame.Navigate(typeof(CartPage)); } break; } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } } } }
private async void HyperlinkButton_Click(object sender, RoutedEventArgs e) { var registerDialog = new RegisterDialog(); MainPage.ReplaceDialog(registerDialog); try { ContentDialogResult registerResult; do { registerResult = await registerDialog.ShowAsync(); } while ((registerDialog.IsUserExist || !registerDialog.IsPasswordVaild) && registerResult == ContentDialogResult.Primary); } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } }
// Prompt user if they really wish to empty cart, only empty cart when user confirm private async void btnEmptyCart_Click(object sender, RoutedEventArgs e) { if (ItemList.Items.Count == 0) { var dlgNotEmpty = new ContentDialog { Title = "Unable To Empty Cart", Content = "Cart is already empty.", PrimaryButtonText = "OK" }; MainPage.ReplaceDialog(dlgNotEmpty, sender); try { await dlgNotEmpty.ShowAsync(); return; } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } } var dlgEmpty = new ContentDialog { Title = "Empty Cart", Content = "Are you sure about emptying the cart?", PrimaryButtonText = "Yes", SecondaryButtonText = "No" }; MainPage.ReplaceDialog(dlgEmpty, sender); try { var result = await dlgEmpty.ShowAsync(); if (result == ContentDialogResult.Primary) { Cart.Items.Clear(); ContentFrame.Navigate(typeof(CartPage)); } return; } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } }
private async void btnAdd_Click(object sender, RoutedEventArgs e) { List <string> Sauces = new List <string>(); int Pieces = Convert.ToInt32( (cbxPieces.SelectedItem as ComboBoxItem).Tag.ToString()); foreach (CheckBox sauce in this.Sauces) { if ((bool)sauce.IsChecked) { Sauces.Add(sauce.Content.ToString()); } } if (Sauces.Count == 0) { await new MessageDialog("Please select at least one sauce.", "Unable to place item").ShowAsync(); return; } else if (Pieces == 20 && Sauces.Count == 1) { await new MessageDialog("Please select at least two sauce for 20 Chicken Bites.", "Unable to place item").ShowAsync(); return; } ChickenBite bites = new ChickenBite(Pieces, Sauces); var dlg = new ConfirmItemDialog(bites.PricedString()); MainPage.ReplaceDialog(dlg, sender); try { var result = await dlg.ShowAsync(); if (result == ContentDialogResult.Primary) { Cart.Items.Add(bites); ContentFrame.Navigate(typeof(ChickenBitesPage)); } } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } }
private async void btnSubmit_Click(object sender, RoutedEventArgs e) { errorMsg.Text = ""; string name = txtName.Text; string email = txtEmail.Text; string content = txtFeedback.Text; if (name.Length == 0) { errorMsg.Text = "Please enter your name."; return; } if (email.Length == 0) { errorMsg.Text = "Please enter your email address."; return; } if (!globalProperties.IsEmailValid(email)) { errorMsg.Text = "Please enter a valid email address."; return; } if (content.Length == 0) { errorMsg.Text = "Please fill in your feedback."; return; } int result = globalProperties.SubmitFeedBack(name, email, content); ContentDialog dlg; if (result == 1) { dlg = new ContentDialog { Title = "Feedback sent!", Content = "Your opinion is very important to us. We appreciate your feedback and will use it to evaluate changes and make improvements in our app.", PrimaryButtonText = "OK" } } ; else { dlg = new ContentDialog { Title = "Feedback Failed to Send", Content = "Encountered technical difficulities, please try again later.", PrimaryButtonText = "OK" } }; MainPage.ReplaceDialog(dlg, sender); try { await dlg.ShowAsync(); } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } } }
// Display receipt and ask for payment method private async void btnCheckOut_Click(object sender, RoutedEventArgs e) { string summary = ""; SubTotal = 0; btnRefresh_Click(this, new RoutedEventArgs()); // Abort action when cart is empty if (Cart.Items.Count == 0) { var dlgEmpty = new ContentDialog { Title = "Unable to checkout", Content = "There are no item placed in cart", PrimaryButtonText = "OK" }; MainPage.ReplaceDialog(dlgEmpty, sender); try { await dlgEmpty.ShowAsync(); return; } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } } // generate receipt string receipt = "\n\t Papa Dario's Pizza"; receipt += "\n\tOrdered at: " + DateTime.Now.ToString(); receipt += "\n----------------------------------------------\n\n"; foreach (Item item in Cart.Items) { receipt += item.PricedString() + "\n\n"; SubTotal += item.SubTotal; summary += item.Summary + "\n"; } if (globalProperties.IsLoggedIn) { SubTotal = (float)(SubTotal * 0.9); } Tax = (float)Math.Round((0.13 * (double)SubTotal), 2); receipt += "----------------------------------------------\n"; receipt += String.Format("{0, 38} {1, 7}\n", "Subtotal:", "$" + Math.Round(SubTotal, 2)); receipt += String.Format("{0, 38} {1, 7}\n", "Tax:", "$" + Math.Round(Tax, 2)); receipt += String.Format("{0, 38} {1, 7}\n", "Total:", "$" + Math.Round((SubTotal + Tax), 2)); receipt += "\n\n Thank you for purchasing from Papa Dario's!"; var dlg = new ReceiptDialog(receipt); MainPage.ReplaceDialog(dlg, sender); try { var result = await dlg.ShowAsync(); if (result == ContentDialogResult.Primary) { int orderId = globalProperties.PlaceOrder(summary, Math.Round(SubTotal, 2), Math.Round(Tax, 2), Math.Round((SubTotal + Tax), 2)); foreach (Item item in Cart.Items) { globalProperties.PlaceOrderedItem(orderId, item.Summary); } Cart.Items.Clear(); var dlgSuccess = new ContentDialog { Title = "Order Placed", Content = "Thank you for ordering from Papa Dario's!", PrimaryButtonText = "Close" }; MainPage.ReplaceDialog(dlgSuccess, sender); await dlgSuccess.ShowAsync(); ContentFrame.Navigate(typeof(CartPage)); } return; } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } }