Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have 2 forms (login form,main form).
The login form enters the user by the database. In other words, the data of log in is stored in database.
A certain tabpage does not appear to a certain user (by privileges).
i have already used this way but it was not useful.So please if you don't mind could you tell me what I do.
C#
private void Login_Enter_but_Click(object sender, EventArgs e)
{
    this.m.connect.Open();
    this.mycmd = "select User_name , Password from Users where User_name='" + 
                 Login_YourName_txt.Text + 
                 "' and Password='" + login_pass_txt.Text + 
                 "'";
    this.command= new SqlCommand(this.mycmd,this.m.connect);
    if (this.command.ExecuteScalar() != null)
    {
        this.mycmd = "select U_State from Users where User_name='" + 
                     Login_YourName_txt.Text + 
                     "' and Password='" + 
                     login_pass_txt.Text + 
                     "'";
        this.command = new SqlCommand(this.mycmd, this.m.connect);
        string num = this.command.ExecuteScalar().ToString();
        if (num == "1")
        {
            this.Hide();
            Interfaces f = new Interfaces();
            f.Show();
            //f.tabControl1.TabPages.Remove(tabPage1);
            f.tabControl1.TabPages[0].Hide();
        }
        else
        {
            this.Hide();
            Interfaces f = new Interfaces();
            f.Show();
        }
        else
        {
            MessageBox.Show("Sorry,your name or passwrod are wrong try agian", "Sorry", 
                            MessageBoxButtons.OK, 
                            MessageBoxIcon.Warning);
            /* count++;
            if (count >= 4)
            {
                this.Close();
                count++;
            }*/
        }
        m.connect.Close();
    }
}


thank you for your cooperation
Posted
Updated 3-Jul-10 23:18pm
v5

Where to start. I hope no-one is paying for this code, because it is horrible.

this.mycmd = "select User_name , Password from Users where User_name='" +
Login_YourName_txt.Text +
"' and Password='" + login_pass_txt.Text +
"'";

This show you have no idea about security and should NOT be working on a secure system. Give me access to your login page and I can probably break in and I can certainly erase your entire database. Like I said, you would be literally a criminal and a liar to be charging anyone for this code, so I assume this is a class. Ask your teacher about SQL Injection attacks.

The SQL is also redundant. Read up on select count statements.

Also I suggest reading up on how professional developers design their code, 'n tiered development' is what you should google.

this.Hide();

is a dumb idea. Have your main form show a login form. Otherwise, your main form if you look it up anywhere in your app, is your hidden login form.

I would remove the tab page, not hide it. You've tried both. What other solution did you hope to find ? You could start with nothing and ADD them as needed, but those are really your only options.
 
Share this answer
 
You cannot hide and show tabs in a tabcontrol. The best you can do is to remove them all and add the ones you need, or to not show some in the first place.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900