protected void SendButton_Click(object sender, EventArgs e) { if (Page.IsValid) { Receipt receipt = new Receipt(new double()); receipt.Calculate(double.Parse(InputBox.Text)); Total.Text = String.Format("{0:c}",receipt.Subtotal); Rabattsats.Text = String.Format("{0}%",receipt.DiscountRate); Rabatt.Text = String.Format("{0:c}", receipt.MoneyOff); Pay.Text = String.Format("{0:c}", receipt.Total); Kvitto.Visible = true; } }
protected void CalcDiscount_Click(object sender, EventArgs e) { if (IsValid) { double theSum; if (double.TryParse(InputField.Text, out theSum)) // lika bra att va extra säker med tryparse { Receipt rec = new Receipt(theSum); rec.Calculate(theSum); DrawReceipt(rec); } else { ErrorText.Text = "Error! Något blev fel vid parsningen"; } } }