private void bt_back_Click(object sender, RoutedEventArgs e) { StudentMain studentMain = new StudentMain(); studentMain.Show(); this.Close(); }
private void btnSubmit_Click(object sender, RoutedEventArgs e) { SqlConnection sqlCon = new SqlConnection(@"SERVER=79.107.181.7; DATABASE= Learn_English; USER ID = TestUser; PASSWORD = TestPassword ;"); try { if (sqlCon.State == ConnectionState.Closed) { sqlCon.Open(); } String query = "SELECT COUNT(1) FROM Users WHERE username=@Username AND password=@Password"; SqlCommand sqlCmd = new SqlCommand(query, sqlCon); sqlCmd.CommandType = CommandType.Text; sqlCmd.Parameters.AddWithValue("@Username", txtUsername.Text); sqlCmd.Parameters.AddWithValue("@Password", txtPassword.Password); int count = Convert.ToInt32(sqlCmd.ExecuteScalar()); if (count == 1) { String rolequery = "SELECT role FROM Users WHERE username=@Username AND password=@Password"; SqlCommand rolesqlCmd = new SqlCommand(rolequery, sqlCon); rolesqlCmd.CommandType = CommandType.Text; rolesqlCmd.Parameters.AddWithValue("@Username", txtUsername.Text); rolesqlCmd.Parameters.AddWithValue("@Password", txtPassword.Password); SqlDataReader reader = rolesqlCmd.ExecuteReader(); while (reader.Read()) { var roleBoolean = reader.GetBoolean(0); if (roleBoolean) { TeacherMain teacherMain = new TeacherMain(); teacherMain.Show(); this.Close(); break; } else { StudentMain studentMain = new StudentMain(); studentMain.Show(); this.Close(); break; } } } else { MessageBox.Show("Username or password is incorrect. Please contact the admin."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { sqlCon.Close(); } }
private void btnSubmit_Click(object sender, RoutedEventArgs e) { SqlConnection sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString); try { if (sqlConnection.State == ConnectionState.Closed) { sqlConnection.Open(); } String query = "SELECT COUNT(1) FROM Students WHERE student_username=@Username AND student_password=@Password"; SqlCommand sqlCmd = new SqlCommand(query, sqlConnection); sqlCmd.CommandType = CommandType.Text; sqlCmd.Parameters.AddWithValue("@Username", txtUsername.Text); sqlCmd.Parameters.AddWithValue("@Password", txtPassword.Password); int count = Convert.ToInt32(sqlCmd.ExecuteScalar()); if (count == 1) { String id_query = "SELECT student_uid FROM Students WHERE student_username=@Username AND student_password=@Password"; SqlCommand id_sqlCmd = new SqlCommand(id_query, sqlConnection); id_sqlCmd.CommandType = CommandType.Text; id_sqlCmd.Parameters.AddWithValue("@Username", txtUsername.Text); id_sqlCmd.Parameters.AddWithValue("@Password", txtPassword.Password); student_uid = Convert.ToInt32(id_sqlCmd.ExecuteScalar()); student_username = txtUsername.Text; StudentMain studentMain = new StudentMain(); studentMain.Show(); this.Close(); } else { MessageBox.Show("Username or password is incorrect. Please contact the admin."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { sqlConnection.Close(); } }
private void bt_main_Click(object sender, RoutedEventArgs e) { StudentMain studentMain = new StudentMain(); studentMain.Show(); }