Browse Source

修改数据绑定

样式分支
fyf 2 years ago
parent
commit
b626c22293
11 changed files with 146 additions and 42 deletions
  1. +1
    -0
      BPASmart.Model/PublishModel.cs
  2. +11
    -3
      BPASmartClient.Compiler/FRedisClient.cs
  3. +11
    -1
      BPASmartClient.DATABUS/Class_DataBus.cs
  4. +2
    -2
      BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs
  5. +81
    -3
      BPASmartClient.SCADAControl/CustomerControls/SwitchButton.cs
  6. +0
    -1
      BPASmartClient.SCADAControl/CustomerControls/TheButton.xaml
  7. +2
    -3
      BPASmartClient.SCADAControl/CustomerControls/TheButton.xaml.cs
  8. +31
    -15
      BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs
  9. +2
    -2
      BPASmartClient.SCADAControl/CustomerControls/TheTextBlock.cs
  10. +2
    -10
      BPASmartClient.SCADAControl/CustomerControls/TheTextBox.cs
  11. +3
    -2
      SCADA.Test/MainWindow.xaml.cs

+ 1
- 0
BPASmart.Model/PublishModel.cs View File

@@ -10,6 +10,7 @@ namespace BPASmart.Model
{
public string DeviceName { get; set; }
public string RealAddress { get; set; }
public string VarName { get; set; }
public string Value { get; set; }
public EDataType DataType { get; set; }
public int Sleep { get; set; }


+ 11
- 3
BPASmartClient.Compiler/FRedisClient.cs View File

@@ -51,6 +51,7 @@ namespace BPASmartClient.Compiler
_database = _connection.GetDatabase(0);//默认使用db0
subscibe = _connection.GetSubscriber();
}
int dbi = 0;
public void Connect(string connection)
{
_connection = ConnectionMultiplexer.Connect(ConfigurationOptions.Parse(connection));
@@ -58,7 +59,7 @@ namespace BPASmartClient.Compiler
{
string[] str=connection.Split(',');
string stro = str.ToList().Find(s => s.Contains("defaultDatabase="));
int dbi = 0;
try
{
dbi=int.Parse(stro.Replace("defaultDatabase=",""));
@@ -72,7 +73,7 @@ namespace BPASmartClient.Compiler
}
else
{
_database = _connection.GetDatabase();//默认使用db0
_database = _connection.GetDatabase(dbi);//默认使用db0
}
subscibe = _connection.GetSubscriber();
}
@@ -89,7 +90,14 @@ namespace BPASmartClient.Compiler
//获取指定服务器
var server = _connection.GetServer(endPoint);
//在指定服务器上使用 keys 或者 scan 命令来遍历key
foreach (var key in server.Keys(0,"设备列表:*"))
//foreach (var key in server.Keys(0,"设备列表:*"))
//{
// //获取key对于的值
// var val = _database.StringGet(key);
// Console.WriteLine($"key: {key}, value: {val}");
// keys[key] = val;
//}
foreach (var key in server.Keys(dbi,"*"))
{
//获取key对于的值
var val = _database.StringGet(key);


+ 11
- 1
BPASmartClient.DATABUS/Class_DataBus.cs View File

@@ -28,11 +28,21 @@ namespace BPASmartClient.DATABUS
/// <summary>
/// 设备数据
/// </summary>
public ConcurrentDictionary<string, Dictionary<string,object>> Dic_DeviceData = new ConcurrentDictionary<string,Dictionary<string,object>>();
public ConcurrentDictionary<string, Dictionary<string,DeviceDataModel>> Dic_DeviceData = new ConcurrentDictionary<string,Dictionary<string,DeviceDataModel>>();
/// <summary>
/// API数据
/// </summary>
public ConcurrentDictionary<string,string> Dic_APIData = new ConcurrentDictionary<string,string>();
#endregion
}


public class DeviceDataModel
{
public string VarName { get; set; }
public string VarVaule { get; set; }
public string DataType { get; set; }

}

}

+ 2
- 2
BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs View File

@@ -570,10 +570,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0]))
{
Dictionary<string,object> b= Class_DataBus.GetInstance().Dic_DeviceData[str[0]];
Dictionary<string,DeviceDataModel> b= Class_DataBus.GetInstance().Dic_DeviceData[str[0]];
if (b!=null && b.ContainsKey(str[1]))
{
object _value = b[str[1]];
object _value = b[str[1]].VarVaule;
this.GetType().GetProperty(item.Key).SetValue(this,_value);
}
}


+ 81
- 3
BPASmartClient.SCADAControl/CustomerControls/SwitchButton.cs View File

@@ -1,8 +1,10 @@
using BPASmartClient.Compiler;
using BPASmartClient.DATABUS;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@@ -16,6 +18,7 @@ using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace BPASmartClient.SCADAControl.CustomerControls
{
@@ -40,7 +43,14 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(SwitchButton), new FrameworkPropertyMetadata(typeof(SwitchButton)));
}

[Category("事件")]
public string Value
{
get { return (string)GetValue(ValueProperty); }
set { SetValue(ValueProperty,value); }
}
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value",typeof(string),typeof(SwitchButton),new PropertyMetadata(string.Empty));
/// <summary>
/// 不勾选时执行代码
/// </summary>
@@ -64,7 +74,14 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
public static readonly DependencyProperty CheckedExecProperty =
DependencyProperty.Register("CheckedExec", typeof(string), typeof(SwitchButton), new PropertyMetadata(string.Empty));

[Category("数据绑定-数据来源")]
public int TimeCount
{
get { return (int)GetValue(TimeCountProperty); }
set { SetValue(TimeCountProperty,value); }
}
public static readonly DependencyProperty TimeCountProperty =
DependencyProperty.Register("TimeCount",typeof(int),typeof(SwitchButton),new PropertyMetadata(5));
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
@@ -128,12 +145,73 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
}
}

/// <summary>
/// 属性刷新器
/// </summary>
DispatcherTimer timer = new DispatcherTimer();
/// <summary>
/// 属性绑定变量集合
/// </summary>
Dictionary<string,string> propertyBing = new Dictionary<string,string>();
public void Register()
{
PropertyInfo[] propertyInfos = this.GetType().GetProperties();
foreach (PropertyInfo propertyInfo in propertyInfos)
{
var propName = propertyInfo?.GetValue(this,null);
if (propName is string && propName != null && propName.ToString().Contains("Binding ") && propName.ToString().Contains("."))
{
propertyBing[propertyInfo.Name] = propName.ToString();
}
}
timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick; ;
timer.Start();
Checked += TheCheckBox_Checked;
Unchecked += TheCheckBox_Unchecked;
}
/// <summary>
/// 属性刷新事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Timer_Tick(object? sender,EventArgs e)
{
try
{
foreach (var item in propertyBing)
{
//{Binding 测试设备.VAR_A_2}
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split(".");
if (str.Length > 1)
{
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0]))
{
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]];
if (b != null && b.ContainsKey(str[1]))
{
object _value = b[str[1]].VarVaule;
bool _checked = false;
try
{
_checked = bool.Parse(_value.ToString());
}
catch (Exception ex)
{
_checked = false;
}
this.GetType().GetProperty("IsChecked").SetValue(this,_checked);
}
}
}
}
}
catch (Exception ex)
{

}
}

private void TheCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
Config.GetInstance().RunJsScipt(UnCheckedExec);


+ 0
- 1
BPASmartClient.SCADAControl/CustomerControls/TheButton.xaml View File

@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPASmartClient.SCADAControl"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
</Button>

+ 2
- 3
BPASmartClient.SCADAControl/CustomerControls/TheButton.xaml.cs View File

@@ -48,7 +48,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls
isExecuteState = value;
if (IsExecuteState)
{
Style = null;
Register();
}
}
@@ -124,10 +123,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0]))
{
Dictionary<string,object> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]];
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]];
if (b != null && b.ContainsKey(str[1]))
{
object _value = b[str[1]];
object _value = b[str[1]].VarVaule;
this.GetType().GetProperty(item.Key).SetValue(this,_value);
}
}


+ 31
- 15
BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs View File

@@ -47,7 +47,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
foreach (Image tb in FindVisualChildren<Image>(this))
{
// do something with tb here
if (tb.Tag != null)
{
if (tb.Tag.ToString() == "正常")
@@ -69,7 +68,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls

foreach (TextBlock tb in FindVisualChildren<TextBlock>(this))
{
// do something with tb here
if (tb.Tag != null)
{
if (tb.Tag.ToString() == "显示文字")
@@ -159,17 +157,38 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
if (Direction == 1) //定时读取数据
{
if (!string.IsNullOrEmpty(DeviceName))
try
{
RedisValue obj = fRedisClient.RedisGet(DeviceName);
FDataSouce = obj.ToString();
List<ReeisDataModel> str = JsonConvert.DeserializeObject<List<ReeisDataModel>>(FDataSouce);
Dictionary<string,object> keys=new Dictionary<string, object>();
str?.ForEach(par =>
if (!string.IsNullOrEmpty(DeviceName))
{
RedisValue obj = fRedisClient.RedisGet(DeviceName);
List<DeviceDataModel> str = JsonConvert.DeserializeObject<List<DeviceDataModel>>(obj.ToString());
Dictionary<string,DeviceDataModel> keys = new Dictionary<string,DeviceDataModel>();
str?.ForEach(par =>
{
keys[par.VarName] = par;
});
Class_DataBus.GetInstance().Dic_DeviceData[DeviceName] = keys;
if (PropertyChange != null) PropertyChange(this,null);
}
else
{
keys[par.VarName] = par.VarVaule;
});
Class_DataBus.GetInstance().Dic_DeviceData[DeviceName] = keys;
fRedisClient.GetKeys()?.ToList().ForEach(par => {

List<DeviceDataModel> str = JsonConvert.DeserializeObject<List<DeviceDataModel>>(par.Value);
Dictionary<string,DeviceDataModel> keys = new Dictionary<string,DeviceDataModel>();
str?.ForEach(par =>
{
keys[par.VarName] = par;
});
Class_DataBus.GetInstance().Dic_DeviceData[par.Key] = keys;
});
if (PropertyChange != null) PropertyChange(this,null);
}
}
catch (Exception ex)
{

}
}
}
@@ -284,10 +303,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
if (!string.IsNullOrEmpty(FDataSouce))
{
GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code,new object[] { FDataSouce });
if (PropertyChange != null)
{
PropertyChange(this,null);
}
}
}
catch (Exception ex)


+ 2
- 2
BPASmartClient.SCADAControl/CustomerControls/TheTextBlock.cs View File

@@ -108,10 +108,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0]))
{
Dictionary<string,object> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]];
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]];
if (b != null && b.ContainsKey(str[1]))
{
object _value = b[str[1]];
object _value = b[str[1]].VarVaule;
this.GetType().GetProperty(item.Key).SetValue(this,_value);
}
}


+ 2
- 10
BPASmartClient.SCADAControl/CustomerControls/TheTextBox.cs View File

@@ -35,17 +35,9 @@ namespace BPASmartClient.SCADAControl.CustomerControls
ResourceDictionary languageResDic = new ResourceDictionary();
languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
this.Resources.MergedDictionaries.Add(languageResDic);
Text = "0.01";
//VerticalContentAlignment = VerticalAlignment.Center;
//Style = Application.Current.Resources["DesignTheTextBox"] as Style;//FindResource("DesignTheTextBox") as Style;
//Focusable = false;
Height = 30;
Width = 80;
FontSize = 16;
//HorizontalAlignment = HorizontalAlignment.Left;
//VerticalAlignment = VerticalAlignment.Center;
//Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#a2c2e8"));
//BorderThickness=new Thickness(1);
}
public string ControlType => "控件";

@@ -122,10 +114,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
if (Class_DataBus.GetInstance().Dic_DeviceData.ContainsKey(str[0]))
{
Dictionary<string,object> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]];
Dictionary<string,DeviceDataModel> b = Class_DataBus.GetInstance().Dic_DeviceData[str[0]];
if (b != null && b.ContainsKey(str[1]))
{
object _value = b[str[1]];
object _value = b[str[1]].VarVaule;
this.GetType().GetProperty(item.Key).SetValue(this,_value);
}
}


+ 3
- 2
SCADA.Test/MainWindow.xaml.cs View File

@@ -40,13 +40,14 @@ namespace SCADA.Test
/// 接收消息集合
/// </summary>
List<EventReceiveMessage> eventReceiveMessages = new List<EventReceiveMessage>();
FRedisClient fRedisClient = new FRedisClient();

public MainWindow()
{
InitializeComponent();

RedisHelper.GetInstance.ConnectAsync(String.Empty);
fRedisClient.Connect("124.222.238.75:16000,password=123456,defaultDatabase=1");
Dictionary<string,string> sdsd= fRedisClient.GetKeys();
string _code = " public string main(string message) \n { \n //请在此填写你的代码\n\n return message; \n }\n";
string GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(_code,new object[] { "ERERERERE" });



Loading…
Cancel
Save