终端一体化运控平台
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.
 
 
 

100 lines
2.8 KiB

  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. }
  29. static TheTimer()
  30. {
  31. DefaultStyleKeyProperty.OverrideMetadata(typeof(TheTimer), new FrameworkPropertyMetadata(typeof(TheTimer)));
  32. }
  33. public string ControlType => "控件";
  34. private bool isExecuteState;
  35. public bool IsExecuteState
  36. {
  37. get { return isExecuteState; }
  38. set
  39. {
  40. isExecuteState = value;
  41. if (IsExecuteState)
  42. {
  43. Register();
  44. Style = null;
  45. }
  46. }
  47. }
  48. DispatcherTimer timer = new DispatcherTimer();
  49. public void Register()
  50. {
  51. timer.Interval = TimeSpan.FromMilliseconds(Interval);
  52. timer.Tick += Timer_Tick;
  53. timer.Start();
  54. }
  55. private void Timer_Tick(object sender, EventArgs e)
  56. {
  57. Config.GetInstance().RunJsScipt(TikcExecute);
  58. }
  59. public void Start() => timer.Start();
  60. public void Stop() => timer.Stop();
  61. public void Dispose()
  62. {
  63. timer.Stop();
  64. }
  65. /// <summary>
  66. /// 时间间隔
  67. /// </summary>
  68. public int Interval
  69. {
  70. get { return (int)GetValue(IntervalProperty); }
  71. set { SetValue(IntervalProperty, value); }
  72. }
  73. public static readonly DependencyProperty IntervalProperty =
  74. DependencyProperty.Register("Interval", typeof(int), typeof(TheTimer), new PropertyMetadata(0));
  75. /// <summary>
  76. /// 执行内容
  77. /// </summary>
  78. [Category("事件")]
  79. public string TikcExecute
  80. {
  81. get { return (string)GetValue(TikcExecuteProperty); }
  82. set { SetValue(TikcExecuteProperty, value); }
  83. }
  84. public static readonly DependencyProperty TikcExecuteProperty =
  85. DependencyProperty.Register("TikcExecute", typeof(string), typeof(TheTimer), new PropertyMetadata(string.Empty));
  86. }
  87. }