Administrator 3 months ago
parent
commit
ec7e89f5bb
  1. 41
      UserClass/AsyncTcpServer.cs
  2. 7
      ViewModel/MainWindowViewModel.cs

41
UserClass/AsyncTcpServer.cs

@ -5,9 +5,11 @@ using System.Data;
using System.Security.Cryptography.Pkcs; using System.Security.Cryptography.Pkcs;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Windows.Markup;
using System.Xml.Linq; using System.Xml.Linq;
using TouchSocket.Core; using TouchSocket.Core;
using TouchSocket.Sockets; using TouchSocket.Sockets;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace SunlightAggregationManager.UserClass namespace SunlightAggregationManager.UserClass
{ {
@ -64,6 +66,7 @@ namespace SunlightAggregationManager.UserClass
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + deserializedPerson?.User + "'", myDict); MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + deserializedPerson?.User + "'", myDict);
Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]Note[" + (deserializedPerson?.Dat ?? "unknown") + "]"); Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]Note[" + (deserializedPerson?.Dat ?? "unknown") + "]");
client.SendAsync(Command(deserializedPerson?.Dat?? "NOT"));
} }
else else
{//首次登录记录 {//首次登录记录
@ -164,6 +167,44 @@ namespace SunlightAggregationManager.UserClass
Console.WriteLine("TCP Port:"+ port2.ToString()); Console.WriteLine("TCP Port:"+ port2.ToString());
Console.WriteLine("TCP SERVER:START"); Console.WriteLine("TCP SERVER:START");
} }
public static string Command(string dat)
{
string Command="", ret ="";
Dictionary<string, object> data_ = new Dictionary<string, object>();
var deserialized = JsonSerializer.Deserialize<Dictionary<string, object>>(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<Dictionary<string, object>> ToList(DataTable table)
{
if (table == null) return null;
// 使用 AsEnumerable() 将 DataTable 转换为 IEnumerable<DataRow>
// 然后投影为 Dictionary
return table.AsEnumerable().Select(row =>
table.Columns.Cast<DataColumn>().ToDictionary(
col => col.ColumnName,
col => row[col]
)
).ToList();
}
} }
class MyTcpService : TcpService<MyTcpSessionClient> class MyTcpService : TcpService<MyTcpSessionClient>

7
ViewModel/MainWindowViewModel.cs

@ -38,7 +38,6 @@ namespace SunlightAggregationManager.ViewModel
[ObservableProperty] [ObservableProperty]
public static DataTable _userData = new DataTable(); public static DataTable _userData = new DataTable();
public MainWindowViewModel() public MainWindowViewModel()
{ {
SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件 SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件
@ -70,7 +69,7 @@ namespace SunlightAggregationManager.ViewModel
row["LinkID"] = 0; row["LinkID"] = 0;
} }
Machines.RowChanged += Machines_Updata;
UserData.RowChanged += UserData_Updata;//注册userdata表更新事件 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) private void UserData_Updata(object sender, DataRowChangeEventArgs e)
{ {

Loading…
Cancel
Save