From 56c23626fac526326770289f34031e5ec82fefa2 Mon Sep 17 00:00:00 2001 From: taoye Date: Sat, 17 Sep 2022 16:45:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/HardwareStatusView.xaml | 20 ++++----- .../View/HardwareStatusView.xaml.cs | 24 ++++++----- .../ViewModel/HardwareStatusViewModel.cs | 41 +++++++++++++++++++ 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/BPASmartClient.JXJFoodBigStation/View/HardwareStatusView.xaml b/BPASmartClient.JXJFoodBigStation/View/HardwareStatusView.xaml index c48331ce..a4beb585 100644 --- a/BPASmartClient.JXJFoodBigStation/View/HardwareStatusView.xaml +++ b/BPASmartClient.JXJFoodBigStation/View/HardwareStatusView.xaml @@ -44,10 +44,10 @@ - + @@ -463,9 +463,9 @@ Background="#112AB2E7" BorderThickness="0" Command="{Binding DataContext.StartCommand, RelativeSource={RelativeSource AncestorType=ListBox, Mode=FindAncestor}}" - CommandParameter="{Binding RecipeCode}" + CommandParameter="{Binding DeviceName}" Tag="{Binding DeviceName}" - Click="IcoButton_Click" + Content="启动" EnterBackground="#222AB2E7" Foreground="#FF2AB2E7" @@ -481,9 +481,9 @@ Background="#11F53F62" BorderThickness="0" Command="{Binding DataContext.StopCommand, RelativeSource={RelativeSource AncestorType=ListBox, Mode=FindAncestor}}" - CommandParameter="{Binding RecipeCode}" + CommandParameter="{Binding DeviceName}" Tag="{Binding DeviceName}" - Click="IcoButton_Click_1" + Content="停止" EnterBackground="#22F53F62" Foreground="#FFF53F62" @@ -613,9 +613,9 @@ Background="#112AB2E7" BorderThickness="0" Command="{Binding DataContext.StartCommand, RelativeSource={RelativeSource AncestorType=ListBox, Mode=FindAncestor}}" - CommandParameter="{Binding RecipeCode}" + CommandParameter="{Binding DeviceName}" Tag="{Binding DeviceName}" - Click="IcoButton_Click_2" + Content="启动" EnterBackground="#222AB2E7" Foreground="#FF2AB2E7" @@ -631,9 +631,9 @@ Background="#11F53F62" BorderThickness="0" Command="{Binding DataContext.StopCommand, RelativeSource={RelativeSource AncestorType=ListBox, Mode=FindAncestor}}" - CommandParameter="{Binding RecipeCode}" + CommandParameter="{Binding DeviceName}" Tag="{Binding DeviceName}" - Click="IcoButton_Click_3" + Content="停止" EnterBackground="#22F53F62" Foreground="#FFF53F62" diff --git a/BPASmartClient.JXJFoodBigStation/View/HardwareStatusView.xaml.cs b/BPASmartClient.JXJFoodBigStation/View/HardwareStatusView.xaml.cs index 622119e7..5a54f04f 100644 --- a/BPASmartClient.JXJFoodBigStation/View/HardwareStatusView.xaml.cs +++ b/BPASmartClient.JXJFoodBigStation/View/HardwareStatusView.xaml.cs @@ -28,7 +28,11 @@ namespace BPASmartClient.JXJFoodBigStation.View { InitializeComponent(); storyboard = Resources["Open"] as Storyboard; - ActionManage.GetInstance.Register(new Action((deviceName) => { + ActionManage.GetInstance.CancelRegister("StartTopDevice"); + ActionManage.GetInstance.CancelRegister("StopTopDevice"); + ActionManage.GetInstance.CancelRegister("StartBottomDevice"); + ActionManage.GetInstance.CancelRegister("StopBottomDevice"); + ActionManage.GetInstance.Register(new Action((deviceName) => { foreach (var item in this.FListView.Items) { var myListBoxItem = (ListViewItem)FListView.ItemContainerGenerator.ContainerFromItem(item); @@ -43,7 +47,7 @@ namespace BPASmartClient.JXJFoodBigStation.View Path pt = obj as Path; if (pt != null) { - if (pt.Tag.ToString() == deviceName && storyboard != null) + if (pt.Tag.ToString() == deviceName.ToString()&& storyboard != null) { pt.Visibility = Visibility.Visible; pt.BeginStoryboard(storyboard); @@ -54,7 +58,7 @@ namespace BPASmartClient.JXJFoodBigStation.View }),"StartTopDevice" ); - ActionManage.GetInstance.Register(new Action((deviceName) => { + ActionManage.GetInstance.Register(new Action((deviceName) => { foreach (var item in this.FListView.Items) { var myListBoxItem = (ListViewItem)FListView.ItemContainerGenerator.ContainerFromItem(item); @@ -69,7 +73,7 @@ namespace BPASmartClient.JXJFoodBigStation.View Path pt = obj as Path; if (pt != null) { - if (pt.Tag.ToString() == deviceName) + if (pt.Tag.ToString() == deviceName.ToString()) pt.Visibility = Visibility.Collapsed; } @@ -77,7 +81,7 @@ namespace BPASmartClient.JXJFoodBigStation.View }), "StopTopDevice"); - ActionManage.GetInstance.Register(new Action((deviceName) => { + ActionManage.GetInstance.Register(new Action((deviceName) => { foreach (var item in this.buttonListView.Items) { var myListBoxItem = (ListViewItem)buttonListView.ItemContainerGenerator.ContainerFromItem(item); @@ -92,7 +96,7 @@ namespace BPASmartClient.JXJFoodBigStation.View Path pt = obj as Path; if (pt != null) { - if (pt.Tag.ToString() == deviceName && storyboard != null) + if (pt.Tag.ToString() == deviceName.ToString() && storyboard != null) { pt.Visibility = Visibility.Visible; pt.BeginStoryboard(storyboard); @@ -101,9 +105,9 @@ namespace BPASmartClient.JXJFoodBigStation.View } } - }), "StartBottonDevice"); + }), "StartBottomDevice"); - ActionManage.GetInstance.Register(new Action((deviceName) => { + ActionManage.GetInstance.Register(new Action((deviceName) => { foreach (var item in this.buttonListView.Items) { var myListBoxItem = (ListViewItem)buttonListView.ItemContainerGenerator.ContainerFromItem(item); @@ -118,13 +122,13 @@ namespace BPASmartClient.JXJFoodBigStation.View Path pt = obj as Path; if (pt != null) { - if (pt.Tag.ToString() == deviceName) + if (pt.Tag.ToString() == deviceName.ToString()) pt.Visibility = Visibility.Collapsed; } } - }), "StopBottonDevice"); + }), "StopBottomDevice"); } //顶部启动下料动画 diff --git a/BPASmartClient.JXJFoodBigStation/ViewModel/HardwareStatusViewModel.cs b/BPASmartClient.JXJFoodBigStation/ViewModel/HardwareStatusViewModel.cs index a881d3bd..68319389 100644 --- a/BPASmartClient.JXJFoodBigStation/ViewModel/HardwareStatusViewModel.cs +++ b/BPASmartClient.JXJFoodBigStation/ViewModel/HardwareStatusViewModel.cs @@ -37,9 +37,50 @@ namespace BPASmartClient.JXJFoodBigStation.ViewModel Weight = new Random().Next(0, 100) }); } + + StartCommand = new RelayCommand((deviceName) => { + //PLC控制 + + //动画 + if (deviceName != null) + { + var top= TopDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == deviceName); + if (top != null) + { + ActionManage.GetInstance.Send("StartTopDevice", deviceName); + } + var bottom = BottomDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == deviceName); + if (bottom != null) + { + ActionManage.GetInstance.Send("StartBottomDevice", deviceName); + } + } + }); + StopCommand = new RelayCommand((deviceName) => { + //PLC控制 + + //动画 + if (deviceName != null) + { + var top = TopDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == deviceName); + if (top != null) + { + ActionManage.GetInstance.Send("StopTopDevice", deviceName); + } + var bottom = BottomDeviceCurrentStatuses.FirstOrDefault(p => p.DeviceName == deviceName); + if (bottom != null) + { + ActionManage.GetInstance.Send("StopBottomDevice", deviceName); + } + } + }); } public ObservableCollection TopDeviceCurrentStatuses { get; set; } = new ObservableCollection(); public ObservableCollection BottomDeviceCurrentStatuses { get; set; } = new ObservableCollection(); + + public RelayCommand StartCommand { get; set; } + + public RelayCommand StopCommand { get; set; } } }