public static void SaveResults(ResultData theResults) { if (theResults.Answers.Count == 0) { System.Windows.Forms.MessageBox.Show("There are no answers to save.", "JiTU", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } else if (theResults.Student.Id == 0) { System.Windows.Forms.MessageBox.Show("The user id is invalid.", "JiTU", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } else { theEntity.AddResult(theResults); } }
/// <summary> /// handles submit buttons click event. /// Allows student to submit a quiz they are taking. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void btnSubmit_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to submit this quiz?", "Submit", MessageBoxButtons.OKCancel) == DialogResult.OK) { ResultData temp = new ResultData(GlobalData.currentUser, GlobalData.currentQuiz); foreach (QuestionBox ind in questionBoxes) { for (int i = 0; i < ind.rbtnAnswers.Length; i++) { if (ind.rbtnAnswers[i].Checked) { temp.Answers.Add((AnswerData)ind.rbtnAnswers[i].Tag); } } } ResultsEntity res = new ResultsEntity(); res.AddResult(temp); res.Dispose(); MessageBox.Show("You scored " + ResultsController.GetStudentPercentage(GlobalData.currentUser, GlobalData.currentQuiz) + "%"); GoBackToQuizzesView(); } }