EvaluationResults.cs 7.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using iText.Kernel.Colors;
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Element;
using iText.Layout.Properties;
using PDFGenerator.Models;
using PDFGenerator.Utilities;
using System.Collections.Generic;
using static PDFGenerator.Utilities.Globals;

namespace PDFGenerator.EvaluationReport
{
    public class EvaluationResults : BaseSection
    {
        private PDFEvaluationResults Results { get; }
        public Dictionary<string, byte[]> CustomUploads { get; private set; }

        public EvaluationResults(PDFEvaluationResults results, Document document, Bookmarks bookmarks, TableOfContents tableOfContents)
        : base(document, bookmarks, tableOfContents)
        {
            Results = results;
            CustomUploads = new Dictionary<string, byte[]>();
        }

        /// <summary>
        /// Renders the content regarding the assessment of criterion targets and KPIs.
        /// </summary>
        public override void Render()
        {
            Document = Document;
            Results.Pillars.ForEach(pillar => RenderPillar(pillar));
        }

        /// <summary>
        /// Adds pillar information to document and goes through all its quality targets.
        /// </summary>
37
        /// <param name="pillar">input pillar</param>
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
        private void RenderPillar(Pillar pillar)
        {
            Bookmarks.AddRootOutline(pillar.Heading, RootOutline);

            TocItem tocItem = new TocItem
            {
                Title = pillar.Heading,
                Indent = Results.Sections[pillar.Heading],
                Page = GetCurrentPage()
            };
            TableOfContents.AddToTOC(tocItem);

            Paragraph p = new Paragraph(new Text(pillar.Heading).AddStyle(Styles.H1)).SetDestination(pillar.Heading);
            Document.Add(p);

            pillar.QualityTargets.ForEach(qualitytarget => RenderQualityTarget(qualitytarget));
        }

        /// <summary>
        /// Adds quality target information to document and goes through all its criteria.
        /// </summary>
59
        /// <param name="qualityTarget">input quality target</param>
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
        private void RenderQualityTarget(QualityTarget qualityTarget)
        {
            string section = qualityTarget.Paragraphs[0];
            string description = qualityTarget.Paragraphs[1];

            Bookmarks.AddOutline(section, OutlineLevel.Level1);

            TocItem tocItem = new TocItem
            {
                Title = section,
                Indent = Results.Sections[section],
                Page = GetCurrentPage()
            };
            TableOfContents.AddToTOC(tocItem);

            Style style = Styles.H3;
            style.SetFontColor(ColorConstants.WHITE);

            Paragraph p = new Paragraph(new Text(section).AddStyle(style)).SetDestination(section)
            .SetMultipliedLeading(0.85f);

            style = Styles.Paragraph.SetItalic();
            style.SetFontColor(ColorConstants.WHITE);
            p.Add(NewLine).Add(new Text(description).AddStyle(style));

            Document.Add(Panel.GetPanel(p, new DeviceRgb(64, 127, 183)));

            qualityTarget.Criterions.ForEach(criterion => RenderCriterion(criterion));
        }

        /// <summary>
        /// Adds criterion information to document and goes through all its kpi evaluations.
        /// </summary>
93
        /// <param name="criterion">input criterion</param>
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
        private void RenderCriterion(Criterion criterion)
        {
            new CriterionTarget(criterion.CriterionTarget, Results.Sections[criterion.CriterionTarget.Paragraphs[0]], CustomUploads,
                Document, Bookmarks, TableOfContents)
            .Render();

            criterion.KpiEvaluations.ForEach(kpiEvaluation => new KpiEvaluation(kpiEvaluation, CustomUploads, Document, Bookmarks, TableOfContents)
            .Render());

            AddMeasureSection(criterion.MeasureTable);

            AddPageBreak();
        }

        /// <summary>
        /// Adds a table for listing measures as part of the criterion information
        /// </summary>
        /// <param name="measureTable">holds the information of each measure</param>
        private void AddMeasureSection(MeasureTable measureTable)
        {
            Table table = new Table(UnitValue.CreatePercentArray(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f }), false)
                        .UseAllAvailableWidth().SetKeepTogether(false).SetMarginTop(4f).SetMarginBottom(10f);


            // only show header if there are measures or some other content
            string header = measureTable.Paragraphs[0];
            if (measureTable.Paragraphs.Count == 1 && measureTable.Measures.Count == 0)
            {
                return;
            }

            table.AddCell(
                new Cell(1, 10).Add(new Paragraph(new Text(header).AddStyle(Styles.H4)))
                .SetBorder(Border.NO_BORDER).SetPaddingBottom(5f)
            );

            measureTable.Measures.ForEach(measure =>
            {
                //first row
                table.AddCell(new Cell().Add(new Paragraph(new Text("Kriterium/ Kennzahl").AddStyle(Styles.SmallBold)).SetMultipliedLeading(1f)).SetPaddingBottom(0));
                table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text("Studiengang").AddStyle(Styles.SmallBold))).SetVerticalAlignment(VerticalAlignment.MIDDLE).SetPaddingBottom(0));
                table.AddCell(new Cell().Add(new Paragraph(new Text("Fristigkeit").AddStyle(Styles.SmallBold))).SetVerticalAlignment(VerticalAlignment.MIDDLE).SetPaddingBottom(0));
                table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text("Zuständigkeit").AddStyle(Styles.SmallBold))).SetVerticalAlignment(VerticalAlignment.MIDDLE).SetPaddingBottom(0));

                //spans rows 2-4 
                table.AddCell(new Cell(3, 1).Add(new Paragraph(new Text(measure.FullId).AddStyle(Styles.Small)).SetMultipliedLeading(1f)).SetPaddingBottom(0));

                //second row
                table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text(measure.CourseName).AddStyle(Styles.Small)).SetMultipliedLeading(0.9f)).SetPaddingBottom(0));
                table.AddCell(new Cell().Add(new Paragraph(new Text(measure.Maturity).AddStyle(Styles.Small)).SetMultipliedLeading(0.9f)).SetPaddingBottom(0));
                table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text(measure.Responsibilities).AddStyle(Styles.Small)).SetMultipliedLeading(0.9f)).SetPaddingBottom(0));

                //third row
                table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text("Maßnahme").AddStyle(Styles.SmallBold)).SetMultipliedLeading(1f)).SetPaddingBottom(0));
                table.AddCell(new Cell(1, 5).Add(new Paragraph(new Text("Kommentar").AddStyle(Styles.SmallBold)).SetMultipliedLeading(1f)).SetPaddingBottom(0));

                //fourth row
                table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text(measure.Description).AddStyle(Styles.Small)).SetMultipliedLeading(0.9f)).SetPaddingBottom(0));
                table.AddCell(new Cell(1, 5).Add(new Paragraph(new Text(measure.Comments).AddStyle(Styles.Small)).SetMultipliedLeading(0.9f)).SetPaddingBottom(0));
            });

            // message for non-available measures, if available
            if (measureTable.Measures.Count == 0 && measureTable.Paragraphs.Count > 1)
            {
                table.AddCell(
                    new Cell(1, 10).Add(new Paragraph(new Text(measureTable.Paragraphs[1]).AddStyle(Styles.Paragraph)))
                    .SetBorder(Border.NO_BORDER)
                );
            }

            Document.Add(table);
        }
    }
}