ARTICLE
Application Level Security System
This article will provide help in developing Application Level Security System.
Download
Files:
Description
This is a common situation where one needs to restrict some user for accessing
some menus and some operations like AddNew Record, Edit / Change Record, Delete
Record etc. it is required for almost every application that runs in multi user
environment.
To fulfill this task you need some tables to hold data and a form to manipulate
that data according to your policy.
Follow the three steps given below to accomplish this task.
Step 1:
Create following tables in your database or in a new database.




Step 2 :
Make a form like given below (Codes attached)

Step 3
Add following codes in your mdiForm's or Form contains menus Load events.
Public Sub LoadMenu()
Try
Dim da As New SqlDataAdapter
Dim
ds As New
DataSet
Dim
ds1 As New
DataSet
Dim
strSql As String
Dim
nParentId As Integer
Dim
i As Integer
Dim
tsm As ToolStripMenuItem
For Each tsm In
frmMain.MenuStrip.Items
strSql = "select Menus.MenuID,Menus.MenuName from
UserRights " _
& "Inner Join Menus On Menus.MenuID=UserRights.MenuID
" _
& "Where userID=" & intUserId &
" And Menus.MenuName='" & tsm.Name.ToString &
"' and
Menus.programid=" & intProgramID
da =
New SqlDataAdapter(strSql, conSecurity)
ds.Tables.Clear()
ds = Nothing
ds = New DataSet
da.Fill(ds)
If
ds.Tables(0).Rows.Count > 0 Then
nParentId = ds.Tables(0).Rows(0).Item("Menuid")
tsm.Enabled = True
For
i = 0 To tsm.DropDown.Items.Count - 1
'MsgBox(tsm.DropDownItems(i).Text)
strSql =
"select Menus.MenuID,Menus.MenuName from UserRights " _
& "Inner Join Menus On Menus.MenuID=UserRights.MenuID AND Menus.programid
= UserRights.ProgramID " _
& " Where userID=" & intUserId & " And
Menus.MenuName='" & tsm.DropDownItems(i).Name &
"'"
da = New SqlDataAdapter(strSql,
conSecurity)
ds1.Tables.Clear()
ds1 = Nothing
ds1 = New DataSet
da.Fill(ds1)
If
ds1.Tables(0).Rows.Count > 0 Then
tsm.DropDownItems(i).Enabled = True
Else
tsm.DropDownItems(i).Enabled =
False
End If
Next
Else
' tsm.Enabled = False
End If
Next
Catch
ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "Loading
Menus")
End Try
End Sub
Article Extensions
Looks perfect. I downloaded and will try it.
Thanks very much - will save a lot of redundant effort