Small fixes

This commit is contained in:
Jan Zubrycki 2020-06-20 02:56:51 +02:00
parent e9310434ac
commit ff5c722703
3 changed files with 13 additions and 10 deletions

View File

@ -28,9 +28,11 @@ namespace WebApplication5.Templates
var questions = new List<Question>();
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)

View File

@ -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<Answer> 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<Question> questions, int moved, bool isEven = false)
private PdfPTable CreateAnswersTable(List<Question> 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);
}

View File

@ -1,7 +1,7 @@
@using WebApplication5.Models
@model List<CategoryViewModel>
@{
ViewBag.Title = "Kategorie";
ViewBag.Title = "Generacja testu";
}
<h2>@ViewBag.Title</h2>