// //=============================Quan Ly ky thi============================= // void refreshExam() { using (var db = new dbQLThiTracNghiemDataContext()) { gvExams.DataSource = db.Examinations.Where(p => p.type.Contains(cbExamType.SelectedItem.ToString())); }; }
private void editExam_Click(object sender, EventArgs e) { if (gvExams.SelectedRows.Count == 1) { frmTaoKyThi frm = new frmTaoKyThi(); Examination oldTest = (Examination)gvExams.SelectedRows[0].DataBoundItem; frm.loadValue(oldTest); frm.ShowDialog(); if (frm.subEdit) { var newTest = frm.getValue(); using (var db = new dbQLThiTracNghiemDataContext()) { Examination t = db.Examinations.Where(p => p.idExamination == oldTest.idExamination).Select(p => p).Single(); t.nameExamination = newTest.nameExamination; t.grade = newTest.grade; t.startTime = newTest.startTime; t.time = newTest.time; t.countStudent = newTest.countStudent; t.type = newTest.type; db.SubmitChanges(); //int index = bs.IndexOf(oldTest); //bs.Remove(oldTest); //bs.Insert(index, t); bs.DataSource = db.Examinations.ToList(); } refreshExam(); } } else { MessageBox.Show("Chọn 1 dòng để chỉnh sửa!"); } }
public void LoadID(int id) { using (var db = new dbQLThiTracNghiemDataContext()) { curTeacher = db.Teachers.Where(t => t.idAccount == id).Select(t => t).Single(); } }
void frmDSCauHoi_Load(object sender, EventArgs e) { using (var db = new dbQLThiTracNghiemDataContext()) { gvQuestions.DataSource = db.Questions.ToList(); } }
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(); }
public void LoadID(int id) { using (var db = new dbQLThiTracNghiemDataContext()) { my = db.Students.Where(s => s.idAccount == id).SingleOrDefault(); } }
private void button1_Click(object sender, EventArgs e) { try { if (gvTests.SelectedRows.Count > 0) { using (var db = new dbQLThiTracNghiemDataContext()) { for (int i = 0; i < gvTests.SelectedRows.Count; i++) { db.Test_Examinations.InsertOnSubmit(new Test_Examination { idExamination = idKT, idTest = (gvTests.SelectedRows[i].DataBoundItem as Test).idTest }); } db.SubmitChanges(); } Close(); } else { MessageBox.Show("Chọn ít nhất 1 dòng để thêm!"); } }catch (Exception) { MessageBox.Show("Đề thii đã tồn tại"); } }
private void loadCauHoiTracNghiem(string monhoc) { using (var db = new dbQLThiTracNghiemDataContext()) { var tmp = (from t in db.Test_Examinations from f in db.Question_Tests from q in db.Questions where t.idExamination == thongtin.idKiThi && t.idTest == f.idTest && f.idQuestion == q.idQuestion select q).Distinct().ToArray(); //var Question_idQuesCurrent = (from q in db.Questions where q.idQuestion == thongtin.idCauHoiHienTai && q.subject == monhoc select q).ToArray(); var CauHoi = new Question(); CauHoi.question = tmp[k].question.ToString(); CauHoi.answerA = tmp[k].answerA.ToString(); CauHoi.answerB = tmp[k].answerB.ToString(); CauHoi.answerC = tmp[k].answerC.ToString(); CauHoi.answerD = tmp[k].answerD.ToString(); CauHoi.answerTrue = tmp[k].answerTrue.ToString(); //CauHoi.question = Question_idQuesCurrent[0].question.ToString(); //CauHoi.answerA = Question_idQuesCurrent[0].answerA.ToString(); //CauHoi.answerB = Question_idQuesCurrent[0].answerB.ToString(); //CauHoi.answerC = Question_idQuesCurrent[0].answerC.ToString(); //CauHoi.answerD = Question_idQuesCurrent[0].answerD.ToString(); //CauHoi.answerTrue = Question_idQuesCurrent[0].answerTrue.ToString(); lblSttCau.Text = "CÂU " + thongtin.sttCauHoi.ToString() + ": " + CauHoi.question; lblCauA.Text = "A) " + CauHoi.answerA; lblCauB.Text = "B) " + CauHoi.answerB; lblCauC.Text = "C) " + CauHoi.answerC; lblCauD.Text = "D) " + CauHoi.answerD; } k++; }
private void btnNopBai_Click_1(object sender, EventArgs e) { List <string> da = new List <string>();//lưu câu trả lời của phiếu đáp án da = layPhieuTraLoi(); if (da.Count > 0 || thongtin.active != true) { BoDemTime.Dispose(); for (int i = 0; i < thongtin.SoLuongHoanTat; i++) { if (da[i] == AllDapAn[i + thongtin.idCauHoiDau - 1]) { thongtin.SoDiem++; } } MessageBox.Show("Đúng:" + thongtin.SoDiem.ToString() + " Sai:" + (10 - thongtin.SoDiem).ToString() + " Điểm:" + thongtin.SoDiem.ToString()); //Lưu kết quả using (var db = new dbQLThiTracNghiemDataContext()) { var loaiKiThi = (from k in db.Examinations where k.idExamination == thongtin.idKiThi select k.type).ToArray(); if (loaiKiThi[0].ToString() == "thi thật") { luuKetQuaThi(thongtin.SoDiem); } } thongtin.SoLuongHoanTat = 0; this.Dispose(); } else { MessageBox.Show("Chưa hoàn thành bài làm", "Chưa Hoàn Thành", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void addExam_Click(object sender, EventArgs e) { frmTaoKyThi frm = new frmTaoKyThi(); using (var db = new dbQLThiTracNghiemDataContext()) { var t = new Examination(); db.Examinations.InsertOnSubmit(t); //bs.Add(t); db.SubmitChanges(); frm.idExam = t.idExamination; frm.ShowDialog(); if (frm.subEdit) { frm.setValue(ref t); } else { //db.Examinations.Attach(t); db.Examinations.DeleteOnSubmit(t); //bs.Remove(t); } db.SubmitChanges(); } refreshExam(); }
private void TabControl1_SelectedIndexChanged(object sender, EventArgs e) { if ((sender as TabControl).SelectedTab == tabPage2) { using (var db = new dbQLThiTracNghiemDataContext()) { var g = db.Classes.Where(c => c.className == my.@class).SingleOrDefault(); var s = (from ex in db.Examinations from re in db.Results where re.idExamination == ex.idExamination && my.idStudent == re.idStudent select ex); s = s.Distinct(); foreach (Examination i in s) { i.nameExamination += " - " + i.startTime.Value.Year.ToString() + " - " + i.type; } cbExams.DataSource = s.ToList(); cbExams.DisplayMember = "nameExamination"; } refrestGVKQ(); } if ((sender as TabControl).SelectedTab == tabPage3) { using (var db = new dbQLThiTracNghiemDataContext()) { var g = db.Classes.Where(c => c.className == my.@class).SingleOrDefault(); var s = from ex in db.Examinations where ex.grade == g.grade && ex.startTime >= DateTime.Now select ex; foreach (Examination i in s) { i.nameExamination += " - " + i.startTime.Value.Year.ToString() + " - " + i.type; } cbExams2.DataSource = s.ToList(); cbExams2.DisplayMember = "nameExamination"; } refrestGVLT(); } if ((sender as TabControl).SelectedTab == tabPage1) { refrestTab1(); } if ((sender as TabControl).SelectedTab == tabPage4) { using (var db = new dbQLThiTracNghiemDataContext()) { gvFakeExams.DataSource = db.Examinations.Where(ex => ex.type == "thi thử").ToList(); } } if ((sender as TabControl).SelectedTab == tabPage5) { using (var db = new dbQLThiTracNghiemDataContext()) { dgvDSCH.DataSource = db.QuestionRequests.Where(q => q.idStudent == my.idStudent).ToList(); } } }
public void LoadID(Student x) { using (var db = new dbQLThiTracNghiemDataContext()) { ac = db.Accounts.Where(a => a.idAccount == x.idAccount).SingleOrDefault(); } lbAccount.Text += ac.username; }
void refeshExam() { using (var db = new dbQLThiTracNghiemDataContext()) { gvTests.DataSource = from i in db.Tests select i; } }
private void btnDelete_Click(object sender, EventArgs e) { dbQLThiTracNghiemDataContext dbQLThiTracNghiemDataContext = new dbQLThiTracNghiemDataContext(); try { var selectedRow = dgvUser.SelectedRows[0]; if (cbUser.Text == "Admin") { int id = int.Parse(selectedRow.Cells[0].Value.ToString()); var admin = dbQLThiTracNghiemDataContext.Admins.Where((t) => (t.idAdmin == id)).SingleOrDefault(); int idaccount = int.Parse(admin.idAccount.ToString()); var account = dbQLThiTracNghiemDataContext.Accounts.Where((t) => (t.idAccount == admin.idAccount)).SingleOrDefault(); dbQLThiTracNghiemDataContext.Admins.DeleteOnSubmit(admin); dbQLThiTracNghiemDataContext.Accounts.DeleteOnSubmit(account); dbQLThiTracNghiemDataContext.SubmitChanges(); LoadAdmin(); } else if (cbUser.Text == "Teacher") { int id = int.Parse(selectedRow.Cells[0].Value.ToString()); var teacher = dbQLThiTracNghiemDataContext.Teachers.Where((t) => (t.idTeacher == id)).SingleOrDefault(); int idaccount = int.Parse(teacher.idAccount.ToString()); var account = dbQLThiTracNghiemDataContext.Accounts.Where((t) => (t.idAccount == teacher.idAccount)).SingleOrDefault(); dbQLThiTracNghiemDataContext.Teachers.DeleteOnSubmit(teacher); dbQLThiTracNghiemDataContext.Accounts.DeleteOnSubmit(account); dbQLThiTracNghiemDataContext.SubmitChanges(); LoadTeacher(); } else if (cbUser.Text == "Student") { int id = int.Parse(selectedRow.Cells[0].Value.ToString()); var student = dbQLThiTracNghiemDataContext.Students.Where((t) => (t.idStudent == id)).SingleOrDefault(); int idaccount = int.Parse(student.idAccount.ToString()); var account = dbQLThiTracNghiemDataContext.Accounts.Where((t) => (t.idAccount == student.idAccount)).SingleOrDefault(); dbQLThiTracNghiemDataContext.Students.DeleteOnSubmit(student); dbQLThiTracNghiemDataContext.Accounts.DeleteOnSubmit(account); dbQLThiTracNghiemDataContext.SubmitChanges(); LoadStudent(); } else { int id = int.Parse(selectedRow.Cells[0].Value.ToString()); var ac = dbQLThiTracNghiemDataContext.AccountRequests.Where((t) => (t.id == id)).SingleOrDefault(); dbQLThiTracNghiemDataContext.AccountRequests.DeleteOnSubmit(ac); dbQLThiTracNghiemDataContext.SubmitChanges(); LoadListDisApprove(); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
// gop cau hoi private void btnThemCauHoi_Click_1(object sender, EventArgs e) { frmDongGopCauHoi f2 = new frmDongGopCauHoi(my.idStudent); f2.ShowDialog(); using (var db = new dbQLThiTracNghiemDataContext()) { dgvDSCH.DataSource = db.QuestionRequests.Where(q => q.idStudent == my.idStudent).ToList(); } }
void refeshGV() { using (var db = new dbQLThiTracNghiemDataContext()) { gvQuestions.DataSource = from i in db.Question_Tests from q in db.Questions where i.idQuestion == q.idQuestion && i.idTest == idTest select q; } }
void refestGV() { using (var db = new dbQLThiTracNghiemDataContext()) { gvTests.DataSource = (from test in db.Tests from te in db.Test_Examinations where te.idExamination == idExam && te.idTest == test.idTest select test).Distinct(); } }
public void LoadListDisApprove() { dbQLThiTracNghiemDataContext dbQLThiTracNghiemDataContext = new dbQLThiTracNghiemDataContext(); var data = from s in dbQLThiTracNghiemDataContext.Students join ac in dbQLThiTracNghiemDataContext.AccountRequests on s.idStudent equals ac.id where ac.role == 3 select new { s.idStudent, s.nameStudent, s.gender, ac.role, ac.username, ac.password }; var data1 = from t in dbQLThiTracNghiemDataContext.Teachers join ac in dbQLThiTracNghiemDataContext.AccountRequests on t.idTeacher equals ac.id where ac.role == 2 select new { t.idTeacher, t.nameTeacher, t.gender, ac.username, ac.password, ac.role }; List <AccountRequestUser> user = new List <AccountRequestUser>(); foreach (var item in data) { AccountRequestUser temp = new AccountRequestUser(); temp.id = item.idStudent; temp.name = item.nameStudent; temp.password = item.password; temp.username = item.username; temp.gender = item.gender; temp.role = item.role.ToString(); user.Add(temp); } foreach (var item in data1) { AccountRequestUser temp = new AccountRequestUser(); temp.id = item.idTeacher; temp.name = item.nameTeacher; temp.password = item.password; temp.username = item.username; temp.gender = item.gender; temp.role = item.role.ToString(); user.Add(temp); } accountRequestUserBS.DataSource = user; dgvUser.DataSource = accountRequestUserBS; ClearDataBinding(); txtID.DataBindings.Add("Text", accountRequestUserBS, "id"); txtName.DataBindings.Add("Text", accountRequestUserBS, "name"); txtGender.DataBindings.Add("Text", accountRequestUserBS, "gender"); txtUsername.DataBindings.Add("Text", accountRequestUserBS, "username"); txtPassword.DataBindings.Add("Text", accountRequestUserBS, "password"); txtClass.Visible = false; txtGrade.Visible = false; lblClass.Visible = false; lblGrade.Visible = false; }
private void btnExportQuestion_Click(object sender, EventArgs e) { List <Question> lst = new List <Question>(); using (var db = new dbQLThiTracNghiemDataContext()) { lst = db.Questions.ToList(); } myExcel.Export(MyTool.ConvertToDataTable(lst)); MessageBox.Show("Xuất câu hỏi thành công!"); }
public static int SoCauHoiTrung2(string CauHoi, Table <Question> listqs) { int r = 0; using (var db = new dbQLThiTracNghiemDataContext()) { var p = listqs.Where(q => q.question == CauHoi).Select(q => q); r = p.Count(); } return(r); }
void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { if ((sender as TabControl).SelectedTab == tabPage1) { //refeshGVCauHoiDongGop(); using (var db = new dbQLThiTracNghiemDataContext()) { bs.DataSource = db.QuestionRequests.ToList(); } } if ((sender as TabControl).SelectedTab == tabPage2) { //refeshGVQLCauHoi(); using (var db = new dbQLThiTracNghiemDataContext()) { bs.DataSource = db.Questions.ToList(); } } if ((sender as TabControl).SelectedTab == tabPage3) { //refeshGVDeThi(); using (var db = new dbQLThiTracNghiemDataContext()) { bs.DataSource = db.Tests.ToList(); } } if ((sender as TabControl).SelectedTab == tabPage4) { using (var db = new dbQLThiTracNghiemDataContext()) { cbExamType.SelectedIndex = 0; refreshExam(); } } if ((sender as TabControl).SelectedTab == tabPage5) { List <Examination> lst = new List <Examination>(); using (var db = new dbQLThiTracNghiemDataContext()) { lst = (from ex in db.Examinations from r in db.Results where ex.idExamination == r.idExamination select ex).Distinct().ToList(); } foreach (Examination i in lst) { i.nameExamination += " - " + i.startTime.Value.Year.ToString() + " - " + i.type; } cbExams.DataSource = lst; cbExams.DisplayMember = "nameExamination"; refrestGVKQ(); } }
// //=============================Tab Ket Qua SV============================= // void refrestGVKQ() { Examination ex = cbExams.SelectedItem as Examination; if (ex != null) { using (var db = new dbQLThiTracNghiemDataContext()) { gvResult.DataSource = db.Results.Where(r => r.idExamination == ex.idExamination).ToList(); } } }
int countStudent(int grade) { int x; using (var db = new dbQLThiTracNghiemDataContext()) { x = (from s in db.Students from c in db.Classes where s.@class == c.className && c.grade == grade select s).Count(); } return(x); }
// Xem KQ void refrestGVKQ() { var exam = cbExams.SelectedItem as Examination; using (var db = new dbQLThiTracNghiemDataContext()) { var abc = db.Results.Where(r => r.idStudent == my.idStudent && r.idExamination == exam.idExamination).ToList(); if (abc != null) { gvResults.DataSource = abc; } } }
void refrestGVLT() { var exam = cbExams2.SelectedItem as Examination; using (var db = new dbQLThiTracNghiemDataContext()) { var abc = db.Examinations.Where(r => r.idExamination == exam.idExamination && r.startTime >= DateTime.Now).ToList(); if (abc != null) { gvExamTime.DataSource = abc; } } }
private void cbbMon_SelectedIndexChanged(object sender, EventArgs e) { thongtin.monhoc = cbbMon.SelectedItem.ToString(); using (var db = new dbQLThiTracNghiemDataContext()) { var khoi = (from k in db.Classes where k.className == my.@class select k.grade).First(); var thoigian = (from t in db.Tests where t.grade == khoi && t.subject == thongtin.monhoc select t.time); if (thoigian.Count() > 0 && thongtin.active == false) { thongtin.time = (int)thoigian.First(); } } loadCauHoiTracNghiem(thongtin.monhoc); }
private void BtnStartExam_Click(object sender, EventArgs e) { using (var db = new dbQLThiTracNghiemDataContext()) { var x = db.Results.Where(r => r.idExamination == 2 && r.idStudent == my.idStudent).Count(); if (x == 1) { MessageBox.Show("chưa có kì thi nào để thi!"); return; } } frmTracNghiem frm = new frmTracNghiem(my.idStudent, 2); frm.StartPosition = FormStartPosition.CenterParent; frm.ShowDialog(); }
public frmTracNghiem(int id, int idexam) { InitializeComponent(); thongtin.idKiThi = idexam; using (var db = new dbQLThiTracNghiemDataContext()) { my = db.Students.Where(s => s.idAccount == id).SingleOrDefault(); var loaiKiThi = (from k in db.Examinations where k.idExamination == thongtin.idKiThi select k.type).ToArray(); if (loaiKiThi[0].ToString() == "thi thử") { btnGoiY.Visible = true; } } loadTracNghiem(); }
private void btlogin_Click(object sender, EventArgs e) { using (var db = new dbQLThiTracNghiemDataContext()) { var r = db.Accounts.Where(a => a.username == txtUsername.Text && a.password == Object.MyTool.getHashString(txtUsername.Text + txtPass.Text)).Select(a => a).SingleOrDefault(); if (r != null) { id = r.idAccount; role = (int)r.role; Close(); } else { MessageBox.Show("Sai tài khoản hoặc mật khẩu!"); } } }
// //================================Tab Quan Ly Cau Hoi================================ // private void ThemFile_Click(object sender, EventArgs e) { OpenFileDialog browser = new OpenFileDialog(); browser.Filter = "Excel file | *.xls;*.xlsx"; DialogResult r = browser.ShowDialog(); if (browser.FileName != "") { myExcel.read(browser.FileName); using (var db = new dbQLThiTracNghiemDataContext()) { bs.DataSource = db.Questions.ToList(); } //refeshGVQLCauHoi(); } }