public static void QuizXml() { LearnSite.BLL.Quiz bll = new LearnSite.BLL.Quiz(); DataSet ds = bll.GetAllList(); string xmlFile = QuizStorage() + "Quiz.xml"; string rarfileurl = "~/Quiz/Quiz.rar"; string rarFile = HttpContext.Current.Server.MapPath(rarfileurl); if (File.Exists(xmlFile)) { File.Delete(xmlFile);//如果已经存在则删除 } if (ds != null) { ds.DataSetName = "LearnSite"; if (ds.Tables[0].Rows.Count > 0) { ds.Tables[0].TableName = "Quiz"; ds.WriteXml(xmlFile); //生成xml文件 LearnSite.Store.SharpZip.PackFiles(rarFile, QuizStorage()); //把Storage文件夹打包 File.Delete(xmlFile); } } ds.Dispose(); }
public static void QuizXml() { LearnSite.BLL.Quiz bll = new LearnSite.BLL.Quiz(); DataSet ds = bll.GetAllList(); string xmlFile =QuizStorage()+ "Quiz.xml"; string rarfileurl = "~/Quiz/Quiz.rar"; string rarFile = HttpContext.Current.Server.MapPath(rarfileurl); if (File.Exists(xmlFile)) File.Delete(xmlFile);//如果已经存在则删除 if (ds != null) { ds.DataSetName = "LearnSite"; if (ds.Tables[0].Rows.Count > 0) { ds.Tables[0].TableName = "Quiz"; ds.WriteXml(xmlFile);//生成xml文件 LearnSite.Store.SharpZip.PackFiles(rarFile, QuizStorage());//把Storage文件夹打包 File.Delete(xmlFile); } } ds.Dispose(); }
/// <summary> /// 从上传的试题包xml中导入试题到数据库 /// </summary> /// <returns></returns> public static string XmltoQuiz(FileUpload fud) { string msg = ""; if (Uploadxml(fud)) { string xmlFile = QuizStorage() + "Quiz.xml"; if (File.Exists(xmlFile)) { DataSet ds = new DataSet(); ds.ReadXml(xmlFile); DataTable dt = ds.Tables["Quiz"]; if (dt != null) { int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { LearnSite.Model.Quiz model = new LearnSite.Model.Quiz(); if (dt.Rows[i]["Qid"].ToString() != "") { model.Qid = int.Parse(dt.Rows[i]["Qid"].ToString()); } if (dt.Rows[i]["Qtype"].ToString() != "") { model.Qtype = int.Parse(dt.Rows[i]["Qtype"].ToString()); } model.Question = dt.Rows[i]["Question"].ToString(); model.Qanswer = dt.Rows[i]["Qanswer"].ToString(); model.Qanalyze = dt.Rows[i]["Qanalyze"].ToString(); if (dt.Rows[i]["Qscore"].ToString() != "") { model.Qscore = int.Parse(dt.Rows[i]["Qscore"].ToString()); } model.Qclass = dt.Rows[i]["Qclass"].ToString(); if (dt.Rows[i]["Qselect"].ToString() != "") { if ((dt.Rows[i]["Qselect"].ToString() == "1") || (dt.Rows[i]["Qselect"].ToString().ToLower() == "true")) { model.Qselect = true; } else { model.Qselect = false; } } LearnSite.BLL.Quiz bll = new LearnSite.BLL.Quiz(); bll.Add(model); } msg = "成功导入" + count.ToString() + "条试题!"; File.Delete(xmlFile);//删除上传文件 ds.Dispose(); } else { msg = "试题包为空!"; } } else { msg = "试题包不正确!"; } } else { msg = "试题包不存在!"; } } else { msg = "试题包格式不正确!"; } return(msg); }
/// <summary> /// 从上传的试题包xml中导入试题到数据库 /// </summary> /// <returns></returns> public static string XmltoQuiz(FileUpload fud) { string msg = ""; if (Uploadxml(fud)) { string xmlFile = QuizStorage() + "Quiz.xml"; if (File.Exists(xmlFile)) { DataSet ds = new DataSet(); ds.ReadXml(xmlFile); DataTable dt = ds.Tables["Quiz"]; if (dt != null) { int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { LearnSite.Model.Quiz model = new LearnSite.Model.Quiz(); if (dt.Rows[i]["Qid"].ToString() != "") { model.Qid = int.Parse(dt.Rows[i]["Qid"].ToString()); } if (dt.Rows[i]["Qtype"].ToString() != "") { model.Qtype = int.Parse(dt.Rows[i]["Qtype"].ToString()); } model.Question = dt.Rows[i]["Question"].ToString(); model.Qanswer = dt.Rows[i]["Qanswer"].ToString(); model.Qanalyze = dt.Rows[i]["Qanalyze"].ToString(); if (dt.Rows[i]["Qscore"].ToString() != "") { model.Qscore = int.Parse(dt.Rows[i]["Qscore"].ToString()); } LearnSite.BLL.Quiz bll = new LearnSite.BLL.Quiz(); bll.Add(model); } msg = "成功导入" + count.ToString() + "条试题!"; File.Delete(xmlFile);//删除上传文件 ds.Dispose(); } else { msg = "试题包为空!"; } } else { msg = "试题包不正确!"; } } else { msg = "试题包不存在!"; } } else { msg = "试题包格式不正确!"; } return msg; }