none
logon with privaleges RRS feed

  • Question

  • i am creating a store system, and am trying to give privaleges to the admin to access the entire system and the cashier to access the form for sales only without accessing the inventory and sales reports. in my ms database i have a table with Username, Password, Role and StaffID. Please help

    Imports System.Data.OleDb
    Public Class frmLogin

        Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
            Try

                sqL = "SELECT * FROM Users WHERE Username = '" & txtUser.Text & "' AND pwd = '" & txtPwd.Text & "'"
                ConnDB()
                cmd = New OleDbCommand(sqL, conn)

                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)

                If dr.Read = True Then

                    frmMain.lblEmployeeNo.Text = dr("StaffID")


                    frmMain.ManageToolStripMenuItem.Enabled = True
                    'frmMain.TransactionToolStripMenuItem.Enabled = False
                    frmMain.SalesReportToolStripMenuItem.Enabled = True
                    frmMain.MenuStrip1.Visible = True


                    txtUser.Text = ""
                    txtPwd.Text = ""
                    Me.Close()
                ElseIf txtUser.Text = "user" And txtPwd.Text = "password" Then
                    MsgBox("Welcome Cashier")

                    frmMain.ManageToolStripMenuItem.Enabled = False
                    'frmMain.TransactionToolStripMenuItem.Enabled = False
                    frmMain.SalesReportToolStripMenuItem.Enabled = False
                    frmMain.MenuStrip1.Visible = True

                    txtUser.Text = ""
                    txtPwd.Text = ""
                    Me.Close()
                Else
                    MsgBox("Incorrect username or password!", MsgBoxStyle.Critical, "Login")
                    txtPwd.Focus()
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                cmd.Dispose()
                conn.Close()
            End Try
        End Sub

        Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click
            If MsgBox("Are you sure you want to close?", MsgBoxStyle.YesNo, "Close Window") = MsgBoxResult.Yes Then
                Me.Close()
                frmMain.Close()
            End If
            txtUser.Focus()
        End Sub

        Private Sub frmLogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        End Sub
    End Class

    • Moved by 宝宝徐 Thursday, December 7, 2017 2:21 AM
    Wednesday, December 6, 2017 10:14 AM

All replies