This commit is contained in:
Administrator committed 2026-05-12 01:41:11 +08:00
commit ecd78d8f6b
1 file changed
+8 -4
+8 -4
View File
@@ -168,7 +168,7 @@ namespace SunlightAggregationManager.UserClass
Console.WriteLine("TCP SERVER:START");
}
public static string Command(string dat)
public static string Command(string dat)//
{
string Command="", ret ="";
@@ -176,7 +176,7 @@ namespace SunlightAggregationManager.UserClass
var deserialized = JsonSerializer.Deserialize<Dictionary<string, object>>(dat)!;
if (deserialized.TryGetValue("Command", out var val) && val != null) Command = val.ToString()!;
if (Command == "Info")
if (Command == "Info")//回复info请求的信息
{
var t = ToList(MainWindowViewModel._machines).ToJsonString();
@@ -189,7 +189,7 @@ namespace SunlightAggregationManager.UserClass
return ret;
}
public static List<Dictionary<string, object>> ToList(DataTable table)
public static List<Dictionary<string, object?>>? ToList(DataTable table)//datatable转list
{
if (table == null) return null;
@@ -198,7 +198,11 @@ namespace SunlightAggregationManager.UserClass
return table.AsEnumerable().Select(row =>
table.Columns.Cast<DataColumn>().ToDictionary(
col => col.ColumnName,
col => row[col]
col => {
var value = row[col];
// 核心修改:如果是数据库空值 DBNull.Value,则转为 C# 的 null,否则保持原值
return value == DBNull.Value ? null : value;
}
)
).ToList();
}