//inserts the mark info into the table public static void SaveMark(Info.MarkInfo info) { //connection using (IDbConnection cnn = new SqlConnection(connection())) { //inserts into table cnn.Execute("insert into Marks (Test,ActualAnswer,TheirAnswer,Question,StudentId) values (@Test,@ActualAnswer,@TheirAnswer,@Question,@StudentId)", info); } }
protected void BtSubmit_Click(object sender, EventArgs e) { //filling list test = SqlMethods.fillTest(); //assigning variable string questionselected = LBQuestions.SelectedItem.ToString(); //checking what they answered if ((bool)RbA.Checked == true) { answer = 'A'; } if ((bool)RbB.Checked == true) { answer = 'B'; } if ((bool)RbC.Checked == true) { answer = 'C'; } if ((bool)RbD.Checked == true) { answer = 'D'; } //looping through list foreach (Info.TestInfo b in test) { //checking if the questions are the same if (questionselected == ("Questions" + b.id.ToString())) { //chekcing is the answer they answered was right or wrong if (answer == b.ActualAnswer.ToCharArray()[0]) { //adding data to variables Test = b.Test.ToString(); ActualAnswer = b.ActualAnswer.ToString(); TheirAnswer = answer.ToString(); id = b.id.ToString(); //printing that they where right if that questioin had not been doen before if (isthere == true) { //message } } else { //adding data to variables Test = b.Test.ToString(); ActualAnswer = b.ActualAnswer.ToString(); TheirAnswer = answer.ToString(); id = b.id.ToString(); //printing that they where wrong if that questioin had not been doen before if (isthere == true) { //message } } } } //adding answers and other info to objects Info.MarkInfo m = new Info.MarkInfo(); m.Test = Test; m.ActualAnswer = ActualAnswer; m.TheirAnswer = TheirAnswer; m.Question = "Question" + id; //filling list marks = SqlMethods.fillMarks(); //looping through list foreach (Info.MarkInfo h in marks) { //checking is the person has answered this question before if (h.StudentId == Session["id"]) { //checking iff match if (h.Question == "Question" + id) { isthere = true; } } } if (isthere == true) { //saying that they have answered that question before LBQuestions.Items.Remove(LBQuestions.SelectedItem); LBQuestions.SelectedIndex = LBQuestions.SelectedIndex + 1; //print out isthere = false; } else { //saves info to DB SqlMethods.SaveMark(m); } }