diff --git a/Class/TcpServer.cs b/Class/TcpServer.cs index 690eeee..a9f9189 100644 --- a/Class/TcpServer.cs +++ b/Class/TcpServer.cs @@ -141,6 +141,10 @@ namespace SunlightAggregationTerminal.Class { QueryPage.Query_data(val.ToString()!); } + if (data.TryGetValue("QueryDetail", out val) && val != null)//查询接受 + { + QueryDetail.Query_data(val.ToString()!); + } if (data.TryGetValue("Notification", out val) && val != null)//信息通知接受 { var dataNotification = JsonSerializer.Deserialize>(val.ToString()!); diff --git a/InfoDetail.xaml.cs b/InfoDetail.xaml.cs index 19c23e1..636c54e 100644 --- a/InfoDetail.xaml.cs +++ b/InfoDetail.xaml.cs @@ -20,44 +20,7 @@ public partial class InfoDetail : ContentPage InfoProbuctItems.Add(new ProbuctItem { ProductName = "afars", ProductCode = "cs", ProductState = "", ProductInf = "" }); - InfoDyelotDetailsItems.Add(new DyelotDetailsItem - { Dyelot = "2134566", Machine = "g01", CreationTime = "", CallTime = "" , - ReDye=0, - Information = "yyjjy\nfxfxdsdg\n", - }); - InfoDyelotDetailsItems.Add(new DyelotDetailsItem - { - Dyelot = "231423134566", - Machine = "g01", - CreationTime = "", - CallTime = "", - Information = "yyjjy\nfxfxdsdg\n", - }); - - InfoDyelotDetailsItems.Add(new DyelotDetailsItem - { - Dyelot = "2131324354566", - Machine = "g01", - CreationTime = "", - CallTime = "", - Information = "yyjjy\nfxfxdsdg\n", - }); - InfoDyelotDetailsItems.Add(new DyelotDetailsItem - { - Dyelot = "2134123243566", - Machine = "g01", - CreationTime = "", - CallTime = "", - Information = "yyjjy\nfxfxdsdg\n", - }); - InfoDyelotDetailsItems.Add(new DyelotDetailsItem - { - Dyelot = "2134566", - Machine = "g01", - CreationTime = "", - Information = "yyjjy\nfxfxdsdg\n", - }); - + CardCollectionView_machine.ItemsSource = InfoProbuctItems; CardCollectionView_history.ItemsSource = InfoDyelotDetailsItems; diff --git a/InfoPage.xaml b/InfoPage.xaml index 4c75824..49752ae 100644 --- a/InfoPage.xaml +++ b/InfoPage.xaml @@ -11,8 +11,7 @@ - + diff --git a/Models/DataSource.cs b/Models/DataSource.cs index 3e4788a..91381f9 100644 --- a/Models/DataSource.cs +++ b/Models/DataSource.cs @@ -52,30 +52,34 @@ namespace SunlightAggregationTerminal.Models { public string? Dyelot { get; set; } public int? ReDye { get; set; } + public int? Color { get; set; } public string? Machine { get; set; } + public string? Program { get; set; } public string? CreationTime { get; set; } public string? FabricName { get; set; } public string? ColorName { get; set; } public string? CustomerName { get; set; } - public string? Information { get; set; } + public string? Notes { get; set; } } public class DyelotDetailsItem { public string? Dyelot { get; set; } public int? ReDye { get; set; } - public string? Step { get; set; } + public int? StepNumber { get; set; } public string? ProductName { get; set; } public string? ProductCode { get; set; } - public string? ProductType { get; set; } - public string? ProductProgram { get; set; } - public string? DispenserGram { get; set; } - public string? Gram { get; set; } - public string? Machine { get; set; } - public string? CreationTime { get; set; } - public string? CallTime { get; set; } - public string? EndTime { get; set; } - public string? StartTime { get; set; } - public string? Information { get; set; } + public int? ProductType { get; set; } + public string? Process { get; set; } + public double? Grams { get; set; } + public string GramsDisplay => Grams?.ToString("F2") ?? ""; + public string? Created { get; set; } + public string? DispenseStartTime { get; set; } + public string? DispenseEndTime { get; set; } + public string? DispenseTime { get; set; } + public double? DispenseGrams { get; set; } + public string DispenseGramsDisplay => DispenseGrams?.ToString("F2") ?? ""; + public int? DispenseResult { get; set; } + public string? Notes { get; set; } } public static class DataService diff --git a/QueryDetail.xaml b/QueryDetail.xaml index 4c2f6a0..f572372 100644 --- a/QueryDetail.xaml +++ b/QueryDetail.xaml @@ -2,7 +2,7 @@ + Title="细节" > @@ -36,8 +36,8 @@ @@ -52,19 +52,19 @@ - - @@ -78,6 +78,19 @@ - + + + + + + \ No newline at end of file diff --git a/QueryDetail.xaml.cs b/QueryDetail.xaml.cs index 73cbb1e..36835be 100644 --- a/QueryDetail.xaml.cs +++ b/QueryDetail.xaml.cs @@ -1,12 +1,14 @@ +using SunlightAggregationTerminal.Class; using SunlightAggregationTerminal.Models; using System.Collections.ObjectModel; +using System.Text.Json; +using TouchSocket.Core; namespace SunlightAggregationTerminal; public partial class QueryDetail : ContentPage { public static ObservableCollection QueryDetailDyelotDetailsItems { get; set; } = new(); - public static ObservableCollection QueryDetailDyelotDetailsItemst { get; set; } = new(); public QueryDetail(DyelotItem item) { InitializeComponent(); @@ -18,73 +20,37 @@ public partial class QueryDetail : ContentPage _FabricName.Text = item.FabricName; _CustomerName.Text = item.CustomerName; _ColorName.Text = item.ColorName; + // 如果 item.Color 为 null,则默认为透明色 + _Color.Color = item.Color.HasValue ? Color.FromInt(item.Color.Value) : Colors.Gray; - QueryDetailDyelotDetailsItems.Add(new DyelotDetailsItem - { - Dyelot = "2134566", - Machine = "g01", - Step="3", - CreationTime = "", - DispenserGram="32434", - Gram = "3212", - ReDye = 0, - ProductName="sdvsf1", - Information = "yyjjy\nfxfxdsdg\n", - }); - QueryDetailDyelotDetailsItems.Add(new DyelotDetailsItem - { - Dyelot = "2134566", - Machine = "g01", - Step = "3", - CreationTime = "", - DispenserGram = "32423434", - Gram = "3212434", - ReDye = 0, - ProductName = "sdvsf2", - Information = "yyjjy\nfxfxdsdg\n", - }); - QueryDetailDyelotDetailsItems.Add(new DyelotDetailsItem - { - Dyelot = "2134566", - Machine = "g01", - CreationTime = "", - DispenserGram = "3212434", - Gram= "3212434", - Step = "4", - ReDye = 0, - ProductName = "sdvsf3", - Information = "yyjjy\nfxfxdsdg\n", - }); - - Data_(); - - + Dictionary QueryDictionary = new Dictionary(); + QueryDictionary.Add("Command", "QueryDetail"); + QueryDictionary.Add("Field", "[Dyelot],[ReDye],[StepNumber],[ProductCode],[ProductName]," + + "[ProductType],[Grams],[Created],[DispenseStartTime],[DispenseEndTime],[DispenseTime]," + + "[DispenseGrams],[DispenseResult],[Process],[Notes]"); + QueryDictionary.Add("Dyelot", item.Dyelot?.ToString() ?? ""); + QueryDictionary.Add("ReDye", item.ReDye?.ToString()??""); + Query_Command(QueryDictionary.ToJsonString()); } private void Data_() { - var processedList = QueryDetailDyelotDetailsItems .GroupBy(item => new { - // 建议加上 ?.Trim() 防止空格和 null 导致的分组偏差 + // ?.Trim() 防止空格和 null 导致的分组偏差 Dyelot = item.Dyelot?.Trim(), - Step = item.Step?.Trim() + Step = item.StepNumber }) .Select(g => { - var firstItem = g.First(); - // 提取该组内所有的 ProductName 并转为字符串 - // 提取该组内所有的 Gram,安全地转为字符串(防止 null 报错) - // 将两者用 Zip 方法一一配对,拼接成 "ProductName(Gram)" 的格式 - // 如果只想简单的全部堆在一起,也可以直接用 string.Join(",", productNames.Concat(grams)) - var productNames = g.Select(x => x.ProductName); - var grams = g.Select(x => x.Gram?.ToString()); - var dispenserGrams = g.Select(x => x.DispenserGram?.ToString()); - // 使用 Zip 将三者一一配对,拼接成 "名称(Gram/dispenserGram)" 的格式 - var combinedInfo = string.Join("\n",productNames.Zip(grams, (name, gram) => (name, gram)) // 先把前两个拼成元组 - .Zip(dispenserGrams, (pair, dispGram) => $"原料:{pair.name}\n目标用量:{pair.gram}g\n实际用量:{dispGram}g")); - + var list = g.ToList(); + var firstItem = list.First(); + // 直接使用 Select 的重载,获取当前元素的索引 i,然后通过 list[i] 访问对应的其他字段 + var combinedInfo = string.Join("\n", + list.Select((x, i) => $"原料: {list[i].ProductName} ({list[i].ProductCode})\n" + + $"目标/实际: {list[i].GramsDisplay}g / {list[i].DispenseGramsDisplay}g") + ); // 赋值给最终展示的 ProductName firstItem.ProductName = combinedInfo; return firstItem; @@ -99,4 +65,55 @@ public partial class QueryDetail : ContentPage } CardCollectionView_data.ItemsSource = QueryDetailDyelotDetailsItems; } + + public async void Query_Command(string dat) + { + LoadingIndicator.IsVisible = true; + QueryDetailDyelotDetailsItems.Clear(); + + TcpServer.TcpTransmit(dat); + + // 创建一个 秒的延时任务 + Task delayTask = Task.Delay(10000); + // 创建一个监测任务,不断检查变量 + Task monitorTask = Task.Run(async () => + { + while (QueryDetailDyelotDetailsItems.Count == 0) + { + // 每隔 100 毫秒检查一次,避免 CPU 占用过高 + await Task.Delay(1000); + } + }); + // 使用 Task.WhenAny 等待任意一个任务完成 + await Task.WhenAny(delayTask, monitorTask); + + Data_(); + + LoadingIndicator.IsVisible = false; + } + + public static void Query_data(string dat) + { + try + { + var data = JsonSerializer.Deserialize>(dat); + + if (data != null) + { + //添加入显示信息 + foreach (var item in data) + { + QueryDetailDyelotDetailsItems.Add(item); + } + + if (data.Count == 0) + {//如果无信息添加空白行 + QueryDetailDyelotDetailsItems.Add(new DyelotDetailsItem { }); + } + } + } + catch (Exception) + { + } + } } \ No newline at end of file diff --git a/QueryPage.xaml b/QueryPage.xaml index d6af685..b2e3535 100644 --- a/QueryPage.xaml +++ b/QueryPage.xaml @@ -18,25 +18,23 @@ - - - -