소스 검색

更新控件样式

样式分支
fyf 2 년 전
부모
커밋
346e74d245
16개의 변경된 파일446개의 추가작업 그리고 812개의 파일을 삭제
  1. +9
    -0
      BPASmartClient.DATABUS/Class_DataBus.cs
  2. +25
    -2
      BPASmartClient.SCADAControl/Converters/BoolToVisibilityConverter.cs
  3. +0
    -1
      BPASmartClient.SCADAControl/CustomerControls/NewConveyorBelt.xaml.cs
  4. +2
    -2
      BPASmartClient.SCADAControl/CustomerControls/Silos.xaml
  5. +57
    -342
      BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs
  6. +43
    -88
      BPASmartClient.SCADAControl/CustomerControls/SwitchButton.cs
  7. +26
    -55
      BPASmartClient.SCADAControl/CustomerControls/TheButton.xaml.cs
  8. +63
    -8
      BPASmartClient.SCADAControl/CustomerControls/TheCheckBox.xaml.cs
  9. +1
    -1
      BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs
  10. +5
    -1
      BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs
  11. +7
    -31
      BPASmartClient.SCADAControl/CustomerControls/TheTextBlock.cs
  12. +40
    -70
      BPASmartClient.SCADAControl/CustomerControls/TheTextBox.cs
  13. +50
    -82
      BPASmartClient.SCADAControl/CustomerControls/TheToggleButton.xaml.cs
  14. +17
    -32
      BeDesignerSCADA/Controls/MainCanvasPanel.xaml
  15. +98
    -96
      BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs
  16. +3
    -1
      BeDesignerSCADA/ViewModel/MainViewModelNew.cs

+ 9
- 0
BPASmartClient.DATABUS/Class_DataBus.cs 파일 보기

@@ -25,6 +25,15 @@ namespace BPASmartClient.DATABUS
#endregion

#region 实时数据->大数据量
public EventHandler BindingAction { get; set; }
/// <summary>
/// 绑定数据
/// </summary>
public Dictionary<string, object> Dic_RedisDataBinding=new Dictionary<string, object>();
public void refreshDataAction(string Name)
{
BindingAction?.Invoke(Name,null);
}
/// <summary>
/// 缓存Redis数据
/// </summary>


+ 25
- 2
BPASmartClient.SCADAControl/Converters/BoolToVisibilityConverter.cs 파일 보기

@@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@@ -32,5 +33,27 @@ namespace BPASmartClient.SCADAControl.Converters
{
throw new NotImplementedException();
}
}
}


public class JTokenToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return value;
else
{
Newtonsoft.Json.Linq.JToken mj = (value as Newtonsoft.Json.Linq.JToken);
if (mj.Type == JTokenType.Boolean) return ((bool)mj);
else return mj;
}
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Newtonsoft.Json.Linq.JToken jToken = (value as Newtonsoft.Json.Linq.JToken);
return jToken;
}
}
}

+ 0
- 1
BPASmartClient.SCADAControl/CustomerControls/NewConveyorBelt.xaml.cs 파일 보기

@@ -89,7 +89,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
IsEnabled = true;
Register();
//Style = null;
}
}
}


+ 2
- 2
BPASmartClient.SCADAControl/CustomerControls/Silos.xaml 파일 보기

@@ -71,9 +71,9 @@
Grid.RowSpan="2"
Source="/BPASmartClient.SCADAControl;component/Images/光柱.png"
Stretch="Fill" />
<StackPanel Tag="ControlEvent" HorizontalAlignment="Right" Orientation="Vertical" Grid.Row="1" VerticalAlignment="Bottom" >
<!--<StackPanel Tag="ControlEvent" HorizontalAlignment="Right" Orientation="Vertical" Grid.Row="1" VerticalAlignment="Bottom" >
<Image Margin="20,10,0,0" Tag="出料" Source="/BPASmartClient.SCADAControl;component/Images/借出.png" Cursor="Hand" ToolTip="出料" Width="24" ></Image>
<Image Margin="20,10,0,10" Tag="停止出料" Source="/BPASmartClient.SCADAControl;component/Images/退出.png" Cursor="Hand" Width="24" ToolTip="停止出料"></Image>
</StackPanel>
</StackPanel>-->
</Grid>
</UserControl>

+ 57
- 342
BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs 파일 보기

@@ -43,44 +43,19 @@ namespace BPASmartClient.SCADAControl.CustomerControls
TextBlock textBlockValue = null;
TextBlock textBlockText = null;
TextBlock textBlockTitle = null;


Ellipse ellipseControl = null;
Storyboard storyboard = new Storyboard();

object typeName;
public List<string> typeNameList = new List<string>();
public Enum @enum = null;
#endregion

public Silos()
{
InitializeComponent();
this.DataContext = this;
Width = 180;
Height = 270;
this.DataContext = this;
this.SizeChanged += Silos_SizeChanged; ;
this.Loaded += Silos_Loaded;
}

private void Silos_Loaded(object sender,RoutedEventArgs e)
{
EventReceiveNameList.CollectionChanged += EventNameList_CollectionChanged;
}

private void EventNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (EventReceiveNameList.Count > 0)
{
try
{
EventReceiveNameListStr = JsonConvert.SerializeObject(EventReceiveNameList);

}
catch (Exception ex)
{
}
}
}

public string ControlType => "物料仓";
@@ -164,33 +139,22 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
if (item is Image)
{
(item as Image).MouseLeftButtonDown += Image_MouseLeftButtonDown;
if ((item as Image).Tag != null)
typeNameList.Add((item as Image).Tag?.ToString());

}
else if (item is Button)
{
(item as Button).Click += Button_Click;
if ((item as Button).Tag != null)
typeNameList.Add((item as Button).Tag?.ToString());
(item as Image).MouseLeftButtonDown += Image_MouseLeftButtonDown; ;
}
else if (item is TextBox)
{
(item as TextBox).TextChanged += TextBox_TextChanged;
if ((item as TextBox).Tag != null)
typeNameList.Add((item as TextBox).Tag?.ToString());
}
else if (item is CheckBox)
{
(item as CheckBox).Checked += CheckBox_Checked;
(item as CheckBox).Unchecked += CheckBox_Unchecked;
if ((item as CheckBox).Tag != null)
typeNameList.Add((item as CheckBox).Tag?.ToString());
}

//else if (item is Button)
//{
// (item as Button).Click += Button_Click;
//}
//else if (item is TextBox)
//{
// (item as TextBox).TextChanged += TextBox_TextChanged;
//}
//else if (item is CheckBox)
//{
// (item as CheckBox).Checked += CheckBox_Checked;
// (item as CheckBox).Unchecked += CheckBox_Unchecked;
//}
}
@enum = EnumExtensions.CreateEnum(typeNameList,$"{this.Name}ControlEunm");

}
}
@@ -262,133 +226,48 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
(d as Silos)?.Refresh();
}

[Category("名称[自动生成]")]
public string EventReceiveNameListStr
{
get { return (string)GetValue(EventReceiveNameListStrProperty); }
set { SetValue(EventReceiveNameListStrProperty,value); }
}
public static readonly DependencyProperty EventReceiveNameListStrProperty =
DependencyProperty.Register("EventReceiveNameListStr",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty,new PropertyChangedCallback(onEventReceiveNameListStrChanged)));
private static void onEventReceiveNameListStrChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.ReceiveNameRefresh();

[Category("消息接收名称集合")]
public ObservableCollection<EventReceiveMessage> EventReceiveNameList
{
get { return (ObservableCollection<EventReceiveMessage>)GetValue(EventReceiveNameListProperty); }
set { SetValue(EventReceiveNameListProperty,value); }
}
public static readonly DependencyProperty EventReceiveNameListProperty =
DependencyProperty.Register("EventReceiveNameList",typeof(ObservableCollection<EventReceiveMessage>),typeof(Silos),new PropertyMetadata(new ObservableCollection<EventReceiveMessage>()));
#endregion

#region 数据绑定模块
public event EventHandler PropertyChange; //声明一个事件
//[Category("数据绑定-数据来源")]
//public DataTypeEnum DataSouceType
//{
// get { return (DataTypeEnum)GetValue(DataSouceTypeProperty); }
// set { SetValue(DataSouceTypeProperty,value); }
//}
//public static readonly DependencyProperty DataSouceTypeProperty =
// DependencyProperty.Register("DataSouceType",typeof(DataTypeEnum),typeof(Silos),new PropertyMetadata(DataTypeEnum.静态数据));
[Category("数据绑定-数据来源")]
public int TimeCount
public string SendText
{
get { return (int)GetValue(TimeCountProperty); }
set { SetValue(TimeCountProperty,value); }
get { return (string)GetValue(SendTextProperty); }
set { SetValue(SendTextProperty, value); }
}
public static readonly DependencyProperty TimeCountProperty =
DependencyProperty.Register("TimeCount",typeof(int),typeof(Silos),new PropertyMetadata(5));
//[Category("数据绑定-数据来源")]
//public string DataSouceInformation
//{
// get { return (string)GetValue(DataSouceInformationProperty); }
// set { SetValue(DataSouceInformationProperty,value); }
//}
//public static readonly DependencyProperty DataSouceInformationProperty =
// DependencyProperty.Register("DataSouceInformation",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));
//[Category("数据绑定-数据来源")]
//public string DeviceName
//{
// get { return (string)GetValue(DeviceNameProperty); }
// set { SetValue(DeviceNameProperty,value); }
//}
//public static readonly DependencyProperty DeviceNameProperty =
// DependencyProperty.Register("DeviceName",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));
//[Category("数据绑定-数据来源")]
//public string DeviceValuleName
//{
// get { return (string)GetValue(DeviceValuleNameProperty); }
// set { SetValue(DeviceValuleNameProperty,value); }
//}
//public static readonly DependencyProperty DeviceValuleNameProperty =
// DependencyProperty.Register("DeviceValuleName",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));

[Category("数据绑定")]
public string FDataSouce
public static readonly DependencyProperty SendTextProperty =
DependencyProperty.Register("SendText", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
public string ChuLiaoExecute
{
get { return (string)GetValue(FDataSouceProperty); }
set { SetValue(FDataSouceProperty,value); }
get { return (string)GetValue(ChuLiaoExecuteProperty); }
set { SetValue(ChuLiaoExecuteProperty, value); }
}
public static readonly DependencyProperty FDataSouceProperty =
DependencyProperty.Register("FDataSouce",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty,new PropertyChangedCallback(onFDataSouceChanged)));
private static void onFDataSouceChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.DataSouceRefresh();
public void DataSouceRefresh()
public static readonly DependencyProperty ChuLiaoExecuteProperty =
DependencyProperty.Register("ChuLiaoExecute", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
public string StopChuLiaoExecute
{
try
{
if (!string.IsNullOrEmpty(FDataSouce))
{
GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code,new object[] { FDataSouce });
if (PropertyChange != null)
{
PropertyChange(this,null);
}
}
}
catch (Exception ex)
{

}
}
public static string _code = "public string main(string message) \n{ \n //请在此填写你的代码\n\n return message; \n}\n";
[Category("数据绑定")]
public string Code
{
get { return (string)GetValue(CodeProperty); }
set { SetValue(CodeProperty,value); }
}
public static readonly DependencyProperty CodeProperty =
DependencyProperty.Register("Code",typeof(string),typeof(Silos),new PropertyMetadata(_code));
[Category("数据绑定")]
public string GenerateData
{
get { return (string)GetValue(GenerateDataProperty); }
set { SetValue(GenerateDataProperty,value); }
get { return (string)GetValue(StopChuLiaoExecuteProperty); }
set { SetValue(StopChuLiaoExecuteProperty, value); }
}
public static readonly DependencyProperty GenerateDataProperty =
DependencyProperty.Register("GenerateData",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));
#endregion

#region 发送事件名称集合
[Category("事件处理")]
public MessageNameEnum 出料单击事件
public static readonly DependencyProperty StopChuLiaoExecuteProperty =
DependencyProperty.Register("StopChuLiaoExecute", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
public string ValueChangedExecute
{
get { return (MessageNameEnum)GetValue(出料单击事件Property); }
set { SetValue(出料单击事件Property,value); }
get { return (string)GetValue(ValueChangedExecuteProperty); }
set { SetValue(ValueChangedExecuteProperty, value); }
}
public static readonly DependencyProperty 出料单击事件Property =
DependencyProperty.Register("出料单击事件",typeof(MessageNameEnum),typeof(Silos),new PropertyMetadata(MessageNameEnum.Null));
[Category("事件处理")]
public MessageNameEnum 停止出料单击事件
public static readonly DependencyProperty ValueChangedExecuteProperty =
DependencyProperty.Register("ValueChangedExecute", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
public event EventHandler PropertyChange; //声明一个事件
/// <summary>
/// 数据模板
/// </summary>
private Dictionary<string, object> DataModel
{
get { return (MessageNameEnum)GetValue(停止出料单击事件Property); }
set { SetValue(停止出料单击事件Property,value); }
get { return (Dictionary<string, object>)GetValue(DataModelProperty); }
set { SetValue(DataModelProperty, value); }
}
public static readonly DependencyProperty 停止出料单击事件Property =
DependencyProperty.Register("停止出料单击事件",typeof(MessageNameEnum),typeof(Silos),new PropertyMetadata(MessageNameEnum.Null));
private static readonly DependencyProperty DataModelProperty =
DependencyProperty.Register("DataModel", typeof(Dictionary<string, object>), typeof(Silos), new PropertyMetadata(new Dictionary<string, object>()));
#endregion

#region 函数
@@ -432,172 +311,46 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
}

}

/// <summary>
/// 运行名称变化事件
/// </summary>
public void RunNameRefresh()
{

}

/// <summary>
/// 接收数据改变
/// </summary>
public void ReceiveNameRefresh()
{
}
#endregion

#region 运行事件
DispatcherTimer timer = new DispatcherTimer();
Dictionary<string, string> propertyBing = new Dictionary<string,string>();
List<string> MessageNameL = null;
public void Register()
{
if (!string.IsNullOrEmpty(EventReceiveNameListStr))
{
try
{
EventReceiveNameList = JsonConvert.DeserializeObject<ObservableCollection<EventReceiveMessage>>(EventReceiveNameListStr);
}
catch (Exception ex)
{

}
}

List<string> MessageNameNew = EventReceiveNameList?.Select(o => o.MeaageName.ToString())?.Distinct()?.ToList();
if (MessageNameL == null || !MessageNameNew.SequenceEqual(MessageNameL))
{
MessageNameL?.ForEach(o => Class_InnerMessageBus.GetInstance().RemoveMessage(o,"SliosEventHandler"));
MessageNameNew?.ForEach(x => Class_InnerMessageBus.GetInstance().ListenMessage(this,x,"SliosEventHandler"));
MessageNameL = MessageNameNew;
}

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();
}
}

if (propertyBing.Count > 0)
{
timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick; ;
timer.Start();
}
}

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_RedisData.ContainsKey(str[0]))
{
Dictionary<string, object> b= Class_DataBus.GetInstance().Dic_RedisData[str[0]];
if (b!=null && b.ContainsKey(str[1])) this.GetType().GetProperty(item.Key).SetValue(this, b[str[1]]);
}
}
}
}
catch (Exception ex)
{

}
Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
}

/// <summary>
/// 统一事件消息处理中心
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void SliosEventHandler(object sender,InnerMessageEventArgs e)
public void BindingActionHeader(object sender, EventArgs e)
{
try
this.Dispatcher.Invoke((Action)(() =>
{
if (IsExecuteState = true)//正在运行
{
if (e.obj_MessageObj is RunEnumModel)//接收到运行消息
{
RunEnumModel mode = (RunEnumModel)e.obj_MessageObj;
var msg = EventReceiveNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID);
//必对消息号:
if (msg != null)
{
Direction = mode.Run == RunEnum.Run ? 1 : 2;
}
}
else if (e.obj_MessageObj is SilosMessageModel)//接收到数据模型
{
SilosMessageModel mode = (SilosMessageModel)e.obj_MessageObj;
var msg = EventReceiveNameList?.ToList().Find(par => par.MeaageName.ToString() == e.str_MessageStr && par.MeaageID == mode.MessageID);
//必对消息号:
if (msg != null)
{
WLTitle = mode.Title;
KgValue = mode.Value;
WLText = mode.Text;
}
}
}
}
catch (Exception ex)
{

}
DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
PropertyChange?.Invoke(this, EventArgs.Empty);
}));
}
#endregion

#region 发送消息事件
public void Dispose()
{
timer.Stop();
}

/// <summary>
/// 按钮按下
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Image_MouseLeftButtonDown(object sender,MouseButtonEventArgs e)
private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
Image image = sender as Image;
if (image.Tag != null)
{
if (image.Tag.ToString() == "出料" && 出料单击事件 != MessageNameEnum.Null)
if (image.Tag.ToString() == "出料")
{
EventSendMessage eventSend = new EventSendMessage();
eventSend.ControlName = this.Name;
eventSend.ControlTitle = this.WLTitle;
eventSend.ControlSource = image.Tag.ToString();
eventSend.EventType = ControlEventType.MouseLeftButtonDown;
eventSend.MeaageName = 出料单击事件;
Class_InnerMessageBus.GetInstance().PostMessage(this,出料单击事件.ToString(),eventSend);
Config.GetInstance().RunJsScipt(ChuLiaoExecute);
}
else if (image.Tag.ToString() == "停止出料" && 停止出料单击事件 != MessageNameEnum.Null)
else if (image.Tag.ToString() == "停止出料")
{
EventSendMessage eventSend = new EventSendMessage();
eventSend.ControlName = this.Name;
eventSend.ControlTitle = this.WLTitle;
eventSend.ControlSource = image.Tag.ToString();
eventSend.EventType = ControlEventType.MouseLeftButtonDown;
eventSend.MeaageName = 停止出料单击事件;
Class_InnerMessageBus.GetInstance().PostMessage(this,停止出料单击事件.ToString(),eventSend);
Config.GetInstance().RunJsScipt(StopChuLiaoExecute);
}
}
}
@@ -606,47 +359,9 @@ namespace BPASmartClient.SCADAControl.CustomerControls

}
}
#endregion

/// <summary>
/// 按钮类型
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click(object sender,RoutedEventArgs e)
{

}

/// <summary>
/// 值改变
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TextBox_TextChanged(object sender,TextChangedEventArgs e)
{


}

/// <summary>
/// 选中
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckBox_Checked(object sender,RoutedEventArgs e)
{

}

/// <summary>
/// 取消选中
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckBox_Unchecked(object sender,RoutedEventArgs e)
{

}
#endregion
}
}

+ 43
- 88
BPASmartClient.SCADAControl/CustomerControls/SwitchButton.cs 파일 보기

@@ -45,14 +45,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(SwitchButton), new FrameworkPropertyMetadata(typeof(SwitchButton)));
}
[Category("事件")]
public string BindingIsChecked
{
get { return (string)GetValue(BingIsCheckedProperty); }
set { SetValue(BingIsCheckedProperty, value); }
}
public static readonly DependencyProperty BingIsCheckedProperty =
DependencyProperty.Register("BindingIsChecked", typeof(string),typeof(SwitchButton),new PropertyMetadata(string.Empty));
[Category("事件")]
public string SendText
{
@@ -60,8 +52,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
set { SetValue(SendTextProperty, value); }
}
public static readonly DependencyProperty SendTextProperty =
DependencyProperty.Register("SendText", typeof(string),typeof(SwitchButton),new PropertyMetadata(string.Empty));

DependencyProperty.Register("SendText", typeof(string), typeof(SwitchButton), new PropertyMetadata(string.Empty));
/// <summary>
/// 不勾选时执行代码
/// </summary>
@@ -73,7 +64,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
public static readonly DependencyProperty UnCheckedExecProperty =
DependencyProperty.Register("UnCheckedExec", typeof(string), typeof(SwitchButton), new PropertyMetadata(string.Empty));

/// <summary>
/// 勾选时执行代码
/// </summary>
@@ -85,14 +75,6 @@ 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(100));
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
@@ -100,6 +82,16 @@ namespace BPASmartClient.SCADAControl.CustomerControls
ellipse.Height = Height - 8;
Refresh();
}
/// <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(SwitchButton), new PropertyMetadata(new Dictionary<string, object>()));

TranslateTransform transX;
Ellipse ellipse;
@@ -119,7 +111,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls
base.OnUnchecked(e);
Refresh();
}

void Refresh()
{
if (ellipse == null)
@@ -157,91 +148,55 @@ 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();
}
}
if (propertyBing.Count > 0)
{
timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick; ;
timer.Start();
}
Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
this.Click += SwitchButton_Click;
}



/// <summary>
/// 属性刷新事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Timer_Tick(object? sender,EventArgs e)
public void BindingActionHeader(object sender, EventArgs e)
{
try
this.Dispatcher.Invoke((Action)(() =>
{
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_RedisData.ContainsKey(str[0]))
{
Dictionary<string,object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]];
if (b != null && b.ContainsKey(str[1]))
{
this.GetType().GetProperty("IsChecked").SetValue(this, b[str[1]]);
}
}
}
}
}
catch (Exception ex)
{

}
DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
PropertyChange?.Invoke(this, EventArgs.Empty);
}));
}

private void SwitchButton_Click(object sender,RoutedEventArgs e)
private void SwitchButton_Click(object sender, RoutedEventArgs e)
{
timer.Stop();
foreach (var item in propertyBing)
Binding binding = BindingOperations.GetBinding(this, IsCheckedProperty);
if (binding != null && !string.IsNullOrEmpty(binding.Path.Path))
{
//{Binding 测试设备.VAR_A_2}
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split(".");
if (str.Length > 1)
string path = binding.Path.Path; string _Name = string.Empty; string _Value = string.Empty;
if (!string.IsNullOrEmpty(path) && path.Contains("."))
{
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0]))//包含设备名称
try
{
_Name = path.Split('.')[0].Replace("DataModel[", "").TrimEnd(']');
_Value = path.Split('.')[1];
}
catch (Exception ex)
{
Dictionary<string,string> blx = Class_DataBus.GetInstance().Dic_RedisDataType[str[0]];

if (blx != null && blx.ContainsKey(str[1]))
{
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType), blx[str[1]]);
SendText = JsonConvert.SerializeObject(new PublishModel { DeviceName = str[0],VarName = str[1],Value = this.IsChecked.ToString(),DataType = eDataType });
}
}
}
Dictionary<string, string> blx = new Dictionary<string, string>();
if (Class_DataBus.GetInstance().Dic_RedisDataType.ContainsKey(_Name))
blx = Class_DataBus.GetInstance().Dic_RedisDataType[_Name];
if (blx != null && blx.ContainsKey(_Value))
{
SendText = JsonConvert.SerializeObject(new PublishModel
{
DeviceName = _Name,
VarName = _Value,
Value = this.IsChecked.ToString(),
DataType = (EDataType)Enum.Parse(typeof(EDataType), blx[_Value])
});
}
}
if(this.IsChecked==true) Config.GetInstance().RunJsScipt(CheckedExec);
if (this.IsChecked == true) Config.GetInstance().RunJsScipt(CheckedExec);
else Config.GetInstance().RunJsScipt(UnCheckedExec);
timer.Start();
}

public string ControlType => "控件";


+ 26
- 55
BPASmartClient.SCADAControl/CustomerControls/TheButton.xaml.cs 파일 보기

@@ -32,9 +32,17 @@ 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);
Content = "按钮";
Width = 80;
Height = 30;
this.Loaded += TheButton_Loaded;
}

private void TheButton_Loaded(object sender, RoutedEventArgs e)
{
if (this.ActualWidth <= 20)
{
Content = "按钮";
Width = 80;
Height = 30;
}
}

public string ControlType => "控件";
@@ -69,70 +77,33 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}

#region 数据绑定模块
[Category("数据绑定-数据来源")]
public int TimeCount
{
get { return (int)GetValue(TimeCountProperty); }
set { SetValue(TimeCountProperty,value); }
}
public static readonly DependencyProperty TimeCountProperty =
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheButton),new PropertyMetadata(5));
public event EventHandler PropertyChange; //声明一个事件
/// <summary>
/// 属性刷新器
/// </summary>
DispatcherTimer timer = new DispatcherTimer();
/// <summary>
/// 属性绑定变量集合
/// 数据模板
/// </summary>
Dictionary<string,string> propertyBing = new Dictionary<string,string>();
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(TheButton), new PropertyMetadata(new Dictionary<string, object>()));
/// <summary>
/// 运行事件
/// </summary>
public void Register()
{
Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
this.Click += MyButton_Click;
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();
}
/// <summary>
/// 属性刷新事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Timer_Tick(object? sender,EventArgs e)
public void BindingActionHeader(object sender, EventArgs e)
{
try
this.Dispatcher.Invoke((Action)(() =>
{
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_RedisData.ContainsKey(str[0]))
{
Dictionary<string, object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]];
if (b != null && b.ContainsKey(str[1])) this.GetType().GetProperty(item.Key).SetValue(this, b[str[1]]);
}
}
}
}
catch (Exception ex)
{

}
DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
PropertyChange?.Invoke(this, EventArgs.Empty);
}));
}
#endregion
}


+ 63
- 8
BPASmartClient.SCADAControl/CustomerControls/TheCheckBox.xaml.cs 파일 보기

@@ -1,5 +1,8 @@
using BPASmartClient.Compiler;
using BPASmart.Model;
using BPASmartClient.Compiler;
using BPASmartClient.DATABUS;
using BPASmartClient.SCADAControl;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -72,21 +75,73 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
public static readonly DependencyProperty CheckedExecProperty =
DependencyProperty.Register("CheckedExec", typeof(string), typeof(TheCheckBox), new PropertyMetadata(string.Empty));

[Category("事件")]
public string SendText
{
get { return (string)GetValue(SendTextProperty); }
set { SetValue(SendTextProperty, value); }
}
public static readonly DependencyProperty SendTextProperty =
DependencyProperty.Register("SendText", typeof(string), typeof(TheCheckBox), new PropertyMetadata(string.Empty));
/// <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(TheCheckBox), new PropertyMetadata(new Dictionary<string, object>()));
public void Register()
{
Checked += TheCheckBox_Checked;
Unchecked += TheCheckBox_Unchecked;
Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
this.Click += TheCheckBox_Click; ;
}

private void TheCheckBox_Unchecked(object sender, RoutedEventArgs e)
private void TheCheckBox_Click(object sender, RoutedEventArgs e)
{
Config.GetInstance().RunJsScipt(UnCheckedExec);
Binding binding = BindingOperations.GetBinding(this, IsCheckedProperty);
if (binding != null && !string.IsNullOrEmpty(binding.Path.Path))
{
string path = binding.Path.Path; string _Name = string.Empty; string _Value = string.Empty;
if (!string.IsNullOrEmpty(path) && path.Contains("."))
{
try
{
_Name = path.Split('.')[0].Replace("DataModel[", "").TrimEnd(']');
_Value = path.Split('.')[1];
}
catch (Exception ex)
{

}
}
Dictionary<string, string> blx = new Dictionary<string, string>();
if (Class_DataBus.GetInstance().Dic_RedisDataType.ContainsKey(_Name))
blx = Class_DataBus.GetInstance().Dic_RedisDataType[_Name];
if (blx != null && blx.ContainsKey(_Value))
{
SendText = JsonConvert.SerializeObject(new PublishModel
{
DeviceName = _Name,
VarName = _Value,
Value = this.IsChecked.ToString(),
DataType = (EDataType)Enum.Parse(typeof(EDataType), blx[_Value])
});
}
}
if (this.IsChecked == true) Config.GetInstance().RunJsScipt(CheckedExec);
else Config.GetInstance().RunJsScipt(UnCheckedExec);
}

private void TheCheckBox_Checked(object sender, RoutedEventArgs e)
public void BindingActionHeader(object sender, EventArgs e)
{
Config.GetInstance().RunJsScipt(CheckedExec);
this.Dispatcher.Invoke((Action)(() =>
{
DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
PropertyChange?.Invoke(this, EventArgs.Empty);
}));
}
}
}

+ 1
- 1
BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs 파일 보기

@@ -277,7 +277,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
else
{
this.ItemsSource = new DataTable().DefaultView;
// this.ItemsSource = new DataTable().DefaultView;
}
}


+ 5
- 1
BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs 파일 보기

@@ -172,7 +172,9 @@ namespace BPASmartClient.SCADAControl.CustomerControls
keyValuesType[jon.VarName] = jon.DataType.ToString();
});
Class_DataBus.GetInstance().Dic_RedisData[DeviceName] = keyValues;
Class_DataBus.GetInstance().Dic_RedisDataBinding = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(Class_DataBus.GetInstance().Dic_RedisData));
Class_DataBus.GetInstance().Dic_RedisDataType[DeviceName] = keyValuesType;
Class_DataBus.GetInstance().refreshDataAction(DeviceName);
if (PropertyChange != null) PropertyChange(this,null);
}
else
@@ -189,8 +191,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls
keyValuesType[jon.VarName] = jon.DataType.ToString();
});
Class_DataBus.GetInstance().Dic_RedisData[par.Key] = keyValues;
Class_DataBus.GetInstance().Dic_RedisDataBinding = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(Class_DataBus.GetInstance().Dic_RedisData));
Class_DataBus.GetInstance().Dic_RedisDataType[par.Key] = keyValuesType;
Class_DataBus.GetInstance().refreshDataAction(par.Key);

});
if (PropertyChange != null) PropertyChange(this,null);
}


+ 7
- 31
BPASmartClient.SCADAControl/CustomerControls/TheTextBlock.cs 파일 보기

@@ -65,14 +65,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}

#region 数据绑定模块
[Category("数据绑定-数据来源")]
public int TimeCount
{
get { return (int)GetValue(TimeCountProperty); }
set { SetValue(TimeCountProperty,value); }
}
public static readonly DependencyProperty TimeCountProperty =
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheTextBlock),new PropertyMetadata(50));
/// <summary>
/// 数据模板
/// </summary>
@@ -86,36 +78,20 @@ namespace BPASmartClient.SCADAControl.CustomerControls

public event EventHandler PropertyChange; //声明一个事件
/// <summary>
/// 属性刷新器
/// </summary>
DispatcherTimer timer = new DispatcherTimer();
/// <summary>
/// 运行事件
/// </summary>
public void Register()
{
if (BindingOperations.GetBinding(this, TextProperty) != null)
{
timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick; ;
timer.Start();
}
Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
}
/// <summary>
/// 属性刷新事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Timer_Tick(object? sender,EventArgs e)

public void BindingActionHeader(object sender, EventArgs e)
{
try
{
DataModel = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(Class_DataBus.GetInstance().Dic_RedisData));
}
catch (Exception ex)
this.Dispatcher.Invoke((Action)(() =>
{

}
DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
PropertyChange?.Invoke(this, EventArgs.Empty);
}));
}
#endregion
}


+ 40
- 70
BPASmartClient.SCADAControl/CustomerControls/TheTextBox.cs 파일 보기

@@ -64,26 +64,37 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
if (isRun)
{
timer.Stop();
foreach (var item in propertyBing)
Binding binding = BindingOperations.GetBinding(this, TextProperty);
if (binding != null && !string.IsNullOrEmpty(binding.Path.Path))
{
//{Binding 测试设备.VAR_A_2}
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split(".");
if (str.Length > 1)
string path = binding.Path.Path; string _Name = string.Empty; string _Value = string.Empty;
if (!string.IsNullOrEmpty(path) && path.Contains("."))
{
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0]))
try
{
Dictionary<string, string> blx = Class_DataBus.GetInstance().Dic_RedisDataType[str[0]];
if (blx != null && blx.ContainsKey(str[1]))
{
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType), blx[str[1]]);
SendText = JsonConvert.SerializeObject(new PublishModel { DeviceName = str[0], VarName = str[1], Value = Text, DataType = eDataType });
}
_Name = path.Split('.')[0].Replace("DataModel[", "").TrimEnd(']');
_Value = path.Split('.')[1];
}
catch (Exception ex)
{
}
}
Dictionary<string, string> blx = new Dictionary<string, string>();
if (Class_DataBus.GetInstance().Dic_RedisDataType.ContainsKey(_Name))
blx = Class_DataBus.GetInstance().Dic_RedisDataType[_Name];
if (blx != null && blx.ContainsKey(_Value))
{
SendText = JsonConvert.SerializeObject(new PublishModel
{
DeviceName = _Name,
VarName = _Value,
Value = this.Text.ToString(),
DataType = (EDataType)Enum.Parse(typeof(EDataType), blx[_Value])
});
}
}
Config.GetInstance().RunJsScipt(ValueChangedExecute);
timer.Start();
isRun=false;
}

@@ -103,13 +114,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls
IsEnabled = true;
Focusable = true;
Register();
//Style = null;
}
}
}



#region 数据绑定模块
public string ValueChangedExecute
{
@@ -126,71 +134,33 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
public static readonly DependencyProperty SendTextProperty =
DependencyProperty.Register("SendText", typeof(string),typeof(TheTextBox),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(TheTextBox),new PropertyMetadata(100));
public event EventHandler PropertyChange; //声明一个事件
/// <summary>
/// 属性刷新器
/// </summary>
DispatcherTimer timer = new DispatcherTimer();
/// <summary>
/// 属性绑定变量集合
/// 数据模板
/// </summary>
Dictionary<string,string> propertyBing = new Dictionary<string,string>();
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(TheTextBox), new PropertyMetadata(new Dictionary<string, object>()));

/// <summary>
/// 运行事件
/// </summary>
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();
}
}
if (propertyBing.Count > 0)
{
timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick; ;
timer.Start();
}
Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
}
/// <summary>
/// 属性刷新事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Timer_Tick(object? sender,EventArgs e)

public void BindingActionHeader(object sender, EventArgs e)
{
try
this.Dispatcher.Invoke((Action)(() =>
{
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_RedisData.ContainsKey(str[0]))
{
Dictionary<string, object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]];
if (b != null && b.ContainsKey(str[1])) this.GetType().GetProperty(item.Key).SetValue(this, b[str[1]].ToString());
}
}
}
}
catch (Exception ex)
{

}
DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
PropertyChange?.Invoke(this, EventArgs.Empty);
}));
}
#endregion



+ 50
- 82
BPASmartClient.SCADAControl/CustomerControls/TheToggleButton.xaml.cs 파일 보기

@@ -37,15 +37,23 @@ namespace BPASmartClient.SCADAControl.CustomerControls
public TheToggleButton()
{
InitializeComponent();
Width = 80;
Height = 30;
ResourceDictionary languageResDic = new ResourceDictionary();
languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
this.Resources.MergedDictionaries.Add(languageResDic);
this.Loaded += TheToggleButton_Loaded;
}

public string ControlType => "控件";
private void TheToggleButton_Loaded(object sender, RoutedEventArgs e)
{
if (this.ActualWidth <= 20)
{
Content = "按钮";
Width = 80;
Height = 30;
}
}

public string ControlType => "控件";
private bool isExecuteState;
public bool IsExecuteState
{
@@ -62,14 +70,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
}
[Category("事件")]
public string BindingIsChecked
{
get { return (string)GetValue(BindingIsCheckedProperty); }
set { SetValue(BindingIsCheckedProperty, value); }
}
public static readonly DependencyProperty BindingIsCheckedProperty =
DependencyProperty.Register("BindingIsChecked", typeof(string),typeof(TheToggleButton),new PropertyMetadata(string.Empty));
[Category("事件")]
public string SendText
{
get { return (string)GetValue(SendTextProperty); }
@@ -100,96 +100,64 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
public static readonly DependencyProperty CheckedExecProperty =
DependencyProperty.Register("CheckedExec", typeof(string), typeof(TheToggleButton), 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(TheToggleButton),new PropertyMetadata(100));
/// <summary>
/// 属性刷新器
/// </summary>
DispatcherTimer timer = new DispatcherTimer();

/// <summary>
/// 属性绑定变量集合
/// 数据模板
/// </summary>
Dictionary<string,string> propertyBing = new Dictionary<string,string>();
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(TheToggleButton), new PropertyMetadata(new Dictionary<string, object>()));
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();
}
}
if (propertyBing.Count > 0)
{
timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick; ;
timer.Start();
}
Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
Click += TheToggleButton_Click;
}



/// <summary>
/// 属性刷新事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Timer_Tick(object? sender,EventArgs e)
public void BindingActionHeader(object sender, EventArgs e)
{
try
this.Dispatcher.Invoke((Action)(() =>
{
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_RedisData.ContainsKey(str[0]))
{
Dictionary<string, object> b = Class_DataBus.GetInstance().Dic_RedisData[str[0]];
if (b != null && b.ContainsKey(str[1])) this.GetType().GetProperty("IsChecked").SetValue(this, b[str[1]]);
}
}
}
}
catch (Exception ex)
{

}
DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
PropertyChange?.Invoke(this, EventArgs.Empty);
}));
}

private void TheToggleButton_Click(object sender,RoutedEventArgs e)
{
timer.Stop();
foreach (var item in propertyBing)
Binding binding = BindingOperations.GetBinding(this, IsCheckedProperty);
if (binding != null && !string.IsNullOrEmpty(binding.Path.Path))
{
//{Binding 测试设备.VAR_A_2}
string[] str = item.Value.Replace("{Binding ","").Replace("}","").Split(".");
if (str.Length > 1)
string path = binding.Path.Path; string _Name = string.Empty; string _Value = string.Empty;
if (!string.IsNullOrEmpty(path) && path.Contains("."))
{
if (Class_DataBus.GetInstance().Dic_RedisData.ContainsKey(str[0]))
try
{
_Name = path.Split('.')[0].Replace("DataModel[", "").TrimEnd(']');
_Value = path.Split('.')[1];
}
catch (Exception ex)
{
Dictionary<string, string> blx = Class_DataBus.GetInstance().Dic_RedisDataType[str[0]];
if (blx != null && blx.ContainsKey(str[1]))
{
EDataType eDataType = (EDataType)Enum.Parse(typeof(EDataType), blx[str[1]]);
SendText = JsonConvert.SerializeObject(new PublishModel { DeviceName = str[0], VarName = str[1], Value = IsChecked.ToString(), DataType = eDataType });
}

}
}
Dictionary<string, string> blx = new Dictionary<string, string>();
if (Class_DataBus.GetInstance().Dic_RedisDataType.ContainsKey(_Name))
blx = Class_DataBus.GetInstance().Dic_RedisDataType[_Name];
if (blx != null && blx.ContainsKey(_Value))
{
SendText = JsonConvert.SerializeObject(new PublishModel
{
DeviceName = _Name,
VarName = _Value,
Value = this.IsChecked.ToString(),
DataType = (EDataType)Enum.Parse(typeof(EDataType), blx[_Value])
});
}
}
if (this.IsChecked == true) Config.GetInstance().RunJsScipt(CheckedExec);
else Config.GetInstance().RunJsScipt(UnCheckedExec);
timer.Start();
}
}
}

+ 17
- 32
BeDesignerSCADA/Controls/MainCanvasPanel.xaml 파일 보기

@@ -359,10 +359,14 @@
</mypro:EditorTemplateDefinition.EditingTemplate>
</mypro:EditorTemplateDefinition>

<mypro:EditorTemplateDefinition TargetProperties="IsRun" >
<mypro:EditorTemplateDefinition TargetProperties="IsRun,IsChecked" >
<mypro:EditorTemplateDefinition.EditingTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">定时业务</CheckBox>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<CheckBox Margin="10,0,0,0" VerticalAlignment="Center" IsChecked="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"></CheckBox>
<ToggleButton Grid.Column="1" Height="20" Content="绑定" Width="30" Margin="20,0,0,0" HorizontalAlignment="Left" Click="BingToggleButton_Click"></ToggleButton>
<ToggleButton Height="20" Content="解绑" Width="30" Margin="5,0,0,0" HorizontalAlignment="Right" Click="ClearBingToggleButton_Click"></ToggleButton>
</StackPanel>
</DataTemplate>
</mypro:EditorTemplateDefinition.EditingTemplate>
</mypro:EditorTemplateDefinition>
@@ -377,39 +381,20 @@
</mypro:EditorTemplateDefinition.EditingTemplate>
</mypro:EditorTemplateDefinition>

<mypro:EditorTemplateDefinition TargetProperties="Text,Content,Title,Value,BindingIsChecked,Header,KgValue,WLText,WLTitle,DataSouceInformation" >
<mypro:EditorTemplateDefinition TargetProperties="Text,Title,Value,BindingIsChecked,Header,KgValue,WLText,WLTitle,DataSouceInformation" >
<mypro:EditorTemplateDefinition.EditingTemplate>
<DataTemplate>
<!--此处可自由发挥-->
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Margin="0,5,0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="*" x:Name="key"/>
<ColumnDefinition Width="*" x:Name="Text"/>
</Grid.ColumnDefinitions>
<TextBlock>绑定:</TextBlock>
<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"
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl},Path=DataContext.DevNameList}">
</ComboBox>
<ComboBox x:Name="valuebox" DropDownOpened="valuebox_DropDownOpened" Grid.Column="2" Height="25" IsTextSearchEnabled="True" IsEditable="True" Tag="{Binding Text, ElementName=namebox}" TextBoxBase.TextChanged="ComboBoxValue_TextChanged"
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl},Path=DataContext.DevValueList}"/>
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Row="2" x:Name="wenben" Padding="5" Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"></TextBox>
<StackPanel Grid.Column="1">
<ToggleButton Grid.Column="1" Height="20" Content="绑定" Width="30" Margin="5,0,5,0" HorizontalAlignment="Left" Click="BingToggleButton_Click"></ToggleButton>
<ToggleButton Height="20" Content="解绑" Width="30" Margin="5,2,5,0" HorizontalAlignment="Right" Click="ClearBingToggleButton_Click"></ToggleButton>
</StackPanel>
</Grid>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Row="2" x:Name="wenben" Padding="5" Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"></TextBox>
<StackPanel Grid.Column="1">
<ToggleButton Grid.Column="1" Height="20" Content="绑定" Width="30" Margin="5,0,5,0" HorizontalAlignment="Left" Click="BingToggleButton_Click"></ToggleButton>
<ToggleButton Height="20" Content="解绑" Width="30" Margin="5,2,5,0" HorizontalAlignment="Right" Click="ClearBingToggleButton_Click"></ToggleButton>
</StackPanel>
</Grid>
</DataTemplate>
</mypro:EditorTemplateDefinition.EditingTemplate>


+ 98
- 96
BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs 파일 보기

@@ -473,105 +473,107 @@ namespace BeDesignerSCADA.Controls

}
}
/// <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;
Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text))
propertyGridCommand.Value = "{" + $"Binding {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
{
viewModel.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(viewModel.VariablePath))
{
communication = DataBusModel.GetInstance().KeyValues[viewModel.VariablePath];
}
CommunicationModel mode = communication?.CommunicationDevices?.ToList().Find(par => par.DeviceName == toggle.Tag.ToString());
if (mode != null)
{
mode?.VarTableModels?.ToList().ForEach(par => { viewModel.DevValueList.Add(par.VarName); });
}
}
}
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;
Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text))
propertyGridCommand.Value = "{" + $"Binding {toggle.Text}.{toggle.Tag}" + "}";
else if (!string.IsNullOrEmpty(toggle.Text))
propertyGridCommand.Value = "{" + $"Binding {toggle.Text}." + "}";

}
}
catch (Exception ex)
{

}
}
/// <summary>
/// 设备名称下拉框打开事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void namebox_DropDownOpened(object sender, EventArgs e)
{

viewModel.DevNameList = new System.Collections.ObjectModel.ObservableCollection<string>();
CommunicationPar communication = null;
if (DataBusModel.GetInstance().KeyValues.ContainsKey(viewModel.VariablePath))
{
communication = DataBusModel.GetInstance().KeyValues[viewModel.VariablePath];
}
communication?.CommunicationDevices?.ToList().ForEach(x => { viewModel.DevNameList.Add(x.DeviceName); });
}
#endregion


#region 不需要的
///// <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;
// Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
// if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text))
// propertyGridCommand.Value = "{" + $"Binding {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
// {
// viewModel.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(viewModel.VariablePath))
// {
// communication = DataBusModel.GetInstance().KeyValues[viewModel.VariablePath];
// }
// CommunicationModel mode = communication?.CommunicationDevices?.ToList().Find(par => par.DeviceName == toggle.Tag.ToString());
// if (mode != null)
// {
// mode?.VarTableModels?.ToList().ForEach(par => { viewModel.DevValueList.Add(par.VarName); });
// }
// }
// }
// 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;
// Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
// if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text))
// propertyGridCommand.Value = "{" + $"Binding {toggle.Text}.{toggle.Tag}" + "}";
// else if (!string.IsNullOrEmpty(toggle.Text))
// propertyGridCommand.Value = "{" + $"Binding {toggle.Text}." + "}";

// }
// }
// catch (Exception ex)
// {

// }
//}
///// <summary>
///// 设备名称下拉框打开事件
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void namebox_DropDownOpened(object sender, EventArgs e)
//{

// viewModel.DevNameList = new System.Collections.ObjectModel.ObservableCollection<string>();
// CommunicationPar communication = null;
// if (DataBusModel.GetInstance().KeyValues.ContainsKey(viewModel.VariablePath))
// {
// communication = DataBusModel.GetInstance().KeyValues[viewModel.VariablePath];
// }
// communication?.CommunicationDevices?.ToList().ForEach(x => { viewModel.DevNameList.Add(x.DeviceName); });
//}
#endregion
}




+ 3
- 1
BeDesignerSCADA/ViewModel/MainViewModelNew.cs 파일 보기

@@ -8,6 +8,7 @@ using BPASmartClient.MessageName;
using BPASmartClient.MessageName.EnumHelp;
using BPASmartClient.MessageName.发送消息Model;
using BPASmartClient.MessageName.接收消息Model;
using BPASmartClient.SCADAControl.Converters;
using ICSharpCode.AvalonEdit;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
@@ -274,7 +275,8 @@ namespace BeDesignerSCADA.ViewModel
Binding bindingText = new Binding()
{
Mode = BindingMode.TwoWay,
RelativeSource=new RelativeSource { Mode=RelativeSourceMode.Self},
Converter= new JTokenToBoolConverter(),
RelativeSource =new RelativeSource { Mode=RelativeSourceMode.Self},
Path = new PropertyPath(_binding)
};
(selectControl as FrameworkElement).SetBinding(dependencyProperty, bindingText);


불러오는 중...
취소
저장