private void button1_Click(object sender, EventArgs e) { using (DataContextDataContext DB = new DataContextDataContext()) { DAO.HT.CauHoiDAO cauHoiDAO = new CauHoiDAO(); if (String.IsNullOrEmpty(txtFileName.Text) == true) { MessageBox.Show("File trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (String.IsNullOrEmpty(comboBox1.Text) == true) { MessageBox.Show("sheet trông", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (var mem in cauHois) { if (cauHoiDAO.getCauHoiOnCauHoi(mem.NoiDung) == true) { MessageBox.Show("Câu hỏi có nội dung là :" + mem.NoiDung + " . Đã là tồn tại trong csdl ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); continue; } DB.CauHois.InsertOnSubmit(mem); } DB.SubmitChanges(); MessageBox.Show("Thành công", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public ActionResult Create(CauHoi collection) { try { // TODO: Add insert logic here if (ModelState.IsValid) { byte[] imageData = null; if (Request.Files.Count > 0) { HttpPostedFileBase poImgFile = Request.Files["fileim"]; using (var binary = new BinaryReader(poImgFile.InputStream)) { imageData = binary.ReadBytes(poImgFile.ContentLength); } } collection.Picture = imageData; var qz = new CauHoiDAO(); int id = qz.Insert(collection); if (id > 0) { return(RedirectToAction("Index", "CauHoi")); } else { ModelState.AddModelError("", "Thêm thất bại"); } } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Index(int page = 1, int pageSize = 10) { CauHoiDAO qz = new CauHoiDAO(); var model = qz.ListQuizPaging(page, pageSize); return(View(model)); }
public ActionResult Delete(int id) { CauHoiDAO dao = new CauHoiDAO(); //HocSinh hs = dao.FindStudentById(id); dao.Delete(id); return(RedirectToAction("Index")); }
public ActionResult Edit(int id, CauHoi collection) { try { // TODO: Add update logic here if (ModelState.IsValid) { byte[] imageData = null; HttpPostedFileBase poImgFile = Request.Files["fileim"]; if (poImgFile != null && poImgFile.ContentLength > 0) { using (var binary = new BinaryReader(poImgFile.InputStream)) { imageData = binary.ReadBytes(poImgFile.ContentLength); } collection.Picture = imageData; var ts = new CauHoiDAO(); var res = ts.Update(collection); if (res) { return(RedirectToAction("Index", "CauHoi")); } else { ModelState.AddModelError("", "Sửa thất bại"); } } else { byte[] tana = tn.CauHois.Where(x => x.MaCH == id).Select(u => u.Picture).SingleOrDefault(); collection.Picture = tana; var ts = new CauHoiDAO(); var res = ts.Update(collection); if (res) { return(RedirectToAction("Index", "CauHoi")); } else { ModelState.AddModelError("", "Sửa thất bại"); } } } return(RedirectToAction("Index")); } catch { return(View()); } }
public void SetViewBagDD(int?selectedID = null) { var qz = new CauHoiDAO(); ViewBag.MaCh = new SelectList(qz.ListQuiz(), "MaCH", "CauHoi1", selectedID); }