|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- using BPASmartClient.Compiler;
- using BPASmartClient.MessageCommunication;
- using BPASmartClient.MessageCommunication.MsgControl;
- using BPASmartClient.MessageName;
- using BPASmartClient.MessageName.Enum.运行状态;
- using BPASmartClient.MessageName.接收消息Model;
- using BPASmartClient.MessageName.接收消息Model.物料仓;
- using Newtonsoft.Json;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
-
- namespace BPASmartClient.SCADAControl
- {
- /// <summary>
- /// Silos.xaml 的交互逻辑
- /// 物料仓
- /// </summary>
- public partial class Silos : UserControl, IExecutable
- {
- #region 临时变量
- TextBlock textBlockCLKZ = null;
- TextBlock textBlockValue=null;
- TextBlock textBlockText = null;
- TextBlock textBlockTitle = null;
-
-
- Ellipse ellipseControl = null;
- Storyboard storyboard = new Storyboard();
- #endregion
-
- public Silos()
- {
- InitializeComponent();
- this.DataContext = this;
- Width = 180;
- Height = 270;
- this.Loaded += Silos_Loaded;
- }
-
- private void Silos_Loaded(object sender, RoutedEventArgs e)
- {
- Silos_SizeChanged(null, null);
- EventNameList.CollectionChanged += EventNameList_CollectionChanged;
- }
-
- private void EventNameList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
- {
- if (EventNameList.Count > 0)
- {
- try
- {
- EventNameListStr = JsonConvert.SerializeObject(EventNameList);
-
- }
- catch (Exception ex)
- {
- }
- }
- }
-
- public string ControlType => "物料仓";
- private bool isExecuteState;
- public bool IsExecuteState
- {
- get { return isExecuteState; }
- set
- {
- isExecuteState = value;
- if (IsExecuteState)
- {
- IsEnabled = true;
- Register();
- Style = null;
- }
- }
- }
-
- #region 动画
- /// <summary>
- /// 字节改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Silos_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- //查找
- if (ellipseControl == null)
- {
- foreach (Ellipse tb in FindVisualChildren<Ellipse>(this))
- {
- // do something with tb here
- if (tb.Tag != null)
- {
- if (tb.Tag.ToString() == "出料圆")
- {
- ellipseControl = tb;
- }
- }
- }
-
- foreach (TextBlock tb in FindVisualChildren<TextBlock>(this))
- {
- // do something with tb here
- if (tb.Tag != null)
- {
- if (tb.Tag.ToString() == "出料控制")
- {
- textBlockCLKZ = tb;
- }else if (tb.Tag.ToString() == "Value")
- {
- textBlockValue = tb;
- }
- else if (tb.Tag.ToString() == "Text")
- {
- textBlockText = tb;
- }
- else if (tb.Tag.ToString() == "Title")
- {
- textBlockTitle = 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);
- }
- public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
- {
- if (depObj != null)
- {
- for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
- {
- DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
- if (child != null && child is T)
- {
- yield return (T)child;
- }
-
- foreach (T childOfChild in FindVisualChildren<T>(child))
- {
- yield return childOfChild;
- }
- }
- }
- }
- #endregion
-
- #region 属性
- [Category("值设定")]
- public string Value
- {
- get { return (string)GetValue(ValueProperty); }
- 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();
-
- [Category("值设定")]
- public string Text
- {
- get { return (string)GetValue(TextProperty); }
- set { SetValue(TextProperty, value); }
- }
- public static readonly DependencyProperty TextProperty =
- 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); }
- }
- public static readonly DependencyProperty TitleProperty =
- DependencyProperty.Register("Title", typeof(string), typeof(Silos), new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
-
- [Category("消息名称")]
- public string EventNameListStr
- {
- get { return (string)GetValue(EventNameListStrProperty); }
- set { SetValue(EventNameListStrProperty, value); }
- }
- public static readonly DependencyProperty EventNameListStrProperty =
- DependencyProperty.Register("EventNameListStr", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
-
- [Category("消息名称集合")]
- public ObservableCollection<EventReceiveMessage> EventNameList
- {
- get { return (ObservableCollection<EventReceiveMessage>)GetValue(EventNameListProperty); }
- set { SetValue(EventNameListProperty, value); }
- }
- public static readonly DependencyProperty EventNameListProperty =
- DependencyProperty.Register("EventNameList", typeof(ObservableCollection<EventReceiveMessage>), typeof(Silos), new PropertyMetadata(new ObservableCollection<EventReceiveMessage>(), 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); }
- }
- 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)
- {
- (d as Silos)?.Refresh();
- }
- #endregion
-
- #region 函数
- /// <summary>
- /// 目标属性刷新
- /// </summary>
- public void TargetRefresh()
- {
- if (textBlockValue != null && textBlockText != null && textBlockTitle != null)
- {
- textBlockValue.Text = Value;
- textBlockText.Text = Text;
- textBlockTitle.Text = Title;
- }
- }
-
-
- /// <summary>
- /// 值变化刷新
- /// </summary>
- public void Refresh()
- {
- if (ellipseControl != null)
- {
- if (Direction == 1)
- {
- ellipseControl.Visibility = Visibility.Visible;
- textBlockCLKZ.Visibility = Visibility.Visible;
- storyboard.Begin();
- }
- else if (Direction == 2)
- {
- ellipseControl.Visibility = Visibility.Collapsed;
- textBlockCLKZ.Visibility = Visibility.Collapsed;
- storyboard.Stop();
- }
- else
- {
- ellipseControl.Visibility = Visibility.Collapsed;
- textBlockCLKZ.Visibility = Visibility.Collapsed;
- storyboard.Stop();
- }
- }
-
- }
-
- /// <summary>
- /// 运行名称变化事件
- /// </summary>
- public void RunNameRefresh()
- {
-
- }
-
- /// <summary>
- /// 数据名称变化事件
- /// </summary>
- public void DataNameRefresh()
- {
-
- }
- #endregion
-
- #region 运行事件
- public void Register()
- {
- if (!string.IsNullOrEmpty(EventNameListStr))
- {
- try
- {
- EventNameList = JsonConvert.DeserializeObject<ObservableCollection<EventReceiveMessage>>(EventNameListStr);
- }
- catch (Exception ex)
- {
-
- }
- }
- if (EventNameList != null)
- {
- EventNameList?.ToList().ForEach(x =>
- {
- Class_InnerMessageBus.GetInstance().ListenMessage(this, x.Name.ToString(), "EventHandler");
- });
- }
- }
- /// <summary>
- /// 统一事件消息处理中心
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void EventHandler(object sender, InnerMessageEventArgs e)
- {
- try
- {
- if (IsExecuteState = true)//正在运行
- {
- if (e.obj_MessageObj is RunEnumModel)//接收到运行消息
- {
- RunEnumModel mode = (RunEnumModel)e.obj_MessageObj;
- var msg = EventNameList?.ToList().Find(par => par.Name.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID);
- //必对消息号:
- if (msg!=null)
- {
- Direction = mode.Run == RunEnum.Run ? 1 : 2;
- }
- }else if (e.obj_MessageObj is SilosMessageModel)//接收到数据模型
- {
- SilosMessageModel mode = (SilosMessageModel)e.obj_MessageObj;
- var msg = EventNameList?.ToList().Find(par => par.Name.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID);
- //必对消息号:
- if (msg != null)
- {
- Title = mode.Title;
- Value = mode.Value;
- }
- }
- }
- }
- catch (Exception ex)
- {
-
- }
- }
- #endregion
-
- }
-
- }
|