Guest User

Untitled

a guest
Jul 11th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub cmdadd_Click()
  2. frmcreate.Show
  3. cmdsavelogin.Visible = True
  4. cmdgenp.Visible = True
  5. cmdgenu.Visible = True
  6. txtusername.Visible = True
  7. txtpassword.Visible = True
  8. lbluser.Visible = True
  9. lblpass.Visible = True
  10.  
  11. If cmdstafflogin.Visible = True Then
  12. cmdstafflogin.Visible = False
  13. End If
  14.  
  15.  
  16. End Sub
  17.  
  18. Private Sub cmdbrowse_Click()
  19. Unload Me
  20. frmgamecentral.Show
  21. 'this takes you to the next form and unloads the current form
  22.  
  23. End Sub
  24.  
  25. Private Sub cmdcustomer_Click()
  26. 'the following causes certain buttons and textboxes to appear.
  27. lbluser.Visible = True
  28. txtusername.Visible = True
  29.  
  30. lblpass.Visible = True
  31. txtpassword.Visible = True
  32.  
  33. cmdlogin.Visible = True
  34. If cmdsavelogin.Visible = True Then
  35. cmdsavelogin.Visible = False
  36. End If
  37.  
  38. If cmdgenp.Visible = True Then
  39. cmdgenp.Visible = False
  40. End If
  41.  
  42. If cmdgenu.Visible = True Then
  43. cmdgenu.Visible = False
  44. End If
  45.  
  46. frmcreate.Hide
  47. frmcreate.txtlast.Text = ""
  48. frmcreate.txtname.Text = ""
  49. frmcreate.txtstreet.Text = ""
  50.  
  51. 'certain command buttons are undesirable and the following invisible if they are visible
  52. If cmdstafflogin.Visible = True Then
  53. cmdstafflogin.Visible = False
  54. End If
  55.  
  56.  
  57.  
  58.  
  59.  
  60. End Sub
  61.  
  62. Private Sub cmdgenp_Click()
  63. txtpassword.PasswordChar = ""
  64. Randomize
  65. txtpassword = Int(Rnd * 10000)
  66.  
  67. 'the code above generates a random number between 0 and 10000 which is used as a password
  68.  
  69.  
  70. End Sub
  71.  
  72.  
  73.  
  74.  
  75. Private Sub cmdgenu_Click()
  76. first = frmcreate.txtname.Text
  77. last = frmcreate.txtlast.Text
  78. street = frmcreate.txtstreet.Text
  79.  
  80. txtusername.Text = Mid(first, 1, 1) & Mid(last, 1, 3) & Mid(street, 1, 3)
  81.  
  82.  
  83. MsgBox ("please write your username down for future reference.")
  84.  
  85. End Sub
  86.  
  87.  
  88.  
  89. Private Sub cmdleave_Click()
  90. Unload Me
  91. frmlogin.Show
  92.  
  93. End Sub
  94.  
  95. Private Sub cmdlogin2_Click()
  96. 'login code
  97. aSQL = " SELECT username, password FROM acc WHERE username = '" & txtusername.Text & "'" & " And password =  '" & txtpassword.Text & "'" & ""
  98. 'selects username and password that mathes in the database to whats written in corresponding textboxes
  99.  
  100. With accs
  101. .Open aSQL, connect
  102. If .EOF Then
  103.   MsgBox ("Username or Password Incorrect")
  104.   GoTo Redo
  105. End If
  106. End With
  107.  
  108.  
  109. If formrelation = 1 Then
  110. frmlogin.Hide
  111. loginname = txtusername.Text
  112. Unload Me
  113. frmgameform.Show
  114.  
  115. ElseIf formrelation = 2 Then
  116. frmlogin.Hide
  117. loginname = txtusername.Text
  118. Unload Me
  119. frmbasket.Show
  120. End If
  121.  
  122.  
  123. Redo:
  124. accs.Close
  125. Set accs = Nothing
  126. End Sub
  127.  
  128. Private Sub cmdsavelogin_Click()
  129.  
  130. If txtusername.Text = "" Or txtpassword.Text = "" Then
  131. MsgBox ("Boxes are empty")
  132.  
  133. ElseIf Not (txtusername.Text = "") And Not (txtpassword.Text = "") Then
  134. With customers
  135. .ActiveConnection = connect
  136. .LockType = adLockOptimistic
  137. .CursorType = adOpenKeyset
  138. .Open bSQL
  139.  
  140. customers.AddNew
  141. 'this resets the record set
  142.  
  143.    
  144.     .Fields("CustomerID").Value = txtusername.Text
  145.     .Fields("Firstname").Value = frmcreate.txtname.Text
  146.     .Fields("Surname").Value = frmcreate.txtlast.Text
  147.     .Fields("Address").Value = frmcreate.txtstreet.Text
  148.    
  149.    
  150.    
  151.  
  152. 'this saves all details in the textboxes into the corresponding fields in the database
  153.    
  154. MsgBox ("Customer details saved")
  155.    
  156.  
  157.    
  158. End With
  159.  
  160. customers.Update
  161.  
  162. '----------------------------------------------------------------------------------------------
  163.  
  164.  
  165. With accs
  166. .ActiveConnection = connect
  167. .LockType = adLockOptimistic
  168. .CursorType = adOpenKeyset
  169. .Open aSQL
  170.  
  171. accs.AddNew
  172. 'this resets the record set
  173.  
  174.    
  175.     .Fields("username").Value = txtusername.Text
  176.     .Fields("password").Value = txtpassword.Text
  177.     .Fields("CustomerID").Value = txtusername.Text
  178.    
  179.    
  180.    
  181.  
  182. 'this saves all details in the textboxes into the corresponding fields in the database
  183.    
  184. MsgBox ("Customer details saved")
  185.    
  186.  
  187.    
  188. End With
  189. 'all boxes except txtNewID are cleared as it is needed for saving in the next form
  190. accs.Update
  191. '----------------------------------------------------------------------------------------------
  192. loginname = txtusername.Text
  193. Unload Me
  194. frmgamecentral.Show
  195.  
  196. End If
  197. Set customers = Nothing
  198. Set accs = Nothing
  199. End Sub
  200.  
  201. Private Sub cmdlogin_Click()
  202.  
  203. 'login code
  204. aSQL = " SELECT username, password FROM acc WHERE username = '" & txtusername.Text & "'" & " And password =  '" & txtpassword.Text & "'" & ""
  205. 'selects username and password that mathes in the database to whats written in corresponding textboxes
  206. With accs
  207.  
  208. .Open aSQL, connect
  209.  
  210. If .EOF Then
  211.   MsgBox ("Username or Password Incorrect")
  212.   GoTo Redo
  213. End If
  214. End With
  215.  
  216.  
  217. frmgamecentral.Show
  218. frmlogin.Hide
  219. loginname = txtusername.Text
  220. Unload Me
  221.  
  222. Redo:
  223. accs.Close
  224. Set accs = Nothing
  225. End Sub
  226.  
  227. Private Sub cmdsavelogin2_Click()
  228. If txtusername.Text = "" Or txtpassword.Text = "" Then
  229. MsgBox ("Boxes are empty")
  230.  
  231. ElseIf Not (txtusername.Text = "") And Not (txtpassword.Text = "") Then
  232. With customers
  233. .ActiveConnection = connect
  234. .LockType = adLockOptimistic
  235. .CursorType = adOpenKeyset
  236. .Open bSQL
  237.  
  238. customers.AddNew
  239. 'this resets the record set
  240.  
  241.    
  242.     .Fields("CustomerID").Value = txtusername.Text
  243.     .Fields("Firstname").Value = frmcreate.txtname.Text
  244.     .Fields("Surname").Value = frmcreate.txtlast.Text
  245.     .Fields("Address").Value = frmcreate.txtstreet.Text
  246.    
  247.    
  248.    
  249.  
  250. 'this saves all details in the textboxes into the corresponding fields in the database
  251.    
  252. MsgBox ("Customer details saved")
  253.    
  254.  
  255.    
  256. End With
  257.  
  258. customers.Update
  259.  
  260. '----------------------------------------------------------------------------------------------
  261.  
  262.  
  263. With accs
  264. .ActiveConnection = connect
  265. .LockType = adLockOptimistic
  266. .CursorType = adOpenKeyset
  267. .Open aSQL
  268.  
  269. accs.AddNew
  270. 'this resets the record set
  271.  
  272.    
  273.     .Fields("username").Value = txtusername.Text
  274.     .Fields("password").Value = txtpassword.Text
  275.     .Fields("CustomerID").Value = txtusername.Text
  276.    
  277.    
  278.    
  279.  
  280. 'this saves all details in the textboxes into the corresponding fields in the database
  281.    
  282. MsgBox ("Customer details saved")
  283.    
  284.  
  285.    
  286. End With
  287.  
  288. accs.Update
  289. '----------------------------------------------------------------------------------------------
  290. loginname = txtusername.Text
  291. Unload Me
  292.  
  293.  
  294. End If
  295. Set customers = Nothing
  296. Set accs = Nothing
  297. End Sub
  298. End Sub
  299.  
  300. Private Sub cmdstafflogin_Click()
  301. 'login code
  302. stSQL = " SELECT Username, Password FROM [Staff acc] WHERE Username = '" & txtusername.Text & "'" & " And Password =  '" & txtpassword.Text & "'" & ""
  303. 'selects username and password that mathes in the database to whats written in corresponding textboxes
  304. With staccs
  305. .Open stSQL, connect
  306. If .EOF Then 'if the search doesnt match up then a meesage box appears and the procedure skips to the end
  307.  MsgBox ("Username or Password Incorrect")
  308.   GoTo Redo
  309. End If
  310. End With
  311.  
  312. Unload Me
  313. frmstaffhome.Show
  314. frmcreate.Hide
  315.  
  316.  
  317.  
  318. Redo:
  319. staccs.Close
  320. Set staccs = Nothing
  321. End Sub
  322.  
  323. Private Sub cmdStaff_Click()
  324. 'the following causes certain buttons and textboxes to appear.
  325. lbluser.Visible = True
  326. txtusername.Visible = True
  327. lblpass.Visible = True
  328. txtpassword.Visible = True
  329. cmdstafflogin.Visible = True
  330.  
  331. 'certain command buttons are undesirable and the following invisible if they are visible
  332. If cmdsavelogin.Visible = True Then
  333. cmdsavelogin.Visible = False
  334. End If
  335.  
  336. If cmdgenu.Visible = True Then
  337. cmdgenu.Visible = False
  338. End If
  339.  
  340. If cmdgenp.Visible = True Then
  341. cmdgenp.Visible = False
  342. End If
  343.  
  344. If cmdlogin.Visible = True Then
  345. cmdlogin.Visible = False
  346. End If
  347.  
  348. frmcreate.Hide
  349.  
  350. End Sub
  351.  
  352. Private Sub Form_Load()
  353. 'these hide certain command buttons to avoid confusion
  354. lbluser.Visible = False
  355. txtusername.Visible = False
  356. cmdgenu.Visible = False
  357. lblpass.Visible = False
  358. txtpassword.Visible = False
  359. cmdgenp.Visible = False
  360. cmdsavelogin.Visible = False
  361. cmdlogin.Visible = False
  362. cmdstafflogin.Visible = False
  363. cmdlogin2.Visible = False
  364. cmdsavelogin2.Visible = False
  365. cmdleave.Visible = False
  366.  
  367. '--------------------------------------------------------------------------------
  368. 'database connection
  369. 'this code is used to retrieve information from tables in the database
  370. Set connect = New ADODB.Connection
  371. DBsePath = App.Path & "\gamedb.mdb"
  372. connect.ConnectionString = "provider = microsoft.jet.OLEDB.4.0;data source=" & DBsePath
  373. connect.Open
  374.  
  375.  
  376. bSQL = "SELECT * FROM customer"
  377. aSQL = "SELECT * FROM acc"
  378. stSQL = "SELECT * FROM Staff acc"
  379.  
  380. End Sub
Add Comment
Please, Sign In to add comment