| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using QuestPDF.Helpers;
- using QuestPDF.ReportSample.Layouts;
- namespace QuestPDF.ReportSample
- {
- public static class DataSource
- {
- public static int SectionCounter { get; set; }
- public static int FieldCounter { get; set; }
-
- public static ReportModel GetReport()
- {
- return new ReportModel
- {
- Title = "Sample Report Document",
- HeaderFields = HeaderFields(),
-
- LogoData = Helpers.GetImage("logo.png"),
- Sections = Enumerable.Range(0, 10).Select(x => GenerateSection()).ToList(),
- Photos = Enumerable.Range(0, 10).Select(x => GetReportPhotos()).ToList()
- };
- List<ReportHeaderField> HeaderFields()
- {
- return new List<ReportHeaderField>
- {
- new ReportHeaderField()
- {
- Label = "Scope",
- Value = "Internal activities"
- },
- new ReportHeaderField()
- {
- Label = "Author",
- Value = "Marcin Ziąbek"
- },
- new ReportHeaderField()
- {
- Label = "Date",
- Value = DateTime.Now.ToString("g")
- }
- };
- }
-
- ReportSection GenerateSection()
- {
- var sectionLength = Helpers.Random.NextDouble() > 0.75
- ? Helpers.Random.Next(10, 20)
- : Helpers.Random.Next(3, 11);
-
- return new ReportSection
- {
- Title = TextPlaceholder.Label(),
- Parts = Enumerable.Range(0, sectionLength).Select(x => GetRandomElement()).ToList()
- };
- }
- ReportSectionElement GetRandomElement()
- {
- var random = Helpers.Random.NextDouble();
- if (random < 0.8f)
- return GetTextElement();
-
- if (random < 0.9f)
- return GetMapElement();
-
- return GetPhotosElement();
- }
-
- ReportSectionText GetTextElement()
- {
- return new ReportSectionText
- {
- Label = TextPlaceholder.Label(),
- Text = TextPlaceholder.Paragraph()
- };
- }
-
- ReportSectionMap GetMapElement()
- {
- var rnd = Helpers.Random.Next(0, 64);
-
- return new ReportSectionMap
- {
- Label = "Location",
- ImageSource = x => Helpers.GetDocumentMap($"{rnd}.jpg"),
- Location = Helpers.RandomLocation()
- };
- }
-
- ReportSectionPhotos GetPhotosElement()
- {
- return new ReportSectionPhotos
- {
- Label = "Photos",
- Photos = Enumerable
- .Range(0, Helpers.Random.Next(1, 10))
- .Select(x => Helpers.Random.Next(0, 128))
- .Select(x => Helpers.GetPhoto($"{x}.jpg"))
- .ToList()
- };
- }
- ReportPhoto GetReportPhotos()
- {
- var photoId = Helpers.Random.Next(0, 128);
- var mapId = Helpers.Random.Next(0, 64);
- return new ReportPhoto()
- {
- PhotoData = Helpers.GetPhoto($"{photoId}.jpg"),
- Comments = TextPlaceholder.Paragraph(),
- Date = DateTime.Now - TimeSpan.FromDays(Helpers.Random.NextDouble() * 100),
- Location = Helpers.RandomLocation(),
- MapContextSource = x => Helpers.GetContextMap($"{mapId}.jpg"),
- MapDetailsSource = x => Helpers.GetDetailsMap($"{mapId}.jpg")
- };
- }
- }
- }
- }
|