Administrator 2 months ago
parent
commit
321e7d84c2
  1. 19
      Class/TcpServer.cs
  2. 6
      InfoPage.xaml.cs
  3. 18
      QueryDetail.xaml
  4. 12
      QueryDetail.xaml.cs
  5. 23
      QueryPage.xaml
  6. 15
      QueryPage.xaml.cs

19
Class/TcpServer.cs

@ -78,7 +78,10 @@ namespace SunlightAggregationTerminal.Class
} }
catch (Exception ex) catch (Exception ex)
{ {
await Application.Current!.Windows[0].Page!.DisplayAlertAsync("错误", ex.Message.ToString(), "是"); MainThread.BeginInvokeOnMainThread(() =>
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("错误", ex.Message.ToString(), "是");
});
} }
finally finally
{ {
@ -171,7 +174,12 @@ namespace SunlightAggregationTerminal.Class
} }
} }
catch (Exception ex) { Application.Current!.Windows[0].Page!.DisplayAlertAsync("", ex.Message.ToString(), "是"); } catch (Exception ex) {
MainThread.BeginInvokeOnMainThread(() =>
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("", ex.Message.ToString(), "是");
});
}
return EasyTask.CompletedTask; return EasyTask.CompletedTask;
}; };
@ -180,6 +188,7 @@ namespace SunlightAggregationTerminal.Class
try try
{ {
await tcpClient.SetupAsync(new TouchSocketConfig() await tcpClient.SetupAsync(new TouchSocketConfig()
.SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包
.SetRemoteIPHost(ip) .SetRemoteIPHost(ip)
.ConfigurePlugins(a => .ConfigurePlugins(a =>
{ {
@ -188,11 +197,15 @@ namespace SunlightAggregationTerminal.Class
options.PollingInterval = TimeSpan.FromSeconds(5); options.PollingInterval = TimeSpan.FromSeconds(5);
}); });
})); }));
await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。 await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。
} }
catch (Exception ex) catch (Exception ex)
{ {
await Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", ex.Message.ToString(), "是"); MainThread.BeginInvokeOnMainThread(() =>
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", ex.Message.ToString(), "是");
});
} }
} }
} }

6
InfoPage.xaml.cs

@ -11,8 +11,6 @@ public partial class InfoPage : ContentPage
{ {
public static ObservableCollection<InfoItem> InfoItems { get; set; } = new(); public static ObservableCollection<InfoItem> InfoItems { get; set; } = new();
private DateTime _lastRefreshTime = DateTime.MinValue; private DateTime _lastRefreshTime = DateTime.MinValue;
public static string? _Name, _State, _MachineName, _Machine, _Information, _Model,
_Type, _ModelA, _ModelB, _ModelC, _ModelD, _ModelE, _ModelF;
public InfoPage() public InfoPage()
{ {
@ -27,8 +25,8 @@ public partial class InfoPage : ContentPage
}); });
//注册当前页面的下滑刷新 //注册当前页面的下滑刷新
myRefreshView_.Refreshing += (sender, e) => { myRefreshView_.Refreshing += (sender, e) => {
// 5秒防抖判断:如果距离上次刷新不足5秒,直接取消本次操作 // 防抖判断:如果距离上次刷新不足5秒,直接取消本次操作
if ((DateTime.Now - _lastRefreshTime).TotalSeconds < 5) if ((DateTime.Now - _lastRefreshTime).TotalSeconds < 1)
{ {
myRefreshView_.IsRefreshing = false; myRefreshView_.IsRefreshing = false;
return; return;

18
QueryDetail.xaml

@ -8,34 +8,34 @@
<VerticalStackLayout> <VerticalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="工单: " FontAttributes="Bold" FontSize="22" TextColor="Black"/> <Label Text="工单: " FontAttributes="Bold" FontSize="22" TextColor="Black"/>
<Label Text="{Binding Dyelot}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/> <Label x:Name="_Dyelot" FontAttributes="Bold" FontSize="22" TextColor="Gray"/>
<Label Text="@" FontAttributes="Bold" FontSize="22" TextColor="Black"/> <Label Text="@" FontAttributes="Bold" FontSize="22" TextColor="Black"/>
<Label Text="{Binding ReDye}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/> <Label x:Name="_ReDye" 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 Machine}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/> <Label x:Name="_Machine" 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 CreationTime}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/> <Label x:Name="_CreationTime" 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 x:Name="_FabricName1" 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 x:Name="_FabricName" 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 CustomerName}" FontAttributes="Bold" FontSize="22" TextColor="Gray"/> <Label x:Name="_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 FontSize="22" BackgroundColor="Black"/> <Label FontSize="22" BackgroundColor="Black"/>
<Label Text="{Binding 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 HeightRequest="25" Color="#E0E0E0" Margin="0,0" />
</VerticalStackLayout> </VerticalStackLayout>

12
QueryDetail.xaml.cs

@ -8,11 +8,17 @@ 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 static ObservableCollection<DyelotDetailsItem> QueryDetailDyelotDetailsItemst { get; set; } = new();
public QueryDetail(DyelotItem item) public QueryDetail(DyelotItem item)
{ {
InitializeComponent(); InitializeComponent();
_Dyelot.Text = item.Dyelot;
_ReDye.Text = item.ReDye?.ToString()??"";
_Machine.Text = item.Machine;
_CreationTime.Text = item.CreationTime;
_FabricName.Text = item.FabricName;
_CustomerName.Text = item.CustomerName;
_ColorName.Text = item.ColorName;
QueryDetailDyelotDetailsItems.Add(new DyelotDetailsItem QueryDetailDyelotDetailsItems.Add(new DyelotDetailsItem
{ {
Dyelot = "2134566", Dyelot = "2134566",

23
QueryPage.xaml

@ -4,8 +4,9 @@
x:Class="SunlightAggregationTerminal.QueryPage" x:Class="SunlightAggregationTerminal.QueryPage"
Title=""> Title="">
<Grid> <Grid>
<VerticalStackLayout> <Grid RowDefinitions="Auto, *" >
<Grid RowDefinitions="Auto, *" ColumnDefinitions="*, Auto"> <Grid RowDefinitions="Auto, *" ColumnDefinitions="*, Auto"
Grid.Row="0" Grid.Column="0">
<Border Grid.Row="0" Grid.Column="0" Stroke="#CCCCCC" <Border Grid.Row="0" Grid.Column="0" Stroke="#CCCCCC"
StrokeThickness="1" StrokeShape="RoundRectangle 10" StrokeThickness="1" StrokeShape="RoundRectangle 10"
BackgroundColor="White" Padding="0,0" BackgroundColor="White" Padding="0,0"
@ -26,16 +27,16 @@
</Button> </Button>
<StackLayout Grid.Row="1" Grid.Column="0" > <StackLayout Grid.Row="1" Grid.Column="0" >
<HorizontalStackLayout> <HorizontalStackLayout>
<DatePicker x:Name="StartTime" Format="yyyy-MM-dd" FontSize="18"/> <DatePicker x:Name="StartTime" Format="yyyy年MM月dd日" FontSize="16"/>
<Label Text="~" FontSize="32"/> <Label Text="~" FontSize="32"/>
<DatePicker x:Name="EndTime" Format="yyyy-MM-dd" FontSize="18"/> <DatePicker x:Name="EndTime" Format="yyyy年MM月dd日" FontSize="16"/>
<Button Text="搜索" Margin="5"/> <Button Text="搜索" Clicked="Button_Clicked" Padding="25,0,25,0"/>
</HorizontalStackLayout> </HorizontalStackLayout>
</StackLayout> </StackLayout>
</Grid> </Grid>
<Grid>
<CollectionView x:Name="CardCollectionView" <Grid Grid.Row="1" Grid.Column="0">
RemainingItemsThreshold="5"> <CollectionView x:Name="CardCollectionView" RemainingItemsThreshold="5">
<!-- 保持滚动条 --> <!-- 保持滚动条 -->
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -81,10 +82,10 @@
</Border> </Border>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
</Grid> </Grid>
</VerticalStackLayout> </Grid>
<!-- 查询中动画页面 --> <!-- 查询中动画页面 -->
<Grid x:Name="LoadingIndicator" BackgroundColor="Gray" <Grid x:Name="LoadingIndicator" BackgroundColor="Gray"
IsVisible="False" Opacity="0.9"> IsVisible="False" Opacity="0.9">

15
QueryPage.xaml.cs

@ -25,9 +25,8 @@ public partial class QueryPage : ContentPage
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());
TcpServer.TcpTransmit(QueryDictionary.ToJsonString()); 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)
@ -91,6 +90,16 @@ public partial class QueryPage : ContentPage
LoadingIndicator.IsVisible = false; LoadingIndicator.IsVisible = false;
} }
private void Button_Clicked(object sender, EventArgs e)
{
Dictionary<string, object> QueryDictionary = new Dictionary<string, object>();
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());
}
// 处理“回车/完成”按钮点击 // 处理“回车/完成”按钮点击
/* private void OnEntryCompleted() /* private void OnEntryCompleted()
{ {

Loading…
Cancel
Save