public float ChamDiem(out int soCauDung) { soCauDung = 0; float diem = 0; if (CAUHOITHI == null) { MessageBox.Show("Đã có lỗi trong quá trình thi vui lòng kiểm tra kết nối!"); return(diem); } for (int i = 0; i < CAUHOITHI.Count; i++) { HoTroLayCauHoiThi ht = CAUHOITHI[i]; if (!string.IsNullOrEmpty(ht.LuaChon)) { if (ht.LuaChon.Trim() == ht.DapAn.Trim()) { soCauDung++; } } } if (soCauDung != 0) { diem = (10 / CAUHOITHI.Count) * soCauDung; } return(diem); }
private void LuaChon_Click(object sender, EventArgs e) { RadioButton rGLuaChon = (RadioButton)sender; if (rGLuaChon.Checked == true) { rGLuaChon.BackColor = Color.YellowGreen; } else { rGLuaChon.BackColor = Color.White; } if (rGLuaChon == null && CAUHOITHI == null) { return; } string luaChon = rGLuaChon.Name.Trim().Split('-')[0]; int maCH = Int32.Parse(rGLuaChon.Name.Trim().Split('-')[1]); HoTroLayCauHoiThi ht = CAUHOITHI.Where(x => x.MaCH == maCH).FirstOrDefault(); if (ht != null) { ht.LuaChon = luaChon; } CAUHOITHI.Where(x => x.MaCH == maCH).FirstOrDefault().LuaChon = ht.LuaChon; }
private void FormThi_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'dtsTTN.CT_BAITHI' table. You can move, or remove it, as needed. this.cT_BAITHITableAdapter.Fill(this.dtsTTN.CT_BAITHI); bANGDIEMTableAdapter.Fill(this.dtsTTN.BANGDIEM); MyTimer.Interval = (1000); // 1 mins MyTimer.Tick += new EventHandler(t_Tick); MyTimer.Start(); if (MaBD != -1) { BDThiTam = BoDe.LayBDThi(MaBD); if (BDThi == null) { return; } CAUHOITHI = new List <HoTroLayCauHoiThi>(); HoTroLayCauHoiThi htCHThi = null; Panel pnCauHoi = null; int i = BDThiTam.Count; while (BDThiTam.Count != 0) { htCHThi = new HoTroLayCauHoiThi(); int r = rnd.Next(BDThiTam.Count); HoTroLayBDThi ht = BDThiTam[r]; BDThi.Add(ht); CAUHOI cauHoi = CauHoi.GetCauHoiByMaCH(ht.MaCauHoi); List <LUACHON> luachon = CauHoi.GetLuaChonByMaCH(ht.MaCauHoi); pnCauHoi = new Panel(); pnCauHoi.AutoSize = true; pnCauHoi.Dock = DockStyle.Top; Label lb = new Label(); lb.AutoSize = true; FontStyle newFontStyle = (FontStyle)(FontStyle.Bold); lb.Font = new Font("Times New Rowman", 25, newFontStyle); lb.Text = "Câu " + i + " : " + cauHoi.NOIDUNG; RadioButton rGLuaChon = null; foreach (LUACHON lc in luachon) { rGLuaChon = new RadioButton(); rGLuaChon.AutoSize = true; rGLuaChon.Name = lc.MALC.Trim() + "-" + cauHoi.MACH.ToString().Trim(); rGLuaChon.Font = new Font("Times New Rowman", 25, newFontStyle); // update dap an neu thay doi lua chon rGLuaChon.CheckedChanged += new EventHandler(LuaChon_Click); //rGLuaChon.Add(new RadioGroupItem(lc.MALC.ToString(), "Câu " + lc.MALC.ToString() + " : " + lc.NOIDUNG)); rGLuaChon.Text = "Câu " + lc.MALC.ToString() + " : " + lc.NOIDUNG; rGLuaChon.Dock = DockStyle.Bottom; rGLuaChon.Focus(); pnCauHoi.Controls.Add(rGLuaChon); } lb.Dock = DockStyle.Top; pnCauHoi.Controls.Add(lb); pnThi.Controls.Add(pnCauHoi); htCHThi.MaCH = cauHoi.MACH; htCHThi.STT = ht.SoTT; htCHThi.DapAn = cauHoi.DAPAN; htCHThi.STTKhiThi = i - 1; CAUHOITHI.Add(htCHThi); BDThiTam.RemoveAt(r); i--; } } pnThi.AllowDrop = true; pnThi.AutoScroll = true; }