Home

MS Visual Basic .NET Applications:
Georgetown Cleaning Services

 

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 Practical Learning: Introducing File-Based Databases

  1. Start a new Windows Forms Application named GCS5
  2. In the Solution Explorer, right-click Form1.vb and click Rename
  3. Change the name to OrderProcessing.vb
  4. Design the form as follows:
     
    Control Name Text Additional Properties
    GroupBox GroupBox   Order Identification  
    Label Label   Customer Name:  
    TextBox TextBox txtCustomerName    
    Label Label   Customer Phone:  
    TextBox TextBox txtCustomerPhone    
    Label Label   Date Left:  
    DateTimePicker DateTimePicker dtpDateLeft   Format: Custom
    Custom Format: dddd dd MMM yyyy
    Label Label   Time Left:  
    DateTimePicker DateTimePicker dtpTimeLeft   Format: Time
    Label Label   Date Expected:  
    DateTimePicker DateTimePicker dtpDateExpected   Format: Custom
    Custom Format: dddd dd MMM yyyy
    Label     Time Expected:  
    DateTimePicker DateTimePicker dtpTimeExpected   Format: Time
    GroupBox GroupBox   Order Processing  
    Label Label   Item Type  
    Label Label   Unit Price  
    Label Label   Qty  
    Label Label   Sub Total  
    Label Label   Shirts  
    TextBox TextBox txtShirtsUnitPrice 1.25 TextAlign: Right
    TextBox TextBox txtShirtsQuantity 0 TextAlign: Right
    TextBox TextBox txtShirtsSubTotal 0.00 TextAlign: Right
    Label Label   Pants  
    TextBox TextBox txtPantsUnitPrice 1.95 TextAlign: Right
    TextBox TextBox txtPantsQuantity   TextAlign: Right
    TextBox TextBox txtPantsSubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cboItem1 None  
    TextBox TextBox txtItem1UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem1Quantity 0 TextAlign: Right
    TextBox TextBox txtItem1SubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cboItem2 None  
    TextBox TextBox txtItem2UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem2Quantity 0 TextAlign: Right
    TextBox TextBox txtItem2SubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cboItem3 None  
    TextBox TextBox txtItem3UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem3Quantity 0 TextAlign: Right
    TextBox TextBox txtItem3SubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cboItem4 None  
    TextBox TextBox txtItem4UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem4Quantity 0 TextAlign: Right
    TextBox TextBox txtItem4SubTotal 0.00 TextAlign: Right
    GroupBox GroupBox   Order Summary  
    Label Label   Cleaning Total:  
    TextBox TextBox txtOrderTotal 0.00 TextAlign: Right
    Label Label   Tax Rate:  
    TextBox TextBox txtTaxRate 5.75 TextAlign: Right
    Label Label   %  
    Label Label   Tax Amount:  
    TextBox TextBox txtTaxAmount 0.00 TextAlign: Right
    Label Label   Net Price:  
    TextBox TextBox txtNetPrice 0.00 TextAlign: Right
    Button   btnClose Close  
    GroupBox     Maintenance  
    Button   btnSave... Save  
    Button   btnReset Reset  
    Label     Receipt #:  
    TextBox   txtReceiptNumber    
    Button   btnOpen Open...  
  5. Click each combo box. Access its Items property and fill it up as follows:
     
  6. Click OK and save All
  7. On the form, double-click the Time Left control and implement its ValueChanged event as follows:
     
    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
  8. Just under the above End Sub line, create the following procedure:
     
    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
  9. In the Class Name combo box, select txtShirtsQuantity
  10. In the Method Name combo box, select Leave  and implement the event as follows:
     
    Private Sub txtShirtsQuantity_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtShirtsQuantity.Leave
            CalculateTotal()
    End Sub
  11. In the Class Name combo box, select txtPantsQuantity
  12. In the Method Name combo box, select Leave and implement the event as follows:
     
    Private Sub txtPantsQuantity_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPantsQuantity.Leave
            CalculateTotal()
    End Sub
  13. In the Class Name combo box, select txtItem1Quantity
  14. In the Method Name combo box, select Leave and implement the event as follows:
     
    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
  15. In the Class Name combo box, select txtItem2Quantity
  16. In the Method Name combo box, select Leave and implement the event as follows:
     
    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
  17. In the Class Name combo box, select txtItem3Quantity
  18. In the Method Name combo box, select Leave and implement the event as follows:
     
    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
  19. In the Class Name combo box, select txtItem4Quantity
  20. In the Method Name combo box, select Leave and implement the event as follows:
     
    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
  21. In the Class Name combo box, select txtTaxRate
  22. In the Method Name combo box, select Leave and implement the event as follows:
     
    Private Sub txtTaxRate_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTaxRate.Leave
            CalculateTotal()
    End Sub
  23. In the Class Name combo box, select btnClose
  24. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
            End
    End Sub
  25. In the Class Name combo box, select btnReset
  26. In the Method Name combo box, select Click and implement the event as follows:
     
    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
  27. Save all
 

Home Copyright © 2004-2011 FunctionX Next