private string BuildSurveyTableNoLinks(Survey survey) { try { StringBuilder sb = new StringBuilder(); string root = Request.Url.OriginalString.Substring(0, Request.Url.OriginalString.ToLower().LastIndexOf("/survey/")); if (!root.EndsWith("/")) root += "/"; sb.AppendLine("<table style=\"border-spacing:0;border-collapse:collapse;\" class=\"surveytable\">"); sb.AppendLine("<tr class=\"surveyrow\">"); sb.AppendLine("<td class=\"gridtext\">" + survey.SurveyName + "</td>"); sb.AppendLine("<td class=\"gridtext\" style=\"width:110px;\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"width:25px;\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"width:45px;\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"width:35px;\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"width:55px;\"></td>"); sb.AppendLine("</tr>"); // Loop through each question and question option ISurveyQuestionRepository qrep = new EntitySurveyQuestionRepository(); ISurveyQuestionOptionRepository orep = new EntitySurveyQuestionOptionRepository(); List<SurveyQuestion> questions = qrep.GetSurveyQuestions(survey.SurveyID).ToList(); foreach (SurveyQuestion question in questions) { sb.AppendLine("<tr class=\"questionrow\">"); string selectionmode = " (Single Select)"; if (question.AllowMultiSelect) selectionmode = " (Multi Select)"; sb.AppendLine("<td class=\"gridtext\">" + question.SurveyQuestionText + selectionmode + "</td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>"); sb.AppendLine("</tr>"); // Loop through each question option List<SurveyQuestionOption> options = orep.GetSurveyQuestionOptions(question.SurveyQuestionID).ToList(); foreach (SurveyQuestionOption option in options) { sb.AppendLine("<tr class=\"optionrow\">"); sb.AppendLine("<td class=\"gridtext\" style=\"padding-left:15px;\">" + option.SurveyQuestionOptionText + "</td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>"); sb.AppendLine("</tr>"); } } sb.Append("</table>"); return sb.ToString(); } catch { return String.Empty; } }
private string BuildSurveyResultsTable(int surveyid) { try { StringBuilder sb = new StringBuilder(); ISurveyRepository srep = new EntitySurveyRepository(); Survey survey = srep.GetSurvey(surveyid); if (survey == null) return String.Empty; // Get the answered surveys IAnsweredSurveyRepository answeredsurveyrespository = new EntityAnsweredSurveyRepository(); IEnumerable<AnsweredSurvey> answeredsurveys = answeredsurveyrespository.GetBySurveyID(surveyid); sb.AppendLine("<table style=\"border-spacing:0;border-collapse:collapse;\" class=\"surveytable\">"); sb.AppendLine("<tr class=\"surveyrow\">"); sb.AppendLine("<td class=\"gridtext\">" + survey.SurveyName + "</td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"width:100px;\"></td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"width:100px;\"></td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("<td class=\"gridtext\" style=\"width:100px;\"></td>"); sb.AppendLine("</tr>"); sb.AppendLine("<tr class=\"surveysubheadrow\">"); sb.AppendLine("<td class=\"gridtext\">Total Answered Survey Count: " + answeredsurveys.Count().ToString() + "</td>"); sb.AppendLine("<td class=\"gridtext\" colspan=\"2\">Selected</td>"); sb.AppendLine("<td class=\"gridtext\" colspan=\"2\">Deselected</td>"); sb.AppendLine("<td class=\"gridtext\" colspan=\"2\">Unanswered</td>"); sb.AppendLine("</tr>"); // Loop through each question and question option ISurveyQuestionRepository qrep = new EntitySurveyQuestionRepository(); ISurveyQuestionOptionRepository orep = new EntitySurveyQuestionOptionRepository(); IAnsweredSurveyQuestionOptionRepository aorep = new EntityAnsweredSurveyQuestionOptionRepository(); List<SurveyQuestion> questions = qrep.GetSurveyQuestions(survey.SurveyID).ToList(); foreach (SurveyQuestion question in questions) { sb.AppendLine("<tr class=\"questionrow\">"); sb.AppendLine("<td class=\"gridtext\">" + question.SurveyQuestionText + "</td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("<td class=\"gridtext\"></td>"); sb.AppendLine("</tr>"); // Loop through each question option List<SurveyQuestionOption> options = orep.GetSurveyQuestionOptions(question.SurveyQuestionID).ToList(); foreach (SurveyQuestionOption option in options) { // Add the number of selected/unselected double selectedcount = 0; double deselectedcount = 0; double unansweredcount = 0; IEnumerable<AnsweredSurveyQuestionOption> aoptions = aorep.GetBySurveyQuestionOptionId(option.SurveyQuestionOptionID); foreach (AnsweredSurveyQuestionOption aoption in aoptions) { if (aoption.IsSelected) selectedcount += 1.0; else deselectedcount += 1.0; } unansweredcount = Convert.ToDouble(answeredsurveys.Count()) - selectedcount - deselectedcount; int selectedwidth = 0; int deselectedwidth = 0; int unansweredwidth = 0; if (answeredsurveys.Count() > 0) { selectedwidth = Convert.ToInt32((selectedcount / Convert.ToDouble(answeredsurveys.Count())) * 90); deselectedwidth = Convert.ToInt32((deselectedcount / Convert.ToDouble(answeredsurveys.Count())) * 90); unansweredwidth = Convert.ToInt32((unansweredcount / Convert.ToDouble(answeredsurveys.Count())) * 90); } sb.AppendLine("<tr class=\"optionrow\">"); sb.AppendLine("<td class=\"gridtext\" style=\"padding-left:15px;\">" + option.SurveyQuestionOptionText + "</td>"); sb.AppendLine("<td class=\"gridtext\">" + selectedcount.ToString() + "</td>"); sb.AppendLine("<td class=\"gridtext\">"); sb.Append(@"<div style=""width:" + selectedwidth.ToString() + @"px;height:8px;background-color:#00CC00;"" /> "); sb.AppendLine("</td>"); sb.AppendLine("<td class=\"gridtext\">" + deselectedcount.ToString() + "</td>"); sb.AppendLine("<td class=\"gridtext\">"); sb.Append(@"<div style=""width:" + deselectedwidth.ToString() + @"px;height:8px;background-color:#0000CC;"" /> "); sb.AppendLine("<td class=\"gridtext\">" + unansweredcount.ToString() + "</td>"); sb.AppendLine("<td class=\"gridtext\">"); sb.Append(@"<div style=""width:" + unansweredwidth.ToString() + @"px;height:8px;background-color:#CC0000;"" /> "); sb.AppendLine("</td>"); sb.AppendLine("</tr>"); } } sb.Append("</table>"); return sb.ToString(); } catch { return String.Empty; } }