From d2ab2b11ec95baeb7213f1a60e01aad0448eb7c1 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Thu, 2 Sep 2021 10:52:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=AA=E9=99=A4=E9=9B=BB=E7=AB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PowerStationController.cs | 34 ++++++++ SolarPower/Properties/launchSettings.json | 8 +- .../Implement/PowerStationRepository.cs | 50 +++++++++++ .../Interface/IPowerStationRepository.cs | 2 + SolarPower/Views/PowerStation/Index.cshtml | 87 +++++++++++++------ .../PowerStation/PowerStationEdit.cshtml | 7 -- 6 files changed, 147 insertions(+), 41 deletions(-) diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index bcfef6d..b678478 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -3071,7 +3071,19 @@ namespace SolarPower.Controllers try { + var powerstation = await powerStationRepository.GetOneAsync(stationId); + if (powerstation == null) + { + apiResult.Code = "9992"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + await powerStationRepository.DeleteOneByIdWithCustomDBNameAndTable(stationId, powerstation.SiteDB, "power_station"); + + await powerStationRepository.DropShareDevice(stationId, powerstation.SiteDB); + await powerStationRepository.DeleteOne(stationId); + apiResult.Msg = "刪除成功"; apiResult.Code = "0000"; } @@ -3121,5 +3133,27 @@ namespace SolarPower.Controllers } } + public async Task>> GetShareDevicePowerstationName (int Id) + { + ApiResult> apiResult = new ApiResult>(); + List names = new List(); + try + { + var powerStation = await powerStationRepository.GetOneAsync(Id); + + names = await powerStationRepository.GetShareDevicePowerstationName(Id, powerStation.SiteDB); + + apiResult.Code = "0000"; + apiResult.Data = names; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + } } diff --git a/SolarPower/Properties/launchSettings.json b/SolarPower/Properties/launchSettings.json index 5ef5dfe..989d8d4 100644 --- a/SolarPower/Properties/launchSettings.json +++ b/SolarPower/Properties/launchSettings.json @@ -2,13 +2,9 @@ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, - "iis": { - "applicationUrl": "http://localhost/SolarPower", - "sslPort": 0 - }, "iisExpress": { - "applicationUrl": "http://localhost:63003", - "sslPort": 0 + "applicationUrl": "http://localhost:57957/", + "sslPort": 44361 } }, "profiles": { diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index f8c8b6a..ed1a900 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -5274,5 +5274,55 @@ namespace SolarPower.Repository.Implement return result; } } + + public async Task> GetShareDevicePowerstationName (int Id , string DBname) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $@"SELECT ps.Name FROM {DBname}.sharedevice sh + LEFT JOIN power_station ps ON ps.Id = sh.PowerStationId + WHERE sh.DeviceId IN + (SELECT Id FROM {DBname}.device WHERE PowerStationId = {Id}) group BY ps.Name"; + + result = (await conn.QueryAsync(sql)).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + public async Task DropShareDevice(int powerstationId ,string DBname) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + var sql = $"DELETE FROM {DBname}.sharedevice WHERE DeviceId IN (SELECT Id FROM {DBname}.device WHERE PowerStationId = {powerstationId} )"; + + await conn.ExecuteAsync(sql, 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 757aa6c..0df7b0d 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -595,5 +595,7 @@ namespace SolarPower.Repository.Interface Task> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter); Task> GetApicallItemList(int powerStationId, string dbname); Task> GetApicallList(int PowerStationId, string Type); + Task> GetShareDevicePowerstationName(int Id, string DBname); + Task DropShareDevice(int powerstationId, string DBname); } } diff --git a/SolarPower/Views/PowerStation/Index.cshtml b/SolarPower/Views/PowerStation/Index.cshtml index f265638..32d29f3 100644 --- a/SolarPower/Views/PowerStation/Index.cshtml +++ b/SolarPower/Views/PowerStation/Index.cshtml @@ -514,36 +514,67 @@ var selected_id = $(this).parents('tr').attr('data-id'); var selected_cityid = $(this).parents('tr').attr('datacity-id'); - Swal.fire( - { - title: "刪除", - text: "你確定是否刪除此筆資料?", - icon: 'warning', - showCancelButton: true, - confirmButtonText: "是", - cancelButtonText: "否" - }).then(function (result) { - if (result.value) { - //刪除單一運維紀錄 - var url = "/PowerStation/DeletePowerStation/"; - var send_data = { - stationId: selected_id - } - $.post(url, send_data, function (rel) { - if (rel.code == "9999") { - toast_error(rel.msg); - return; - } - toast_ok(rel.msg); - var cityamount = $('#ul-List-' + selected_cityid).text(); - $('#ul-List-' + selected_cityid).text(cityamount - 1); - $('#li-List-' + selected_id).hide(); + var url = "/PowerStation/GetShareDevicePowerstationName"; + var send_data = { + Id: selected_id + } + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + else { + var stationName = ""; + if (rel.data.length != 0) { + stationName = "此電站與 " + $.each(rel.data, function (index, val) { + stationName += index + 1 + "." + val + ""; + }); + stationName += "以上電站共用設備刪除則將解除所有設備共用關係!" - Cityes(); - - }, 'json'); } - }); + var text = stationName + "請問確定是否刪除該電站? " + Swal.fire( + { + title: "刪除", + icon: 'warning', + html: text, + showCancelButton: true, + confirmButtonText: "刪除", + cancelButtonText: "取消" + }).then(function (result) { + if (result.value) { + //刪除電站 + var url = "/PowerStation/DeletePowerStation/"; + var send_data = { + stationId: selected_id + } + $.post(url, send_data, function (rel) { + if (rel.code == "9999") { + toast_error(rel.msg); + return; + } + toast_ok(rel.msg); + var cityamount = $('#ul-List-' + selected_cityid).text(); + $('#ul-List-' + selected_cityid).text(cityamount - 1); + $('#li-List-' + selected_id).hide(); + + Cityes(); + + }, 'json'); + } + }); + + + return; + } + + }, 'json'); + + + + + }); diff --git a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml index 611c10a..67cbd85 100644 --- a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml +++ b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml @@ -2611,7 +2611,6 @@ ExceptionTable.ajax.reload(); return; } - }, 'json'); } } @@ -2622,16 +2621,12 @@ $("#Exception-modal .modal-title").html("異常設定資料 - 編輯"); var tyname = $(this).parents('tr').attr('data-typename'); selected_id = $(this).parents('tr').attr('data-id'); - //取得單一異常設定資料 var url = "/PowerStation/GetOneException/"; - var send_data = { SelectedId: selected_id, PowerStationId: stationId, } - - $.post(url, send_data, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); @@ -3013,9 +3008,7 @@ }); $('#power_station_operation_personnel').change(function () { - //$(this).valid(); if (stationId == 'new' || station_infocreate) { - console.log($('#power_station_operation_personnel').val().length); if ($('#power_station_operation_personnel').val().length == 0) { $('#power_station_operation_personnel-error').show(); } else {