系統管理-裝置管理: 裝置細項增加修改功能

This commit is contained in:
wanling040@gmail.com 2022-08-17 15:41:16 +08:00
parent a759f1e58d
commit acbd98c93f
4 changed files with 165 additions and 9 deletions

View File

@ -257,6 +257,98 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
/// <summary>
/// 取得單一裝置類型
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<SensorDetail>> GetOneSensorTypeDetail(int id)
{
ApiResult<SensorDetail> apiResult = new ApiResult<SensorDetail>();
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;
}
/// <summary> /// <summary>
/// 新增 / 修改 設備-細項資料 /// 新增 / 修改 設備-細項資料
/// </summary> /// </summary>
@ -330,7 +422,7 @@ namespace SolarPower.Controllers
SensorDetail update = new SensorDetail() SensorDetail update = new SensorDetail()
{ {
Id = sensorDetail.Id, Id = sensorDetail.Id,
SensorTypeId = post.SensorTypeId, //SensorTypeId = post.SensorTypeId,
ItemName = post.ItemName, ItemName = post.ItemName,
ItemEName = post.ItemEName, ItemEName = post.ItemEName,
HourType = post.HourType, HourType = post.HourType,
@ -347,7 +439,7 @@ namespace SolarPower.Controllers
List<string> properties = new List<string>() List<string> properties = new List<string>()
{ {
"Id", "Id",
"SensorTypeId", //"SensorTypeId",
"ItemName", "ItemName",
"ItemEName", "ItemEName",
"HourType", "HourType",

View File

@ -101,5 +101,29 @@ namespace SolarPower.Repository.Implement
} }
} }
/// <summary>
/// 透過sensorEName取得單一筆資料
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<SensorDetail> 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<SensorDetail>(sql);
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
} }
} }

View File

@ -31,6 +31,7 @@ namespace SolarPower.Repository.Interface
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
Task<SensorDetail> GetOneSensorDetailAsync(int id); Task<SensorDetail> GetOneSensorDetailAsync(int id);
Task<SensorDetail> GetOneDetailByIdAsync(int id);
} }
} }

View File

@ -116,10 +116,10 @@
<form class="SensorDetail-form" id="SensorDetail-form"> <form class="SensorDetail-form" id="SensorDetail-form">
<div class="row"> <div class="row">
<div class="form-group col-lg-6"> @*<div class="form-group col-lg-6">
<label class="form-label" for="SensorDetail_SensorType_modal"><span class="text-danger">*</span>裝置類型</label> <label class="form-label" for="SensorDetail_SensorType_modal"><span class="text-danger">*</span>裝置類型</label>
<input type="text" id="SensorDetail_SensorType_modal" name="SensorDetail_SensorType_modal" class="form-control" disabled> <input type="text" id="SensorDetail_SensorType_modal" name="SensorDetail_SensorType_modal" class="form-control" disabled>
</div> </div>*@
<div class="form-group col-lg-6"> <div class="form-group col-lg-6">
<label class="form-label" for="SensorDetail_ItemName_modal"><span class="text-danger">*</span>項目名稱</label> <label class="form-label" for="SensorDetail_ItemName_modal"><span class="text-danger">*</span>項目名稱</label>
<input type="text" id="SensorDetail_ItemName_modal" name="SensorDetail_ItemName_modal" class="form-control"> <input type="text" id="SensorDetail_ItemName_modal" name="SensorDetail_ItemName_modal" class="form-control">
@ -265,7 +265,7 @@
"data": "createdAt" "data": "createdAt"
}, { }, {
"data": null, "data": null,
"defaultContent": '<button class="btn btn-success detail-btn">新增細項</button><button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>' "defaultContent": '<button class="btn btn-success detail-btn">新增細項</button><button class="btn btn-secondary detailEdit-btn">修改細項</button><button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>'
}], }],
"columnDefs": [{ "columnDefs": [{
'targets': 2, 'targets': 2,
@ -435,7 +435,6 @@
$('#SensorType_table').on("click", "button.detail-btn", function () { $('#SensorType_table').on("click", "button.detail-btn", function () {
$("#SensorDetail-modal .modal-title").html("裝置細項 - 新增"); $("#SensorDetail-modal .modal-title").html("裝置細項 - 新增");
$("#SensorDetail-form").trigger("reset"); $("#SensorDetail-form").trigger("reset");
document.getElementById('SensorDetail_SensorType_modal').disabled = true;
selected_id = 0; selected_id = 0;
selected_type_id = $(this).parents('tr').attr('data-id'); selected_type_id = $(this).parents('tr').attr('data-id');
@ -460,9 +459,6 @@
return; return;
} }
//$("#SensorDetail_SensorType_modal").val(selected_type_id);
$("#SensorDetail_SensorType_modal").val(rel.data.sensorName);
$("#SensorDetail-modal").modal(); $("#SensorDetail-modal").modal();
hideLoading(); hideLoading();
}, 'json'); }, '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
</script> </script>
} }