//int indexsamplecode = -1; private void taoCauHoi() { // txtInfo.Text = ""; data.Clear(); var result = from t1 in context.tbCAUHOIs from t2 in context.Dethis from t3 in context.Dotthis where t1.maloaicauhoi == t2.maloaicauhoi && t2.madethi == t3.madethi && t2.madethi == _dethi select new { Macauhoi = t1.macauhoi, loaicauhoi01 = t2.maloaicauhoi, Madethi = t2.madethi, cauhoi = t1.cauhoi, Dapan = t1.cau_a, Dapan1 = t1.cau_b, Dapan2 = t1.cau_c, Dapan3 = t1.cau_d, traloi = t1.dapan, cautraloi = "" }; var data1 = result.OrderBy(x => Guid.NewGuid()).ToList(); foreach (var item in data1) { trailoi ch = new trailoi(); ch.Macauhoi = item.Macauhoi; ch.Madethi = item.Madethi; ch.Loaicauhoi = item.loaicauhoi01; ch.Cauhoi = item.cauhoi; ch.Dapan = item.Dapan; ch.Dapan1 = item.Dapan1; ch.Dapan2 = item.Dapan2; ch.Dapan3 = item.Dapan3; ch.Traloi = item.traloi; ch.Cautraloi = ""; data.Add(ch); } }
//private void AddNewKetqua(trailoi tl) // { // Ketquadoithi kq = new Ketquadoithi(); // kq.MaTS = txtmathisinh.Text; // kq.madothi = txtdoithi.Text; // kq.Socaudung = tl.Socaudung1.ToString(); // kq.Ketqua = tl.Ketquathi1; // } private void AddNewTraloi(trailoi tl) { tbBaitraloi ch = new tbBaitraloi(); //ch.macauhoi = (txtmacauhoi.Text); //ch.maloaicauhoi = (txtloaicauhoi.Text); //ch.cauhoi = (txtcauhoi.Text); //ch.cau_a = (txtcaua.Text); //ch.cau_b = (txtcaub.Text); //ch.cau_c = (txtcauc.Text); //ch.cau_d = (txtcaud.Text); //ch.dapan = (txtdapan.Text); ch.MaTS = txtmathisinh.Text; ch.madoithi = txtdoithi.Text; ch.macauhoi = tl.Macauhoi; ch.cautraloi = tl.Cautraloi; ch.Chamcau = tl.Traloi; int dem = 0; if (ch.cautraloi == ch.Chamcau) { dem++; ch.Socaudung = dem.ToString(); } else { dem--; ch.Socaudung = dem.ToString(); } int dem1 = 0; if (ch.Socaudung == "1") { ch.Ketqua = dem1.ToString(); } else { dem1--; ch.Ketqua = dem1.ToString(); } context.tbBaitralois.InsertOnSubmit(ch); context.SubmitChanges(); }