private void backToMainButton_Click(object sender, EventArgs e) { Form_MainAdmin admin = new Form_MainAdmin(); admin.Show(); this.Close(); }
private void button_BackToMainClick(object sender, EventArgs e) { Form_MainAdmin fa = new Form_MainAdmin(); fa.Show(); this.Close(); }
private void button_SignInClick(object sender, EventArgs e) { try { myConnection = new SqlConnection(connection); myCommand = new SqlCommand("SELECT username, password FROM Accounts WHERE username = @username AND password = @password", myConnection); SqlParameter username = new SqlParameter("@username", SqlDbType.VarChar); SqlParameter password = new SqlParameter("@password", SqlDbType.VarChar); username.Value = textBox1.Text; password.Value = textBox2.Text; myCommand.Parameters.Add(username); myCommand.Parameters.Add(password); myCommand.Connection.Open(); SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); if (myReader.Read() == true) { if (textBox1.Text == "admin" && textBox2.Text == "admin") { MessageBox.Show("Admin Login Successfull!", "Login Success"); Form_MainAdmin admin = new Form_MainAdmin(); admin.Show(); this.Hide(); } else { MessageBox.Show("Login Successfull!", "Login Success"); Form_Login.LoginName = textBox1.Text; Form_MainUser user = new Form_MainUser(); user.Show(); this.Hide(); } } else { if (textBox1.Text == "" && textBox2.Text == "") { MessageBox.Show("Username and Password cannot be empty!", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBox1.Text == "") { MessageBox.Show("Username cannot be empty!", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBox2.Text == "") { MessageBox.Show("Password cannot be empty!", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBox1.Text != username.ToString()) { MessageBox.Show("Username or Password not found!", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Login failed! Try again!", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (myConnection.State == ConnectionState.Open) { myConnection.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }