MS Visual Basic .NET Applications: |
|
Introduction to Serialization |
This application follows the Georgetown Cleaning Services that primarily demonstrated the use of various Windows controls such as the date picker, the time picker, and bitmap buttons. One of the issues that was not dealt with was the ability to save the customers orders. In this application, after a customer's order has been processed, we will allow the user to save it. |
Practical Learning: Introducing File-Based Databases |
|
Private Sub dtpTimeLeft_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles dtpTimeLeft.ValueChanged Dim dateLeft As DateTime = Me.dtpDateLeft.Value Dim timeLeft As DateTime = Me.dtpTimeLeft.Value Dim time9AM As DateTime = New DateTime(timeLeft.Year, timeLeft.Month, timeLeft.Day, 9, 0, 0) ' if thenthe customer leaves clothes before 9AM... If timeLeft <= time9AM Then ' ... then they should be ready the same day after 5PM Me.dtpDateExpected.Value = dateLeft Me.dtpTimeExpected.Value = New DateTime(dateLeft.Year, dateLeft.Month, dateLeft.Day, 17, 0, 0) Else ' if thenthe clothese were left after 9AM, they will be availablethe following morning at 8AM Me.dtpDateExpected.Value = New DateTime(dateLeft.Year, dateLeft.Month, dateLeft.Day + 1) Me.dtpTimeExpected.Value = New DateTime(dateLeft.Year, dateLeft.Month, dateLeft.Day + 1, 8, 0, 0) End If End Sub |
Private Sub CalculateTotal() Dim unitPriceShirts As Double Dim unitPricePants As Double Dim unitPriceItem1 As Double Dim unitPriceItem2 As Double Dim unitPriceItem3 As Double Dim unitPriceItem4 As Double Dim subTotalShirts As Double Dim subTotalPants As Double Dim subTotalItem1 As Double Dim subTotalItem2 As Double Dim subTotalItem3 As Double Dim subTotalItem4 As Double Dim qtyShirts As Integer Dim qtyPants As Integer Dim qtyItem1 As Integer Dim qtyItem2 As Integer Dim qtyItem3 As Integer Dim qtyItem4 As Integer Dim cleaningTotal As Double Dim taxRate As Double Dim taxAmount As Double Dim netPrice As Double ' Retrieve the unit price of this item ' Just in case the user types an invalid value, we are using a try...catch Try unitPriceShirts = CDbl(Me.txtShirtsUnitPrice.Text) Catch exc As FormatException MsgBox("The value you entered for the price of shirts is not valid" & _ vbCrLf & "Please try again") End Try ' Retrieve the number of this item ' Just in case the user types an invalid value, we are using a try...catch Try qtyShirts = CInt(Me.txtShirtsQuantity.Text) Catch exc As FormatException MsgBox("The value you entered for the number of shirts is not valid" & _ vbCrLf & "Please try again") End Try Try unitPricePants = CDbl(Me.txtPantsUnitPrice.Text) Catch exc As FormatException MsgBox("The value you entered for the price of pants is not valid" & _ vbCrLf & "Please try again") End Try Try qtyPants = CInt(Me.txtPantsQuantity.Text) Catch exc As FormatException MsgBox("The value you entered for the number of pants is not valid" & _ vbCrLf & "Please try again") End Try Try unitPriceItem1 = CDbl(Me.txtItem1UnitPrice.Text) Catch exc As FormatException MsgBox("The value you entered for the price is not valid" & _ vbCrLf & "Please try again") End Try Try qtyItem1 = CInt(Me.txtItem1Quantity.Text) Catch exc As FormatException MsgBox("The value you entered is not valid" & _ vbCrLf & "Please try again") End Try Try unitPriceItem2 = CDbl(Me.txtItem2UnitPrice.Text) Catch exc As FormatException MsgBox("The value you entered for the price is not valid" & _ vbCrLf & "Please try again") End Try Try qtyItem2 = CInt(Me.txtItem2Quantity.Text) Catch exc As FormatException MsgBox("The value you entered is not valid" & _ vbCrLf & "Please try again") End Try Try unitPriceItem3 = CDbl(Me.txtItem3UnitPrice.Text) Catch exc As FormatException MsgBox("The value you entered for the price is not valid" & _ vbCrLf & "Please try again") End Try Try qtyItem3 = CInt(Me.txtItem3Quantity.Text) Catch exc As FormatException MsgBox("The value you entered is not valid" & _ vbCrLf & "Please try again") End Try Try unitPriceItem4 = CDbl(Me.txtItem4UnitPrice.Text) Catch exc As FormatException MsgBox("The value you entered for the price is not valid" & _ vbCrLf & "Please try again") End Try Try qtyItem4 = CInt(Me.txtItem4Quantity.Text) Catch exc As FormatException MsgBox("The value you entered is not valid" & _ vbCrLf & "Please try again") End Try ' Calculate the sub-total for this item subTotalShirts = qtyShirts * unitPriceShirts subTotalPants = qtyPants * unitPricePants subTotalItem1 = qtyItem1 * unitPriceItem1 subTotalItem2 = qtyItem2 * unitPriceItem2 subTotalItem3 = qtyItem3 * unitPriceItem3 subTotalItem4 = qtyItem4 * unitPriceItem4 ' Calculate the total based on sub-totals cleaningTotal = subTotalShirts + subTotalPants + subTotalItem1 + _ subTotalItem2 + subTotalItem3 + subTotalItem4 taxRate = CDbl(Me.txtTaxRate.Text) ' Calculate the amount owed for the taxes taxAmount = cleaningTotal * taxRate / 100 ' Add the tax amount to the total order netPrice = cleaningTotal + taxAmount ' Display the sub-total in the corresponding text box Me.txtShirtsSubTotal.Text = subTotalShirts.ToString("F") Me.txtPantsSubTotal.Text = subTotalPants.ToString("F") Me.txtItem1SubTotal.Text = subTotalItem1.ToString("F") Me.txtItem2SubTotal.Text = subTotalItem2.ToString("F") Me.txtItem3SubTotal.Text = subTotalItem3.ToString("F") Me.txtItem4SubTotal.Text = subTotalItem4.ToString("F") Me.txtCleaningTotal.Text = cleaningTotal.ToString("F") Me.txtTaxAmount.Text = taxAmount.ToString("F") Me.txtNetPrice.Text = netPrice.ToString("F") End Sub |
Private Sub txtShirtsQuantity_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtShirtsQuantity.Leave CalculateTotal() End Sub |
Private Sub txtPantsQuantity_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPantsQuantity.Leave CalculateTotal() End Sub |
Private Sub txtItem1Quantity_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtItem1Quantity.Leave If Me.cboItem1.Text <> "None" Then CalculateTotal() Else MsgBox("Make sure you select an item in the combo box") End If End Sub |
Private Sub txtItem2Quantity_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtItem2Quantity.Leave If Me.cboItem2.Text <> "None" Then CalculateTotal() Else MsgBox("Make sure you select an item in the combo box") End If End Sub |
Private Sub txtItem3Quantity_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtItem3Quantity.Leave If Me.cboItem3.Text <> "None" Then CalculateTotal() Else MsgBox("Make sure you select an item in the combo box") End If End Sub |
Private Sub txtItem4Quantity_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtItem4Quantity.Leave If Me.cboItem4.Text <> "None" Then CalculateTotal() Else MsgBox("Make sure you select an item in the combo box") End If End Sub |
Private Sub txtTaxRate_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTaxRate.Leave CalculateTotal() End Sub |
Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click End End Sub |
Private Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click ' Reset the controls Me.txtCustomerName.Text = "" Me.txtCustomerPhone.Text = "" Me.txtShirtsUnitPrice.Text = "1.25" Me.txtShirtsQuantity.Text = "0" Me.txtShirtsSubTotal.Text = "0.00" Me.txtPantsUnitPrice.Text = "1.95" Me.txtPantsQuantity.Text = "0" Me.txtPantsSubTotal.Text = "0.00" Me.cboItem1.Text = "None" Me.txtItem1UnitPrice.Text = "0.00" Me.txtItem1Quantity.Text = "0" Me.txtItem1SubTotal.Text = "0.00" Me.cboItem2.Text = "None" Me.txtItem2UnitPrice.Text = "0.00" Me.txtItem2Quantity.Text = "0" Me.txtItem2SubTotal.Text = "0.00" Me.cboItem3.Text = "None" Me.txtItem3UnitPrice.Text = "0.00" Me.txtItem3Quantity.Text = "0" Me.txtItem3SubTotal.Text = "0.00" Me.cboItem4.Text = "None" Me.txtItem4UnitPrice.Text = "0.00" Me.txtItem4Quantity.Text = "0" Me.txtItem4SubTotal.Text = "0.00" Me.txtCleaningTotal.Text = "0.00" Me.txtTaxRate.Text = "5.75" Me.txtTaxAmount.Text = "0.00" Me.txtNetPrice.Text = "0.00" Me.txtCustomerName.Focus() End Sub |
|
||
Home | Copyright © 2004-2012, FunctionX | Next |
|