protected override string GenerateQuestionsReport(bool onlyAnswered)
		{
			StringBuilder questionsReport = new StringBuilder();
			_questionData = new Questions().GetQuestionHierarchy(_surveyId);

			questionsReport.Append(Environment.NewLine + "<br />" + ResourceManager.GetString("SurveyAnswersTitle") + Environment.NewLine + "<br />");
			questionsReport.Append("-----------------------------------------" + Environment.NewLine + "<br />");

			QuestionData.QuestionsRow[] parentQuestions = GetParentQuestions();

			for (int i=0;i<parentQuestions.Length;i++)
			{
				string questionText = ((QuestionData.QuestionsRow)parentQuestions[i]).QuestionText;
				questionText = questionText.Replace("<br />", Environment.NewLine + "<br />");
				questionText = 	new PipeManager().PipeValuesInText(((QuestionData.QuestionsRow)parentQuestions[i]).QuestionId, questionText, _voterAnswers.VotersAnswers, null);

				if (System.Web.HttpContext.Current != null)
				{
					questionText = System.Text.RegularExpressions.Regex.Replace(questionText, "<[^>]*>", " ");
				}

				// Check if the question has childs
				string filter = string.Format("ParentQuestionID = {0}", ((QuestionData.QuestionsRow)parentQuestions[i]).QuestionId); 
				QuestionData.QuestionsRow[] childQuestions = (QuestionData.QuestionsRow[])_questionData.Questions.Select(filter,"DisplayOrder", DataViewRowState.CurrentRows);
				if (childQuestions.Length == 0)
				{
					StringBuilder answerReport = new StringBuilder();

					for (int sectionNumber=0;sectionNumber<=GetQuestionSectionCount(((QuestionData.QuestionsRow)parentQuestions[i]).QuestionId);sectionNumber++)
					{
						answerReport.Append(GenerateAnswersReport(((QuestionData.QuestionsRow)parentQuestions[i]).QuestionId, onlyAnswered, sectionNumber));
						answerReport.Append(Environment.NewLine + "<br />");
					}
					
					if (answerReport.Length > 0 || !onlyAnswered)
					{

						questionsReport.Append( questionText + Environment.NewLine + "<br />");
						questionsReport.Append(answerReport);
						if (isScored)
						{
							questionsReport.Append(Environment.NewLine + "<br />");
							questionsReport.Append(ResourceManager.GetString("QuestionScoreLabel")+ _questionScore);
						}
						_totalScore += _questionScore;
						questionsReport.Append(Environment.NewLine + "<br />" + Environment.NewLine + "<br />");
					}
					_questionScore = 0;
				}
				else
				{
					questionsReport.Append( "-----" + Environment.NewLine + "<br />");
					questionsReport.Append( questionText + Environment.NewLine + "<br />" + Environment.NewLine + "<br />" );
					for (int sectionNumber=0;sectionNumber<=GetMatrixSectionCount(new DataView(_questionData.Questions,filter,"DisplayOrder", DataViewRowState.CurrentRows));sectionNumber++)
					{
						questionsReport.Append(GenerateMatrixReport(childQuestions, onlyAnswered, sectionNumber));
						questionsReport.Append(Environment.NewLine + "<br />");
					}
					questionsReport.Append( "-----"+ Environment.NewLine + "<br />");
					questionsReport.Append(Environment.NewLine + "<br />" + Environment.NewLine + "<br />");
				}
			}

			return questionsReport.ToString();
		}
		/// <summary>
		/// Generates the answers list for the question
		/// </summary>
		/// <param name="questionId"></param>
		/// <param name="onlyAnswered">show only answers that have been answered</param>
		string GenerateAnswersReport(int questionId, bool onlyAnswered, int sectionNumber)
		{
			StringBuilder answersReport = new StringBuilder();

			AnswerData questionAnswers = new Answers().GetAnswers(questionId, null);
			int longestTextLength = GetLongestAnswerLength(questionAnswers);

			foreach (AnswerData.AnswersRow answer in questionAnswers.Answers.Rows)
			{
				AnswerTypeMode typeMode = (AnswerTypeMode) answer.TypeMode;

				VoterAnswersData.VotersAnswersRow voterAnswer = _voterAnswers.VotersAnswers.FindByVoterIdAnswerIdSectionNumber(_voterAnswers.Voters[0].VoterId , answer.AnswerId, sectionNumber);
				string answerText = new PipeManager().PipeValuesInText(questionId, answer.AnswerText, _voterAnswers.VotersAnswers, null);

				if (voterAnswer != null)
				{

					// Check answer type
					if ((((typeMode & AnswerTypeMode.Field) > 0) || 
						((typeMode & AnswerTypeMode.Custom) > 0) ||
						((typeMode & AnswerTypeMode.DataSource) > 0)) &&
						((typeMode & AnswerTypeMode.Selection) == 0))
					{
						if (voterAnswer.AnswerText.Length > 0)
						{
							answersReport.Append(" " + answerText + GenerateMissingSpaces(answerText.Length, longestTextLength) + " " + voterAnswer.AnswerText + Environment.NewLine + "<br />");
						}
						else if (!onlyAnswered)
						{
							answersReport.Append(" " + answerText + GenerateMissingSpaces(answerText.Length, longestTextLength) + " " + ResourceManager.GetString("AnswerNotAnsweredMessage") + Environment.NewLine + "<br />");
						}
					}
					else if (((AnswerTypeMode)answer.TypeMode & AnswerTypeMode.Field) > 0 &&
							((AnswerTypeMode)answer.TypeMode & AnswerTypeMode.Selection) > 0)
					{
						answersReport.Append( " " + answerText + GenerateMissingSpaces(answerText.Length, longestTextLength) + " [x] " +voterAnswer.AnswerText+ Environment.NewLine + "<br />");
						_questionScore += answer.ScorePoint;
					}
					else if(((AnswerTypeMode)typeMode & AnswerTypeMode.Upload) > 0)
					{
						answersReport.Append( " " + answerText + GenerateMissingSpaces(answerText.Length, longestTextLength) + " " +GenerateFileList(voterAnswer.AnswerText)+ Environment.NewLine + "<br />");
					}

					else
					{
						answersReport.Append( " " + answerText + GenerateMissingSpaces(answerText.Length, longestTextLength) + " [x]" + Environment.NewLine + "<br />");
						_questionScore += answer.ScorePoint;
					}
				}
				else if (!onlyAnswered)
				{
					// Check answer type
					if ((((typeMode & AnswerTypeMode.Field) > 0) || 
						((typeMode & AnswerTypeMode.Custom) > 0) ||
						((typeMode & AnswerTypeMode.DataSource) > 0)) &&
						((typeMode & AnswerTypeMode.Selection) == 0))
					{
						answersReport.Append(" " + answerText + GenerateMissingSpaces(answerText.Length, longestTextLength) + " " + ResourceManager.GetString("AnswerNotAnsweredMessage")+ Environment.NewLine + "<br />");
					}
					else if ( ((AnswerTypeMode)answer.TypeMode & AnswerTypeMode.Field) > 0 &&
							((AnswerTypeMode)answer.TypeMode & AnswerTypeMode.Selection) > 0)
					{
						answersReport.Append( " " + answerText + GenerateMissingSpaces(answerText.Length, longestTextLength) + " [] " +ResourceManager.GetString("AnswerNotAnsweredMessage")+ Environment.NewLine + "<br />");
					}
					else
					{
						answersReport.Append( " " + answerText + GenerateMissingSpaces(answerText.Length, longestTextLength) + " []" + Environment.NewLine + "<br />");
					}

				}
			}

			return answersReport.ToString();
		}
コード例 #3
0
 /// <summary>
 /// Parse the given string and replace any
 /// available templates by their runtime values
 /// </summary>
 private static string ParseDefaultAnswerText(int questionId, string currentDefaultText, VoterAnswersData.VotersAnswersDataTable voterAnswersState, string languageCode)
 {
     currentDefaultText = new PipeManager().PipeValuesInText(questionId, currentDefaultText, voterAnswersState, languageCode);
     string str = new Regex(@"#{2}((\S)+)#{2}").Match(currentDefaultText).Groups[1].ToString();
     if ((str.Length > 0) && (HttpContext.Current != null))
     {
         currentDefaultText = (HttpContext.Current.Request[str] == null) ? string.Empty : HttpContext.Current.Request[str];
         return currentDefaultText;
     }
     string str2 = new Regex(@"%{2}((\S)+)%{2}").Match(currentDefaultText).Groups[1].ToString();
     if ((str2.Length > 0) && (HttpContext.Current != null))
     {
         currentDefaultText = (HttpContext.Current.Request.ServerVariables[str2] == null) ? string.Empty : HttpContext.Current.Request.ServerVariables[str2];
         return currentDefaultText;
     }
     string str3 = new Regex(@"@{2}((\S)+)@{2}").Match(currentDefaultText).Groups[1].ToString();
     if ((str3.Length > 0) && (HttpContext.Current != null))
     {
         currentDefaultText = (HttpContext.Current.Session[str3] == null) ? string.Empty : HttpContext.Current.Session[str3].ToString();
         return currentDefaultText;
     }
     string str4 = new Regex(@"&{2}((\S)+)&{2}").Match(currentDefaultText).Groups[1].ToString();
     if ((str4.Length > 0) && (HttpContext.Current != null))
     {
         currentDefaultText = (HttpContext.Current.Request.Cookies[str4] == null) ? string.Empty : HttpContext.Current.Request.Cookies[str4].Value.ToString();
         return currentDefaultText;
     }
     return currentDefaultText;
 }