Browse Source

查询页面相关的信息

master
Administrator 2 months ago
parent
commit
7aad6f8d1a
  1. 4
      Class/TcpServer.cs
  2. 39
      InfoDetail.xaml.cs
  3. 3
      InfoPage.xaml
  4. 28
      Models/DataSource.cs
  5. 31
      QueryDetail.xaml
  6. 129
      QueryDetail.xaml.cs
  7. 30
      QueryPage.xaml
  8. 38
      QueryPage.xaml.cs

4
Class/TcpServer.cs

@ -141,6 +141,10 @@ namespace SunlightAggregationTerminal.Class
{ {
QueryPage.Query_data(val.ToString()!); 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)//信息通知接受 if (data.TryGetValue("Notification", out val) && val != null)//信息通知接受
{ {
var dataNotification = JsonSerializer.Deserialize<Dictionary<string, object>>(val.ToString()!); var dataNotification = JsonSerializer.Deserialize<Dictionary<string, object>>(val.ToString()!);

39
InfoDetail.xaml.cs

@ -20,44 +20,7 @@ public partial class InfoDetail : ContentPage
InfoProbuctItems.Add(new ProbuctItem { ProductName = "afars", ProductCode = "cs", ProductState = "", ProductInf = "" }); 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_machine.ItemsSource = InfoProbuctItems;
CardCollectionView_history.ItemsSource = InfoDyelotDetailsItems; CardCollectionView_history.ItemsSource = InfoDyelotDetailsItems;

3
InfoPage.xaml

@ -11,8 +11,7 @@
</ResourceDictionary> </ResourceDictionary>
</ContentPage.Resources> </ContentPage.Resources>
<RefreshView x:Name="myRefreshView_" > <RefreshView x:Name="myRefreshView_" >
<CollectionView x:Name="CardCollectionView" <CollectionView x:Name="CardCollectionView">
RemainingItemsThreshold="5">
<!-- 保持滚动条 --> <!-- 保持滚动条 -->
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>

28
Models/DataSource.cs

@ -52,30 +52,34 @@ namespace SunlightAggregationTerminal.Models
{ {
public string? Dyelot { get; set; } public string? Dyelot { get; set; }
public int? ReDye { get; set; } public int? ReDye { get; set; }
public int? Color { get; set; }
public string? Machine { get; set; } public string? Machine { get; set; }
public string? Program { get; set; }
public string? CreationTime { get; set; } public string? CreationTime { get; set; }
public string? FabricName { get; set; } public string? FabricName { get; set; }
public string? ColorName { get; set; } public string? ColorName { get; set; }
public string? CustomerName { get; set; } public string? CustomerName { get; set; }
public string? Information { get; set; } public string? Notes { get; set; }
} }
public class DyelotDetailsItem public class DyelotDetailsItem
{ {
public string? Dyelot { get; set; } public string? Dyelot { get; set; }
public int? ReDye { get; set; } public int? ReDye { get; set; }
public string? Step { get; set; } public int? StepNumber { get; set; }
public string? ProductName { get; set; } public string? ProductName { get; set; }
public string? ProductCode { get; set; } public string? ProductCode { get; set; }
public string? ProductType { get; set; } public int? ProductType { get; set; }
public string? ProductProgram { get; set; } public string? Process { get; set; }
public string? DispenserGram { get; set; } public double? Grams { get; set; }
public string? Gram { get; set; } public string GramsDisplay => Grams?.ToString("F2") ?? "";
public string? Machine { get; set; } public string? Created { get; set; }
public string? CreationTime { get; set; } public string? DispenseStartTime { get; set; }
public string? CallTime { get; set; } public string? DispenseEndTime { get; set; }
public string? EndTime { get; set; } public string? DispenseTime { get; set; }
public string? StartTime { get; set; } public double? DispenseGrams { get; set; }
public string? Information { get; set; } public string DispenseGramsDisplay => DispenseGrams?.ToString("F2") ?? "";
public int? DispenseResult { get; set; }
public string? Notes { get; set; }
} }
public static class DataService public static class DataService

31
QueryDetail.xaml

@ -2,7 +2,7 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SunlightAggregationTerminal.QueryDetail" x:Class="SunlightAggregationTerminal.QueryDetail"
Title="细节"> Title="细节" >
<Grid RowDefinitions="Auto, *" > <Grid RowDefinitions="Auto, *" >
<Grid BackgroundColor="#CCCCCC" Padding="10" Grid.Row="0" Grid.Column="0"> <Grid BackgroundColor="#CCCCCC" Padding="10" Grid.Row="0" Grid.Column="0">
<VerticalStackLayout> <VerticalStackLayout>
@ -36,8 +36,8 @@
<Label Text="颜色: " FontAttributes="Bold" FontSize="22" TextColor="Black"/> <Label Text="颜色: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
<Label FontSize="22" BackgroundColor="Black"/> <Label FontSize="22" BackgroundColor="Black"/>
<Label x:Name="_ColorName" FontAttributes="Bold" FontSize="22" TextColor="Gray"/> <Label x:Name="_ColorName" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<BoxView HeightRequest="25" Color="#E0E0E0" Margin="0,0" /> <BoxView x:Name="_Color" HeightRequest="25" />
</VerticalStackLayout> </VerticalStackLayout>
</Grid> </Grid>
@ -52,19 +52,19 @@
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="步骤: " FontAttributes="Bold" <Label Text="步骤: " FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
<Label Text="{Binding Step}" FontAttributes="Bold" <Label Text="{Binding StepNumber}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="呼叫: " FontAttributes="Bold" <Label Text="开始时间: " FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
<Label Text="{Binding Machine}" FontAttributes="Bold" <Label Text="{Binding DispenseStartTime}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="时间: " FontAttributes="Bold" <Label Text="完成时间: " FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
<Label Text="{Binding EndTime}" FontAttributes="Bold" <Label Text="{Binding DispenseEndTime}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<BoxView HeightRequest="3" Color="#CCCCCC" /> <BoxView HeightRequest="3" Color="#CCCCCC" />
@ -78,6 +78,19 @@
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
</Grid> </Grid>
<Grid x:Name="LoadingIndicator" Grid.Row="1" Grid.Column="0"
BackgroundColor="Gray" IsVisible="False" Opacity="0.9">
<VerticalStackLayout Padding="30" Spacing="10"
VerticalOptions="Center"
HorizontalOptions="Center">
<ActivityIndicator IsRunning="True"
Color="#512BD4"
HorizontalOptions="Center"
VerticalOptions="Center" />
<Label Text="查询中..." FontAttributes="Bold"
FontSize="24" TextColor="Black"/>
</VerticalStackLayout>
</Grid>
</Grid> </Grid>
</ContentPage> </ContentPage>

129
QueryDetail.xaml.cs

@ -1,12 +1,14 @@
using SunlightAggregationTerminal.Class;
using SunlightAggregationTerminal.Models; using SunlightAggregationTerminal.Models;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Text.Json;
using TouchSocket.Core;
namespace SunlightAggregationTerminal; namespace SunlightAggregationTerminal;
public partial class QueryDetail : ContentPage public partial class QueryDetail : ContentPage
{ {
public static ObservableCollection<DyelotDetailsItem> QueryDetailDyelotDetailsItems { get; set; } = new(); public static ObservableCollection<DyelotDetailsItem> QueryDetailDyelotDetailsItems { get; set; } = new();
public static ObservableCollection<DyelotDetailsItem> QueryDetailDyelotDetailsItemst { get; set; } = new();
public QueryDetail(DyelotItem item) public QueryDetail(DyelotItem item)
{ {
InitializeComponent(); InitializeComponent();
@ -18,73 +20,37 @@ public partial class QueryDetail : ContentPage
_FabricName.Text = item.FabricName; _FabricName.Text = item.FabricName;
_CustomerName.Text = item.CustomerName; _CustomerName.Text = item.CustomerName;
_ColorName.Text = item.ColorName; _ColorName.Text = item.ColorName;
// 如果 item.Color 为 null,则默认为透明色
_Color.Color = item.Color.HasValue ? Color.FromInt(item.Color.Value) : Colors.Gray;
QueryDetailDyelotDetailsItems.Add(new DyelotDetailsItem Dictionary<string, object> QueryDictionary = new Dictionary<string, object>();
{ QueryDictionary.Add("Command", "QueryDetail");
Dyelot = "2134566", QueryDictionary.Add("Field", "[Dyelot],[ReDye],[StepNumber],[ProductCode],[ProductName]," +
Machine = "g01", "[ProductType],[Grams],[Created],[DispenseStartTime],[DispenseEndTime],[DispenseTime]," +
Step="3", "[DispenseGrams],[DispenseResult],[Process],[Notes]");
CreationTime = "", QueryDictionary.Add("Dyelot", item.Dyelot?.ToString() ?? "");
DispenserGram="32434", QueryDictionary.Add("ReDye", item.ReDye?.ToString()??"");
Gram = "3212", Query_Command(QueryDictionary.ToJsonString());
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_();
} }
private void Data_() private void Data_()
{ {
var processedList = QueryDetailDyelotDetailsItems var processedList = QueryDetailDyelotDetailsItems
.GroupBy(item => new .GroupBy(item => new
{ {
// 建议加上 ?.Trim() 防止空格和 null 导致的分组偏差 // ?.Trim() 防止空格和 null 导致的分组偏差
Dyelot = item.Dyelot?.Trim(), Dyelot = item.Dyelot?.Trim(),
Step = item.Step?.Trim() Step = item.StepNumber
}) })
.Select(g => .Select(g =>
{ {
var firstItem = g.First(); var list = g.ToList();
// 提取该组内所有的 ProductName 并转为字符串 var firstItem = list.First();
// 提取该组内所有的 Gram,安全地转为字符串(防止 null 报错) // 直接使用 Select 的重载,获取当前元素的索引 i,然后通过 list[i] 访问对应的其他字段
// 将两者用 Zip 方法一一配对,拼接成 "ProductName(Gram)" 的格式 var combinedInfo = string.Join("\n",
// 如果只想简单的全部堆在一起,也可以直接用 string.Join(",", productNames.Concat(grams)) list.Select((x, i) => $"原料: {list[i].ProductName} ({list[i].ProductCode})\n" +
var productNames = g.Select(x => x.ProductName); $"目标/实际: {list[i].GramsDisplay}g / {list[i].DispenseGramsDisplay}g")
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"));
// 赋值给最终展示的 ProductName // 赋值给最终展示的 ProductName
firstItem.ProductName = combinedInfo; firstItem.ProductName = combinedInfo;
return firstItem; return firstItem;
@ -99,4 +65,55 @@ public partial class QueryDetail : ContentPage
} }
CardCollectionView_data.ItemsSource = QueryDetailDyelotDetailsItems; 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)
{
}
}
} }

30
QueryPage.xaml

@ -18,25 +18,23 @@
</Border> </Border>
<!--扫码按钮--> <!--扫码按钮-->
<Button Grid.Row="0" Grid.Column="1" Clicked="OnScanButtonClicked" <Button Grid.Row="0" Grid.Column="1" Clicked="OnScanButtonClicked"
BackgroundColor="Transparent" WidthRequest="60" BackgroundColor="Transparent" WidthRequest="80"
HeightRequest="60" Margin="10"> HeightRequest="60" Margin="10">
<Button.ImageSource> <Button.ImageSource>
<!-- 设置图标 --> <!-- 设置图标 -->
<FileImageSource File="lucidescanline.png" /> <FileImageSource File="lucidescanline.png" />
</Button.ImageSource> </Button.ImageSource>
</Button> </Button>
<StackLayout Grid.Row="1" Grid.Column="0" > <HorizontalStackLayout Grid.Row="1" Grid.Column="0">
<HorizontalStackLayout> <DatePicker x:Name="StartTime" Format="yyyy年MM月dd日" FontSize="16"/>
<DatePicker x:Name="StartTime" Format="yyyy年MM月dd日" FontSize="16"/> <Label Text="~" FontSize="28"/>
<Label Text="~" FontSize="32"/> <DatePicker x:Name="EndTime" Format="yyyy年MM月dd日" FontSize="16"/>
<DatePicker x:Name="EndTime" Format="yyyy年MM月dd日" FontSize="16"/> </HorizontalStackLayout>
<Button Text="搜索" Clicked="Button_Clicked" Padding="25,0,25,0"/> <Button Grid.Row="1" Grid.Column="1" Text="搜索" Clicked="Button_Clicked" Padding="30,0,30,0" Margin="5" />
</HorizontalStackLayout>
</StackLayout>
</Grid> </Grid>
<Grid Grid.Row="1" Grid.Column="0"> <Grid Grid.Row="1" Grid.Column="0">
<CollectionView x:Name="CardCollectionView" RemainingItemsThreshold="5"> <CollectionView x:Name="CardCollectionView">
<!-- 保持滚动条 --> <!-- 保持滚动条 -->
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -61,20 +59,20 @@
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="工艺: " FontAttributes="Bold" FontSize="22" TextColor="Black"/> <Label Text="工艺: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
<Label Text="{Binding FabricName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/> <Label Text="{Binding Program}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="面料: " FontAttributes="Bold" FontSize="22" TextColor="Black"/> <Label Text="面料: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
<Label Text="{Binding FabricName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/> <Label Text="{Binding FabricName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label Text="客户: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
<Label Text="{Binding CustomerName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="颜色: " FontAttributes="Bold" FontSize="22" TextColor="Black"/> <Label Text="颜色: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
<Label Text="{Binding ColorName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/> <Label Text="{Binding ColorName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout>
<Label Text="客户: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
<Label Text="{Binding CustomerName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
</HorizontalStackLayout>
</VerticalStackLayout> </VerticalStackLayout>
<Border.GestureRecognizers> <Border.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/> <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>

38
QueryPage.xaml.cs

@ -20,13 +20,8 @@ public partial class QueryPage : ContentPage
ResultEntry.Text = scannedValue; ResultEntry.Text = scannedValue;
}); });
Dictionary<string, object> QueryDictionary = new Dictionary<string, object>(); Query_data();
QueryDictionary.Add("Command", "Query");
QueryDictionary.Add("StartTime", StartTime.Date.ToString()!);
DateTime EndTime_ = (DateTime)EndTime.Date!;
QueryDictionary.Add("EndTime", EndTime_.AddDays(1).ToString());
Query_Command(QueryDictionary.ToJsonString());
CardCollectionView.ItemsSource = DyelotItems; CardCollectionView.ItemsSource = DyelotItems;
} }
private async void OnScanButtonClicked(object sender, EventArgs e) private async void OnScanButtonClicked(object sender, EventArgs e)
@ -61,7 +56,12 @@ public partial class QueryPage : ContentPage
{ {
DyelotItems.Add(item); DyelotItems.Add(item);
} }
}
if (data.Count == 0)
{//如果无信息添加空白行
DyelotItems.Add(new DyelotItem { });
}
}
} }
catch (Exception ex) { catch (Exception ex) {
} }
@ -92,14 +92,36 @@ public partial class QueryPage : ContentPage
} }
private void Button_Clicked(object sender, EventArgs e) 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>(); Dictionary<string, object> QueryDictionary = new Dictionary<string, object>();
QueryDictionary.Add("Command", "Query"); 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()!); QueryDictionary.Add("StartTime", StartTime.Date.ToString()!);
DateTime EndTime_ = (DateTime)EndTime.Date!; DateTime EndTime_ = (DateTime)EndTime.Date!;
QueryDictionary.Add("EndTime", EndTime_.AddDays(1).ToString()); QueryDictionary.Add("EndTime", EndTime_.AddDays(1).ToString());
Query_Command(QueryDictionary.ToJsonString()); Query_Command(QueryDictionary.ToJsonString());
} }
// 处理“回车/完成”按钮点击 // 处理“回车/完成”按钮点击
/* private void OnEntryCompleted() /* private void OnEntryCompleted()
{ {

Loading…
Cancel
Save