diff --git a/Frontend/_historyData.html b/Frontend/_historyData.html index f98eedc..9e6f02c 100644 --- a/Frontend/_historyData.html +++ b/Frontend/_historyData.html @@ -84,6 +84,7 @@ initApp.buildNavigation($('#js_nested_list')); loadTable(null); + $(`[onclick="setDateType('today')"]`).click(); }); function initList() { @@ -186,12 +187,12 @@ var edt = new Date(new Date().setDate(sdt.getDate() + 1)); start = start ?? sdt.toLocaleDateString(); end = end ?? edt.toLocaleDateString(); - getHistoryDataByBaja(pageAct.deviceNumber + "_" + pageAct.deviceItem, - new Date(start).getTime(), - new Date(end).getTime(), - pageAct.deviceName, - "Mitsubishi_Sup", - callBackFromHistory); + // getHistoryDataByBaja(pageAct.deviceNumber + "_" + pageAct.deviceItem, + //new Date(start).getTime(), + //new Date(end).getTime(), + //pageAct.deviceName, + // "Mitsubishi_Sup", + // callBackFromHistory); } function callBackFromHistory(res) { @@ -262,7 +263,7 @@ if (pageAct.dateType == "day") end = new Date(new Date().setDate(start.getDate() + 1)); - else if (pageAct.dateType == "month") { + else if (pageAct.dateType == "month") { start = new Date($('#getmonth').val()); end = new Date(new Date().setDate(start.getDate() + 30)); } @@ -290,7 +291,7 @@ let column_defs = [ { "targets": [0], "width": "20%", "sortable": true }, { "targets": [1], "width": "20%", "sortable": true }, - { "targets": [2], "width": "20%", "sortable": true }, + { "targets": [2], "width": "20%", "sortable": true } ]; let columns = [ @@ -308,17 +309,25 @@ "render": function (date) { return displayDate(date, "datetime"); } - }, + } ]; - + historyTable = new YourTeam.JqDataTables.getTableByStatic(tag, data, columns, column_defs, null, null, null, null, "tpi"); } function exportExcel() { let url = baseApiUrl + "/History/OpeExportExcel"; - objSendData.Data = $('#historyTable').dataTable().fnGetData();; + objSendData.Data = $('#historyTable').dataTable().fnGetData(); + + $.each(objSendData.Data, function (i, v) { + v.starttime = (pageAct.dateType == "month" ? new Date($('#getmonth').val()) : new Date($('#startdate').val())); + v.endtime = $('#enddate input').val() === "" ? null : new Date($('#enddate input').val()); + v.dateType = pageAct.dateType; + }); + ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) { - location.href = baseApiUrl + "/api/df?fileName=" + rel.data + "&token=" + localStorage.getItem("JWT-Authorization"); + if (rel.code == "0000") + location.href = baseApiUrl + "/api/df?fileName=" + rel.data + "&token=" + localStorage.getItem("JWT-Authorization"); }, null, "POST").send(); } \ No newline at end of file diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index a876641..ee5d6a7 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -55,7 +55,8 @@ namespace FrontendWebApi.ApiControllers try { - var fileName = "廠商資料.xlsx"; + var fileDateName = lhe.FirstOrDefault().dateType == "month" ? lhe.FirstOrDefault().starttime.ToString("yyyy-MM") : lhe.FirstOrDefault().endtime == null ? lhe.FirstOrDefault().starttime.ToString("yyyy-MM-dd") : lhe.FirstOrDefault().starttime.ToString("yyyy-MM-dd") + "_" + ((DateTime)lhe.FirstOrDefault().endtime).ToString("yyyy-MM-dd"); + var fileName = "廠商資料_"+fileDateName+".xlsx"; var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "history"); if (!System.IO.Directory.Exists(filePath)) diff --git a/FrontendWebApi/Models/HistoryClass.cs b/FrontendWebApi/Models/HistoryClass.cs index c823fa4..d9a08b4 100644 --- a/FrontendWebApi/Models/HistoryClass.cs +++ b/FrontendWebApi/Models/HistoryClass.cs @@ -268,5 +268,8 @@ namespace FrontendWebApi.Models public string deviceName { get; set; } public int value { get; set; } public DateTime timestamp { get; set; } + public DateTime starttime { get; set; } + public DateTime? endtime { get; set; } + public string dateType { get; set; } } } diff --git a/FrontendWebApi/wwwroot/excel/history/廠商資料.xlsx b/FrontendWebApi/wwwroot/excel/history/廠商資料.xlsx deleted file mode 100644 index bd5d517..0000000 Binary files a/FrontendWebApi/wwwroot/excel/history/廠商資料.xlsx and /dev/null differ