public static DataTable prepareExportTable(List <Factor> factors, List <CustomPersonalAnswer> personalAnswers) { try { DataTable dt = new DataTable(); foreach (Factor f in factors) { foreach (Question q in f.questions) { dt.Columns.Add(q.text, typeof(string)); } } List <DataRow> dataRows = new List <DataRow>(); foreach (CustomPersonalAnswer answer in personalAnswers) { DataRow dataRow = dt.NewRow(); for (int i = 0; i < answer.answers.Count; i++) { switch (answer.questions.ElementAt(i).type) { case QuestionTypes.LIKERT_3: dataRow[answer.questions.ElementAt(i).text] = QuestionTypes.likertStrings_3().ElementAt(answer.answers.ElementAt(i).value - 1); break; case QuestionTypes.LIKERT_5: dataRow[answer.questions.ElementAt(i).text] = QuestionTypes.likertStrings_5().ElementAt(answer.answers.ElementAt(i).value - 1); break; case QuestionTypes.LIKERT_7: dataRow[answer.questions.ElementAt(i).text] = QuestionTypes.likertStrings_7().ElementAt(answer.answers.ElementAt(i).value - 1); break; case QuestionTypes.RADIO: dataRow[answer.questions.ElementAt(i).text] = answer.questions.ElementAt(i).choices[answer.answers.ElementAt(i).value - 1]; break; case QuestionTypes.CHECK_BOX: string value = ""; foreach (int index in answer.answers.ElementAt(i).chValues) { value += answer.questions.ElementAt(i).choices[index] + ","; } value = value.Remove(value.Length - 1); dataRow[answer.questions.ElementAt(i).text] = value; break; } } dt.Rows.Add(dataRow); } return(dt); } catch (Exception e) { Console.WriteLine(e.StackTrace); } return(null); }
private void Init(Question question) { switch (question.type) { case QuestionTypes.CHECK_BOX: counts = new int[question.choices.Count()]; choices = question.choices.ToList(); foreach (Answer answer in question.answers) { int j = 0; foreach (String choice in question.choices) { if (answer.chValues.Contains(j)) { counts[j]++; } j++; } } break; case QuestionTypes.RADIO: counts = new int[question.choices.Count()]; choices = question.choices.ToList(); foreach (Answer answer in question.answers) { counts[answer.value - 1]++; } break; case QuestionTypes.LIKERT_3: counts = new int[3]; choices = QuestionTypes.likertStrings_3(); foreach (Answer answer in question.answers) { counts[answer.value - 1]++; } break; case QuestionTypes.LIKERT_5: counts = new int[5]; choices = QuestionTypes.likertStrings_5(); foreach (Answer answer in question.answers) { counts[answer.value - 1]++; } break; case QuestionTypes.LIKERT_7: counts = new int[7]; choices = QuestionTypes.likertStrings_7(); foreach (Answer answer in question.answers) { counts[answer.value - 1]++; } break; } labelQuestion.DataBindings.Add("Text", question, "text", true, DataSourceUpdateMode.OnPropertyChanged); SeriesCollection series = new SeriesCollection(); int i = 0; foreach (String choice in choices) { series.Add(new PieSeries { Title = choices.ElementAt(i), Values = new ChartValues <int> { counts[i] }, LabelPoint = labelPoint, DataLabels = false }); i++; } pieChart.Series = series; pieChart.Visible = true; pieChart.LegendLocation = LegendLocation.Right; }