This commit is contained in:
dev02 2023-07-26 15:36:02 +08:00
commit 7ae883a1b6
17 changed files with 196 additions and 12 deletions

View File

@ -509,7 +509,7 @@
{ {
"data": null, "data": null,
"render": function (data, type, row, meta){ "render": function (data, type, row, meta){
return '<button bg-guid="'+row.building_tag+'" ms-guid="'+row.main_system_tag+'" ss-guid="'+row.sub_system_tag+'" class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>'; return '<button bg-guid="'+row.building_tag+'" ms-guid="'+row.main_system_tag+'" ss-guid="'+row.sub_system_tag+'" class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn" bg-guid="'+row.building_tag+'" ms-guid="'+row.main_system_tag+'" ss-guid="'+row.sub_system_tag+'" >刪除</button>';
} }
} }
], ],

View File

@ -23,7 +23,7 @@
<th>#</th> <th>#</th>
<th>角色</th> <th>角色</th>
<th>功能類型</th> <th>功能類型</th>
<th>區域</th> <th>棟別</th>
<th>功能名稱</th> <th>功能名稱</th>
<th>功能細項名稱</th> <th>功能細項名稱</th>
<th>建立時間</th> <th>建立時間</th>

View File

@ -107,7 +107,7 @@ namespace FrontendWebApi.ApiControllers
[HttpPost] [HttpPost]
[Route("api/EmergencyContact/PDF")] [Route("api/EmergencyContact/PDF")]
public async Task<ActionResult<ApiResult<string>>> ExportPDF(export post) public async Task<ActionResult<ApiResult<string>>> ExportPDF([FromBody] export post)
{ {
//var grouping = JsonConvert.DeserializeObject<export>(post); //var grouping = JsonConvert.DeserializeObject<export>(post);
ApiResult<string> apiResult = new ApiResult<string>(); ApiResult<string> apiResult = new ApiResult<string>();
@ -182,7 +182,7 @@ namespace FrontendWebApi.ApiControllers
[HttpPost] [HttpPost]
[Route("api/EmergencyContact/Excel")] [Route("api/EmergencyContact/Excel")]
public async Task<ActionResult<ApiResult<string>>> ExportExcel(export post) public async Task<ActionResult<ApiResult<string>>> ExportExcel([FromBody] export post)
{ {
//var guid = Guid.NewGuid().ToString(); //var guid = Guid.NewGuid().ToString();
ApiResult<string> apiResult = new ApiResult<string>(); ApiResult<string> apiResult = new ApiResult<string>();

View File

@ -766,7 +766,157 @@ namespace FrontendWebApi.ApiControllers
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
return File(ms, "application/vnd.ms-excel", "電表報表.xlsx"); return File(ms, "application/vnd.ms-excel", "電表報表.xlsx");
} }
[HttpPost]
[Route("api/ExportWaterList")]
public FileResult OpeExportExcelWater([FromBody] HydroMeterInput input)
{
var result = this.WaterList(input).Result.Value.Data.ToList();
var workbook = new XSSFWorkbook();
#region excel設定
IFont font12 = workbook.CreateFont();
font12.FontName = "新細明體";
font12.FontHeightInPoints = 12;
ICellStyle style12 = workbook.CreateCellStyle();
style12.SetFont(font12);
style12.Alignment = HorizontalAlignment.Center;
style12.VerticalAlignment = VerticalAlignment.Center;
IFont font12Times = workbook.CreateFont();
font12Times.FontName = "Times New Roman";
font12Times.FontHeightInPoints = 12;
IFont font18 = workbook.CreateFont();
font18.FontName = "新細明體";
font18.FontHeightInPoints = 18;
font18.IsBold = true;
ICellStyle styleTitle18 = workbook.CreateCellStyle();
styleTitle18.SetFont(font18);
styleTitle18.Alignment = HorizontalAlignment.Center;
styleTitle18.VerticalAlignment = VerticalAlignment.Center;
ICellStyle styleLeft12 = workbook.CreateCellStyle();
styleLeft12.SetFont(font12);
styleLeft12.Alignment = HorizontalAlignment.Left;
styleLeft12.VerticalAlignment = VerticalAlignment.Center;
ICellStyle styleLine12 = workbook.CreateCellStyle();
styleLine12.SetFont(font12);
styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
styleLine12.VerticalAlignment = VerticalAlignment.Center;
styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
ICellStyle stylein12 = workbook.CreateCellStyle();
stylein12.SetFont(font12Times);
stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
stylein12.VerticalAlignment = VerticalAlignment.Center;
stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.WrapText = true;
#endregion
var sheet = workbook.CreateSheet("電表報表");
int RowPosition = 0;
if (result.Count > 0)
{
#region set cell
IRow row = sheet.CreateRow(RowPosition);
sheet.SetColumnWidth(0, 4 * 160 * 12);
sheet.SetColumnWidth(1, 4 * 160 * 12);
sheet.SetColumnWidth(2, 4 * 160 * 12);
int i = 0;
ICell cell = row.CreateCell(i++);
cell.SetCellValue("東別");
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue("樓層");
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue("設備");
cell.CellStyle = styleLine12;
foreach (var rr in result.FirstOrDefault().rawData)
{
cell = row.CreateCell(i++);
cell.SetCellValue(rr.timeStamp);
cell.CellStyle = styleLine12;
}
cell = row.CreateCell(i++);
cell.SetCellValue("小計");
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue("單價");
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue("金額總計");
cell.CellStyle = styleLine12;
#endregion
foreach (var r in result)
{
RowPosition += 1;
int k = 3;
row = sheet.CreateRow(RowPosition);
for (int j = 0; j <= i; j++)
{
cell = row.CreateCell(j);
if (j == 0)
{
cell.SetCellValue(r.building_name);
}
if (j == 1)
{
cell.SetCellValue(r.floor_tag);
}
if (j == 2)
{
cell.SetCellValue(r.device_serial_tag);
}
if (j == 3)
{
foreach (var rr in r.rawData)
{
cell.SetCellValue(rr.avg_rawdata.ToString());
j++;
k++;
cell = row.CreateCell(j);
}
}
if (j == k)
{
cell.SetCellValue(r.total);
}
if (j == k + 1)
{
cell.SetCellValue(r.price);
}
if (j == k + 2)
{
cell.SetCellValue(r.total_price);
}
cell.CellStyle = style12;
}
}
}
var ms = new NpoiMemoryStream
{
AllowClose = false
};
workbook.Write(ms);
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
return File(ms, "application/vnd.ms-excel", "水表報表.xlsx");
}
public static int GetDayInMonth(string yearMonth) public static int GetDayInMonth(string yearMonth)
{ {
List<string> datesList = new List<string>(); List<string> datesList = new List<string>();

View File

@ -32,8 +32,6 @@
</div> </div>
<div class="pr-3 row col"> <div class="pr-3 row col">
<div class="frame-wrap" id="groupinglist"> <div class="frame-wrap" id="groupinglist">
</div> </div>
</div> </div>
<div class="card border mb-g w-100 mb-5" id="emergency_setting_card"> <div class="card border mb-g w-100 mb-5" id="emergency_setting_card">
@ -201,8 +199,7 @@
} }
//選擇組別 //選擇組別
function SelectGrouping(grouping, e) function SelectGrouping(grouping, e) {
{
if ($(e).hasClass("btn-outline-success")) { if ($(e).hasClass("btn-outline-success")) {
$(e).removeClass("btn-outline-success").addClass("btn-success"); $(e).removeClass("btn-outline-success").addClass("btn-success");
selectgroupidlist.push(grouping); selectgroupidlist.push(grouping);
@ -218,8 +215,7 @@
} }
//全選所有組別 //全選所有組別
function Allgroupingselect() function Allgroupingselect() {
{
if (Allgroupingbool) { if (Allgroupingbool) {
$('#groupinglist').find(".btn-success").removeClass("btn-success").addClass("btn-outline-success"); $('#groupinglist').find(".btn-success").removeClass("btn-success").addClass("btn-outline-success");
selectgroupidlist = []; selectgroupidlist = [];
@ -249,7 +245,27 @@
disaster: $('#Disasterlist').find('.btn-success').html(), disaster: $('#Disasterlist').find('.btn-success').html(),
groupidlist: selectgroupidlist groupidlist: selectgroupidlist
} }
window.location = "/EmergencyContact/ExportPDF?post=" + JSON.stringify(send_data);
var url = "/api/EmergencyContact/PDF";
$.ajax({
method: "POST",
contentType:"application/json; chatset='utf-8'",
headers: { "Authorization": "Bearer " + localStorage.getItem('JWT-Authorization') },
url: url,
data: JSON.stringify(send_data),
success: (res, text, xhr) => {
if (res.code == "9999") {
toast_error(res.msg);
return;
}
if(res.data && res.code == "0000"){
window.open(location.origin + "/" + res.data)
} else {
toast_error("系統發生錯誤,請再重新嘗試");
}
}
})
} }
} }
@ -269,7 +285,25 @@
disaster: $('#Disasterlist').find('.btn-success').html(), disaster: $('#Disasterlist').find('.btn-success').html(),
groupidlist: selectgroupidlist groupidlist: selectgroupidlist
} }
window.location = "/EmergencyContact/ExportExcel?post=" + JSON.stringify(send_data); var url = "/api/EmergencyContact/Excel";
$.ajax({
method: "POST",
contentType: "application/json; chatset='utf-8'",
headers: { "Authorization": "Bearer " + localStorage.getItem('JWT-Authorization') },
url: url,
data: JSON.stringify(send_data),
success: (res, text, xhr) => {
if (res.code == "9999") {
toast_error(res.msg);
return;
}
if(res.data && res.code == "0000"){
window.open(location.origin + "/" + res.data)
} else {
toast_error("系統發生錯誤,請再重新嘗試");
}
}
})
} }
} }