예제 #1
0
        private int AddPage(PdfDocument document, RapportageRepository repo, Account account, int jobId, List <Vraag> questions, int latestQuestion)
        {
            PdfPage        page         = document.AddPage();
            XGraphics      gfx          = XGraphics.FromPdfPage(page);
            XTextFormatter txtFormatter = new XTextFormatter(gfx);

            // Fonts
            XFont normalFont = new XFont("Arial", 14, XFontStyle.Regular);
            XFont boldFont   = new XFont("Arial", 14, XFontStyle.Bold);
            XFont titleFont  = new XFont("Arial", 20, XFontStyle.Bold);
            XFont italicFont = new XFont("Arial", 14, XFontStyle.Italic);

            // Inspecteur
            txtFormatter.DrawString($"Inspecteur: {account.Voornaam} {account.Tussenvoegsel} {account.Achternaam}", titleFont, XBrushes.Black, new XRect(20, 20, page.Width, page.Height), XStringFormats.TopLeft);

            // Vragen
            int currentY = 60;

            int currentQuestion = latestQuestion;
            int sizeLeft        = 2000;

            while ((currentQuestion < questions.Count && sizeLeft > 200))
            {
                Vraag question = questions[currentQuestion];

                int textHeight = txtFormatter.DrawString($"Vraag {currentQuestion + 1}: {question.Vraagstelling}", boldFont, XBrushes.Black, new XRect(20, currentY, page.Width, page.Height), XStringFormats.TopLeft);

                currentY += textHeight;

                List <Antwoorden> answers = question.Antwoorden.Where(x => x.InspecteurID == account.AccountID).ToList();

                switch (question.Vraagtype)
                {
                case "tv":
                    currentY = DrawTableQuestionAnswer(gfx, page, answers, question.VraagMogelijkAntwoord.Count, italicFont, currentY);

                    break;

                case "av":
                    currentY = DrawImageQuestionAnswer(gfx, page, answers, currentY);

                    break;

                default:
                    currentY = DrawQuestionAnswer(txtFormatter, page, answers, italicFont, currentY);
                    break;
                }

                sizeLeft -= currentY;
                currentQuestion++;
            }

            return(currentQuestion);
        }
예제 #2
0
        public void ExportQuestion(PdfDocument document, RapportageRepository repo, int jobId)
        {
            foreach (Account account in repo.GetInspectorsWithFilledAnswers())
            {
                List <Vraag> questions = repo.GetQuestionsFromInspector(account.AccountID, jobId);

                int questionAmount = questions.Count;
                int latestQuestion = 0;

                while (questionAmount != latestQuestion)
                {
                    latestQuestion = AddPage(document, repo, account, jobId, questions, latestQuestion);
                }
            }
        }