fix table connection

This commit is contained in:
misya 2025-05-20 15:25:33 +08:00
parent 00660345fc
commit d5e5fe9a3f
3 changed files with 10 additions and 31 deletions

View File

@ -10,10 +10,11 @@ using System.Threading;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Data.SqlClient; using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using MySqlConnector;
namespace PSTW_CentralSystem.Areas.MMS.Controllers namespace PSTW_CentralSystem.Areas.MMS.Controllers
{ {
public class SimpleTarballDto public class TarballPdfDto
{ {
// From tbl_marine_tarball // From tbl_marine_tarball
public int Id { get; set; } public int Id { get; set; }
@ -58,8 +59,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
{ {
try try
{ {
var marineTarballs = _context.MarineTarballs //error=========================================== var marineTarballs = _context.MarineTarballs //ERRORRRRRRR======================================
.Where(t => t.StationID != "1") // To remove unusable data with invalid stationID
.Select(t => new .Select(t => new
{ {
t.Id, t.Id,
@ -287,7 +287,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
WHERE marine.Id = @id"; WHERE marine.Id = @id";
var tarball = await _context.Database var tarball = await _context.Database
.SqlQueryRaw<TarballPdfDto>(query, new SqlParameter("@id", id)) .SqlQueryRaw<TarballPdfDto>(query, new MySqlParameter("@id", id))
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
if (tarball == null) if (tarball == null)
@ -413,31 +413,6 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers
} }
} }
// Add this class outside your controller (e.g., in a DTOs folder)
public class TarballPdfDto
{
public string StateName { get; set; }
public string StationID { get; set; }
public string LocationName { get; set; }
public string Longitude { get; set; }
public string Latitude { get; set; }
public DateTime DateSample { get; set; }
public TimeSpan TimeSample { get; set; }
public string ClassifyID { get; set; }
public int TarBallYes { get; set; } // SQL returns 1/0 for bits
public int TarBallNo { get; set; }
public int IsSand { get; set; }
public int IsNonSandy { get; set; }
public int IsCoquina { get; set; }
public string OptionalName1 { get; set; }
public string OptionalName2 { get; set; }
public string OptionalName3 { get; set; }
public string OptionalName4 { get; set; }
public string FirstSampler { get; set; }
public string FullName { get; set; }
public string LevelName { get; set; }
}
private bool IsImageValid(string imagePath) private bool IsImageValid(string imagePath)
{ {
try try

View File

@ -46,12 +46,16 @@ namespace PSTW_CentralSystem.DBContext
entity.Property(e => e.OptionalName4).HasColumnName("optionalName4"); entity.Property(e => e.OptionalName4).HasColumnName("optionalName4");
entity.Property(e => e.Timestamp).HasColumnName("timestamp"); entity.Property(e => e.Timestamp).HasColumnName("timestamp");
entity.HasOne(t => t.User)
.WithMany()
.HasForeignKey(t => t.FirstSampler)
.HasPrincipalKey(u => u.FullName); // Assuming User has FullName
//Configure relationship with TarballStation //Configure relationship with TarballStation
entity.HasOne(m => m.MarineStation) entity.HasOne(m => m.MarineStation)
.WithMany() .WithMany()
.HasForeignKey(m => m.StationID) .HasForeignKey(m => m.StationID)
.HasPrincipalKey(t => t.StationID); .HasPrincipalKey(t => t.StationID);
}); });
modelBuilder.Entity<MarineStation>(entity => modelBuilder.Entity<MarineStation>(entity =>

View File

@ -34,7 +34,7 @@ namespace PSTW_CentralSystem.Models
[ForeignKey("StationID")] [ForeignKey("StationID")]
public required MarineStation MarineStation { get; set; } public required MarineStation MarineStation { get; set; }
[ForeignKey("FirstSampler")] [ForeignKey("FirstSampler")]
public required MarineStation User { get; set; } public required User User { get; set; }
} }
public class MarineStation public class MarineStation