You are on page 1of 4

'Project: ticket master case project

'Purpose: Displays billing info for Temple Town Theatre


' Displays ticket cost, tax, and totals
'Created by: Jennifer Pierce on 2/16/13
'Updated by: Jennifer Pierce on 4/23/13 - corrected code and updated
comments
Public Class billingForm
Private Sub billingForm_Load(sender As Object, e As EventArgs) Handles MyBas
e.Load
'Display billing number
Dim strBillNum As String
strBillNum = getRandomNum()
txtBillNum.Text = strBillNum
txtTickets.Text = gTkts.ToString
End Sub
Private Sub btnTotal_Click(sender As Object, e As EventArgs) Handles btnTota
l.Click
'declare variables for storing ticket cost items
Dim dblPrice, dblCost, dblTax, dblTotal As Double
Dim intTickets As Integer
'try to convert string input to integer
intTickets = gTkts
' Call method to get pricing information
dblPrice = getPricing()
If txtName.Text = String.Empty Or txtTickets.Text = String.Empty Then
'Or IsNumeric(txtTickets.Text) = False
'call method to display error message
displayError()
ElseIf intTickets < 1 Or intTickets > 40 Then
'call method to display error messages
displayError()
Else 'If text boxes contain text, continue
'Determine cost of tickets
dblCost = getCost(intTickets, dblPrice)
dblTotal += dblCost 'Add cost of tickets to subtotal
'Determine tax amount
dblTax = getTax(intTickets, dblPrice)
dblTotal += dblTax 'Add tax amount to subtotal
'Display total cost
lstPrices.Items.Add("---------")
lstPrices.Items.Add(dblTotal.ToString("C2"))
End If
End Sub
Private Function getCost(ByVal tickets As Integer, ByVal price As Double) As
Double
'Declare variables
'get text of selected event from main form
Dim strEventName As String = mainForm.eventsListbox.SelectedItem
Dim total As Double
'update the event name on the form
lstItems.Items.Add(strEventName)
'Determine ticket cost
total = tickets * price
'Display ticket cost on form
lstPrices.Items.Add(total.ToString("C2"))
lstQuant.Items.Add(txtTickets.Text)
'return the total to function call
Return total
End Function
Private Function getTax(ByVal subTotal As Double, ByVal price As Double) As
Double
Dim tax As Double
Dim taxrate As Double = 0.9 'tax rate
'Determine tax amount
tax = taxrate * subTotal
'Display tax amount on form
lstItems.Items.Add("Tax")
lstItems.Items.Add(" ")
lstItems.Items.Add("TOTAL")
lstPrices.Items.Add(" ")
lstPrices.Items.Add(tax.ToString("C2"))
Return tax
End Function
Private Function getRandomNum() As String
Dim randomNum As String
Dim int1, int2, int3 As Integer ' Three random integers
Dim randomGenerator As New Random
'Generate the three random ints
int1 = randomGenerator.Next(10, 51)
int2 = randomGenerator.Next(20, 61)
int3 = randomGenerator.Next(30, 71)
'concatenate random integers in a string
randomNum = int1.ToString & int2.ToString & int3.ToString
'Return the string value
Return randomNum
End Function
Private Function getPricing() As Double
'variable to return price
Dim dblPrice As Double
'Determine event type from the selected item on the main form
If mainForm.concertRadio.Checked Then
dblPrice = 40
ElseIf mainForm.theaterRadio.Checked Then
dblPrice = 30
ElseIf mainForm.otherRadio.Checked Then
dblPrice = 25
End If
'Return the price
Return dblPrice
End Function
Private Sub btnReturn_Click(sender As Object, e As EventArgs) Handles btnRet
urn.Click
'Change focus to main form
mainForm.Focus()
'Close out the billing form
Me.Close()
End Sub
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrin
t.Click
'Print to print preview window
PrintForm.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm.Print()
End Sub
Private Sub displayError()
'Display error message
MessageBox.Show("Please enter a customer name and the number of tickets
required. No. of Tickets must be a valid number between 1 and 40.")
txtName.Text = String.Empty
txtTickets.Text = String.Empty
End Sub
Private Function getSeatNumber(ByVal seat As Integer) As Integer
Dim intSeatAvail, intSeatTry, intSeatTaken As Integer
intSeatTry = 1 'Set first seat to try reserving to Seat1
intSeatAvail = 1 'Set the first seat available to be Seat1
Dim strLine As String
Dim strEventName As String
'Open seating file for reading
Dim seatFile As IO.StreamReader
seatFile = IO.File.OpenText("seating.txt")
'Get the event name from the main form
strEventName = mainForm.eventsListbox.SelectedItem.ToString
strEventName = strEventName.ToUpper
MessageBox.Show("String event name: " & strEventName)
Do Until seatFile.Peek = -1
'Read lines from the file
strLine = seatFile.ReadLine
MessageBox.Show("strLine: " & strLine)
'Check for lines that contain the event name
If strLine.ToUpper.Contains(strEventName) Then
'Get the seat number substring and save as strLine
Dim intSeatNum As Integer = strLine.LastIndexOf("#")
Try
strLine = strLine.Substring(intSeatNum + 5, 2)
Catch ex As Exception
strLine = strLine.Substring(intSeatNum + 5, 1)
End Try
MessageBox.Show("strLine: " & strLine)
Integer.TryParse(strLine, intSeatTaken)
If intSeatTry = intSeatTaken Then
'increment the seat number to try by one
intSeatTry += 1
Else
'if the seat number tried does NOT equal the seat taken, set
seat number tried as the available number
intSeatAvail = intSeatTry
End If
Else
'if no lines contain the event name with currently reserved seat
s,
'the first seat to reserve will be Seat1
intSeatAvail = 1
End If
Loop
'Close out seating file
seatFile.Close()
intSeatAvail = intSeatTry
Return intSeatAvail
End Function
End Class

You might also like