|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- using BeDesignerSCADA.Common;
- using BeDesignerSCADA.ViewModel;
- using BPASmart.Model;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- 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.Shapes;
-
- namespace BeDesignerSCADA.View
- {
- /// <summary>
- /// PropertyBindingWindow.xaml 的交互逻辑
- /// </summary>
- public partial class PropertyBindingWindow : Window
- {
- public PropertyBindingWindow()
- {
- InitializeComponent();
- Owner = Application.Current.MainWindow;
- Closing += (s, e) => { e.Cancel = true; Hide(); };
- }
-
- public static PropertyBindingWindow Instance { get; } = new PropertyBindingWindow();
-
- /// <summary>
- /// 设备名称集合
- /// </summary>
- private ObservableCollection<string> _DevNameList;
- public ObservableCollection<string> DevNameList
- {
- get
- {
- return _DevNameList;
- }
- set
- {
- _DevNameList = value;
- }
- }
-
- /// <summary>
- /// 设备变量集合
- /// </summary>
- private ObservableCollection<string> _DevValueList;
- public ObservableCollection<string> DevValueList
- {
- get
- {
- return _DevValueList;
- }
- set
- {
- _DevValueList = value;
- }
- }
-
- public string VariablePath = string.Empty;
-
- public static string ShowEdit(DependencyProperty selectproperty, FrameworkElement control, string _VariablePath)
- {
- // 获取所有控件的可用属性
- var pros = PropertyHelper.GetBindString(selectproperty, control);
- Instance.VariablePath = _VariablePath;
- Instance.ProperpName.Text = selectproperty.Name;
- Instance.BindingName.Text = pros;
- Instance.ShowDialog();
-
- if (Instance.IsOk)
- {
- return Instance.BindingName.Text;
- }
- else
- {
- return pros;
- }
- }
-
- public bool IsOk { get; set; }
- private void CancelBtn_Click(object sender, RoutedEventArgs e)
- {
- IsOk = false;
- Close();
- }
-
- private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
- {
- IsOk = true;
- Close();
- }
-
- private void ClearBtn_Click(object sender, RoutedEventArgs e)
- {
- Instance.BindingName.Text = "";
- IsOk = true;
- Close();
- }
-
- /// <summary>
- /// 变量选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ComboBoxValue_TextChanged(object sender, TextChangedEventArgs e)
- {
- try
- {
-
- if (sender is System.Windows.Controls.ComboBox)
- {
- System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender;
- if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text))
- {
- Instance.BindingName.Text = string.Format("DataModel[{0}].{1}", toggle.Tag, toggle.Text);
- }
- }
- }
- catch (Exception ex)
- {
-
- }
- }
- /// <summary>
- /// 变量下拉框打开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void valuebox_DropDownOpened(object sender, EventArgs e)
- {
- try
- {
- Instance.DevValueList = new System.Collections.ObjectModel.ObservableCollection<string>();
- if (sender is System.Windows.Controls.ComboBox)
- {
- System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender;
- if (toggle.Tag == null) return;
-
- CommunicationPar communication = null;
- if (DataBusModel.GetInstance().KeyValues.ContainsKey(Instance.VariablePath))
- {
- communication = DataBusModel.GetInstance().KeyValues[Instance.VariablePath];
- }
- CommunicationModel mode = communication?.CommunicationDevices?.ToList().Find(par => par.DeviceName == toggle.Tag.ToString());
- if (mode != null)
- {
- mode?.VarTableModels?.ToList().ForEach(par => { Instance.DevValueList.Add(par.VarName); });
- }
- }
- valuebox.ItemsSource = Instance.DevValueList;
-
- }
- catch (Exception ex)
- {
-
- }
-
- }
- /// <summary>
- /// 设备名称选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ComboBoxName_TextChanged(object sender, TextChangedEventArgs e)
- {
- try
- {
- if (sender is System.Windows.Controls.ComboBox)
- {
- System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender;
- if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text))
- {
- Instance.BindingName.Text = string.Format("DataModel[{0}].{1}", toggle.Text, toggle.Tag);
- }
- }
- }
- catch (Exception ex)
- {
-
- }
- }
- /// <summary>
- /// 设备名称下拉框打开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void namebox_DropDownOpened(object sender, EventArgs e)
- {
-
- Instance.DevNameList = new System.Collections.ObjectModel.ObservableCollection<string>();
- CommunicationPar communication = null;
- if (DataBusModel.GetInstance().KeyValues.ContainsKey(Instance.VariablePath))
- {
- communication = DataBusModel.GetInstance().KeyValues[Instance.VariablePath];
- }
- communication?.CommunicationDevices?.ToList().ForEach(x => { Instance.DevNameList.Add(x.DeviceName); });
- namebox.ItemsSource = Instance.DevNameList;
- }
- }
- }
|