private static Question makeQuestion(string reponses, string titreq) { Question res = null; String titrequestion = getTitreQuestion(titreq); String nomquestion = getNomQuestion(titreq); String typequestion = getTypeQuestion(reponses); titrequestion = titrequestion.Replace("\n", ""); nomquestion = nomquestion.Replace("\n", ""); List <Reponse> reps = getReponses(reponses); switch (typequestion) { case "TRUEFALSE": res = new QuestionVF(); break; case "ESSAY": res = new QuestionEssay(); break; case "NUMERICAL": res = new QuestionNumerical(); break; case "SIMPLE": res = new QuestionSimple(); break; case "MULTIPLE": res = new QuestionMultiple(); break; case "SHORTANSWER": res = new QuestionShort(); break; case "APPARIEMENT": res = new QuestionAppariement(); break; } foreach (Reponse r in reps) { cleanReponse(r); res.addReponse(r); } res.addTitre(titrequestion); res.nomq = nomquestion; return(res); }
/// <summary> /// 从一个大的dictionary中筛选出难度系数为condition的List(只包含它的key) /// </summary> /// <param name="bigDictionary"></param> /// <param name="condition"></param> /// <returns></returns> private List <Int32> GetSmallQuestion(Dictionary <Int32, QuestionSimple> bigDictionary, decimal condition) { List <Int32> small = new List <Int32>(); QuestionSimple qs = null; foreach (Int32 item in bigDictionary.Keys) { qs = bigDictionary[item]; if (qs.Difficulty == condition) { small.Add(qs.ID); } } return(small); }
private static Question makeMultiChoiceQuestion(XmlNode question) { Question res; String titreq = ""; String feedbackq = ""; if (question["single"].InnerText.Equals("true")) { res = new QuestionSimple(); } else { res = new QuestionMultiple(); } String nom = ""; if (question.SelectSingleNode("name") != null) { nom = question["name"].FirstChild.InnerText; } res.nomq = nom; if (question.SelectSingleNode("questiontext") != null) { titreq = question["questiontext"].FirstChild.InnerText; } if (question.SelectSingleNode("generalfeedback") != null) { feedbackq = question["generalfeedback"].FirstChild.InnerText; } foreach (XmlNode reponse in question.SelectNodes("answer")) { String feedbackr = ""; Boolean vrai = false; if (reponse.SelectSingleNode("feedback") != null) { feedbackr = reponse["feedback"].FirstChild.InnerText; } if (double.Parse(reponse.Attributes[0].InnerText.Replace(".", ",")) > 0) { vrai = true; } res.addReponse(new ReponseSimple(feedbackr, reponse["text"].InnerText, vrai)); } res.addTitre(titreq); res.feedbackQ = feedbackq; return(res); }
/// <summary> /// 获取存放某一科目题目的临时字典 /// </summary> /// <param name="tableName">表的名字</param> /// <param name="subjectChapterID">科目ID</param> /// <returns></returns> private Dictionary <Int32, QuestionSimple> GetQuesOfSubject(String tableName, Int32 subjectID) { Dictionary <Int32, QuestionSimple> dictonary = new Dictionary <int, QuestionSimple>(); StringBuilder sqlStr = new StringBuilder(); sqlStr.Append("SELECT id,chapterid,diff FROM "); sqlStr.Append(tableName); sqlStr.Append(" WHERE chapterid IN (SELECT DISTINCT [id] FROM [tbChapter] WHERE subjectid=@subjectid) and questype=1"); DataSet ds = SQLHelper.ExecuteDataset(SqlTransaction, CommandType.Text, sqlStr.ToString(), new SqlParameter("@subjectid", subjectID)); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { QuestionSimple qs = new QuestionSimple(); qs.ID = (Int32)ds.Tables[0].Rows[i][0]; qs.SubjectChapterID = (Int32)ds.Tables[0].Rows[i][1]; qs.Difficulty = Convert.ToDecimal(ds.Tables[0].Rows[i][2].ToString()); dictonary.Add(qs.ID, qs); } return(dictonary); }
private static Object makeQuestion(Groupe gp, Boolean open, string ligne) { String type = ligne.Substring(0, 2); Question q = null; Groupe g = null; switch (type) { case "*<": q = new QuestionOuverteAMC(); int nblignes = 1; int debutl = ligne.IndexOf("<"); int finl = ligne.IndexOf(">"); if ((debutl != -1) && (finl != -1)) { String options = ligne.Substring(debutl + 1, finl - 2); String[] spl = options.Split("="); if (spl[0].ToLower().Equals("lines")) { nblignes = int.Parse(spl[1]); } q.addTitre(ligne.Substring(finl + 1)); } ((QuestionOuverte)q).setLignes(nblignes); break; case "**": q = new QuestionMultiple(); break; case "*(": g = new Groupe(); g.addTexte1(ligne.Substring(3)); break; case "*)": if (open) { open = false; if (ligne.Length > 2) { gp.addTexte2(ligne.Substring(2)); } } break; default: q = new QuestionSimple(); break; } int debutopt = ligne.IndexOf("{"); int finopt = ligne.IndexOf("}"); if ((debutopt != -1) && (finopt != -1)) { ligne = ligne.Substring(finopt + 2); } else { ligne = ligne.Substring(2); } if (q != null) { if (q.titre.Count == 0) { q.addTitre(ligne); } return(q); } return(g); }