From b757669d144f6ceafcd4dd8ebfc9bad661b2d8b1 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Fri, 18 Jun 2021 03:20:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=95=B0=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PowerStationController.cs | 230 +++++++++++++++- SolarPower/Helper/DatabaseHelper.cs | 2 +- SolarPower/Models/PowerStation.cs | 19 ++ .../Implement/PowerStationRepository.cs | 117 ++++++++ .../Interface/IPowerStationRepository.cs | 24 ++ .../PowerStation/PowerStationEdit.cshtml | 255 ++++++++++++++++-- .../Views/PowerStation/_DeviceSetting.cshtml | 43 --- .../Views/PowerStation/_Exception.cshtml | 73 +++++ 8 files changed, 699 insertions(+), 64 deletions(-) create mode 100644 SolarPower/Views/PowerStation/_Exception.cshtml diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 7e7c324..a10b9ae 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -843,7 +843,8 @@ namespace SolarPower.Controllers TableName = Device.TableName, Type = Device.Type, UID = Device.PowerStationId + "-" + Device.Type, - CreatedBy = myUser.Id + CreatedBy = myUser.Id, + TypeName = Device.TypeName }; List properties = new List() { @@ -858,7 +859,8 @@ namespace SolarPower.Controllers "TableName", "Type", "UID", - "CreatedBy" + "CreatedBy", + "TypeName" }; await powerStationRepository.AddDevice(DeviceInfo,properties); @@ -880,7 +882,8 @@ namespace SolarPower.Controllers TableName = Device.TableName, Type = Device.Type, UID = Device.PowerStationId + "-" + Device.Type, - CreatedBy = myUser.Id + CreatedBy = myUser.Id, + TypeName = Device.TypeName }; List properties = new List() { @@ -895,7 +898,8 @@ namespace SolarPower.Controllers "TableName", "Type", "UID", - "CreatedBy" + "CreatedBy", + "TypeName" }; await powerStationRepository.UpdateDevice(DeviceInfo, properties); apiResult.Code = "0000"; @@ -910,7 +914,11 @@ namespace SolarPower.Controllers } return apiResult; } - + /// + /// 設備DataTable + /// + /// + /// public async Task DeviceTable(int stationId) { List deviceTables = new List(); @@ -976,6 +984,218 @@ namespace SolarPower.Controllers Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } + return apiResult; + } + /// + /// 取單一設備資料 + /// + /// + /// + public async Task> GetOneDevice(int id) + { + DeviceInfo Device = new DeviceInfo(); + ApiResult apiResult = new ApiResult(); + try + { + apiResult.Code = "0000"; + Device = await powerStationRepository.OneDeviceInfo(id); + apiResult.Data = Device; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + + return apiResult; + } + /// + /// 刪除設備 + /// + /// + /// + public async Task> DeleteOneDevice(int id) + { + ApiResult apiResult = new ApiResult(); + DeviceInfo Device = new DeviceInfo(); + try + { + Device = await powerStationRepository.OneDeviceInfo(id); + + if (Device == null) + { + apiResult.Code = "9996"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + await powerStationRepository.DeleteOneOtherTable(Device.Id, "device"); + + 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; + } + + public async Task> SaveException(ExceptionModal exceptionModal) + { + ApiResult apiResult = new ApiResult(); + try + { + if (exceptionModal.Id == 0) + { + ExceptionModal Exception = new ExceptionModal() + { + Alarm = exceptionModal.Alarm, + CreatedBy = myUser.Id, + PowerStationId = exceptionModal.PowerStationId, + Id = exceptionModal.Id, + LowerLimit = exceptionModal.LowerLimit, + Type = exceptionModal.Type, + UpperLimit = exceptionModal.UpperLimit + }; + List properties = new List() + { + "Alarm", + "CreatedBy", + "PowerStationId", + "Id", + "LowerLimit", + "Type", + "UpperLimit", + }; + await powerStationRepository.AddException(Exception, properties); + + apiResult.Code = "0000"; + apiResult.Msg = "新增成功"; + } + else + { + ExceptionModal Exception = new ExceptionModal() + { + Alarm = exceptionModal.Alarm, + CreatedBy = myUser.Id, + PowerStationId = exceptionModal.PowerStationId, + Id = exceptionModal.Id, + LowerLimit = exceptionModal.LowerLimit, + Type = exceptionModal.Type, + UpperLimit = exceptionModal.UpperLimit + }; + List properties = new List() + { + "Alarm", + "CreatedBy", + "PowerStationId", + "Id", + "LowerLimit", + "Type", + "UpperLimit", + }; + await powerStationRepository.UpdateException(Exception, properties); + apiResult.Code = "0000"; + apiResult.Msg = "儲存成功"; + } + + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + return apiResult; + } + + public async Task ExceptionTable(int stationId) + { + List exceptionTable = new List(); + ApiResult> apiResult = new ApiResult>(); + try + { + apiResult.Code = "0000"; + exceptionTable = await powerStationRepository.ExceptionTable(stationId); + foreach (ExceptionTable a in exceptionTable) + { + a.Function = @" + + "; + if(a.Type == 1) + { + a.TypeName = "PR值"; + } + if (a.Alarm == 1) + { + a.AlarmName = "email通知"; + } + } + apiResult.Data = exceptionTable; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + var result = Json(new + { + data = apiResult + }); + return result; + } + + public async Task> GetOneException(int id) + { + ExceptionModal Exception = new ExceptionModal(); + ApiResult apiResult = new ApiResult(); + try + { + apiResult.Code = "0000"; + Exception = await powerStationRepository.OneException(id); + apiResult.Data = Exception; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + + return apiResult; + } + + public async Task> DeleteOneException(int id) + { + ApiResult apiResult = new ApiResult(); + ExceptionModal Exception = new ExceptionModal(); + try + { + Exception = await powerStationRepository.OneException(id); + + if (Exception == null) + { + apiResult.Code = "9996"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + await powerStationRepository.DeleteOneOtherTable(Exception.Id, "power_station_exception"); + + 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/Helper/DatabaseHelper.cs b/SolarPower/Helper/DatabaseHelper.cs index b359893..2e57aa3 100644 --- a/SolarPower/Helper/DatabaseHelper.cs +++ b/SolarPower/Helper/DatabaseHelper.cs @@ -37,7 +37,7 @@ namespace SolarPower.Helper var passwordStr = ed.DESDecrypt(dbConfig.Password); //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; - var connStr = @"server=127.0.0.1;database=solar_power;user=root;password=000000;charset=utf8;"; + var connStr = @"server=127.0.0.1;port=3308;database=solar_power;user=root;password=00000000;charset=utf8;"; this._connectionString = connStr; } diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 67bce18..c52d9df 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -321,6 +321,7 @@ namespace SolarPower.Models.PowerStation public string TableName { get; set; } public string ColName { get; set; } public string Remark { get; set; } + public string TypeName { get; set; }//類型名稱 } public class Device : DeviceInfo { @@ -332,4 +333,22 @@ namespace SolarPower.Models.PowerStation public string UID { get; set; }//設備編號 public string Function { get; set; }//功能 } + public class ExceptionModal : Created + { + public int Id { get; set; } + public int PowerStationId { get; set; } + public byte Type { get; set; } + public decimal UpperLimit { get; set; } + public decimal LowerLimit { get; set; } + public byte Alarm { get; set; } + } + public class ExceptionTable : ExceptionModal + { + public string PowerStationName { get; set; } + public string PowerStationCode { get; set; } + public string Function { get; set; }//功能 + public string TypeName { get; set; } + public string AlarmName { get; set; } + } + } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 029c9e2..295d551 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -641,5 +641,122 @@ namespace SolarPower.Repository.Implement return Device; } + public async Task OneDeviceInfo(int id) + { + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + DeviceInfo Device; + conn.Open(); + try + { + string sql = @$"SELECT * FROM device WHERE Id = @Id"; + Device = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return Device; + } + } + + public async Task AddException(ExceptionModal Exception, List properties) + { + using IDbConnection conn = _databaseHelper.GetConnection(); + conn.Open(); + try + { + string sql = GenerateInsertQueryWithCustomTable(properties, "power_station_exception"); + + await conn.ExecuteAsync(sql, Exception); + + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + } + + /// + /// 異常dataTable + /// + /// + /// + public async Task> ExceptionTable(int stationId) + { + using IDbConnection conn = _databaseHelper.GetConnection(); + conn.Open(); + List Exception = new List(); + try + { + string sql = @$"SELECT pe.Type,pe.UpperLimit,pe.LowerLimit,pe.Alarm,ps.Code AS PowerStationCode ,ps.Name AS PowerStationName,pe.CreatedAt,pe.Id + FROM power_station_exception pe + LEFT JOIN power_station ps ON pe.PowerStationId = ps.Id + WHERE pe.Deleted = 0 AND pe.PowerStationId = @StationId"; + Exception = (await conn.QueryAsync(sql, new { StationId = stationId })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return Exception; + } + + public async Task OneException(int id) + { + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + ExceptionModal Exception; + conn.Open(); + try + { + string sql = @$"SELECT * FROM power_station_exception WHERE Id = @Id"; + Exception = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return Exception; + } + } + + public async Task UpdateException(ExceptionModal Exception, List properties) + { + using IDbConnection conn = _databaseHelper.GetConnection(); + conn.Open(); + var trans = conn.BeginTransaction(); + try + { + var updateQuery = GenerateUpdateQueryWithCustomTable(properties, "power_station_exception"); + await conn.ExecuteAsync(updateQuery.ToString(), Exception, trans); + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index d542640..8836ebb 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -131,5 +131,29 @@ namespace SolarPower.Repository.Interface /// /// Task> DeviceTable(int stationId); + + /// + /// 異常datatable + /// + /// + /// + Task> ExceptionTable(int stationId); + /// + /// 取單一筆DeviceInfo + /// + /// + /// + Task OneDeviceInfo(int id); + /// + /// 新增 異常設定 + /// + /// + /// + /// + Task AddException(ExceptionModal Exception, List properties); + + Task OneException(int id); + + Task UpdateException(ExceptionModal Exception, List properties); } } diff --git a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml index 9836ba5..cb2aebc 100644 --- a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml +++ b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml @@ -52,7 +52,7 @@ @@ -74,10 +74,8 @@ @Html.Partial("_UploadImage") -
-
- 此處放異常設定數據 -
+
+ @Html.Partial("_Exception")
@@ -178,7 +176,7 @@ } }); //#endregion - //#region 運維列表 DataTable + //#region 設備列表 DataTable DeviceTable = $("#Device_table").DataTable({ "paging": true, "lengthChange": false, @@ -189,17 +187,17 @@ "responsive": true, "order": [[9, "desc"]], "columns": [{ - "data": "uID" + "data": "uid" }, { "data": "name" }, { - "data": "type" + "data": "typeName" }, { "data": "brand" }, { "data": "productModel" }, { - "data": "dBName" + "data": "dbName" }, { "data": "tableName" }, { @@ -262,6 +260,87 @@ } } }); + //#endregion + //#region 異常設定列表 DataTable + ExceptionTable = $("#Exception_table").DataTable({ + "paging": true, + "lengthChange": false, + "searching": false, + "ordering": true, + "info": true, + "autoWidth": false, + "responsive": true, + "order": [[7, "desc"]], + "columns": [{ + "data": "powerStationCode" + }, { + "data": "powerStationName" + }, { + "data": "typeName" + }, { + "data": "upperLimit" + }, { + "data": "lowerLimit" + }, { + "data": "alarmName" + }, { + "data": "createdAt" + }, { + "data": "function" + }], + "columnDefs": [{ + 'targets': 1, + 'searchable': false, + 'orderable': false, + 'className': 'dt-body-center' + }], + "language": { + "emptyTable": "無資料...", + "processing": "處理中...", + "loadingRecords": "載入中...", + "lengthMenu": "顯示 _MENU_ 項結果", + "zeroRecords": "沒有符合的結果", + "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項", + "infoEmpty": "顯示第 0 至 0 項結果,共 0 項", + "infoFiltered": "(從 _MAX_ 項結果中過濾)", + "infoPostFix": "", + "search": "搜尋:", + "paginate": { + "first": "第一頁", + "previous": "上一頁", + "next": "下一頁", + "last": "最後一頁" + }, + "aria": { + "sortAscending": ": 升冪排列", + "sortDescending": ": 降冪排列" + } + }, + 'createdRow': function (row, data, dataIndex) { + $(row).attr('data-id', data.id); + }, + "ajax": { + "url": "/PowerStation/ExceptionTable", + "type": "POST", + "data": function (d) { + d.stationId = stationId; + }, + "dataSrc": function (rel) { + if (rel.data.code == "9999") { + toast_error(rel.data.msg); + return; + } + + data = rel.data.data; + + if (data == null || data.length == 0) { + this.data = []; + } + + return data; + } + } + }); //#endregion //#region 電站資料 view 控制 if (stationId == 'new') { @@ -942,7 +1021,7 @@ //加入新增土地房屋卡片 CreateAddLandBuildingCard(landBuildingCard); } - + //#endregion //#region 創建每份土地房屋資訊卡片 function CreateLandBuildingCard(dom, value) { var appendStr = ""; @@ -1143,7 +1222,7 @@ } - + //#endregion //#region 新增維運資料 function AddOperation() { @@ -1217,6 +1296,29 @@ }); //#endregion //#region 刪除運維 + $('#Device_table').on("click", "button.del-btn", function () { + + selected_id = $(this).parents('tr').attr('data-id'); + + var url = "/PowerStation/DeleteOneDevice/"; + + var send_data = { + Id: selected_id + } + + $.post(url, send_data, function (rel) { + if (rel.code == "9999") { + toast_error(rel.msg); + return; + } + + toast_ok(rel.msg); + DeviceTable.ajax.reload(); + }, 'json'); + + }); + //#endregion + //#region 刪除設備 $('#Operation_table').on("click", "button.del-btn", function () { selected_id = $(this).parents('tr').attr('data-id'); @@ -1246,7 +1348,13 @@ $("#Device-modal").modal(); } //#endregion - + //#region 新增異常設定資料 + function AddException() { + $("#Exception-modal .modal-title").html("異常設定資料 - 新增"); + $("#Exception-form").trigger("reset"); + $("#Exception-modal").modal(); + } + //#endregion //#region 儲存裝置資料 function SaveDevice() { @@ -1257,12 +1365,14 @@ PowerStationId: stationId, Name: $("#Device_Name_modal").val(), Type: $("#Device_Type_modal").val(), + TypeName: $("#Device_Type_modal :selected").text(), Brand: $("#Device_Brand_modal").val(), ProductModel: $("#Device_ProductModel_modal").val(), DBName: $("#Device_DBName_modal").val(), TableName: $("#Device_TableName_modal").val(), ColName: $("#Device_ColName_modal").val(), - Remark: $("#Device_Remark_modal").val(), + Remark: $("#Device_Remark_modal").val() + } $.post(url, send_data, function (rel) { if (rel.code != "0000") { @@ -1272,6 +1382,7 @@ else { toast_ok(rel.msg); $('#Device-modal').modal('hide'); + DeviceTable.ajax.reload(); return; } @@ -1280,9 +1391,66 @@ } } //#endregion - - + //#region 儲存異常設定資料 + function SaveException() { + if ($("#Exception-form").valid()) { + var url = "/PowerStation/SaveException"; + var send_data = { + Id: selected_id, + PowerStationId: stationId, + Type: $("#Exception_Type_modal").val(), + UpperLimit: $("#Exception_UpperLimit_modal").val(), + LowerLimit: $("#Exception_LowerLimit_modal").val(), + Alarm: $("#Exception_Alarm_modal").val() + } + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + else { + toast_ok(rel.msg); + $('#Exception-modal').modal('hide'); + ExceptionTable.ajax.reload(); + return; + } + + + }, 'json'); + } + } + //#endregion + //#region 取一筆異常設定 + $('#Exception_table').on("click", "button.edit-btn", function () { + $("#Exception-modal .modal-title").html("異常設定資料 - 編輯"); + + selected_id = $(this).parents('tr').attr('data-id'); + + //取得單一異常設定資料 + var url = "/PowerStation/GetOneException/"; + + var send_data = { + id: selected_id + } + + + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + $("#Exception_Type_modal").val(rel.data.type); + $("#Exception_Alarm_modal").val(rel.data.alarm); + $("#Exception_UpperLimit_modal").val(rel.data.upperLimit); + $("#Exception_LowerLimit_modal").val(rel.data.lowerLimit); + + $("#Exception-modal").modal(); + }, 'json'); + + }); + //#endregion //#region 土地與房屋按鈕控制 //儲存 $('#land_buildingPart').on("click", "button.save-land-building-info-btn", function () { @@ -1353,5 +1521,62 @@ $("#add-land-building-card button#cancel-add-land-building-info-btn").hide(); }); //#endregion + //#region 取一筆設備 + $('#Device_table').on("click", "button.edit-btn", function () { + $("#Device-modal .modal-title").html("設備資料 - 編輯"); + + selected_id = $(this).parents('tr').attr('data-id'); + + //取得單一運維基本資料 + var url = "/PowerStation/GetOneDevice/"; + + var send_data = { + id: selected_id + } + + + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + $("#Device_Name_modal").val(rel.data.name); + $("#Device_Type_modal").val(rel.data.type); + $("#Device_Brand_modal").val(rel.data.brand); + $("#Device_ProductModel_modal").val(rel.data.productModel); + $("#Device_DBName_modal").val(rel.data.dbName); + $("#Device_TableName_modal").val(rel.data.tableName); + $("#Device_ColName_modal").val(rel.data.colName); + $("#Device_Remark_modal").val(rel.data.remark); + $("#Device-modal").modal(); + }, 'json'); + + }); + //#endregion + + //#region 刪除運維 + $('#Exception_table').on("click", "button.del-btn", function () { + + selected_id = $(this).parents('tr').attr('data-id'); + + var url = "/PowerStation/DeleteOneException/"; + + var send_data = { + Id: selected_id + } + + $.post(url, send_data, function (rel) { + if (rel.code == "9999") { + toast_error(rel.msg); + return; + } + + toast_ok(rel.msg); + ExceptionTable.ajax.reload(); + }, 'json'); + + }); + //#endregion } \ No newline at end of file diff --git a/SolarPower/Views/PowerStation/_DeviceSetting.cshtml b/SolarPower/Views/PowerStation/_DeviceSetting.cshtml index 466c389..5922416 100644 --- a/SolarPower/Views/PowerStation/_DeviceSetting.cshtml +++ b/SolarPower/Views/PowerStation/_DeviceSetting.cshtml @@ -22,49 +22,6 @@ - - PEP-NTP001-PYR-01 - 日照計01 - 日照計 - ADTEK - CS1 - - CS1 - - - - - - - - PEP-NTP001-THR-01 - 溫度計03 - 溫度計 - ADTEK - CS1 - - CS1 - - - - - - - - 05101300967-PWR - 電表01 - 電表 - ADTEK - CS1 - - CS1 - - - - - - - diff --git a/SolarPower/Views/PowerStation/_Exception.cshtml b/SolarPower/Views/PowerStation/_Exception.cshtml new file mode 100644 index 0000000..0709db5 --- /dev/null +++ b/SolarPower/Views/PowerStation/_Exception.cshtml @@ -0,0 +1,73 @@ +
+

異常自動檢查設定

+ +
+ + + + + + + + + + + + + + + +
電站編號電站名稱項目下限 ( <= )上限 ( >= )警示方式建立時間功能
+
+
+ + \ No newline at end of file From e8873251d1199a47b5305a16118a95dc7b4062b3 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Fri, 18 Jun 2021 10:03:15 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=A8=BB=E8=A7=A3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PowerStationController.cs | 25 +++++++++--- SolarPower/Models/PowerStation.cs | 12 ++++++ .../Implement/PowerStationRepository.cs | 40 ++++++++++++++++--- .../Interface/IPowerStationRepository.cs | 30 +++++++++++++- 4 files changed, 94 insertions(+), 13 deletions(-) diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index a10b9ae..01780dc 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -946,7 +946,6 @@ namespace SolarPower.Controllers }); return result; } - /// /// 軟刪除單一土地房屋資訊 /// @@ -1044,7 +1043,11 @@ namespace SolarPower.Controllers return apiResult; } - + /// + /// 新增/修改異常 + /// + /// + /// public async Task> SaveException(ExceptionModal exceptionModal) { ApiResult apiResult = new ApiResult(); @@ -1112,7 +1115,11 @@ namespace SolarPower.Controllers } return apiResult; } - + /// + /// 異常dataTable + /// + /// + /// public async Task ExceptionTable(int stationId) { List exceptionTable = new List(); @@ -1148,7 +1155,11 @@ namespace SolarPower.Controllers }); return result; } - + /// + /// 取一筆異常設定 + /// + /// + /// public async Task> GetOneException(int id) { ExceptionModal Exception = new ExceptionModal(); @@ -1167,7 +1178,11 @@ namespace SolarPower.Controllers return apiResult; } - + /// + /// 刪除一筆異常設定 + /// + /// + /// public async Task> DeleteOneException(int id) { ApiResult apiResult = new ApiResult(); diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index c52d9df..e18f2e7 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -301,6 +301,9 @@ namespace SolarPower.Models.PowerStation { public List Type { get; set; } } + /// + /// 表Variable 取來解析 + /// public class Variable { public string name { get; set; } @@ -328,11 +331,17 @@ namespace SolarPower.Models.PowerStation public string UID { get; set; }//設備編號 public int CreatedBy { get; set; }//建立者 } + /// + ///設備dataTable + /// public class DeviceTable : DeviceInfo { public string UID { get; set; }//設備編號 public string Function { get; set; }//功能 } + /// + /// 異常modal + /// public class ExceptionModal : Created { public int Id { get; set; } @@ -342,6 +351,9 @@ namespace SolarPower.Models.PowerStation public decimal LowerLimit { get; set; } public byte Alarm { get; set; } } + /// + /// 異常設定Table + /// public class ExceptionTable : ExceptionModal { public string PowerStationName { get; set; } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 295d551..f7ddb09 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -406,8 +406,13 @@ namespace SolarPower.Repository.Implement } } } - + /// + /// 新增運維 + /// + /// + /// + /// public async Task AddOperation(OperationInfo operation, List properties) { using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -493,7 +498,12 @@ namespace SolarPower.Repository.Implement return operation; } } - + /// + /// 更新運維 + /// + /// + /// + /// public async Task UpdateOperation(OperationInfo operation , List properties) { using IDbConnection conn = _databaseHelper.GetConnection(); @@ -640,7 +650,11 @@ namespace SolarPower.Repository.Implement } return Device; } - + /// + /// 取單一筆DeviceInfo + /// + /// + /// public async Task OneDeviceInfo(int id) { using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -663,7 +677,12 @@ namespace SolarPower.Repository.Implement return Device; } } - + /// + /// 新增 異常設定 + /// + /// + /// + /// public async Task AddException(ExceptionModal Exception, List properties) { using IDbConnection conn = _databaseHelper.GetConnection(); @@ -713,7 +732,11 @@ namespace SolarPower.Repository.Implement } return Exception; } - + /// + /// 取一筆異常設定 + /// + /// + /// public async Task OneException(int id) { using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -736,7 +759,12 @@ namespace SolarPower.Repository.Implement return Exception; } } - + /// + /// 更新異常設定 + /// + /// + /// + /// public async Task UpdateException(ExceptionModal Exception, List properties) { using IDbConnection conn = _databaseHelper.GetConnection(); diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 8836ebb..19548d4 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -98,6 +98,12 @@ namespace SolarPower.Repository.Interface /// /// Task DeleteOneLandBuildingInfo(int id); + /// + /// 新增運維 + /// + /// + /// + /// Task AddOperation(OperationInfo operation, List properties); /// /// 運維dataTable @@ -105,7 +111,18 @@ namespace SolarPower.Repository.Interface /// /// Task> OperationTable (int stationId); + /// + /// 取一筆運維 + /// + /// + /// Task OneOperationInfo (int stationId); + /// + /// 更新運維 + /// + /// + /// + /// Task UpdateOperation(OperationInfo operation, List properties); /// /// 裝置類型下拉式選單 @@ -151,9 +168,18 @@ namespace SolarPower.Repository.Interface /// /// Task AddException(ExceptionModal Exception, List properties); - + /// + /// 取一筆異常設定 + /// + /// + /// Task OneException(int id); - + /// + /// 更新異常設定 + /// + /// + /// + /// Task UpdateException(ExceptionModal Exception, List properties); } } From 9cf929df5fc6ac9254097eca60afcb7f088a6776 Mon Sep 17 00:00:00 2001 From: Kai Date: Fri, 18 Jun 2021 10:45:44 +0800 Subject: [PATCH 3/4] =?UTF-8?q?1.=E9=9B=BB=E7=AB=99=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E8=B3=87=E6=96=99=E9=87=8D=E6=95=B4=202.=20DBHelper=20Connecti?= =?UTF-8?q?on=20sting=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Helper/DatabaseHelper.cs | 2 +- .../Views/PowerStation/PowerStationAdd.cshtml | 163 ----- .../PowerStation/PowerStationEdit.cshtml | 643 +++++++++--------- 3 files changed, 330 insertions(+), 478 deletions(-) delete mode 100644 SolarPower/Views/PowerStation/PowerStationAdd.cshtml diff --git a/SolarPower/Helper/DatabaseHelper.cs b/SolarPower/Helper/DatabaseHelper.cs index 2e57aa3..b359893 100644 --- a/SolarPower/Helper/DatabaseHelper.cs +++ b/SolarPower/Helper/DatabaseHelper.cs @@ -37,7 +37,7 @@ namespace SolarPower.Helper var passwordStr = ed.DESDecrypt(dbConfig.Password); //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; - var connStr = @"server=127.0.0.1;port=3308;database=solar_power;user=root;password=00000000;charset=utf8;"; + var connStr = @"server=127.0.0.1;database=solar_power;user=root;password=000000;charset=utf8;"; this._connectionString = connStr; } diff --git a/SolarPower/Views/PowerStation/PowerStationAdd.cshtml b/SolarPower/Views/PowerStation/PowerStationAdd.cshtml deleted file mode 100644 index 7155fc9..0000000 --- a/SolarPower/Views/PowerStation/PowerStationAdd.cshtml +++ /dev/null @@ -1,163 +0,0 @@ - -
-
-
-
-
-
- -
-
- -
- -
電站基本資料
- -
-
-
-
- - -
-
- - -
-
-

是否為代管:

-

-

- - -
-

-
-
- - -
-
- - -
-
- -
-
- - -
-
- - -
- -
-
- - -
-
- - -
-
- - -
-
- -
-
-
逆變器
-
-
- - -
-
- - -
-
- - -
-
-
-
-
光電板
-
-
- - -
-
- - -
-
- - -
-
- - -
-
-
-
- -
-
-
-
-
-
-
-
-
-@section Scripts{ - - -} \ No newline at end of file diff --git a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml index cb2aebc..a5ea878 100644 --- a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml +++ b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml @@ -175,92 +175,93 @@ } } }); - //#endregion + //#endregion + //#region 設備列表 DataTable DeviceTable = $("#Device_table").DataTable({ - "paging": true, - "lengthChange": false, - "searching": false, - "ordering": true, - "info": true, - "autoWidth": false, - "responsive": true, - "order": [[9, "desc"]], - "columns": [{ - "data": "uid" - }, { - "data": "name" - }, { - "data": "typeName" - }, { - "data": "brand" - }, { - "data": "productModel" - }, { - "data": "dbName" - }, { - "data": "tableName" - }, { - "data": "colName" - }, { - "data": "remark" - },{ - "data": "function" - }], - "columnDefs": [{ - 'targets': 1, - 'searchable': false, - 'orderable': false, - 'className': 'dt-body-center' - }], - "language": { - "emptyTable": "無資料...", - "processing": "處理中...", - "loadingRecords": "載入中...", - "lengthMenu": "顯示 _MENU_ 項結果", - "zeroRecords": "沒有符合的結果", - "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項", - "infoEmpty": "顯示第 0 至 0 項結果,共 0 項", - "infoFiltered": "(從 _MAX_ 項結果中過濾)", - "infoPostFix": "", - "search": "搜尋:", - "paginate": { - "first": "第一頁", - "previous": "上一頁", - "next": "下一頁", - "last": "最後一頁" - }, - "aria": { - "sortAscending": ": 升冪排列", - "sortDescending": ": 降冪排列" - } - }, - 'createdRow': function (row, data, dataIndex) { - $(row).attr('data-id', data.id); - }, - "ajax": { - "url": "/PowerStation/DeviceTable", - "type": "POST", - "data": function (d) { - d.stationId = stationId; - }, - "dataSrc": function (rel) { - if (rel.data.code == "9999") { - toast_error(rel.data.msg); - return; + "paging": true, + "lengthChange": false, + "searching": false, + "ordering": true, + "info": true, + "autoWidth": false, + "responsive": true, + "order": [[9, "desc"]], + "columns": [{ + "data": "uid" + }, { + "data": "name" + }, { + "data": "typeName" + }, { + "data": "brand" + }, { + "data": "productModel" + }, { + "data": "dbName" + }, { + "data": "tableName" + }, { + "data": "colName" + }, { + "data": "remark" + },{ + "data": "function" + }], + "columnDefs": [{ + 'targets': 1, + 'searchable': false, + 'orderable': false, + 'className': 'dt-body-center' + }], + "language": { + "emptyTable": "無資料...", + "processing": "處理中...", + "loadingRecords": "載入中...", + "lengthMenu": "顯示 _MENU_ 項結果", + "zeroRecords": "沒有符合的結果", + "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項", + "infoEmpty": "顯示第 0 至 0 項結果,共 0 項", + "infoFiltered": "(從 _MAX_ 項結果中過濾)", + "infoPostFix": "", + "search": "搜尋:", + "paginate": { + "first": "第一頁", + "previous": "上一頁", + "next": "下一頁", + "last": "最後一頁" + }, + "aria": { + "sortAscending": ": 升冪排列", + "sortDescending": ": 降冪排列" } + }, + 'createdRow': function (row, data, dataIndex) { + $(row).attr('data-id', data.id); + }, + "ajax": { + "url": "/PowerStation/DeviceTable", + "type": "POST", + "data": function (d) { + d.stationId = stationId; + }, + "dataSrc": function (rel) { + if (rel.data.code == "9999") { + toast_error(rel.data.msg); + return; + } - data = rel.data.data; + data = rel.data.data; - if (data == null || data.length == 0) { - this.data = []; + if (data == null || data.length == 0) { + this.data = []; + } + + return data; } - - return data; } - } - }); - //#endregion + }); + //#endregion //#region 異常設定列表 DataTable ExceptionTable = $("#Exception_table").DataTable({ "paging": true, @@ -341,7 +342,8 @@ } } }); - //#endregion + //#endregion + //#region 電站資料 view 控制 if (stationId == 'new') { //#region 電站基本資料 @@ -378,6 +380,7 @@ $("#land_buildingPart").hide(); $("#tablist").hide(); + $("#tablist").find(".nav-item > a").first().click(); } else { var url = "/PowerStation/GetOnePowerStation" @@ -410,6 +413,7 @@ }, 'json'); } + //#endregion //#region 預先載入運維人員下拉式選單select_option var url_user_select_option = "/PowerStation/GetUserSelectOptionList"; @@ -486,6 +490,8 @@ }); }); //#endregion + + //#region 預先載入設備類型下拉式選單select_option var url_DeviceType = "/PowerStation/GetDeviceTypeSelectOptionList"; $.get(url_DeviceType, function (rel) { if (rel.code != "0000") { @@ -498,11 +504,10 @@ $("#Device_Type_modal").append($("