|
|
|
@ -4,6 +4,7 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Data; |
|
|
|
using System.Net; |
|
|
|
using System.Net.NetworkInformation; |
|
|
|
using System.Net.Sockets; |
|
|
|
using System.Text; |
|
|
|
using System.Text.Json; |
|
|
|
@ -23,15 +24,40 @@ namespace SunlightAggregationTerminal.Class |
|
|
|
|
|
|
|
public static string GetLocalIpSimple() |
|
|
|
{ |
|
|
|
var host = Dns.GetHostEntry(Dns.GetHostName()); |
|
|
|
foreach (var ip in host.AddressList) |
|
|
|
try |
|
|
|
{ |
|
|
|
if (ip.AddressFamily == AddressFamily.InterNetwork && !IPAddress.IsLoopback(ip)) |
|
|
|
// 获取当前设备上所有的网络接口
|
|
|
|
var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); |
|
|
|
|
|
|
|
foreach (var networkInterface in networkInterfaces) |
|
|
|
{ |
|
|
|
return ip.ToString(); |
|
|
|
// 仅检查处于活动状态的网络接口
|
|
|
|
if (networkInterface.OperationalStatus != OperationalStatus.Up) |
|
|
|
continue; |
|
|
|
|
|
|
|
// 获取该接口下的所有单播 IP 地址
|
|
|
|
var addresses = networkInterface.GetIPProperties().UnicastAddresses; |
|
|
|
|
|
|
|
foreach (var address in addresses) |
|
|
|
{ |
|
|
|
// 筛选条件:必须是 IPv4、非回环地址(127.x.x.x),且通常属于局域网网段
|
|
|
|
if (address.Address.AddressFamily == AddressFamily.InterNetwork && |
|
|
|
!IPAddress.IsLoopback(address.Address)) |
|
|
|
{ |
|
|
|
return address.Address.ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return "No network connection"; |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
MainThread.BeginInvokeOnMainThread(() => |
|
|
|
{ |
|
|
|
Application.Current!.Windows[0].Page!.DisplayAlertAsync("获取IP地址失败", ex.Message.ToString(), "是"); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
return null; // 如果未找到有效IP则返回null
|
|
|
|
} |
|
|
|
|
|
|
|
public static string ServerIP = ""; |
|
|
|
@ -64,10 +90,10 @@ namespace SunlightAggregationTerminal.Class |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
MainThread.BeginInvokeOnMainThread(() => |
|
|
|
{ |
|
|
|
Application.Current!.Windows[0].Page!.DisplayAlertAsync("", inf, "是"); |
|
|
|
}); |
|
|
|
// MainThread.BeginInvokeOnMainThread(() =>
|
|
|
|
// {
|
|
|
|
// Application.Current!.Windows[0].Page!.DisplayAlertAsync("", inf, "是");
|
|
|
|
// });
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -86,10 +112,9 @@ namespace SunlightAggregationTerminal.Class |
|
|
|
if (data.TryGetValue("UserName", out val) && val != null) App.GlobalData.UserName = val.ToString() ?? ""; |
|
|
|
if (data.TryGetValue("UserId", out val) && val != null) |
|
|
|
{ |
|
|
|
DataReceived.Transmit("{\"Command\":\"Info\"}"); |
|
|
|
App.GlobalData.UserId = val.ToString() ?? ""; |
|
|
|
App.GlobalData.LogNo = true; |
|
|
|
|
|
|
|
Transmit("{\"Command\":\"Info\"}"); |
|
|
|
} |
|
|
|
|
|
|
|
if (data.TryGetValue("UserData", out var value_UserData)) |
|
|
|
@ -125,19 +150,23 @@ namespace SunlightAggregationTerminal.Class |
|
|
|
foreach (var dataNotificationrow in dataNotification!) |
|
|
|
{ |
|
|
|
//解析信息
|
|
|
|
if (dataNotificationrow!.TryGetValue("id", out var value_Notification_id)) |
|
|
|
if (dataNotificationrow!.TryGetValue("id", out var value_Notification_id) |
|
|
|
&& value_Notification_id != null) |
|
|
|
{ |
|
|
|
_id = (int)value_Notification_id; |
|
|
|
} |
|
|
|
if (dataNotificationrow!.TryGetValue("Title", out var value_Notification_Title)) |
|
|
|
if (dataNotificationrow!.TryGetValue("Title", out var value_Notification_Title) |
|
|
|
&& value_Notification_Title != null) |
|
|
|
{ |
|
|
|
_Title = value_Notification_Title.ToString() ?? ""; |
|
|
|
} |
|
|
|
if (dataNotificationrow!.TryGetValue("Content", out var value_Notification_Content)) |
|
|
|
if (dataNotificationrow!.TryGetValue("Content", out var value_Notification_Content) |
|
|
|
&& value_Notification_Content != null) |
|
|
|
{ |
|
|
|
_Content = value_Notification_Content.ToString() ?? ""; |
|
|
|
} |
|
|
|
if (dataNotificationrow!.TryGetValue("Type", out var value_Notification_Type)) |
|
|
|
if (dataNotificationrow!.TryGetValue("Type", out var value_Notification_Type) |
|
|
|
&& value_Notification_Type != null) |
|
|
|
{ |
|
|
|
string temp = value_Notification_Type?.ToString() ?? ""; |
|
|
|
// 转换
|
|
|
|
@ -148,19 +177,24 @@ namespace SunlightAggregationTerminal.Class |
|
|
|
_ => 0 |
|
|
|
}; |
|
|
|
} |
|
|
|
//记录信息到数据库
|
|
|
|
DataSet? Notificationdata = AppModels.Select("select * from Notification where Id = " + _id); |
|
|
|
if (Notificationdata != null) |
|
|
|
if (_id != 0) |
|
|
|
{ |
|
|
|
if (Notificationdata.Tables[0].Rows.Count == 0) |
|
|
|
//记录信息到数据库
|
|
|
|
DataSet? Notificationdata = AppModels.Select("select * from Notification where Id = " + _id); |
|
|
|
if (Notificationdata != null) |
|
|
|
{ |
|
|
|
AppModels.INSERT("INSERT INTO Notification (Title,Content,Time,Type,Id)VALUES('" + |
|
|
|
_Title + "','" + _Content + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + |
|
|
|
"','" + _Type + "'," + _id + ");"); |
|
|
|
if (Notificationdata.Tables[0].Rows.Count == 0) |
|
|
|
{ |
|
|
|
AppModels.INSERT("INSERT INTO Notification (Title,Content,Time,Type,Id)VALUES('" + |
|
|
|
_Title + "','" + _Content + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + |
|
|
|
"','" + _Type + "'," + _id + ");"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|