This commit is contained in:
misya 2025-06-20 16:23:27 +08:00
parent c857468d91
commit 6ad2f11e9e
3 changed files with 27 additions and 22 deletions

View File

@ -1,20 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using PSTW_CentralSystem.DBContext;
using PSTW_CentralSystem.Areas.MMS.Models;
using System.IO;
using System.Linq;
//using PSTW_CentralSystem.Areas.MMS.Models;
//using System.IO;
//using System.Linq;
using PSTW_CentralSystem.Areas.MMS.Models.PDFGenerator;
using QuestPDF.Fluent;
using System.Threading.Tasks;
using System.Threading;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
//using System.Threading.Tasks;
//using System.Threading;
//using System.Collections.Generic;
//using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using MySqlConnector;
namespace PSTW_CentralSystem.Areas.MMS.Controllers
{
public class TarballPdfDto
public class TarballPdfDto //data transfer object, only holds data, used to move data between programs
{
// From tbl_marine_tarball
public int Id { get; set; }
@ -55,11 +55,11 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
return View();
}
public IActionResult TarBallForm()
public async Task<IActionResult> TarBallForm()//make it async in case of traffic/frequent usage
{
try
{
var marineTarballs = _context.MarineTarballs
var marineTarballs = await _context.MarineTarballs
.Select(t => new
{
id = t.Id,
@ -67,9 +67,9 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
station = t.StationID,
time = t.TimeSample.ToString("hh\\:mm\\:ss")
})
.ToList();
.ToListAsync();
Console.WriteLine($"Marine Tarballs Count: {marineTarballs.Count}");
Console.WriteLine($"Marine Tarballs Count: {marineTarballs.Count}"); //???
return View(marineTarballs);
}
catch (Exception ex)
@ -79,6 +79,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
}
[HttpGet] // Explicitly mark as a GET endpoint
//removal TBD===============!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
public IActionResult TestCredentials()
{
try
@ -102,6 +103,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
return StatusCode(500, $"Credentials test failed: {ex.Message}");
}
}
//====================!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
public IActionResult GetImage(string fileName)
{
@ -156,6 +158,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
Console.WriteLine($"Attempting to access image at: {imagePath}");
// Verify file exists
//removal TBD
if (!System.IO.File.Exists(imagePath))
{
Console.WriteLine($"Image not found at path: {imagePath}");
@ -163,6 +166,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
}
// Verify file is an image
//consider removal if/since verification already happened during image uploading (other program)
if (!IsImageValid(imagePath))
{
Console.WriteLine($"Invalid image file at path: {imagePath}");
@ -174,6 +178,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
Console.WriteLine($"Successfully read image: {sanitizedFileName} ({imageBytes.Length} bytes)");
// Determine content type based on extension
//removal TBD??? IF image type verification already done during image uploading =========!!!!!!!!!!!
string contentType = "image/jpeg"; // default
string extension = Path.GetExtension(sanitizedFileName).ToLower();
//string extension = Path.GetExtension(sanitizedFileName)?.ToLower();
@ -227,11 +232,10 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
return await GeneratePdfResponse(id, true);
}
public async Task<IActionResult> DownloadPDF(int id)
{
return await GeneratePdfResponse(id, true);
}
//public async Task<IActionResult> DownloadPDF(int id)
//{
// return await GeneratePdfResponse(id, true);
//}
public IActionResult ViewPDF(int id)
{

View File

@ -116,10 +116,10 @@ public class NetworkShareAccess : IDisposable
public ResourceType ResourceType;
public ResourceDisplayType DisplayType;
public int Usage;
public string? LocalName;
public string? RemoteName;
public string? Comment;
public string? Provider;
public string? LocalName; //? or required TBD
public string? RemoteName; //
public string? Comment; //
public string? Provider; //
}
private enum ResourceScope { Connected = 1, GlobalNetwork, Remembered, Recent, Context }

View File

@ -177,6 +177,7 @@
<a href="/MMS/Marine/ViewPDF?id=${data.id}" class="btn btn-primary" target="_blank">View PDF</a>
<a href="/MMS/Marine/GenerateReport?id=${data.id}" class="btn btn-primary">Download PDF</a>
`
//uses ViewPDF for view, GenerateReport for downloading
}
],
"rowCallback": function(row, data, index) {
@ -214,7 +215,7 @@
this.updateDataTable(newData);
//trigger search function after updating data(?)
if(this.dataTable) {
this.dataTable.search('').draw();//clear existing search
this.dataTable.search('').draw();
}
}
}