Sunteți pe pagina 1din 3

'Project: ticket master case project

'Purpose: seating arrangment for Temple Town Theatre


' purchased seating is indicated by maroon-colored seats
'Created by: Jennifer Pierce on 1/26/13
'Updated on: Jennifer Pierce on 2/16/13
' Updated code to change font color to red if clicked
'Updated by: Jennifer Pierce on 4/23/13 - corrected code and updated
comments
Option Strict On
Option Explicit On
Option Infer Off
Public Class seatingForm
Private Sub seatingForm_Load(ByVal sender As System.Object, ByVal e As Syste
m.EventArgs) Handles MyBase.Load
'Declare variables
Dim seatFile As IO.StreamReader = IO.File.OpenText("seating.txt")
Dim strLine As String
Dim lblControl As Control
'set number of selected tickets back to 0
gTkts = 0
'Pull the name of the event from the main form
gEvtName = mainForm.eventsListbox.SelectedItem.ToString
Label42.Text = gEvtName
While seatFile.Peek <> -1
strLine = seatFile.ReadLine
Dim testSTring As String = strLine.Substring(strLine.IndexOf("#") +
1)
'MessageBox.Show("gEvtName " & gEvtName & " testString: " & testSTri
ng)
If testSTring.ToUpper.Contains(gEvtName.ToUpper) Then
For Each lblControl In Controls
'If the tab index number matches the seat number stored in t
he seating file, update font color
If (lblControl.TabIndex) = Convert.ToInt32(strLine.Substring
(0, strLine.IndexOf("#"))) Then
lblControl.ForeColor = Color.Red
End If
Next
End If
End While
seatFile.Close()
End Sub
Private Sub returnButton_Click(sender As Object, e As EventArgs) Handles ret
urnButton.Click
'Close the seatForm and update the seating.txt file
'Declare variables
Dim inFile As IO.StreamReader
Dim tempFile As IO.StreamWriter
Dim backupFile As IO.StreamWriter
Dim strEventName As String = String.Empty
Dim strReadEvent As String = String.Empty
gEvtName = mainForm.eventsListbox.SelectedItem.ToString
If IO.File.Exists("Seating.txt") Then
inFile = IO.File.OpenText("Seating.txt")
tempFile = IO.File.CreateText("TempFile.txt")
backupFile = IO.File.CreateText("Backup.txt")
Dim strLine As String
Dim lblControl As Control
While inFile.Peek <> -1
'Read seat number in line from file
strLine = inFile.ReadLine

'If the string contains the current event name
If strLine.ToUpper.Contains(gEvtName.ToUpper) Then
'MessageBox.Show("skipping current event name")
Else 'If the seating.txt line is for another event name, just c
opy line over to temp file
' MessageBox.Show("Writing other seats back to the file")
tempFile.WriteLine(strLine)
End If
End While
'loop through the label controls to determine which labels have been
selected and add them to the file
For Each lblControl In Controls
If lblControl.ForeColor = Color.Red Then
'Write line to temp file with the current event name if the
seat has been selected (red color)
'MessageBox.Show("Writing current event seats" & (lblControl
.TabIndex) & "#" & gEvtName)
tempFile.WriteLine((lblControl.TabIndex) & "#" & gEvtName)
End If
Next
'close out files
inFile.Close()
tempFile.Close()
backupFile.Close()
End If

'Replace the event file contents with the Temp file contents
IO.File.Replace("TempFile.txt", "Seating.txt", "Backup.txt")
'clear the event name
gEvtName = String.Empty
Me.Close()
End Sub
Private Sub Label_Click(sender As Object, e As EventArgs) Handles Label1.Cli
ck, Label2.Click, Label3.Click, Label4.Click, Label5.Click,
Label6.Click, Label7.Click, Label8.Click, Label9.Click, Label10.Click, La
bel11.Click, Label12.Click, Label13.Click, Label14.Click,
Label15.Click, Label16.Click, Label17.Click, Label18.Click, Label19.Cl
ick, Label20.Click, Label21.Click, Label22.Click, Label23.Click,
Label24.Click, Label25.Click, Label26.Click, Label27.Click, Label28.Cli
ck, Label29.Click, Label30.Click, Label31.Click, Label32.Click,
Label33.Click, Label34.Click, Label35.Click, Label36.Click, Label37.Clic
k, Label38.Click, Label39.Click, Label40.Click
'If label is clicked, change the fore color to red
Dim labelClick As String = sender.ToString
Dim intSeatNum As Integer = Convert.ToInt32(labelClick.Substring(33))
Dim lblControl As Control
For Each lblControl In Controls
If lblControl.TabIndex = intSeatNum - 1 Then
If lblControl.ForeColor = Color.Black Then
lblControl.ForeColor = Color.Red
gSeatNum += intSeatNum.ToString
Exit For
ElseIf lblControl.ForeColor = Color.Red Then
lblControl.ForeColor = Color.Black
End If
End If
Next
'increment total number of selected tickets
gTkts += 1
End Sub
End Class

S-ar putea să vă placă și