Example #1
0
        private void addTest_Click(object sender, EventArgs e)
        {
            frmDeThi frm = new frmDeThi();

            using (var db = new dbQLThiTracNghiemDataContext())
            {
                var t = new Test();
                db.Tests.InsertOnSubmit(t);
                bs.Add(t);
                db.SubmitChanges();
                frm.idTest = t.idTest;
                frm.ShowDialog();
                if (frm.subEdit)
                {
                    frm.setValue(ref t);
                }
                else
                {
                    //db.Tests.Attach(t);
                    db.Tests.DeleteOnSubmit(t);
                    bs.Remove(t);
                }
                db.SubmitChanges();
            }
            //refeshGVDeThi();
        }
Example #2
0
 private void editTest_Click(object sender, EventArgs e)
 {
     if (gvTests.SelectedRows.Count == 1)
     {
         frmDeThi frm     = new frmDeThi();
         Test     oldTest = (Test)gvTests.SelectedRows[0].DataBoundItem;
         frm.loadValue(oldTest);
         frm.ShowDialog();
         if (frm.subEdit)
         {
             var newTest = frm.getValue();
             using (var db = new dbQLThiTracNghiemDataContext())
             {
                 Test t = db.Tests.Where(p => p.idTest == oldTest.idTest).Select(p => p).Single();
                 t.grade = newTest.grade;
                 t.time  = newTest.time;
                 if (newTest.nameTest != "")
                 {
                     t.nameTest = newTest.nameTest;
                 }
                 if (newTest.subject != "")
                 {
                     t.subject = newTest.subject;
                 }
                 db.SubmitChanges();
                 int index = bs.IndexOf(oldTest);
                 bs.Remove(oldTest);
                 bs.Insert(index, t);
             }
             //refeshGVDeThi();
         }
     }
     else
     {
         MessageBox.Show("Chọn 1 dòng để chỉnh sửa!");
     }
 }