public void GetTest() { if (TestCode.Text == "") { MessageBox.Show("Please Enter A Subject Code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); TestCode.Focus(); return; } try { var test = _testService.GetTestDetails(TestCode.Text); if (test != null) { _stateService.SetTestId(test.Id); this.Hide(); var questionPage = Program.CreateServiceProvider().GetRequiredService <QuestionPage>(); questionPage.ShowDialog(); } else { MessageBox.Show("Wrong Passcode", "information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (SqlException exception) { MessageBox.Show(exception.Message, "information!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
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); } }