diff --git a/WebApplication5/Templates/TemplateGenerator.cs b/WebApplication5/Templates/TemplateGenerator.cs index b648949..19048ec 100644 --- a/WebApplication5/Templates/TemplateGenerator.cs +++ b/WebApplication5/Templates/TemplateGenerator.cs @@ -28,9 +28,11 @@ namespace WebApplication5.Templates var questions = new List(); foreach (var cat in _templatesOrder.Categories) { + var catQuestions = GetQuestionsForCategory(cat); + if (!catQuestions.Any()) + continue; writer.WriteCategory(_db.Categories.First(c => c.Id == cat.CategoryId).Name); - var catQuestions = GetQuestionsForCategory(cat); writer.WriteQuestions(catQuestions, questionNumber); questionNumber += catQuestions.Count; questions = questions.Concat(catQuestions) diff --git a/WebApplication5/Templates/Writer.cs b/WebApplication5/Templates/Writer.cs index 3ec7ffe..03d386e 100644 --- a/WebApplication5/Templates/Writer.cs +++ b/WebApplication5/Templates/Writer.cs @@ -38,7 +38,7 @@ namespace WebApplication5.Writer FontFactory.Register(ConfigurationManager.AppSettings["Fonts"]); titleFont = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED, 18, Font.BOLD); - catFont = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED, 16, Font.BOLD); + catFont = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED, 14, Font.BOLD); baseFont = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED, 12); var path = ConfigurationManager.AppSettings["TestsFolder"]; @@ -54,7 +54,7 @@ namespace WebApplication5.Writer } private void WriteQuestion(string question, int questionNumber) { - document.Add(new Paragraph(string.Format("{0}. {1}", questionNumber, question),baseFont)); + document.Add(new Paragraph(string.Format("{0}. {1}", questionNumber, question), baseFont)); } private string FormatAnswer(int letter, string answer) { @@ -63,12 +63,13 @@ namespace WebApplication5.Writer private void WriteAnswers(List answers) { PdfPTable table = new PdfPTable(2); - + table.SpacingAfter = 10; + table.SpacingBefore = 5; table.WidthPercentage = 90; table.DefaultCell.Border = 0; for (int i = 0; i < answers.Count; i++) { - table.AddCell(new Phrase(FormatAnswer(i, answers.ElementAt(i).AnswerText),baseFont)); + table.AddCell(new Phrase(FormatAnswer(i, answers.ElementAt(i).AnswerText), baseFont)); } if (answers.Count % 2 == 1) @@ -135,7 +136,7 @@ namespace WebApplication5.Writer EndPage(); } - private PdfPTable CreateAnswersTable(List questions, int moved, bool isEven = false) + private PdfPTable CreateAnswersTable(List questions, int moved, bool isEven = true) { var maxWidth = questions.Max(t => t.Answers.Count) + 1; var table = new PdfPTable(maxWidth); @@ -168,14 +169,14 @@ namespace WebApplication5.Writer for (int i = 0; i < questions.Count; i++) { var ansCount = 1; - var numberCell = new PdfPCell(new Phrase(string.Format("{0}.", i + 1 + moved))); + var numberCell = new PdfPCell(new Phrase(string.Format("{0}.", i + 1 + moved), baseFont)); numberCell.Border = 0; numberCell.HorizontalAlignment = Element.ALIGN_RIGHT; table.AddCell(numberCell); foreach (var a in questions.ElementAt(i).Answers) { - var answerCell = new PdfPCell(new Phrase(" ")); + var answerCell = new PdfPCell(new Phrase(" ", baseFont)); answerCell.Border = 15; table.AddCell(answerCell); ansCount++; @@ -192,7 +193,7 @@ namespace WebApplication5.Writer { for (int j = 0; j < maxWidth; j++) { - var emptyAnswerCell = new PdfPCell(new Phrase(" ")); + var emptyAnswerCell = new PdfPCell(new Phrase(" ", baseFont)); emptyAnswerCell.Border = 0; table.AddCell(emptyAnswerCell); } diff --git a/WebApplication5/Views/CRUD/AllForTemplate.cshtml b/WebApplication5/Views/CRUD/AllForTemplate.cshtml index 07f5247..affe9a0 100644 --- a/WebApplication5/Views/CRUD/AllForTemplate.cshtml +++ b/WebApplication5/Views/CRUD/AllForTemplate.cshtml @@ -1,7 +1,7 @@ @using WebApplication5.Models @model List @{ - ViewBag.Title = "Kategorie"; + ViewBag.Title = "Generacja testu"; }

@ViewBag.Title