Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,
I am using MS Access and VB.Net 2008 and I need help

1. I have Purchases and Employee Information forms with buttons (Add, Save, Update, Delete and Reload).
2. Main menu form
3. Login form.
I want to limit some privileges for the User in such a way that if the User logs in, Update and Delete buttons should be disabled so that the User is unable to Delete and Update records unless admin.

I have coded the login button in the login form as shown below. But if I logs in as User (Username: system. Password: manager) and open purchases or Employees information form, it first disable Delete and Update buttons and later they become active (not disabled) after adding another record or clicking reload button.

Below is the coding:

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

'Admin login
Dim admin As String
Dim administrator As String

'User login
Dim system As String
Dim manager As String

If txtadmin.Text = "" Then : MsgBox("Please input User Name", MsgBoxStyle.Exclamation) : txtadmin.Focus() : Exit Sub : End If
If txtadmin1.Text = "" Then : MsgBox("Please input Password", MsgBoxStyle.Exclamation) : txtadmin1.Focus() : Exit Sub : End If

If txtadmin.Text = "admin" And txtadmin1.Text = "administrator" Then
Me.Hide()

ElseIf txtadmin.Text = "system" And txtadmin1.Text = "manager" Then
frmPurchases.btnDelete.Enabled = False
frmPurchases.btnUpdate.Enabled = False

frmEmployessDetails.btnDelete.Enabled = False
frmEmployessDetails.btnUpdate.Enabled = False


Me.Hide()
Else
MsgBox("Sorry, Your Login Detail is invalid" & vbCrLf & vbCrLf & "Please contact the system administrator", MsgBoxStyle.Critical MsgBoxStyle.OkOnly, "Error: Username or Password Invalid")
txtadmin.Focus()

txtadmin.Clear()
txtadmin1.Clear()

End If
End Sub
Posted

1 solution

C#
class security
{
 public static string role;
}
Create a column in users table [Role]
now read that role at the time of login
store it in static variable (i think shared in vb.net)
initialize like this
security.role=usertable.Row[0]["Role"];

now on any form load check it like this
form_load(object obj,eventargs sender)
{
   if(security.role=="admin")
      btnsave.Enabled=false;
}
 
Share this answer
 
Comments
Member 9493910 3-Sep-13 8:15am    
Hi Zafar Zafi Thank you very much. I am really not familiar with C# but if you could provide vb.net codes for this steps Thank you

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