刪除電站
This commit is contained in:
parent
4f96b2ef92
commit
d2ab2b11ec
@ -3071,7 +3071,19 @@ namespace SolarPower.Controllers
|
|||||||
|
|
||||||
try
|
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);
|
await powerStationRepository.DeleteOne(stationId);
|
||||||
|
|
||||||
apiResult.Msg = "刪除成功";
|
apiResult.Msg = "刪除成功";
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
}
|
}
|
||||||
@ -3121,5 +3133,27 @@ namespace SolarPower.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ApiResult<List<string>>> GetShareDevicePowerstationName (int Id)
|
||||||
|
{
|
||||||
|
ApiResult<List<string>> apiResult = new ApiResult<List<string>>();
|
||||||
|
List<string> names = new List<string>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,13 +2,9 @@
|
|||||||
"iisSettings": {
|
"iisSettings": {
|
||||||
"windowsAuthentication": false,
|
"windowsAuthentication": false,
|
||||||
"anonymousAuthentication": true,
|
"anonymousAuthentication": true,
|
||||||
"iis": {
|
|
||||||
"applicationUrl": "http://localhost/SolarPower",
|
|
||||||
"sslPort": 0
|
|
||||||
},
|
|
||||||
"iisExpress": {
|
"iisExpress": {
|
||||||
"applicationUrl": "http://localhost:63003",
|
"applicationUrl": "http://localhost:57957/",
|
||||||
"sslPort": 0
|
"sslPort": 44361
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"profiles": {
|
"profiles": {
|
||||||
|
|||||||
@ -5274,5 +5274,55 @@ namespace SolarPower.Repository.Implement
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<string>> GetShareDevicePowerstationName (int Id , string DBname)
|
||||||
|
{
|
||||||
|
List<string> 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<string>(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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -595,5 +595,7 @@ namespace SolarPower.Repository.Interface
|
|||||||
Task<List<PowerStationIdAndCity>> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter);
|
Task<List<PowerStationIdAndCity>> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter);
|
||||||
Task<List<AreaSelectItemList>> GetApicallItemList(int powerStationId, string dbname);
|
Task<List<AreaSelectItemList>> GetApicallItemList(int powerStationId, string dbname);
|
||||||
Task<List<ApicallList>> GetApicallList(int PowerStationId, string Type);
|
Task<List<ApicallList>> GetApicallList(int PowerStationId, string Type);
|
||||||
|
Task<List<string>> GetShareDevicePowerstationName(int Id, string DBname);
|
||||||
|
Task DropShareDevice(int powerstationId, string DBname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -514,17 +514,37 @@
|
|||||||
var selected_id = $(this).parents('tr').attr('data-id');
|
var selected_id = $(this).parents('tr').attr('data-id');
|
||||||
var selected_cityid = $(this).parents('tr').attr('datacity-id');
|
var selected_cityid = $(this).parents('tr').attr('datacity-id');
|
||||||
|
|
||||||
|
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 = "此電站與 <br\><br\>"
|
||||||
|
$.each(rel.data, function (index, val) {
|
||||||
|
stationName += index + 1 + "." + val + "<br\>";
|
||||||
|
});
|
||||||
|
stationName += "<br\>以上電站共用設備<br\>刪除則將解除所有設備共用關係!<br\>"
|
||||||
|
|
||||||
|
}
|
||||||
|
var text = stationName + "請問確定是否刪除該電站? <br\>"
|
||||||
Swal.fire(
|
Swal.fire(
|
||||||
{
|
{
|
||||||
title: "刪除",
|
title: "刪除",
|
||||||
text: "你確定是否刪除此筆資料?",
|
|
||||||
icon: 'warning',
|
icon: 'warning',
|
||||||
|
html: text,
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
confirmButtonText: "是",
|
confirmButtonText: "刪除",
|
||||||
cancelButtonText: "否"
|
cancelButtonText: "取消"
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
if (result.value) {
|
if (result.value) {
|
||||||
//刪除單一運維紀錄
|
//刪除電站
|
||||||
var url = "/PowerStation/DeletePowerStation/";
|
var url = "/PowerStation/DeletePowerStation/";
|
||||||
var send_data = {
|
var send_data = {
|
||||||
stationId: selected_id
|
stationId: selected_id
|
||||||
@ -544,6 +564,17 @@
|
|||||||
}, 'json');
|
}, 'json');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 'json');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2611,7 +2611,6 @@
|
|||||||
ExceptionTable.ajax.reload();
|
ExceptionTable.ajax.reload();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}, 'json');
|
}, 'json');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2622,16 +2621,12 @@
|
|||||||
$("#Exception-modal .modal-title").html("異常設定資料 - 編輯");
|
$("#Exception-modal .modal-title").html("異常設定資料 - 編輯");
|
||||||
var tyname = $(this).parents('tr').attr('data-typename');
|
var tyname = $(this).parents('tr').attr('data-typename');
|
||||||
selected_id = $(this).parents('tr').attr('data-id');
|
selected_id = $(this).parents('tr').attr('data-id');
|
||||||
|
|
||||||
//取得單一異常設定資料
|
//取得單一異常設定資料
|
||||||
var url = "/PowerStation/GetOneException/";
|
var url = "/PowerStation/GetOneException/";
|
||||||
|
|
||||||
var send_data = {
|
var send_data = {
|
||||||
SelectedId: selected_id,
|
SelectedId: selected_id,
|
||||||
PowerStationId: stationId,
|
PowerStationId: stationId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$.post(url, send_data, function (rel) {
|
$.post(url, send_data, function (rel) {
|
||||||
if (rel.code != "0000") {
|
if (rel.code != "0000") {
|
||||||
toast_error(rel.msg);
|
toast_error(rel.msg);
|
||||||
@ -3013,9 +3008,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#power_station_operation_personnel').change(function () {
|
$('#power_station_operation_personnel').change(function () {
|
||||||
//$(this).valid();
|
|
||||||
if (stationId == 'new' || station_infocreate) {
|
if (stationId == 'new' || station_infocreate) {
|
||||||
console.log($('#power_station_operation_personnel').val().length);
|
|
||||||
if ($('#power_station_operation_personnel').val().length == 0) {
|
if ($('#power_station_operation_personnel').val().length == 0) {
|
||||||
$('#power_station_operation_personnel-error').show();
|
$('#power_station_operation_personnel-error').show();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user