修复许多bug

This commit is contained in:
杨毅 2024-12-01 13:13:03 +08:00
parent 6fb76f5904
commit 8280ee1102
4 changed files with 56 additions and 17 deletions

View File

@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.DataEncryption;
using Microsoft.EntityFrameworkCore.DataEncryption.Providers;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using System.Security.Cryptography;
using System.Text;
using static asg_form.Controllers.Budget.BgCountController;
@ -296,12 +297,25 @@ namespace asg_form.Controllers
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string connStr = @"Host=localhost;Port=2345;Database=asg;Username=postgres;Password=luolan12323;";
optionsBuilder.UseNpgsql(connStr);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
foreach (var property in entityType.GetProperties())
{
if (property.ClrType == typeof(DateTime) || property.ClrType == typeof(DateTime?))
{
property.SetValueConverter(new ValueConverter<DateTime, DateTime>(
v => v.ToUniversalTime(),
v => DateTime.SpecifyKind(v, DateTimeKind.Unspecified)));
}
}
}
modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
}
@ -324,6 +338,18 @@ namespace asg_form.Controllers
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
foreach (var property in entityType.GetProperties())
{
if (property.ClrType == typeof(DateTime) || property.ClrType == typeof(DateTime?))
{
property.SetValueConverter(new ValueConverter<DateTime, DateTime>(
v => v.ToUniversalTime(),
v => DateTime.SpecifyKind(v, DateTimeKind.Unspecified)));
}
}
}
modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
}

View File

@ -35,7 +35,7 @@ namespace asg_form.Controllers
public static void ExportToExcel_noadmin(List<form> data, string fileName)
public static void ExportToExcel_noadmin(List<form> data,string eventname, string fileName)
{
using (var package = new ExcelPackage())
{
@ -56,9 +56,16 @@ namespace asg_form.Controllers
worksheet.Cells[1, a].Style.Fill.BackgroundColor.SetColor(Color.RoyalBlue);
a++;
}
var pic = worksheet.Drawings.AddPicture(form.team_name, $@"{AppDomain.CurrentDomain.BaseDirectory}loge\{form.team_name}.png");
pic.SetSize(50, 50);
pic.SetPosition(26, 0);
try
{
var pic = worksheet.Drawings.AddPicture(form.team_name, $@"{AppDomain.CurrentDomain.BaseDirectory}loge/{eventname}/{form.team_name}.png");
pic.SetSize(50, 50);
pic.SetPosition(26, 0);
}
catch (Exception)
{
Console.WriteLine($@"{AppDomain.CurrentDomain.BaseDirectory}loge/{eventname}/{form.team_name}.png");
}
worksheet.Cells[2, 2].Value = form.Id;
worksheet.Cells[2, 3].Value = form.team_name;
worksheet.Cells[2, 4].Value = form.team_tel;
@ -107,7 +114,7 @@ namespace asg_form.Controllers
public static void ExportToExcel(List<form> data, string fileName)
public static void ExportToExcel(List<form> data, string eventname, string fileName)
{
using (var package = new ExcelPackage())
{
@ -131,9 +138,17 @@ namespace asg_form.Controllers
worksheet.Cells[1, a].Style.Fill.BackgroundColor.SetColor(Color.RoyalBlue);
a++;
}
var pic = worksheet.Drawings.AddPicture(form.team_name, $@"{AppDomain.CurrentDomain.BaseDirectory}loge\{form.team_name}.png");
pic.SetSize(50, 50);
pic.SetPosition(26, 0);
try
{
var pic = worksheet.Drawings.AddPicture(form.team_name, $@"{AppDomain.CurrentDomain.BaseDirectory}loge/{eventname}/{form.team_name}.png");
pic.SetSize(50, 50);
pic.SetPosition(26, 0);
}
catch (Exception)
{
}
worksheet.Cells[2, 2].Value = form.Id;
worksheet.Cells[2, 3].Value = form.team_name;
worksheet.Cells[2, 4].Value = form.team_tel;
@ -341,16 +356,16 @@ namespace asg_form.Controllers
{
string guid = Guid.NewGuid().ToString();
TestDbContext testDb = new TestDbContext();
List<form> result = testDb.Forms.ToList();
List<form> result = testDb.Forms.Include(a=>a.role).Include(a=>a.events).Where(a=>a.events.name==event_name).ToList();
if (this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "nbadmin"))
{
ExportToExcel(result, $"{AppDomain.CurrentDomain.BaseDirectory}excel/{guid}.xlsx");
ExportToExcel(result,event_name, $"{AppDomain.CurrentDomain.BaseDirectory}excel/{guid}.xlsx");
return Ok(guid);
}
else if (this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
{
ExportToExcel_noadmin(result, $"{AppDomain.CurrentDomain.BaseDirectory}excel/{guid}.xlsx");
ExportToExcel_noadmin(result,event_name, $"{AppDomain.CurrentDomain.BaseDirectory}excel/{guid}.xlsx");
return Ok(guid);
}
else

View File

@ -423,7 +423,7 @@ namespace asg_form.Controllers
if (imageFile == null || imageFile.Length == 0)
return BadRequest("Invalid image file.");
// 将文件保存到磁盘
var filePath = Path.Combine(Directory.GetCurrentDirectory(), $"loge/{for1.events_name}/", $"{imageFile.FileName}");
var filePath = Path.Combine(Directory.GetCurrentDirectory(), $"loge/{for1.events_name}/", $"{for1.team_name}.png");
using (var stream = new FileStream(filePath, FileMode.Create))
{
await imageFile.CopyToAsync(stream);

View File

@ -30,6 +30,7 @@
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="ChatGPT.Net" Version="2.0.0" />
<PackageReference Include="EntityFrameworkCore.DataEncryption" Version="5.0.0" />
<PackageReference Include="EPPlus" Version="7.5.1" />
<PackageReference Include="Flandre.Adapters.OneBot.Extensions" Version="2.0.0-rc.3" />
<PackageReference Include="Flandre.Core" Version="1.0.0-rc.4" />
<PackageReference Include="Flandre.Framework" Version="1.0.0-rc.11" />
@ -37,7 +38,6 @@
<PackageReference Include="ini-parser" Version="2.5.2" />
<PackageReference Include="MailKit" Version="4.3.0" />
<PackageReference Include="Masuit.Tools.Abstractions" Version="2024.5.8" />
<PackageReference Include="Masuit.Tools.Excel" Version="1.2.8" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
@ -53,10 +53,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="9.0.0" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="MiniExcel" Version="1.31.2" />
<PackageReference Include="MiniExcel" Version="1.35.0" />
<PackageReference Include="Mirai.Net" Version="2.5.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.2.4" />
@ -69,11 +69,9 @@
<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.8" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="Zack.EventBus" Version="1.1.3" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>