提交更新
This commit is contained in:
@@ -6,11 +6,22 @@ using System.Timers;
|
||||
using BITFactory;
|
||||
using BITKit;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SQLitePCL;
|
||||
using Timer = System.Timers.Timer;
|
||||
// ReSharper disable All
|
||||
|
||||
namespace BITFactory;
|
||||
public partial class IDIS_THService : Node
|
||||
{
|
||||
public enum UpdateMode
|
||||
{
|
||||
None,
|
||||
Update,
|
||||
Insert,
|
||||
}
|
||||
|
||||
[Export] private UpdateMode currentUpdateMode = UpdateMode.Insert;
|
||||
|
||||
[ExportCategory("Services")]
|
||||
[Export] private IDIS_Service service;
|
||||
|
||||
@@ -19,12 +30,13 @@ public partial class IDIS_THService : Node
|
||||
[ExportCategory("UI 绑定")]
|
||||
[Export] private Button submitButton;
|
||||
[Export] private CheckButton autoUpdateButton;
|
||||
[Export] private OptionButton updateModeButton;
|
||||
[Export] private LineEdit handleEdit;
|
||||
[Export] private LineEdit temperatureEdit;
|
||||
[Export] private LineEdit humidityEdit;
|
||||
[Export] private RichTextLabel hintsLabel;
|
||||
[Export] private RichTextLabel autoUpdateLabel;
|
||||
|
||||
|
||||
private Timer autoUpdateTimer;
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -38,6 +50,15 @@ public partial class IDIS_THService : Node
|
||||
autoUpdateTimer.Enabled = toggle;
|
||||
};
|
||||
|
||||
updateModeButton.GetPopup().Clear();
|
||||
updateModeButton.GetPopup().AddItem("不更新");
|
||||
updateModeButton.GetPopup().AddItem("更新记录");
|
||||
updateModeButton.GetPopup().AddItem("添加记录");
|
||||
updateModeButton.GetPopup().IndexPressed += index =>
|
||||
{
|
||||
currentUpdateMode = (UpdateMode)index;
|
||||
};
|
||||
|
||||
autoUpdateTimer = new Timer();
|
||||
autoUpdateTimer.AutoReset = true;
|
||||
autoUpdateTimer.Interval = 1000;
|
||||
@@ -47,7 +68,7 @@ public partial class IDIS_THService : Node
|
||||
private async void AutoUpdate(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
|
||||
UpdateByReader();
|
||||
UpdateTH(handleEdit.Text,thReader.temperature.ToString(),thReader.humidity.ToString());
|
||||
}
|
||||
|
||||
private void Submit()
|
||||
@@ -64,43 +85,38 @@ public partial class IDIS_THService : Node
|
||||
hintsLabel.Text = "请输入湿度";
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (service.Update(handleEdit.Text, "温度", humidityEdit.Text) is false)
|
||||
{
|
||||
hintsLabel.Text = "温度更新失败: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
return;
|
||||
}
|
||||
if (service.Update(handleEdit.Text, "湿度", temperatureEdit.Text) is false)
|
||||
{
|
||||
hintsLabel.Text = "湿度更新失败: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
return;
|
||||
}
|
||||
hintsLabel.Text = "更新成功: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
hintsLabel.Text = e.Message;
|
||||
throw;
|
||||
}
|
||||
UpdateTH(handleEdit.Text,temperatureEdit.Text,humidityEdit.Text);
|
||||
}
|
||||
|
||||
private void UpdateByReader()
|
||||
private void UpdateTH(string handle,string temperature,string humidity)
|
||||
{
|
||||
if (string.IsNullOrEmpty(handleEdit.Text))
|
||||
if (string.IsNullOrEmpty(handle))
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("空的标识码");
|
||||
return;
|
||||
}
|
||||
if (service.Update(handleEdit.Text, "温度", thReader.temperature.ToString(CultureInfo.InvariantCulture)) is false)
|
||||
|
||||
switch (currentUpdateMode)
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("温度更新失败,未知异常");
|
||||
return;
|
||||
}
|
||||
if (service.Update(handleEdit.Text, "湿度", thReader.humidity.ToString(CultureInfo.InvariantCulture)) is false)
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("湿度更新失败,未知异常");
|
||||
return;
|
||||
case UpdateMode.Insert:
|
||||
service.Register(handle ,"温度", temperature, "环境");
|
||||
service.Register(handle, "湿度", humidity, "环境");
|
||||
break;
|
||||
case UpdateMode.Update:
|
||||
if (service.Update(handle, "温度",temperature) is false)
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("温度更新失败,未知异常");
|
||||
return;
|
||||
}
|
||||
|
||||
if (service.Update(handle, "湿度",humidity) is false)
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("湿度更新失败,未知异常");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
autoUpdateLabel.SetTextAsync($"温湿度已自动更新:{DateTime.Now}");
|
||||
}
|
||||
|
Reference in New Issue
Block a user