|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
|
|
|
using SunlightAggregationTerminal.Class;
|
|
|
|
|
using SunlightAggregationTerminal.Models;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using TouchSocket.Core;
|
|
|
|
|
|
|
|
|
|
namespace SunlightAggregationTerminal;
|
|
|
|
|
|
|
|
|
|
public partial class QueryPage : ContentPage
|
|
|
|
|
{
|
|
|
|
|
public static ObservableCollection<DyelotItem> DyelotItems { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
public QueryPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
WeakReferenceMessenger.Default.Register<string>(this, (r, scannedValue) =>
|
|
|
|
|
{
|
|
|
|
|
ResultEntry.Text = scannedValue;
|
|
|
|
|
//扫码返回信息
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(scannedValue))
|
|
|
|
|
{
|
|
|
|
|
Dictionary<string, object> QueryDictionary = new Dictionary<string, object>();
|
|
|
|
|
QueryDictionary.Add("Command", "QueryDyelot");
|
|
|
|
|
QueryDictionary.Add("Field", "[Dyelot],[ReDye],[Program],[Color],[CreationTime]," +
|
|
|
|
|
"[Batch],[OrderNo],[TotalWeight],[LiquidRatio],[TotalVolume],[Final],[UserAccount]," +
|
|
|
|
|
"[FabricName],[ColorName],[CustomerName],[Notes]");
|
|
|
|
|
QueryDictionary.Add("DyelotName", scannedValue);
|
|
|
|
|
Query_Command(QueryDictionary.ToJsonString());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Query_data();
|
|
|
|
|
|
|
|
|
|
CardCollectionView.ItemsSource = DyelotItems;
|
|
|
|
|
}
|
|
|
|
|
private async void OnScanButtonClicked(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 跳转到扫码页面
|
|
|
|
|
await Navigation.PushAsync(new ScanPage(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (sender is Microsoft.Maui.Controls.BindableObject bindable)
|
|
|
|
|
{
|
|
|
|
|
var context = bindable.BindingContext;
|
|
|
|
|
|
|
|
|
|
if (context is DyelotItem item)
|
|
|
|
|
{
|
|
|
|
|
await Navigation.PushAsync(new QueryDetail(item));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//信息回复
|
|
|
|
|
public static void Query_data(string dat)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var data = JsonSerializer.Deserialize<List<DyelotItem>>(dat);
|
|
|
|
|
|
|
|
|
|
if (data != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in data)
|
|
|
|
|
{
|
|
|
|
|
if(item.CreationTime != null) item.CreationTime = item.CreationTime.Replace("T", " ");
|
|
|
|
|
DyelotItems.Add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.Count == 0)
|
|
|
|
|
{//如果无信息添加空白行
|
|
|
|
|
DyelotItems.Add(new DyelotItem { });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void Query_Command(string dat)
|
|
|
|
|
{
|
|
|
|
|
LoadingIndicator.IsVisible = true;
|
|
|
|
|
DyelotItems.Clear();
|
|
|
|
|
|
|
|
|
|
DataReceived.Transmit(dat);
|
|
|
|
|
|
|
|
|
|
// 创建一个 15 秒的延时任务
|
|
|
|
|
Task delayTask = Task.Delay(15000);
|
|
|
|
|
// 创建一个监测任务,不断检查变量
|
|
|
|
|
Task monitorTask = Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
while (DyelotItems.Count==0)
|
|
|
|
|
{
|
|
|
|
|
// 每隔 100 毫秒检查一次,避免 CPU 占用过高
|
|
|
|
|
await Task.Delay(100);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 使用 Task.WhenAny 等待任意一个任务完成
|
|
|
|
|
await Task.WhenAny(delayTask, monitorTask);
|
|
|
|
|
|
|
|
|
|
LoadingIndicator.IsVisible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Button_Clicked(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (ResultEntry.Text != null)
|
|
|
|
|
{
|
|
|
|
|
Dictionary<string, object> QueryDictionary = new Dictionary<string, object>();
|
|
|
|
|
QueryDictionary.Add("Command", "QueryDyelot");
|
|
|
|
|
QueryDictionary.Add("Field", "[Dyelot],[ReDye],[Program],[Color],[CreationTime]," +
|
|
|
|
|
"[Batch],[OrderNo],[TotalWeight],[LiquidRatio],[TotalVolume],[Final],[UserAccount]," +
|
|
|
|
|
"[FabricName],[ColorName],[CustomerName],[Notes]");
|
|
|
|
|
QueryDictionary.Add("DyelotName", ResultEntry.Text);
|
|
|
|
|
Query_Command(QueryDictionary.ToJsonString());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Query_data();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Query_data()
|
|
|
|
|
{
|
|
|
|
|
Dictionary<string, object> QueryDictionary = new Dictionary<string, object>();
|
|
|
|
|
QueryDictionary.Add("Command", "Query");
|
|
|
|
|
QueryDictionary.Add("Field", "[Dyelot],[ReDye],[Program],[Color],[CreationTime]," +
|
|
|
|
|
"[Batch],[OrderNo],[TotalWeight],[LiquidRatio],[TotalVolume],[Final],[UserAccount]," +
|
|
|
|
|
"[FabricName],[ColorName],[CustomerName],[Notes]");
|
|
|
|
|
QueryDictionary.Add("StartTime", StartTime.Date.ToString()!);
|
|
|
|
|
DateTime EndTime_ = (DateTime)EndTime.Date!;
|
|
|
|
|
QueryDictionary.Add("EndTime", EndTime_.AddDays(1).ToString());
|
|
|
|
|
Query_Command(QueryDictionary.ToJsonString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理“回车/完成”按钮点击
|
|
|
|
|
/* private void OnEntryCompleted()
|
|
|
|
|
{
|
|
|
|
|
string inputText = ResultEntry.Text;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(inputText))
|
|
|
|
|
{
|
|
|
|
|
Dictionary<string, object> QueryDictionary = new Dictionary<string, object>();
|
|
|
|
|
QueryDictionary.Add("Command", "QueryDyelot");
|
|
|
|
|
QueryDictionary.Add("Field", "[Dyelot],[ReDye],[Program],[Color],[CreationTime]," +
|
|
|
|
|
"[Batch],[OrderNo],[TotalWeight],[LiquidRatio],[TotalVolume],[Final],[UserAccount]," +
|
|
|
|
|
"[FabricName],[ColorName],[CustomerName],[Notes]");
|
|
|
|
|
QueryDictionary.Add("DyelotName", inputText);
|
|
|
|
|
Query_Command(QueryDictionary.ToJsonString());
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
}
|