From 2c7ee5aca96b617f8b7b235e98cf5bf26b9205b2 Mon Sep 17 00:00:00 2001 From: misya Date: Fri, 28 Mar 2025 10:29:59 +0800 Subject: [PATCH] tarballform --- Areas/MMS/Controllers/MarineController.cs | 20 +++ Areas/MMS/Models/PDFGenerator/TarBallPDF.cs | 81 +++++++++ Areas/MMS/Views/Marine/TarBallForm.cshtml | 174 ++++++++++++++++++++ PSTW_CentralSystem.csproj | 7 +- 4 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 Areas/MMS/Models/PDFGenerator/TarBallPDF.cs diff --git a/Areas/MMS/Controllers/MarineController.cs b/Areas/MMS/Controllers/MarineController.cs index 1f15d13..0021d97 100644 --- a/Areas/MMS/Controllers/MarineController.cs +++ b/Areas/MMS/Controllers/MarineController.cs @@ -2,9 +2,13 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using PSTW_CentralSystem.Areas.MMS; +using QuestPDF.Fluent; namespace PSTW_CentralSystem.Areas.MMS.Controllers { + [Area("MMS")] + + //[Authorize(Policy = "RoleModulePolicy")] public class MarineController : Controller { public IActionResult Index() @@ -15,5 +19,21 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers { 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."); + } + } } } diff --git a/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs b/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs new file mode 100644 index 0000000..ad1aa45 --- /dev/null +++ b/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs @@ -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}"); + } + } +} +; + diff --git a/Areas/MMS/Views/Marine/TarBallForm.cshtml b/Areas/MMS/Views/Marine/TarBallForm.cshtml index 9ddf96d..201f2d7 100644 --- a/Areas/MMS/Views/Marine/TarBallForm.cshtml +++ b/Areas/MMS/Views/Marine/TarBallForm.cshtml @@ -2,4 +2,178 @@ ViewData["Title"] = "Tar Ball Sampling Form"; Layout = "~/Views/Shared/_Layout.cshtml"; } + + + + + + + <h3>Tarball Sampling Form</h3> + + + + +
+ Download PDF +
+
+ + + + + + + + + + + + + + + + + +
+ + Company Logo + +

TARBALL SAMPLING FORM

+
Document: F-MM06
Effective Date: 1 April 2025
Revision No.: 02
+
+ +

Please be informed that we have observed the following conditions:

+
+
+ + + + + + + + + + + + + + + + + + + + + +
+

STATE

+
+

+
+

STATION ID

+
+

+
+

LOCATION

+
+

+
+

TARBALL SURVEY LOCATION LONGITUDE & LATITUDE

+
+

+
+

DATE / TIME

+
+

+
+
+
+

SURVEY FINDING:

+

Tar Ball

+ + + + +

+

If YES, Tar Ball falls under the Classification of:

+ + + + + + +

+

*Tick wherever applicable

+
+ +
+ + \ No newline at end of file diff --git a/PSTW_CentralSystem.csproj b/PSTW_CentralSystem.csproj index 29c6e4b..85e3d6f 100644 --- a/PSTW_CentralSystem.csproj +++ b/PSTW_CentralSystem.csproj @@ -22,13 +22,18 @@ + + + + + + -