frmMailOrder2.vb ' RobinsonGeorge05 ' Very Busy Mail Order 2 ' Programmer: George Robinson ' Chapter 6 LAB Assignment: Mail Order 2 ' Create a project that allows the user to input an item name, quantity desired, weight, price and ' “ship to” state (a 2 letter state abbreviation). All input is to be from textboxes-you are not ' allowed to use any type of list control for State. The project will calculate the total amount due ' For Each order. ' An order may consist Of one Or more items but the ship To state (can only be Thentered at the start Of ' the order When the first item Is entered. Option Explicit On Option Strict On Public Class frmMailOrder2 ' Functions for Sales Tax Calculation and Shipping & Handling Function salesTaxCalculator(ByVal strState As String, ByVal dblAmountDue As Double) As Double Dim dblSalesTax As Double = 0.0 'Processing If strState = "CA" Then dblSalesTax = 0.08 End If ' Calculate the Sales Tax dblSalesTax *= dblAmountDue 'Return Results Return dblSalesTax End Function Function shippingHandlingCalc(ByVal dblTotalWeight As Double) As Double Dim dblHandling As Double 'Calculate Handling Select Case dblTotalWeight Case 0 To 10 dblHandling = 1 Case 10 To 100 dblHandling = 3 Case > 100 dblHandling = 5 End Select 'Calculate Shipping dblTotalWeight = Math.Floor(dblTotalWeight) * 0.25 'Calculate Shipping and Handling dblHandling += dblTotalWeight 'Return Results Return dblHandling End Function ' Global Variable for frmMailOrder Public shippingWeight As Double Public totalOrderCharge As Double Public deliveryState As String Private Sub frmMailOrder2_Load(sender As Object, e As EventArgs) Handles Me.Load ' Locking down the maximum length of the State entry to only two characters txtShippingStateInput.MaxLength = 2 btnCompleteOrder.Enabled = False btnNewOrder.Enabled = False ' Establish Clock and Programmer Information lblDate.Text = "Date " & Now().ToString tmrNow.Enabled = True tmrNow.Interval = 1000 lblPrgm.Text = lblPrgm.Text & " George Robinson" End Sub Private Sub tmrNow_Tick(sender As Object, e As EventArgs) Handles tmrNow.Tick lblDate.Text = "Date: " & Now.ToString() End Sub Private Sub btnAddItem_Click(sender As Object, e As EventArgs) Handles btnAddItem.Click Try ' /// ' INPUT VALIDATION FUNCTIONS - found down at the bottom of the code {There are 3 of them, two call on the others} ' /// If isString(txtItemNameInput.Text) = False Then MessageBox.Show("Please enter a string into the Item Name text box.", "Needs A String", MessageBoxButtons.OK, MessageBoxIcon.Information) txtItemNameInput.Focus() ElseIf isInteger(txtQtyDesiredInput.Text) = False Then MessageBox.Show("Please enter an integer into the Quantity Desired text box.", "Needs An Integer", MessageBoxButtons.OK, MessageBoxIcon.Information) txtQtyDesiredInput.Focus() ElseIf isANumber(txtWeightInput.Text) = False Then MessageBox.Show("Please enter a number into the Weight text box.", "Needs A Number", MessageBoxButtons.OK, MessageBoxIcon.Information) txtWeightInput.Focus() ElseIf isANumber(txtPriceInput.Text) = False Then MessageBox.Show("Please enter a number into the Price Input text box.", "Needs A Number", MessageBoxButtons.OK, MessageBoxIcon.Information) txtPriceInput.Focus() ElseIf isString(txtShippingStateInput.Text) = False Then MessageBox.Show("Please enter a string into the Shipping State text box.", "Needs A String", MessageBoxButtons.OK, MessageBoxIcon.Information) txtShippingStateInput.Focus() Else ' Diable Shipping State Input txtShippingStateInput.Enabled = False ' Enable Buttons for Complete Order and New Order btnCompleteOrder.Enabled = True btnNewOrder.Enabled = True ' Reset Focus to top of input. txtItemNameInput.Focus() ' Output to Public Variables shippingWeight += (CDbl(txtWeightInput.Text) * CDbl(txtQtyDesiredInput.Text)) totalOrderCharge += (CDbl(txtPriceInput.Text) * CDbl(txtQtyDesiredInput.Text)) deliveryState = txtShippingStateInput.Text End If Catch ex As Exception MessageBox.Show("Something wrong happened!", "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btnClearItem_Click(sender As Object, e As EventArgs) Handles btnClearItem.Click txtItemNameInput.Clear() txtPriceInput.Clear() txtQtyDesiredInput.Clear() txtWeightInput.Clear() txtItemNameInput.Focus() If txtShippingStateInput.Enabled = True Then txtShippingStateInput.Clear() End If End Sub Private Sub btnCompleteOrder_Click(sender As Object, e As EventArgs) Handles btnCompleteOrder.Click frmCompleteOrder.Show() End Sub Private Sub btnNewOrder_Click(sender As Object, e As EventArgs) Handles btnNewOrder.Click Dim userInput As DialogResult = MessageBox.Show("Are you sure you wish to start a new order and clear all order data?", "Clear Order?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) If userInput = DialogResult.Yes Then txtShippingStateInput.Enabled = True btnClearItem_Click(sender, e) shippingWeight = 0 totalOrderCharge = 0 deliveryState = "" btnCompleteOrder.Enabled = False End If End Sub Private Sub btnExitProgram_Click(sender As Object, e As EventArgs) Handles btnExitProgram.Click Me.Close() End Sub Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitTool.Click Me.Close() End Sub Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutTool.Click MessageBox.Show("The programmer of this wonderful tool is George Robinson.", "About this program", MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub 'Functions to Validate the inputs Function isString(ByVal strvalue As String) As Boolean Dim stringFlag As Boolean = False If strvalue = "" Then 'Tested to see if anything was there Else ' If all above values are false, then Boolean becomes True stringFlag = True End If ' Return boolean value to program Return stringFlag End Function Function isANumber(ByVal numvalue As String) As Boolean Dim dblFlag As Boolean = False If isString(numvalue) = False Then ' Tested to see if anything was there ElseIf IsNumeric(numvalue) = False Then ' Checking to see if the value is a number ElseIf CDbl(numvalue) <= 0 Then ' Checking to see if the number is greater than zero. Else ' If all above values are false, then Boolean becomes True dblFlag = True End If ' Return boolean value to program Return dblFlag End Function Function isInteger(ByVal intvalue As String) As Boolean Dim intFlag As Boolean = False If isANumber(intvalue) = False Then ' Tested to see if it is matches a number or string requirements. ElseIf Math.Floor(CDbl(intvalue)) <> Math.Ceiling(CDbl(intvalue)) Then ' Checking to see if the number is greater than zero. Else ' If all above values are false, then Boolean becomes True intFlag = True End If ' Return boolean value to program Return intFlag End Function End Class frmCompleteOrder.vb Public Class frmCompleteOrder Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click Me.Close() End Sub Private Sub frmCompleteOrder_Load(sender As Object, e As EventArgs) Handles Me.Load Dim orderSubTotal As Double = frmMailOrder2.totalOrderCharge Dim shippingCost As Double = frmMailOrder2.shippingHandlingCalc(frmMailOrder2.shippingWeight) Dim salesTax As Double = frmMailOrder2.salesTaxCalculator(frmMailOrder2.deliveryState, orderSubTotal) Dim orderTotal As Double = orderSubTotal + shippingCost + salesTax lblOrderAmt.Text = orderSubTotal.ToString("c") lblSalesTax.Text = salesTax.ToString("c") lblShipping.Text = shippingCost.ToString("c") lblTotalDue.Text = orderTotal.ToString("c") End Sub End Class