diff --git a/Class/DataReceived.cs b/Class/DataReceived.cs index b692efb..aa932bf 100644 --- a/Class/DataReceived.cs +++ b/Class/DataReceived.cs @@ -143,7 +143,7 @@ namespace SunlightAggregationTerminal.Class } if (data.TryGetValue("InfoMachine", out val) && val != null)// { - InfoDetail.Info_data(val.ToString()!,data.GetValue("Type").ToString()!); + InfoDetail.Info_data(val.ToString()!, data.GetValue("Type").ToString()!); } if (data.TryGetValue("InfoMachineHistory", out val) && val != null)// { @@ -158,7 +158,7 @@ namespace SunlightAggregationTerminal.Class var dataNotification = JsonSerializer.Deserialize>>(val.ToString()!); string _Title = "", _Content = ""; - int _Type = 0 ,_id = 0; + int _Type = 0, _id = 0; foreach (var dataNotificationrow in dataNotification!) { @@ -173,12 +173,12 @@ namespace SunlightAggregationTerminal.Class { _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() ?? ""; @@ -206,6 +206,10 @@ namespace SunlightAggregationTerminal.Class } } } + if (data.TryGetValue("SETUSER", out val) && val != null)//信息通知接受 + { + ProfilePage._data(data.GetValue("VALUE").ToString()!,data.GetValue("KEY").ToString()!); + } } diff --git a/ProfilePage.xaml.cs b/ProfilePage.xaml.cs index 157e5ae..30d45cf 100644 --- a/ProfilePage.xaml.cs +++ b/ProfilePage.xaml.cs @@ -3,17 +3,63 @@ using SunlightAggregationTerminal.Class; using SunlightAggregationTerminal.Models; using SunlightAggregationTerminal.View; using System.Collections.ObjectModel; +using TouchSocket.Core; namespace SunlightAggregationTerminal; public partial class ProfilePage : ContentPage { + private static bool SET = false; public ProfilePage() { InitializeComponent(); this.BindingContext = App.GlobalData; } - + + public static void _data(string v,string k) + { + if (k == "Password") + { + App.GlobalData.UserPassword = v; + string sql = @"UPDATE Users SET UserPassword = '" + App.GlobalData.UserPassword + + "' WHERE User='" + App.GlobalData.User + "';"; + AppModels.Updata(sql); + SET = false; + } + if (k == "Name") + { + App.GlobalData.UserName = v; + string sql = @"UPDATE Users SET UserName = '" + App.GlobalData.UserName + + "' WHERE User='" + App.GlobalData.User + "';"; + AppModels.Updata(sql); + SET = false; + } + } + public async void _Command(string dat) + { + DataReceived.Transmit(dat); + SET = true; + // 创建一个 秒的延时任务 + Task delayTask = Task.Delay(10000); + // 创建一个监测任务,不断检查变量 + Task monitorTask = Task.Run(async () => + { + while (SET) + { + // 每隔 100 毫秒检查一次,避免 CPU 占用过高 + await Task.Delay(1000); + } + }); + // 使用 Task.WhenAny 等待任意一个任务完成 + Task task = await Task.WhenAny(delayTask, monitorTask); + + if (task==delayTask) + { //超时 + await DisplayAlertAsync("", "修改失败", "是"); + } + SET = false; + } + private async void Out_Clicked(object sender, EventArgs e) { //退出 @@ -38,10 +84,19 @@ public partial class ProfilePage : ContentPage // 处理结果 if (!string.IsNullOrWhiteSpace(result)) { - App.GlobalData.UserName=result; - string sql = @"UPDATE Users SET UserName = '" + App.GlobalData.UserName - + "' WHERE User='" + App.GlobalData.User + "';"; - AppModels.Updata(sql); + Dictionary data_ = new Dictionary(); + data_.Add("Command", "SETUSER"); + data_.Add("USER", App.GlobalData.User); + data_.Add("KEY", "Name"); + data_.Add("VALUE", result); + _Command(data_.ToJsonString()); + + /* + + App.GlobalData.UserName=result; + string sql = @"UPDATE Users SET UserName = '" + App.GlobalData.UserName + + "' WHERE User='" + App.GlobalData.User + "';"; + AppModels.Updata(sql);*/ } } private async void UserPassword_Tapped(object sender, TappedEventArgs e) @@ -51,10 +106,18 @@ public partial class ProfilePage : ContentPage // 处理结果 if (!string.IsNullOrWhiteSpace(result)) { - App.GlobalData.UserPassword = result; - string sql = @"UPDATE Users SET UserPassword = '" + App.GlobalData.UserPassword - + "' WHERE User='" + App.GlobalData.User + "';"; - AppModels.Updata(sql); + Dictionary data_ = new Dictionary(); + data_.Add("Command", "SETUSER"); + data_.Add("USER", App.GlobalData.User); + data_.Add("KEY", "Password"); + data_.Add("VALUE", result); + _Command(data_.ToJsonString()); + + + /* App.GlobalData.UserPassword = result; + string sql = @"UPDATE Users SET UserPassword = '" + App.GlobalData.UserPassword + + "' WHERE User='" + App.GlobalData.User + "';"; + AppModels.Updata(sql);*/ } } private async void ServerID_Tapped(object sender, TappedEventArgs e)