pry 2 år sedan
förälder
incheckning
c9359a25c0
5 ändrade filer med 181 tillägg och 8 borttagningar
  1. +26
    -1
      BPASmartClient.SCADAControl/CustomerControls/TheTextBlock.cs
  2. +0
    -3
      BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs
  3. +16
    -2
      BeDesignerSCADA/View/PropertyBindingWindow.xaml
  4. +138
    -1
      BeDesignerSCADA/View/PropertyBindingWindow.xaml.cs
  5. +1
    -1
      BeDesignerSCADA/ViewModel/MainViewModelNew.cs

+ 26
- 1
BPASmartClient.SCADAControl/CustomerControls/TheTextBlock.cs Visa fil

@@ -1,6 +1,7 @@
using BPASmartClient.Compiler;
using BPASmartClient.DATABUS;
using BPASmartClient.SCADAControl;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -72,6 +73,17 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
public static readonly DependencyProperty TimeCountProperty =
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheTextBlock),new PropertyMetadata(50));
/// <summary>
/// 数据模板
/// </summary>
private Dictionary<string, object> DataModel
{
get { return (Dictionary<string, object>)GetValue(DataModelProperty); }
set { SetValue(DataModelProperty, value); }
}
private static readonly DependencyProperty DataModelProperty =
DependencyProperty.Register("DataModel", typeof(Dictionary<string, object>), typeof(TheTextBlock), new PropertyMetadata(new Dictionary<string, object>()));

public event EventHandler PropertyChange; //声明一个事件
/// <summary>
/// 属性刷新器
@@ -86,6 +98,16 @@ namespace BPASmartClient.SCADAControl.CustomerControls
/// </summary>
public void Register()
{
//Binding binding = new Binding();
//binding.RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.Self };
//binding.Path = new PropertyPath(string.Format("DataModel[{0}].通道校准参数2", "小配料机"));
//SetBinding(TextProperty, binding);

//Binding binding = new Binding();
//binding.RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.Self };
//binding.Path = new PropertyPath("this");
//SetBinding(DataContextProperty, binding);

PropertyInfo[] propertyInfos = this.GetType().GetProperties();
foreach (PropertyInfo propertyInfo in propertyInfos)
{
@@ -99,7 +121,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
}

if (propertyBing.Count > 0)
//if (propertyBing.Count > 0)
{
timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick; ;
@@ -115,12 +137,15 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
try
{
DataModel = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(Class_DataBus.GetInstance().Dic_RedisData));

foreach (var item in propertyBing)
{
//{Binding 测试设备.VAR_A_2}
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split(".");
if (str.Length > 1)
{
DataModel = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(Class_DataBus.GetInstance().Dic_RedisData));
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0]))
{
Dictionary<string, object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]];


+ 0
- 3
BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs Visa fil

@@ -553,9 +553,6 @@ namespace BeDesignerSCADA.Controls

}
}



/// <summary>
/// 设备名称下拉框打开事件
/// </summary>


+ 16
- 2
BeDesignerSCADA/View/PropertyBindingWindow.xaml Visa fil

@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BeDesignerSCADA.View"
mc:Ignorable="d"
Title="PropertyBindingWindow" Height="160" Width="400"
Title="PropertyBindingWindow" Height="220" Width="400"
Background="White"
BorderBrush="#FFDEDEDE"
BorderThickness="1"
@@ -25,7 +25,21 @@
<TextBlock Foreground="Green" FontSize="16" Text="当前设置属性名称为:" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock x:Name="ProperpName" Foreground="Red" FontSize="14" Text="属性名称" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<ComboBox x:Name="BindingName" Margin="10,0,10,0" Height="24" Grid.Column="1" IsEditable="True" ></ComboBox>
<TextBlock Margin="10,0,0,0" Foreground="Green" FontSize="12" Text="Redis数据绑定模板" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<Grid Margin="0,5,0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="*" x:Name="key"/>
<ColumnDefinition Width="*" x:Name="Text"/>
</Grid.ColumnDefinitions>
<ComboBox x:Name="namebox" DropDownOpened="namebox_DropDownOpened" Grid.Column="1" Height="25" IsTextSearchEnabled="True" IsEditable="True" Tag="{Binding Text, ElementName=valuebox}" TextBoxBase.TextChanged="ComboBoxName_TextChanged"
>
</ComboBox>
<ComboBox x:Name="valuebox" Margin="20,0,20,0" DropDownOpened="valuebox_DropDownOpened" Grid.Column="2" Height="25" IsTextSearchEnabled="True" IsEditable="True" Tag="{Binding Text, ElementName=namebox}" TextBoxBase.TextChanged="ComboBoxValue_TextChanged"
/>
</Grid>
<TextBlock Margin="10,0,0,0" Foreground="Green" FontSize="12" Text="最终模板" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox x:Name="BindingName" Margin="10,0,20,0" Height="24" Grid.Column="1" ></TextBox>

</StackPanel>
</Grid>


+ 138
- 1
BeDesignerSCADA/View/PropertyBindingWindow.xaml.cs Visa fil

@@ -1,6 +1,9 @@
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;
@@ -29,11 +32,45 @@ namespace BeDesignerSCADA.View

public static PropertyBindingWindow Instance { get; } = new PropertyBindingWindow();

/// <summary>
/// 设备名称集合
/// </summary>
private ObservableCollection<string> _DevNameList;
public ObservableCollection<string> DevNameList
{
get
{
return _DevNameList;
}
set
{
_DevNameList = value;
}
}

public static string ShowEdit(DependencyProperty selectproperty, FrameworkElement control)
/// <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();
@@ -67,5 +104,105 @@ namespace BeDesignerSCADA.View
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;
}
}
}

+ 1
- 1
BeDesignerSCADA/ViewModel/MainViewModelNew.cs Visa fil

@@ -268,7 +268,7 @@ namespace BeDesignerSCADA.ViewModel
DependencyProperty dependencyProperty = PropertyHelper.GetDependencyProperties(selectControl)?.ToList().Find(x => x.Name == selectProName);
if (dependencyProperty != null)
{
string _binding = PropertyBindingWindow.ShowEdit(dependencyProperty, (selectControl as FrameworkElement));
string _binding = PropertyBindingWindow.ShowEdit(dependencyProperty, (selectControl as FrameworkElement), VariablePath);
if (!string.IsNullOrEmpty(_binding))
{
Binding bindingText = new Binding() { Mode = BindingMode.TwoWay, Path = new PropertyPath(_binding) };


Laddar…
Avbryt
Spara