public void UpdateQuestion(Kho_CauHoi QuesTion) { var cmd = Question(QuesTion.Ma_CauHoi); cmd.MucDo = QuesTion.MucDo; cmd.NoiDung = QuesTion.NoiDung; cmd.HinhAnh = QuesTion.MucDo; tracNghiem.SaveChanges(); }
public bool DeleteQuestion(Kho_CauHoi QuesTion) { try { tracNghiem.Kho_CauHoi.Remove(QuesTion); tracNghiem.SaveChanges(); } catch { return(false); } return(true); }
public long CreatrQuestion(Kho_CauHoi QuesTion) { try { tracNghiem.Kho_CauHoi.Add(QuesTion); tracNghiem.SaveChanges(); } catch (Exception e) { return(0); } return(tracNghiem.Kho_CauHoi.Select(x => x).ToList().Last().Ma_CauHoi); }
public List <Kho_CauHoi> listkhocauhoi(long mabd) { var cauhoi = db.CauHois.Where(x => x.Ma_BoDe == mabd).ToList(); List <Kho_CauHoi> khoch = new List <Kho_CauHoi>(); var khocauhoi = db.Kho_CauHoi.Select(x => x).ToList(); var dapan = db.Dap_AN.Select(x => x).ToList(); foreach (var a in cauhoi) { Kho_CauHoi ch = new Kho_CauHoi(); foreach (var b in khocauhoi) { foreach (var c in dapan) { if (a.Ma_CauHoi == b.Ma_CauHoi && b.Ma_CauHoi == c.Ma_CauHoi) { Dap_AN da = new Dap_AN(); ch.NoiDung = b.NoiDung; ch.HinhAnh = b.HinhAnh; ch.MucDo = b.MucDo; ch.Ma_Chuong = b.Ma_Chuong; ch.TrangThai = b.TrangThai; da.NoiDung = c.NoiDung; da.TrangThai = c.TrangThai; da.Ma_CauHoi = c.Ma_CauHoi; da.MA_DAN = c.MA_DAN; da.HinhAnh = c.HinhAnh; ch.Dap_AN.Add(da); } } } khoch.Add(ch); } return(khoch); }
public JsonResult XuLyFile(HttpPostedFileBase file) { List <Kho_CauHoi> cauHois = new List <Kho_CauHoi>(); string strExtexsion = Path.GetFileName(file.FileName).Trim(); int COUT = 0; DateTime aDateTime = DateTime.Now; object path = Server.MapPath("~/Content/" + file.FileName); if (System.IO.File.Exists(path.ToString())) { System.IO.File.Delete(path.ToString()); } file.SaveAs(path.ToString()); List <String> anh = new List <string>(); string totalText = ""; Document document = new Document(path.ToString()); //Get Each Section of Document foreach (Section section in document.Sections) { //Get Each Paragraph of Section foreach (Paragraph paragraph in section.Paragraphs) { //Get Each Document Object of Paragraph Items foreach (DocumentObject docObject in paragraph.ChildObjects) { //If Type of Document Object is Picture, Extract. if (docObject.DocumentObjectType == DocumentObjectType.Picture) { int sas = Convert.ToInt32(aDateTime.Year * 12 * 30 * 24 * 60 * 60 + aDateTime.Month * 30 * 24 * 60 * 60 + aDateTime.Day * 24 * 60 * 60 + aDateTime.Hour * 60 * 60 + aDateTime.Minute * 60 + aDateTime.Second); DocPicture pic = docObject as DocPicture; String imgName = Server.MapPath("~/Content/Img/Anh" + sas + "-" + COUT + String.Format(".png")); anh.Add("/Content/Img/Anh" + sas + "-" + COUT + String.Format(".png")); //Save Image pic.Image.Save(imgName, System.Drawing.Imaging.ImageFormat.Png); COUT++; aDateTime = DateTime.Now; } else if (docObject.DocumentObjectType == DocumentObjectType.TextRange) { TextRange nd = docObject as TextRange; totalText += nd.Text; } else if (docObject.DocumentObjectType == DocumentObjectType.OfficeMath) { totalText += (docObject as OfficeMath).ToMathMLCode().Replace("mml:", ""); } } } } int slanh = 0; List <Dap_AN> dapan2 = new List <Dap_AN>(); cauHois = new List <Kho_CauHoi>(); for (int i = 0; i < totalText.Length; i++) { if (totalText[i] == '$' && totalText[i + 1] == 'c' && totalText[i + 2] == '$') { int slcau = 0; Kho_CauHoi ch = new Kho_CauHoi(); int sldapa = 0; int slda = 0; List <Dap_AN> dapan = new List <Dap_AN>(); ch.Dap_AN = new List <Dap_AN>(); for (int j = i; j < totalText.Length; j++) { if ((totalText[j] == '$' && totalText[j + 1] == '*' && totalText[j + 2] == '$') || (totalText[j] == '$' && totalText[j + 1] == '$')) { slcau++; Dap_AN da = new Dap_AN(); if (slcau == 1) { ch.NoiDung = totalText.Substring(i + 3, j - i - 3); if (ch.NoiDung[0] == '1') { ch.MucDo = "Nhận Biết"; } else if (ch.NoiDung[0] == '2') { ch.MucDo = "Thông Hiểu"; } else if (ch.NoiDung[0] == '3') { ch.MucDo = "Vận Dụng"; } else { ch.MucDo = "Vận Dụng Cao"; } ch.NoiDung = ch.NoiDung.Substring(1, ch.NoiDung.Length - 1); ch.HinhAnh = ""; for (int z = 0; z < ch.NoiDung.Length - 2; z++) { if (ch.NoiDung[z] == '#' && ch.NoiDung[z + 1] == 'h' && ch.NoiDung[z + 2] == '#') { ch.HinhAnh = anh[slanh]; slanh++; ch.NoiDung = ch.NoiDung.Substring(0, z); break; } } } if (ch.MucDo == "Chua có mức độ") { break; } for (int k = j + 2; k < totalText.Length; k++) { if (totalText[j] == '$' && totalText[j + 1] == '*' && totalText[j + 2] == '$') { if (totalText[k] == '$' && totalText[k + 1] == '$') { da.HinhAnh = ""; da.NoiDung = totalText.Substring(j + 3, k - j - 3); da.TrangThai = true; for (int z = 0; z < da.NoiDung.Length - 2; z++) { if (da.NoiDung[z] == '#' && da.NoiDung[z + 1] == 'h' && da.NoiDung[z + 2] == '#') { da.HinhAnh = anh[slanh]; slanh++; da.NoiDung = da.NoiDung.Substring(0, z); } } j = k - 1; ch.Dap_AN.Add(da); } else if (totalText[k] == '$' && totalText[k + 1] == 'c' && totalText[k + 2] == '$') { da.HinhAnh = ""; da.NoiDung = totalText.Substring(j + 3, k - 3 - j); da.TrangThai = true; for (int z = 0; z < da.NoiDung.Length - 2; z++) { if (da.NoiDung[z] == '#' && da.NoiDung[z + 1] == 'h' && da.NoiDung[z + 2] == '#') { da.HinhAnh = anh[slanh]; slanh++; da.NoiDung = da.NoiDung.Substring(0, z); } } sldapa++; j = k - 1; ch.Dap_AN.Add(da); break; } else if (k == totalText.Length - 1) { da.HinhAnh = ""; da.NoiDung = totalText.Substring(j + 3, totalText.Length - j - 3); da.TrangThai = true; for (int z = 0; z < da.NoiDung.Length - 2; z++) { if (da.NoiDung[z] == '#' && da.NoiDung[z + 1] == 'h' && da.NoiDung[z + 2] == '#') { da.HinhAnh = anh[slanh]; slanh++; da.NoiDung = da.NoiDung.Substring(0, z); } } sldapa++; j = totalText.Length - 1; ch.Dap_AN.Add(da); break; } } else if (totalText[j] == '$' && totalText[j + 1] == '$') { if (totalText[k] == '$' && totalText[k + 1] == '$') { da.HinhAnh = ""; da.NoiDung = totalText.Substring(j + 2, k - j - 2); da.TrangThai = false; for (int z = 0; z < da.NoiDung.Length - 2; z++) { if (da.NoiDung[z] == '#' && da.NoiDung[z + 1] == 'h' && da.NoiDung[z + 2] == '#') { da.HinhAnh = anh[slanh]; slanh++; da.NoiDung = da.NoiDung.Substring(0, z); } } j = k - 1; ch.Dap_AN.Add(da); } else if (totalText[k] == '$' && totalText[k + 1] == '*' && totalText[k + 2] == '$') { da.HinhAnh = ""; da.NoiDung = totalText.Substring(j + 2, k - j - 2); da.TrangThai = false; for (int z = 0; z < da.NoiDung.Length - 2; z++) { if (da.NoiDung[z] == '#' && da.NoiDung[z + 1] == 'h' && da.NoiDung[z + 2] == '#') { da.HinhAnh = anh[slanh]; slanh++; da.NoiDung = da.NoiDung.Substring(0, z); } } j = k - 1; ch.Dap_AN.Add(da); } else if (totalText[k] == '$' && totalText[k + 1] == 'c' && totalText[k + 2] == '$') { da.HinhAnh = ""; da.NoiDung = totalText.Substring(j + 2, k - j - 2); da.TrangThai = false; for (int z = 0; z < da.NoiDung.Length - 2; z++) { if (da.NoiDung[z] == '#' && da.NoiDung[z + 1] == 'h' && da.NoiDung[z + 2] == '#') { da.HinhAnh = anh[slanh]; slanh++; da.NoiDung = da.NoiDung.Substring(0, z); } } sldapa++; j = k - 1; ch.Dap_AN.Add(da); break; } else if (k == totalText.Length - 1) { da.HinhAnh = ""; da.NoiDung = totalText.Substring(j + 2, totalText.Length - j - 2); da.TrangThai = false; for (int z = 0; z < da.NoiDung.Length - 2; z++) { if (da.NoiDung[z] == '#' && da.NoiDung[z + 1] == 'h' && da.NoiDung[z + 2] == '#') { da.HinhAnh = anh[slanh]; slanh++; da.NoiDung = da.NoiDung.Substring(0, z); } } sldapa++; ch.Dap_AN.Add(da); j = totalText.Length - 1; break; } } } } if (sldapa != 0) { cauHois.Add(ch); break; } } } } Session[ComMon.ComMonStants.Cauhoi] = cauHois; return(Json(new { status = true })); }