public static void GetCorrectAnswer() { OleDbConnection cn = new OleDbConnection(); cn.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString(); cn.Open(); OleDbCommand thisComand = cn.CreateCommand(); thisComand.CommandText = @"SELECT CorrectAnswer FROM " + User.NameOfTest + " WHERE numQuestion = " + User.ArrOfQuestions[User.NumQuestion]; OleDbDataReader thisReader = thisComand.ExecuteReader(); string FromDb = string.Empty; if (thisReader.Read()) { FromDb += thisReader["CorrectAnswer"]; } AddToList.SaveCorrectAnswer(FromDb); cn.Close(); }
private void bTest1_Click(object sender, EventArgs e) { bFinish.Show(); User.NameOfTest = cbListTests.SelectedValue.ToString(); pTestsMain.Hide(); lNameTest.Text = "Test: " + User.NameOfTest; lScore.Text = ""; DB.GetAmountOfQuestions(); AddToList.SetDefaultAnswers(); pCenter.Show(); pTriggers.Show(); User.NumQuestion = 1; User.TotalScore = 0; TestFinished = false; bBack.Hide(); bNext.Show(); ShowQuestions(); pLeft.Hide(); tbQ1.BackColor = Color.FromName("White"); tbQ2.BackColor = Color.FromName("White"); tbQ3.BackColor = Color.FromName("White"); tbQ4.BackColor = Color.FromName("White"); TestFinished = false; }
void ShowQuestions() { rA.Checked = false; rB.Checked = false; rC.Checked = false; rD.Checked = false; User.Question = (DB.LoadTest1(@"SELECT Questions FROM " + User.NameOfTest + " WHERE numQuestion = " + User.ArrOfQuestions[User.NumQuestion])); rtbQuestionField.Text = User.Question; User.AnswerQ1 = ""; User.AnswerQ2 = ""; User.AnswerQ3 = ""; User.AnswerQ4 = ""; DB.GetQAnswers(User.ArrOfQuestions[User.NumQuestion]); if (User.AnswerQ1 == "") { tbQ1.Hide(); rA.Hide(); } else { tbQ1.Show(); rA.Show(); } if (User.AnswerQ2 == "") { tbQ2.Hide(); rB.Hide(); } else { tbQ2.Show(); rB.Show(); } if (User.AnswerQ3 == "") { tbQ3.Hide(); rC.Hide(); } else { tbQ3.Show(); rC.Show(); } if (User.AnswerQ4 == "") { tbQ4.Hide(); rD.Hide(); } else { tbQ4.Show(); rD.Show(); } DB.GetCorrectAnswer(); tbQ1.Text = User.AnswerQ1; tbQ2.Text = User.AnswerQ2; tbQ3.Text = User.AnswerQ3; tbQ4.Text = User.AnswerQ4; lQuestion.Text = "Questions: " + User.NumQuestion + "/" + User.AmountOfQuestions; CheckUserAnswer(); AddToList.MakeListOfQuestion(); if (User.NumQuestion == User.AmountOfQuestions) { bNext.Hide(); } else { bNext.Show(); } if (User.NumQuestion == 1) { bBack.Hide(); } else { bBack.Show(); } }
public void ShowQuestions() { User.NameOfTest = cbListTests.SelectedValue.ToString(); if (User.NumQuestion < User.AmountOfQuestions) { bBack.Show(); bNext.Show(); } if (User.NumQuestion > 1) { bBack.Show(); bNext.Show(); } if (User.NumQuestion == 1) { bBack.Hide(); bNext.Show(); } if (User.NumQuestion == 0) { User.NumQuestion = 1; bBack.Hide(); bNext.Hide(); return; } User.AmountOfQuestions = 0; DB.GetAmountOfQuestions(); if (User.AmountOfQuestions == 1) { bDeleteQuestion.Hide(); } else { bDeleteQuestion.Show(); } if (User.NumQuestion == User.AmountOfQuestions) { bNext.Hide(); bBack.Show(); } DB.GetQAnswers(User.NumQuestion); tbAnsw1.Text = User.AnswerQ1; tbAnsw2.Text = User.AnswerQ2; tbAnsw3.Text = User.AnswerQ3; tbAnsw4.Text = User.AnswerQ4; User.Question = (DB.LoadTest1(@"SELECT Questions FROM " + User.NameOfTest + " WHERE numQuestion = " + User.ArrOfQuestions[User.NumQuestion])); rtbAddQuestion.Text = User.Question; AddToList.SetDefaultAnswers(); DB.GetCorrectAnswer(); if ((User.CorrectAnswer.ElementAt(User.NumQuestion)) == tbAnsw1.Text) { rbAA.Checked = true; } ; if ((User.CorrectAnswer.ElementAt(User.NumQuestion)) == tbAnsw2.Text) { rbBB.Checked = true; } ; if ((User.CorrectAnswer.ElementAt(User.NumQuestion)) == tbAnsw3.Text) { rbCC.Checked = true; } ; if ((User.CorrectAnswer.ElementAt(User.NumQuestion)) == tbAnsw4.Text) { rbDD.Checked = true; } ; lInfo.Text = "Test: " + User.NameOfTest; lQuestion.Text = "Question " + User.NumQuestion + "/" + User.AmountOfQuestions; if (lQuestion.Text == "Question 1/1") { bBack.Hide(); bNext.Hide(); } if (lQuestion.Text == "Question 0/0") { MessageBox.Show("Test without questions"); } }