终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

345 rivejä
12 KiB

  1. using BPASmartClient.Compiler;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.ComponentModel;
  8. using System.Drawing.Design;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Animation;
  20. using System.Windows.Media.Imaging;
  21. using System.Windows.Navigation;
  22. using System.Windows.Shapes;
  23. using System.Windows.Threading;
  24. namespace BPASmartClient.SCADAControl.CustomerControls
  25. {
  26. /// <summary>
  27. /// Silos.xaml 的交互逻辑
  28. /// 物料仓
  29. /// </summary>
  30. public partial class Silos :UserControl, IExecutable, IDisposable
  31. {
  32. #region 临时变量
  33. TextBlock textBlockCLKZ = null;
  34. TextBlock textBlockValue = null;
  35. TextBlock textBlockText = null;
  36. TextBlock textBlockTitle = null;
  37. Ellipse ellipseControl = null;
  38. Storyboard storyboard = new Storyboard();
  39. #endregion
  40. public Silos()
  41. {
  42. InitializeComponent();
  43. Width = 180;
  44. Height = 270;
  45. this.DataContext = this;
  46. this.SizeChanged += Silos_SizeChanged; ;
  47. }
  48. public string ControlType => "物料仓";
  49. private bool isExecuteState;
  50. public bool IsExecuteState
  51. {
  52. get { return isExecuteState; }
  53. set
  54. {
  55. isExecuteState = value;
  56. if (IsExecuteState)
  57. {
  58. IsEnabled = true;
  59. Register();
  60. //Style = null;
  61. }
  62. }
  63. }
  64. #region 动画
  65. /// <summary>
  66. /// 加载内部变量
  67. /// </summary>
  68. private void Silos_SizeChanged(object sender,SizeChangedEventArgs e)
  69. {
  70. //查找
  71. if (ellipseControl == null)
  72. {
  73. foreach (Ellipse tb in FindVisualChildren<Ellipse>(this))
  74. {
  75. // do something with tb here
  76. if (tb.Tag != null)
  77. {
  78. if (tb.Tag.ToString() == "出料圆")
  79. {
  80. ellipseControl = tb;
  81. storyboard.RepeatBehavior = RepeatBehavior.Forever;
  82. DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
  83. Storyboard.SetTarget(animation,ellipseControl);
  84. Storyboard.SetTargetProperty(animation,new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"));
  85. animation.KeyFrames.Add(new EasingDoubleKeyFrame(0,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
  86. animation.KeyFrames.Add(new EasingDoubleKeyFrame(180,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));
  87. animation.KeyFrames.Add(new EasingDoubleKeyFrame(360,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))));
  88. storyboard.Children.Add(animation);
  89. }
  90. }
  91. }
  92. foreach (TextBlock tb in FindVisualChildren<TextBlock>(this))
  93. {
  94. // do something with tb here
  95. if (tb.Tag != null)
  96. {
  97. if (tb.Tag.ToString() == "出料控制")
  98. {
  99. textBlockCLKZ = tb;
  100. }
  101. else if (tb.Tag.ToString() == "Value")
  102. {
  103. textBlockValue = tb;
  104. }
  105. else if (tb.Tag.ToString() == "Text")
  106. {
  107. textBlockText = tb;
  108. }
  109. else if (tb.Tag.ToString() == "Title")
  110. {
  111. textBlockTitle = tb;
  112. }
  113. }
  114. }
  115. foreach (StackPanel tb in FindVisualChildren<StackPanel>(this))
  116. {
  117. // do something with tb here
  118. if (tb.Tag != null)
  119. {
  120. if (tb.Tag.ToString() == "ControlEvent")
  121. {
  122. foreach (var item in tb.Children)
  123. {
  124. if (item is Image)
  125. {
  126. (item as Image).MouseLeftButtonDown += Image_MouseLeftButtonDown; ;
  127. }
  128. }
  129. }
  130. }
  131. }
  132. TargetRefresh();
  133. }
  134. }
  135. public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
  136. {
  137. if (depObj != null)
  138. {
  139. for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
  140. {
  141. DependencyObject child = VisualTreeHelper.GetChild(depObj,i);
  142. if (child != null && child is T)
  143. {
  144. yield return (T)child;
  145. }
  146. foreach (T childOfChild in FindVisualChildren<T>(child))
  147. {
  148. yield return childOfChild;
  149. }
  150. }
  151. }
  152. }
  153. #endregion
  154. #region 属性
  155. [Category("值设定")]
  156. public string KgValue
  157. {
  158. get { return (string)GetValue(KgValueProperty); }
  159. set { SetValue(KgValueProperty, value); }
  160. }
  161. public static readonly DependencyProperty KgValueProperty =
  162. DependencyProperty.Register("KgValue", typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
  163. private static void onTargetChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.TargetRefresh();
  164. [Category("值设定")]
  165. public string WLText
  166. {
  167. get { return (string)GetValue(WLTextProperty); }
  168. set { SetValue(WLTextProperty, value); }
  169. }
  170. public static readonly DependencyProperty WLTextProperty =
  171. DependencyProperty.Register("WLText", typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
  172. [Category("值设定")]
  173. public string WLTitle
  174. {
  175. get { return (string)GetValue(WLTitleProperty); }
  176. set { SetValue(WLTitleProperty, value); }
  177. }
  178. public static readonly DependencyProperty WLTitleProperty =
  179. DependencyProperty.Register("WLTitle", typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
  180. [Category("值设定")]
  181. public int Direction
  182. {
  183. get { return (int)GetValue(DirectionProperty); }
  184. set { SetValue(DirectionProperty,value); }
  185. }
  186. public static readonly DependencyProperty DirectionProperty =
  187. DependencyProperty.Register("Direction",typeof(int),typeof(Silos),
  188. new PropertyMetadata(0,new PropertyChangedCallback(OnPropertyChanged)));
  189. private static void OnPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)
  190. {
  191. (d as Silos)?.Refresh();
  192. }
  193. #endregion
  194. #region 数据绑定模块
  195. public string SendText
  196. {
  197. get { return (string)GetValue(SendTextProperty); }
  198. set { SetValue(SendTextProperty, value); }
  199. }
  200. public static readonly DependencyProperty SendTextProperty =
  201. DependencyProperty.Register("SendText", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
  202. public string ChuLiaoExecute
  203. {
  204. get { return (string)GetValue(ChuLiaoExecuteProperty); }
  205. set { SetValue(ChuLiaoExecuteProperty, value); }
  206. }
  207. public static readonly DependencyProperty ChuLiaoExecuteProperty =
  208. DependencyProperty.Register("ChuLiaoExecute", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
  209. public string StopChuLiaoExecute
  210. {
  211. get { return (string)GetValue(StopChuLiaoExecuteProperty); }
  212. set { SetValue(StopChuLiaoExecuteProperty, value); }
  213. }
  214. public static readonly DependencyProperty StopChuLiaoExecuteProperty =
  215. DependencyProperty.Register("StopChuLiaoExecute", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
  216. public string ValueChangedExecute
  217. {
  218. get { return (string)GetValue(ValueChangedExecuteProperty); }
  219. set { SetValue(ValueChangedExecuteProperty, value); }
  220. }
  221. public static readonly DependencyProperty ValueChangedExecuteProperty =
  222. DependencyProperty.Register("ValueChangedExecute", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
  223. public event EventHandler PropertyChange; //声明一个事件
  224. /// <summary>
  225. /// 数据模板
  226. /// </summary>
  227. private Dictionary<string, object> DataModel
  228. {
  229. get { return (Dictionary<string, object>)GetValue(DataModelProperty); }
  230. set { SetValue(DataModelProperty, value); }
  231. }
  232. private static readonly DependencyProperty DataModelProperty =
  233. DependencyProperty.Register("DataModel", typeof(Dictionary<string, object>), typeof(Silos), new PropertyMetadata(new Dictionary<string, object>()));
  234. #endregion
  235. #region 函数
  236. /// <summary>
  237. /// 目标属性刷新
  238. /// </summary>
  239. public void TargetRefresh()
  240. {
  241. if (textBlockValue != null && textBlockText != null && textBlockTitle != null)
  242. {
  243. textBlockValue.Text = KgValue;
  244. textBlockText.Text = WLText;
  245. textBlockTitle.Text = WLTitle;
  246. }
  247. }
  248. /// <summary>
  249. /// 值变化刷新
  250. /// </summary>
  251. public void Refresh()
  252. {
  253. if (ellipseControl != null)
  254. {
  255. if (Direction == 1)
  256. {
  257. ellipseControl.Visibility = Visibility.Visible;
  258. textBlockCLKZ.Visibility = Visibility.Visible;
  259. storyboard.Begin();
  260. }
  261. else if (Direction == 2)
  262. {
  263. ellipseControl.Visibility = Visibility.Collapsed;
  264. textBlockCLKZ.Visibility = Visibility.Collapsed;
  265. storyboard.Stop();
  266. }
  267. else
  268. {
  269. ellipseControl.Visibility = Visibility.Collapsed;
  270. textBlockCLKZ.Visibility = Visibility.Collapsed;
  271. storyboard.Stop();
  272. }
  273. }
  274. }
  275. #endregion
  276. #region 运行事件
  277. List<string> MessageNameL = null;
  278. public void Register()
  279. {
  280. Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
  281. }
  282. public void BindingActionHeader(object sender, EventArgs e)
  283. {
  284. this.Dispatcher.Invoke((Action)(() =>
  285. {
  286. DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
  287. PropertyChange?.Invoke(this, EventArgs.Empty);
  288. }));
  289. }
  290. #endregion
  291. #region 发送消息事件
  292. public void Dispose()
  293. {
  294. }
  295. private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  296. {
  297. try
  298. {
  299. Image image = sender as Image;
  300. if (image.Tag != null)
  301. {
  302. if (image.Tag.ToString() == "出料")
  303. {
  304. Config.GetInstance().RunJsScipt(ChuLiaoExecute);
  305. }
  306. else if (image.Tag.ToString() == "停止出料")
  307. {
  308. Config.GetInstance().RunJsScipt(StopChuLiaoExecute);
  309. }
  310. }
  311. }
  312. catch (Exception ex)
  313. {
  314. }
  315. }
  316. #endregion
  317. }
  318. }