Smanyx
asked on
Problems in working with different layers
Hello Experts,
I have a class that handles the connection to the database. In that class I have a function: ConnectToLoginTable() that returns a dataset
My Login table has the following fields: LoginID, CardNumber, UserName, Password, UserType_ID
I want to authenticate a user from the Login form, on matching UserName and Password(enter in textbox with the ones stored in the table), display the Welcome form with full or restricted access depending on their UserType.
I use a separated architecture, a data layer where the database operations are handled: connection, different functions etc... in the clsDatabase class.
I am having trouble, at the user interface layer, to correctly manipulate the clsDatabase class.
I will be grateful if you could point me to some literature that explains more on N-tier or 3-tier architecture.
For the time being, I would also appreciate a hand as I am struggling with the following lines of code. An explanation on how it actually should be done will be very appreciated.
Thanks guys!
I have a class that handles the connection to the database. In that class I have a function: ConnectToLoginTable() that returns a dataset
My Login table has the following fields: LoginID, CardNumber, UserName, Password, UserType_ID
I want to authenticate a user from the Login form, on matching UserName and Password(enter in textbox with the ones stored in the table), display the Welcome form with full or restricted access depending on their UserType.
I use a separated architecture, a data layer where the database operations are handled: connection, different functions etc... in the clsDatabase class.
I am having trouble, at the user interface layer, to correctly manipulate the clsDatabase class.
I will be grateful if you could point me to some literature that explains more on N-tier or 3-tier architecture.
For the time being, I would also appreciate a hand as I am struggling with the following lines of code. An explanation on how it actually should be done will be very appreciated.
Thanks guys!
'DATA LAYER
Public Class clsDatabase
Public con As New OleDbConnection()
Public command As New OleDbCommand()
Public dataadapt As New OleDbDataAdapter()
Dim reader As New OleDbDataReader()
Public ds As New DataSet()
'Other Functions go here...
Public Function ConnectToLoginTable() As Data.DataSet
'check that we are connected to the database
If con.State = ConnectionState.Broken OrElse con.State = ConnectionState.Closed Then
' reopen the connection
con.Open()
End If
Try
command.CommandText = "SELECT Username, Password, UserType from LOGIN"
Catch ex As Exception
MsgBox(ex.Message & vbCrLf & ex.StackTrace)
Finally
dataadapt.Fill(ds, "LOGIN")
End Try
Return ds
End Function
End Class
'USER INTERFACE LAYER
Public Class LoginForm1
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim mycon As New clsDatabase
Dim theCommand As New OleDb.OleDbCommand
theCommand.CommandText = "SELECT * FROM LOGIN WHERE Username= '" & txtLoginUserName.Text & "' AND '" & txtLoginPW.Text & "';"
theCommand.ExecuteReader()
Dim Count As Integer
Count = mycon.ConnectToLoginTable.Tables(0).Rows.Count
Dim user_type As Integer
' i want to get the UserType from the ds and pass it to user_type
user_type = mycon.ds. ?????
If Count > 0 Then
Select Case user_type
Case 1
MessageBox.Show("Welcome to the System!")
Welcome.Size = New Size(1000, 750)
Welcome.StartPosition = FormStartPosition.CenterScreen
Welcome.btnAdministration.Enabled = False
Welcome.btnCirculationControl.Enabled = False
Welcome.btnLibraryOperations.Enabled = False
Welcome.btnVariousReports.Enabled = False
'Restricted access to member's area only
MembersArea.btnDischargeMode.Enabled = False
MembersArea.btnDischarge.Enabled = False
Welcome.Show()
Case 2
MessageBox.Show("Welcome to the System!")
Welcome.Size = New Size(1000, 750)
Welcome.StartPosition = FormStartPosition.CenterScreen
Welcome.btnAdministration.Enabled = False
Welcome.btnCirculationControl.Enabled = False
Welcome.btnLibraryOperations.Enabled = False
Welcome.btnVariousReports.Enabled = False
'Restricted access to member's area only
MembersArea.btnDischargeMode.Enabled = False
MembersArea.btnDischarge.Enabled = False
Welcome.Show()
Case 3
MessageBox.Show("Welcome to the System!")
Welcome.Size = New Size(1000, 750)
Welcome.StartPosition = FormStartPosition.CenterScreen
'Welcome.btnCirculationControl.Enabled = False
'Full access
Welcome.Show()
End Select
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER