From 196b00595a298cbfc81f1eb2cb4e3499bb05c5df Mon Sep 17 00:00:00 2001 From: b110212000 Date: Wed, 4 Aug 2021 10:29:11 +0800 Subject: [PATCH 1/3] .. --- .../ElectricitySoldRecordController.cs | 43 ++++++++++-- .../ElectricitySoldRecordRepository.cs | 69 ++++++++++++++----- .../Views/ElectricitySoldRecord/Index.cshtml | 41 ++++++++++- 3 files changed, 128 insertions(+), 25 deletions(-) diff --git a/SolarPower/Controllers/ElectricitySoldRecordController.cs b/SolarPower/Controllers/ElectricitySoldRecordController.cs index e209466..6b5b7b6 100644 --- a/SolarPower/Controllers/ElectricitySoldRecordController.cs +++ b/SolarPower/Controllers/ElectricitySoldRecordController.cs @@ -68,7 +68,6 @@ namespace SolarPower.Controllers UpdatedBy = myUser.Id, Kwh = post.Kwh, Money = post.Money, - PowerstationId = post.PowerstationId, StartAt = post.StartAt }; List properties = new List() @@ -78,7 +77,6 @@ namespace SolarPower.Controllers "UpdatedBy", "Kwh", "Money", - "PowerstationId", "StartAt" }; await electricitySoldRecordRepository.Update(record, properties); @@ -99,21 +97,30 @@ namespace SolarPower.Controllers return apiResult; } + [HttpPost] public async Task RecordTable(ElectricitySoldRecordTablePost info) { List electricitySoldRecordTable = new List(); ApiResult> apiResult = new ApiResult>(); try { - electricitySoldRecordTable = await electricitySoldRecordRepository.RecordTable(info); - foreach (ElectricitySoldRecordTable a in electricitySoldRecordTable) + if(info.StationId == null || info.Time == null) { - a.Function = @" + apiResult.Code = "0000"; + } + else + { + electricitySoldRecordTable = await electricitySoldRecordRepository.RecordTable(info); + foreach (ElectricitySoldRecordTable a in electricitySoldRecordTable) + { + a.Function = @" "; + a.CreatedDay = Convert.ToDateTime(a.CreatedAt).ToString("yyyy-MM-dd"); + } + apiResult.Code = "0000"; + apiResult.Data = electricitySoldRecordTable; } - apiResult.Code = "0000"; - apiResult.Data = electricitySoldRecordTable; } catch (Exception exception) { @@ -129,5 +136,27 @@ namespace SolarPower.Controllers }); return result; } + + public async Task> GetOnePowerStation(int id) + { + ApiResult apiResult = new ApiResult(); + ElectricitySoldRecord record = new ElectricitySoldRecord(); + try + { + record = await electricitySoldRecordRepository.GetOneAsync(id); + apiResult.Code = "0000"; + apiResult.Data = record; + + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } } } diff --git a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs index cf69909..d11d164 100644 --- a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs +++ b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs @@ -1,8 +1,10 @@ -using SolarPower.Helper; +using Dapper; +using SolarPower.Helper; using SolarPower.Models; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Threading.Tasks; @@ -16,26 +18,61 @@ namespace SolarPower.Repository.Implement } public async Task> RecordTable (ElectricitySoldRecordTablePost post) { - List a = new List(); + string sql = ""; + List ids = new List(); + foreach(var id in post.StationId) + { + ids.Add(Convert.ToInt32(id.Value)); + } + + switch (post.SearchType) { - //case 0: - // post.Time.Replace("-","~").Replace("") - // sql = ""; - // break; - //case 1: - // sql = ""; - // break; - //case 2: - // sql = ""; - // break; - //case 3: - // sql = ""; - // break; + case 0: + post.Time = post.Time.Replace(" ", ""); + post.Time = post.Time.Replace("-", "~"); + post.Time = post.Time.Replace("/", "-"); + var time = post.Time.Split("~"); + sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + LEFT JOIN power_station ps ON es.PowerstationId = ps.Id + WHERE es.StartAt BETWEEN '{time[0]}' AND '{time[1]}' AND es.PowerstationId IN @ids"; + break; + case 1: + post.Time = post.Time.Replace(" ", ""); + post.Time = post.Time.Replace("-", "~"); + post.Time = post.Time.Replace("/", "-"); + var time1 = post.Time.Split("~"); + sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + LEFT JOIN power_station ps ON es.PowerstationId = ps.Id + WHERE es.StartAt BETWEEN '{time1[0]}' AND '{time1[1]}' AND es.PowerstationId IN @ids"; + sql = ""; + break; + case 2: + sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + LEFT JOIN power_station ps ON es.PowerstationId = ps.Id + WHERE DATE_FORMAT(es.StartAt , '%Y-%m') = '{post.Time}' AND es.PowerstationId IN @ids"; + break; + case 3: + sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + LEFT JOIN power_station ps ON es.PowerstationId = ps.Id + WHERE DATE_FORMAT(es.StartAt , '%Y') = '{post.Time}' AND es.PowerstationId IN @ids"; + break; + } + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + List a = new List(); + try + { + a = (await conn.QueryAsync(sql,new { ids = ids})).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return a; } - return a; } } } diff --git a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml index a854a67..eadd9bf 100644 --- a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml +++ b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml @@ -243,9 +243,10 @@ } \ No newline at end of file From ca631fc115a2b86aa0659dc350217536ce1951ff Mon Sep 17 00:00:00 2001 From: b110212000 Date: Wed, 4 Aug 2021 14:05:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=8F=B0=E9=9B=BB=E5=94=AE=E9=9B=BB?= =?UTF-8?q?=E7=B4=80=E9=8C=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricitySoldRecordController.cs | 23 +++++++ .../Controllers/StationReportController.cs | 2 +- .../ElectricitySoldRecordRepository.cs | 8 +-- .../Views/ElectricitySoldRecord/Index.cshtml | 64 ++++++++++++++++--- 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/SolarPower/Controllers/ElectricitySoldRecordController.cs b/SolarPower/Controllers/ElectricitySoldRecordController.cs index 6b5b7b6..a256397 100644 --- a/SolarPower/Controllers/ElectricitySoldRecordController.cs +++ b/SolarPower/Controllers/ElectricitySoldRecordController.cs @@ -153,10 +153,33 @@ namespace SolarPower.Controllers apiResult.Code = "9999"; Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } apiResult.Msg = errorCode.GetString(apiResult.Code); return apiResult; } + + public async Task> DeleteRecord(int id) + { + ApiResult apiResult = new ApiResult(); + try + { + await electricitySoldRecordRepository.DeleteOne(id); + apiResult.Code = "0000"; + apiResult.Msg = "刪除成功"; + + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + + } } } diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 2fb27a3..a417625 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -1181,7 +1181,7 @@ namespace SolarPower.Controllers { Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename)); } - var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", "FIC太陽能監控平台" + "_" + name + "報表" + "_" + postObject.Userid + Datename + ".xlsx"); + var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename, "FIC太陽能監控平台" + "_" + name + "報表" + "_" + postObject.Userid + Datename + ".xlsx"); FileStream FS = new FileStream(n, FileMode.Create, FileAccess.Write); workbook.Write(FS); FS.Close(); diff --git a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs index d11d164..d6b6c7f 100644 --- a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs +++ b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs @@ -36,7 +36,7 @@ namespace SolarPower.Repository.Implement var time = post.Time.Split("~"); sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id - WHERE es.StartAt BETWEEN '{time[0]}' AND '{time[1]}' AND es.PowerstationId IN @ids"; + WHERE es.StartAt BETWEEN '{time[0]}' AND '{time[1]}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; break; case 1: post.Time = post.Time.Replace(" ", ""); @@ -45,18 +45,18 @@ namespace SolarPower.Repository.Implement var time1 = post.Time.Split("~"); sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id - WHERE es.StartAt BETWEEN '{time1[0]}' AND '{time1[1]}' AND es.PowerstationId IN @ids"; + WHERE es.StartAt BETWEEN '{time1[0]}' AND '{time1[1]}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; sql = ""; break; case 2: sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id - WHERE DATE_FORMAT(es.StartAt , '%Y-%m') = '{post.Time}' AND es.PowerstationId IN @ids"; + WHERE DATE_FORMAT(es.StartAt , '%Y-%m') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; break; case 3: sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es LEFT JOIN power_station ps ON es.PowerstationId = ps.Id - WHERE DATE_FORMAT(es.StartAt , '%Y') = '{post.Time}' AND es.PowerstationId IN @ids"; + WHERE DATE_FORMAT(es.StartAt , '%Y') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; break; } using (IDbConnection conn = this._databaseHelper.GetConnection()) diff --git a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml index eadd9bf..32788f1 100644 --- a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml +++ b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml @@ -491,6 +491,7 @@ if ($("#Record-form").valid()) { var url = "/ElectricitySoldRecord/SaveSoldMoney"; var send_data = { + Id: selected_id, StartAt: $("#StartTime_modal").val(), EndAt: $("#EndTime_modal").val(), Kwh: $("#BuyKwh_modal").val(), @@ -505,8 +506,8 @@ } else { toast_ok(rel.msg); - //$('#ShareDevice-modal').modal('hide'); - //ShareDeviceTable.ajax.reload(); + $('#Record-modal').modal('hide'); + RecordTable.ajax.reload(); return; } @@ -604,17 +605,14 @@ } $('#RecordTable').on("click", "button.edit-btn", function () { - $("#Operation-modal .modal-title").html("運維廠商資料 - 編輯"); - + $("#Record-modal .modal-title").html("台電售電紀錄 - 編輯"); selected_id = $(this).parents('tr').attr('data-id'); var powerstationName = $(this).parents('tr').attr('powerstation-Name'); //取得單一運維基本資料 var url = "/ElectricitySoldRecord/GetOnePowerStation/"; - var send_data = { Id: selected_id } - $.post(url, send_data, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); @@ -622,18 +620,66 @@ } $('#PowerStationId_modal').empty(); $("#PowerStationId_modal").attr("disabled", true); - $("#PowerStationId_modal").append($("