Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class CaseStudyCh3_Auto_Center
- 'Declares commission rate @ 20%.
- Const CommissionRateDecimal As Decimal = 0.2D
- Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
- 'Declares variables used in calculation; Sales price, cost price, commission, and MessageString.
- Dim MessageString As String
- Dim SalesPriceDecimal, CostPriceDecimal, CommissionDecimal As Decimal
- Dim HaveValidInputs As Boolean
- HaveValidInputs = True
- 'Confirms employee's name is entered
- If String.IsNullOrEmpty(EmployeeNameTextBox.Text) Then
- HaveValidInputs = False
- 'Displays error if employee's name is omitted.
- MessageString = "Please enter employee's name."
- MessageBox.Show(MessageString, "Error, Will Robinson!", MessageBoxButtons.OK)
- With EmployeeNameTextBox
- .Focus()
- .SelectAll()
- End With
- End If
- If HaveValidInputs = True Then
- Try
- SalesPriceDecimal = Decimal.Parse(SalesPriceTextBox.Text)
- Catch SalesPriceException As FormatException
- HaveValidInputs = False
- 'Catches sales price exception if input is not formatted as a decimal value.
- MessageString = "Please enter sales price as a decimal with no dollar signs."
- MessageBox.Show(MessageString, "Error, Will Robinson!",
- MessageBoxButtons.OK)
- With SalesPriceTextBox
- .Focus()
- .SelectAll()
- End With
- End Try
- End If
- If HaveValidIputs = True Then
- Try
- CostPriceDecimal = Decimal.Parse(CostPriceTextBox.Text)
- Catch CostPriceException As FormatException
- HaveValidInputs = False
- 'Catches cost price exception if input is not formatted as a decimal.
- MessageString = "Please enter cost price as a decimal with no dollar signs."
- MessageBox.Show(MessageString, "Error, Will Robinson!", MessageBoxButtons.OK)
- With CostPriceTextBox
- .Focus()
- .SelectAll()
- End With
- End Try
- End If
- If HaveValidInputs = True Then
- 'Calculates commission for employee.
- If SalesPriceDecimal > CostPriceDecimal Then
- CommissionDecimal = CommissionRateDecimal * (SalesPriceDecimal - CostPriceDecimal)
- Else
- CommissionDecimal = 0
- End If
- 'Displays commission total in text field.
- CommissionTextBox.Text = CommissionDecimal.ToString("C")
- End If
- End Sub
- Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
- 'Clears all fields for new entry.
- With EmployeeNameTextBox
- .Clear()
- .Focus()
- End With
- SalesPriceTextBox.Clear()
- CostPriceTextBox.Clear()
- CommissionTextBox.Clear()
- End Sub
- Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
- 'Prints the form; need that $$$BLINGBLING$$$!
- PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
- PrintForm1.Print()
- End Sub
- Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
- 'Closes the program.
- Me.Close()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement