Hi Forum Colleagues,
Gratefully appreciate your prompt assistance when I post a question on the platform.
On developing my payroll database, I have gotten to a stage of building users access control. I have successfully created the users login control, where when the user role logs in within the respective role, with the username and password the user is directed to the dashboard where all the respective links to their respective privileges are accessed.
Now, my current problem is that, apart from the Admin, whenever any user logs in, all other command buttons on the dashboard should be disabled except the command button of the user role that logged. Other roles on the dashboard are Accountant, HR and ReadOnly.
I want to attach the text code so that someone could help modify my effort for me.
Thanks for your assistance
Gratefully appreciate your prompt assistance when I post a question on the platform.
On developing my payroll database, I have gotten to a stage of building users access control. I have successfully created the users login control, where when the user role logs in within the respective role, with the username and password the user is directed to the dashboard where all the respective links to their respective privileges are accessed.
Now, my current problem is that, apart from the Admin, whenever any user logs in, all other command buttons on the dashboard should be disabled except the command button of the user role that logged. Other roles on the dashboard are Accountant, HR and ReadOnly.
I want to attach the text code so that someone could help modify my effort for me.
Thanks for your assistance
C#:
private void loginButton_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
SqlCommand command = new SqlCommand();
con.Open();
string userText = userTextBox.Text;
string passText = pwdTextBox.Text;
SqlCommand cmd = new SqlCommand("select role from UsersLogin where UserName='" + userTextBox.Text + "'and Password='" + pwdTextBox.Text + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Welcome to the Dashboard");
this.Hide();
Dashboard dashboard = new Dashboard();
dashboard.Show();
cmd = new SqlCommand("SELECT Role from UsersLogin where Username=@Username", con);
cmd.Parameters.AddWithValue("[USER=7968]@username[/USER]", userText);
string role = cmd.ExecuteScalar().ToString();
MessageBox.Show("Welcome " + role);
con.Close();
}
else
{
MessageBox.Show("Access Denied!!");
Application.Exit();
}
con.Close();
}
Last edited by a moderator: