public Solution(Totals totals) { InitializeComponent(); tb_totalCost.Text = "$" + totals.GrandTotal.ToString(); tb_costPerPerson.Text = "$" + totals.GrandTotalPerPerson.ToString(); }
private void butt_calculate_Click(object sender, RoutedEventArgs e) { if (!IsWindowOpen <Solution>()) { try { string message = ""; int item1Cost, item1Quantity, item2Cost, item2Quantity, item3Cost, item3Quantity; int item1Total = 0, item2Total = 0, item3Total = 0; int grandTotal, grandTotalPerPerson; bool pass = true; ResetLabelColors(); if ((bool)rb_three.IsChecked) { //item three calcs if (!int.TryParse(tb_price3.Text, out item3Cost)) { lbl_price3.Foreground = Brushes.Red; tb_price3.Focus(); message += "Please enter cost of item three.\n"; pass = false; } if (!int.TryParse(tb_quantity3.Text, out item3Quantity)) { lbl_quantity3.Foreground = Brushes.Red; tb_quantity3.Focus(); message += "Please enter quantity of item three.\n"; pass = false; } item3Total = item3Cost * item3Quantity; item3Total -= (int)(item3Total * (int.Parse(tb_discount3.Text) / 100)); } if ((bool)rb_two.IsChecked || (bool)rb_three.IsChecked) { //item two calcs if (!int.TryParse(tb_price2.Text, out item2Cost)) { lbl_price2.Foreground = Brushes.Red; tb_price2.Focus(); message += "Please enter cost of item two.\n"; pass = false; } if (!int.TryParse(tb_quantity2.Text, out item2Quantity)) { lbl_quantity2.Foreground = Brushes.Red; tb_quantity2.Focus(); message += "Please enter quantity of item two.\n"; pass = false; } item2Total = item2Cost * item2Quantity; item2Total -= (int)(item2Total * (int.Parse(tb_discount2.Text) / 100)); } //item one calcs if (!int.TryParse(tb_price1.Text, out item1Cost)) { lbl_price1.Foreground = Brushes.Red; tb_price1.Focus(); message += "Please enter cost of item one.\n"; pass = false; } if (!int.TryParse(tb_quantity1.Text, out item1Quantity)) { lbl_quantity1.Foreground = Brushes.Red; tb_quantity1.Focus(); message += "Please enter quantity of item one.\n"; pass = false; } item1Total = item1Cost * item1Quantity; item1Total -= (int)(item1Total * (int.Parse(tb_discount1.Text) / 100)); if (pass) { //Final Math grandTotal = item1Total + item2Total + item3Total; grandTotalPerPerson = grandTotal / int.Parse(cb_roomates.Text); Totals totals = new Totals { GrandTotal = grandTotal, GrandTotalPerPerson = grandTotalPerPerson }; //print to solution window if (!IsWindowOpen <Solution>()) { Solution s = new Solution(totals); s.Show(); } } else { MessageBox.Show(message, "Error"); } } catch (Exception ex) { MessageBox.Show("Please enter a number in each box.", "Error"); } } }