新增出去加改Bug
This commit is contained in:
parent
f11f8cdd33
commit
04daae2fc2
@ -167,10 +167,9 @@ namespace WebApi_data_value.Controllers
|
|||||||
worksheet.Cell(i + 2, 4).Value = log.RemainingSpaces;
|
worksheet.Cell(i + 2, 4).Value = log.RemainingSpaces;
|
||||||
worksheet.Cell(i + 2, 5).Value = log.MonthlyRentSpaces;
|
worksheet.Cell(i + 2, 5).Value = log.MonthlyRentSpaces;
|
||||||
worksheet.Cell(i + 2, 6).Value = log.TemporaryRentSpaces;
|
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(1).Width = 25;
|
||||||
worksheet.Column(2).Width = 10;
|
worksheet.Column(2).Width = 10;
|
||||||
worksheet.Column(3).Width = 15;
|
worksheet.Column(3).Width = 15;
|
||||||
|
@ -10,6 +10,7 @@ using Parking_space_WebAPI.Services;
|
|||||||
using Parking_space_WebAPI.ViewModel;
|
using Parking_space_WebAPI.ViewModel;
|
||||||
using Parking_space_WebAPI.Authorization;
|
using Parking_space_WebAPI.Authorization;
|
||||||
using OfficeOpenXml;
|
using OfficeOpenXml;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
|
|
||||||
namespace Parking_space_WebAPI.Controllers
|
namespace Parking_space_WebAPI.Controllers
|
||||||
@ -52,7 +53,6 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 獲取進入雲科的100筆資料
|
#region 獲取進入雲科的100筆資料
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 獲取進入雲科的100筆資料
|
/// 獲取進入雲科的100筆資料
|
||||||
@ -69,6 +69,7 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
in_time = c.in_time,
|
in_time = c.in_time,
|
||||||
out_time = c.out_time,
|
out_time = c.out_time,
|
||||||
location = c.location,
|
location = c.location,
|
||||||
|
out_location = c.out_location,
|
||||||
}
|
}
|
||||||
).Skip(num).Take(100).ToListAsync();
|
).Skip(num).Take(100).ToListAsync();
|
||||||
|
|
||||||
@ -96,6 +97,7 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
in_time = c.in_time,
|
in_time = c.in_time,
|
||||||
out_time = c.out_time,
|
out_time = c.out_time,
|
||||||
location = c.location,
|
location = c.location,
|
||||||
|
out_location = c.out_location,
|
||||||
}).Skip(0).Take(500).ToListAsync();
|
}).Skip(0).Take(500).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
@ -127,6 +129,7 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
in_time = c.in_time,
|
in_time = c.in_time,
|
||||||
out_time = c.out_time,
|
out_time = c.out_time,
|
||||||
location = c.location,
|
location = c.location,
|
||||||
|
out_location = c.out_location,
|
||||||
}).ToListAsync();
|
}).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
@ -153,6 +156,7 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
in_time = c.in_time,
|
in_time = c.in_time,
|
||||||
out_time = c.out_time,
|
out_time = c.out_time,
|
||||||
location = c.location,
|
location = c.location,
|
||||||
|
out_location = c.out_location,
|
||||||
}).ToListAsync();
|
}).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
@ -226,7 +230,7 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 尋找所有進出校園的地點
|
#region 尋找所有進入校園的地點
|
||||||
///<summary>
|
///<summary>
|
||||||
///尋找所有進出校園的地點
|
///尋找所有進出校園的地點
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -235,18 +239,37 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
public async Task<IEnumerable<object>> Get_in_Yuntech_location_name()
|
public async Task<IEnumerable<object>> Get_in_Yuntech_location_name()
|
||||||
{
|
{
|
||||||
var location_name_table = await _context.yuntech_in_car_table
|
var location_name_table = await _context.yuntech_in_car_table
|
||||||
.GroupBy(c=>c.location)
|
.GroupBy(c => new { c.location })
|
||||||
.Select(group => new
|
.Select(group => new
|
||||||
{
|
{
|
||||||
location_name = group.Key,
|
location_name = group.Key.location, // 取得進入地點
|
||||||
|
|
||||||
})
|
})
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
return location_name_table;
|
return location_name_table;
|
||||||
}
|
}
|
||||||
#endregion
|
#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 新增資料
|
#region 新增資料
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -363,7 +386,6 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region City_parking 新增進入資料
|
#region City_parking 新增進入資料
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// City_parking 新增進入資料
|
/// City_parking 新增進入資料
|
||||||
@ -479,7 +501,6 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 新增出去資料
|
#region 新增出去資料
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 新增出去雲科的車輛資料
|
/// 新增出去雲科的車輛資料
|
||||||
@ -680,7 +701,6 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 刪除資料
|
#region 刪除資料
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 刪除指定資料
|
/// 刪除指定資料
|
||||||
@ -720,13 +740,14 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
where c.location == id
|
where c.location == id
|
||||||
where c.in_time >= start_time
|
where c.in_time >= start_time
|
||||||
where c.in_time <= end_time
|
where c.in_time <= end_time
|
||||||
orderby c.in_time descending // 按進入時間降序排列
|
orderby c.in_time descending
|
||||||
select new Yuntech_in_car_table
|
select new Yuntech_in_car_table
|
||||||
{
|
{
|
||||||
license_plate_number = c.license_plate_number,
|
license_plate_number = c.license_plate_number,
|
||||||
in_time = c.in_time,
|
in_time = c.in_time,
|
||||||
out_time = c.out_time,
|
out_time = c.out_time,
|
||||||
location = c.location,
|
location = c.location,
|
||||||
|
out_location = c.out_location,
|
||||||
}).ToListAsync();
|
}).ToListAsync();
|
||||||
|
|
||||||
using (ExcelPackage package = new ExcelPackage())
|
using (ExcelPackage package = new ExcelPackage())
|
||||||
@ -737,13 +758,18 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
worksheet.Cells["A1"].Value = "進入位置";
|
worksheet.Cells["A1"].Value = "進入位置";
|
||||||
worksheet.Cells["B1"].Value = "車牌號碼";
|
worksheet.Cells["B1"].Value = "車牌號碼";
|
||||||
worksheet.Cells["C1"].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(1).Width = 20;
|
||||||
worksheet.Column(2).Width = 15;
|
worksheet.Column(2).Width = 15;
|
||||||
worksheet.Column(3).Width = 25;
|
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;
|
int row = 2;
|
||||||
@ -752,8 +778,8 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
worksheet.Cells["A" + row].Value = item.location;
|
worksheet.Cells["A" + row].Value = item.location;
|
||||||
worksheet.Cells["B" + row].Value = item.license_plate_number;
|
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["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++;
|
row++;
|
||||||
}
|
}
|
||||||
@ -761,8 +787,13 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
// 將ExcelPackage保存到內存流中
|
// 將ExcelPackage保存到內存流中
|
||||||
MemoryStream stream = new MemoryStream(package.GetAsByteArray());
|
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的內容
|
// 設置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");
|
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -793,6 +824,7 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
in_time = c.in_time,
|
in_time = c.in_time,
|
||||||
out_time = c.out_time,
|
out_time = c.out_time,
|
||||||
location = c.location,
|
location = c.location,
|
||||||
|
out_location = c.out_location,
|
||||||
}).ToListAsync();
|
}).ToListAsync();
|
||||||
|
|
||||||
// 創建ExcelPackage對象
|
// 創建ExcelPackage對象
|
||||||
@ -804,12 +836,15 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
worksheet.Cells["A1"].Value = "進入位置";
|
worksheet.Cells["A1"].Value = "進入位置";
|
||||||
worksheet.Cells["B1"].Value = "車牌號碼";
|
worksheet.Cells["B1"].Value = "車牌號碼";
|
||||||
worksheet.Cells["C1"].Value = "進入時間";
|
worksheet.Cells["C1"].Value = "進入時間";
|
||||||
worksheet.Cells["D1"].Value = "出去時間";
|
worksheet.Cells["D1"].Value = "出去區域";
|
||||||
|
worksheet.Cells["E1"].Value = "出去時間";
|
||||||
|
|
||||||
// 設置列寬
|
// 設置列寬
|
||||||
worksheet.Column(1).Width = 20;
|
worksheet.Column(1).Width = 20;
|
||||||
worksheet.Column(2).Width = 15;
|
worksheet.Column(2).Width = 15;
|
||||||
worksheet.Column(3).Width = 25;
|
worksheet.Column(3).Width = 25;
|
||||||
worksheet.Column(4).Width = 25;
|
worksheet.Column(4).Width = 20;
|
||||||
|
worksheet.Column(5).Width = 25;
|
||||||
// 添加資料
|
// 添加資料
|
||||||
int row = 2;
|
int row = 2;
|
||||||
foreach (var item in in_car_table)
|
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["A" + row].Value = item.location;
|
||||||
worksheet.Cells["B" + row].Value = item.license_plate_number;
|
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["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++;
|
row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -831,7 +867,6 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 生成全部進入車輛EXCEL
|
#region 生成全部進入車輛EXCEL
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 生成全部進入車輛EXCEL
|
/// 生成全部進入車輛EXCEL
|
||||||
@ -848,8 +883,9 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
in_time = c.in_time,
|
in_time = c.in_time,
|
||||||
out_time = c.out_time,
|
out_time = c.out_time,
|
||||||
location = c.location,
|
location = c.location,
|
||||||
|
out_location = c.out_location,
|
||||||
|
|
||||||
}).ToListAsync();
|
}).ToListAsync();
|
||||||
|
|
||||||
// 創建ExcelPackage對象
|
// 創建ExcelPackage對象
|
||||||
using (ExcelPackage package = new ExcelPackage())
|
using (ExcelPackage package = new ExcelPackage())
|
||||||
@ -860,12 +896,15 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
worksheet.Cells["A1"].Value = "進入位置";
|
worksheet.Cells["A1"].Value = "進入位置";
|
||||||
worksheet.Cells["B1"].Value = "車牌號碼";
|
worksheet.Cells["B1"].Value = "車牌號碼";
|
||||||
worksheet.Cells["C1"].Value = "進入時間";
|
worksheet.Cells["C1"].Value = "進入時間";
|
||||||
worksheet.Cells["D1"].Value = "出去時間";
|
worksheet.Cells["D1"].Value = "出去區域";
|
||||||
|
worksheet.Cells["E1"].Value = "出去時間";
|
||||||
|
|
||||||
// 設置列寬
|
// 設置列寬
|
||||||
worksheet.Column(1).Width = 20;
|
worksheet.Column(1).Width = 20;
|
||||||
worksheet.Column(2).Width = 15;
|
worksheet.Column(2).Width = 15;
|
||||||
worksheet.Column(3).Width = 25;
|
worksheet.Column(3).Width = 25;
|
||||||
worksheet.Column(4).Width = 25;
|
worksheet.Column(4).Width = 20;
|
||||||
|
worksheet.Column(5).Width = 25;
|
||||||
|
|
||||||
// 添加資料
|
// 添加資料
|
||||||
int row = 2;
|
int row = 2;
|
||||||
@ -874,7 +913,8 @@ namespace Parking_space_WebAPI.Controllers
|
|||||||
worksheet.Cells["A" + row].Value = item.location;
|
worksheet.Cells["A" + row].Value = item.location;
|
||||||
worksheet.Cells["B" + row].Value = item.license_plate_number;
|
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["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++;
|
row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user