private void DuyetCauHoi_Click(object sender, EventArgs e) { if (gvContributeQuestions.SelectedRows.Count > 0) { using (var db = new dbQLThiTracNghiemDataContext()) { for (int i = 0; i < gvContributeQuestions.SelectedRows.Count; i++) { QuestionRequest qs = (QuestionRequest)gvContributeQuestions.SelectedRows[i].DataBoundItem; var nq = new Question() { question = qs.question, answerA = qs.answerA, answerB = qs.answerB, answerC = qs.answerC, answerD = qs.answerD, answerTrue = qs.answerTrue, hardlevel = qs.hardlevel, subject = qs.subject, grade = qs.grade }; if (MyTool.SoCauHoiTrung(nq.question) == 0) { db.Questions.InsertOnSubmit(nq); } else { MessageBox.Show("Câu hỏi đã tồn tại!"); } db.QuestionRequests.Attach(qs); db.QuestionRequests.DeleteOnSubmit(qs); bs.Remove(qs); } db.SubmitChanges(); } //refeshGVCauHoiDongGop(); } else { MessageBox.Show("Chọn ít nhất 1 dòng để duyệt!"); } }
private void ThemCauHoi_Click(object sender, EventArgs e) { frmCauHoi frm = new frmCauHoi(); frm.ShowDialog(); if (frm.subEdit) { var q = frm.getValue(); if (MyTool.SoCauHoiTrung(q.question) == 0) { using (var db = new dbQLThiTracNghiemDataContext()) { db.Questions.InsertOnSubmit(q); bs.Add(q); db.SubmitChanges(); } //refeshGVQLCauHoi(); } else { MessageBox.Show("Câu hỏi đã tồn tại!"); } } }
private void SuaCauHoi_Click(object sender, EventArgs e) { if (gvQuestions.SelectedRows.Count == 1) { frmCauHoi frm = new frmCauHoi(); Question oldq = (Question)gvQuestions.SelectedRows[0].DataBoundItem; frm.loadvalue(oldq); frm.ShowDialog(); if (frm.subEdit) { Question newq = frm.getValue(); if (MyTool.SoCauHoiTrung(newq.question) <= 1) { using (var db = new dbQLThiTracNghiemDataContext()) { Question question = db.Questions.Where(q => q == oldq).Select(q => q).Single(); question.hardlevel = newq.hardlevel; if (newq.question != "") { question.question = newq.question; } if (newq.answerA != "") { question.answerA = newq.answerA; } if (newq.answerB != "") { question.answerB = newq.answerB; } if (newq.answerC != "") { question.answerC = newq.answerC; } if (newq.answerD != "") { question.answerD = newq.answerD; } if (newq.answerTrue != "") { question.answerTrue = newq.answerTrue; } if (newq.subject != "") { question.subject = newq.subject; } if (newq.grade != 0) { question.grade = newq.grade; } db.SubmitChanges(); int index = bs.IndexOf(oldq); bs.Remove(oldq); bs.Insert(index, question); } //refeshGVQLCauHoi(); } else { MessageBox.Show("Câu hỏi đã tồn tại!"); } } } else { MessageBox.Show("Chọn 1 dòng để chỉnh sửa!"); } }