2021-01-16 01:31:39 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using QuestPDF.Helpers;
|
|
|
|
|
|
|
|
|
|
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(),
|
|
|
|
|
|
2021-04-20 12:55:07 +02:00
|
|
|
LogoData = Helpers.GetImage("Logo.png"),
|
2021-08-27 11:40:33 +02:00
|
|
|
Sections = Enumerable.Range(0, 40).Select(x => GenerateSection()).ToList(),
|
|
|
|
|
Photos = Enumerable.Range(0, 25).Select(x => GetReportPhotos()).ToList()
|
2021-01-16 01:31:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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")
|
2021-04-20 12:55:07 +02:00
|
|
|
},
|
|
|
|
|
new ReportHeaderField()
|
|
|
|
|
{
|
|
|
|
|
Label = "Status",
|
|
|
|
|
Value = "Completed, found 2 issues"
|
2021-01-16 01:31:39 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReportSection GenerateSection()
|
|
|
|
|
{
|
|
|
|
|
var sectionLength = Helpers.Random.NextDouble() > 0.75
|
2021-05-03 13:32:46 +02:00
|
|
|
? Helpers.Random.Next(20, 40)
|
|
|
|
|
: Helpers.Random.Next(5, 10);
|
2021-01-16 01:31:39 +01:00
|
|
|
|
|
|
|
|
return new ReportSection
|
|
|
|
|
{
|
2021-04-18 23:11:29 +02:00
|
|
|
Title = Placeholders.Label(),
|
2021-01-16 01:31:39 +01:00
|
|
|
Parts = Enumerable.Range(0, sectionLength).Select(x => GetRandomElement()).ToList()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReportSectionElement GetRandomElement()
|
|
|
|
|
{
|
|
|
|
|
var random = Helpers.Random.NextDouble();
|
|
|
|
|
|
2021-04-20 12:55:07 +02:00
|
|
|
if (random < 0.9f)
|
2021-01-16 01:31:39 +01:00
|
|
|
return GetTextElement();
|
|
|
|
|
|
2021-04-20 12:55:07 +02:00
|
|
|
if (random < 0.95f)
|
2021-01-16 01:31:39 +01:00
|
|
|
return GetMapElement();
|
|
|
|
|
|
|
|
|
|
return GetPhotosElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReportSectionText GetTextElement()
|
|
|
|
|
{
|
|
|
|
|
return new ReportSectionText
|
|
|
|
|
{
|
2021-04-18 23:11:29 +02:00
|
|
|
Label = Placeholders.Label(),
|
|
|
|
|
Text = Placeholders.Paragraph()
|
2021-01-16 01:31:39 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReportSectionMap GetMapElement()
|
|
|
|
|
{
|
|
|
|
|
return new ReportSectionMap
|
|
|
|
|
{
|
|
|
|
|
Label = "Location",
|
2021-04-20 12:55:07 +02:00
|
|
|
ImageSource = Placeholders.Image,
|
2021-01-16 01:31:39 +01:00
|
|
|
Location = Helpers.RandomLocation()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReportSectionPhotos GetPhotosElement()
|
|
|
|
|
{
|
|
|
|
|
return new ReportSectionPhotos
|
|
|
|
|
{
|
|
|
|
|
Label = "Photos",
|
|
|
|
|
Photos = Enumerable
|
2021-05-03 13:32:46 +02:00
|
|
|
.Range(0, Helpers.Random.Next(1, 15))
|
2021-04-20 12:55:07 +02:00
|
|
|
.Select(x => Placeholders.Image(400, 300))
|
2021-01-16 01:31:39 +01:00
|
|
|
.ToList()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReportPhoto GetReportPhotos()
|
|
|
|
|
{
|
|
|
|
|
return new ReportPhoto()
|
|
|
|
|
{
|
2021-05-03 13:32:46 +02:00
|
|
|
PhotoData = Placeholders.Image(800, 600),
|
2021-01-16 01:31:39 +01:00
|
|
|
|
2021-04-20 12:55:07 +02:00
|
|
|
Comments = Placeholders.Sentence(),
|
2021-01-16 01:31:39 +01:00
|
|
|
Date = DateTime.Now - TimeSpan.FromDays(Helpers.Random.NextDouble() * 100),
|
|
|
|
|
Location = Helpers.RandomLocation(),
|
|
|
|
|
|
2021-04-20 12:55:07 +02:00
|
|
|
MapContextSource = x => Placeholders.Image(400, 300),
|
|
|
|
|
MapDetailsSource = x => Placeholders.Image(400, 300)
|
2021-01-16 01:31:39 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|