Problem with Dynamic Method To Enable or Disable Buttons in Forms

  • Thread starter Thread starter Tamer Galal
  • Start date Start date
T

Tamer Galal

Guest
I create a special program for the rights of users through three Forms the first Form is for the registration of user data and the second Form is for the addition of powers such as [AD, VIP, US] and the third Form is Form receives data from a Dynamic Method To Enable or Disable Controls Buttons in Forms From a TreeView for the name of the Form and the buttons belong to this Form to control fully of the forms and i build it with SQL Server

also the MenuStrip is working Ok but the buttons is not

Pleas Help

the method is:

public void RetrieveUserPermissionByRole(String Role, Form Form)
{
string query = "select Permissions_tbl.per_id, Permissions_tbl.per_name, Permissions_tbl.per_form, RolePermissions_tbl.role_code, RolePermissions_tbl.per_id, RolePermissions_tbl.user_id FROM Permissions_tbl INNER JOIN RolePermissions_tbl ON Permissions_tbl.per_id = RolePermissions_tbl.per_id WHERE Permissions_tbl.per_form = '" + Form.Name + "' AND RolePermissions_tbl.role_code = '" + Role + "' ";
SqlCommand cmd = new SqlCommand(query,dbhelper.GetDbConnection());
dbhelper.OpenDBConnection();
//create data Adapter
DataTable datatable = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
// this will query your database and return the result to your data

da.Fill(datatable);
dbhelper.CloseDbConnection();
da.Dispose();

// MessageBox.Show(datatable.Rows.Count.ToString());
for (int i = 0; i < datatable.Rows.Count; i++)
{
foreach (var MS in Form.Controls.OfType<MenuStrip>())
{
foreach (ToolStripMenuItem item in MS.Items)
{
if (item.Name == datatable.Rows[1].ToString())
{
if (datatable.Rows[5].ToString().Equals("1"))
{
item.Enabled = true;
}
else if (datatable.Rows[5].ToString().Equals("0"))
{
item.Enabled = false;
}
}
}
}

foreach (var BTN in Form.Controls.OfType<Button>())
{
if (BTN.Name == datatable.Rows[1].ToString())
{
if (datatable.Rows[5].ToString().Equals("1"))
{
BTN.Enabled = true;
}
else if (datatable.Rows[5].ToString().Equals("0"))
{
BTN.Enabled = false;
}
}
}
}
}

Continue reading...
 
Back
Top