|
|
|
@ -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<DyelotDetailsItem> QueryDetailDyelotDetailsItems { get; set; } = new(); |
|
|
|
public static ObservableCollection<DyelotDetailsItem> 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<string, object> QueryDictionary = new Dictionary<string, object>(); |
|
|
|
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<List<DyelotDetailsItem>>(dat); |
|
|
|
|
|
|
|
if (data != null) |
|
|
|
{ |
|
|
|
//添加入显示信息
|
|
|
|
foreach (var item in data) |
|
|
|
{ |
|
|
|
QueryDetailDyelotDetailsItems.Add(item); |
|
|
|
} |
|
|
|
|
|
|
|
if (data.Count == 0) |
|
|
|
{//如果无信息添加空白行
|
|
|
|
QueryDetailDyelotDetailsItems.Add(new DyelotDetailsItem { }); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |