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

209 lines
6.6 KiB

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