Best and quick solution
Create 3 table
1. ControlPoint with column Names: ControlId,ControlName,ControlProperty
Example 1, btnSave, Enable/Visible (It's property of that controls)
2. Roles with column Names: RoleId,RoleDesc
Example 101, Admin
102, Manager
103, StoreKeeper
3. RolePermission with Column named RolePermissionsId,FK_RoleId,FK_ControlId,IsAllowed
Example : 1, 101 , 1, True Check based on what you wants to set to that role
2, 102 , 1, False
protected bool SetFormAccess(Form frm)
{
Control item = null;
string ctrlName = "";
bool isAllow = false;
DataTable dt = GetControlList(string RoleId);
foreach (DataRow dr in dt.Rows)
{
ctrlName = dr["ControlName"].ToString();
isAllow = Convert.ToBoolean(dr["IsAllowed"]);
foreach (Control c in frm.Controls)
{
if (c.Name == ctrlName)
item = c;
}
if (item != null)
{
if (dr["ControlProperty"].ToString() == "Enabled")
item.Enabled = isAllow;
else if (dr["ControlProperty"].ToString() == "Visible")
item.Visible = isAllow;
else
item.Enabled = isAllow;
}
}
return true;
}