![]() |
Visual Basic .NET Examples: Georgetown Cleaning Services |
Some times if you are asked to create an application
for a store that sells a specific number of items based on a fixed list,
you may ask for the list of items so you can create its elements in the
application. Here is an example: ![]() For such an application, when the list of items changes, you may have to modify the application, recompile, and redistribute (or re-install it). One solution to this problem would consist of providing placeholders for an employee to fill out and process the order with them. Another problem that can be common with this type of application is that, while the form may be crowded with too many objects, most of the time, some items are rarely ordered. In this exercise, to make this type of application a little more flexible, we will use a few combo boxes that allow the user to simply select the items that are valid for the order.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Application Implementation |
|
As a dry cleaning applications, there are some behaviors we will apply. About dates, if a customer leaves his or her clothes in the morning before 9AM, we will promise that the clothes can be ready on the same day after 5PM. If a customer leaves the clothes after 9AM, they will be ready only the following day. To process an order, we provided the clerk with 4 combo boxes to select some of the most regularly ordered cleaning items. The combo boxes also allow the user to type an item that is not in the list. Also, because we can't or we won't predict the prices of these items, we let the user specify their price. Once an order is ready, we will calculate it using classic operations. |
|
|
Private Sub dtpDateLeft_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpDateLeft.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 the 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 the 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 btnCalcShirts_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalcShirts.Click
Dim quantity As Integer = 1
Dim unitPrice As Double
Dim subTotal As Double
' Retrieve the number of this item
' Just in case the user types an invalid value, we are using a try...catch
Try
quantity = CInt(Me.txtShirtsQuantity.Text)
Catch ex As FormatException
MsgBox("The value you entered for the number of shirts is not valid" & _
vbCrLf & "Please try again")
End Try
' Retrieve the unit price of this item
' Just in case the user types an invalid value, we are using a try...catch
Try
unitPrice = CDbl(Me.txtShirtsUnitPrice.Text)
Catch ex As FormatException
MsgBox("The value you entered for the price of shirts is not valid" & _
vbCrLf & "Please try again")
End Try
' Calculate the sub-total for this item
subTotal = quantity * unitPrice
' Display the sub-total in the corresponding text box
Me.txtShirtsSubTotal.Text = subTotal.ToString("F")
End Sub
|
Private Sub btnCalcPants_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalcPants.Click
Dim quantity As Integer = 1
Dim unitPrice As Double
Dim subTotal As Double
Try
quantity = CInt(Me.txtPantsQuantity.Text)
Catch ex As FormatException
MsgBox("The value you entered for the number of pants is not valid" & _
vbCrLf & "Please try again")
End Try
Try
unitPrice = CDbl(Me.txtPantsUnitPrice.Text)
Catch ex As FormatException
MsgBox("The value you entered for the price of pants is not valid" & _
vbCrLf & "Please try again")
End Try
subTotal = quantity * unitPrice
Me.txtPantsSubTotal.Text = subTotal.ToString("F")
End Sub
|
Private Sub btnCalcItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalcItem1.Click
Dim quantity As Integer = 1
Dim unitPrice As Double
Dim subTotal As Double
Try
quantity = CInt(Me.txtItem1Quantity.Text)
Catch ex As FormatException
MsgBox("The value you entered is not valid" & _
vbCrLf & "Please try again")
End Try
Try
unitPrice = CDbl(Me.txtItem1UnitPrice.Text)
Catch ex As FormatException
MsgBox("The value you entered for the price is not valid" & _
vbCrLf & "Please try again")
End Try
subTotal = quantity * unitPrice
Me.txtItem1SubTotal.Text = subTotal.ToString("F")
End Sub
|
Private Sub btnCalcItem2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalcItem2.Click
Dim quantity As Integer = 1
Dim unitPrice As Double
Dim subTotal As Double
Try
quantity = CInt(Me.txtItem2Quantity.Text)
Catch ex As FormatException
MsgBox("The value you entered is not valid" & _
vbCrLf & "Please try again")
End Try
Try
unitPrice = CDbl(Me.txtItem2UnitPrice.Text)
Catch ex As FormatException
MsgBox("The value you entered for the price is not valid" & _
vbCrLf & "Please try again")
End Try
subTotal = quantity * unitPrice
Me.txtItem2SubTotal.Text = subTotal.ToString("F")
End Sub
|
Private Sub btnCalcItem3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalcItem3.Click
Dim quantity As Integer = 1
Dim unitPrice As Double
Dim subTotal As Double
Try
quantity = CInt(Me.txtItem3Quantity.Text)
Catch ex As FormatException
MsgBox("The value you entered is not valid" & _
vbCrLf & "Please try again")
End Try
Try
unitPrice = CDbl(Me.txtItem3UnitPrice.Text.)
Catch ex As FormatException
MsgBox("The value you entered for the price is not valid" & _
vbCrLf & "Please try again")
End Try
subTotal = quantity * unitPrice
Me.txtItem3SubTotal.Text = subTotal.ToString("F")
End Sub
|
Private Sub btnCalcItem4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalcItem4.Click
Dim quantity As Integer = 1
Dim unitPrice As Double
Dim subTotal As Double
Try
quantity = CInt(Me.txtItem4Quantity.Text)
Catch ex As FormatException
MsgBox("The value you entered is not valid" & _
vbCrLf & "Please try again")
End Try
Try
unitPrice = CDbl(Me.txtItem4UnitPrice.Text)
Catch ex As FormatException
MsgBox("The value you entered for the price is not valid" & _
vbCrLf & "Please try again")
End Try
subTotal = quantity * unitPrice
Me.txtItem4SubTotal.Text = subTotal.ToString("F")
End Sub
|
Private Sub btnCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim priceShirts As Double
Dim pricePants As Double
Dim priceItem1 As Double
Dim priceItem2 As Double
Dim priceItem3 As Double
Dim priceItem4 As Double
Dim totalOrder As Double
Dim taxRate As Double
Dim taxAmount As Double
Dim netPrice As Double
' Retrieve the value of the sub-total for each category of items
priceShirts = CDbl(Me.txtShirtsSubTotal.Text)
pricePants = CDbl(Me.txtPantsSubTotal.Text)
priceItem1 = CDbl(Me.txtItem1SubTotal.Text)
priceItem2 = CDbl(Me.txtItem2SubTotal.Text)
priceItem3 = CDbl(Me.txtItem3SubTotal.Text)
priceItem4 = CDbl(Me.txtItem4SubTotal.Text)
' Calculate the total
totalOrder = priceShirts + pricePants + _
priceItem1 + priceItem2 + priceItem3 + priceItem4
' Retrieve the value of the tax rate
Try
taxRate = CDbl(Me.txtTaxRate.Text)
Catch ex As FormatException
MsgBox("The tax rate you entered is invalid" & _
vbCrLf & "Please try again")
End Try
' Calculate the amount owed for the taxes
taxAmount = totalOrder * taxRate / 100
' Add the tax amount to the total order
netPrice = totalOrder + taxAmount
' Display the values of the order summary
Me.txtOrderTotal.Text = totalOrder.ToString("C")
Me.txtTaxAmount.Text = taxAmount.ToString("C")
Me.txtOrderPrice.Text = netPrice.ToString("C")
End Sub
|
|
|
||
| Home | Copyright © 2004-2005 FunctionX, Inc. | |
|
|
||