private static string exportReponsesMultiple(QuestionMultiple q) { String res = "{\n"; foreach (Reponse r in q.getReponses()) { ReponseSimple rs = (ReponseSimple)r; String fraction = ""; if (rs.isTrue()) { fraction = "100"; } else { fraction = "-100"; } res += "~%" + fraction + "%" + rs.texte; if (!rs.feedbackR.Equals("")) { res += "#" + rs.feedbackR; } res += "\n"; } if (!q.feedbackQ.Equals("")) { res += "####" + q.feedbackQ + "\n"; } res += "}\n\n"; return(res); }
public Question Create() { switch (Type) { case (int)QuestionType.QT_Single: List <Answer> answers1 = new List <Answer>(); foreach (GAnswer answer in this.GAnswer) { answers1.Add(answer.Create()); } QuestionSingle question1 = new QuestionSingle(Text, answers1); return(question1); case (int)QuestionType.QT_Multiple: List <Answer> answers2 = new List <Answer>(); foreach (GAnswer answer in this.GAnswer) { answers2.Add(answer.Create()); } QuestionMultiple question2 = new QuestionMultiple(Text, answers2); return(question2); case (int)QuestionType.QT_Free: Answer answer3 = default(Answer); foreach (GAnswer answer in this.GAnswer) { answer3 = answer.Create(); } QuestionFree question3 = new QuestionFree(Text, answer3); return(question3); default: throw new NotImplementedException(); } }
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); }
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); }
public async Task <Survey> GetSurveyData(string surveyID) { Survey survey = new Survey(); using (var connection = ConnectionManager.GetConnection()) { using (SqlCommand cmd = new SqlCommand( "SELECT id, user_owner, survey_name, survey_description " + "FROM dbo.Survey WHERE id = @surveyID AND is_closed = 0" , connection)) { try { cmd.Parameters.AddWithValue("surveyID", surveyID); connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { // Check is the reader has any rows at all before starting to read. if (reader.HasRows) { while (reader.Read()) { var ID = reader.GetString(reader.GetOrdinal("id")); var surveyOwner = reader.GetString(reader.GetOrdinal("user_owner")); var surveyName = reader.GetString(reader.GetOrdinal("survey_name")); var surveyDesc = reader.GetString(reader.GetOrdinal("survey_description")); survey.ID = ID; survey.Name = surveyName; survey.Description = surveyDesc; survey.Owner = surveyOwner; } } } } catch (Exception ex) { Console.WriteLine("Cannot get survey: " + ex.ToString()); return(null); } } QuestionMultiple question; var questions = new List <QuestionMultiple>(); using (SqlCommand cmd = new SqlCommand( $"SELECT id, question_pos, question_text, option_one, option_two, option_three, option_four " + $"FROM dbo.QuestionMultiple WHERE survey_id = @survey_id" , connection)) { try { cmd.Parameters.AddWithValue("survey_id", surveyID); using (SqlDataReader reader = cmd.ExecuteReader()) { // Check is the reader has any rows at all before starting to read. if (reader.HasRows) { while (reader.Read()) { var id = reader.GetString(reader.GetOrdinal("id")); var pos = reader.GetInt32(reader.GetOrdinal("question_pos")); var text = reader.GetString(reader.GetOrdinal("question_text")); var one = reader.GetString(reader.GetOrdinal("option_one")); var two = reader.GetString(reader.GetOrdinal("option_two")); var three = reader.GetString(reader.GetOrdinal("option_three")); var four = reader.GetString(reader.GetOrdinal("option_four")); question = new QuestionMultiple(id, text, new List <string>() { one, two, three, four }); questions.Add(question); } } } } catch (Exception ex) { Console.WriteLine("Cannot get answers for survey: " + ex.ToString()); return(null); } } survey.QuestionsMultipleChoice = questions; } return(survey); }
public async Task <List <Survey> > GetAllSurveysPopulated(string userID) { var surveys = new List <Survey>(); using (var connection = ConnectionManager.GetConnection()) { using (SqlCommand cmd = new SqlCommand( $"SELECT id, user_owner, survey_name, survey_description " + $"FROM dbo.Survey WHERE user_owner = @user_owner AND is_closed = 0" , connection)) { try { cmd.Parameters.AddWithValue("user_owner", userID); connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { // Check is the reader has any rows at all before starting to read. if (reader.HasRows) { while (reader.Read()) { var surveyID = reader.GetString(reader.GetOrdinal("id")); var surveyOwner = reader.GetString(reader.GetOrdinal("user_owner")); var surveyName = reader.GetString(reader.GetOrdinal("survey_name")); var surveyDesc = reader.GetString(reader.GetOrdinal("survey_description")); surveys.Add(new Survey(surveyID, surveyOwner, surveyName, surveyDesc)); } } } } catch (Exception ex) { Console.WriteLine("Cannot get surveys: " + ex.ToString()); return(null); } } foreach (var survey in surveys) { QuestionMultiple question; var questions = new List <QuestionMultiple>(); using (SqlCommand cmd = new SqlCommand( $"SELECT id, question_pos, question_text, option_one, option_two, option_three, option_four " + $"FROM dbo.QuestionMultiple WHERE survey_id = @survey_id" , connection)) { try { cmd.Parameters.AddWithValue("survey_id", survey.ID); using (SqlDataReader reader = cmd.ExecuteReader()) { // Check is the reader has any rows at all before starting to read. if (reader.HasRows) { while (reader.Read()) { var id = reader.GetString(reader.GetOrdinal("id")); var pos = reader.GetInt32(reader.GetOrdinal("question_pos")); var text = reader.GetString(reader.GetOrdinal("question_text")); var one = reader.GetString(reader.GetOrdinal("option_one")); var two = reader.GetString(reader.GetOrdinal("option_two")); var three = reader.GetString(reader.GetOrdinal("option_three")); var four = reader.GetString(reader.GetOrdinal("option_four")); question = new QuestionMultiple(id, text, new List <string>() { one, two, three, four }); questions.Add(question); } } } } catch (Exception ex) { Console.WriteLine("Cannot get answers for surveys: " + ex.ToString()); return(null); } } survey.QuestionsMultipleChoice = questions; //set the QuestionsMultiple property to the questions matching the surveyID //surveys.Select(o => { o.QuestionsMultipleChoice = questions; return o;}).Where(x => x.ID == survey.ID).ToList(); } } return(surveys); }
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); }