diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index c857286..cd3e674 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -1177,7 +1177,9 @@ namespace SolarPower.Controllers "Status", "Enabled", "InstallDate", - "BrandNum" + "BrandNum", + "SensorTypeId", + "SensorTypeDetailId" }; if (Device.WarrantyDate != "0001-01-01") { @@ -1246,7 +1248,9 @@ namespace SolarPower.Controllers "Status", "Enabled", "InstallDate", - "BrandNum" + "BrandNum", + "SensorTypeId", + "SensorTypeDetailId" }; if (Device.WarrantyDate != "0001-01-01") { diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 13e84ab..08bf78f 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -442,6 +442,8 @@ namespace SolarPower.Models.PowerStation public string InstallDate { get { return Convert.ToDateTime(installDate).ToString("yyyy-MM-dd"); } set { installDate = value; } } //安裝日期 public string BrandNum { get; set; }//廠商序號 public string WarrantyDate { get { return Convert.ToDateTime(warrantyDate).ToString("yyyy-MM-dd"); } set { warrantyDate = value; } } //保固日期 + public int SensorTypeId { get; set; } + public int SensorTypeDetailId { get; set; } } public class Device : DeviceInfo diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index e9a5697..5d1a34b 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -1018,6 +1018,10 @@ namespace SolarPower.Repository.Implement var trans = conn.BeginTransaction(); try { + string getSensorTypeId = $@"SELECT id from sensor_type + WHERE SensorEName = '{DeviceInfo.Type}' AND Deleted = 0"; + DeviceInfo.SensorTypeId = await conn.QueryFirstOrDefaultAsync(getSensorTypeId); + DeviceInfo.SensorTypeDetailId = DeviceInfo.SensorTypeId; string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "device"); await conn.ExecuteAsync(sql, DeviceInfo); @@ -1050,6 +1054,11 @@ namespace SolarPower.Repository.Implement var trans = conn.BeginTransaction(); try { + string getSensorTypeId = $@"SELECT id from sensor_type + WHERE SensorEName = '{DeviceInfo.Type}' AND Deleted = 0"; + DeviceInfo.SensorTypeId = await conn.QueryFirstOrDefaultAsync(getSensorTypeId); + DeviceInfo.SensorTypeDetailId = DeviceInfo.SensorTypeId; + var updateQuery = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, "device"); await conn.ExecuteAsync(updateQuery.ToString(), DeviceInfo, trans); trans.Commit();