Example #1
0
        public override DataSet Clone()
        {
            QuestionResultsData data = (QuestionResultsData)base.Clone();

            data.InitVars();
            return(data);
        }
        /// <summary>
        /// Returns the question and its answers results
        /// </summary>
        public QuestionResultsData GetQuestionResults(int questionId, int filterId, string sortOrder, string languageCode, DateTime startDate, DateTime endDate)
        {
            //SqlParameter[] commandParameters = new SqlParameter[] 
            //{ new SqlParameter("@questionId", questionId), 
            //    new SqlParameter("@filterId", filterId), 
            //    new SqlParameter("@sortOrder", sortOrder), 
            //    new SqlParameter("@LanguageCode", languageCode), 
            //    new SqlParameter("@StartDate", startDate), 
            //    new SqlParameter("@EndDate", endDate) 
            //};

            ArrayList commandParameters = new ArrayList();
            {
                commandParameters.Add(new SqlParameter("@questionId", questionId).SqlValue);
                commandParameters.Add(new SqlParameter("@filterId", filterId).SqlValue);
                commandParameters.Add(new SqlParameter("@sortOrder", sortOrder).SqlValue);
                commandParameters.Add(new SqlParameter("@LanguageCode", languageCode).SqlValue);
                commandParameters.Add(new SqlParameter("@StartDate", startDate).SqlValue);
                commandParameters.Add(new SqlParameter("@EndDate", endDate).SqlValue);
            } 
            
            
            QuestionResultsData dataSet = new QuestionResultsData();
            DbConnection.db.LoadDataSet("vts_spQuestionGetResults", dataSet, new string[] { "Questions", "Answers" }, commandParameters.ToArray());
            return dataSet;
        }
		private void SetAnswerData(QuestionResultsData.AnswersRow[] answers, float totalOfVotes, ChartEngine engine, WebChart.PieChart pieChart)
		{
			float currentRate = 0; 
			float totalRate = 0;
			float totalRateVotes = 0;
			
			foreach (QuestionResultsData.AnswersRow answer in answers)
			{
				if ((((AnswerTypeMode)answer.TypeMode & AnswerTypeMode.Selection) > 0))
				{
					float VotePercent = 0;

					if (totalOfVotes != 0)
					{
						if (answer.VoterCount==0)
							VotePercent = 0;		
						else
							VotePercent = ((float)answer.VoterCount / (float)totalOfVotes) * 100;
					}

					// Add answer text & vote count
					answer.AnswerText = Server.HtmlDecode(System.Text.RegularExpressions.Regex.Replace(answer.AnswerText, "<[^>]*>", " "));
					string answerChartText;
					
					if (VotePercent == 0)
					{
						answerChartText = string.Format("{0} " + Environment.NewLine +"({1} - 0%)",
							answer.AnswerText, answer.VoterCount.ToString(), VotePercent.ToString("##.##"));
					}
					else
					{
						answerChartText = string.Format("{0} " + Environment.NewLine +" ({1} - {2}%)",
							answer.AnswerText, answer.VoterCount.ToString(), VotePercent.ToString("##.##"));
					}
					
					
					pieChart.Data.Add(new ChartPoint(answerChartText, VotePercent));

					// Do we include this answer in the
					// rating total
					if (answer.RatePart)
					{
						currentRate++;
						totalRate += currentRate * answer.VoterCount;
						totalRateVotes += answer.VoterCount;
					}
				}
			}
		
			StringFormat horizontalFormat = new StringFormat();
			horizontalFormat.LineAlignment = StringAlignment.Near;
			engine.XTitle  = new ChartText();
			engine.XTitle.StringFormat = horizontalFormat;
			engine.XTitle.Font = new System.Drawing.Font("Verdana", 8);

			// Do we show the average rating 
			if (_dataSource.Questions[0].RatingEnabled)
			{
				double meanRate = 0;

				if (totalOfVotes == 0)
					meanRate = 0;
				else
					meanRate = totalRate / totalRateVotes;

				engine.XTitle.Text = string.Format("{0} - {1}",
					String.Format(ResourceManager.GetString("TotalOfVotes"), totalOfVotes),
					string.Format(ResourceManager.GetString("RatingResults"), meanRate.ToString("##.##"), currentRate));		
			}
			else
			{
				engine.XTitle.Text = String.Format(ResourceManager.GetString("TotalOfVotes"), totalOfVotes);
			}
		}
		private float GetVotersTotal(QuestionResultsData.AnswersRow[] answers)
		{
			float total = 0;
			foreach (QuestionResultsData.AnswersRow answer in answers)
			{
				// Increment only selection answers that can be selected
				if ((((AnswerTypeMode)answer.TypeMode & AnswerTypeMode.Selection) > 0))
				{
					total += answer.VoterCount;
				}
			}
			return total;
		}
		private Table BuildResultsBarTable(QuestionResultsData.AnswersRow[] answers, double totalOfVotes)
		{
			double currentRate = 0; 
			double totalRate = 0;
			double totalOfVotesRate = 0;

			Table barTable = new Table();
			barTable.Width = Unit.Percentage(95);
			barTable.BorderWidth = 0;
			barTable.ControlStyle.CopyFrom(AnswerStyle);

			foreach (QuestionResultsData.AnswersRow answer in answers)
			{
				if ((((AnswerTypeMode)answer.TypeMode & AnswerTypeMode.Selection) > 0))
				{
					double VotePercent = 0;

					if (totalOfVotes != 0)
					{
						if (answer.VoterCount==0)
							VotePercent = 0;		
						else
							VotePercent = ((double)answer.VoterCount / (double)totalOfVotes) * 100;
					}

					// Add answer text & vote count
					answer.AnswerText = Context.Server.HtmlEncode(System.Text.RegularExpressions.Regex.Replace(answer.AnswerText, "<[^>]*>", " "));
					string answerCellText;
					if (!ShowOnlyPercent)
					{
						answerCellText = string.Format("{0}&nbsp;({1})",
							answer.AnswerText, answer.VoterCount.ToString());
					}
					else
					{
						answerCellText = answer.AnswerText;
					}
					barTable.Rows.Add(BuildRow(answerCellText, AnswerStyle));				

					// Add results bar
					ResultsBar resultsBar = new ResultsBar();
					resultsBar.Progress = (int)Math.Round(VotePercent);
					resultsBar.ItemStyle = this.AnswerStyle;
					resultsBar.BarColor = BarColor;
					if (this.Width.IsEmpty)
					{
						resultsBar.TableWidth = 110;
					}
					else
					{
						resultsBar.TableWidth = this.Width;
					}
					barTable.Rows.Add(BuildRow(resultsBar, AnswerStyle));				
					
					// Do we include this answer in the
					// rating total
					if (answer.RatePart)
					{
						currentRate++;
						totalRate += currentRate * answer.VoterCount;
						totalOfVotesRate += answer.VoterCount;
					}
				}
			}
			
			// Add Rating Bar
			if (_dataSource.Questions[0].RatingEnabled && currentRate>0)
			{
				double meanRate = 0;

				if (totalOfVotes == 0)
					meanRate = 0;
				else
					meanRate = totalRate / totalOfVotesRate;
			
				RatingBar ratingBar = new RatingBar();
				ratingBar.MaxRating = currentRate;
				ratingBar.Rating = meanRate;
				ratingBar.ItemStyle = this.AnswerStyle;

				if (this.Width.IsEmpty)
				{
					ratingBar.TableWidth = 110;
				}
				else
				{
					ratingBar.TableWidth = this.Width;
				}

				barTable.Rows.Add(BuildRow(ratingBar, AnswerStyle));
			}

			return barTable;
		}
 public void RemoveQuestionsRow(QuestionResultsData.QuestionsRow row)
 {
     base.Rows.Remove(row);
 }
 public void AddQuestionsRow(QuestionResultsData.QuestionsRow row)
 {
     base.Rows.Add(row);
 }
 public AnswersRowChangeEvent(QuestionResultsData.AnswersRow row, DataRowAction action)
 {
     this.eventRow = row;
     this.eventAction = action;
 }
 public void RemoveAnswersRow(QuestionResultsData.AnswersRow row)
 {
     base.Rows.Remove(row);
 }
 public QuestionResultsData.AnswersRow AddAnswersRow(QuestionResultsData.QuestionsRow parentQuestionsRowByQuestionsAnswers, int AnswerTypeId, int VoterCount, int TypeMode, string AnswerText, bool RatePart)
 {
     QuestionResultsData.AnswersRow row = (QuestionResultsData.AnswersRow) base.NewRow();
     object[] objArray = new object[7];
     objArray[1] = parentQuestionsRowByQuestionsAnswers[0];
     objArray[2] = AnswerTypeId;
     objArray[3] = VoterCount;
     objArray[4] = TypeMode;
     objArray[5] = AnswerText;
     objArray[6] = RatePart;
     row.ItemArray = objArray;
     base.Rows.Add(row);
     return row;
 }
 public void AddAnswersRow(QuestionResultsData.AnswersRow row)
 {
     base.Rows.Add(row);
 }