终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TheTimer.cs 3.0 KiB

2 年前
2 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using BPASmartClient.Compiler;
  2. using BPASmartClient.SCADAControl;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. using System.Windows.Threading;
  19. namespace BPASmartClient.SCADAControl.CustomerControls
  20. {
  21. public class TheTimer : Control, IExecutable, IDisposable
  22. {
  23. public event EventHandler PropertyChange; //声明一个事件
  24. public TheTimer()
  25. {
  26. Width = 40;
  27. Height = 40;
  28. ResourceDictionary languageResDic = new ResourceDictionary();
  29. languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml", UriKind.RelativeOrAbsolute);
  30. this.Resources.MergedDictionaries.Add(languageResDic);
  31. }
  32. static TheTimer()
  33. {
  34. DefaultStyleKeyProperty.OverrideMetadata(typeof(TheTimer), new FrameworkPropertyMetadata(typeof(TheTimer)));
  35. }
  36. public string ControlType => "控件";
  37. private bool isExecuteState;
  38. public bool IsExecuteState
  39. {
  40. get { return isExecuteState; }
  41. set
  42. {
  43. isExecuteState = value;
  44. if (IsExecuteState)
  45. {
  46. Register();
  47. //Style = null;
  48. }
  49. }
  50. }
  51. DispatcherTimer timer = new DispatcherTimer();
  52. public void Register()
  53. {
  54. timer.Interval = TimeSpan.FromMilliseconds(Interval);
  55. timer.Tick += Timer_Tick;
  56. timer.Start();
  57. }
  58. private void Timer_Tick(object sender, EventArgs e)
  59. {
  60. Config.GetInstance().RunJsScipt(TikcExecute);
  61. }
  62. public void Start() => timer.Start();
  63. public void Stop() => timer.Stop();
  64. public void Dispose()
  65. {
  66. timer.Stop();
  67. }
  68. /// <summary>
  69. /// 时间间隔
  70. /// </summary>
  71. public int Interval
  72. {
  73. get { return (int)GetValue(IntervalProperty); }
  74. set { SetValue(IntervalProperty, value); }
  75. }
  76. public static readonly DependencyProperty IntervalProperty =
  77. DependencyProperty.Register("Interval", typeof(int), typeof(TheTimer), new PropertyMetadata(0));
  78. /// <summary>
  79. /// 执行内容
  80. /// </summary>
  81. [Category("事件")]
  82. public string TikcExecute
  83. {
  84. get { return (string)GetValue(TikcExecuteProperty); }
  85. set { SetValue(TikcExecuteProperty, value); }
  86. }
  87. public static readonly DependencyProperty TikcExecuteProperty =
  88. DependencyProperty.Register("TikcExecute", typeof(string), typeof(TheTimer), new PropertyMetadata(string.Empty));
  89. }
  90. }