Sie sind auf Seite 1von 4

'Project: ticket master case project

'Purpose: capstone project for advanced VB course;


' illustrates use of subs/functions, multiple forms, array
s,
' string manipulation, files, databases, and classes
'Created by: Jennifer Pierce on 1/28/13
'Updated by: Jennifer Pierce on 2/16/13 - added Billing form
'Update by: Jennifer Pierce on 3/6/13 - incorporated text file
'Updated by: Jennifer Pierce on 4/23/13 - corrected code and updated
comments
Option Strict On
Option Explicit On
Option Infer Off
Public Class mainForm

Private Sub displayButton_Click(sender As Object, e As EventArgs) Handles di
splayButton.Click
'Display the seating form only if an item is selected in the eventsListB
ox
If eventsListbox.SelectedIndex >= 0 Then
seatingForm.Show()
End If
End Sub
Private Sub concertRadio_CheckedChanged(sender As Object, e As EventArgs) Ha
ndles concertRadio.CheckedChanged, theaterRadio.CheckedChanged, otherRadio.Check
edChanged
Dim SubscriptVenue As Integer
If concertRadio.Checked = True Then
SubscriptVenue = 0
ElseIf theaterRadio.Checked = True Then
SubscriptVenue = 1
Else
SubscriptVenue = 2
End If
'Open the events text file
Dim eventFile As IO.StreamReader
If IO.File.Exists("events.txt") Then
eventFile = IO.File.OpenText("events.txt")
'Call method to populate the eventsListBox, passing index and io fil
e
updateEventListBox(SubscriptVenue, eventFile)
eventFile.Close()
End If
End Sub

Private Sub updateEventListBox(ByVal intIndex As Integer, ByRef ioFile As IO
.StreamReader)
'Declare variables
Dim eventName As String
Dim eventType As Integer = intIndex
Dim charIndex As Integer
'Clear the contents of the eventsListBox
eventsListbox.Items.Clear()
Do Until ioFile.Peek = -1
eventName = ioFile.ReadLine
If eventType = 0 Then
If eventName.Substring(0, 1) = "C" Then
eventName = eventName.Remove(0, 2)
charIndex = eventName.IndexOf("#")
eventName = eventName.Remove(charIndex, 1)
eventName = eventName.Insert(charIndex, " - ")
eventsListbox.Items.Add(eventName)
End If
ElseIf eventType = 1 Then
If eventName.Substring(0, 1) = "T" Then
eventName = eventName.Remove(0, 2)
charIndex = eventName.IndexOf("#")
eventName = eventName.Remove(charIndex, 1)
eventName = eventName.Insert(charIndex, " - ")
eventsListbox.Items.Add(eventName)
End If
ElseIf eventType = 2 Then
If eventName.Substring(0, 1) = "O" Then
eventName = eventName.Remove(0, 2)
charIndex = eventName.IndexOf("#")
eventName = eventName.Remove(charIndex, 1)
eventName = eventName.Insert(charIndex, " - ")
eventsListbox.Items.Add(eventName)
End If
End If
Loop
'Set the event name equal to the empty string
'set focus to first item in the list box
eventName = String.Empty
eventsListbox.SelectedIndex = 0
End Sub
Private Sub ClosingToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles closingMenuTitle.Click
Me.Close()
End Sub
Private Sub calculateMenuItem_Click(sender As Object, e As EventArgs) Handle
s calculateMenuItem.Click
billingForm.ShowDialog()
End Sub
Private Sub addMenuItem_Click(sender As Object, e As EventArgs) Handles addM
enuItem.Click
Dim eventFile As IO.StreamWriter
If IO.File.Exists("events.txt") Then
eventFile = IO.File.AppendText("events.txt")
Dim strNewEvent As String = String.Empty
'Prompt user to enter new event
Dim strType As String = String.Empty
strType = InputBox("Enter Event type (C for Concert, T for Theatre,
or O for Other):", "Event Type")
If strType.ToUpper = "C" Or strType.ToUpper = "T" Or strType.ToUpper
= "O" Then
strNewEvent = strType.ToUpper & "#"
Else
MessageBox.Show("Incorrect event type", "Error", MessageBoxButto
ns.OK)
Me.Close()
End If
Dim strEventName As String = String.Empty
strEventName = InputBox("Enter Event Name", "Event Name")
If strEventName = String.Empty Then
MessageBox.Show("Event Name required", "Error", MessageBoxButton
s.OK)
Me.Close()
Else
'Concatenate string to event name
strNewEvent += strEventName & "#"
End If
Dim strDate As String = String.Empty
strDate = InputBox("Enter Event Date", "Event Date")
If strDate = String.Empty Then
MessageBox.Show("Date field cannot be empty", "Error", MessageBo
xButtons.OK)
Me.Close()
Else
'Concatenate date string to event name
strNewEvent += strDate
End If
eventFile.WriteLine(strNewEvent)
'Close out the file
eventFile.Close()
End If
End Sub
Private Sub removeMenuItem_Click(sender As Object, e As EventArgs) Handles r
emoveMenuItem.Click
'Variables
Dim eventFile 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
If IO.File.Exists("events.txt") Then
eventFile = IO.File.OpenText("events.txt")
tempFile = IO.File.CreateText("TempFile.txt")
backupFile = IO.File.CreateText("Backup.txt")
'Prompt user to enter event name to remove
strEventName = InputBox("Enter Event Name to remove:", "Remove Event
")
If strEventName = String.Empty Then
MessageBox.Show("Event Name required", "Error", MessageBoxButton
s.OK)
Me.Close()
Else
'Search eventfile for the string
Do Until eventFile.Peek = -1
'readline and compare string to see if contains the letter a
nd name
strReadEvent = eventFile.ReadLine
If strReadEvent.ToUpper.Contains(strEventName.ToUpper) Then
'If True, Confirm that this is the event to remove?
Dim charIndex As Integer
Dim strDisplayEvent As String
strDisplayEvent = strReadEvent.Remove(0, 2)
charIndex = strDisplayEvent.IndexOf("#")
strDisplayEvent = strDisplayEvent.Remove(charIndex, 1)
strDisplayEvent = strDisplayEvent.Insert(charIndex, " -
")
If MessageBox.Show("Press YES to remove event, or NO to
cancel: " & strDisplayEvent, "Remove Event?", MessageBoxButtons.YesNo, MessageBo
xIcon.Exclamation) = DialogResult.No Then
'If No, write line to the temp file
tempFile.WriteLine(strReadEvent)
End If
Else
'If false, write line to the temp file
tempFile.WriteLine(strReadEvent)
End If
Loop
tempFile.Close()
eventFile.Close()
backupFile.Close()
End If
'Replace the event file contents with the Temp file contents
IO.File.Replace("TempFile.txt", "events.txt", "backup.txt")
End If
End Sub
Private Sub eventsListbox_SelectedIndexChanged(ByVal sender As System.Object
, ByVal e As System.EventArgs) Handles eventsListbox.SelectedIndexChanged
'update the event name
gEvtName = eventsListbox.SelectedItem.ToString
End Sub
Private Sub mainForm_Load(sender As Object, e As EventArgs) Handles MyBase.L
oad
End Sub
End Class

Das könnte Ihnen auch gefallen