Vous êtes sur la page 1sur 4

'Project: case study (premiere products)

'Purpose: illustrates understanding of functions and sub procedures


' calculates total charge for products purchased
'Created by: Cheril Grimmett on 1/27/11
'Modified by: Jared Clark on 1/24/14
' Found logic errors: total variable was used in tax calculation before
it was assigned value,
' total variable was assigned value of the index of
the price list,
' and total variable was not reset when reset
button was pressed.
' Fixed logic errors. Total now assigned value before tax calculation,
assigned the value of the list
' rather the index number, and now resets
correctly.
' Created function to handle the calculation of total, tax, and
totalCharge.
' Created function to reset the value of total.
' Created sub to display values.
'Modified by: Jared Clark on 2/17/14
' Replaced part number and price listbox with a display label and two
arrays. Previous functions and subs
' updated accordingly.
' Added second form. To be coded later.
'Modified by: Jared Clark on 3/9/14
' Enabled listbox to display entire list.
' Purchased products now correctly display in displayLabel.
' Added menu items and submenu items File (Save, open, exit), Edit
(undo, copy, cut, paste), format(font),
' print, and help (About Premier Products) on main
form.
' Added menu items and submenu items File (Add, Exit) on add form.
' Coded menu and submenu items.
' Coded function in add menu to check for accurate part numbers when
added.
'Modified by: Jared Clark on 3/24/14
' Coded second form to write new product number, product name, and
product price to a file
' Coded event handler for the add button to also handle the add submenu
option
' Function "checkProCode" is now a sub
' Removed arrays


Option Explicit On
Option Strict On
Option Infer Off

Public Class mainForm
Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
'write listbox
Dim theProduct As New Product
theProduct.writeListBox()
End Sub

Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles exitButton.Click
'close application
Close()
End Sub

Private Sub resetButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles resetButton.Click
'reset text and listbox
totalChargeLabel.ResetText()
totalLabel.ResetText()
taxLabel.ResetText()
displayLabel.ResetText()

productListbox.SelectedIndex = 0
End Sub

Private Sub enterButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles enterButton.Click
Static total As Single 'retains every price as items for a single order are
selected
Dim tax, totalCharge As Single
Dim partPrice As Single
Dim partNum As String
Dim theProduct As New Product

'call function to reset total for new customer
total = resetTotal(total)

'Get the price of the selected product
total += theProduct.getPrice

'Write the individual price for each product
partPrice = theProduct.getPrice

'Get the product number
partNum = theProduct.getPart

'call function to calculate sales tax
tax = calcTax(total)

'call function to calculate total charge
totalCharge = calcTotal(total, tax)

'call sub to display results
display(total, tax, totalCharge, partPrice, partNum)
End Sub

Private Function calcTax(ByVal T As Single) As Single
'calculate sales tax based on tax rate
Const taxRate As Decimal = 0.09D

Return T * taxRate
End Function

Private Function calcTotal(ByVal P As Single, ByVal T As Single) As Single
'calculate total charge
Return (P + T)
End Function

Private Sub display(ByVal P As Single, ByVal T As Single, ByVal C As Single, ByVal Pa
As Single, ByVal N As String)
'display results
totalLabel.Text = P.ToString("c2")
taxLabel.Text = T.ToString("c2")
totalChargeLabel.Text = C.ToString("c2")

'display price and product number
displayLabel.Text += Pa.ToString("c2") & " " & N &
ControlChars.NewLine
End Sub
Private Function resetTotal(ByVal T As Single) As Single
'if the reset button has been pressed, then this function will set the static
total to 0
'otherwise, it will return the current value of "total"
Select Case True
Case totalLabel.Text = ""
Return 0
Case Else
Return T
End Select
End Function

Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles addButton.Click
'bring up the add form
addForm.Show()
End Sub

Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SaveToolStripMenuItem.Click
'save file
SaveFileDialog1.ShowDialog()
End Sub

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OpenToolStripMenuItem.Click
'open file
OpenFileDialog1.ShowDialog()
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ExitToolStripMenuItem.Click
'close application. Identical to exit button
Close()
End Sub

Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles FontToolStripMenuItem.Click
'open font menu
FontDialog1.ShowDialog()
End Sub

Private Sub AboutPremierProductsToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
AboutPremierProductsToolStripMenuItem.Click
'Display message under help item
MsgBox("Premium products is a distributor of appliances, housewares, and sporting
goods.")
End Sub

Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PrintToolStripMenuItem.Click
'Open print preview
PrintPreviewDialog1.ShowDialog()
End Sub

End Class

Vous aimerez peut-être aussi