Click here to Skip to main content
14,383,699 members
   

C#

 
GeneralRe: Code not splitting for login form. C# Pin
Richard MacCutchan11-Nov-19 2:50
protectorRichard MacCutchan11-Nov-19 2:50 
AnswerRe: Code not splitting for login form. C# Pin
OriginalGriff11-Nov-19 2:32
protectorOriginalGriff11-Nov-19 2:32 
NewsRe: Code not splitting for login form. C# Pin
Eddy Vluggen11-Nov-19 4:20
mveEddy Vluggen11-Nov-19 4:20 
QuestionQuestion Pin
Member 1450924010-Nov-19 2:39
memberMember 1450924010-Nov-19 2:39 
QuestionRe: Question Pin
Richard MacCutchan10-Nov-19 2:44
protectorRichard MacCutchan10-Nov-19 2:44 
AnswerRe: Question Pin
OriginalGriff10-Nov-19 2:48
protectorOriginalGriff10-Nov-19 2:48 
AnswerRe: Question Pin
Eddy Vluggen10-Nov-19 2:51
mveEddy Vluggen10-Nov-19 2:51 
QuestionHow to disable other buttons based on user role login Pin
Member 146022408-Nov-19 23:05
memberMember 146022408-Nov-19 23:05 
Hi forum members,

I am very new beginner in programming. I am trying to develop a window application form database project. The database has four different user roles that log in at the UserLogin form (i.e. Admin, Accountant, HR and ReadOnly).

When any of the users logs in, they are all redirected to a Dashboard with four link buttons named; Admin, Accountant, HR and ReadOnly; that open to the individual's access pages. Now, with the exception of the Admin, I want all the other roles buttons on the Dashboard disabled except the button of the role user who logged in.

I will appreciate if someone could assist me modify my code in order to achieve the expected success.
Below is a section of my login code:-

<pre>        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.Show();

                cmd = new SqlCommand("SELECT Role from UsersLogin where Username=@Username", con);
                cmd.Parameters.AddWithValue("@Username", userText);
                string role = cmd.ExecuteScalar().ToString();
                MessageBox.Show("Welcome " + role);
                con.Close();
            }       
            else
            {
                MessageBox.Show("Access Denied!!");
                Application.Exit();
            }
            con.Close();
        }


modified 9-Nov-19 4:16am.

AnswerRe: How to disable other buttons based on user role login Pin
OriginalGriff8-Nov-19 23:30
protectorOriginalGriff8-Nov-19 23:30 
AnswerRe: How to disable other buttons based on user role login Pin
Richard MacCutchan8-Nov-19 23:53
protectorRichard MacCutchan8-Nov-19 23:53 
GeneralRe: How to disable other buttons based on user role login Pin
Mycroft Holmes9-Nov-19 11:21
memberMycroft Holmes9-Nov-19 11:21 
GeneralRe: How to disable other buttons based on user role login Pin
OriginalGriff9-Nov-19 11:35
protectorOriginalGriff9-Nov-19 11:35 
GeneralRe: How to disable other buttons based on user role login Pin
Richard MacCutchan9-Nov-19 21:53
protectorRichard MacCutchan9-Nov-19 21:53 
GeneralRe: How to disable other buttons based on user role login Pin
Mycroft Holmes10-Nov-19 11:08
memberMycroft Holmes10-Nov-19 11:08 
AnswerRe: How to disable other buttons based on user role login Pin
BillWoodruff9-Nov-19 21:31
mveBillWoodruff9-Nov-19 21:31 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 3:01
mveEddy Vluggen10-Nov-19 3:01 
GeneralRe: How to disable other buttons based on user role login Pin
BillWoodruff10-Nov-19 5:24
mveBillWoodruff10-Nov-19 5:24 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 7:16
mveEddy Vluggen10-Nov-19 7:16 
GeneralRe: How to disable other buttons based on user role login Pin
Richard MacCutchan10-Nov-19 5:49
protectorRichard MacCutchan10-Nov-19 5:49 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 7:14
mveEddy Vluggen10-Nov-19 7:14 
GeneralRe: How to disable other buttons based on user role login Pin
Richard MacCutchan10-Nov-19 7:20
protectorRichard MacCutchan10-Nov-19 7:20 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 8:32
mveEddy Vluggen10-Nov-19 8:32 
GeneralRe: How to disable other buttons based on user role login Pin
BillWoodruff10-Nov-19 7:47
mveBillWoodruff10-Nov-19 7:47 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 8:45
mveEddy Vluggen10-Nov-19 8:45 
GeneralRe: How to disable other buttons based on user role login Pin
Eddy Vluggen10-Nov-19 9:01
mveEddy Vluggen10-Nov-19 9:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.