diff --git a/WebApi_data_value/Controllers/Violation_car_tableController.cs b/WebApi_data_value/Controllers/Violation_car_tableController.cs
index ddd5576..f00f6fa 100644
--- a/WebApi_data_value/Controllers/Violation_car_tableController.cs
+++ b/WebApi_data_value/Controllers/Violation_car_tableController.cs
@@ -10,6 +10,8 @@ using Parking_space_WebAPI.Services;
using Parking_space_WebAPI.ViewModel;
using Parking_space_WebAPI.Authorization;
using Mysqlx;
+using OfficeOpenXml;
+using System.Net;
namespace Parking_space_WebAPI.Controllers
{
@@ -317,6 +319,7 @@ namespace Parking_space_WebAPI.Controllers
violation_car_table.create_data_time = DateTime.Now;
var location_name = violation_car_table.violation_location_name;
var license_plate_number = violation_car_table.license_plate_number;
+ var in_car_img = violation_car_table.car_start_img;
// 取得現在時間
DateTime time = DateTime.Now;
// 取得 10秒前的時間
@@ -328,7 +331,7 @@ namespace Parking_space_WebAPI.Controllers
//判斷10秒內有多少資料
if (Data_list.Count == 1) //只有1筆 若與全景判斷的車牌不同就替換車牌
{
- if (Data_list[0].license_plate_number != license_plate_number)
+ if (Data_list[0].license_plate_number != license_plate_number && time.Hour <= 17)
{
var data = Data_list[0];
_context.violation_car_table.Remove(Data_list[0]);
@@ -342,7 +345,25 @@ namespace Parking_space_WebAPI.Controllers
else {
return Ok();
}
-
+
+ if (Data_list[0].license_plate_number != license_plate_number && time.Hour > 17)
+ {
+ var data = Data_list[0];
+ _context.violation_car_table.Remove(Data_list[0]);
+ await _context.SaveChangesAsync();
+ data.license_plate_number = license_plate_number;
+ data.car_start_img = in_car_img;
+ _context.violation_car_table.Add(data);
+ await _context.SaveChangesAsync();
+ return Ok();
+
+ }
+ else
+ {
+ return Ok();
+ }
+
+
}
if (Data_list.Count > 1)//超過2筆
{
@@ -369,6 +390,153 @@ namespace Parking_space_WebAPI.Controllers
}
#endregion
+ #region 生成全部違規車輛EXCEL
+ ///
+ /// 生成全部違規車輛EXCEL
+ ///
+ ///
+ [HttpGet("export-all_excel")]
+ public async Task GenerateExcel()
+ {
+ var violation_car_table = await(from c in _context.violation_car_table
+ orderby c.create_data_time descending
+ select new Violation_car_table
+ {
+ license_plate_number = c.license_plate_number,
+ create_data_time = c.create_data_time,
+ violation_location_name = c.violation_location_name,
+
+ }).ToListAsync();
+
+ // 創建ExcelPackage對象
+ using (ExcelPackage package = new ExcelPackage())
+ {
+ ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("ViolationCarTable");
+
+ // 添加標題行
+ worksheet.Cells["A1"].Value = "違規位置";
+ worksheet.Cells["B1"].Value = "車牌號碼";
+ worksheet.Cells["C1"].Value = "違規時間";
+
+ // 添加資料
+ int row = 2;
+ foreach (var item in violation_car_table)
+ {
+ worksheet.Cells["A" + row].Value = item.violation_location_name;
+ worksheet.Cells["B" + row].Value = item.license_plate_number;
+ worksheet.Cells["C" + row].Value = item.create_data_time.ToString(); // 可以自行調整日期時間的格式
+ row++;
+ }
+
+ // 將ExcelPackage保存到內存流中
+ MemoryStream stream = new MemoryStream(package.GetAsByteArray());
+
+ // 設置HttpResponseMessage的內容
+ Response.Headers.Add("Content-Disposition", "attachment; filename=test.xlsx");
+ return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ }
+ }
+ #endregion
+
+ #region 生成指定車輛EXCEL
+ ///
+ /// 生成指定車輛EXCEL
+ ///
+ ///
+ [HttpGet("export-excel_license_plate_number-{id}")]
+ public async Task Getlicense_plate_number_excel(string id)
+ {
+ var violation_car_table = await (from c in _context.violation_car_table
+ where c.license_plate_number == id
+ orderby c.create_data_time descending
+ select new Single_violation_car_table
+ {
+ violation_location_name = c.violation_location_name,
+ license_plate_number = c.license_plate_number,
+ create_data_time = c.create_data_time,
+ }).ToListAsync();
+
+ // 創建ExcelPackage對象
+ using (ExcelPackage package = new ExcelPackage())
+ {
+ ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("ViolationCarTable");
+
+ // 添加標題行
+ worksheet.Cells["A1"].Value = "違規位置";
+ worksheet.Cells["B1"].Value = "車牌號碼";
+ worksheet.Cells["C1"].Value = "違規時間";
+
+ // 添加資料
+ int row = 2;
+ foreach (var item in violation_car_table)
+ {
+ worksheet.Cells["A" + row].Value = item.violation_location_name;
+ worksheet.Cells["B" + row].Value = item.license_plate_number;
+ worksheet.Cells["C" + row].Value = item.create_data_time.ToString(); // 可以自行調整日期時間的格式
+ row++;
+ }
+
+ // 將ExcelPackage保存到內存流中
+ MemoryStream stream = new MemoryStream(package.GetAsByteArray());
+
+ // 設置HttpResponseMessage的內容
+ Response.Headers.Add("Content-Disposition", "attachment; filename=test.xlsx");
+ return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ }
+ }
+ #endregion
+
+ #region 生成指定時間內EXCEL
+ ///
+ /// 生成指定時間內EXCEL
+ ///
+ ///
+ [HttpGet("export-excel_location_name_1_-{id}-start_time-{start_time}-end_time-{end_time}")]
+ public async Task Getviolation_car_table_date_excel(string id, DateTime start_time, DateTime end_time)
+ {
+ var violation_car_table = await (from c in _context.violation_car_table
+ where c.violation_location_name == id
+ where c.create_data_time >= start_time
+ where c.create_data_time <= end_time
+ select new Single_violation_car_table
+ {
+ violation_location_name = c.violation_location_name,
+ license_plate_number = c.license_plate_number,
+ create_data_time = c.create_data_time,
+ }).ToListAsync();
+
+ // 創建ExcelPackage對象
+ using (ExcelPackage package = new ExcelPackage())
+ {
+ ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("ViolationCarTable");
+
+ // 添加標題行
+ worksheet.Cells["A1"].Value = "違規位置";
+ worksheet.Cells["B1"].Value = "車牌號碼";
+ worksheet.Cells["C1"].Value = "違規時間";
+
+ // 添加資料
+ int row = 2;
+ foreach (var item in violation_car_table)
+ {
+ worksheet.Cells["A" + row].Value = item.violation_location_name;
+ worksheet.Cells["B" + row].Value = item.license_plate_number;
+ worksheet.Cells["C" + row].Value = item.create_data_time.ToString(); // 可以自行調整日期時間的格式
+ row++;
+ }
+
+ // 將ExcelPackage保存到內存流中
+ MemoryStream stream = new MemoryStream(package.GetAsByteArray());
+
+ // 設置HttpResponseMessage的內容
+ Response.Headers.Add("Content-Disposition", "attachment; filename=test.xlsx");
+ return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ }
+ }
+ #endregion
+
+
+
private bool Violation_car_tableExists(string id)
{
return (_context.violation_car_table?.Any(e => e.violation_location_name == id)).GetValueOrDefault();
diff --git a/WebApi_data_value/WebApi_data_value.csproj b/WebApi_data_value/WebApi_data_value.csproj
index a685b69..20b88d1 100644
--- a/WebApi_data_value/WebApi_data_value.csproj
+++ b/WebApi_data_value/WebApi_data_value.csproj
@@ -20,6 +20,7 @@
+