tarballform

This commit is contained in:
misya 2025-03-28 10:29:59 +08:00
parent 3d6647b87d
commit 2c7ee5aca9
4 changed files with 281 additions and 1 deletions

View File

@ -2,9 +2,13 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PSTW_CentralSystem.Areas.MMS; using PSTW_CentralSystem.Areas.MMS;
using QuestPDF.Fluent;
namespace PSTW_CentralSystem.Areas.MMS.Controllers namespace PSTW_CentralSystem.Areas.MMS.Controllers
{ {
[Area("MMS")]
//[Authorize(Policy = "RoleModulePolicy")]
public class MarineController : Controller public class MarineController : Controller
{ {
public IActionResult Index() public IActionResult Index()
@ -15,5 +19,21 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
{ {
return View(); return View();
} }
// Generates and returns a Tar Ball Sampling Report PDF
public IActionResult GenerateReport()
{
try
{
var document = new TarBallPDF();
var pdf = document.GeneratePdf();
return File(pdf, "application/pdf", "TarBallReport.pdf");
}
catch (Exception ex)
{
// Log the error (use a logger if configured)
Console.WriteLine(ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while generating the PDF.");
}
}
} }
} }

View File

@ -0,0 +1,81 @@
using Microsoft.AspNetCore.Mvc;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
public class TarBallPDF : IDocument
{
public DocumentMetadata GetMetadata() => DocumentMetadata.Default;
public void Compose(IDocumentContainer container)
{
try
{
container.Page(page =>
{
// Page Setup
page.Size(PageSizes.A4);
page.Margin(2, Unit.Centimetre);
page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(12));
// Header Section
page.Header().Column(column =>
{
column.Spacing(10);
// Logo and Title
column.Item().AlignCenter().Text("Company Logo Placeholder").FontSize(12).Italic();
// Document Details
column.Item().Text("Document: F-MM06").FontSize(14);
column.Item().Text("Effective Date: 1 April 2025").FontSize(14);
column.Item().Text("Revision No.: 02").FontSize(14);
});
// Content Section
page.Content().Column(column =>
{
column.Spacing(20);
// Table Section
column.Item().Table(table =>
{
table.ColumnsDefinition(columns =>
{
columns.RelativeColumn(1); // Column 1
columns.RelativeColumn(2); // Column 2
});
table.Cell().Text("STATE").Bold();
table.Cell().Text("Your State Data Here");
table.Cell().Text("STATION ID").Bold();
table.Cell().Text("Your Station ID Here");
});
// Survey Findings Section
column.Item().Text("SURVEY FINDING").Bold().FontSize(14);
column.Item().Text("Tar Ball ☐ Yes ☐ No");
column.Item().Text("If YES, Tar Ball falls under the classification of:");
column.Item().Text("☐ Sand ☐ Non-sandy ☐ Coquina");
});
// Footer Section
page.Footer().AlignCenter().Text(x =>
{
x.Span("Page ");
x.CurrentPageNumber();
x.Span(" of ");
x.TotalPages();
});
});
}
catch (Exception ex)
{
// Log the exception (you can use any logging framework or method you prefer)
Console.WriteLine($"Error generating PDF: {ex.Message}");
}
}
}
;

View File

@ -2,4 +2,178 @@
ViewData["Title"] = "Tar Ball Sampling Form"; ViewData["Title"] = "Tar Ball Sampling Form";
Layout = "~/Views/Shared/_Layout.cshtml"; Layout = "~/Views/Shared/_Layout.cshtml";
} }
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
<h3>Tarball Sampling Form</h3>
</title>
<style>
div {
padding-top:10px;
padding-bottom:10px:
}
.container {
width: 1200px; /* Approximate width for A4 aspect ratio */
margin: 20px auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
overflow: hidden;
.details-cell
}
.form-header {
display: table;
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
.form-header th, .form-header td {
border: 1px solid #ccc;
padding: 10px;
text-align: center;
}
.logo-cell {
width: 40%;
text-align: center;
vertical-align: middle;
}
.logo-cell img {
max-width: 20%; /*limit the cell's width*/
height: auto;
}
.title-cell {
width: 40%;
vertical-align: middle;
font-size: 14px;
}
.details-cell {
width: 10%;
text-align: left;
font-size: 14px;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
text-align: center;
}
td {
background-color: #fff;
}
</style>
</head>
<body>
<div>
<a href="/MMS/Marine/GenerateReport" class="btn btn-primary">Download PDF</a>
</div>
<div class="container">
<table class="form-header">
<tr>
<td class="logo-cell" rowspan="4">
<!-- Replace with company logo -->
<img src="company-logo.png" alt="Company Logo">
</td>
<td class="details-cell" rowspan="4">
<h3>TARBALL SAMPLING FORM</h3>
</td>
</tr>
<tr>
<td class="details-cell">Document: </td>
<td class="details-cell"><strong>F-MM06</strong></td>
</tr>
<tr>
<td class="details-cell">Effective Date: </td>
<td class="details-cell"><strong>1 April 2025</strong></td>
</tr>
<tr>
<td class="details-cell">Revision No.: </td>
<td class="details-cell"><strong>02</strong></td>
</tr>
</table>
<div>
<!-- -->
<p>Please be informed that we have observed the following conditions:</p>
</div>
<div>
<table>
<tr>
<td>
<p>STATE</p>
</td>
<td>
<p></p>
</td>
</tr>
<tr>
<td>
<p>STATION ID</p>
</td>
<td>
<p></p>
</td>
</tr>
<tr>
<td>
<p>LOCATION</p>
</td>
<td>
<p></p>
</td>
</tr>
<tr>
<td>
<p>TARBALL SURVEY LOCATION LONGITUDE & LATITUDE </p>
</td>
<td>
<p></p>
</td>
</tr>
<tr>
<td>
<p>DATE / TIME</p>
</td>
<td>
<p></p>
</td>
</tr>
</table>
</div>
<form>
<p><strong>SURVEY FINDING:</strong></p>
<p>Tar Ball</p>
<input type="radio" id="yes" name="tarball" value="yes">
<label for="yes">YES</label>
<input type="radio" id="no" name="tarball" value="no">
<label for="no">NO</label>
<br><br>
<p>If YES, Tar Ball falls under the Classification of:</p>
<input type="checkbox" id="sand" name="classification" value="sand">
<label for="sand">Sand</label>
<input type="checkbox" id="non-sandy" name="classification" value="non-sandy">
<label for="non-sandy">Non-sandy</label>
<input type="checkbox" id="coquina" name="classification" value="coquina">
<label for="coquina">Coquina</label>
<br><br>
<p><em>*Tick wherever applicable</em></p>
</form>
</div> <!--A4 CONTAINER-->
</body>
</html>

View File

@ -22,13 +22,18 @@
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="PDFsharp" Version="6.1.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageReference Include="QuestPDF" Version="2025.1.7" />
<PackageReference Include="QuestPDF.HTML" Version="1.4.2" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" /> <PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="System.Drawing.Common" Version="9.0.3" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.3" />
<PackageReference Include="Verify.QuestPDF" Version="2.3.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Areas\JSA\Models\" /> <Folder Include="Areas\JSA\Models\" />
<Folder Include="Areas\MMS\Models\" />
<Folder Include="Areas\JSA\Views\" /> <Folder Include="Areas\JSA\Views\" />
<Folder Include="Areas\Report\Models\" /> <Folder Include="Areas\Report\Models\" />
<Folder Include="Logs\" /> <Folder Include="Logs\" />