Exemple #1
0
 private void btnCreate_Click_1(object sender, EventArgs e)
 {
     subEdit = true;
     if (gvTests.SelectedRows.Count < 0)
     {
         MessageBox.Show("Chọn ít nhất 1 đề.");
         subEdit = false;
     }
     else
     {
         using (var db = new dbQLThiTracNghiemDataContext())
         {
             for (int i = 0; i < gvTests.SelectedRows.Count; i++)
             {
                 Test qs = (Test)gvTests.SelectedRows[i].DataBoundItem;
                 if (qs.grade != nudGrade.Value)
                 {
                     MessageBox.Show("Đề thi không hợp với khối.");
                     subEdit = false;
                     break;
                 }
             }
             if (subEdit)
             {
                 for (int i = 0; i < gvTests.SelectedRows.Count; i++)
                 {
                     var id = (gvTests.SelectedRows[i].DataBoundItem as Test).idTest;
                     Test_Examination te = new Test_Examination()
                     {
                         idExamination = idExam,
                         idTest        = id
                     };
                     db.Test_Examinations.Attach(te);
                 }
                 db.SubmitChanges();
             }
         }
     }
     if (subEdit)
     {
         Close();
     }
 }
Exemple #2
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (gvTests.SelectedRows.Count > 0)
     {
         using (var db = new dbQLThiTracNghiemDataContext())
         {
             for (int i = 0; i < gvTests.SelectedRows.Count; i++)
             {
                 var id = (gvTests.SelectedRows[i].DataBoundItem as Test).idTest;
                 Test_Examination qs = db.Test_Examinations.Where(r => r.idExamination == idExam && r.idTest == id).Select(r => r).Single();
                 //db.Question_Tests.Attach(qs);
                 db.Test_Examinations.DeleteOnSubmit(qs);
             }
             db.SubmitChanges();
         }
         refestGV();
     }
     else
     {
         MessageBox.Show("Chọn ít nhất 1 dòng để xóa!");
     }
 }