protected void Getdiscount_Click(object sender, EventArgs e)
        {
            // när beräkna rabatt klickats

            if (IsValid) {

                // och valideringen lyckats
                double userArmount;
                Double.TryParse(Amount.Text, out userArmount);

                // skapa nytt kvitto och kör Calculate funktionen som räknar ut de olika värdena
                var receipt = new Model.Receipt(userArmount);
                receipt.Calculate(userArmount);

                // lägg till värdena i kvittot och ändra till visible - true
                Subtotal.Text = String.Format("Totalt: {0:c}", receipt.Subtotal);
                Subtotal.Visible = true;

                DiscountRate.Text = String.Format("Rabattsats: {0:p0}", receipt.DiscountRate);
                DiscountRate.Visible = true;

                MoneyOff.Text = String.Format("Rabatt: {0:C}", receipt.MoneyOff);
                MoneyOff.Visible = true;

                Total.Text = String.Format("Att betala: {0:c2}", receipt.Total);
                Total.Visible = true;

            }
        }
        protected void CalculateButton_Click(object sender, EventArgs e)
        {
            float parsedValue;

            Model.Receipt receipt;

            // Only execute code if form data validated
            if (IsValid)
            {
                // Try parse userinput
                if (float.TryParse(UserInputTextbox.Text, out parsedValue))
                {
                    // Create new Receipt
                    receipt = new Model.Receipt(parsedValue);

                    // Set new Receipt values to literals for display on page.
                    SubtotalLiteral.Text     = String.Format("{0:c}", receipt.Subtotal);
                    MoneyOffLiteral.Text     = String.Format("{0:c}", receipt.MoneyOff);
                    DiscountRateLiteral.Text = String.Format("{0:p0}", receipt.DiscountRate);
                    TotalLiteral.Text        = String.Format("{0:c}", receipt.Total);

                    // Display Receipt
                    ReceiptContainer.Visible = true;
                }
            }
        }
Example #3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                try
                {
                    var           input   = InputTextBox.Text;
                    Model.Receipt Receipt = new Model.Receipt(double.Parse(input));
                    //Receipt.Calculate(double.Parse(input));

                    TotalLabel.Text           = String.Format("{0:c}", Receipt.Subtotal);
                    DiscountPercentLabel.Text = String.Format("{0:p0}", Receipt.DiscountRate);
                    DiscoutLabel.Text         = String.Format("{0:c}", Receipt.MoneyOff);
                    ToPayLabel.Text           = String.Format("{0:c}", Receipt.Total);

                    SummaryDiv.Visible = true;
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(String.Empty, ex.Message);
                }
            }
        }