Advertisement
Guest User

Untitled

a guest
Apr 5th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. #Region "Constructors"
  2. 'Everytime we instantiate the object (ClsLogin) a connection to the database must be established
  3. Public Sub New()
  4.  
  5. con.ConnectionString = dbprovider & dbsource
  6. con.Open()
  7.  
  8. End Sub
  9.  
  10. #End Region
  11.  
  12. #Region "Methods"
  13. 'Function that logs the user in by using the employeeid, username, password, roleid and email.
  14. Public Function Login(strUsername As String, strPassword As String) As Boolean
  15.  
  16. 'Below is the command that will enable the program to find and use the username and password that is stored in the database of an employee
  17. Dim cmd As String
  18. cmd = "SELECT Employeeid, username, password, roleid, email FROM tblEmployees WHERE username = ? AND password = ?"
  19.  
  20. 'Create a new DataAdapter and establish a new SQL Command
  21. da = New OleDb.OleDbDataAdapter(cmd, con)
  22. da.SelectCommand.Parameters.Add("@username", OleDb.OleDbType.VarChar, 25).Value = strUsername
  23. da.SelectCommand.Parameters.Add("@password", OleDb.OleDbType.VarChar, 25).Value = strPassword
  24. da.Fill(ds, "Login")
  25. dt = ds.Tables("Login")
  26.  
  27. If dt.Rows.Count > 0 Then
  28. employeeid = dt.Rows(0).Item("Employeeid")
  29. username = dt.Rows(0).Item("username")
  30. password = dt.Rows(0).Item("password")
  31. Roleid = dt.Rows(0).Item("roleid")
  32. email = dt.Rows(0).Item("email")
  33. Return True
  34. Else
  35. Return False
  36. End If
  37.  
  38. da.Dispose()
  39. con.Close()
  40.  
  41.  
  42. End Function
  43. 'Function that builds the main menu by using the tables and information within the database
  44. Public Function GetMainMenu()
  45. Try
  46.  
  47. 'Below is the statement that will enable the program to select the correct fields to produce the correct Main Menu for each user
  48. Dim cmd As String
  49. cmd = "Select MenuText from tblMenuMaster1 Where MainMenuID = 0 and MenuID in (Select MenuID from tblAccess Where AccessID = " & Roleid & ") And isActive = 1"
  50.  
  51. da = New OleDb.OleDbDataAdapter(cmd, con)
  52.  
  53. da.Fill(ds, "MenuText")
  54. dt = ds.Tables("Menutext")
  55.  
  56. da.Dispose()
  57. con.Close()
  58. Return dt
  59.  
  60. Catch ex As Exception
  61. MsgBox(ex)
  62. End Try
  63. End Function
  64. 'Function that gets the MenuID from tblMenuMaster1 in the Database - regarding the specific access levels
  65. Public Function GetMenuID(Menutext As String)
  66.  
  67. 'Below is the command that will enable the program to ascertain the right access levels for the Manager, Admin and Employees
  68. Dim cmd As String
  69. cmd = "Select MenuID from tblMenuMaster1 Where MenuText = '" & Menutext & "'"
  70.  
  71. da = New OleDb.OleDbDataAdapter(cmd, con)
  72.  
  73. da.Fill(ds, "MenuText")
  74. dt = ds.Tables("Menutext")
  75.  
  76. da.Dispose()
  77. con.Close()
  78. Return dt
  79.  
  80. End Function
  81. 'Function that ascertains the correct menu text to be displayed on the form
  82. Public Function GetMenuText(parentMenuID As Integer)
  83.  
  84. 'Below is the statement that will enable the program to select the correct menu text from the database to be displayed within the main menu
  85. Dim cmd As String
  86. cmd = ""
  87. cmd = "Select MenuText from tblMenuMaster1 Where MainMenuID = " & parentMenuID & " And isActive = 1 And MenuID in (Select MenuID from tblAccess Where AccessId = " & Roleid & ")" & "Order BY MenuOrder"
  88.  
  89. da = New OleDb.OleDbDataAdapter(cmd, con)
  90.  
  91. da.Fill(ds, "parentMenuID")
  92. dt = ds.Tables("parentMenuID")
  93.  
  94. da.Dispose()
  95. con.Close()
  96.  
  97. Return dt
  98.  
  99. End Function
  100. 'Function that gets the correct formname that is stored in the database in order to produce the correct and desired main menu
  101. Public Function GetFormName(Menutext As String)
  102.  
  103. 'Below is the command that will select the correct formname that is stored in teh database
  104. Dim cmd As String
  105. cmd = ""
  106. cmd = "Select FormName from tblMenuMaster1 Where MenuText = '" & Menutext & "'"
  107.  
  108. da = New OleDb.OleDbDataAdapter(cmd, con)
  109.  
  110. da.Fill(ds, "formName")
  111. dt = ds.Tables("formName")
  112.  
  113. da.Dispose()
  114. con.Close()
  115.  
  116. Return dt
  117.  
  118. End Function
  119. 'Function that allows the user to update their own password
  120. Public Sub Updateuserpassword(stremployeeid As Integer, strpassword As String)
  121. Try
  122. da = New OleDb.OleDbDataAdapter()
  123. Dim command As OleDb.OleDbCommand
  124. command = New OleDb.OleDbCommand
  125.  
  126. Using da
  127. 'Below is the command that will enable the user to update their password and will be stored in the correct field in the database
  128. command.CommandText = "UPDATE Tblusers SET Tblusers.Password = ? WHERE (((Tblusers.UserID)=?));"
  129. command.Parameters.AddWithValue("@password", OleDb.OleDbType.VarChar).Value = strpassword
  130. command.Parameters.AddWithValue("@employeeid", stremployeeid)
  131.  
  132. command.Connection = con
  133. command.ExecuteNonQuery()
  134.  
  135. End Using
  136.  
  137. Catch ex As Exception
  138. MsgBox(ex.Message)
  139. End Try
  140. End Sub
  141. 'Function that allows the program - according to the correct access level - to create a new user to be inserted and stored in the database
  142. Public Sub InsertNewuser()
  143. Try
  144.  
  145. da = New OleDb.OleDbDataAdapter()
  146. Dim command As OleDb.OleDbCommand
  147. command = New OleDb.OleDbCommand
  148. 'Dim command As OleDb.OleDbCommand
  149. 'command = New OleDb.OleDbCommand
  150. 'Dim da As New OleDb.OleDbDataAdapter(command, con)
  151.  
  152. Using da
  153.  
  154. 'Below is the command that allow the user - with the correct access levels - to insert a new user with their username and password
  155. command.CommandText = "INSERT INTO Tblusers (Username, Password) VALUES( ?, ?)"
  156. 'command.Parameters.AddWithValue("@username", getUsername)
  157. 'command.Parameters.AddWithValue("@password", getpassword)
  158. command.Connection = con
  159. command.ExecuteNonQuery()
  160.  
  161. End Using
  162.  
  163. Catch ex As Exception
  164. MsgBox(ex.Message)
  165. End Try
  166. End Sub
  167.  
  168. #End Region
  169.  
  170.  
  171. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement