public PdfPTable QuestionReport(String path, ViewModels.PollReportViewModel model,String entity) { if (model.selectedEntities.Count == 0) { PdfPTable table = new PdfPTable(4); int[] width = new int[4] { 2, 15, 12, 6 }; table.WidthPercentage = 100; table.SetWidths(width); Phrase phrase = new Phrase("#", font); BaseColor basecolor = new BaseColor(232, 238, 244); BaseColor heading = new BaseColor(232, 238, 0); heading.Darker(); heading.Darker(); if (entity != null) { PdfPCell entityline = new PdfPCell(new Phrase("Entity: " + entity, font)); entityline.BackgroundColor = heading; entityline.Colspan = 4; table.AddCell(entityline); } if (model.tick != null) { String line; if (model.include) line = "Include "; else line = "Exclude "; line += model.field.name + ", Values: "; foreach (string i in model.tick) line += i + ", "; line = line.Remove(line.Length - 2); PdfPCell demo = new PdfPCell(new Phrase(line + entity, font)); demo.BackgroundColor = heading; demo.Colspan = 4; table.AddCell(demo); } table.AddCell(new PdfPCell(new PdfPCell(new Phrase(phrase)) { BackgroundColor = basecolor })); phrase.Clear(); phrase.Add("Question"); table.AddCell(new PdfPCell(new PdfPCell(new Phrase(phrase)) { BackgroundColor = basecolor })); phrase.Clear(); phrase.Add("Answers"); table.AddCell(new PdfPCell(new PdfPCell(new Phrase(phrase)) { BackgroundColor = basecolor })); phrase.Clear(); phrase.Add("Number of Responses"); table.AddCell(new PdfPCell(new PdfPCell(new Phrase(phrase)) { BackgroundColor = basecolor })); foreach (var question in model.questions) { if (question.deletionTime == null) { phrase.Clear(); phrase.Add(question.questionNumber.ToString()); table.AddCell(new Phrase(phrase)); phrase.Clear(); phrase.Add(question.question); table.AddCell(new Phrase(phrase)); PdfPTable options = new PdfPTable(2); options.SetWidths(new int[2] { 4, 2 }); foreach (var answer in model.responses[question]) { phrase.Clear(); phrase.Add(answer.Key); options.AddCell(new Phrase(phrase)); phrase.Clear(); phrase.Add(answer.Value.ToString()); options.AddCell(new Phrase(phrase)); } PdfPCell full = new PdfPCell(options); full.Colspan = 2; table.AddCell(full); } } return table; } else { PdfPTable table = new PdfPTable(3 + model.selectedEntities.Count); table.WidthPercentage = 100; List<int> widthList = new List<int>(); widthList.Add(2); widthList.Add(15); widthList.Add(12); widthList.Add(6); for (int i = 0; i < model.selectedEntities.Count-1; i++) { widthList.Add(6); } table.SetWidths(widthList.ToArray()); Phrase phrase = new Phrase("#", font); BaseColor basecolor = new BaseColor(232, 238, 244); BaseColor heading = new BaseColor(232, 238, 0); heading.Darker(); heading.Darker(); if (model.selectedEntities.Count > 0) { Phrase entities = new Phrase("", new Font(FontFactory.GetFont("Verdana", 14))); int i = 0; if (model.selectedEntities.Count == 1) entities.Add("Entity: "); else entities.Add("Entities: "); foreach (Models.Entity ent in model.selectedEntities) { if (i == model.selectedEntities.Count - 1) entities.Add(ent.name); else entities.Add(ent.name + ", "); i++; } PdfPCell entityline = new PdfPCell(entities); entityline.BackgroundColor = heading; entityline.Colspan = 5; table.AddCell(entityline); } if (model.tick != null) { String line; if (model.include) line = "Include "; else line = "Exclude "; line += model.field.name + ", Values: "; foreach (string i in model.tick) line += i + ", "; line = line.Remove(line.Length - 2); PdfPCell demo = new PdfPCell(new Phrase(line + entity, font)); demo.BackgroundColor = heading; demo.Colspan = 5; table.AddCell(demo); } table.AddCell(new PdfPCell(new PdfPCell(new Phrase(phrase)) { BackgroundColor = basecolor })); phrase.Clear(); phrase.Add("Question"); table.AddCell(new PdfPCell(new PdfPCell(new Phrase(phrase)) { BackgroundColor = basecolor })); phrase.Clear(); phrase.Add("Answers"); table.AddCell(new PdfPCell(new PdfPCell(new Phrase(phrase)) { BackgroundColor = basecolor })); phrase.Clear(); foreach (var e in model.selectedEntities) { phrase.Add(e.name); table.AddCell(new PdfPCell(new PdfPCell(new Phrase(phrase)) { BackgroundColor = basecolor })); phrase.Clear(); } foreach (var question in model.questions) { if (question.deletionTime == null) { phrase.Clear(); phrase.Add(question.questionNumber.ToString()); table.AddCell(new Phrase(phrase)); phrase.Clear(); phrase.Add(question.question); table.AddCell(new Phrase(phrase)); PdfPTable options = new PdfPTable(1 + model.selectedEntities.Count); List<int> widthList2 = new List<int>(); widthList2.Add(4); widthList2.Add(2); for (int i = 0; i < model.selectedEntities.Count-1; i++) { widthList2.Add(2); } options.SetWidths(widthList2.ToArray()); foreach (var answer in model.filteredResponses[question]) { phrase.Clear(); phrase.Add(answer.Key); options.AddCell(new Phrase(phrase)); foreach (var e in model.selectedEntities) { phrase.Clear(); phrase.Add(answer.Value[e.entityID].ToString()); options.AddCell(new Phrase(phrase)); } } PdfPCell full = new PdfPCell(options); full.Colspan = model.selectedEntities.Count+1; table.AddCell(full); } } return table; } }