From 7ecdd8603d14fbe3094ddbb6439d57ba28371661 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Thu, 17 Jun 2021 22:06:49 +0800 Subject: [PATCH] datatab --- .../Controllers/PowerStationController.cs | 19 +++++++++++++- SolarPower/Models/PowerStation.cs | 1 + .../Implement/PowerStationRepository.cs | 26 ++++++++++++++++++- .../Interface/IPowerStationRepository.cs | 11 ++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 5091616..6652df9 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -498,7 +498,7 @@ namespace SolarPower.Controllers "UID", "CreatedBy" }; - await powerStationRepository.AddDevice(DeviceInfo, properties); + await powerStationRepository.UpdateDevice(DeviceInfo, properties); apiResult.Code = "0000"; apiResult.Msg = "儲存成功"; } @@ -516,6 +516,23 @@ namespace SolarPower.Controllers { List deviceTables = new List(); ApiResult> apiResult = new ApiResult>(); + try + { + apiResult.Code = "0000"; + deviceTables = await powerStationRepository.DeviceTable(stationId); + foreach (DeviceTable a in deviceTables) + { + a.Function = @" + + "; + } + apiResult.Data = deviceTables; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } var result = Json(new { data = apiResult diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index e2caf70..be763eb 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -139,6 +139,7 @@ namespace SolarPower.Models.PowerStation } public class DeviceTable : DeviceInfo { + public string UID { get; set; }//設備編號 public string Function { get; set; }//功能 } } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 1c25742..b6165e4 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -259,7 +259,31 @@ namespace SolarPower.Repository.Implement conn.Close(); } } - + /// + /// 裝置dataTable + /// + /// + /// + public async Task> DeviceTable(int stationId) + { + using IDbConnection conn = _databaseHelper.GetConnection(); + conn.Open(); + List Device = new List(); + try + { + string sql = @$"SELECT * FROM device WHERE Deleted = 0 AND PowerStationId = @StationId"; + Device = (await conn.QueryAsync(sql, new { StationId = stationId })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return Device; + } } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 7e5553a..7f134b0 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -10,6 +10,11 @@ namespace SolarPower.Repository.Interface public interface IPowerStationRepository : IRepositoryBase { Task AddOperation(OperationInfo operation, List properties); + /// + /// 運維dataTable + /// + /// + /// Task> OperationTable (int stationId); Task OneOperationInfo (int stationId); Task UpdateOperation(OperationInfo operation, List properties); @@ -31,5 +36,11 @@ namespace SolarPower.Repository.Interface /// /// Task UpdateDevice(Device DeviceInfo, List properties); + /// + /// 設備datatable + /// + /// + /// + Task> DeviceTable(int stationId); } }