Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightAggregationTerminal
This commit is contained in:
commit
06bbb5c8be
3 files changed
+368
-29
No files matched your search
+10
-1
@@ -8,6 +8,7 @@ using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using TouchSocket.Core;
|
||||
|
||||
namespace SunlightAggregationTerminal.Class
|
||||
{
|
||||
@@ -136,10 +137,18 @@ namespace SunlightAggregationTerminal.Class
|
||||
{
|
||||
QueryPage.Query_data(val.ToString()!);
|
||||
}
|
||||
if (data.TryGetValue("QueryDetail", out val) && val != null)//查询接受
|
||||
if (data.TryGetValue("QueryDetail", out val) && val != null)//
|
||||
{
|
||||
QueryDetail.Query_data(val.ToString()!);
|
||||
}
|
||||
if (data.TryGetValue("InfoMachine", out val) && val != null)//
|
||||
{
|
||||
InfoDetail.Info_data(val.ToString()!,data.GetValue("Type").ToString()!);
|
||||
}
|
||||
if (data.TryGetValue("InfoMachinePipes", out val) && val != null)//
|
||||
{
|
||||
InfoDetail.Info_data(val.ToString()!, "00");
|
||||
}
|
||||
if (data.TryGetValue("Notification", out val) && val != null)//信息通知接受
|
||||
{
|
||||
var dataNotification = JsonSerializer.Deserialize<List<Dictionary<string, object>>>(val.ToString()!);
|
||||
|
||||
+34
-22
@@ -3,7 +3,8 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="SunlightAggregationTerminal.InfoDetail"
|
||||
xmlns:converters="clr-namespace:SunlightAggregationTerminal.Converters"
|
||||
Title="细节信息">
|
||||
Title="细节信息"
|
||||
Loaded="ContentPage_Loaded">
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
<converters:StringToImageConverter x:Key="StringToImageConverter" />
|
||||
@@ -44,23 +45,25 @@
|
||||
<Button Text="远程控制" Clicked="Button_control" BackgroundColor="Transparent" TextColor="Black"/>
|
||||
</HorizontalStackLayout>
|
||||
</Grid>
|
||||
<Grid x:Name="_real" Grid.Row="2" Grid.Column="0" >
|
||||
<VerticalStackLayout VerticalOptions="Center">
|
||||
<!-- 设备信息 -->
|
||||
<Label Text="{Binding ModelA}" FontAttributes="Bold" FontSize="22" TextColor="Black"
|
||||
IsVisible="{Binding Path=ModelA, Converter={StaticResource StringToBoolConverter}}"/>
|
||||
<Label Text="{Binding ModelB}" FontAttributes="Bold" FontSize="22" TextColor="Black"
|
||||
IsVisible="{Binding Path=ModelB, Converter={StaticResource StringToBoolConverter}}"/>
|
||||
<Label Text="{Binding ModelC}" FontAttributes="Bold" FontSize="22" TextColor="Black"
|
||||
IsVisible="{Binding Path=ModelC, Converter={StaticResource StringToBoolConverter}}"/>
|
||||
<Label Text="{Binding ModelD}" FontAttributes="Bold" FontSize="22" TextColor="Black"
|
||||
IsVisible="{Binding Path=ModelD, Converter={StaticResource StringToBoolConverter}}"/>
|
||||
<Label Text="{Binding ModelE}" FontAttributes="Bold" FontSize="22" TextColor="Black"
|
||||
IsVisible="{Binding Path=ModelE, Converter={StaticResource StringToBoolConverter}}"/>
|
||||
<Label Text="{Binding ModelF}" FontAttributes="Bold" FontSize="22" TextColor="Black"
|
||||
IsVisible="{Binding Path=ModelF, Converter={StaticResource StringToBoolConverter}}"/>
|
||||
<Label Text="{Binding Information}" FontAttributes="Bold" FontSize="22" TextColor="Black"/>
|
||||
</VerticalStackLayout>
|
||||
<Grid x:Name="_real" Grid.Row="2" Grid.Column="0" BackgroundColor="#F0F0F0">
|
||||
<!-- 设备信息 -->
|
||||
<RefreshView x:Name="myCardCollectionView_" >
|
||||
<CollectionView x:Name="CardCollectionView_inf" RemainingItemsThreshold="5">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border BackgroundColor="White" Stroke="#CCCCCC"
|
||||
StrokeThickness="2" Margin="10,0,10,10" StrokeShape="RoundRectangle 10">
|
||||
<VerticalStackLayout VerticalOptions="Center">
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="{Binding inf}" FontAttributes="Bold"
|
||||
FontSize="22" TextColor="Black"/>
|
||||
</HorizontalStackLayout>
|
||||
</VerticalStackLayout>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
</RefreshView>
|
||||
</Grid>
|
||||
|
||||
<!-- 设备内容 -->
|
||||
@@ -89,10 +92,7 @@
|
||||
<Label Text="{Binding ProductState}" FontAttributes="Bold"
|
||||
FontSize="22" TextColor="Black"/>
|
||||
</HorizontalStackLayout>
|
||||
<BoxView HeightRequest="3" Color="#CCCCCC" />
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="信息: " FontAttributes="Bold"
|
||||
FontSize="22" TextColor="Black"/>
|
||||
<Label Text="{Binding ProductInf}" FontAttributes="Bold"
|
||||
FontSize="22" TextColor="Black"/>
|
||||
</HorizontalStackLayout>
|
||||
@@ -156,6 +156,18 @@
|
||||
<Grid x:Name="_control" IsVisible="False" Grid.Row="2" Grid.Column="0" BackgroundColor="#F0F0F0">
|
||||
|
||||
</Grid>
|
||||
|
||||
<Grid x:Name="LoadingIndicator" Grid.Row="2" 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>
|
||||
</ContentPage>
|
||||
+324
-6
@@ -1,29 +1,122 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using SunlightAggregationTerminal.Class;
|
||||
using SunlightAggregationTerminal.Models;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text.Json;
|
||||
using TouchSocket.Core;
|
||||
|
||||
namespace SunlightAggregationTerminal;
|
||||
|
||||
public partial class InfoDetail : ContentPage
|
||||
public class InfoMachineItem
|
||||
{
|
||||
public string? inf { get; set; }
|
||||
}public partial class InfoDetail : ContentPage
|
||||
{
|
||||
public static ObservableCollection<ProbuctItem> InfoProbuctItems { get; set; } = new();
|
||||
public static ObservableCollection<DyelotDetailsItem> InfoDyelotDetailsItems { get; set; } = new();
|
||||
public static ObservableCollection<InfoMachineItem> InfoMachineItems { get; set; } = new();
|
||||
public static InfoItem infoItem=new();
|
||||
private DateTime _lastRefreshTime = DateTime.MinValue;
|
||||
public InfoDetail(InfoItem item)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.BindingContext = item;
|
||||
infoItem = item;
|
||||
myCardCollectionView_.Refreshing += (sender, e) => {
|
||||
// 防抖判断:如果距离上次刷新不足5秒,直接取消本次操作
|
||||
if ((DateTime.Now - _lastRefreshTime).TotalSeconds < 1)
|
||||
{
|
||||
myCardCollectionView_.IsRefreshing = false;
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
// 更新刷新时间
|
||||
_lastRefreshTime = DateTime.Now;
|
||||
InfoMachine();
|
||||
myCardCollectionView_.IsRefreshing = false;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
InfoProbuctItems.Add(new ProbuctItem { ProductName="cs", ProductCode="cs", ProductState="", ProductInf="" });
|
||||
InfoProbuctItems.Add(new ProbuctItem { ProductName = "c23s", ProductCode = "cweds", ProductState = "", ProductInf = "" });
|
||||
private void ContentPage_Loaded(object sender, EventArgs e)
|
||||
{
|
||||
InfoMachine();
|
||||
|
||||
InfoMachineItems.Clear();
|
||||
InfoProbuctItems.Clear();
|
||||
InfoDyelotDetailsItems.Clear();
|
||||
|
||||
|
||||
|
||||
CardCollectionView_inf.ItemsSource = InfoMachineItems;
|
||||
CardCollectionView_machine.ItemsSource = InfoProbuctItems;
|
||||
CardCollectionView_history.ItemsSource = InfoDyelotDetailsItems;
|
||||
}
|
||||
|
||||
private void InfoMachine() {
|
||||
Dictionary<string, object> data_ = new Dictionary<string, object>();
|
||||
data_.Add("Command", "InfoMachine");
|
||||
if (infoItem.Model == "252")
|
||||
{
|
||||
data_.Add("Type", "10");
|
||||
data_.Add("Field", "*");
|
||||
data_.Add("MachinName", infoItem.Machine!);
|
||||
Query_Command(data_.ToJsonString());
|
||||
}
|
||||
else if (infoItem.Model == "252-2T")
|
||||
{
|
||||
data_.Add("Type", "10");
|
||||
data_.Add("Field", "*");
|
||||
data_.Add("MachinName", infoItem.Machine!);
|
||||
Query_Command(data_.ToJsonString());
|
||||
}
|
||||
else if (infoItem.Model == "252RB")
|
||||
{
|
||||
data_.Add("Type", "10");
|
||||
data_.Add("Field", "*");
|
||||
data_.Add("MachinName", infoItem.Machine!);
|
||||
Query_Command(data_.ToJsonString());
|
||||
}
|
||||
else if (infoItem.Model == "252RDRM")
|
||||
{
|
||||
data_.Add("Type", "12");
|
||||
data_.Add("Field", "*");
|
||||
data_.Add("MachinName", infoItem.Machine!);
|
||||
Query_Command(data_.ToJsonString());
|
||||
}
|
||||
else if (infoItem.Model == "242W")
|
||||
{
|
||||
data_.Add("Type", "10");
|
||||
data_.Add("Field", "*");
|
||||
data_.Add("MachinName", infoItem.Machine!);
|
||||
Query_Command(data_.ToJsonString());
|
||||
}
|
||||
else if (infoItem.Model == "302")
|
||||
{
|
||||
data_.Add("Type", "20");
|
||||
data_.Add("Field", "*");
|
||||
data_.Add("MachinName", infoItem.Machine!);
|
||||
Query_Command(data_.ToJsonString());
|
||||
}
|
||||
else if (infoItem.Model == "303")
|
||||
{
|
||||
data_.Add("Type", "20");
|
||||
data_.Add("Field", "*");
|
||||
data_.Add("MachinName", infoItem.Machine!);
|
||||
Query_Command(data_.ToJsonString());
|
||||
}
|
||||
else if (infoItem.Model == "303PDW")
|
||||
{
|
||||
data_.Add("Type", "20");
|
||||
data_.Add("Field", "*");
|
||||
data_.Add("MachinName", infoItem.Machine!);
|
||||
Query_Command(data_.ToJsonString());
|
||||
}
|
||||
}
|
||||
|
||||
//设备信息
|
||||
private void Button_real(object sender, EventArgs e)
|
||||
{
|
||||
@@ -34,12 +127,28 @@ public partial class InfoDetail : ContentPage
|
||||
}
|
||||
|
||||
//设备内容
|
||||
private void Button_machine(object sender, EventArgs e)
|
||||
private async void Button_machine(object sender, EventArgs e)
|
||||
{
|
||||
_real.IsVisible = false;
|
||||
_machine.IsVisible = true;
|
||||
_history.IsVisible = false;
|
||||
_control.IsVisible = false;
|
||||
|
||||
if (infoItem.Model == "252" || infoItem.Model == "252-2T" ||
|
||||
infoItem.Model == "252RB" || infoItem.Model == "242W" ||
|
||||
infoItem.Model == "252RDRM")
|
||||
{
|
||||
await DisplayAlertAsync("限制", "当前功能暂不可用", "是");
|
||||
return;
|
||||
}
|
||||
|
||||
if (InfoProbuctItems.Count == 0)
|
||||
{
|
||||
Dictionary<string, object> data_ = new Dictionary<string, object>();
|
||||
data_.Add("Command", "InfoMachinePipes");
|
||||
data_.Add("MachinName", infoItem.Machine!);
|
||||
Query_Probuct(data_.ToJsonString());
|
||||
}
|
||||
}
|
||||
|
||||
//历史
|
||||
@@ -60,4 +169,213 @@ public partial class InfoDetail : ContentPage
|
||||
_control.IsVisible = true;
|
||||
await DisplayAlertAsync("限制", "当前功能暂不可用", "是");
|
||||
}
|
||||
|
||||
//发送请求
|
||||
public async void Query_Command(string dat)
|
||||
{
|
||||
LoadingIndicator.IsVisible = true;
|
||||
InfoMachineItems.Clear();
|
||||
|
||||
DataReceived.Transmit(dat);
|
||||
|
||||
// 创建一个 秒的延时任务
|
||||
Task delayTask = Task.Delay(10000);
|
||||
// 创建一个监测任务,不断检查变量
|
||||
Task monitorTask = Task.Run(async () =>
|
||||
{
|
||||
while (InfoMachineItems.Count == 0)
|
||||
{
|
||||
// 每隔 100 毫秒检查一次,避免 CPU 占用过高
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
});
|
||||
// 使用 Task.WhenAny 等待任意一个任务完成
|
||||
await Task.WhenAny(delayTask, monitorTask);
|
||||
|
||||
LoadingIndicator.IsVisible = false;
|
||||
}
|
||||
public async void Query_Probuct(string dat)
|
||||
{
|
||||
LoadingIndicator.IsVisible = true;
|
||||
InfoProbuctItems.Clear();
|
||||
|
||||
DataReceived.Transmit(dat);
|
||||
|
||||
// 创建一个 秒的延时任务
|
||||
Task delayTask = Task.Delay(10000);
|
||||
// 创建一个监测任务,不断检查变量
|
||||
Task monitorTask = Task.Run(async () =>
|
||||
{
|
||||
while (InfoProbuctItems.Count == 0)
|
||||
{
|
||||
// 每隔 100 毫秒检查一次,避免 CPU 占用过高
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
});
|
||||
// 使用 Task.WhenAny 等待任意一个任务完成
|
||||
await Task.WhenAny(delayTask, monitorTask);
|
||||
|
||||
LoadingIndicator.IsVisible = false;
|
||||
}
|
||||
|
||||
public static void Info_data(string dat, string id)
|
||||
{
|
||||
var data = JsonSerializer.Deserialize<List<Dictionary<string, object>>>(dat)!;
|
||||
if (id == "00")
|
||||
{
|
||||
foreach (var item in data!)
|
||||
{
|
||||
ProbuctItem probuctItem = new ProbuctItem();
|
||||
|
||||
probuctItem.ProductCode = item.GetValue("ProductCode").ToString()!;
|
||||
probuctItem.ProductName = item.GetValue("ProductName").ToString()!;
|
||||
if (item.GetValue("Enabled").ToString()! == "1")
|
||||
{
|
||||
probuctItem.ProductState = "启用";
|
||||
}
|
||||
else { probuctItem.ProductState = "停用"; }
|
||||
if (item!.TryGetValue("No", out var _No) && _No != null)
|
||||
{
|
||||
probuctItem.ProductInf = "管路:" + _No + "\n";
|
||||
}
|
||||
if (item!.TryGetValue("MinLimit", out var _MinLimit) && _MinLimit != null)
|
||||
{
|
||||
probuctItem.ProductInf = probuctItem.ProductInf+"最少量:" + _MinLimit + "g\n";
|
||||
}
|
||||
if (item!.TryGetValue("MaxLimit", out var _MaxLimit) && _MaxLimit != null)
|
||||
{
|
||||
probuctItem.ProductInf = probuctItem.ProductInf + "最大量:" + _MinLimit + "g\n";
|
||||
}
|
||||
if (item!.TryGetValue("Conc", out var _Conc) && _Conc != null)
|
||||
{
|
||||
probuctItem.ProductInf = probuctItem.ProductInf + "浓度:" + _Conc + "\n";
|
||||
}
|
||||
if (item!.TryGetValue("Enabled", out var _Gravity) && _Gravity != null)
|
||||
{
|
||||
probuctItem.ProductInf = probuctItem.ProductInf + "比重:" + _Gravity;
|
||||
}
|
||||
InfoProbuctItems.Add(probuctItem);
|
||||
}
|
||||
if (InfoProbuctItems.Count == 0) InfoProbuctItems.Add(new ProbuctItem());
|
||||
}
|
||||
else if(id == "10")
|
||||
{
|
||||
foreach (var item in data!)
|
||||
{
|
||||
string inf_ = "染机:" + item.GetValue("Machine").ToString()! + "\n";
|
||||
inf_ = inf_ + "料单:" + item.GetValue("Dyelot").ToString()!;
|
||||
inf_ = inf_ + "@" + item.GetValue("ReDye").ToString()! + "\n";
|
||||
inf_ = inf_ + "步骤:" + item.GetValue("StepNumber").ToString()! + "\n";
|
||||
inf_ = inf_ + "流程:" + item.GetValue("Process").ToString()! + "\n";
|
||||
inf_ = inf_ + "化料桶:" + item.GetValue("TankNO").ToString()! + "\n";
|
||||
inf_ = inf_ + "染料桶数:" + item.GetValue("TotalNumber").ToString()!;
|
||||
if (item!.TryGetValue("BarrelState", out var _Type) && _Type != null)
|
||||
{
|
||||
string temp = _Type?.ToString() ?? "";
|
||||
// 转换
|
||||
_Type = temp switch
|
||||
{
|
||||
"301" => "就绪",
|
||||
"309" => "未准备",
|
||||
_ => "无信息"
|
||||
};
|
||||
inf_ = inf_ + _Type;
|
||||
}
|
||||
inf_ = inf_ + "状态:" + item.GetValue("State").ToString()! + "\n";
|
||||
|
||||
InfoMachineItem infoMachineItem = new InfoMachineItem();
|
||||
infoMachineItem.inf = inf_;
|
||||
InfoMachineItems.Add(infoMachineItem);
|
||||
}
|
||||
if (InfoMachineItems.Count == 0) InfoMachineItems.Add(new InfoMachineItem());
|
||||
}
|
||||
else if (id == "12")
|
||||
{
|
||||
foreach (var item in data!)
|
||||
{
|
||||
string inf_ = "位置:" + item.GetValue("position").ToString()! + "\n";
|
||||
inf_ = inf_ + "料单:" + item.GetValue("Dyelot").ToString()!;
|
||||
inf_ = inf_ + "@" + item.GetValue("ReDye").ToString()! + "\n";
|
||||
inf_ = inf_ + "步骤:" + item.GetValue("StepNumber").ToString()! + "\n";
|
||||
if (item!.TryGetValue("BarrelType", out var _Type) && _Type != null)
|
||||
{
|
||||
string temp = _Type?.ToString() ?? "";
|
||||
// 转换
|
||||
_Type = temp switch
|
||||
{
|
||||
"1" => "空桶",
|
||||
"2" => "染料桶",
|
||||
_ => "无桶"
|
||||
};
|
||||
inf_ = inf_ + "类型:" + _Type;
|
||||
}
|
||||
if (item!.TryGetValue("BarrelState", out var _BarrelState) && _BarrelState != null)
|
||||
{
|
||||
string temp = _BarrelState?.ToString() ?? "";
|
||||
_BarrelState = temp switch
|
||||
{
|
||||
"201" => "[分桶]",
|
||||
_ => ""
|
||||
};
|
||||
inf_ = inf_ + _BarrelState;
|
||||
}
|
||||
inf_ = inf_ + "[" + item.GetValue("Barrelserialnumber").ToString()! + "]\n";
|
||||
inf_ = inf_ + "上架时间:" + DateTime.Parse(item.GetValue("createtime").ToString() ?? "")
|
||||
.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
|
||||
inf_ = inf_ + "状态[" + item.GetValue("State").ToString()! + "]";
|
||||
|
||||
InfoMachineItem infoMachineItem = new InfoMachineItem();
|
||||
infoMachineItem.inf = inf_;
|
||||
InfoMachineItems.Add(infoMachineItem);
|
||||
}
|
||||
if (InfoMachineItems.Count == 0) InfoMachineItems.Add(new InfoMachineItem());
|
||||
}
|
||||
else if (id == "20")
|
||||
{
|
||||
foreach (var item in data!)
|
||||
{
|
||||
string inf_ = "染机:" + item.GetValue("Machine").ToString()! + "\n";
|
||||
inf_ = inf_ + "料单:" + item.GetValue("Dyelot").ToString()!;
|
||||
inf_ = inf_ + "@" + item.GetValue("ReDye").ToString()! + "\n";
|
||||
inf_ = inf_ + "步骤:" + item.GetValue("StepNumber").ToString()! + "\n";
|
||||
inf_ = inf_ + "总浴量:" + item.GetValue("Volume").ToString()! + "\n";
|
||||
inf_ = inf_ + "计量模组:" + item.GetValue("DispenseModule").ToString()! + "\n";
|
||||
if (item!.TryGetValue("TankNo", out var _TankNo) && _TankNo != null)
|
||||
{
|
||||
inf_ = inf_ + "目标位置:" + item.GetValue("TankNo").ToString()! + "\n";
|
||||
}
|
||||
else {
|
||||
inf_ = inf_ + "目标位置:未指定\n" ;
|
||||
}
|
||||
inf_ = inf_ + "开始时间:" + DateTime.Parse(item.GetValue("DispenseStartTime").ToString() ?? "")
|
||||
.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
|
||||
if (item!.TryGetValue("State", out var _Type) && _Type != null)
|
||||
{
|
||||
string temp = _Type?.ToString() ?? "";
|
||||
// 转换
|
||||
_Type = temp switch
|
||||
{
|
||||
"102" => "计量中",
|
||||
"301" => "完成",
|
||||
"309" => "异常",
|
||||
_ => "无信息"
|
||||
};
|
||||
inf_ = inf_ + "状态:" + _Type;
|
||||
}
|
||||
|
||||
InfoMachineItem infoMachineItem = new InfoMachineItem();
|
||||
infoMachineItem.inf = inf_;
|
||||
|
||||
if (!InfoMachineItems.Any(x => x.inf == inf_))
|
||||
{
|
||||
InfoMachineItems.Add(infoMachineItem);
|
||||
}
|
||||
|
||||
}
|
||||
if (InfoMachineItems.Count==0) InfoMachineItems.Add(new InfoMachineItem());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user