From bc0950b8152874bbac6d6a627df6b12baa066b44 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Tue, 5 Oct 2021 17:20:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A0=B1=E8=A1=A8=E5=8C=AF=E5=87=BA=E9=A9=97?= =?UTF-8?q?=E8=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/StationReportController.cs | 42 ++++++++++++++++- .../Implement/StationReportRepository.cs | 46 +++++++++++++++++++ .../Interface/IStationReportRepository.cs | 1 + .../PowerStation/PowerStationEdit.cshtml | 2 +- SolarPower/Views/StationReport/Index.cshtml | 20 +++++++- 5 files changed, 108 insertions(+), 3 deletions(-) diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 42a07a9..b5d7f5a 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -2186,6 +2186,46 @@ namespace SolarPower.Controllers return Path.Combine("\\" + "upload", "report", Datename, "FIC太陽能監控平台" + "_" + "綜合報表" + "_" + postObject.Userid + Datename + ".xlsx"); } - + public async Task>> CheckExcel(Select_table2 post) + { + var ApiResult = new ApiResult>(); + var ErrorMessage = new List(); + foreach (var station in post.PowerStation) + { + var Id = Convert.ToInt32(station.Value); + var table = new Select_table() + { + FormType = post.FormType, + SearchType = post.SearchType, + PowerStation = Id, + Time = post.Time, + Userid = post.Userid + }; + var checkinv = await stationReportRepository.Findhaveinv(table); + var getinvsql = checkinv[0] as IDictionary; + if (getinvsql["mySelect"] == null) + { + ErrorMessage.Add(station.Name + "此時段無逆變器資料"); + } + else + { + var cid = await stationReportRepository.CheckExcelAsync(table); + if (cid == 0) + { + ErrorMessage.Add(station.Name + "此時段資料未建立"); + } + } + } + if(ErrorMessage.Count > 0) + { + ApiResult.Code = "9999"; + ApiResult.Data = ErrorMessage; + } + else + { + ApiResult.Code = "0000"; + } + return ApiResult; + } } } diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 0097d0d..00adb1f 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -257,6 +257,52 @@ namespace SolarPower.Repository.Implement } } + public async Task CheckExcelAsync(Select_table post) + { + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + int a; + conn.Open(); + try + { + string sql = ""; + switch ( post.FormType ) + { + case 0: + sql = @$"select Id from power_station_history_day where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = '{post.Time}'"; + break; + case 1: + if(post.SearchType == 2) + { + sql = @$"select Id from power_station_history_month where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = '{post.Time}'"; + } + else + { + var times = post.Time.Replace('-', 'a').Replace('/', '-').Replace(" ", "").Split('a'); + sql = @$"select Id from power_station_history_day where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') BETWEEN '{times[0]}' AND '{times[1]}'"; + } + break; + case 3: + sql = @$"select Id from power_station_history_month where powerstationid = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y') = '{post.Time}'"; + break; + } + a = await conn.QueryFirstOrDefaultAsync(sql); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return a; + } + } + + + + public async Task> GetHire (PsIdAndSiteDB post) { List result = new List(); diff --git a/SolarPower/Repository/Interface/IStationReportRepository.cs b/SolarPower/Repository/Interface/IStationReportRepository.cs index c3f1f8a..3edc23f 100644 --- a/SolarPower/Repository/Interface/IStationReportRepository.cs +++ b/SolarPower/Repository/Interface/IStationReportRepository.cs @@ -13,5 +13,6 @@ namespace SolarPower.Repository.Interface Task> GetHire(PsIdAndSiteDB post); Task> GetMaxtablebody(Select_table2 post); Task Findhaveinv(Select_table post); + Task CheckExcelAsync(Select_table post); } } diff --git a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml index 38a9bf5..ea46e76 100644 --- a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml +++ b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml @@ -1,5 +1,5 @@ @{ - ViewData["MainNum"] = "6"; + ViewData["MainNum"] = "8"; ViewData["SubNum"] = "1"; ViewData["Title"] = "電站管理"; } diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index 2274b9a..3b2739e 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -1225,7 +1225,25 @@ PowerStation: selecterd_invert } if (send_data.FormType != null && send_data.PowerStation.length != 0 && send_data.FormType != 2) { - window.location = "/StationReport/ExportExcel?post=" + JSON.stringify(send_data); + $.post("/StationReport/CheckExcel", send_data, function (rel) { + if (rel.code == "0000") { + window.location = "/StationReport/ExportExcel?post=" + JSON.stringify(send_data); + return; + } + else + { + var text = "原因如下:"; + $.each(rel.data, function (index, val) { + text += index + 1 + "." + val + ""; + }); + Swal.fire( + { + title: "Excel匯出失敗", + icon: 'warning', + html: text, + }); + } + }, 'json'); } else {