示例#1
0
        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!");
                }
            }
        }
示例#2
0
 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!");
     }
 }