public static TestResults GetTestResults(int studentID, int testID) { string sqlString = "SELECT * " + "FROM student_quiz " + "JOIN test_question ON test_question.test_id = student_quiz.test_id " + "WHERE student_id = " + studentID + " " + "AND student_quiz.test_id = " + testID + ";"; SqlDataAdapter adapter = new SqlDataAdapter(sqlString, DAL_Connection.Connection); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); int rightAnswerCount = 0; int totalAnswerCount = 0; for (int x = 0; x < dataTable.Rows.Count; x++) { totalAnswerCount++; int questionID = int.Parse(dataTable.Rows[x]["question_id"].ToString()); if (StudentQuizQuestionDAL.AnswerIsRight(studentID, questionID)) { rightAnswerCount++; } } return(new TestResults(rightAnswerCount, totalAnswerCount)); }
public static bool AllQuestionAnswered(int studentID, int testID) { DataTable testTable = TestQuestionDAL.GetDataByTestID(testID); List <int> questionIdList = new List <int>(); //bool allQuestionAnswered = true; DataTable studentQuizTable = StudentQuizQuestionDAL.GetDataByTestID_AndStudentID(testID, studentID); for (int x = 0; x < studentQuizTable.Rows.Count; x++) { if (studentQuizTable.Rows[x]["answer_id"].ToString() == "") { return(false); } else { questionIdList.Add( int.Parse(studentQuizTable.Rows[x]["question_id"].ToString())); } } for (int x = 0; x < testTable.Rows.Count; x++) { int questionID = int.Parse(testTable.Rows[x]["question_id"].ToString()); bool questionIdExists = false; for (int y = 0; y < questionIdList.Count; y++) { if (questionIdList[y] == questionID) { questionIdExists = true; } } if (!questionIdExists) { return(false); } } return(true); throw new NotImplementedException(); }