终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

144 lines
4.7 KiB

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