终端一体化运控平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

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