Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Image of the design with controls explained: https://imgur.com/a/vsjbWzi
- // XAML code for reference: https://pastebin.com/dBQS8Crv
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Text.RegularExpressions;
- namespace Mario_Pizza_Application
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- { // Global variables for the prices and items
- double _prijsgerecht = 0;
- int items = 0;
- double _totalprice = 0;
- public MainWindow()
- {
- InitializeComponent();
- }
- private void ValidateInfo()
- {
- // Gets the postcode and name of the user
- string postcode = tbPostcode.Text;
- string name = tbName.Text;
- if (!Regex.IsMatch(postcode, @"[0-9]{4} [A-Z]{2}"))
- {
- MessageBox.Show("Vul een geldige postcode in!");
- return;
- }
- if (!Regex.IsMatch(postcode, @"[0-9]{4} [A-Z]{2}"))
- {
- MessageBox.Show("Vul een geldige postcode in!");
- return;
- }
- }
- private void SetPrice()
- {
- ComboBoxItem selectedMealCBI = (ComboBoxItem)cbPizzas.SelectedItem;
- string selectedMeal = selectedMealCBI.Content.ToString();
- // Price order: Hawaii 0, Margaritha 1, Peperoni 2, Funghi 3, Quattro 4, Calzone 5, Prosciutto 6, Diavola 7, Napoli 8, Tonno 9, Frute Di Mare 10
- double[] prices = {10.00, 8.00, 9.00, 10.50, 10.00, 11.00, 10.50, 10.00, 11.00, 11.00, 10.50, 10.00, 12.00, 14.00 };
- // Price order: Bolognese 0, Gorgonzola 1, Vongole 2, Pesto 3, Classico 4
- double[] pricesPastas = { 8.00, 9.50, 12.50, 7.00, 11.00};
- switch (selectedMeal)
- { //Pizzagerechten + sets the price based on the radiobutton thats selected.
- case "Hawaii":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[0]; } else { _prijsgerecht = prices[0] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- case "Margaritha":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[1]; } else { _prijsgerecht = prices[1] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- case "Peperoni":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[2]; } else { _prijsgerecht = prices[2] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- case "Funghi":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[3]; } else { _prijsgerecht = prices[3] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- case "Quattro":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[4]; } else { _prijsgerecht = prices[4] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- case "Calzone":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[5]; } else { _prijsgerecht = prices[5] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- case "Prosciutto":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[6]; } else { _prijsgerecht = prices[6] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- case "Diavola":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[7]; } else { _prijsgerecht = prices[7] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- case "Napoli":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[8]; } else { _prijsgerecht = prices[8] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- case "Tonno":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[9]; } else { _prijsgerecht = prices[9] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- case "Frute Di Mare":
- if ((bool)rb35cm.IsChecked) { _prijsgerecht = prices[10]; } else { _prijsgerecht = prices[10] * 0.7; };
- tbFormat.Visibility = Visibility.Visible;
- rb25cm.Visibility = Visibility.Visible;
- rb35cm.Visibility = Visibility.Visible;
- break;
- // Pastagerechten, since pastas don't come in sizes of 25cm and 35cm, the visiblity of the format and sizes are hidden.
- case "Macaroni Bolognese":
- _prijsgerecht = pricesPastas[0];
- tbFormat.Visibility = Visibility.Hidden;
- rb25cm.Visibility = Visibility.Hidden;
- rb35cm.Visibility = Visibility.Hidden;
- break;
- case "Farfalle Gorgonzola":
- _prijsgerecht = pricesPastas[1];
- tbFormat.Visibility = Visibility.Hidden;
- rb25cm.Visibility = Visibility.Hidden;
- rb35cm.Visibility = Visibility.Hidden;
- break;
- case "Spaghetti Vongole":
- _prijsgerecht = pricesPastas[2];
- tbFormat.Visibility = Visibility.Hidden;
- rb25cm.Visibility = Visibility.Hidden;
- rb35cm.Visibility = Visibility.Hidden;
- break;
- case "Fusilli Pesto":
- _prijsgerecht = pricesPastas[3];
- tbFormat.Visibility = Visibility.Hidden;
- rb25cm.Visibility = Visibility.Hidden;
- rb35cm.Visibility = Visibility.Hidden;
- break;
- case "Lasagne Classico ":
- _prijsgerecht = pricesPastas[4];
- tbFormat.Visibility = Visibility.Hidden;
- rb25cm.Visibility = Visibility.Hidden;
- rb35cm.Visibility = Visibility.Hidden;
- break;
- }
- }
- private void btnAdd_Click(object sender, RoutedEventArgs e)
- {
- ValidateInfo();
- ComboBoxItem selectedMealCBI = (ComboBoxItem)cbPizzas.SelectedItem; // Gets the selected combo box item
- string selectedMeal = selectedMealCBI.Content.ToString(); // Converts it to a string
- string order = selectedMeal + ';' + "Totaal;" + "$" + (_prijsgerecht * int.Parse(tbAmount.Text)).ToString("0.00");
- lbItems.Items.Add(order); // Gets the selected pizza/pasta, the amount of items and the cost per pizza/pasta.
- _totalprice = double.Parse(tbTotalPizza.Text) + _totalprice; // Gets the "Prijs:" price and then adds it to _totalprice (0)
- tbTotalPrice.Text = _totalprice.ToString(); // Sets the price to the textblock
- ValidateInfo();
- }
- private void lbItems_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- // Removes the selected item when its double clicked.
- ComboBoxItem selectedMealCBI = (ComboBoxItem)cbPizzas.SelectedItem; // Gets the selected combo box item
- string selectedMeal = selectedMealCBI.Content.ToString(); // Converts it to a string
- lbItems.Items.RemoveAt(lbItems.SelectedIndex);
- double totalPriceLBI = _prijsgerecht * int.Parse(tbAmount.Text);
- string order = selectedMeal + ';' + "Totaal;" + "$" + totalPriceLBI.ToString("0.00");
- string[] splitOrder = order.Split('$');
- tbTotalPrice.Text = (_totalprice - double.Parse(splitOrder[1])).ToString();
- }
- private void cbPizzas_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- SetPrice(); // Executes the Set Price function
- }
- private void tbAmount_TextChanged(object sender, TextChangedEventArgs e)
- {
- try
- {
- SetPrice();
- items = int.Parse(tbAmount.Text);
- tbTotalPizza.Text = (_prijsgerecht * items).ToString(); // When the amount is changed, the "Prijs:" textblock gets updated
- }
- catch
- {
- MessageBox.Show("Vul een getal in!"); // When the input is invalid (e.g when its empty) this message appears
- }
- }
- private void rb25cm_Checked(object sender, RoutedEventArgs e)
- {
- SetPrice(); // When the 25cm button is checked, this code gets executed
- }
- private void rb35cm_Checked(object sender, RoutedEventArgs e)
- {
- SetPrice(); // When the 35cm button is checked, this code gets executed
- }
- }
- }
Add Comment
Please, Sign In to add comment