diff --git a/UserClass/AsyncTcpServer.cs b/UserClass/AsyncTcpServer.cs index 45f42dd..a18f351 100644 --- a/UserClass/AsyncTcpServer.cs +++ b/UserClass/AsyncTcpServer.cs @@ -5,9 +5,11 @@ using System.Data; using System.Security.Cryptography.Pkcs; using System.Text; using System.Text.Json; +using System.Windows.Markup; using System.Xml.Linq; using TouchSocket.Core; using TouchSocket.Sockets; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace SunlightAggregationManager.UserClass { @@ -64,6 +66,7 @@ namespace SunlightAggregationManager.UserClass MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + deserializedPerson?.User + "'", myDict); Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]Note[" + (deserializedPerson?.Dat ?? "unknown") + "]"); + client.SendAsync(Command(deserializedPerson?.Dat?? "NOT")); } else {//首次登录记录 @@ -164,6 +167,44 @@ namespace SunlightAggregationManager.UserClass Console.WriteLine("TCP Port:"+ port2.ToString()); Console.WriteLine("TCP SERVER:START"); } + + public static string Command(string dat) + { + string Command="", ret =""; + + Dictionary data_ = new Dictionary(); + var deserialized = JsonSerializer.Deserialize>(dat)!; + if (deserialized.TryGetValue("Command", out var val) && val != null) Command = val.ToString()!; + + if (Command == "Info") + { + var t = ToList(MainWindowViewModel._machines).ToJsonString(); + + data_.Add("Info", t); + + ret = JsonSerializer.Serialize(data_); + } + + + return ret; + } + + public static List> ToList(DataTable table) + { + if (table == null) return null; + + // 使用 AsEnumerable() 将 DataTable 转换为 IEnumerable + // 然后投影为 Dictionary + return table.AsEnumerable().Select(row => + table.Columns.Cast().ToDictionary( + col => col.ColumnName, + col => row[col] + ) + ).ToList(); + } + + + } class MyTcpService : TcpService diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index c27d6e4..3594401 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -38,7 +38,6 @@ namespace SunlightAggregationManager.ViewModel [ObservableProperty] public static DataTable _userData = new DataTable(); - public MainWindowViewModel() { SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件 @@ -70,7 +69,7 @@ namespace SunlightAggregationManager.ViewModel row["LinkID"] = 0; } - + Machines.RowChanged += Machines_Updata; UserData.RowChanged += UserData_Updata;//注册userdata表更新事件 } @@ -101,6 +100,10 @@ namespace SunlightAggregationManager.ViewModel } } + private void Machines_Updata(object sender, DataRowChangeEventArgs e) + { + + } private void UserData_Updata(object sender, DataRowChangeEventArgs e) {