Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.22 KB | None | 0 0
  1. Imports System
  2. Imports System.Security.Cryptography
  3. Imports System.Text
  4.  
  5.  
  6.  
  7. Module Module1
  8.  
  9.  
  10. Structure userBlueprint
  11. Dim id As Integer
  12. Dim username As String
  13. Dim password As String
  14. Dim fname As String
  15. Dim sname As String
  16. Dim points As Integer
  17.  
  18. End Structure
  19. Structure formBlueprint
  20. Dim id As Integer
  21. Dim name As String
  22. Dim password As String
  23. Dim fname As String
  24. Dim sname As String
  25.  
  26. End Structure
  27. Dim activeuser As userBlueprint
  28. Dim userdb(100) As userBlueprint
  29. Dim activeform As formBlueprint
  30. Dim formdb(100) As formBlueprint
  31. Function GetHash(theInput As String) As String
  32. Using hasher As MD5 = MD5.Create() ' create hash object
  33. ' Convert to byte array and get hash
  34. Dim dbytes As Byte() =
  35. hasher.ComputeHash(Encoding.UTF8.GetBytes(theInput))
  36. ' sb to create string from bytes
  37. Dim sBuilder As New StringBuilder()
  38. ' convert byte data to hex string
  39. For n As Integer = 0 To dbytes.Length - 1
  40. sBuilder.Append(dbytes(n).ToString("X2"))
  41. Next n
  42. Return sBuilder.ToString()
  43. End Using
  44. End Function
  45. Sub Main()
  46.  
  47.  
  48.  
  49. Console.WriteLine("1 - Teacher")
  50. Console.WriteLine("2 - Student")
  51. Console.WriteLine("3 - exit")
  52. Dim choice As Integer
  53. Do
  54. Try
  55. choice = Console.ReadLine()
  56. Exit Do
  57. Catch ex As Exception
  58. Console.WriteLine("Error")
  59. Console.Clear()
  60. End Try
  61.  
  62. Loop
  63.  
  64. If choice = 1 Then
  65. Console.Clear()
  66. formchoice()
  67. End If
  68. If choice = 2 Then
  69. Console.Clear()
  70. userchoice()
  71.  
  72. End If
  73. If choice = 3 Then
  74.  
  75. End
  76. End If
  77.  
  78.  
  79.  
  80.  
  81.  
  82. End Sub
  83. Sub spendpoints()
  84. Console.WriteLine("You have " + activeuser.points.ToString + " to spend.")
  85. Console.WriteLine("1 - Set of pens for 25 points.")
  86. Console.WriteLine("2 - Football for 50 points.")
  87. Console.WriteLine("3 - CD voucher for 60 points.")
  88. Console.WriteLine("4 - Memory stick for 100 points.")
  89. Console.WriteLine("5 - An ice skating voucher for 110 points.")
  90. Console.WriteLine("6 - A computer game for 150 points.")
  91. Console.WriteLine("7 - A driving lesson for 250 points.")
  92. Console.WriteLine("8 - A digital camera for 300 points.")
  93. Console.WriteLine("9 - An mp3 player for 400 points.")
  94. Console.WriteLine("10 - A games console for 500 points.")
  95. Dim buychoice = Console.ReadLine
  96. If buychoice = 1 And activeuser.points > 25 Then
  97. Console.WriteLine("You have redeemed your pens")
  98. activeuser.points = activeuser.points - 25
  99. spendpoints()
  100. Else Console.WriteLine("Please select again")
  101. Console.ReadLine()
  102.  
  103. End If
  104. If buychoice = 2 And activeuser.points > 50 Then
  105. Console.WriteLine("You have redeemed a football")
  106. activeuser.points = activeuser.points - 50
  107. spendpoints()
  108. Else Console.WriteLine("Please select again")
  109. Console.ReadLine()
  110.  
  111. End If
  112. If buychoice = 3 And activeuser.points > 60 Then
  113. Console.WriteLine("You have redeemed a CD voucher")
  114. activeuser.points = activeuser.points - 60
  115. spendpoints()
  116. Else Console.WriteLine("Please select again")
  117. Console.ReadLine()
  118.  
  119. End If
  120. If buychoice = 4 And activeuser.points > 100 Then
  121. Console.WriteLine("You have redeemed a memory stick")
  122. activeuser.points = activeuser.points - 100
  123. spendpoints()
  124. Else Console.WriteLine("Please select again")
  125. Console.ReadLine()
  126.  
  127. End If
  128. If buychoice = 5 And activeuser.points > 110 Then
  129. Console.WriteLine("You have redeemed an ice skating voucher")
  130. activeuser.points = activeuser.points - 110
  131. spendpoints()
  132. Else Console.WriteLine("Please select again")
  133. Console.ReadLine()
  134.  
  135. End If
  136. If buychoice = 6 And activeuser.points > 150 Then
  137. Console.WriteLine("You have redeemed a computer game")
  138. activeuser.points = activeuser.points - 150
  139. spendpoints()
  140. Else Console.WriteLine("Please select again")
  141. Console.ReadLine()
  142.  
  143. End If
  144. If buychoice = 7 And activeuser.points > 250 Then
  145. Console.WriteLine("You have redeemed a driving lesson")
  146. activeuser.points = activeuser.points - 250
  147. spendpoints()
  148. Else Console.WriteLine("Please select again")
  149. Console.ReadLine()
  150. End If
  151. If buychoice = 8 And activeuser.points > 300 Then
  152. Console.WriteLine("You have redeemed a digital camera")
  153. activeuser.points = activeuser.points - 300
  154. spendpoints()
  155. Else Console.WriteLine("Please select again")
  156. Console.ReadLine()
  157. End If
  158. If buychoice = 9 And activeuser.points > 400 Then
  159. Console.WriteLine("You have redeemed an mp3 player")
  160.  
  161. activeuser.points = activeuser.points - 400
  162. spendpoints()
  163. Else Console.WriteLine("Please select again")
  164. Console.ReadLine()
  165. End If
  166. If buychoice = 10 And activeuser.points > 500 Then
  167. Console.WriteLine("You have redeemed a games console")
  168.  
  169. activeuser.points = activeuser.points - 500
  170. spendpoints()
  171. Else Console.WriteLine("Please select again")
  172. Console.ReadLine()
  173. End If
  174.  
  175. End Sub
  176. Sub userchoice()
  177. Console.WriteLine("1 - Login")
  178. Console.WriteLine("2 - Create")
  179. Dim choice As Integer = Console.ReadLine
  180. If choice = 1 Then userlogin()
  181. If choice = 2 Then adduser()
  182. End Sub
  183. Sub formchoice()
  184. Console.WriteLine("1 - Login")
  185. Console.WriteLine("2 - Create")
  186. Dim choice As Integer = Console.ReadLine
  187. If choice = 1 Then formlogin()
  188. If choice = 2 Then addteacher()
  189.  
  190. End Sub
  191. Sub useroptions()
  192. Console.WriteLine("1 - Spend points")
  193. Console.WriteLine("2 - See points")
  194. Dim choice As Integer = Console.ReadLine
  195. If choice = 1 Then
  196. spendpoints()
  197.  
  198. If choice = 2 Then
  199. Console.WriteLine(activeuser.points)
  200. Console.ReadLine()
  201. End If
  202. End If
  203. End Sub
  204. Sub formoptions()
  205. Console.Clear()
  206. Console.WriteLine("Add poitns to students - 1")
  207. Console.WriteLine("Take points from students - 2")
  208. Dim choice As Integer = Console.ReadLine
  209.  
  210. If choice = 1 Then
  211. addpoints()
  212. ElseIf choice = 2 Then
  213. takepoints()
  214. End If
  215. End Sub
  216. Sub formlogin()
  217.  
  218. readstaff()
  219.  
  220. Console.Write("Username: ")
  221. Dim searchcriteria As String = Console.ReadLine()
  222. Console.Write("Password : ")
  223. Dim searchcriteria2 As String = Console.ReadLine()
  224. For i = 0 To formdb.Length - 1
  225. If searchcriteria2 <> Nothing And searchcriteria <> Nothing And searchcriteria = formdb(i).name And searchcriteria2 = formdb(i).password Then
  226. activeform = formdb(i)
  227. formoptions()
  228. End If
  229. Next
  230.  
  231.  
  232.  
  233. End Sub
  234.  
  235. Sub userlogin()
  236. readstudent()
  237. Console.Write("Username: ")
  238. Dim searchcriteria As String = Console.ReadLine()
  239. Console.Write("Password : ")
  240. Dim searchcriteria2 As String = Console.ReadLine()
  241. For i = 0 To userdb.Length - 1
  242. If searchcriteria = userdb(i).username And searchcriteria2 = userdb(i).password Then
  243. activeuser = userdb(i)
  244.  
  245. End If
  246.  
  247. Next
  248. useroptions()
  249.  
  250.  
  251. End Sub
  252. Sub takepoints()
  253. Console.WriteLine("Which user do you want to take points from? ")
  254. Console.WriteLine("Type students username:")
  255. Dim searchcriteria As String = Console.ReadLine()
  256. For i = 0 To userdb.Length - 1
  257. If searchcriteria = userdb(i).username Then
  258. activeuser = userdb(i)
  259. Console.WriteLine("How many points ")
  260. Dim points As Integer = Console.ReadLine
  261. activeuser.points = activeuser.points - points
  262. Exit Sub
  263. Else
  264. Exit Sub
  265. End If
  266. Next
  267. writefileStudent()
  268. End Sub
  269. Sub addpoints()
  270. Console.WriteLine("Which user do you want to give points? ")
  271. Console.WriteLine("Type students username:")
  272. Dim searchcriteria As String = Console.ReadLine()
  273. For i = 0 To userdb.Length - 1
  274. If searchcriteria = userdb(i).username Then
  275. activeuser = userdb(i)
  276. Console.WriteLine("How many points ")
  277. Dim points As Integer = Console.ReadLine
  278. activeuser.points = activeuser.points + points
  279. Exit Sub
  280. Else
  281. Exit Sub
  282. End If
  283. Next
  284. writefileStudent()
  285. End Sub
  286. Sub addteacher()
  287.  
  288. For i = 0 To formdb.Length - 1
  289. If formdb(i).id = Nothing Then
  290. activeform.id = i
  291. Exit For
  292. End If
  293. Next
  294.  
  295. AddUser("Username: ", activeform.name)
  296. AddUser("Password: ", activeform.password)
  297. AddUser("First name: ", activeform.fname)
  298. AddUser("Surname: ", activeform.sname)
  299. formdb(activeform.id) = activeform
  300.  
  301. writefileStaff()
  302.  
  303. End Sub
  304. Sub adduser()
  305.  
  306. For i = 0 To userdb.Length - 1
  307. If userdb(i).id = Nothing Then
  308. activeuser.id = i
  309. Exit For
  310. End If
  311. Next
  312. AddUser("Username: ", activeuser.username)
  313. AddUser("Password: ", activeuser.password)
  314. AddUser("First name: ", activeuser.fname)
  315. AddUser("Surname: ", activeuser.sname)
  316.  
  317. userdb(activeuser.id) = activeuser
  318.  
  319. writefileStudent()
  320. End Sub
  321. Sub writefileStaff()
  322. Dim filetext As String
  323. For i = 0 To formdb.Length - 1
  324. filetext = filetext + formdb(i).id.ToString
  325. filetext = filetext + "," + formdb(i).name
  326. filetext = filetext + "," + formdb(i).password
  327. filetext = filetext + "," + formdb(i).fname
  328. filetext = filetext + "," + formdb(i).sname + ";"
  329. Next
  330. My.Computer.FileSystem.WriteAllText("staff.txt", filetext, False)
  331. End Sub
  332.  
  333. Sub readstaff()
  334. Dim filetext As String = My.Computer.FileSystem.ReadAllText("staff.txt")
  335. Dim record() As String = filetext.Split(";")
  336. For i = 0 To record.Length - 1
  337. Dim field() As String = record(i).Split(",")
  338. If field(0) <> Nothing Then
  339. activeform.id = field(0)
  340. activeform.name = field(1)
  341. activeform.password = field(2)
  342. activeform.fname = field(3)
  343. activeform.sname = field(4)
  344. formdb(activeform.id) = activeform
  345. End If
  346.  
  347. Next
  348.  
  349. End Sub
  350. Sub writefileStudent()
  351. Dim filetext As String
  352. For i = 0 To userdb.Length - 1
  353. filetext = filetext + userdb(i).id.ToString
  354. filetext = filetext + "," + userdb(i).username
  355. filetext = filetext + "," + userdb(i).password
  356. filetext = filetext + "," + userdb(i).fname
  357. filetext = filetext + "," + userdb(i).sname
  358. filetext = filetext + "," + userdb(i).points.ToString + ";"
  359. Next
  360. My.Computer.FileSystem.WriteAllText("student.txt", filetext, False)
  361. End Sub
  362.  
  363. Sub readstudent()
  364. Dim filetext As String = My.Computer.FileSystem.ReadAllText("student.txt")
  365. Dim record() As String = filetext.Split(";")
  366. For i = 0 To record.Length - 1
  367. Dim field() As String = record(i).Split(",")
  368. If field(0) <> Nothing Then
  369. activeuser.id = field(0)
  370. activeuser.username = field(1)
  371. activeuser.password = field(2)
  372. activeuser.fname = field(3)
  373. activeuser.sname = field(4)
  374. activeuser.points = field(5)
  375. userdb(activeuser.id) = activeuser
  376. End If
  377.  
  378. Next
  379.  
  380. End Sub
  381. Sub AddUser(ByVal text As String, ByRef variable As String)
  382. Do
  383. Try
  384. Console.Write(text)
  385. variable = Console.ReadLine
  386. Exit Do
  387. Catch ex As Exception
  388. Console.WriteLine("Error: Please try again")
  389. End Try
  390. Loop
  391. End Sub
  392.  
  393. Sub AddUser(ByVal text As String, ByRef variable As Integer)
  394. Do
  395. Try
  396. Console.Write(text)
  397. variable = Console.ReadLine
  398. Exit Do
  399. Catch ex As Exception
  400. Console.WriteLine("Error: Please try again")
  401. End Try
  402. Loop
  403. End Sub
  404.  
  405.  
  406.  
  407.  
  408. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement