diff --git a/BPASmartClient.MessageName/BPASmartClient.MessageName.csproj b/BPASmartClient.MessageName/BPASmartClient.MessageName.csproj
index 40bdbea1..87c7214c 100644
--- a/BPASmartClient.MessageName/BPASmartClient.MessageName.csproj
+++ b/BPASmartClient.MessageName/BPASmartClient.MessageName.csproj
@@ -11,6 +11,7 @@
+
diff --git a/BPASmartClient.MessageName/EnumHelp/EnumExtensions.cs b/BPASmartClient.MessageName/EnumHelp/EnumExtensions.cs
index 9edd2d53..2919834e 100644
--- a/BPASmartClient.MessageName/EnumHelp/EnumExtensions.cs
+++ b/BPASmartClient.MessageName/EnumHelp/EnumExtensions.cs
@@ -20,7 +20,7 @@ namespace BPASmartClient.MessageName.EnumHelp
/// 根据控件-》创建枚举类型
///
///
- public static Type CreatEnumType(UIElementCollection list)
+ public static object CreatEnumType(UIElementCollection list)
{
var currentDomain = AppDomain.CurrentDomain;
var assembly = Assembly.GetExecutingAssembly();
@@ -47,6 +47,75 @@ namespace BPASmartClient.MessageName.EnumHelp
}
+ ///
+ /// 动态创建枚举
+ ///
+ /// 枚举元素列表
+ /// 枚举名
+ /// Enum枚举
+ public static Enum CreateEnum(Dictionary enumDictionary,string enumName = "DefalutEnum")
+ {
+ if (enumDictionary == null || enumDictionary.Count <= 0)
+ return null;
+
+ AppDomain currentDomain = AppDomain.CurrentDomain;
+ AssemblyName aName = new AssemblyName("TempAssembly");
+ AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly(aName,AssemblyBuilderAccess.Run);
+ ModuleBuilder mb = ab.DefineDynamicModule(aName.Name);
+ if (string.IsNullOrEmpty(enumName))
+ {
+ enumName = "DefalutEnum";
+ }
+ EnumBuilder eb = mb.DefineEnum(enumName,TypeAttributes.Public,typeof(int));
+
+ foreach (var item in enumDictionary)
+ {
+ eb.DefineLiteral(item.Key,item.Value);
+ }
+
+ Type finished = eb.CreateType();
+ Enum eEnum = Activator.CreateInstance(finished) as Enum;
+ //foreach (object item in Enum.GetValues(eEnum.GetType()))
+ //{
+ // Debug.LogError(string.Format("{0}.{1} = {2}", finished, item, ((int)item)));
+ //}
+ return eEnum;
+ }
+
+ ///
+ /// 动态创建枚举
+ ///
+ /// 枚举元素列表
+ /// 枚举名
+ /// Enum枚举
+ public static Enum CreateEnum(List enumList,string enumName = "DefalutEnum")
+ {
+ if (enumList == null || enumList.Count <= 0)
+ return null;
+
+ AppDomain currentDomain = AppDomain.CurrentDomain;
+ AssemblyName aName = new AssemblyName("TempAssembly");
+ AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly(aName,AssemblyBuilderAccess.Run);
+ ModuleBuilder mb = ab.DefineDynamicModule(aName.Name);
+ if (string.IsNullOrEmpty(enumName))
+ {
+ enumName = "DefalutEnum";
+ }
+ EnumBuilder eb = mb.DefineEnum(enumName,TypeAttributes.Public,typeof(int));
+
+ for (int i = 0; i < enumList.Count; i++)
+ {
+ eb.DefineLiteral(enumList[i],i);
+ }
+ Type finished = eb.CreateType();
+ Enum eEnum = Activator.CreateInstance(finished) as Enum;
+ //foreach (object item in Enum.GetValues(eEnum.GetType()))
+ //{
+ // Debug.LogError(string.Format("{0}.{1} = {2}", finished, item, ((int)item)));
+ //}
+ return eEnum;
+ }
+
///
/// 根据枚举int值获取枚举名称
///
@@ -58,6 +127,14 @@ namespace BPASmartClient.MessageName.EnumHelp
return Enum.GetName(typeof(T), status);
}
+ ///
+ /// 根据枚举名称获取枚举值
+ ///
+ public static T ToEnumValue(string name)
+ {
+ return (T)Enum.Parse(typeof(T),name);
+ }
+
///
/// 获取枚举变量值的 Description 属性
@@ -101,5 +178,7 @@ namespace BPASmartClient.MessageName.EnumHelp
}
return obj.ToString();
}
+
+
}
}
diff --git a/BPASmartClient.MessageName/发送消息Model/EventSendMessage.cs b/BPASmartClient.MessageName/发送消息Model/EventSendMessage.cs
index c8c79222..4453e3ed 100644
--- a/BPASmartClient.MessageName/发送消息Model/EventSendMessage.cs
+++ b/BPASmartClient.MessageName/发送消息Model/EventSendMessage.cs
@@ -11,10 +11,6 @@ namespace BPASmartClient.MessageName.发送消息Model
///
public class EventSendMessage: MessageBase
{
- ///
- /// 控件类型
- ///
- public ControlEventType EventType { get; set; }
///
/// 控件名称
///
@@ -26,11 +22,16 @@ namespace BPASmartClient.MessageName.发送消息Model
///
/// 控件触发源
///
- public string ControlSource { get; set; }
+ public object ControlSource { get; set; }
///
/// 控件状态
///
public string ControlStatus { get; set; }
+ ///
+ /// 控件类型
+ ///
+ public ControlEventType EventType { get; set; }
+
}
///
/// 控件类型
diff --git a/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs b/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs
index 8b709760..67b13017 100644
--- a/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs
+++ b/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs
@@ -337,7 +337,9 @@ namespace BPASmartClient.SCADAControl
set { SetValue(EventReceiveNameListStrProperty, value); }
}
public static readonly DependencyProperty EventReceiveNameListStrProperty =
- DependencyProperty.Register("EventReceiveNameListStr", typeof(string), typeof(NewConveyorBelt), new PropertyMetadata(string.Empty));
+ DependencyProperty.Register("EventReceiveNameListStr",typeof(string),typeof(NewConveyorBelt),new PropertyMetadata(string.Empty,new PropertyChangedCallback(onEventReceiveNameListStrChanged)));
+ private static void onEventReceiveNameListStrChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as NewConveyorBelt)?.ReceiveNameRefresh();
+
[Category("消息接收名称集合")]
public ObservableCollection EventReceiveNameList
{
@@ -348,20 +350,20 @@ namespace BPASmartClient.SCADAControl
DependencyProperty.Register("EventReceiveNameList", typeof(ObservableCollection), typeof(NewConveyorBelt), new PropertyMetadata(new ObservableCollection(), onEventNameListChanged));
private static void onEventNameListChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as NewConveyorBelt)?.RunNameRefresh();
[Category("名称[自动生成]")]
- public string EventSendNameListStr
+ private string EventSendNameListStr
{
get { return (string)GetValue(EventSendNameListStrProperty); }
set { SetValue(EventSendNameListStrProperty,value); }
}
- public static readonly DependencyProperty EventSendNameListStrProperty =
+ private static readonly DependencyProperty EventSendNameListStrProperty =
DependencyProperty.Register("EventSendNameListStr",typeof(string),typeof(NewConveyorBelt),new PropertyMetadata(string.Empty));
[Category("消息发送名称集合")]
- public ObservableCollection EventSendNameList
+ private ObservableCollection EventSendNameList
{
get { return (ObservableCollection)GetValue(EventSendNameListProperty); }
set { SetValue(EventSendNameListProperty,value); }
}
- public static readonly DependencyProperty EventSendNameListProperty =
+ private static readonly DependencyProperty EventSendNameListProperty =
DependencyProperty.Register("EventSendNameList",typeof(ObservableCollection),typeof(NewConveyorBelt),new PropertyMetadata(new ObservableCollection(),new PropertyChangedCallback(onEventNameListChanged)));
#endregion
@@ -469,6 +471,24 @@ namespace BPASmartClient.SCADAControl
{
}
+
+ ///
+ /// 接收数据改变
+ ///
+ public void ReceiveNameRefresh()
+ {
+ if (!string.IsNullOrEmpty(EventReceiveNameListStr))
+ {
+ try
+ {
+ EventReceiveNameList = JsonConvert.DeserializeObject>(EventReceiveNameListStr);
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+ }
#endregion
}
diff --git a/BPASmartClient.SCADAControl/Silos.xaml b/BPASmartClient.SCADAControl/Silos.xaml
index 636294e9..704d6563 100644
--- a/BPASmartClient.SCADAControl/Silos.xaml
+++ b/BPASmartClient.SCADAControl/Silos.xaml
@@ -71,12 +71,10 @@
Grid.RowSpan="2"
Source="/BPASmartClient.SCADAControl;component/Images/光柱.png"
Stretch="Fill" />
-
-
-
-
-
-
+
+
+
+
diff --git a/BPASmartClient.SCADAControl/Silos.xaml.cs b/BPASmartClient.SCADAControl/Silos.xaml.cs
index 48d68608..16446741 100644
--- a/BPASmartClient.SCADAControl/Silos.xaml.cs
+++ b/BPASmartClient.SCADAControl/Silos.xaml.cs
@@ -46,6 +46,8 @@ namespace BPASmartClient.SCADAControl
Storyboard storyboard = new Storyboard();
object typeName;
+ public List typeNameList = new List();
+ public Enum @enum = null;
#endregion
public Silos()
@@ -62,7 +64,6 @@ namespace BPASmartClient.SCADAControl
{
EventReceiveNameList.CollectionChanged += EventNameList_CollectionChanged;
EventSendNameList.CollectionChanged += EventSendNameList_CollectionChanged;
- //Loading();
}
private void EventSendNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
@@ -176,26 +177,38 @@ namespace BPASmartClient.SCADAControl
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());
}
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());
}
+
}
+ @enum = EnumExtensions.CreateEnum(typeNameList,$"{this.Name}ControlEunm");
+
}
}
}
}
-
+
}
public static IEnumerable FindVisualChildren(DependencyObject depObj) where T : DependencyObject
@@ -248,6 +261,20 @@ namespace BPASmartClient.SCADAControl
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title",typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
+ [Category("值设定")]
+ public int Direction
+ {
+ get { return (int)GetValue(DirectionProperty); }
+ set { SetValue(DirectionProperty,value); }
+ }
+ public static readonly DependencyProperty DirectionProperty =
+ DependencyProperty.Register("Direction",typeof(int),typeof(Silos),
+ new PropertyMetadata(0,new PropertyChangedCallback(OnPropertyChanged)));
+ private static void OnPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)
+ {
+ (d as Silos)?.Refresh();
+ }
+
[Category("名称[自动生成]")]
public string EventReceiveNameListStr
{
@@ -255,7 +282,9 @@ namespace BPASmartClient.SCADAControl
set { SetValue(EventReceiveNameListStrProperty,value); }
}
public static readonly DependencyProperty EventReceiveNameListStrProperty =
- DependencyProperty.Register("EventReceiveNameListStr",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));
+ 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 EventReceiveNameList
{
@@ -265,37 +294,41 @@ namespace BPASmartClient.SCADAControl
public static readonly DependencyProperty EventReceiveNameListProperty =
DependencyProperty.Register("EventReceiveNameList",typeof(ObservableCollection),typeof(Silos),new PropertyMetadata(new ObservableCollection(),new PropertyChangedCallback(onEventNameListChanged)));
[Category("名称[自动生成]")]
- public string EventSendNameListStr
+ private string EventSendNameListStr
{
get { return (string)GetValue(EventSendNameListStrProperty); }
set { SetValue(EventSendNameListStrProperty,value); }
}
- public static readonly DependencyProperty EventSendNameListStrProperty =
+ private static readonly DependencyProperty EventSendNameListStrProperty =
DependencyProperty.Register("EventSendNameListStr",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));
[Category("消息发送名称集合")]
- public ObservableCollection EventSendNameList
+ private ObservableCollection EventSendNameList
{
get { return (ObservableCollection)GetValue(EventSendNameListProperty); }
set { SetValue(EventSendNameListProperty,value); }
}
- public static readonly DependencyProperty EventSendNameListProperty =
+ private static readonly DependencyProperty EventSendNameListProperty =
DependencyProperty.Register("EventSendNameList",typeof(ObservableCollection),typeof(Silos),new PropertyMetadata(new ObservableCollection(),new PropertyChangedCallback(onEventNameListChanged)));
private static void onEventNameListChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.DataNameRefresh();
+ #endregion
- [Category("值设定")]
- public int Direction
+ #region 发送事件名称集合
+ [Category("事件处理")]
+ public MessageNameEnum 出料单击事件
{
- get { return (int)GetValue(DirectionProperty); }
- set { SetValue(DirectionProperty,value); }
+ get { return (MessageNameEnum)GetValue(出料单击事件Property); }
+ set { SetValue(出料单击事件Property,value); }
}
- public static readonly DependencyProperty DirectionProperty =
- DependencyProperty.Register("Direction",typeof(int),typeof(Silos),
- new PropertyMetadata(0,new PropertyChangedCallback(OnPropertyChanged)));
- private static void OnPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)
+ public static readonly DependencyProperty 出料单击事件Property =
+ DependencyProperty.Register("出料单击事件",typeof(MessageNameEnum),typeof(Silos),new PropertyMetadata(MessageNameEnum.Null));
+ [Category("事件处理")]
+ public MessageNameEnum 停止出料单击事件
{
- (d as Silos)?.Refresh();
+ get { return (MessageNameEnum)GetValue(停止出料单击事件Property); }
+ set { SetValue(停止出料单击事件Property,value); }
}
-
+ public static readonly DependencyProperty 停止出料单击事件Property =
+ DependencyProperty.Register("停止出料单击事件",typeof(MessageNameEnum),typeof(Silos),new PropertyMetadata(MessageNameEnum.Null));
#endregion
#region 函数
@@ -356,6 +389,24 @@ namespace BPASmartClient.SCADAControl
{
}
+
+ ///
+ /// 接收数据改变
+ ///
+ public void ReceiveNameRefresh()
+ {
+ if (!string.IsNullOrEmpty(EventReceiveNameListStr))
+ {
+ try
+ {
+ EventReceiveNameList = JsonConvert.DeserializeObject>(EventReceiveNameListStr);
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+ }
#endregion
#region 运行事件
@@ -384,14 +435,15 @@ namespace BPASmartClient.SCADAControl
}
}
+
List MessageNameNew = EventReceiveNameList?.Select(o => o.MeaageName.ToString())?.Distinct()?.ToList();
- if (MessageNameL==null || !MessageNameNew.SequenceEqual(MessageNameL))
+ 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;
}
-
+
}
///
/// 统一事件消息处理中心
@@ -446,7 +498,29 @@ namespace BPASmartClient.SCADAControl
try
{
Image image = sender as Image;
-
+ if (image.Tag != null)
+ {
+ if (image.Tag.ToString() == "出料" && 出料单击事件 != MessageNameEnum.Null)
+ {
+ EventSendMessage eventSend = new EventSendMessage();
+ eventSend.ControlName = this.Name;
+ eventSend.ControlTitle = this.Title;
+ eventSend.ControlSource = image.Tag.ToString();
+ eventSend.EventType = ControlEventType.MouseLeftButtonDown;
+ eventSend.MeaageName = 出料单击事件;
+ Class_InnerMessageBus.GetInstance().PostMessage(this,出料单击事件.ToString(),eventSend);
+ }
+ else if (image.Tag.ToString() == "停止出料" && 停止出料单击事件 != MessageNameEnum.Null)
+ {
+ EventSendMessage eventSend = new EventSendMessage();
+ eventSend.ControlName = this.Name;
+ eventSend.ControlTitle = this.Title;
+ eventSend.ControlSource = image.Tag.ToString();
+ eventSend.EventType = ControlEventType.MouseLeftButtonDown;
+ eventSend.MeaageName = 停止出料单击事件;
+ Class_InnerMessageBus.GetInstance().PostMessage(this,停止出料单击事件.ToString(),eventSend);
+ }
+ }
}
catch (Exception ex)
{
@@ -495,7 +569,5 @@ namespace BPASmartClient.SCADAControl
}
#endregion
-
-
}
}
diff --git a/SCADA.Test/MainWindow.xaml b/SCADA.Test/MainWindow.xaml
index a85f89a4..ba58d37a 100644
--- a/SCADA.Test/MainWindow.xaml
+++ b/SCADA.Test/MainWindow.xaml
@@ -16,11 +16,14 @@
+
+
+
diff --git a/SCADA.Test/MainWindow.xaml.cs b/SCADA.Test/MainWindow.xaml.cs
index c842406c..e7579cdd 100644
--- a/SCADA.Test/MainWindow.xaml.cs
+++ b/SCADA.Test/MainWindow.xaml.cs
@@ -1,9 +1,12 @@
using BPASmartClient.MessageCommunication;
+using BPASmartClient.MessageCommunication.MsgControl;
using BPASmartClient.MessageName;
using BPASmartClient.MessageName.EnumHelp;
+using BPASmartClient.MessageName.发送消息Model;
using BPASmartClient.MessageName.接收消息Model;
using BPASmartClient.MessageName.接收消息Model.物料仓;
using Microsoft.Win32;
+using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
@@ -43,9 +46,32 @@ namespace SCADA.Test
xxnc.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
mlname.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
xx.ItemsSource = System.Enum.GetNames(typeof(RunEnum))?.ToList();
+
+ Class_InnerMessageBus.GetInstance().ListenMessage(this,MessageNameEnum.SendMessageName.ToString(),"MainWindowHandler");
+ }
+
+ public void MainWindowHandler(object sender,InnerMessageEventArgs e)
+ {
+ try
+ {
+ if (e.obj_MessageObj is EventSendMessage)//接收到运行消息
+ {
+ EventSendMessage mode = (EventSendMessage)e.obj_MessageObj;
+ LogShowText(JsonConvert.SerializeObject(mode));
+ }
+ }
+ catch (Exception ex)
+ {
+
+ }
}
#region 加载数据
+ public void LogShowText(string str)
+ {
+ LogShow.Text += str + "\n";
+ }
+
///
/// 加载数据
///
diff --git a/SCADA.Test/SCADA.Test.csproj b/SCADA.Test/SCADA.Test.csproj
index cbd3414e..efbc1979 100644
--- a/SCADA.Test/SCADA.Test.csproj
+++ b/SCADA.Test/SCADA.Test.csproj
@@ -7,6 +7,10 @@
true
+
+
+
+