private void btnSubmit_Click(object sender, EventArgs e) { //ghi xuống bảng kết quả tạm thời RESULT_TEMP t = new RESULT_TEMP(); t.idCompe = pemp.id; t.idStudent = temp.id; t.idQuiz = tempQuiz.id; t.idSubtract = pemp.subtractID; if (rdA.Checked == true) { t.answer = 'a'; } if (rdB.Checked == true) { t.answer = 'b'; } if (rdC.Checked == true) { t.answer = 'c'; } if (rdD.Checked == true) { t.answer = 'd'; } if (t.answer == rs3[idxQuizCurrent].answer) { t.truefalse = true; } else { t.truefalse = false; } TracNghiem.GhiBangTam(t); idxQuizCurrent++; if (idxQuizCurrent > 59) { MessageBox.Show("Hết rồi"); } else { txtCurrentQuiz.Text = (idxQuizCurrent + 1).ToString(); } }
public static bool GhiBangTam(RESULT_TEMP t) { bool rt = true; using (var httn = new DBTracNghiemDataContext()) { var rs = httn.RESULT_TEMPs.Where(s => (s.idCompe == t.idCompe && s.idStudent == t.idStudent && s.idSubtract == t.idSubtract && s.idQuiz == t.idQuiz)).Select(s => s).SingleOrDefault(); if (rs != null) { //đã tồn tại thì sửa rs.answer = t.answer; rs.truefalse = t.truefalse; try { httn.SubmitChanges(); } catch (Exception) { rt = false; } } else { //chưa tồn tại thì thêm httn.RESULT_TEMPs.InsertOnSubmit(t); try { httn.SubmitChanges(); } catch (Exception) { rt = false; } } } return(rt); }