Problems in working with different layers

Smanyx
Smanyx used Ask the Experts™
on
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!
'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

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,
A typical 3 tier architecture will have -
Presentation Layer - all UI stuff will go here.
Business Layer - your business related workflows, etc. goes here
Data Layer - all your data related stuff, e.g. connection, executing SPs, etc.
the code you had posted is missing the flow, i would suggest you take a look at the link below to get an idea of 3 tier architecture.
http://www.codeproject.com/KB/vb/N-Tier_Application_VB.aspx
http://www.codeproject.com/KB/architecture/three_tier_architecture.aspx 

Author

Commented:
Thanks for the links. I am exploring it that direction...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial