Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'HASHING
- Imports System
- Imports System.Security.Cryptography
- Imports System.Text
- Module Module1
- 'INFO:
- 'The default Staff (after LogOut) SHOULD BE username: Admin with the password: AdminPass.
- 'Need Hashing Function to be reinstated at school: i can't test at home w/ it.
- 'don't need to fix the entry bypass (pressing ENTER) because it doesn't work when Hashing is applied
- 'To Do:
- 'Add a Default (reset) password & account
- 'HASHING
- Function GetHash(ByVal theInput As String) As String
- Using hasher As MD5 = MD5.Create() ' create hash object
- ' Convert to byte array and get hash
- Dim dbytes As Byte() =
- hasher.ComputeHash(Encoding.UTF8.GetBytes(theInput))
- ' sb to create string from bytes
- Dim sBuilder As New StringBuilder()
- ' convert byte data to hex string
- For n As Integer = 0 To dbytes.Length - 1
- sBuilder.Append(dbytes(n).ToString("X2"))
- Next n
- Return sBuilder.ToString()
- End Using
- End Function
- 'DATABASES
- Structure staffBlueprint
- Dim id As Integer
- Dim username As String
- Dim password As String
- Dim name As String
- End Structure
- Dim activeStaff As staffBlueprint
- Dim staffdb(100) As staffBlueprint
- Structure pupilBlueprint
- Dim id As Integer
- Dim username As String
- Dim password As String
- Dim points As Integer
- Dim name As String
- Dim PointsHistory As String
- Dim PrizeHistory As String
- End Structure
- Dim activePupil As pupilBlueprint
- Dim pupildb(100) As pupilBlueprint
- 'GLOBAL VARIABLES
- Dim choice As Integer
- Dim StaffID As Integer
- Dim PupilID As Integer
- Dim studentPoints(100) As Integer
- Sub Main()
- 'WIPEDATABASE goes here (if needed)
- 'Allows leaderboard function
- For i = 0 To pupildb.Length - 1
- If pupildb(i).name <> Nothing Then
- studentPoints(i) = pupildb(i).points
- End If
- Next
- 'Reads All Files
- StaffIDreadfile()
- PupilIDreadfile()
- StaffReadFile()
- PupilReadFile()
- 'Sends To Main Menu
- MainMenu()
- End Sub
- Sub MainMenu()
- Console.ForegroundColor = ConsoleColor.White
- Do
- Console.Clear()
- Console.WriteLine("Welcome To Your Student Points System.")
- Console.WriteLine("1 - Staff Login")
- Console.WriteLine("2 - Student Login")
- Console.WriteLine("3 - Shut Down")
- CheckInteger("Selection: ", choice)
- Console.Clear()
- If choice = 1 Then
- StaffLogin()
- ElseIf choice = 2 Then
- StudentLogin()
- ElseIf choice = 3 Then
- End
- End If
- Loop
- End Sub
- 'STAFF SECTION
- Sub StaffLogin()
- Do
- Console.Clear()
- Console.WriteLine("STAFF")
- Console.Write("Username: ")
- Dim entry As String = Console.ReadLine()
- Dim valid As Boolean = False
- Dim ID As Integer
- For i = 0 To staffdb.Length - 1 'checks that the username is valid
- If entry = staffdb(i).username Then
- ID = staffdb(i).id
- valid = True
- Exit For
- End If
- Next
- If valid = False Then
- Console.Clear() 'ask for another username
- Else
- Console.Write("Password: ")
- entry = GetHash(Console.ReadLine())
- If entry = staffdb(ID).password Then
- activeStaff = staffdb(ID)
- Exit Do
- End If
- End If
- Loop
- STAFFLoggedInMenu()
- End Sub
- Sub STAFFLoggedInMenu()
- Do
- Console.Clear()
- Console.WriteLine("Welcome, " + activeStaff.name)
- Console.WriteLine("1 - Add Staff")
- Console.WriteLine("2 - Add Pupil")
- Console.WriteLine("3 - Edit Pupil")
- Console.WriteLine("4 - Search Database")
- Console.WriteLine("5 - Edit This Account")
- Console.WriteLine("6 - Add or Deduct Points")
- Console.WriteLine("7 - View Prize List")
- Console.WriteLine("8 - View Leaderboard")
- Console.WriteLine("9 - Log Out")
- CheckInteger("Selection: ", choice)
- Console.Clear()
- If choice = 1 Then
- AddStaff()
- ElseIf choice = 2 Then
- AddPupil()
- ElseIf choice = 3 Then
- EditPupilFromStaff()
- ElseIf choice = 4 Then
- SearchMenu()
- ElseIf choice = 5 Then
- EditActiveStaff()
- ElseIf choice = 6 Then
- AddPoints()
- ElseIf choice = 7 Then
- PrizeList()
- ElseIf choice = 8 Then
- Leaderboard()
- ElseIf choice = 9 Then
- activeStaff = staffdb(0)
- MainMenu()
- End If
- Loop
- End Sub
- Sub viewAllPupils()
- For i = 0 To pupildb.Length - 1
- If pupildb(i).name <> Nothing Then
- Console.WriteLine("Name: " + pupildb(i).name)
- Console.WriteLine("Username: " + pupildb(i).username)
- Console.WriteLine("Points: " + pupildb(i).points)
- Console.WriteLine()
- End If
- Next
- Console.ReadLine()
- End Sub
- Sub viewAllStaff()
- For i = 0 To pupildb.Length - 1
- If pupildb(i).name <> Nothing Then
- Console.WriteLine("Name: " + pupildb(i).name)
- Console.WriteLine("Username: " + pupildb(i).username)
- Console.WriteLine()
- End If
- Next
- Console.ReadLine()
- End Sub
- Sub SearchMenu()
- Console.Clear()
- Do
- Console.WriteLine("SEARCH FOR:")
- Console.WriteLine("1 - Staff")
- Console.WriteLine("2 - Student")
- Console.WriteLine("3 - All")
- Console.WriteLine("4 - View All")
- Console.WriteLine("5 - Back")
- CheckInteger("Selection: ", choice)
- Console.Clear()
- If choice = 1 Then
- Console.WriteLine("SEARCH FOR STAFF:")
- Console.WriteLine("1 - Name")
- Console.WriteLine("2 - Username")
- CheckInteger("Selection: ", choice)
- Console.Clear()
- If choice = 1 Then
- searchStaffName()
- ElseIf choice = 2 Then
- searchStaffUsername()
- End If
- Exit Do
- ElseIf choice = 2 Then
- Console.WriteLine("SEARCH FOR STUDENT:")
- Console.WriteLine("1 - Name")
- Console.WriteLine("2 - Username")
- CheckInteger("Selection: ", choice)
- Console.Clear()
- If choice = 1 Then
- searchpupilName()
- ElseIf choice = 2 Then
- searchpupilUsername()
- End If
- Exit Do
- ElseIf choice = 3 Then
- SearchAll()
- Exit Do
- ElseIf choice = 4 Then
- ViewAllMenu()
- Exit Do
- ElseIf choice = 5 Then
- STAFFLoggedInMenu()
- Exit Do
- End If
- Loop
- End Sub
- Sub ViewAllMenu()
- Do
- Console.WriteLine("View All: ")
- Console.WriteLine("1 - Students")
- Console.WriteLine("2 - Staff")
- CheckInteger("Selection: ", choice)
- If choice = 1 Then
- viewAllPupils()
- Exit Do
- ElseIf choice = 2 Then
- viewAllStaff()
- Exit Do
- ElseIf choice = 3 Then
- STAFFLoggedInMenu()
- Exit Do
- End If
- Loop
- End Sub
- Sub SearchAll()
- Console.Write("Search For: ")
- Dim searchFor As String = Console.ReadLine()
- Dim match As Boolean = False
- Console.Clear()
- For i = 0 To staffdb.Length - 1
- If searchFor = staffdb(i).username Or searchFor = staffdb(i).name Then
- match = True
- Console.WriteLine("STAFF")
- Console.WriteLine("Username: " + staffdb(i).username)
- Console.WriteLine("Name: " + staffdb(i).name)
- Console.WriteLine()
- End If
- Next
- For i = 0 To pupildb.Length - 1
- If searchFor = pupildb(i).username Or searchFor = pupildb(i).name Then
- match = True
- Console.WriteLine("STUDENT")
- Console.WriteLine("Username: " + pupildb(i).username)
- Console.WriteLine("Name: " + pupildb(i).name)
- Console.WriteLine("Points: " + pupildb(i).points.ToString)
- Console.WriteLine()
- End If
- Next
- Console.ReadLine()
- STAFFLoggedInMenu()
- End Sub
- Sub searchStaffUsername()
- Console.Clear()
- Console.Write("Username: ")
- Dim input As String = Console.ReadLine()
- Dim match As Boolean = False
- For i = 0 To staffdb.Length - 1
- If staffdb(i).username = input Then
- match = True
- Console.WriteLine("Name: " + staffdb(i).name)
- Exit For
- End If
- Next
- If match = False Then
- Console.WriteLine("No Match Found.")
- End If
- Console.ReadLine()
- STAFFLoggedInMenu()
- End Sub
- Sub searchStaffName()
- Console.Clear()
- Console.Write("Name: ")
- Dim input As String = Console.ReadLine()
- Console.Clear()
- Dim match As Boolean = False
- For i = 0 To staffdb.Length - 1
- If staffdb(i).name = input Then
- match = True
- Console.WriteLine("Username: " + staffdb(i).username)
- Console.WriteLine("Name: " + staffdb(i).name)
- Console.WriteLine()
- End If
- Next
- If match = False Then
- Console.WriteLine("No Match Found.")
- End If
- Console.ReadLine()
- STAFFLoggedInMenu()
- End Sub
- Sub searchpupilUsername()
- Console.Clear()
- Console.Write("Username: ")
- Dim input As String = Console.ReadLine()
- Dim match As Boolean = False
- For i = 0 To pupildb.Length - 1
- If pupildb(i).username = input Then
- match = True
- Console.WriteLine("Name: " + pupildb(i).name)
- Console.WriteLine("Points: " + pupildb(i).points.ToString)
- Exit For
- End If
- Next
- If match = False Then
- Console.WriteLine("No Match Found.")
- End If
- Console.ReadLine()
- STAFFLoggedInMenu()
- End Sub
- Sub searchpupilName()
- Console.Clear()
- Console.Write("Name: ")
- Dim input As String = Console.ReadLine()
- Console.Clear()
- Dim match As Boolean = False
- For i = 0 To pupildb.Length - 1
- If pupildb(i).name = input Then
- match = True
- Console.WriteLine("Username: " + pupildb(i).username)
- Console.WriteLine("Name: " + pupildb(i).name)
- Console.WriteLine("Points: " + pupildb(i).points.ToString)
- Console.WriteLine()
- End If
- Next
- If match = False Then
- Console.WriteLine("No Match Found.")
- End If
- Console.ReadLine()
- STAFFLoggedInMenu()
- End Sub
- Sub AddPoints()
- Console.Clear()
- Console.Write("Enter Pupil Username: ")
- Dim USerName As String = Console.ReadLine()
- Dim CurrentID As Integer = -1
- For i = 0 To pupildb.Length - 1
- If USerName = pupildb(i).username Then
- CurrentID = i
- Exit For
- End If
- Next
- If CurrentID = -1 Then
- Console.WriteLine("User Not Found.")
- Console.ReadLine()
- STAFFLoggedInMenu()
- Else
- 'actual code goes here
- Dim points As Integer = 0
- Do
- Console.Clear()
- Console.WriteLine("CURRENT PUPIL: " + pupildb(CurrentID).name)
- Console.WriteLine("1 - Add Points")
- Console.WriteLine("2 - Deduct Points")
- Console.WriteLine("3 - Check Balance")
- Console.WriteLine("4 - Switch Pupil")
- Console.WriteLine("5 - Exit")
- CheckInteger("Selection: ", choice)
- Console.Clear()
- If choice = 1 Then
- Console.WriteLine("PUPIL: " + pupildb(CurrentID).name)
- Console.WriteLine("BALANCE: " + pupildb(CurrentID).points.ToString)
- CheckInteger("Points Added: ", points)
- If points > 0 Then
- pupildb(CurrentID).points += points
- pupildb(CurrentID).PointsHistory += "/" + activeStaff.name + " - Added" + points.ToString
- Pupilwritefile()
- Console.WriteLine("Points Successfully Added.")
- Console.ReadLine()
- Else
- Console.WriteLine("Invalid Entry.")
- Console.ReadLine()
- End If
- ElseIf choice = 2 Then
- Console.WriteLine("PUPIL: " + pupildb(CurrentID).name)
- Console.WriteLine("BALANCE: " + pupildb(CurrentID).points.ToString)
- CheckInteger("Points Deducted: ", points)
- If points > 0 Then
- pupildb(CurrentID).points -= points
- pupildb(CurrentID).PointsHistory += "/" + activeStaff.name + " - Deducted" + points.ToString
- Pupilwritefile()
- Console.WriteLine("Points Successfully Deducted.")
- Console.ReadLine()
- Else
- Console.WriteLine("Invalid Entry.")
- Console.ReadLine()
- End If
- ElseIf choice = 3 Then
- Console.Clear()
- Console.WriteLine("PUPIL: " + pupildb(CurrentID).name)
- Console.WriteLine("BALANCE: " + pupildb(CurrentID).points.ToString)
- Console.ReadLine()
- ElseIf choice = 4 Then
- AddPoints()
- Exit Do
- ElseIf choice = 5 Then
- STAFFLoggedInMenu()
- Exit Do
- End If
- Loop
- End If
- End Sub
- Sub EditActiveStaff()
- Do
- Console.WriteLine("CURRENT USER: " + activeStaff.name)
- Console.WriteLine("1 - Edit Username")
- Console.WriteLine("2 - Edit Password")
- Console.WriteLine("3 - Exit")
- CheckInteger("Selection: ", choice)
- Console.Clear()
- If choice = 1 Then
- Console.Clear()
- Type("Old Username: " + activeStaff.username)
- Console.Write("New Username: ")
- AddUser("Username: ", activeStaff.username)
- Staffwritefile()
- Exit Do
- ElseIf choice = 2 Then
- Console.Clear()
- Console.Write("Username: " + activeStaff.username)
- AddUser("Password: ", activeStaff.password)
- activeStaff.password = GetHash(activeStaff.password)
- Staffwritefile()
- Exit Do
- ElseIf choice = 3 Then
- STAFFLoggedInMenu()
- Exit Do
- End If
- Loop
- End Sub
- Sub EditPupilFromStaff()
- Console.Clear()
- Console.Write("Enter Pupil Username: ")
- Dim username As String = Console.ReadLine()
- Dim editPupilID As Integer = -1
- For i = 0 To pupildb.Length - 1
- If username = pupildb(i).username Then
- editPupilID = i
- Exit For
- End If
- Next
- If editPupilID = -1 Then
- Console.WriteLine("User Not Found.")
- Console.ReadLine()
- STAFFLoggedInMenu()
- Else
- Do
- Console.Clear()
- Console.WriteLine("CURRENT PUPIL: " + pupildb(editPupilID).name)
- Console.WriteLine("1 - Edit Username")
- Console.WriteLine("2 - Edit Password")
- Console.WriteLine("3 - Exit")
- CheckInteger("Selection: ", choice)
- Console.Clear()
- Console.Clear()
- If choice = 1 Then
- Type("Old Username: " + pupildb(editPupilID).username)
- Console.Write("New Username: ")
- AddUser("Username: ", pupildb(editPupilID).username)
- Pupilwritefile()
- Exit Do
- ElseIf choice = 2 Then
- Console.Clear()
- Console.Write("Username: " + pupildb(editPupilID).username)
- AddUser("Password: ", pupildb(editPupilID).password)
- pupildb(editPupilID).password = GetHash(pupildb(editPupilID).password)
- Pupilwritefile()
- Exit Do
- ElseIf choice = 3 Then
- STAFFLoggedInMenu()
- Exit Do
- End If
- Loop
- End If
- End Sub
- Sub AddStaff()
- Console.Clear()
- Dim username As String
- activeStaff.id = StaffID
- AddUser("Username: ", username)
- For i = 0 To staffdb.Length - 1
- If username = staffdb(i).username Then
- Console.WriteLine("Username Taken.")
- Console.ReadLine()
- AddStaff()
- Exit Sub
- End If
- Next
- staffdb(StaffID).username = username
- AddUser("Password: ", staffdb(StaffID).password)
- AddUser("Name: ", staffdb(StaffID).name)
- activeStaff.password = GetHash(staffdb(StaffID).password)
- StaffID += 1 : StaffIDwritefile()
- Staffwritefile()
- End Sub
- Sub AddPupil()
- activePupil.id = PupilID : PupilID += 1 : PupilIDwritefile()
- AddUser("Username: ", activePupil.username)
- For i = 0 To pupildb.Length - 1
- If activePupil.username = pupildb(i).username Then
- Console.WriteLine("Username Taken.")
- Console.ReadLine()
- AddPupil()
- Exit Sub
- End If
- Next
- AddUser("Password: ", activePupil.password)
- AddUser("Name: ", activePupil.name)
- activePupil.password = GetHash(activePupil.password)
- pupildb(activePupil.id) = activePupil
- Pupilwritefile()
- End Sub
- 'STUDENT SECTION
- Sub StudentLogin()
- Do
- Console.Clear()
- Console.WriteLine("PUPIL")
- Console.WriteLine("Username: ")
- Dim entry As String = Console.ReadLine()
- Dim valid As Boolean = False
- Dim ID As Integer
- For i = 0 To staffdb.Length - 1 'checks that the username is valid
- If entry = pupildb(i).username Then
- ID = pupildb(i).id
- valid = True
- Exit For
- End If
- Next
- If valid = False Then
- Console.Clear() 'ask for another username
- Else
- Console.Write("Password: ")
- entry = GetHash(Console.ReadLine())
- If entry = pupildb(ID).password Then
- activePupil = pupildb(ID)
- STUDENTLoggedInMenu()
- Exit Do
- End If
- End If
- Loop
- End Sub
- Sub STUDENTLoggedInMenu()
- Do
- Console.Clear()
- Console.WriteLine("Welcome, " + activePupil.name)
- Console.WriteLine("1 - Edit Password")
- Console.WriteLine("2 - View Points")
- Console.WriteLine("3 - View Prize List")
- Console.WriteLine("4 - Use Points")
- Console.WriteLine("5 - View Point History")
- Console.WriteLine("6 - View Leaderboard")
- Console.WriteLine("7 - Log Out")
- CheckInteger("Selection: ", choice)
- Console.Clear()
- If choice = 1 Then
- Console.Clear()
- AddUser("New Password: ", activePupil.password)
- activePupil.password = GetHash(activePupil.password)
- pupildb(activePupil.id) = activePupil
- Pupilwritefile()
- Console.WriteLine("New Password Accepted.")
- Console.ReadLine()
- ElseIf choice = 2 Then
- Console.Clear()
- Console.WriteLine("BALANCE: " + activePupil.points.ToString)
- Console.ReadLine()
- ElseIf choice = 3 Then
- Console.Clear()
- PrizeList()
- ElseIf choice = 4 Then
- Console.Clear()
- UsePoints()
- ElseIf choice = 5 Then
- ViewPointHistory()
- ElseIf choice = 6 Then
- Leaderboard()
- ElseIf choice = 7 Then
- activePupil = pupildb(0)
- MainMenu()
- Exit Do
- End If
- Loop
- End Sub
- Sub ViewPointHistory()
- If activePupil.PointsHistory <> Nothing Then
- For Each letter As Char In activePupil.PointsHistory
- If letter = "/" Then
- Console.WriteLine()
- Else
- Console.Write(letter)
- End If
- Next
- Console.WriteLine()
- Console.ReadLine()
- Console.Clear()
- Console.WriteLine("Wipe History?")
- If Console.ReadLine.ToLower.StartsWith("y") Then
- activePupil.PointsHistory = Nothing
- End If
- Else
- Console.WriteLine("History Is Blank.")
- Console.ReadLine()
- End If
- End Sub
- Sub UsePoints()
- Console.WriteLine()
- If activePupil.points >= 25 Then
- Console.WriteLine("1 - Set of Pens : 25 Points")
- Else
- Console.WriteLine("Please Earn Points To Redeem.")
- Console.ReadLine()
- STUDENTLoggedInMenu()
- End If
- If activePupil.points >= 50 Then
- Console.WriteLine("2 - Football : 50 points")
- End If
- If activePupil.points >= 60 Then
- Console.WriteLine("3 - CD Voucher : 60 points")
- End If
- If activePupil.points >= 100 Then
- Console.WriteLine("4 - Memory Stick : 100 points")
- End If
- If activePupil.points >= 110 Then
- Console.WriteLine("5 - Ice Skating : 110 points")
- End If
- If activePupil.points >= 150 Then
- Console.WriteLine("6 - Computer Game : 150 points")
- End If
- If activePupil.points >= 250 Then
- Console.WriteLine("7 - Driving Lesson : 250 points")
- End If
- If activePupil.points >= 300 Then
- Console.WriteLine("8 - Digital Camera : 300 points")
- End If
- If activePupil.points >= 400 Then
- Console.WriteLine("9 - MP3 Player : 400 points")
- End If
- If activePupil.points >= 500 Then
- Console.WriteLine("10 - Games Console : 500 points")
- End If
- Console.WriteLine()
- Console.WriteLine("BALANCE: " + activePupil.points.ToString)
- Console.WriteLine()
- CheckInteger("Redeem Prize: ", choice)
- Console.Clear()
- If choice = 1 Then
- RedeemPoints("set of pens", 25)
- activePupil.PrizeHistory = activePupil.PrizeHistory + "Set of Pens/"
- Pupilwritefile()
- ElseIf choice = 2 Then
- RedeemPoints("football", 50)
- activePupil.PrizeHistory += "Football/"
- Pupilwritefile()
- ElseIf choice = 3 Then
- RedeemPoints("cd voucher", 60)
- activePupil.PrizeHistory += "CD Voucher/"
- Pupilwritefile()
- ElseIf choice = 4 Then
- RedeemPoints("Memory stick", 100)
- activePupil.PrizeHistory += "Memory Stick/"
- Pupilwritefile()
- ElseIf choice = 5 Then
- RedeemPoints("ice skating", 110)
- activePupil.PrizeHistory += "Ice Skating/"
- Pupilwritefile()
- ElseIf choice = 6 Then
- RedeemPoints("computer game", 150)
- activePupil.PrizeHistory += "Computer Game/"
- Pupilwritefile()
- ElseIf choice = 7 Then
- RedeemPoints("driving lesson", 250)
- activePupil.PrizeHistory += "Driving Lesson/"
- Pupilwritefile()
- ElseIf choice = 8 Then
- RedeemPoints("digital camera", 300)
- activePupil.PrizeHistory += "Digital Camera/"
- Pupilwritefile()
- ElseIf choice = 9 Then
- RedeemPoints("mp3 player", 400)
- activePupil.PrizeHistory += "MP3 Player/"
- Pupilwritefile()
- ElseIf choice = 10 Then
- RedeemPoints("games console", 500)
- activePupil.PrizeHistory += "Games Console/"
- Pupilwritefile()
- Else
- Console.WriteLine("Invalid Selection.")
- Console.ReadLine()
- STUDENTLoggedInMenu()
- End If
- Pupilwritefile()
- End Sub
- Sub RedeemPoints(ByVal prize As String, ByVal points As Integer)
- If activePupil.points >= points Then
- Console.WriteLine(prize.ToUpper + " Chosen.")
- System.Threading.Thread.Sleep(500)
- activePupil.points -= points
- Console.WriteLine("Transaction Successful.")
- Console.ReadLine()
- STUDENTLoggedInMenu()
- Else
- Console.WriteLine("You need " + (points - activePupil.points).ToString + " more points.")
- Console.ReadLine()
- STUDENTLoggedInMenu()
- End If
- End Sub
- 'READFILES
- Sub StaffIDreadfile()
- StaffID = My.Computer.FileSystem.ReadAllText("staffID.txt")
- End Sub
- Sub PupilIDreadfile()
- PupilID = My.Computer.FileSystem.ReadAllText("pupilID.txt")
- End Sub
- Sub StaffReadFile()
- Dim filetext As String = My.Computer.FileSystem.ReadAllText("staff.txt")
- Dim record() As String = filetext.Split(";")
- For i = 0 To record.Length - 1
- Dim field() As String = record(i).Split(",")
- If field(0) <> Nothing Then
- activeStaff.id = field(0)
- activeStaff.username = field(1)
- activeStaff.password = field(2)
- activeStaff.name = field(3)
- staffdb(activeStaff.id) = activeStaff
- End If
- Next
- End Sub
- Sub PupilReadFile()
- Dim filetext As String = My.Computer.FileSystem.ReadAllText("pupil.txt")
- Dim record() As String = filetext.Split(";")
- For i = 0 To record.Length - 1
- Dim field() As String = record(i).Split(",")
- If field(0) <> Nothing Then
- activePupil.id = field(0)
- activePupil.username = field(1)
- activePupil.password = field(2)
- activePupil.points = field(3)
- activePupil.name = field(4)
- activePupil.PointsHistory = field(5)
- activePupil.PrizeHistory = field(6)
- pupildb(activePupil.id) = activePupil
- End If
- Next
- End Sub
- 'WRITEFILES
- Sub StaffIDwritefile()
- My.Computer.FileSystem.WriteAllText("staffID.txt", StaffID, False)
- End Sub
- Sub PupilIDwritefile()
- My.Computer.FileSystem.WriteAllText("pupilID.txt", PupilID, False)
- End Sub
- Sub Staffwritefile()
- Dim filetext As String
- For i = 0 To staffdb.Length - 1
- filetext = filetext + staffdb(i).id.ToString
- filetext = filetext + "," + staffdb(i).username
- filetext = filetext + "," + staffdb(i).password
- filetext = filetext + "," + staffdb(i).name + ";"
- Next
- My.Computer.FileSystem.WriteAllText("staff.txt", filetext, False)
- End Sub
- Sub Pupilwritefile()
- Dim filetext As String
- For i = 0 To pupildb.Length - 1
- filetext = filetext + pupildb(i).id.ToString
- filetext = filetext + "," + pupildb(i).username
- filetext = filetext + "," + pupildb(i).password
- filetext = filetext + "," + pupildb(i).points.ToString
- filetext = filetext + "," + pupildb(i).name
- filetext = filetext + "," + pupildb(i).PointsHistory
- filetext = filetext + "," + pupildb(i).PrizeHistory + ";"
- Next
- My.Computer.FileSystem.WriteAllText("pupil.txt", filetext, False)
- 'writes to leaderboard
- For i = 0 To pupildb.Length - 1
- If pupildb(i).name <> Nothing Then
- studentPoints(i) = pupildb(i).points
- End If
- Next
- End Sub
- 'VALIDATION
- Sub CheckInteger(ByVal message As String, ByRef variable As Integer)
- Do
- Try
- Console.Write(message)
- variable = Console.ReadLine()
- Exit Do
- Catch ex As Exception
- Console.WriteLine("Please Try Again.")
- End Try
- Loop
- End Sub
- 'GENERAL
- Sub AddUser(ByVal text As String, ByRef variable As String)
- Do
- Try
- Console.Write(text)
- variable = Console.ReadLine
- If variable.Contains(",") Or variable.Contains(";") Or variable.Contains("/") Then
- Console.WriteLine("Invalid Character Entered.")
- Else
- Exit Do
- End If
- Catch ex As Exception
- Console.WriteLine("Error: Please try again")
- End Try
- Loop
- End Sub
- Sub AddUser(ByVal text As String, ByRef variable As Integer)
- Do
- Try
- Console.Write(text)
- variable = Console.ReadLine
- Exit Do
- Catch ex As Exception
- Console.WriteLine("Error: Please try again")
- End Try
- Loop
- End Sub
- Sub WipeDatabase() 'must be before readfiles to work
- 'creates Admin
- StaffID = 2 : PupilID = 1
- staffdb(1).id = 1
- staffdb(1).name = "Admin"
- staffdb(1).username = "Admin"
- staffdb(1).password = "E4DAD3290BDEF2BBE21E20AD4948DE90"
- 'creates a random student
- pupildb(1).id = 1
- pupildb(1).name = "Bob"
- pupildb(1).username = "Student1"
- pupildb(1).points = 1
- pupildb(1).password = GetHash("password")
- 'Wipes all files apart from Admin
- StaffIDwritefile() : PupilIDwritefile()
- Staffwritefile() : Pupilwritefile()
- End Sub
- Sub PrizeList()
- Console.Clear()
- Console.WriteLine("PRIZE LIST:")
- Console.WriteLine("Set of Pens : 25 Points")
- Console.WriteLine("Football : 50 points")
- Console.WriteLine("CD Voucher : 60 points")
- Console.WriteLine("Memory Stick : 100 points")
- Console.WriteLine("Ice Skating : 110 points")
- Console.WriteLine("Computer Game : 150 points")
- Console.WriteLine("Driving Lesson : 250 points")
- Console.WriteLine("Digital Camera : 300 points")
- Console.WriteLine("MP3 Player : 400 points")
- Console.WriteLine("Games Console : 500 points")
- Console.ReadLine()
- End Sub
- Sub Type(ByVal message)
- For Each letter As Char In message
- Console.Write(letter)
- System.Threading.Thread.Sleep(15)
- Next
- System.Threading.Thread.Sleep(1000)
- Console.WriteLine()
- End Sub
- Sub Leaderboard()
- Dim topPoints As Integer : Dim Counter As Integer = 0 : Dim restriction As Integer
- Do 'enters restriction
- CheckInteger("View Leaderboard To Position: ", restriction)
- If restriction >= 3 And restriction <= 30 Then
- Console.Clear()
- Console.WriteLine("LEADERBOARD: ")
- Exit Do
- Else
- Console.WriteLine("Please Enter A Number Between 3 and 30.")
- End If
- Loop
- 'runs leaderboard code
- Do
- Counter += 1
- topPoints = 0 'resets topPoints
- For i = 0 To studentPoints.Length - 1 'sets TopPoints
- If topPoints <= studentPoints(i) Then
- topPoints = studentPoints(i)
- End If
- Next
- If topPoints = 0 Then
- Exit Do
- End If
- For i = 0 To studentPoints.Length - 1 'Deletes from Array
- If topPoints = studentPoints(i) Then
- studentPoints(i) = Nothing
- End If
- Next
- For i = 0 To pupildb.Length - 1 'writes all student names with recquired num of points
- If topPoints = pupildb(i).points Then
- Console.WriteLine(Counter.ToString + " - " + pupildb(i).name.ToString + " (" + pupildb(i).points.ToString + " points)")
- End If
- Next
- Console.WriteLine()
- Loop Until Counter = restriction
- Console.ReadLine()
- 'rewrites Student Data
- For i = 0 To pupildb.Length - 1
- If pupildb(i).name <> Nothing Then
- studentPoints(i) = pupildb(i).points
- End If
- Next
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement