設備頁面微調修復

This commit is contained in:
b110212000 2021-08-12 15:41:49 +08:00
parent 05e9a1b09e
commit dc60934c99
6 changed files with 84 additions and 28 deletions

View File

@ -2472,9 +2472,9 @@ namespace SolarPower.Controllers
/// 其他電站下拉式選單
/// </summary>
/// <returns></returns>
public async Task<ApiResult<List<PowerstationOption>>> GetPowerstationOption(int stationId)
public async Task<ApiResult<List<PowerstationOptionAndName>>> GetPowerstationOption(int stationId)
{
ApiResult<List<PowerstationOption>> apiResult = new ApiResult<List<PowerstationOption>>();
ApiResult<List<PowerstationOptionAndName>> apiResult = new ApiResult<List<PowerstationOptionAndName>>();
try
{
var powerStation = await powerStationRepository.GetOneAsync(stationId);
@ -2497,9 +2497,9 @@ namespace SolarPower.Controllers
/// </summary>
/// <param name="stationId"></param>
/// <returns></returns>
public async Task<ApiResult<List<PowerstationOption>>> GetDeviceUIDList(int stationId)
public async Task<ApiResult<List<PowerstationOptionAndName>>> GetDeviceUIDList(int stationId)
{
ApiResult<List<PowerstationOption>> apiResult = new ApiResult<List<PowerstationOption>>();
ApiResult<List<PowerstationOptionAndName>> apiResult = new ApiResult<List<PowerstationOptionAndName>>();
try
{
var powerStation = await powerStationRepository.GetOneAsync(stationId);

View File

@ -574,6 +574,12 @@ namespace SolarPower.Models.PowerStation
public string Text { get; set; }
public string Value { get; set; }
}
public class PowerstationOptionAndName
{
public string Text { get; set; }
public string Value { get; set; }
public string Name { get; set; }
}
/// <summary>
/// 共享設備
/// </summary>

View File

@ -1760,16 +1760,16 @@ namespace SolarPower.Repository.Implement
/// 其餘電站列表
/// </summary>
/// <returns></returns>
public async Task<List<PowerstationOption>> GetPowerstationOptionAsync(string db_name, int stationId)
public async Task<List<PowerstationOptionAndName>> GetPowerstationOptionAsync(string db_name, int stationId)
{
List<PowerstationOption> result;
List<PowerstationOptionAndName> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"SELECT Id AS Value, Code AS Text FROM {db_name}.power_station WHERE Deleted = 0 AND Id !={stationId}";
var sql = $@"SELECT Id AS Value, Code AS Text ,Name FROM {db_name}.power_station WHERE Deleted = 0 AND Id !={stationId}";
result = (await conn.QueryAsync<PowerstationOption>(sql)).ToList();
result = (await conn.QueryAsync<PowerstationOptionAndName>(sql)).ToList();
}
catch (Exception exception)
{
@ -1808,16 +1808,16 @@ namespace SolarPower.Repository.Implement
/// <param name="db_name"></param>
/// <param name="stationId"></param>
/// <returns></returns>
public async Task<List<PowerstationOption>> GetDeviceUIDListAsync(string db_name, int stationId)
public async Task<List<PowerstationOptionAndName>> GetDeviceUIDListAsync(string db_name, int stationId)
{
List<PowerstationOption> result;
List<PowerstationOptionAndName> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"SELECT Id AS Value, UID AS Text FROM {db_name}.device WHERE Deleted = 0 AND PowerStationId ={stationId}";
var sql = $@"SELECT Id AS Value, UID AS Text, Name FROM {db_name}.device WHERE Deleted = 0 AND PowerStationId ={stationId}";
result = (await conn.QueryAsync<PowerstationOption>(sql)).ToList();
result = (await conn.QueryAsync<PowerstationOptionAndName>(sql)).ToList();
}
catch (Exception exception)
{

View File

@ -405,14 +405,14 @@ namespace SolarPower.Repository.Interface
/// 電站下拉式選單
/// </summary>
/// <returns></returns>
Task<List<PowerstationOption>> GetPowerstationOptionAsync(string db_name, int stationId);
Task<List<PowerstationOptionAndName>> GetPowerstationOptionAsync(string db_name, int stationId);
/// <summary>
/// 設備編號下拉式選單
/// </summary>
/// <param name="db_name"></param>
/// <param name="stationId"></param>
/// <returns></returns>
Task<List<PowerstationOption>> GetDeviceUIDListAsync(string db_name, int stationId);
Task<List<PowerstationOptionAndName>> GetDeviceUIDListAsync(string db_name, int stationId);
/// <summary>
/// 新增共享設備
/// </summary>

View File

@ -796,7 +796,7 @@
$("#ShareDevice_PowerStationId_modal").empty();
$.each(rel.data, function (index, val) {
$("#ShareDevice_PowerStationId_modal").append($("<option />").val(val.value).text(val.text));
$("#ShareDevice_PowerStationId_modal").append($("<option />").val(val.value).text(val.text +"/"+ val.name));
});
if (rel.data.length > 0)
{
@ -914,7 +914,7 @@
}
else {
$.each(rel.data, function (index, val) {
$("#ShareDevice_UID_modal").append($("<option />").val(val.value).text(val.text));
$("#ShareDevice_UID_modal").append($("<option />").val(val.value).text(val.text + "/" + val.name));
});
@ -2105,6 +2105,7 @@
document.getElementById('Device_Enabled_modal').disabled = true;
$("#Device-modal .modal-title").html("裝置資料 - 新增");
$("#Device-form").trigger("reset");
/*$("#Device_TableName_modal").val("s" + $("#Device_Controller_modal").text() + "_sensoravg");*/
$("#Device-modal").modal();
}
//#endregion
@ -2284,6 +2285,7 @@
if ($("#Device-form").valid()) {
var url = "/PowerStation/SaveDevice";
var a = padLeft($("#Device_ColName_modal").val(), 2);
var send_data = {
Id: selected_id,
PowerStationId: stationId,
@ -2295,7 +2297,7 @@
ProductModel: $("#Device_ProductModel_modal").val(),
//DBName: $("#Device_DBName_modal").val(),
TableName: $("#Device_TableName_modal").val(),
ColName: $("#Device_ColName_modal").val(),
ColName: "SENSORAVG" + a,
InstallDate: $("#Device_InstallDate_modal").val(),
Status: $("#Device_Status_modal").val(),
Enabled: $("#Device_Enabled_modal").val(),
@ -2345,7 +2347,9 @@
$("#Device_ProductModel_modal").val(rel.data.productModel);
//$("#Device_DBName_modal").val(rel.data.dbName);
$("#Device_TableName_modal").val(rel.data.tableName);
$("#Device_ColName_modal").val(rel.data.colName);
var colNameNum = rel.data.colName.substr(9, 2);
$("#Device_ColName_modal").val(colNameNum);
$("#Device_Controller_modal").val(rel.data.controllerId);
$("#Device_Name_modal").val(rel.data.name);
$("#Device_Status_modal").val(rel.data.status);
@ -2791,5 +2795,55 @@
min: 0
});
});
function padLeft(str, lenght) {
if (str.length >= lenght)
return str;
else
return padLeft("0" + str, lenght);
}
$("#Device-form").validate({
rules: {
Device_Brand_modal: {
required: true
},
Device_Name_modal: {
required: true
},
Device_ProductModel_modal: {
required: true
},
Device_InstallDate_modal: {
required: true
},
Device_ColName_modal: {
max: 50,
min: 1
}
}
});
$("#Inverter-form").validate({
rules: {
Inverter_ControllerId_modal: {
required: true
},
Inverter_InverterName_modal: {
required: true
},
Inverter_InstallDate_modal: {
required: true
},
Inverter_Brand_modal: {
required: true
},
Inverter_Model_modal: {
required: true
},
Inverter_Capacity_modal: {
required: true
},
}
});
</script>
}

View File

@ -275,22 +275,19 @@
<label class="form-label" for="Device_ProductModel_modal"><span class="text-danger">*</span>型號</label>
<input type="text" id="Device_ProductModel_modal" name="Device_ProductModel_modal" class="form-control">
</div>
@*<div class="form-group col-lg-6">
<div style="margin-bottom: 0.3rem">
<label class="form-label" for="Device_DBName_modal">DBName</label>
<input type="text" id="Device_DBName_modal" name="Device_DBName_modal" class="form-control">
</div>
</div>*@
<div class="form-group col-lg-6">
<div style="margin-bottom: 0.3rem">
<label class="form-label" for="Device_TableName_modal">tableName</label>
<input type="text" id="Device_TableName_modal" name="Device_TableName_modal" class="form-control">
<input type="text" id="Device_TableName_modal" name="Device_TableName_modal" class="form-control" disabled>
</div>
</div>
<div class="form-group col-lg-6">
<div style="margin-bottom: 0.3rem">
<label class="form-label" for="Device_ColName_modal">columnName</label>
<input type="text" id="Device_ColName_modal" name="Device_ColName_modal" class="form-control">
<div class="row align-items-center">
<label class="col-lg-4 text-right">SENSORAVG</label>
<input type="number" id="Device_ColName_modal" name="Device_ColName_modal" class="form-control col-md-3">
</div>
</div>
</div>
<div class="form-group col-lg-6">
@ -300,8 +297,7 @@
<div class="form-group col-lg-3">
<label class="form-label" for="Device_Status_modal">狀態</label>
<select class="form-control" id="Device_Status_modal" disabled>
<option value="0" action>未啟用</option>
<option value="1">正常</option>
<option value="1" action>正常</option>
<option value="2">異常</option>
</select>
</div>