From 63cd43dbe6dafb9b5027cf6a9a55754407e4df47 Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Fri, 2 Sep 2022 12:37:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=9F=E6=96=B0=E6=8E=A7=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../物料仓/SilosMessageModel.cs | 4 + .../NewConveyorBelt.xaml.cs | 40 +++--- BPASmartClient.SCADAControl/Silos.xaml.cs | 123 +++++++++--------- SCADA.Test/MainWindow.xaml | 5 +- SCADA.Test/MainWindow.xaml.cs | 1 + 5 files changed, 97 insertions(+), 76 deletions(-) diff --git a/BPASmartClient.MessageName/接收消息Model/物料仓/SilosMessageModel.cs b/BPASmartClient.MessageName/接收消息Model/物料仓/SilosMessageModel.cs index 574dce45..a6b45d05 100644 --- a/BPASmartClient.MessageName/接收消息Model/物料仓/SilosMessageModel.cs +++ b/BPASmartClient.MessageName/接收消息Model/物料仓/SilosMessageModel.cs @@ -23,5 +23,9 @@ namespace BPASmartClient.MessageName.接收消息Model.物料仓 /// 物料仓:重量(G) 35.23 /// public string Value { get; set; } + /// + /// 物料仓:仓号说明 + /// + public string Text { get; set; } } } diff --git a/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs b/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs index 70370f48..8b709760 100644 --- a/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs +++ b/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs @@ -60,17 +60,7 @@ namespace BPASmartClient.SCADAControl { EventReceiveNameList.CollectionChanged += EventNameList_CollectionChanged; EventSendNameList.CollectionChanged += EventSendNameList_CollectionChanged; - foreach (TextBlock tb in FindVisualChildren(this)) - { - // do something with tb here - if (tb.Tag != null) - { - if (tb.Tag.ToString() == "标题") - { - textBlock = tb; - } - } - } + } private void EventSendNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { @@ -169,6 +159,21 @@ namespace BPASmartClient.SCADAControl VisualStateManagerData(); } + if (textBlock == null) + { + foreach (TextBlock tb in FindVisualChildren(this)) + { + // do something with tb here + if (tb.Tag != null) + { + if (tb.Tag.ToString() == "标题") + { + textBlock = tb; + } + } + } + } + if (this.Height > 0 && this.Width > 0) { try @@ -362,6 +367,7 @@ namespace BPASmartClient.SCADAControl #endregion #region 属性变更事件 + List MessageNameL = null; public void Register() { if (!string.IsNullOrEmpty(EventReceiveNameListStr)) @@ -386,16 +392,16 @@ namespace BPASmartClient.SCADAControl } } - if (EventReceiveNameList != null) + List MessageNameNew = EventReceiveNameList?.Select(o => o.MeaageName.ToString())?.Distinct()?.ToList(); + if (MessageNameL == null || !MessageNameNew.SequenceEqual(MessageNameL)) { - EventReceiveNameList?.ToList().ForEach(x => - { - Class_InnerMessageBus.GetInstance().ListenMessage(this,x.MeaageName.ToString(),"EventHandler"); - }); + MessageNameL?.ForEach(o => Class_InnerMessageBus.GetInstance().RemoveMessage(o,"NewConveyorBeltEventHandler")); + MessageNameNew?.ForEach(x => Class_InnerMessageBus.GetInstance().ListenMessage(this,x,"NewConveyorBeltEventHandler")); + MessageNameL = MessageNameNew; } } - public void EventHandler(object sender, InnerMessageEventArgs e) + public void NewConveyorBeltEventHandler(object sender, InnerMessageEventArgs e) { try { diff --git a/BPASmartClient.SCADAControl/Silos.xaml.cs b/BPASmartClient.SCADAControl/Silos.xaml.cs index 9c511d99..48d68608 100644 --- a/BPASmartClient.SCADAControl/Silos.xaml.cs +++ b/BPASmartClient.SCADAControl/Silos.xaml.cs @@ -33,11 +33,11 @@ namespace BPASmartClient.SCADAControl /// Silos.xaml 的交互逻辑 /// 物料仓 /// - public partial class Silos : UserControl, IExecutable + public partial class Silos :UserControl, IExecutable { #region 临时变量 TextBlock textBlockCLKZ = null; - TextBlock textBlockValue=null; + TextBlock textBlockValue = null; TextBlock textBlockText = null; TextBlock textBlockTitle = null; @@ -54,18 +54,18 @@ namespace BPASmartClient.SCADAControl this.DataContext = this; Width = 180; Height = 270; + this.SizeChanged += Silos_SizeChanged; ; this.Loaded += Silos_Loaded; } - - private void Silos_Loaded(object sender, RoutedEventArgs e) + private void Silos_Loaded(object sender,RoutedEventArgs e) { EventReceiveNameList.CollectionChanged += EventNameList_CollectionChanged; EventSendNameList.CollectionChanged += EventSendNameList_CollectionChanged; - Loading(); + //Loading(); } - private void EventSendNameList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + private void EventSendNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (EventSendNameList.Count > 0) { @@ -79,7 +79,7 @@ namespace BPASmartClient.SCADAControl } } } - private void EventNameList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + private void EventNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (EventReceiveNameList.Count > 0) { @@ -115,7 +115,7 @@ namespace BPASmartClient.SCADAControl /// /// 加载内部变量 /// - public void Loading() + private void Silos_SizeChanged(object sender,SizeChangedEventArgs e) { //查找 if (ellipseControl == null) @@ -128,6 +128,14 @@ namespace BPASmartClient.SCADAControl if (tb.Tag.ToString() == "出料圆") { ellipseControl = tb; + storyboard.RepeatBehavior = RepeatBehavior.Forever; + DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames(); + Storyboard.SetTarget(animation,ellipseControl); + Storyboard.SetTargetProperty(animation,new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)")); + animation.KeyFrames.Add(new EasingDoubleKeyFrame(0,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)))); + animation.KeyFrames.Add(new EasingDoubleKeyFrame(180,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)))); + animation.KeyFrames.Add(new EasingDoubleKeyFrame(360,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)))); + storyboard.Children.Add(animation); } } } @@ -140,7 +148,8 @@ namespace BPASmartClient.SCADAControl if (tb.Tag.ToString() == "出料控制") { textBlockCLKZ = tb; - }else if (tb.Tag.ToString() == "Value") + } + else if (tb.Tag.ToString() == "Value") { textBlockValue = tb; } @@ -182,20 +191,11 @@ namespace BPASmartClient.SCADAControl (item as CheckBox).Unchecked += CheckBox_Unchecked; } } - //Type _typeName =EnumExtensions.CreatEnumType(tb.Children); - //typeName = _typeName.Assembly.CreateInstance(_typeName.FullName); } } } } - storyboard.RepeatBehavior = RepeatBehavior.Forever; - DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames(); - Storyboard.SetTarget(animation, ellipseControl); - Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)")); - animation.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)))); - animation.KeyFrames.Add(new EasingDoubleKeyFrame(180, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)))); - animation.KeyFrames.Add(new EasingDoubleKeyFrame(360, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)))); - storyboard.Children.Add(animation); + } public static IEnumerable FindVisualChildren(DependencyObject depObj) where T : DependencyObject @@ -204,7 +204,7 @@ namespace BPASmartClient.SCADAControl { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) { - DependencyObject child = VisualTreeHelper.GetChild(depObj, i); + DependencyObject child = VisualTreeHelper.GetChild(depObj,i); if (child != null && child is T) { yield return (T)child; @@ -224,74 +224,74 @@ namespace BPASmartClient.SCADAControl public string Value { get { return (string)GetValue(ValueProperty); } - set { SetValue(ValueProperty, value); } + set { SetValue(ValueProperty,value); } } public static readonly DependencyProperty ValueProperty = - DependencyProperty.Register("Value", typeof(string), typeof(Silos), new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); - private static void onTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as Silos)?.TargetRefresh(); - + DependencyProperty.Register("Value",typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); + private static void onTargetChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.TargetRefresh(); + [Category("值设定")] public string Text { get { return (string)GetValue(TextProperty); } - set { SetValue(TextProperty, value); } + set { SetValue(TextProperty,value); } } public static readonly DependencyProperty TextProperty = - DependencyProperty.Register("Text", typeof(string), typeof(Silos), new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); + DependencyProperty.Register("Text",typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); [Category("值设定")] public string Title { get { return (string)GetValue(TitleProperty); } - set { SetValue(TitleProperty, value); } + set { SetValue(TitleProperty,value); } } public static readonly DependencyProperty TitleProperty = - DependencyProperty.Register("Title", typeof(string), typeof(Silos), new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); + DependencyProperty.Register("Title",typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); [Category("名称[自动生成]")] public string EventReceiveNameListStr { get { return (string)GetValue(EventReceiveNameListStrProperty); } - set { SetValue(EventReceiveNameListStrProperty, value); } + set { SetValue(EventReceiveNameListStrProperty,value); } } public static readonly DependencyProperty EventReceiveNameListStrProperty = - DependencyProperty.Register("EventReceiveNameListStr", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty)); + DependencyProperty.Register("EventReceiveNameListStr",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty)); [Category("消息接收名称集合")] public ObservableCollection EventReceiveNameList { get { return (ObservableCollection)GetValue(EventReceiveNameListProperty); } - set { SetValue(EventReceiveNameListProperty, value); } + set { SetValue(EventReceiveNameListProperty,value); } } public static readonly DependencyProperty EventReceiveNameListProperty = - DependencyProperty.Register("EventReceiveNameList", typeof(ObservableCollection), typeof(Silos), new PropertyMetadata(new ObservableCollection(), new PropertyChangedCallback(onEventNameListChanged))); + DependencyProperty.Register("EventReceiveNameList",typeof(ObservableCollection),typeof(Silos),new PropertyMetadata(new ObservableCollection(),new PropertyChangedCallback(onEventNameListChanged))); [Category("名称[自动生成]")] public string EventSendNameListStr { get { return (string)GetValue(EventSendNameListStrProperty); } - set { SetValue(EventSendNameListStrProperty, value); } + set { SetValue(EventSendNameListStrProperty,value); } } public static readonly DependencyProperty EventSendNameListStrProperty = - DependencyProperty.Register("EventSendNameListStr", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty)); + DependencyProperty.Register("EventSendNameListStr",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty)); [Category("消息发送名称集合")] public ObservableCollection EventSendNameList { get { return (ObservableCollection)GetValue(EventSendNameListProperty); } - set { SetValue(EventSendNameListProperty, value); } + set { SetValue(EventSendNameListProperty,value); } } public static readonly DependencyProperty EventSendNameListProperty = - DependencyProperty.Register("EventSendNameList", typeof(ObservableCollection), typeof(Silos), new PropertyMetadata(new ObservableCollection(), new PropertyChangedCallback(onEventNameListChanged))); + DependencyProperty.Register("EventSendNameList",typeof(ObservableCollection),typeof(Silos),new PropertyMetadata(new ObservableCollection(),new PropertyChangedCallback(onEventNameListChanged))); private static void onEventNameListChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.DataNameRefresh(); [Category("值设定")] public int Direction { get { return (int)GetValue(DirectionProperty); } - set { SetValue(DirectionProperty, value); } + set { SetValue(DirectionProperty,value); } } public static readonly DependencyProperty DirectionProperty = - DependencyProperty.Register("Direction", typeof(int), typeof(Silos), - new PropertyMetadata(0, new PropertyChangedCallback(OnPropertyChanged))); - private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + DependencyProperty.Register("Direction",typeof(int),typeof(Silos), + new PropertyMetadata(0,new PropertyChangedCallback(OnPropertyChanged))); + private static void OnPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) { (d as Silos)?.Refresh(); } @@ -338,7 +338,7 @@ namespace BPASmartClient.SCADAControl storyboard.Stop(); } } - + } /// @@ -354,11 +354,12 @@ namespace BPASmartClient.SCADAControl /// public void DataNameRefresh() { - + } #endregion #region 运行事件 + List MessageNameL = null; public void Register() { if (!string.IsNullOrEmpty(EventReceiveNameListStr)) @@ -383,17 +384,21 @@ namespace BPASmartClient.SCADAControl } } - EventReceiveNameList?.ToList().ForEach(x => + List MessageNameNew = EventReceiveNameList?.Select(o => o.MeaageName.ToString())?.Distinct()?.ToList(); + if (MessageNameL==null || !MessageNameNew.SequenceEqual(MessageNameL)) { - Class_InnerMessageBus.GetInstance().ListenMessage(this,x.MeaageName.ToString(),"EventHandler"); - }); + MessageNameL?.ForEach(o => Class_InnerMessageBus.GetInstance().RemoveMessage(o,"SliosEventHandler")); + MessageNameNew?.ForEach(x => Class_InnerMessageBus.GetInstance().ListenMessage(this,x,"SliosEventHandler")); + MessageNameL = MessageNameNew; + } + } /// /// 统一事件消息处理中心 /// /// /// - public void EventHandler(object sender, InnerMessageEventArgs e) + public void SliosEventHandler(object sender,InnerMessageEventArgs e) { try { @@ -404,11 +409,12 @@ namespace BPASmartClient.SCADAControl RunEnumModel mode = (RunEnumModel)e.obj_MessageObj; var msg = EventReceiveNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID); //必对消息号: - if (msg!=null) + if (msg != null) { Direction = mode.Run == RunEnum.Run ? 1 : 2; } - }else if (e.obj_MessageObj is SilosMessageModel)//接收到数据模型 + } + else if (e.obj_MessageObj is SilosMessageModel)//接收到数据模型 { SilosMessageModel mode = (SilosMessageModel)e.obj_MessageObj; var msg = EventReceiveNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID); @@ -417,6 +423,7 @@ namespace BPASmartClient.SCADAControl { Title = mode.Title; Value = mode.Value; + Text = mode.Text; } } } @@ -434,7 +441,7 @@ namespace BPASmartClient.SCADAControl /// /// /// - private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + private void Image_MouseLeftButtonDown(object sender,MouseButtonEventArgs e) { try { @@ -446,44 +453,44 @@ namespace BPASmartClient.SCADAControl } } - + /// /// 按钮类型 /// /// /// - private void Button_Click(object sender, RoutedEventArgs e) + private void Button_Click(object sender,RoutedEventArgs e) { } - + /// /// 值改变 /// /// /// - private void TextBox_TextChanged(object sender, TextChangedEventArgs e) + private void TextBox_TextChanged(object sender,TextChangedEventArgs e) { - + } - + /// /// 选中 /// /// /// - private void CheckBox_Checked(object sender, RoutedEventArgs e) + private void CheckBox_Checked(object sender,RoutedEventArgs e) { } - + /// /// 取消选中 /// /// /// - private void CheckBox_Unchecked(object sender, RoutedEventArgs e) + private void CheckBox_Unchecked(object sender,RoutedEventArgs e) { } diff --git a/SCADA.Test/MainWindow.xaml b/SCADA.Test/MainWindow.xaml index fb3b13df..a85f89a4 100644 --- a/SCADA.Test/MainWindow.xaml +++ b/SCADA.Test/MainWindow.xaml @@ -44,7 +44,7 @@ 消息名称 - 仓号 + 消息号 1 标题 @@ -53,6 +53,9 @@ 重量 35.23 + 仓号说明 + 35.23 + diff --git a/SCADA.Test/MainWindow.xaml.cs b/SCADA.Test/MainWindow.xaml.cs index dece296e..c842406c 100644 --- a/SCADA.Test/MainWindow.xaml.cs +++ b/SCADA.Test/MainWindow.xaml.cs @@ -138,6 +138,7 @@ namespace SCADA.Test silosMessage.MessageID = ch.Text; silosMessage.Value = zl.Text; silosMessage.Title = bt.Text; + silosMessage.Text= cgs.Text; Class_InnerMessageBus.GetInstance().PostMessage(this, xxnc.Text, silosMessage); }