新增出去加改Bug

This commit is contained in:
qi_0527 2024-11-18 16:39:21 +08:00
parent f11f8cdd33
commit 04daae2fc2
2 changed files with 69 additions and 30 deletions

View File

@ -167,10 +167,9 @@ namespace WebApi_data_value.Controllers
worksheet.Cell(i + 2, 4).Value = log.RemainingSpaces;
worksheet.Cell(i + 2, 5).Value = log.MonthlyRentSpaces;
worksheet.Cell(i + 2, 6).Value = log.TemporaryRentSpaces;
worksheet.Cell(i + 2, 7).Value = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss dddd");
}
worksheet.Cell( 2, 7).Value = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss dddd");
worksheet.Column(1).Width = 25;
worksheet.Column(2).Width = 10;
worksheet.Column(3).Width = 15;

View File

@ -10,6 +10,7 @@ using Parking_space_WebAPI.Services;
using Parking_space_WebAPI.ViewModel;
using Parking_space_WebAPI.Authorization;
using OfficeOpenXml;
using System.Web;
namespace Parking_space_WebAPI.Controllers
@ -52,7 +53,6 @@ namespace Parking_space_WebAPI.Controllers
}
#endregion
#region 100
/// <summary>
/// 獲取進入雲科的100筆資料
@ -69,6 +69,7 @@ namespace Parking_space_WebAPI.Controllers
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}
).Skip(num).Take(100).ToListAsync();
@ -96,6 +97,7 @@ namespace Parking_space_WebAPI.Controllers
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}).Skip(0).Take(500).ToListAsync();
@ -127,6 +129,7 @@ namespace Parking_space_WebAPI.Controllers
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}).ToListAsync();
@ -153,6 +156,7 @@ namespace Parking_space_WebAPI.Controllers
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}).ToListAsync();
@ -226,7 +230,7 @@ namespace Parking_space_WebAPI.Controllers
}
#endregion
#region
#region
///<summary>
///尋找所有進出校園的地點
/// </summary>
@ -235,18 +239,37 @@ namespace Parking_space_WebAPI.Controllers
public async Task<IEnumerable<object>> Get_in_Yuntech_location_name()
{
var location_name_table = await _context.yuntech_in_car_table
.GroupBy(c=>c.location)
.GroupBy(c => new { c.location })
.Select(group => new
{
location_name = group.Key,
location_name = group.Key.location, // 取得進入地點
})
.ToListAsync();
return location_name_table;
}
#endregion
#region
///<summary>
///尋找所有離開校園的地點
/// </summary>
/// <returns></returns>
[HttpGet("out_location_name")]
public async Task<IEnumerable<object>> Get_out_Yuntech_location_name()
{
var out_location_name_table = await _context.yuntech_in_car_table
.GroupBy(c => new { c.out_location })
.Select(group => new
{
out_location_name = group.Key.out_location // 取得離開地點
})
.ToListAsync();
return out_location_name_table;
}
#endregion
#region
/// <summary>
@ -363,7 +386,6 @@ namespace Parking_space_WebAPI.Controllers
}
#endregion
#region City_parking
/// <summary>
/// City_parking 新增進入資料
@ -479,7 +501,6 @@ namespace Parking_space_WebAPI.Controllers
}
#endregion
#region
/// <summary>
/// 新增出去雲科的車輛資料
@ -680,7 +701,6 @@ namespace Parking_space_WebAPI.Controllers
}
#endregion
#region
/// <summary>
/// 刪除指定資料
@ -720,13 +740,14 @@ namespace Parking_space_WebAPI.Controllers
where c.location == id
where c.in_time >= start_time
where c.in_time <= end_time
orderby c.in_time descending // 按進入時間降序排列
orderby c.in_time descending
select new Yuntech_in_car_table
{
license_plate_number = c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}).ToListAsync();
using (ExcelPackage package = new ExcelPackage())
@ -737,13 +758,18 @@ namespace Parking_space_WebAPI.Controllers
worksheet.Cells["A1"].Value = "進入位置";
worksheet.Cells["B1"].Value = "車牌號碼";
worksheet.Cells["C1"].Value = "進入時間";
worksheet.Cells["D1"].Value = "出去時間";
worksheet.Cells["D1"].Value = "出去區域";
worksheet.Cells["E1"].Value = "出去時間";
worksheet.Cells["F1"].Value = "下載日期";
// 設置列寬
worksheet.Column(1).Width = 20;
worksheet.Column(2).Width = 15;
worksheet.Column(3).Width = 25;
worksheet.Column(4).Width = 25;
worksheet.Column(4).Width = 20;
worksheet.Column(5).Width = 25;
worksheet.Column(6).Width = 25;
worksheet.Cells["F2"].Value = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss dddd");
// 添加資料
int row = 2;
@ -752,8 +778,8 @@ namespace Parking_space_WebAPI.Controllers
worksheet.Cells["A" + row].Value = item.location;
worksheet.Cells["B" + row].Value = item.license_plate_number;
worksheet.Cells["C" + row].Value = item.in_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? "";
worksheet.Cells["D" + row].Value = item.out_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? "";
worksheet.Cells["D" + row].Value = item.out_location;
worksheet.Cells["E" + row].Value = item.out_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? "";
row++;
}
@ -761,8 +787,13 @@ namespace Parking_space_WebAPI.Controllers
// 將ExcelPackage保存到內存流中
MemoryStream stream = new MemoryStream(package.GetAsByteArray());
// 處理文件名中的特殊字符(例如冒號、空格)
string fileName = $"{id}_car_table_{start_time:yyyyMMddHHmmss}_{end_time:yyyyMMddHHmmss}.xlsx";
string encodedFileName = HttpUtility.UrlEncode(fileName)
.Replace("%20", "_")
.Replace("%3A", "-");
// 設置HttpResponseMessage的內容
Response.Headers.Add("Content-Disposition", $"attachment; filename={id}_car_table_{start_time:yyyyMMddHHmmss}_{end_time:yyyyMMddHHmmss}.xlsx");
Response.Headers.Add("Content-Disposition", $"attachment; filename={encodedFileName}");
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
}
@ -793,6 +824,7 @@ namespace Parking_space_WebAPI.Controllers
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}).ToListAsync();
// 創建ExcelPackage對象
@ -804,12 +836,15 @@ namespace Parking_space_WebAPI.Controllers
worksheet.Cells["A1"].Value = "進入位置";
worksheet.Cells["B1"].Value = "車牌號碼";
worksheet.Cells["C1"].Value = "進入時間";
worksheet.Cells["D1"].Value = "出去時間";
worksheet.Cells["D1"].Value = "出去區域";
worksheet.Cells["E1"].Value = "出去時間";
// 設置列寬
worksheet.Column(1).Width = 20;
worksheet.Column(2).Width = 15;
worksheet.Column(3).Width = 25;
worksheet.Column(4).Width = 25;
worksheet.Column(4).Width = 20;
worksheet.Column(5).Width = 25;
// 添加資料
int row = 2;
foreach (var item in in_car_table)
@ -817,7 +852,8 @@ namespace Parking_space_WebAPI.Controllers
worksheet.Cells["A" + row].Value = item.location;
worksheet.Cells["B" + row].Value = item.license_plate_number;
worksheet.Cells["C" + row].Value = item.in_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? "";
worksheet.Cells["D" + row].Value = item.out_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? "";
worksheet.Cells["D" + row].Value = item.out_location;
worksheet.Cells["E" + row].Value = item.out_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? "";
row++;
}
@ -831,7 +867,6 @@ namespace Parking_space_WebAPI.Controllers
}
#endregion
#region EXCEL
/// <summary>
/// 生成全部進入車輛EXCEL
@ -848,6 +883,7 @@ namespace Parking_space_WebAPI.Controllers
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
out_location = c.out_location,
}).ToListAsync();
@ -860,12 +896,15 @@ namespace Parking_space_WebAPI.Controllers
worksheet.Cells["A1"].Value = "進入位置";
worksheet.Cells["B1"].Value = "車牌號碼";
worksheet.Cells["C1"].Value = "進入時間";
worksheet.Cells["D1"].Value = "出去時間";
worksheet.Cells["D1"].Value = "出去區域";
worksheet.Cells["E1"].Value = "出去時間";
// 設置列寬
worksheet.Column(1).Width = 20;
worksheet.Column(2).Width = 15;
worksheet.Column(3).Width = 25;
worksheet.Column(4).Width = 25;
worksheet.Column(4).Width = 20;
worksheet.Column(5).Width = 25;
// 添加資料
int row = 2;
@ -874,7 +913,8 @@ namespace Parking_space_WebAPI.Controllers
worksheet.Cells["A" + row].Value = item.location;
worksheet.Cells["B" + row].Value = item.license_plate_number;
worksheet.Cells["C" + row].Value = item.in_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? "";
worksheet.Cells["D" + row].Value = item.out_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? "";
worksheet.Cells["D" + row].Value = item.out_location;
worksheet.Cells["E" + row].Value = item.out_time?.ToString("yyyy-MM-dd HH:mm:ss") ?? "";
row++;
}