|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- using BPASmartClient.Compiler;
- using Newtonsoft.Json;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Drawing.Design;
- using System.Linq;
- using System.Reflection;
- 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;
- using System.Windows.Threading;
-
- namespace BPASmartClient.SCADAControl.CustomerControls
- {
- /// <summary>
- /// Silos.xaml 的交互逻辑
- /// 物料仓
- /// </summary>
- public partial class Silos :UserControl, IExecutable, IDisposable
- {
- #region 临时变量
- TextBlock textBlockCLKZ = null;
- TextBlock textBlockValue = null;
- TextBlock textBlockText = null;
- TextBlock textBlockTitle = null;
- Ellipse ellipseControl = null;
- Storyboard storyboard = new Storyboard();
- #endregion
-
- public Silos()
- {
- InitializeComponent();
- Width = 180;
- Height = 270;
- this.DataContext = this;
- this.SizeChanged += Silos_SizeChanged; ;
- }
-
- 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>
- 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;
- 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);
- }
- }
- }
-
- 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;
- }
- }
- }
-
- foreach (StackPanel tb in FindVisualChildren<StackPanel>(this))
- {
- // do something with tb here
- if (tb.Tag != null)
- {
- if (tb.Tag.ToString() == "ControlEvent")
- {
- foreach (var item in tb.Children)
- {
- if (item is Image)
- {
- (item as Image).MouseLeftButtonDown += Image_MouseLeftButtonDown; ;
- }
- }
-
- }
- }
- }
- TargetRefresh();
- }
- }
-
- 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 KgValue
- {
- get { return (string)GetValue(KgValueProperty); }
- set { SetValue(KgValueProperty, value); }
- }
- public static readonly DependencyProperty KgValueProperty =
- DependencyProperty.Register("KgValue", typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
- private static void onTargetChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.TargetRefresh();
-
- [Category("值设定")]
- public string WLText
- {
- get { return (string)GetValue(WLTextProperty); }
- set { SetValue(WLTextProperty, value); }
- }
- public static readonly DependencyProperty WLTextProperty =
- DependencyProperty.Register("WLText", typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
-
- [Category("值设定")]
- public string WLTitle
- {
- get { return (string)GetValue(WLTitleProperty); }
- set { SetValue(WLTitleProperty, value); }
- }
- public static readonly DependencyProperty WLTitleProperty =
- DependencyProperty.Register("WLTitle", typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
-
- [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 数据绑定模块
- public string SendText
- {
- get { return (string)GetValue(SendTextProperty); }
- set { SetValue(SendTextProperty, value); }
- }
- public static readonly DependencyProperty SendTextProperty =
- DependencyProperty.Register("SendText", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
- public string ChuLiaoExecute
- {
- get { return (string)GetValue(ChuLiaoExecuteProperty); }
- set { SetValue(ChuLiaoExecuteProperty, value); }
- }
- public static readonly DependencyProperty ChuLiaoExecuteProperty =
- DependencyProperty.Register("ChuLiaoExecute", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
- public string StopChuLiaoExecute
- {
- get { return (string)GetValue(StopChuLiaoExecuteProperty); }
- set { SetValue(StopChuLiaoExecuteProperty, value); }
- }
- public static readonly DependencyProperty StopChuLiaoExecuteProperty =
- DependencyProperty.Register("StopChuLiaoExecute", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
- public string ValueChangedExecute
- {
- get { return (string)GetValue(ValueChangedExecuteProperty); }
- set { SetValue(ValueChangedExecuteProperty, value); }
- }
- public static readonly DependencyProperty ValueChangedExecuteProperty =
- DependencyProperty.Register("ValueChangedExecute", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
- public event EventHandler PropertyChange; //声明一个事件
- /// <summary>
- /// 数据模板
- /// </summary>
- private Dictionary<string, object> DataModel
- {
- get { return (Dictionary<string, object>)GetValue(DataModelProperty); }
- set { SetValue(DataModelProperty, value); }
- }
- private static readonly DependencyProperty DataModelProperty =
- DependencyProperty.Register("DataModel", typeof(Dictionary<string, object>), typeof(Silos), new PropertyMetadata(new Dictionary<string, object>()));
- #endregion
-
- #region 函数
- /// <summary>
- /// 目标属性刷新
- /// </summary>
- public void TargetRefresh()
- {
- if (textBlockValue != null && textBlockText != null && textBlockTitle != null)
- {
- textBlockValue.Text = KgValue;
- textBlockText.Text = WLText;
- textBlockTitle.Text = WLTitle;
- }
- }
-
- /// <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();
- }
- }
-
- }
- #endregion
-
- #region 运行事件
- List<string> MessageNameL = null;
- public void Register()
- {
- Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
- }
-
- public void BindingActionHeader(object sender, EventArgs e)
- {
- this.Dispatcher.Invoke((Action)(() =>
- {
- DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
- PropertyChange?.Invoke(this, EventArgs.Empty);
- }));
- }
- #endregion
-
- #region 发送消息事件
- public void Dispose()
- {
-
- }
-
- private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- try
- {
- Image image = sender as Image;
- if (image.Tag != null)
- {
- if (image.Tag.ToString() == "出料")
- {
- Config.GetInstance().RunJsScipt(ChuLiaoExecute);
- }
- else if (image.Tag.ToString() == "停止出料")
- {
- Config.GetInstance().RunJsScipt(StopChuLiaoExecute);
- }
- }
- }
- catch (Exception ex)
- {
-
- }
- }
- #endregion
-
-
-
- }
- }
|