Advertisement
Guest User

Yolo Troll Gee

a guest
Mar 6th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.38 KB | None | 0 0
  1. 'HASHING
  2. Imports System
  3. Imports System.Security.Cryptography
  4. Imports System.Text
  5. Module Module1
  6. 'INFO:
  7. 'The default Staff (after LogOut) SHOULD BE username: Admin with the password: AdminPass.
  8. 'Need Hashing Function to be reinstated at school: i can't test at home w/ it.
  9. 'don't need to fix the entry bypass (pressing ENTER) because it doesn't work when Hashing is applied
  10.  
  11. 'To Do:
  12. 'Add a Default (reset) password & account
  13.  
  14.  
  15. 'HASHING
  16. Function GetHash(ByVal theInput As String) As String
  17. Using hasher As MD5 = MD5.Create() ' create hash object
  18. ' Convert to byte array and get hash
  19. Dim dbytes As Byte() =
  20. hasher.ComputeHash(Encoding.UTF8.GetBytes(theInput))
  21. ' sb to create string from bytes
  22. Dim sBuilder As New StringBuilder()
  23. ' convert byte data to hex string
  24. For n As Integer = 0 To dbytes.Length - 1
  25. sBuilder.Append(dbytes(n).ToString("X2"))
  26. Next n
  27. Return sBuilder.ToString()
  28. End Using
  29. End Function
  30.  
  31. 'DATABASES
  32. Structure staffBlueprint
  33. Dim id As Integer
  34. Dim username As String
  35. Dim password As String
  36. Dim name As String
  37. End Structure
  38. Dim activeStaff As staffBlueprint
  39. Dim staffdb(100) As staffBlueprint
  40.  
  41. Structure pupilBlueprint
  42. Dim id As Integer
  43. Dim username As String
  44. Dim password As String
  45. Dim points As Integer
  46. Dim name As String
  47. Dim PointsHistory As String
  48. Dim PrizeHistory As String
  49. End Structure
  50. Dim activePupil As pupilBlueprint
  51. Dim pupildb(100) As pupilBlueprint
  52.  
  53. 'GLOBAL VARIABLES
  54. Dim choice As Integer
  55. Dim StaffID As Integer
  56. Dim PupilID As Integer
  57. Dim studentPoints(100) As Integer
  58. Sub Main()
  59. 'WIPEDATABASE goes here (if needed)
  60.  
  61. 'Allows leaderboard function
  62. For i = 0 To pupildb.Length - 1
  63. If pupildb(i).name <> Nothing Then
  64. studentPoints(i) = pupildb(i).points
  65. End If
  66. Next
  67. 'Reads All Files
  68. StaffIDreadfile()
  69. PupilIDreadfile()
  70. StaffReadFile()
  71. PupilReadFile()
  72. 'Sends To Main Menu
  73. MainMenu()
  74. End Sub
  75.  
  76. Sub MainMenu()
  77. Console.ForegroundColor = ConsoleColor.White
  78. Do
  79. Console.Clear()
  80. Console.WriteLine("Welcome To Your Student Points System.")
  81. Console.WriteLine("1 - Staff Login")
  82. Console.WriteLine("2 - Student Login")
  83. Console.WriteLine("3 - Shut Down")
  84. CheckInteger("Selection: ", choice)
  85. Console.Clear()
  86. If choice = 1 Then
  87. StaffLogin()
  88. ElseIf choice = 2 Then
  89. StudentLogin()
  90. ElseIf choice = 3 Then
  91. End
  92. End If
  93. Loop
  94. End Sub
  95. 'STAFF SECTION
  96. Sub StaffLogin()
  97.  
  98. Do
  99. Console.Clear()
  100. Console.WriteLine("STAFF")
  101. Console.Write("Username: ")
  102. Dim entry As String = Console.ReadLine()
  103. Dim valid As Boolean = False
  104. Dim ID As Integer
  105. For i = 0 To staffdb.Length - 1 'checks that the username is valid
  106. If entry = staffdb(i).username Then
  107. ID = staffdb(i).id
  108. valid = True
  109. Exit For
  110. End If
  111. Next
  112. If valid = False Then
  113. Console.Clear() 'ask for another username
  114. Else
  115. Console.Write("Password: ")
  116. entry = GetHash(Console.ReadLine())
  117. If entry = staffdb(ID).password Then
  118. activeStaff = staffdb(ID)
  119. Exit Do
  120. End If
  121. End If
  122. Loop
  123. STAFFLoggedInMenu()
  124. End Sub
  125.  
  126. Sub STAFFLoggedInMenu()
  127. Do
  128. Console.Clear()
  129. Console.WriteLine("Welcome, " + activeStaff.name)
  130. Console.WriteLine("1 - Add Staff")
  131. Console.WriteLine("2 - Add Pupil")
  132. Console.WriteLine("3 - Edit Pupil")
  133. Console.WriteLine("4 - Search Database")
  134. Console.WriteLine("5 - Edit This Account")
  135. Console.WriteLine("6 - Add or Deduct Points")
  136. Console.WriteLine("7 - View Prize List")
  137. Console.WriteLine("8 - View Leaderboard")
  138. Console.WriteLine("9 - Log Out")
  139. CheckInteger("Selection: ", choice)
  140. Console.Clear()
  141. If choice = 1 Then
  142. AddStaff()
  143. ElseIf choice = 2 Then
  144. AddPupil()
  145. ElseIf choice = 3 Then
  146. EditPupilFromStaff()
  147. ElseIf choice = 4 Then
  148. SearchMenu()
  149. ElseIf choice = 5 Then
  150. EditActiveStaff()
  151. ElseIf choice = 6 Then
  152. AddPoints()
  153. ElseIf choice = 7 Then
  154. PrizeList()
  155. ElseIf choice = 8 Then
  156. Leaderboard()
  157. ElseIf choice = 9 Then
  158. activeStaff = staffdb(0)
  159. MainMenu()
  160. End If
  161. Loop
  162. End Sub
  163. Sub viewAllPupils()
  164. For i = 0 To pupildb.Length - 1
  165. If pupildb(i).name <> Nothing Then
  166. Console.WriteLine("Name: " + pupildb(i).name)
  167. Console.WriteLine("Username: " + pupildb(i).username)
  168. Console.WriteLine("Points: " + pupildb(i).points)
  169. Console.WriteLine()
  170. End If
  171. Next
  172. Console.ReadLine()
  173. End Sub
  174. Sub viewAllStaff()
  175. For i = 0 To pupildb.Length - 1
  176. If pupildb(i).name <> Nothing Then
  177. Console.WriteLine("Name: " + pupildb(i).name)
  178. Console.WriteLine("Username: " + pupildb(i).username)
  179. Console.WriteLine()
  180. End If
  181. Next
  182. Console.ReadLine()
  183. End Sub
  184. Sub SearchMenu()
  185. Console.Clear()
  186. Do
  187. Console.WriteLine("SEARCH FOR:")
  188. Console.WriteLine("1 - Staff")
  189. Console.WriteLine("2 - Student")
  190. Console.WriteLine("3 - All")
  191. Console.WriteLine("4 - View All")
  192. Console.WriteLine("5 - Back")
  193. CheckInteger("Selection: ", choice)
  194. Console.Clear()
  195. If choice = 1 Then
  196. Console.WriteLine("SEARCH FOR STAFF:")
  197. Console.WriteLine("1 - Name")
  198. Console.WriteLine("2 - Username")
  199. CheckInteger("Selection: ", choice)
  200. Console.Clear()
  201. If choice = 1 Then
  202. searchStaffName()
  203. ElseIf choice = 2 Then
  204. searchStaffUsername()
  205. End If
  206. Exit Do
  207. ElseIf choice = 2 Then
  208. Console.WriteLine("SEARCH FOR STUDENT:")
  209. Console.WriteLine("1 - Name")
  210. Console.WriteLine("2 - Username")
  211. CheckInteger("Selection: ", choice)
  212. Console.Clear()
  213. If choice = 1 Then
  214. searchpupilName()
  215. ElseIf choice = 2 Then
  216. searchpupilUsername()
  217. End If
  218. Exit Do
  219. ElseIf choice = 3 Then
  220. SearchAll()
  221. Exit Do
  222. ElseIf choice = 4 Then
  223. ViewAllMenu()
  224. Exit Do
  225. ElseIf choice = 5 Then
  226. STAFFLoggedInMenu()
  227. Exit Do
  228. End If
  229. Loop
  230. End Sub
  231.  
  232. Sub ViewAllMenu()
  233. Do
  234. Console.WriteLine("View All: ")
  235. Console.WriteLine("1 - Students")
  236. Console.WriteLine("2 - Staff")
  237. CheckInteger("Selection: ", choice)
  238. If choice = 1 Then
  239. viewAllPupils()
  240. Exit Do
  241. ElseIf choice = 2 Then
  242. viewAllStaff()
  243. Exit Do
  244. ElseIf choice = 3 Then
  245. STAFFLoggedInMenu()
  246. Exit Do
  247. End If
  248. Loop
  249. End Sub
  250. Sub SearchAll()
  251. Console.Write("Search For: ")
  252. Dim searchFor As String = Console.ReadLine()
  253. Dim match As Boolean = False
  254. Console.Clear()
  255. For i = 0 To staffdb.Length - 1
  256. If searchFor = staffdb(i).username Or searchFor = staffdb(i).name Then
  257. match = True
  258. Console.WriteLine("STAFF")
  259. Console.WriteLine("Username: " + staffdb(i).username)
  260. Console.WriteLine("Name: " + staffdb(i).name)
  261. Console.WriteLine()
  262. End If
  263. Next
  264. For i = 0 To pupildb.Length - 1
  265. If searchFor = pupildb(i).username Or searchFor = pupildb(i).name Then
  266. match = True
  267. Console.WriteLine("STUDENT")
  268. Console.WriteLine("Username: " + pupildb(i).username)
  269. Console.WriteLine("Name: " + pupildb(i).name)
  270. Console.WriteLine("Points: " + pupildb(i).points.ToString)
  271. Console.WriteLine()
  272. End If
  273. Next
  274. Console.ReadLine()
  275. STAFFLoggedInMenu()
  276. End Sub
  277.  
  278. Sub searchStaffUsername()
  279. Console.Clear()
  280. Console.Write("Username: ")
  281. Dim input As String = Console.ReadLine()
  282. Dim match As Boolean = False
  283. For i = 0 To staffdb.Length - 1
  284. If staffdb(i).username = input Then
  285. match = True
  286. Console.WriteLine("Name: " + staffdb(i).name)
  287. Exit For
  288. End If
  289. Next
  290. If match = False Then
  291. Console.WriteLine("No Match Found.")
  292. End If
  293. Console.ReadLine()
  294. STAFFLoggedInMenu()
  295. End Sub
  296. Sub searchStaffName()
  297. Console.Clear()
  298. Console.Write("Name: ")
  299. Dim input As String = Console.ReadLine()
  300. Console.Clear()
  301. Dim match As Boolean = False
  302. For i = 0 To staffdb.Length - 1
  303. If staffdb(i).name = input Then
  304. match = True
  305. Console.WriteLine("Username: " + staffdb(i).username)
  306. Console.WriteLine("Name: " + staffdb(i).name)
  307. Console.WriteLine()
  308. End If
  309. Next
  310. If match = False Then
  311. Console.WriteLine("No Match Found.")
  312. End If
  313. Console.ReadLine()
  314. STAFFLoggedInMenu()
  315. End Sub
  316. Sub searchpupilUsername()
  317. Console.Clear()
  318. Console.Write("Username: ")
  319. Dim input As String = Console.ReadLine()
  320. Dim match As Boolean = False
  321. For i = 0 To pupildb.Length - 1
  322. If pupildb(i).username = input Then
  323. match = True
  324. Console.WriteLine("Name: " + pupildb(i).name)
  325. Console.WriteLine("Points: " + pupildb(i).points.ToString)
  326. Exit For
  327. End If
  328. Next
  329. If match = False Then
  330. Console.WriteLine("No Match Found.")
  331. End If
  332. Console.ReadLine()
  333. STAFFLoggedInMenu()
  334. End Sub
  335. Sub searchpupilName()
  336. Console.Clear()
  337. Console.Write("Name: ")
  338. Dim input As String = Console.ReadLine()
  339. Console.Clear()
  340. Dim match As Boolean = False
  341. For i = 0 To pupildb.Length - 1
  342. If pupildb(i).name = input Then
  343. match = True
  344. Console.WriteLine("Username: " + pupildb(i).username)
  345. Console.WriteLine("Name: " + pupildb(i).name)
  346. Console.WriteLine("Points: " + pupildb(i).points.ToString)
  347. Console.WriteLine()
  348. End If
  349. Next
  350. If match = False Then
  351. Console.WriteLine("No Match Found.")
  352. End If
  353. Console.ReadLine()
  354. STAFFLoggedInMenu()
  355. End Sub
  356. Sub AddPoints()
  357.  
  358. Console.Clear()
  359. Console.Write("Enter Pupil Username: ")
  360. Dim USerName As String = Console.ReadLine()
  361. Dim CurrentID As Integer = -1
  362. For i = 0 To pupildb.Length - 1
  363. If USerName = pupildb(i).username Then
  364. CurrentID = i
  365. Exit For
  366. End If
  367. Next
  368. If CurrentID = -1 Then
  369. Console.WriteLine("User Not Found.")
  370. Console.ReadLine()
  371. STAFFLoggedInMenu()
  372. Else
  373. 'actual code goes here
  374. Dim points As Integer = 0
  375. Do
  376. Console.Clear()
  377. Console.WriteLine("CURRENT PUPIL: " + pupildb(CurrentID).name)
  378. Console.WriteLine("1 - Add Points")
  379. Console.WriteLine("2 - Deduct Points")
  380. Console.WriteLine("3 - Check Balance")
  381. Console.WriteLine("4 - Switch Pupil")
  382. Console.WriteLine("5 - Exit")
  383. CheckInteger("Selection: ", choice)
  384. Console.Clear()
  385. If choice = 1 Then
  386. Console.WriteLine("PUPIL: " + pupildb(CurrentID).name)
  387. Console.WriteLine("BALANCE: " + pupildb(CurrentID).points.ToString)
  388. CheckInteger("Points Added: ", points)
  389. If points > 0 Then
  390. pupildb(CurrentID).points += points
  391. pupildb(CurrentID).PointsHistory += "/" + activeStaff.name + " - Added" + points.ToString
  392. Pupilwritefile()
  393. Console.WriteLine("Points Successfully Added.")
  394. Console.ReadLine()
  395. Else
  396. Console.WriteLine("Invalid Entry.")
  397. Console.ReadLine()
  398. End If
  399. ElseIf choice = 2 Then
  400. Console.WriteLine("PUPIL: " + pupildb(CurrentID).name)
  401. Console.WriteLine("BALANCE: " + pupildb(CurrentID).points.ToString)
  402. CheckInteger("Points Deducted: ", points)
  403. If points > 0 Then
  404. pupildb(CurrentID).points -= points
  405. pupildb(CurrentID).PointsHistory += "/" + activeStaff.name + " - Deducted" + points.ToString
  406. Pupilwritefile()
  407. Console.WriteLine("Points Successfully Deducted.")
  408. Console.ReadLine()
  409. Else
  410. Console.WriteLine("Invalid Entry.")
  411. Console.ReadLine()
  412. End If
  413. ElseIf choice = 3 Then
  414. Console.Clear()
  415. Console.WriteLine("PUPIL: " + pupildb(CurrentID).name)
  416. Console.WriteLine("BALANCE: " + pupildb(CurrentID).points.ToString)
  417. Console.ReadLine()
  418. ElseIf choice = 4 Then
  419. AddPoints()
  420. Exit Do
  421. ElseIf choice = 5 Then
  422. STAFFLoggedInMenu()
  423. Exit Do
  424. End If
  425.  
  426. Loop
  427. End If
  428. End Sub
  429.  
  430. Sub EditActiveStaff()
  431. Do
  432. Console.WriteLine("CURRENT USER: " + activeStaff.name)
  433. Console.WriteLine("1 - Edit Username")
  434. Console.WriteLine("2 - Edit Password")
  435. Console.WriteLine("3 - Exit")
  436. CheckInteger("Selection: ", choice)
  437. Console.Clear()
  438. If choice = 1 Then
  439. Console.Clear()
  440. Type("Old Username: " + activeStaff.username)
  441. Console.Write("New Username: ")
  442. AddUser("Username: ", activeStaff.username)
  443. Staffwritefile()
  444. Exit Do
  445. ElseIf choice = 2 Then
  446. Console.Clear()
  447. Console.Write("Username: " + activeStaff.username)
  448. AddUser("Password: ", activeStaff.password)
  449. activeStaff.password = GetHash(activeStaff.password)
  450. Staffwritefile()
  451. Exit Do
  452. ElseIf choice = 3 Then
  453. STAFFLoggedInMenu()
  454. Exit Do
  455. End If
  456. Loop
  457. End Sub
  458. Sub EditPupilFromStaff()
  459. Console.Clear()
  460. Console.Write("Enter Pupil Username: ")
  461. Dim username As String = Console.ReadLine()
  462. Dim editPupilID As Integer = -1
  463. For i = 0 To pupildb.Length - 1
  464. If username = pupildb(i).username Then
  465. editPupilID = i
  466. Exit For
  467. End If
  468. Next
  469. If editPupilID = -1 Then
  470. Console.WriteLine("User Not Found.")
  471. Console.ReadLine()
  472. STAFFLoggedInMenu()
  473. Else
  474. Do
  475. Console.Clear()
  476. Console.WriteLine("CURRENT PUPIL: " + pupildb(editPupilID).name)
  477. Console.WriteLine("1 - Edit Username")
  478. Console.WriteLine("2 - Edit Password")
  479. Console.WriteLine("3 - Exit")
  480. CheckInteger("Selection: ", choice)
  481. Console.Clear()
  482. Console.Clear()
  483. If choice = 1 Then
  484. Type("Old Username: " + pupildb(editPupilID).username)
  485. Console.Write("New Username: ")
  486. AddUser("Username: ", pupildb(editPupilID).username)
  487. Pupilwritefile()
  488. Exit Do
  489. ElseIf choice = 2 Then
  490. Console.Clear()
  491. Console.Write("Username: " + pupildb(editPupilID).username)
  492. AddUser("Password: ", pupildb(editPupilID).password)
  493. pupildb(editPupilID).password = GetHash(pupildb(editPupilID).password)
  494. Pupilwritefile()
  495. Exit Do
  496. ElseIf choice = 3 Then
  497. STAFFLoggedInMenu()
  498. Exit Do
  499. End If
  500. Loop
  501. End If
  502. End Sub
  503.  
  504. Sub AddStaff()
  505. Console.Clear()
  506. Dim username As String
  507. activeStaff.id = StaffID
  508. AddUser("Username: ", username)
  509. For i = 0 To staffdb.Length - 1
  510. If username = staffdb(i).username Then
  511. Console.WriteLine("Username Taken.")
  512. Console.ReadLine()
  513. AddStaff()
  514. Exit Sub
  515. End If
  516. Next
  517. staffdb(StaffID).username = username
  518. AddUser("Password: ", staffdb(StaffID).password)
  519. AddUser("Name: ", staffdb(StaffID).name)
  520. activeStaff.password = GetHash(staffdb(StaffID).password)
  521. StaffID += 1 : StaffIDwritefile()
  522. Staffwritefile()
  523. End Sub
  524. Sub AddPupil()
  525. activePupil.id = PupilID : PupilID += 1 : PupilIDwritefile()
  526. AddUser("Username: ", activePupil.username)
  527. For i = 0 To pupildb.Length - 1
  528. If activePupil.username = pupildb(i).username Then
  529. Console.WriteLine("Username Taken.")
  530. Console.ReadLine()
  531. AddPupil()
  532. Exit Sub
  533. End If
  534. Next
  535. AddUser("Password: ", activePupil.password)
  536. AddUser("Name: ", activePupil.name)
  537. activePupil.password = GetHash(activePupil.password)
  538. pupildb(activePupil.id) = activePupil
  539. Pupilwritefile()
  540. End Sub
  541.  
  542.  
  543. 'STUDENT SECTION
  544. Sub StudentLogin()
  545.  
  546. Do
  547. Console.Clear()
  548. Console.WriteLine("PUPIL")
  549. Console.WriteLine("Username: ")
  550. Dim entry As String = Console.ReadLine()
  551. Dim valid As Boolean = False
  552. Dim ID As Integer
  553. For i = 0 To staffdb.Length - 1 'checks that the username is valid
  554. If entry = pupildb(i).username Then
  555. ID = pupildb(i).id
  556. valid = True
  557. Exit For
  558. End If
  559. Next
  560. If valid = False Then
  561. Console.Clear() 'ask for another username
  562. Else
  563. Console.Write("Password: ")
  564. entry = GetHash(Console.ReadLine())
  565. If entry = pupildb(ID).password Then
  566. activePupil = pupildb(ID)
  567. STUDENTLoggedInMenu()
  568. Exit Do
  569. End If
  570. End If
  571. Loop
  572.  
  573. End Sub
  574.  
  575. Sub STUDENTLoggedInMenu()
  576. Do
  577. Console.Clear()
  578. Console.WriteLine("Welcome, " + activePupil.name)
  579. Console.WriteLine("1 - Edit Password")
  580. Console.WriteLine("2 - View Points")
  581. Console.WriteLine("3 - View Prize List")
  582. Console.WriteLine("4 - Use Points")
  583. Console.WriteLine("5 - View Point History")
  584. Console.WriteLine("6 - View Leaderboard")
  585. Console.WriteLine("7 - Log Out")
  586. CheckInteger("Selection: ", choice)
  587. Console.Clear()
  588. If choice = 1 Then
  589. Console.Clear()
  590. AddUser("New Password: ", activePupil.password)
  591. activePupil.password = GetHash(activePupil.password)
  592. pupildb(activePupil.id) = activePupil
  593. Pupilwritefile()
  594. Console.WriteLine("New Password Accepted.")
  595. Console.ReadLine()
  596. ElseIf choice = 2 Then
  597. Console.Clear()
  598. Console.WriteLine("BALANCE: " + activePupil.points.ToString)
  599. Console.ReadLine()
  600. ElseIf choice = 3 Then
  601. Console.Clear()
  602. PrizeList()
  603. ElseIf choice = 4 Then
  604. Console.Clear()
  605. UsePoints()
  606. ElseIf choice = 5 Then
  607. ViewPointHistory()
  608. ElseIf choice = 6 Then
  609. Leaderboard()
  610. ElseIf choice = 7 Then
  611. activePupil = pupildb(0)
  612. MainMenu()
  613. Exit Do
  614. End If
  615.  
  616. Loop
  617. End Sub
  618. Sub ViewPointHistory()
  619. If activePupil.PointsHistory <> Nothing Then
  620. For Each letter As Char In activePupil.PointsHistory
  621. If letter = "/" Then
  622. Console.WriteLine()
  623. Else
  624. Console.Write(letter)
  625. End If
  626. Next
  627. Console.WriteLine()
  628. Console.ReadLine()
  629. Console.Clear()
  630. Console.WriteLine("Wipe History?")
  631. If Console.ReadLine.ToLower.StartsWith("y") Then
  632. activePupil.PointsHistory = Nothing
  633. End If
  634. Else
  635. Console.WriteLine("History Is Blank.")
  636. Console.ReadLine()
  637. End If
  638. End Sub
  639. Sub UsePoints()
  640. Console.WriteLine()
  641. If activePupil.points >= 25 Then
  642. Console.WriteLine("1 - Set of Pens : 25 Points")
  643. Else
  644. Console.WriteLine("Please Earn Points To Redeem.")
  645. Console.ReadLine()
  646. STUDENTLoggedInMenu()
  647. End If
  648. If activePupil.points >= 50 Then
  649. Console.WriteLine("2 - Football : 50 points")
  650. End If
  651. If activePupil.points >= 60 Then
  652. Console.WriteLine("3 - CD Voucher : 60 points")
  653. End If
  654. If activePupil.points >= 100 Then
  655. Console.WriteLine("4 - Memory Stick : 100 points")
  656. End If
  657. If activePupil.points >= 110 Then
  658. Console.WriteLine("5 - Ice Skating : 110 points")
  659. End If
  660. If activePupil.points >= 150 Then
  661. Console.WriteLine("6 - Computer Game : 150 points")
  662. End If
  663. If activePupil.points >= 250 Then
  664. Console.WriteLine("7 - Driving Lesson : 250 points")
  665. End If
  666. If activePupil.points >= 300 Then
  667. Console.WriteLine("8 - Digital Camera : 300 points")
  668. End If
  669. If activePupil.points >= 400 Then
  670. Console.WriteLine("9 - MP3 Player : 400 points")
  671. End If
  672. If activePupil.points >= 500 Then
  673. Console.WriteLine("10 - Games Console : 500 points")
  674. End If
  675. Console.WriteLine()
  676. Console.WriteLine("BALANCE: " + activePupil.points.ToString)
  677. Console.WriteLine()
  678.  
  679. CheckInteger("Redeem Prize: ", choice)
  680. Console.Clear()
  681. If choice = 1 Then
  682. RedeemPoints("set of pens", 25)
  683. activePupil.PrizeHistory = activePupil.PrizeHistory + "Set of Pens/"
  684. Pupilwritefile()
  685. ElseIf choice = 2 Then
  686. RedeemPoints("football", 50)
  687. activePupil.PrizeHistory += "Football/"
  688. Pupilwritefile()
  689. ElseIf choice = 3 Then
  690. RedeemPoints("cd voucher", 60)
  691. activePupil.PrizeHistory += "CD Voucher/"
  692. Pupilwritefile()
  693. ElseIf choice = 4 Then
  694. RedeemPoints("Memory stick", 100)
  695. activePupil.PrizeHistory += "Memory Stick/"
  696. Pupilwritefile()
  697. ElseIf choice = 5 Then
  698. RedeemPoints("ice skating", 110)
  699. activePupil.PrizeHistory += "Ice Skating/"
  700. Pupilwritefile()
  701. ElseIf choice = 6 Then
  702. RedeemPoints("computer game", 150)
  703. activePupil.PrizeHistory += "Computer Game/"
  704. Pupilwritefile()
  705. ElseIf choice = 7 Then
  706. RedeemPoints("driving lesson", 250)
  707. activePupil.PrizeHistory += "Driving Lesson/"
  708. Pupilwritefile()
  709. ElseIf choice = 8 Then
  710. RedeemPoints("digital camera", 300)
  711. activePupil.PrizeHistory += "Digital Camera/"
  712. Pupilwritefile()
  713. ElseIf choice = 9 Then
  714. RedeemPoints("mp3 player", 400)
  715. activePupil.PrizeHistory += "MP3 Player/"
  716. Pupilwritefile()
  717. ElseIf choice = 10 Then
  718. RedeemPoints("games console", 500)
  719. activePupil.PrizeHistory += "Games Console/"
  720. Pupilwritefile()
  721. Else
  722. Console.WriteLine("Invalid Selection.")
  723. Console.ReadLine()
  724. STUDENTLoggedInMenu()
  725. End If
  726. Pupilwritefile()
  727. End Sub
  728.  
  729. Sub RedeemPoints(ByVal prize As String, ByVal points As Integer)
  730. If activePupil.points >= points Then
  731. Console.WriteLine(prize.ToUpper + " Chosen.")
  732. System.Threading.Thread.Sleep(500)
  733. activePupil.points -= points
  734. Console.WriteLine("Transaction Successful.")
  735. Console.ReadLine()
  736. STUDENTLoggedInMenu()
  737. Else
  738. Console.WriteLine("You need " + (points - activePupil.points).ToString + " more points.")
  739. Console.ReadLine()
  740. STUDENTLoggedInMenu()
  741. End If
  742. End Sub
  743.  
  744. 'READFILES
  745. Sub StaffIDreadfile()
  746. StaffID = My.Computer.FileSystem.ReadAllText("staffID.txt")
  747. End Sub
  748. Sub PupilIDreadfile()
  749. PupilID = My.Computer.FileSystem.ReadAllText("pupilID.txt")
  750. End Sub
  751. Sub StaffReadFile()
  752. Dim filetext As String = My.Computer.FileSystem.ReadAllText("staff.txt")
  753. Dim record() As String = filetext.Split(";")
  754. For i = 0 To record.Length - 1
  755. Dim field() As String = record(i).Split(",")
  756. If field(0) <> Nothing Then
  757. activeStaff.id = field(0)
  758. activeStaff.username = field(1)
  759. activeStaff.password = field(2)
  760. activeStaff.name = field(3)
  761. staffdb(activeStaff.id) = activeStaff
  762. End If
  763. Next
  764. End Sub
  765. Sub PupilReadFile()
  766. Dim filetext As String = My.Computer.FileSystem.ReadAllText("pupil.txt")
  767. Dim record() As String = filetext.Split(";")
  768. For i = 0 To record.Length - 1
  769. Dim field() As String = record(i).Split(",")
  770. If field(0) <> Nothing Then
  771. activePupil.id = field(0)
  772. activePupil.username = field(1)
  773. activePupil.password = field(2)
  774. activePupil.points = field(3)
  775. activePupil.name = field(4)
  776. activePupil.PointsHistory = field(5)
  777. activePupil.PrizeHistory = field(6)
  778. pupildb(activePupil.id) = activePupil
  779. End If
  780. Next
  781. End Sub
  782.  
  783. 'WRITEFILES
  784. Sub StaffIDwritefile()
  785. My.Computer.FileSystem.WriteAllText("staffID.txt", StaffID, False)
  786. End Sub
  787. Sub PupilIDwritefile()
  788. My.Computer.FileSystem.WriteAllText("pupilID.txt", PupilID, False)
  789. End Sub
  790. Sub Staffwritefile()
  791. Dim filetext As String
  792. For i = 0 To staffdb.Length - 1
  793. filetext = filetext + staffdb(i).id.ToString
  794. filetext = filetext + "," + staffdb(i).username
  795. filetext = filetext + "," + staffdb(i).password
  796. filetext = filetext + "," + staffdb(i).name + ";"
  797. Next
  798. My.Computer.FileSystem.WriteAllText("staff.txt", filetext, False)
  799. End Sub
  800. Sub Pupilwritefile()
  801. Dim filetext As String
  802. For i = 0 To pupildb.Length - 1
  803. filetext = filetext + pupildb(i).id.ToString
  804. filetext = filetext + "," + pupildb(i).username
  805. filetext = filetext + "," + pupildb(i).password
  806. filetext = filetext + "," + pupildb(i).points.ToString
  807. filetext = filetext + "," + pupildb(i).name
  808. filetext = filetext + "," + pupildb(i).PointsHistory
  809. filetext = filetext + "," + pupildb(i).PrizeHistory + ";"
  810. Next
  811. My.Computer.FileSystem.WriteAllText("pupil.txt", filetext, False)
  812. 'writes to leaderboard
  813. For i = 0 To pupildb.Length - 1
  814. If pupildb(i).name <> Nothing Then
  815. studentPoints(i) = pupildb(i).points
  816. End If
  817. Next
  818. End Sub
  819.  
  820. 'VALIDATION
  821. Sub CheckInteger(ByVal message As String, ByRef variable As Integer)
  822. Do
  823. Try
  824. Console.Write(message)
  825. variable = Console.ReadLine()
  826. Exit Do
  827. Catch ex As Exception
  828. Console.WriteLine("Please Try Again.")
  829. End Try
  830. Loop
  831. End Sub
  832.  
  833.  
  834. 'GENERAL
  835. Sub AddUser(ByVal text As String, ByRef variable As String)
  836. Do
  837. Try
  838. Console.Write(text)
  839. variable = Console.ReadLine
  840. If variable.Contains(",") Or variable.Contains(";") Or variable.Contains("/") Then
  841. Console.WriteLine("Invalid Character Entered.")
  842. Else
  843. Exit Do
  844. End If
  845. Catch ex As Exception
  846. Console.WriteLine("Error: Please try again")
  847. End Try
  848. Loop
  849. End Sub
  850. Sub AddUser(ByVal text As String, ByRef variable As Integer)
  851. Do
  852. Try
  853. Console.Write(text)
  854. variable = Console.ReadLine
  855. Exit Do
  856. Catch ex As Exception
  857. Console.WriteLine("Error: Please try again")
  858. End Try
  859. Loop
  860. End Sub
  861. Sub WipeDatabase() 'must be before readfiles to work
  862. 'creates Admin
  863. StaffID = 2 : PupilID = 1
  864. staffdb(1).id = 1
  865. staffdb(1).name = "Admin"
  866. staffdb(1).username = "Admin"
  867. staffdb(1).password = "E4DAD3290BDEF2BBE21E20AD4948DE90"
  868. 'creates a random student
  869. pupildb(1).id = 1
  870. pupildb(1).name = "Bob"
  871. pupildb(1).username = "Student1"
  872. pupildb(1).points = 1
  873. pupildb(1).password = GetHash("password")
  874. 'Wipes all files apart from Admin
  875. StaffIDwritefile() : PupilIDwritefile()
  876. Staffwritefile() : Pupilwritefile()
  877. End Sub
  878. Sub PrizeList()
  879.  
  880. Console.Clear()
  881. Console.WriteLine("PRIZE LIST:")
  882. Console.WriteLine("Set of Pens : 25 Points")
  883. Console.WriteLine("Football : 50 points")
  884. Console.WriteLine("CD Voucher : 60 points")
  885. Console.WriteLine("Memory Stick : 100 points")
  886. Console.WriteLine("Ice Skating : 110 points")
  887. Console.WriteLine("Computer Game : 150 points")
  888. Console.WriteLine("Driving Lesson : 250 points")
  889. Console.WriteLine("Digital Camera : 300 points")
  890. Console.WriteLine("MP3 Player : 400 points")
  891. Console.WriteLine("Games Console : 500 points")
  892.  
  893. Console.ReadLine()
  894.  
  895. End Sub
  896. Sub Type(ByVal message)
  897. For Each letter As Char In message
  898. Console.Write(letter)
  899. System.Threading.Thread.Sleep(15)
  900. Next
  901. System.Threading.Thread.Sleep(1000)
  902. Console.WriteLine()
  903. End Sub
  904.  
  905. Sub Leaderboard()
  906. Dim topPoints As Integer : Dim Counter As Integer = 0 : Dim restriction As Integer
  907. Do 'enters restriction
  908. CheckInteger("View Leaderboard To Position: ", restriction)
  909. If restriction >= 3 And restriction <= 30 Then
  910. Console.Clear()
  911. Console.WriteLine("LEADERBOARD: ")
  912. Exit Do
  913. Else
  914. Console.WriteLine("Please Enter A Number Between 3 and 30.")
  915. End If
  916. Loop
  917. 'runs leaderboard code
  918. Do
  919. Counter += 1
  920. topPoints = 0 'resets topPoints
  921. For i = 0 To studentPoints.Length - 1 'sets TopPoints
  922. If topPoints <= studentPoints(i) Then
  923. topPoints = studentPoints(i)
  924. End If
  925. Next
  926. If topPoints = 0 Then
  927. Exit Do
  928. End If
  929. For i = 0 To studentPoints.Length - 1 'Deletes from Array
  930. If topPoints = studentPoints(i) Then
  931. studentPoints(i) = Nothing
  932. End If
  933. Next
  934. For i = 0 To pupildb.Length - 1 'writes all student names with recquired num of points
  935. If topPoints = pupildb(i).points Then
  936. Console.WriteLine(Counter.ToString + " - " + pupildb(i).name.ToString + " (" + pupildb(i).points.ToString + " points)")
  937. End If
  938. Next
  939. Console.WriteLine()
  940. Loop Until Counter = restriction
  941. Console.ReadLine()
  942.  
  943. 'rewrites Student Data
  944. For i = 0 To pupildb.Length - 1
  945. If pupildb(i).name <> Nothing Then
  946. studentPoints(i) = pupildb(i).points
  947. End If
  948. Next
  949. End Sub
  950. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement