Files
QuestPDF/QuestPDF.ReportSample/Layouts/SectionTemplate.cs
T

88 lines
2.9 KiB
C#
Raw Normal View History

2021-11-04 01:02:44 +01:00
using System.Linq;
2021-01-16 01:31:39 +01:00
using QuestPDF.Fluent;
using QuestPDF.Helpers;
2021-01-16 01:31:39 +01:00
using QuestPDF.Infrastructure;
namespace QuestPDF.ReportSample.Layouts
{
public class SectionTemplate : IComponent
{
public ReportSection Model { get; set; }
public SectionTemplate(ReportSection model)
{
Model = model;
}
public void Compose(IContainer container)
{
container
.EnsureSpace()
.Decoration(decoration =>
2021-01-16 01:31:39 +01:00
{
decoration
2021-01-16 01:31:39 +01:00
.Header()
.PaddingBottom(5)
.Text(Model.Title, Typography.Headline);
decoration.Content().Border(0.75f).BorderColor(Colors.Grey.Medium).Stack(stack =>
2021-01-16 01:31:39 +01:00
{
foreach (var part in Model.Parts)
{
2021-08-27 11:40:33 +02:00
stack.Item().EnsureSpace(25).Row(row =>
2021-01-16 01:31:39 +01:00
{
row.ConstantColumn(150).LabelCell().Text(part.Label);
var frame = row.RelativeColumn().ValueCell();
2021-01-16 01:31:39 +01:00
if (part is ReportSectionText text)
frame.ShowEntire().Text(text.Text);
2021-01-16 01:31:39 +01:00
if (part is ReportSectionMap map)
frame.Element(x => MapElement(x, map));
2021-01-16 01:31:39 +01:00
if (part is ReportSectionPhotos photos)
frame.Element(x => PhotosElement(x, photos));
2021-01-16 01:31:39 +01:00
});
}
});
});
}
void MapElement(IContainer container, ReportSectionMap model)
{
2021-11-04 01:02:44 +01:00
if (model.Location == null)
2021-01-16 01:31:39 +01:00
{
container.Text("No location provided");
2021-01-16 01:31:39 +01:00
return;
}
container.ShowEntire().Stack(stack =>
2021-01-16 01:31:39 +01:00
{
stack.Spacing(5);
stack.Item().MaxWidth(250).AspectRatio(4 / 3f).Component<ImagePlaceholder>();
stack.Item().Text(model.Location.Format());
2021-01-16 01:31:39 +01:00
});
}
void PhotosElement(IContainer container, ReportSectionPhotos model)
{
2021-11-04 01:02:44 +01:00
if (model.PhotoCount == 0)
2021-01-16 01:31:39 +01:00
{
container.Text("No photos", Typography.Normal);
return;
}
2021-11-04 01:02:44 +01:00
container.DebugArea("Photos").Grid(grid =>
2021-01-16 01:31:39 +01:00
{
grid.Spacing(5);
grid.Columns(3);
2021-11-04 01:02:44 +01:00
Enumerable
.Range(0, model.PhotoCount)
.ToList()
.ForEach(x => grid.Item().AspectRatio(4 / 3f).Component<ImagePlaceholder>());
2021-01-16 01:31:39 +01:00
});
}
}
}