添加 double 类型的变量值

This commit is contained in:
2025-09-13 08:24:06 +08:00
parent c173ab08d3
commit 5a39796f0e
5 changed files with 120 additions and 0 deletions

View File

@@ -12,7 +12,36 @@ public class VariableDto
public string Name { get; set; }
public string S7Address { get; set; }
public string DataValue { get; set; }
public double NumericValue { get; set; }
public string DisplayValue { get; set; }
/// <summary>
/// 更新数值属性根据DataValue的值进行转换。
/// </summary>
public void UpdateNumericValue()
{
if (string.IsNullOrEmpty(DataValue))
{
NumericValue = 0.0;
return;
}
// 尝试将字符串转换为数值
if (double.TryParse(DataValue, out double numericValue))
{
NumericValue = numericValue;
}
// 如果是布尔值
else if (bool.TryParse(DataValue, out bool boolValue))
{
NumericValue = boolValue ? 1.0 : 0.0;
}
// 如果无法转换保持为0.0
else
{
NumericValue = 0.0;
}
}
public VariableTableDto? VariableTable { get; set; }
public List<VariableMqttAliasDto>? MqttAliases { get; set; } = new List<VariableMqttAliasDto>();
public SignalType SignalType { get; set; }