I am working on a windows forms app that uses a login window, and according to the selected username you get redirected to the form that belongs to that username. In a login window user selects his account name from a ComboBox
and types a correct password in textbox. If wrong password is inserted, user gets a warning message box. The problem is that my procedure with IF an ELSE statements for this login is a total mess.
My problem: If I correctly login with one of the accounts, new form opens, BUT all of the other message boxes from other ELSE statements with error MessageBoxs
will still show up in new form. How can I design this differently. Note: Guest
user does not need password.
My code:
private void button1_Click(object sender, EventArgs e)
{
string selectedUser = this.comboBox1.GetItemText(this.comboBox1.SelectedItem);
if (selectedUser == "Guest")
{
Form3 form5 = new Form3();
form5.Show();
form5.Activate();
this.Hide();
}
if ((selectedUser == "Admin") && (textBox1.Text== "password"))
{
Form1 form3 = new Form1();
form3.Show();
form3.Activate();
this.Hide();
}
else MessageBox.Show("Password is incorrect!", "ERROR!");
if ((selectedUser == "Limited") && (textBox1.Text== "limited"))
{
Form2 form4 = new Form2();
form4.Show();
form4.Activate();
this.Hide();
}
else MessageBox.Show("Password is incorrect!", "ERROR!")
}
Aucun commentaire:
Enregistrer un commentaire