diff --git a/SolarPower/Controllers/MyBaseController.cs b/SolarPower/Controllers/MyBaseController.cs index 3f93fd2..15fa25b 100644 --- a/SolarPower/Controllers/MyBaseController.cs +++ b/SolarPower/Controllers/MyBaseController.cs @@ -97,7 +97,53 @@ namespace SolarPower.Controllers //取得當前使用者可以查看的電站 - ViewBag.myPowerStationSummaries = powerStationRepository.GetMyPowerStationSummary(myUser); + var myPowerStationSummaries = powerStationRepository.GetMyPowerStationSummary(myUser); + ViewBag.myPowerStationSummaries = myPowerStationSummaries; + + if (controllerName == "PowerStation" && actionName == "Edit") + { + //電站資訊的各電站 + string stationId_param = filterContext.HttpContext.Request.Query["stationId"]; + + int stationId = stationId_param == "new" ? 0 : int.Parse(stationId_param); + + + if (stationId > 0) + { + var hasSubTagNum = false; + int i = 0; + foreach(var myPowerStationSummary in myPowerStationSummaries) + { + if (hasSubTagNum) + { + break; + } + int j = 0; + foreach(var myPowerStation in myPowerStationSummary.MyPowerStations) + { + if(myPowerStation.PowerStationId == stationId) + { + ViewData["SubNum"] = i; + ViewData["TagNum"] = j; + hasSubTagNum = true; + break; + } + j++; + } + i++; + } + } + else + { + //電站管理的新增電站 + ViewData["SubNum"] = myPowerStationSummaries.Count(); + ViewData["TagNum"] = 0; + } + }else if(controllerName == "PowerStation" && actionName == "Index") + { + ViewData["SubNum"] = myPowerStationSummaries.Count(); + ViewData["TagNum"] = 0; + } ViewBag.auths = auth_arr; diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index bf87dc9..f145244 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -663,6 +663,37 @@ namespace SolarPower.Controllers return apiResult; } + public async Task> DeleteOneOperationRecode(int id) + { + ApiResult apiResult = new ApiResult(); + + try + { + var operationRecode = await operationRepository.GetOneOperationRecodeAsync(id); + + if (operationRecode == null) + { + apiResult.Code = "9989"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + await operationRepository.DeleteOneOperationRecodeAsync(id); + + 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/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index 7044ef0..35b2af5 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -399,6 +399,34 @@ namespace SolarPower.Repository.Implement } } + public async Task DeleteOneOperationRecodeAsync(int id) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + var sql = $"UPDATE operation_record SET deleted = 1 WHERE Id = @Id"; + + await conn.ExecuteAsync(sql, new { Id = id }, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } + } + } + /// /// 新增運維作業記錄的檔案 /// diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index e817a88..4066b5a 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -41,7 +41,7 @@ namespace SolarPower.Repository.Implement } else if (myUser.Role.Layer == 3) { - sql += @" LEFT JOIN power_station_operation_personnel ps.Id = op.PowerStationId + sql += @" LEFT JOIN power_station_operation_personnel op ON ps.Id = op.PowerStationId WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId "; } else diff --git a/SolarPower/Repository/Interface/IOperationRepository.cs b/SolarPower/Repository/Interface/IOperationRepository.cs index a30eff9..3abeed0 100644 --- a/SolarPower/Repository/Interface/IOperationRepository.cs +++ b/SolarPower/Repository/Interface/IOperationRepository.cs @@ -54,6 +54,8 @@ namespace SolarPower.Repository.Interface /// Task AddOperationRecodeFilesAsync(List entity, List properties); + Task DeleteOneOperationRecodeAsync(int id); + /// /// 透過Id,取得單一運維作業記錄檔案 /// diff --git a/SolarPower/Views/Operation/OperationRecord.cshtml b/SolarPower/Views/Operation/OperationRecord.cshtml index 9a3f839..133a699 100644 --- a/SolarPower/Views/Operation/OperationRecord.cshtml +++ b/SolarPower/Views/Operation/OperationRecord.cshtml @@ -3,6 +3,8 @@ ViewData["SubNum"] = "2"; ViewData["Title"] = "運維作業記錄"; } +@using SolarPower.Models.Role +@model RoleLayerEnum