From acbd98c93f5f4cd73ab715ff3e453275e7c259ee Mon Sep 17 00:00:00 2001 From: "wanling040@gmail.com" Date: Wed, 17 Aug 2022 15:41:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=B5=B1=E7=AE=A1=E7=90=86-=E8=A3=9D?= =?UTF-8?q?=E7=BD=AE=E7=AE=A1=E7=90=86:=20=E8=A3=9D=E7=BD=AE=E7=B4=B0?= =?UTF-8?q?=E9=A0=85=E5=A2=9E=E5=8A=A0=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/SensorTypeController.cs | 96 ++++++++++++++++++- .../Implement/SensorDetailRepository.cs | 24 +++++ .../Interface/ISensorDetailRepository.cs | 1 + SolarPower/Views/SensorType/Index.cshtml | 53 ++++++++-- 4 files changed, 165 insertions(+), 9 deletions(-) diff --git a/SolarPower/Controllers/SensorTypeController.cs b/SolarPower/Controllers/SensorTypeController.cs index 860b3b2..a49b328 100644 --- a/SolarPower/Controllers/SensorTypeController.cs +++ b/SolarPower/Controllers/SensorTypeController.cs @@ -257,6 +257,98 @@ namespace SolarPower.Controllers return apiResult; } + /// + /// 取得單一裝置類型 + /// + /// + /// + [HttpPost] + public async Task> GetOneSensorTypeDetail(int id) + { + ApiResult apiResult = new ApiResult(); + + SensorDetail simpleSensorType = null; + + try + { + simpleSensorType = await sensorDetailRepository.GetOneDetailByIdAsync(id); + switch (simpleSensorType.HourType) + { + case "Sum": + simpleSensorType.HourTypeName = "總數"; + break; + case "Max": + simpleSensorType.HourTypeName = "最大值"; + break; + case "Min": + simpleSensorType.HourTypeName = "最小值"; + break; + case "Avg": + simpleSensorType.HourTypeName = "平均值"; + break; + default: + simpleSensorType.HourTypeName = "無資料"; + break; + } + switch (simpleSensorType.DayType) + { + case "Sum": + simpleSensorType.DayTypeName = "總數"; + break; + case "Max": + simpleSensorType.DayTypeName = "最大值"; + break; + case "Min": + simpleSensorType.DayTypeName = "最小值"; + break; + case "Avg": + simpleSensorType.DayTypeName = "平均值"; + break; + default: + simpleSensorType.DayTypeName = "無資料"; + break; + } + switch (simpleSensorType.MonthType) + { + case "Sum": + simpleSensorType.MonthTypeName = "總數"; + break; + case "Max": + simpleSensorType.MonthTypeName = "最大值"; + break; + case "Min": + simpleSensorType.MonthTypeName = "最小值"; + break; + case "Avg": + simpleSensorType.MonthTypeName = "平均值"; + break; + default: + simpleSensorType.MonthTypeName = "無資料"; + break; + } + + if (simpleSensorType == null) + { + apiResult.Code = "9998"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + apiResult.Code = "0000"; + apiResult.Data = simpleSensorType; + + } + 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; + } + /// /// 新增 / 修改 設備-細項資料 /// @@ -330,7 +422,7 @@ namespace SolarPower.Controllers SensorDetail update = new SensorDetail() { Id = sensorDetail.Id, - SensorTypeId = post.SensorTypeId, + //SensorTypeId = post.SensorTypeId, ItemName = post.ItemName, ItemEName = post.ItemEName, HourType = post.HourType, @@ -347,7 +439,7 @@ namespace SolarPower.Controllers List properties = new List() { "Id", - "SensorTypeId", + //"SensorTypeId", "ItemName", "ItemEName", "HourType", diff --git a/SolarPower/Repository/Implement/SensorDetailRepository.cs b/SolarPower/Repository/Implement/SensorDetailRepository.cs index e02b181..8946466 100644 --- a/SolarPower/Repository/Implement/SensorDetailRepository.cs +++ b/SolarPower/Repository/Implement/SensorDetailRepository.cs @@ -101,5 +101,29 @@ namespace SolarPower.Repository.Implement } } + /// + /// 透過sensorEName,取得單一筆資料 + /// + /// + /// + public async Task GetOneDetailByIdAsync(int id) + { + SensorDetail result; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + try + { + var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND Id = {id}"; + + result = await conn.QueryFirstOrDefaultAsync(sql); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + } } diff --git a/SolarPower/Repository/Interface/ISensorDetailRepository.cs b/SolarPower/Repository/Interface/ISensorDetailRepository.cs index 671ea6d..14c6279 100644 --- a/SolarPower/Repository/Interface/ISensorDetailRepository.cs +++ b/SolarPower/Repository/Interface/ISensorDetailRepository.cs @@ -31,6 +31,7 @@ namespace SolarPower.Repository.Interface /// /// Task GetOneSensorDetailAsync(int id); + Task GetOneDetailByIdAsync(int id); } } diff --git a/SolarPower/Views/SensorType/Index.cshtml b/SolarPower/Views/SensorType/Index.cshtml index 227fd97..c22eb9c 100644 --- a/SolarPower/Views/SensorType/Index.cshtml +++ b/SolarPower/Views/SensorType/Index.cshtml @@ -116,10 +116,10 @@
-
+ @*
-
+
*@
@@ -265,7 +265,7 @@ "data": "createdAt" }, { "data": null, - "defaultContent": ' ' + "defaultContent": ' ' }], "columnDefs": [{ 'targets': 2, @@ -435,7 +435,6 @@ $('#SensorType_table').on("click", "button.detail-btn", function () { $("#SensorDetail-modal .modal-title").html("裝置細項 - 新增"); $("#SensorDetail-form").trigger("reset"); - document.getElementById('SensorDetail_SensorType_modal').disabled = true; selected_id = 0; selected_type_id = $(this).parents('tr').attr('data-id'); @@ -460,9 +459,6 @@ return; } - //$("#SensorDetail_SensorType_modal").val(selected_type_id); - $("#SensorDetail_SensorType_modal").val(rel.data.sensorName); - $("#SensorDetail-modal").modal(); hideLoading(); }, 'json'); @@ -608,5 +604,48 @@ }); }); + + //#region 編輯裝置 + $('#SensorType_table').on("click", "button.detailEdit-btn", function () { + $("#SensorDetail-modal .modal-title").html("細項資料 - 修改"); + //document.getElementById('SensorDetail_SensorType_modal').display = none; + //document.getElementById('SensorDetail_SensorType_modal').disabled = true; + selected_id = $(this).parents('tr').attr('data-id'); + + //取得單一裝置 + showLoading(); + var url = "/SensorType/GetOneSensorTypeDetail/"; + + var send_data = { + id: selected_id + } + + $.post(url, send_data, function (rel) { + if (rel.code == "9999") { + hideLoading(); + toast_error(rel.msg); + return; + } + else if (rel.code == "9998") { + hideLoading(); + toast_error(rel.msg); + return; + } + + $("#SensorDetail_ItemName_modal").val(rel.data.itemName); + $("#SensorDetail_ItemEName_modal").val(rel.data.itemEName); + $("#SensorDetail_WarningURL_modal").val(rel.data.warningURL); + $("#SensorDetail_HourType_modal").val(rel.data.hourType); + $("#SensorDetail_DayType_modal").val(rel.data.dayType); + $("#SensorDetail_MonthType_modal").val(rel.data.monthType); + $("#SensorDetail_UpperValue_modal").val(rel.data.upperValue); + $("#SensorDetail_LowerValue_modal").val(rel.data.lowerValue); + + $("#SensorDetail-modal").modal(); + hideLoading(); + }, 'json'); + + }); + //#endregion } \ No newline at end of file