Files

113 lines
3.5 KiB
C#
Raw Permalink Normal View History

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 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
? Helpers.Random.Next(20, 40)
: Helpers.Random.Next(5, 10);
2021-01-16 01:31:39 +01:00
return new ReportSection
{
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
{
Label = Placeholders.Label(),
Text = Placeholders.Paragraph()
2021-01-16 01:31:39 +01:00
};
}
ReportSectionMap GetMapElement()
{
return new ReportSectionMap
{
Label = "Location",
Location = Helpers.RandomLocation()
};
}
ReportSectionPhotos GetPhotosElement()
{
return new ReportSectionPhotos
{
Label = "Photos",
2021-11-04 01:02:44 +01:00
PhotoCount = Helpers.Random.Next(1, 15)
2021-01-16 01:31:39 +01:00
};
}
ReportPhoto GetReportPhotos()
{
return new ReportPhoto()
{
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),
2021-11-04 01:02:44 +01:00
Location = Helpers.RandomLocation()
2021-01-16 01:31:39 +01:00
};
}
}
}
}