using BPASmartClient.Compiler;
using BPASmartClient.DATABUS;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace BPASmartClient.SCADAControl.CustomerControls
{
///
/// 常用button
/// TheButton.xaml 的交互逻辑
///
public partial class TheButton : Button, IExecutable
{
public TheButton()
{
InitializeComponent();
ResourceDictionary languageResDic = new ResourceDictionary();
languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
this.Resources.MergedDictionaries.Add(languageResDic);
this.Loaded += TheButton_Loaded;
}
private void TheButton_Loaded(object sender, RoutedEventArgs e)
{
if (this.ActualWidth <= 20)
{
Content = "按钮";
Width = 80;
Height = 30;
}
}
public string ControlType => "控件";
private bool isExecuteState;
public bool IsExecuteState
{
get { return isExecuteState; }
set
{
isExecuteState = value;
if (IsExecuteState)
{
Register();
}
}
}
[Category("事件")]
public string ClickExec
{
get { return (string)GetValue(ClickExecProperty); }
set { SetValue(ClickExecProperty, value); }
}
public static readonly DependencyProperty ClickExecProperty =
DependencyProperty.Register("ClickExec", typeof(string), typeof(TheButton), new PropertyMetadata(string.Empty));
private void MyButton_Click(object sender, RoutedEventArgs e)
{
Config.GetInstance().RunJsScipt(ClickExec);
try
{
if (!string.IsNullOrEmpty(StartPath) && StartPath.Contains(".exe"))
{
string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}{StartPath}";
if (File.Exists(path))
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = path;
info.Arguments = "";
//info.WindowStyle = ProcessWindowStyle.Minimized;
Process pro = Process.Start(info);
pro.WaitForExit();
}
}
}
catch (Exception ex)
{
}
}
#region 数据绑定模块
public event EventHandler PropertyChange; //声明一个事件
///
/// 数据模板
///
private Dictionary DataModel
{
get { return (Dictionary)GetValue(DataModelProperty); }
set { SetValue(DataModelProperty, value); }
}
private static readonly DependencyProperty DataModelProperty =
DependencyProperty.Register("DataModel", typeof(Dictionary), typeof(TheButton), new PropertyMetadata(new Dictionary()));
///
/// 启动路径
///
public string StartPath
{
get { return (string)GetValue(StartPathProperty); }
set { SetValue(StartPathProperty, value); }
}
public static readonly DependencyProperty StartPathProperty =
DependencyProperty.Register("StartPath", typeof(string), typeof(TheButton), new PropertyMetadata(string.Empty));
///
/// 运行事件
///
public void Register()
{
Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
this.Click += MyButton_Click;
}
public void BindingActionHeader(object sender, EventArgs e)
{
this.Dispatcher.Invoke((Action)(() =>
{
DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
PropertyChange?.Invoke(this, EventArgs.Empty);
}));
}
#endregion
}
}