Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB.NET
Private Sub loginbtn_Click_1(sender As System.Object, e As System.EventArgs) Handles loginbtn.Click
        For Each ctrl As Control In Me.Controls
            If (usernametxt.Text & passwordtxt.Text = String.Empty) Then
                ErrorProvider1.SetError(usernametxt, "Incorrect")
                ErrorProvider2.SetError(passwordtxt, "Incorrect")
                MsgBox("Fill The Details", MsgBoxStyle.Exclamation)
                Exit Sub
            End If
        Next
        con.Open()
        l = "Select username, password, type From Login where username='" & usernametxt.Text & "' and password='" & passwordtxt.Text & "'"
        com = New SqlCommand(l, con)
        dr = com.ExecuteReader
        dr.Read()
        If usernametxt.Text = dr.GetString(0) Then
            If passwordtxt.Text = dr.GetString(1) Then
                If dr.GetString(2) = "ADMIN" Then
                    Me.Hide()
                    HomePage.Show()
                ElseIf dr.GetString(2) = "EMPLOYEE" Then
                    Me.Hide()
                    HomePage.Show()
                    StudentReg.editbtn.Enabled = False
                    StudentReg.removebtn.Enabled = False
                    StaffReg.editbtn.Enabled = False
                    StaffReg.removebtn.Enabled = False
                    HomePage.CourseFeesToolStripMenuItem.Enabled = False
                    HomePage.BatchesToolStripMenuItem.Enabled = False
                    HomePage.EventsToolStripMenuItem.Enabled = False
                    Billing.Button1.Enabled = False
                    HomePage.ReportsToolStripMenuItem.Enabled = False
                End If
            End If
        Else
            MsgBox("Please Enter Correct Username And Password", MsgBoxStyle.Critical)
        End If
        usernametxt.Text = ""
        passwordtxt.Text = ""
        con.Close()
    End Sub


What I have tried:

I have create Login Form and Database in SQL Server. The database has table Login with 3 columns username, password, type. If type = ADMIN then he have access to full application but if type = employee then some buttons on other form get disable. At first time the code is working when admin or employee gets logged in. i.e. When employee gets logged and open a form the buttons get disable but when he closes and opens the same form again the buttons get enabled. I tried many things but I have not be able solve the problem. Help me with some solution. I want the buttons should be disable throughout the time when employee is logged in to application.
Posted
Updated 23-Feb-16 19:39pm

Change your code to have a global variable that stores their access. Then in the form's load event set all the enabled properties. You're only setting them when login is clicked.
 
Share this answer
 
Comments
Ashutosh Dutondkar 23-Feb-16 20:36pm    
Actually I have tried the above coding so far and I m not so good in VB. Can you please help me to declare them globally. I mean how to save their access and declare them globally. I'll be very thankful if you help me with the same.
ZurdoDev 24-Feb-16 7:08am    
See http://stackoverflow.com/questions/4529862/declare-global-variables-in-visual-studio-2010-and-vb-net
Ashutosh Dutondkar 25-Feb-16 8:39am    
Sorry RyanDev! But m not able to do it. Please can you help me Editing my given code! Making Global Variables in it! It will help me alot Sir!
Hi Ashutosh,

Do one thing disable(set Enabled=false) all buttons by default in design(source).
Then try to do same thing.


Ashish
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900