Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Program: Chapter 9 HandsOn
- 'Programmer: Paul Bock
- 'Date: 9/28/2012
- 'Page: Default
- 'Description: A Web site to calculate the extended price for books sold,
- ' a discount, and the discounted amount. Calculates and displays the total discounts.
- ' Uses validator controls for input validation.
- Partial Class Webform1
- Inherits System.Web.UI.Page
- Private DiscountTotalDecimal As Decimal
- Const DISCOUNT_RATE_Decimal As Decimal = 0.15D
- Sub SubmitButton_Click(ByVal sender As Object,
- ByVal e As System.EventArgs) Handles SubmitButton.Click
- 'Calculate values for sale.
- Dim QuantityInteger As Integer
- Dim PriceDecimal, ExtendedPriceDecimal As Decimal
- Dim DiscountDecimal, DiscountedPriceDecimal As Decimal
- ErrorMessageLabel.Text = String.Empty
- Try
- ' Convert input values to numeric variables.
- QuantityInteger = Integer.Parse(QuantityTextBox.Text)
- PriceDecimal = Decimal.Parse(PriceTextBox.Text)
- ' Calculate values for sale.
- ExtendedPriceDecimal = QuantityInteger * PriceDecimal
- DiscountDecimal = ExtendedPriceDecimal * DISCOUNT_RATE_Decimal
- DiscountedPriceDecimal = ExtendedPriceDecimal - DiscountDecimal
- 'Add to the discount total.
- DiscountTotalDecimal += DiscountDecimal
- ' Save the discount total in a label.
- DiscountHiddenField.Value = DiscountTotalDecimal.ToString()
- ' Format and display answers.
- ExtendedPriceTextBox.Text = ExtendedPriceDecimal.ToString("C")
- DiscountTextBox.Text = DiscountDecimal.ToString("N")
- DiscountPriceTextBox.Text = DiscountedPriceDecimal.ToString("C")
- Catch ex As Exception
- ErrorMessageLabel.Text = "Unable to calculate. Check for numeric values."
- End Try
- End Sub
- Private Sub ClearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ClearButton.Click
- ' Clear previous amounts from the page.
- QuantityTextBox.Text = " "
- TitleTextBox.Text = " "
- PriceTextBox.Text = " "
- ExtendedPriceTextBox.Text = " "
- DiscountTextBox.Text = " "
- DiscountTotalLabel.Text = " "
- ErrorMessageLabel.Text = " "
- End Sub
- Sub Page_Load(ByVal sender As Object,
- ByVal e As System.EventArgs) Handles Me.Load
- ' Check for existing value for the discount total
- With DiscountHiddenField
- If IsPostBack And .Value <> " " Then
- DiscountTotalDecimal = Decimal.Parse(.Value)
- End If
- End With
- End Sub
- Private Sub SummaryButton_Click(ByVal sender As Object,
- ByVal e As System.EventArgs) Handles SummaryButton.Click
- ' Display the total discount.
- DiscountTotalLabel.Text = "Total Discounts:" & DiscountTotalDecimal.ToString("C")
- End Sub
- Protected Overrides Sub Finalize()
- MyBase.Finalize()
- End Sub
- End Class
Add Comment
Please, Sign In to add comment