public void GetTest() { ConnectionString Dbconnect = new ConnectionString(); if (TestCode.Text == "") { MessageBox.Show("Please Enter A Subject Code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); TestCode.Focus(); return; } try { SqlConnection connection = new SqlConnection(); connection = new SqlConnection(Dbconnect.Connect()); connection.Open(); SqlCommand command = new SqlCommand(); command = new SqlCommand("SELECT * FROM test WHERE testcode='" + TestCode.Text + "'", connection); SqlDataReader datareader = command.ExecuteReader(); int count = 0; while (datareader.Read()) { count = count + 1; } datareader.Close(); connection.Close(); if (count == 1) { this.Hide(); //QuestionPage questionPage = new QuestionPage(); //questionPage.Show(); QuestionPage question = new QuestionPage(); question.passCode = TestCode.Text.ToString(); question.Show(); } else { MessageBox.Show("Wrong Passcode", "information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (SqlException exception) { MessageBox.Show(exception.Message, "information!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public void login(string userPass) { ConnectionString Dbconnect = new ConnectionString(); if (Usercode.Text == "") { MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); Usercode.Focus(); return; } try { SqlConnection connection = new SqlConnection(); connection = new SqlConnection(Dbconnect.Connect()); connection.Open(); SqlCommand command = new SqlCommand(); command = new SqlCommand("SELECT * FROM Users WHERE password='******'AND UserType='user'", connection); SqlDataReader datareader = command.ExecuteReader(); int count = 0; while (datareader.Read()) { count = count + 1; } datareader.Close(); connection.Close(); if (count == 1) { QuestionPage quest = new QuestionPage(); TestPage testPage = new TestPage(); this.Hide(); testPage.Show(); } else { MessageBox.Show("Wrong Passcode", "information!", MessageBoxButtons.OK, MessageBoxIcon.Information); Usercode.Text = ""; } } catch (SqlException exception) { MessageBox.Show(exception.Message, "information!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }