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

144 line
4.7 KiB

  1. using BPASmartClient.Compiler;
  2. using BPASmartClient.DATABUS;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Diagnostics;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Navigation;
  20. using System.Windows.Shapes;
  21. using System.Windows.Threading;
  22. namespace BPASmartClient.SCADAControl.CustomerControls
  23. {
  24. /// <summary>
  25. /// 常用button
  26. /// TheButton.xaml 的交互逻辑
  27. /// </summary>
  28. public partial class TheButton : Button, IExecutable
  29. {
  30. public TheButton()
  31. {
  32. InitializeComponent();
  33. ResourceDictionary languageResDic = new ResourceDictionary();
  34. languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
  35. this.Resources.MergedDictionaries.Add(languageResDic);
  36. this.Loaded += TheButton_Loaded;
  37. }
  38. private void TheButton_Loaded(object sender, RoutedEventArgs e)
  39. {
  40. if (this.ActualWidth <= 20)
  41. {
  42. Content = "按钮";
  43. Width = 80;
  44. Height = 30;
  45. }
  46. }
  47. public string ControlType => "控件";
  48. private bool isExecuteState;
  49. public bool IsExecuteState
  50. {
  51. get { return isExecuteState; }
  52. set
  53. {
  54. isExecuteState = value;
  55. if (IsExecuteState)
  56. {
  57. Register();
  58. }
  59. }
  60. }
  61. [Category("事件")]
  62. public string ClickExec
  63. {
  64. get { return (string)GetValue(ClickExecProperty); }
  65. set { SetValue(ClickExecProperty, value); }
  66. }
  67. public static readonly DependencyProperty ClickExecProperty =
  68. DependencyProperty.Register("ClickExec", typeof(string), typeof(TheButton), new PropertyMetadata(string.Empty));
  69. private void MyButton_Click(object sender, RoutedEventArgs e)
  70. {
  71. Config.GetInstance().RunJsScipt(ClickExec);
  72. try
  73. {
  74. if (!string.IsNullOrEmpty(StartPath) && StartPath.Contains(".exe"))
  75. {
  76. string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}{StartPath}";
  77. if (File.Exists(path))
  78. {
  79. ProcessStartInfo info = new ProcessStartInfo();
  80. info.FileName = path;
  81. info.Arguments = "";
  82. //info.WindowStyle = ProcessWindowStyle.Minimized;
  83. Process pro = Process.Start(info);
  84. pro.WaitForExit();
  85. }
  86. }
  87. }
  88. catch (Exception ex)
  89. {
  90. }
  91. }
  92. #region 数据绑定模块
  93. public event EventHandler PropertyChange; //声明一个事件
  94. /// <summary>
  95. /// 数据模板
  96. /// </summary>
  97. private Dictionary<string, object> DataModel
  98. {
  99. get { return (Dictionary<string, object>)GetValue(DataModelProperty); }
  100. set { SetValue(DataModelProperty, value); }
  101. }
  102. private static readonly DependencyProperty DataModelProperty =
  103. DependencyProperty.Register("DataModel", typeof(Dictionary<string, object>), typeof(TheButton), new PropertyMetadata(new Dictionary<string, object>()));
  104. /// <summary>
  105. /// 启动路径
  106. /// </summary>
  107. public string StartPath
  108. {
  109. get { return (string)GetValue(StartPathProperty); }
  110. set { SetValue(StartPathProperty, value); }
  111. }
  112. public static readonly DependencyProperty StartPathProperty =
  113. DependencyProperty.Register("StartPath", typeof(string), typeof(TheButton), new PropertyMetadata(string.Empty));
  114. /// <summary>
  115. /// 运行事件
  116. /// </summary>
  117. public void Register()
  118. {
  119. Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
  120. this.Click += MyButton_Click;
  121. }
  122. public void BindingActionHeader(object sender, EventArgs e)
  123. {
  124. this.Dispatcher.Invoke((Action)(() =>
  125. {
  126. DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
  127. PropertyChange?.Invoke(this, EventArgs.Empty);
  128. }));
  129. }
  130. #endregion
  131. }
  132. }