You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.9 KiB
89 lines
2.9 KiB
using SunlightAggregationTerminal.Class;
|
|
using SunlightAggregationTerminal.Models;
|
|
using System.Collections.ObjectModel;
|
|
using System.Reflection;
|
|
using System.Text.Json;
|
|
using TouchSocket.Core;
|
|
|
|
namespace SunlightAggregationTerminal;
|
|
|
|
public partial class InfoChemicalStatistics : ContentPage
|
|
{
|
|
public class ChemicalTotal
|
|
{
|
|
public string? ProductName { get; set; }
|
|
public string? ProductCode { get; set; }
|
|
public float? TotalDispenseGrams { get; set; }
|
|
}
|
|
|
|
public static ObservableCollection<ChemicalTotal> ChemicalTotals { get; set; } = new();
|
|
public InfoChemicalStatistics()
|
|
{
|
|
InitializeComponent();
|
|
Dictionary<string, object> Dictionary = new Dictionary<string, object>();
|
|
Dictionary.Add("Command", "ChemicalStatistics");
|
|
DateTime StartTimee_ = (DateTime)StartTime.Date!;
|
|
Dictionary.Add("StartTime", StartTimee_.ToString("yyyy-MM-dd"));
|
|
DateTime EndTime_ = (DateTime)EndTime.Date!;
|
|
Dictionary.Add("EndTime", EndTime_.AddDays(1).ToString("yyyy-MM-dd"));
|
|
Total_Command(Dictionary.ToJsonString());
|
|
}
|
|
|
|
public async void Total_Command(string dat)
|
|
{
|
|
LoadingIndicator.IsVisible = true;
|
|
ChemicalTotals.Clear();
|
|
|
|
DataReceived.Transmit(dat);
|
|
|
|
// 创建一个 15 秒的延时任务
|
|
Task delayTask = Task.Delay(15000);
|
|
// 创建一个监测任务,不断检查变量
|
|
Task monitorTask = Task.Run(async () =>
|
|
{
|
|
while (ChemicalTotals.Count == 0)
|
|
{
|
|
// 每隔 100 毫秒检查一次,避免 CPU 占用过高
|
|
await Task.Delay(100);
|
|
}
|
|
});
|
|
// 使用 Task.WhenAny 等待任意一个任务完成
|
|
await Task.WhenAny(delayTask, monitorTask);
|
|
CardCollectionView.ItemsSource = ChemicalTotals;
|
|
|
|
LoadingIndicator.IsVisible = false;
|
|
}
|
|
|
|
public static void Total_data(string dat)
|
|
{
|
|
try
|
|
{
|
|
var data = JsonSerializer.Deserialize<List<ChemicalTotal>>(dat);
|
|
|
|
if (data != null)
|
|
{
|
|
foreach (var item in data)
|
|
{
|
|
item.TotalDispenseGrams = MathF.Round((float)item.TotalDispenseGrams! / 1000, 5);
|
|
|
|
ChemicalTotals.Add(item);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
|
|
//搜索按钮
|
|
private void Button_Clicked(object sender, EventArgs e)
|
|
{
|
|
Dictionary<string, object> Dictionary = new Dictionary<string, object>();
|
|
Dictionary.Add("Command", "ChemicalStatistics");
|
|
DateTime StartTimee_ = (DateTime)StartTime.Date!;
|
|
Dictionary.Add("StartTime", StartTimee_.ToString("yyyy-MM-dd"));
|
|
DateTime EndTime_ = (DateTime)EndTime.Date!;
|
|
Dictionary.Add("EndTime", EndTime_.AddDays(1).ToString("yyyy-MM-dd"));
|
|
Total_Command(Dictionary.ToJsonString());
|
|
}
|
|
}
|