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

200 lines
6.4 KiB

  1. using BeDesignerSCADA.Common;
  2. using BeDesignerSCADA.ViewModel;
  3. using BPASmartClient.SCADAControl;
  4. using System;
  5. using System.Collections.ObjectModel;
  6. using System.Linq;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. namespace BeDesignerSCADA.View
  10. {
  11. /// <summary>
  12. /// PropertyBindingWindow.xaml 的交互逻辑
  13. /// </summary>
  14. public partial class PropertyBindingWindow : Window
  15. {
  16. public PropertyBindingWindow()
  17. {
  18. InitializeComponent();
  19. Owner = Application.Current.MainWindow;
  20. Closing += (s, e) => { e.Cancel = true; Hide(); };
  21. }
  22. public static PropertyBindingWindow Instance { get; } = new PropertyBindingWindow();
  23. /// <summary>
  24. /// 设备名称集合
  25. /// </summary>
  26. private ObservableCollection<string> _DevNameList;
  27. public ObservableCollection<string> DevNameList
  28. {
  29. get
  30. {
  31. return _DevNameList;
  32. }
  33. set
  34. {
  35. _DevNameList = value;
  36. }
  37. }
  38. /// <summary>
  39. /// 设备变量集合
  40. /// </summary>
  41. private ObservableCollection<string> _DevValueList;
  42. public ObservableCollection<string> DevValueList
  43. {
  44. get
  45. {
  46. return _DevValueList;
  47. }
  48. set
  49. {
  50. _DevValueList = value;
  51. }
  52. }
  53. public string VariablePath = string.Empty;
  54. public static string ShowEdit(DependencyProperty selectproperty, FrameworkElement control, string _VariablePath)
  55. {
  56. // 获取所有控件的可用属性
  57. var pros = PropertyHelper.GetBindString(selectproperty, control);
  58. Instance.VariablePath = _VariablePath;
  59. Instance.ProperpName.Text = selectproperty.Name;
  60. Instance.BindingName.Text = pros;
  61. Instance.ShowDialog();
  62. if (Instance.IsOk)
  63. {
  64. return Instance.BindingName.Text;
  65. }
  66. else
  67. {
  68. return pros;
  69. }
  70. }
  71. public bool IsOk { get; set; }
  72. private void CancelBtn_Click(object sender, RoutedEventArgs e)
  73. {
  74. IsOk = false;
  75. Close();
  76. }
  77. private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
  78. {
  79. IsOk = true;
  80. Close();
  81. }
  82. private void ClearBtn_Click(object sender, RoutedEventArgs e)
  83. {
  84. Instance.BindingName.Text = "";
  85. IsOk = true;
  86. Close();
  87. }
  88. /// <summary>
  89. /// 变量选择
  90. /// </summary>
  91. /// <param name="sender"></param>
  92. /// <param name="e"></param>
  93. private void ComboBoxValue_TextChanged(object sender, TextChangedEventArgs e)
  94. {
  95. try
  96. {
  97. if (sender is System.Windows.Controls.ComboBox)
  98. {
  99. System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender;
  100. if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text))
  101. {
  102. Instance.BindingName.Text = string.Format("DataModel[{0}].{1}", toggle.Tag, toggle.Text);
  103. }
  104. }
  105. }
  106. catch (Exception ex)
  107. {
  108. }
  109. }
  110. /// <summary>
  111. /// 变量下拉框打开事件
  112. /// </summary>
  113. /// <param name="sender"></param>
  114. /// <param name="e"></param>
  115. private void valuebox_DropDownOpened(object sender, EventArgs e)
  116. {
  117. try
  118. {
  119. Instance.DevValueList = new System.Collections.ObjectModel.ObservableCollection<string>();
  120. if (sender is System.Windows.Controls.ComboBox)
  121. {
  122. System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender;
  123. if (toggle.Tag == null) return;
  124. CommunicationPar communication = null;
  125. if (DataBusModel.GetInstance().KeyValues.ContainsKey(Instance.VariablePath))
  126. {
  127. communication = DataBusModel.GetInstance().KeyValues[Instance.VariablePath];
  128. }
  129. CommunicationModel mode = communication?.CommunicationDevices?.ToList().Find(par => par.DeviceName == toggle.Tag.ToString());
  130. if (mode != null)
  131. {
  132. mode?.VarTableModels?.ToList().ForEach(par => { Instance.DevValueList.Add(par.VarName); });
  133. }
  134. }
  135. valuebox.ItemsSource = Instance.DevValueList;
  136. }
  137. catch (Exception ex)
  138. {
  139. }
  140. }
  141. /// <summary>
  142. /// 设备名称选择
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void ComboBoxName_TextChanged(object sender, TextChangedEventArgs e)
  147. {
  148. try
  149. {
  150. if (sender is System.Windows.Controls.ComboBox)
  151. {
  152. System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender;
  153. if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text))
  154. {
  155. Instance.BindingName.Text = string.Format("DataModel[{0}].{1}", toggle.Text, toggle.Tag);
  156. }
  157. }
  158. }
  159. catch (Exception ex)
  160. {
  161. }
  162. }
  163. /// <summary>
  164. /// 设备名称下拉框打开事件
  165. /// </summary>
  166. /// <param name="sender"></param>
  167. /// <param name="e"></param>
  168. private void namebox_DropDownOpened(object sender, EventArgs e)
  169. {
  170. Instance.DevNameList = new System.Collections.ObjectModel.ObservableCollection<string>();
  171. CommunicationPar communication = null;
  172. if (DataBusModel.GetInstance().KeyValues.ContainsKey(Instance.VariablePath))
  173. {
  174. communication = DataBusModel.GetInstance().KeyValues[Instance.VariablePath];
  175. }
  176. communication?.CommunicationDevices?.ToList().ForEach(x => { Instance.DevNameList.Add(x.DeviceName); });
  177. namebox.ItemsSource = Instance.DevNameList;
  178. }
  179. }
  180. }