Guest User

Untitled

a guest
Dec 9th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. 'Program: Chapter 9 HandsOn
  2. 'Programmer: Paul Bock
  3. 'Date: 9/28/2012
  4. 'Page: Default
  5. 'Description: A Web site to calculate the extended price for books sold,
  6. ' a discount, and the discounted amount. Calculates and displays the total discounts.
  7. ' Uses validator controls for input validation.
  8.  
  9. Partial Class Webform1
  10.  
  11. Inherits System.Web.UI.Page
  12.  
  13. Private DiscountTotalDecimal As Decimal
  14. Const DISCOUNT_RATE_Decimal As Decimal = 0.15D
  15.  
  16. Sub SubmitButton_Click(ByVal sender As Object,
  17. ByVal e As System.EventArgs) Handles SubmitButton.Click
  18. 'Calculate values for sale.
  19. Dim QuantityInteger As Integer
  20. Dim PriceDecimal, ExtendedPriceDecimal As Decimal
  21. Dim DiscountDecimal, DiscountedPriceDecimal As Decimal
  22.  
  23. ErrorMessageLabel.Text = String.Empty
  24. Try
  25. ' Convert input values to numeric variables.
  26. QuantityInteger = Integer.Parse(QuantityTextBox.Text)
  27. PriceDecimal = Decimal.Parse(PriceTextBox.Text)
  28.  
  29. ' Calculate values for sale.
  30. ExtendedPriceDecimal = QuantityInteger * PriceDecimal
  31. DiscountDecimal = ExtendedPriceDecimal * DISCOUNT_RATE_Decimal
  32. DiscountedPriceDecimal = ExtendedPriceDecimal - DiscountDecimal
  33.  
  34. 'Add to the discount total.
  35. DiscountTotalDecimal += DiscountDecimal
  36.  
  37. ' Save the discount total in a label.
  38. DiscountHiddenField.Value = DiscountTotalDecimal.ToString()
  39.  
  40. ' Format and display answers.
  41. ExtendedPriceTextBox.Text = ExtendedPriceDecimal.ToString("C")
  42. DiscountTextBox.Text = DiscountDecimal.ToString("N")
  43. DiscountPriceTextBox.Text = DiscountedPriceDecimal.ToString("C")
  44. Catch ex As Exception
  45. ErrorMessageLabel.Text = "Unable to calculate. Check for numeric values."
  46.  
  47. End Try
  48.  
  49. End Sub
  50.  
  51. Private Sub ClearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ClearButton.Click
  52. ' Clear previous amounts from the page.
  53.  
  54. QuantityTextBox.Text = " "
  55. TitleTextBox.Text = " "
  56. PriceTextBox.Text = " "
  57. ExtendedPriceTextBox.Text = " "
  58. DiscountTextBox.Text = " "
  59. DiscountTotalLabel.Text = " "
  60. ErrorMessageLabel.Text = " "
  61.  
  62. End Sub
  63.  
  64. Sub Page_Load(ByVal sender As Object,
  65. ByVal e As System.EventArgs) Handles Me.Load
  66. ' Check for existing value for the discount total
  67.  
  68. With DiscountHiddenField
  69. If IsPostBack And .Value <> " " Then
  70. DiscountTotalDecimal = Decimal.Parse(.Value)
  71. End If
  72. End With
  73. End Sub
  74.  
  75. Private Sub SummaryButton_Click(ByVal sender As Object,
  76. ByVal e As System.EventArgs) Handles SummaryButton.Click
  77. ' Display the total discount.
  78.  
  79. DiscountTotalLabel.Text = "Total Discounts:" & DiscountTotalDecimal.ToString("C")
  80.  
  81. End Sub
  82.  
  83. Protected Overrides Sub Finalize()
  84. MyBase.Finalize()
  85. End Sub
  86. End Class
Add Comment
Please, Sign In to add comment