Sfoglia il codice sorgente

跟新控件

样式分支
fyf 2 anni fa
parent
commit
63cd43dbe6
5 ha cambiato i file con 97 aggiunte e 76 eliminazioni
  1. +4
    -0
      BPASmartClient.MessageName/接收消息Model/物料仓/SilosMessageModel.cs
  2. +23
    -17
      BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs
  3. +65
    -58
      BPASmartClient.SCADAControl/Silos.xaml.cs
  4. +4
    -1
      SCADA.Test/MainWindow.xaml
  5. +1
    -0
      SCADA.Test/MainWindow.xaml.cs

+ 4
- 0
BPASmartClient.MessageName/接收消息Model/物料仓/SilosMessageModel.cs Vedi File

@@ -23,5 +23,9 @@ namespace BPASmartClient.MessageName.接收消息Model.物料仓
/// 物料仓:重量(G) 35.23
/// </summary>
public string Value { get; set; }
/// <summary>
/// 物料仓:仓号说明
/// </summary>
public string Text { get; set; }
}
}

+ 23
- 17
BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs Vedi File

@@ -60,17 +60,7 @@ namespace BPASmartClient.SCADAControl
{
EventReceiveNameList.CollectionChanged += EventNameList_CollectionChanged;
EventSendNameList.CollectionChanged += EventSendNameList_CollectionChanged;
foreach (TextBlock tb in FindVisualChildren<TextBlock>(this))
{
// do something with tb here
if (tb.Tag != null)
{
if (tb.Tag.ToString() == "标题")
{
textBlock = tb;
}
}
}
}
private void EventSendNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
@@ -169,6 +159,21 @@ namespace BPASmartClient.SCADAControl
VisualStateManagerData();
}

if (textBlock == null)
{
foreach (TextBlock tb in FindVisualChildren<TextBlock>(this))
{
// do something with tb here
if (tb.Tag != null)
{
if (tb.Tag.ToString() == "标题")
{
textBlock = tb;
}
}
}
}

if (this.Height > 0 && this.Width > 0)
{
try
@@ -362,6 +367,7 @@ namespace BPASmartClient.SCADAControl
#endregion

#region 属性变更事件
List<string> MessageNameL = null;
public void Register()
{
if (!string.IsNullOrEmpty(EventReceiveNameListStr))
@@ -386,16 +392,16 @@ namespace BPASmartClient.SCADAControl

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

public void EventHandler(object sender, InnerMessageEventArgs e)
public void NewConveyorBeltEventHandler(object sender, InnerMessageEventArgs e)
{
try
{


+ 65
- 58
BPASmartClient.SCADAControl/Silos.xaml.cs Vedi File

@@ -33,11 +33,11 @@ namespace BPASmartClient.SCADAControl
/// Silos.xaml 的交互逻辑
/// 物料仓
/// </summary>
public partial class Silos : UserControl, IExecutable
public partial class Silos :UserControl, IExecutable
{
#region 临时变量
TextBlock textBlockCLKZ = null;
TextBlock textBlockValue=null;
TextBlock textBlockValue = null;
TextBlock textBlockText = null;
TextBlock textBlockTitle = null;

@@ -54,18 +54,18 @@ namespace BPASmartClient.SCADAControl
this.DataContext = this;
Width = 180;
Height = 270;
this.SizeChanged += Silos_SizeChanged; ;
this.Loaded += Silos_Loaded;
}


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

private void EventSendNameList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
private void EventSendNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (EventSendNameList.Count > 0)
{
@@ -79,7 +79,7 @@ namespace BPASmartClient.SCADAControl
}
}
}
private void EventNameList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
private void EventNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (EventReceiveNameList.Count > 0)
{
@@ -115,7 +115,7 @@ namespace BPASmartClient.SCADAControl
/// <summary>
/// 加载内部变量
/// </summary>
public void Loading()
private void Silos_SizeChanged(object sender,SizeChangedEventArgs e)
{
//查找
if (ellipseControl == null)
@@ -128,6 +128,14 @@ namespace BPASmartClient.SCADAControl
if (tb.Tag.ToString() == "出料圆")
{
ellipseControl = tb;
storyboard.RepeatBehavior = RepeatBehavior.Forever;
DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
Storyboard.SetTarget(animation,ellipseControl);
Storyboard.SetTargetProperty(animation,new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"));
animation.KeyFrames.Add(new EasingDoubleKeyFrame(0,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
animation.KeyFrames.Add(new EasingDoubleKeyFrame(180,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));
animation.KeyFrames.Add(new EasingDoubleKeyFrame(360,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))));
storyboard.Children.Add(animation);
}
}
}
@@ -140,7 +148,8 @@ namespace BPASmartClient.SCADAControl
if (tb.Tag.ToString() == "出料控制")
{
textBlockCLKZ = tb;
}else if (tb.Tag.ToString() == "Value")
}
else if (tb.Tag.ToString() == "Value")
{
textBlockValue = tb;
}
@@ -182,20 +191,11 @@ namespace BPASmartClient.SCADAControl
(item as CheckBox).Unchecked += CheckBox_Unchecked;
}
}
//Type _typeName =EnumExtensions.CreatEnumType(tb.Children);
//typeName = _typeName.Assembly.CreateInstance(_typeName.FullName);
}
}
}
}
storyboard.RepeatBehavior = RepeatBehavior.Forever;
DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
Storyboard.SetTarget(animation, ellipseControl);
Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"));
animation.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
animation.KeyFrames.Add(new EasingDoubleKeyFrame(180, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));
animation.KeyFrames.Add(new EasingDoubleKeyFrame(360, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))));
storyboard.Children.Add(animation);
}

public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
@@ -204,7 +204,7 @@ namespace BPASmartClient.SCADAControl
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
DependencyObject child = VisualTreeHelper.GetChild(depObj,i);
if (child != null && child is T)
{
yield return (T)child;
@@ -224,74 +224,74 @@ namespace BPASmartClient.SCADAControl
public string Value
{
get { return (string)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
set { SetValue(ValueProperty,value); }
}
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(string), typeof(Silos), new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
private static void onTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as Silos)?.TargetRefresh();
DependencyProperty.Register("Value",typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
private static void onTargetChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.TargetRefresh();
[Category("值设定")]
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
set { SetValue(TextProperty,value); }
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(Silos), new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
DependencyProperty.Register("Text",typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));

[Category("值设定")]
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
set { SetValue(TitleProperty,value); }
}
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(Silos), new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));
DependencyProperty.Register("Title",typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged)));

[Category("名称[自动生成]")]
public string EventReceiveNameListStr
{
get { return (string)GetValue(EventReceiveNameListStrProperty); }
set { SetValue(EventReceiveNameListStrProperty, value); }
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));
[Category("消息接收名称集合")]
public ObservableCollection<EventReceiveMessage> EventReceiveNameList
{
get { return (ObservableCollection<EventReceiveMessage>)GetValue(EventReceiveNameListProperty); }
set { SetValue(EventReceiveNameListProperty, value); }
set { SetValue(EventReceiveNameListProperty,value); }
}
public static readonly DependencyProperty EventReceiveNameListProperty =
DependencyProperty.Register("EventReceiveNameList", typeof(ObservableCollection<EventReceiveMessage>), typeof(Silos), new PropertyMetadata(new ObservableCollection<EventReceiveMessage>(), new PropertyChangedCallback(onEventNameListChanged)));
DependencyProperty.Register("EventReceiveNameList",typeof(ObservableCollection<EventReceiveMessage>),typeof(Silos),new PropertyMetadata(new ObservableCollection<EventReceiveMessage>(),new PropertyChangedCallback(onEventNameListChanged)));
[Category("名称[自动生成]")]
public string EventSendNameListStr
{
get { return (string)GetValue(EventSendNameListStrProperty); }
set { SetValue(EventSendNameListStrProperty, value); }
set { SetValue(EventSendNameListStrProperty,value); }
}
public static readonly DependencyProperty EventSendNameListStrProperty =
DependencyProperty.Register("EventSendNameListStr", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty));
DependencyProperty.Register("EventSendNameListStr",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty));
[Category("消息发送名称集合")]
public ObservableCollection<EventSendMessage> EventSendNameList
{
get { return (ObservableCollection<EventSendMessage>)GetValue(EventSendNameListProperty); }
set { SetValue(EventSendNameListProperty, value); }
set { SetValue(EventSendNameListProperty,value); }
}
public static readonly DependencyProperty EventSendNameListProperty =
DependencyProperty.Register("EventSendNameList", typeof(ObservableCollection<EventSendMessage>), typeof(Silos), new PropertyMetadata(new ObservableCollection<EventSendMessage>(), new PropertyChangedCallback(onEventNameListChanged)));
DependencyProperty.Register("EventSendNameList",typeof(ObservableCollection<EventSendMessage>),typeof(Silos),new PropertyMetadata(new ObservableCollection<EventSendMessage>(),new PropertyChangedCallback(onEventNameListChanged)));
private static void onEventNameListChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.DataNameRefresh();

[Category("值设定")]
public int Direction
{
get { return (int)GetValue(DirectionProperty); }
set { SetValue(DirectionProperty, value); }
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)
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();
}
@@ -338,7 +338,7 @@ namespace BPASmartClient.SCADAControl
storyboard.Stop();
}
}
}

/// <summary>
@@ -354,11 +354,12 @@ namespace BPASmartClient.SCADAControl
/// </summary>
public void DataNameRefresh()
{
}
#endregion

#region 运行事件
List<string> MessageNameL = null;
public void Register()
{
if (!string.IsNullOrEmpty(EventReceiveNameListStr))
@@ -383,17 +384,21 @@ namespace BPASmartClient.SCADAControl

}
}
EventReceiveNameList?.ToList().ForEach(x =>
List<string> MessageNameNew = EventReceiveNameList?.Select(o => o.MeaageName.ToString())?.Distinct()?.ToList();
if (MessageNameL==null || !MessageNameNew.SequenceEqual(MessageNameL))
{
Class_InnerMessageBus.GetInstance().ListenMessage(this,x.MeaageName.ToString(),"EventHandler");
});
MessageNameL?.ForEach(o => Class_InnerMessageBus.GetInstance().RemoveMessage(o,"SliosEventHandler"));
MessageNameNew?.ForEach(x => Class_InnerMessageBus.GetInstance().ListenMessage(this,x,"SliosEventHandler"));
MessageNameL = MessageNameNew;
}
}
/// <summary>
/// 统一事件消息处理中心
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void EventHandler(object sender, InnerMessageEventArgs e)
public void SliosEventHandler(object sender,InnerMessageEventArgs e)
{
try
{
@@ -404,11 +409,12 @@ namespace BPASmartClient.SCADAControl
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)
if (msg != null)
{
Direction = mode.Run == RunEnum.Run ? 1 : 2;
}
}else if (e.obj_MessageObj is SilosMessageModel)//接收到数据模型
}
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);
@@ -417,6 +423,7 @@ namespace BPASmartClient.SCADAControl
{
Title = mode.Title;
Value = mode.Value;
Text = mode.Text;
}
}
}
@@ -434,7 +441,7 @@ namespace BPASmartClient.SCADAControl
/// </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
{
@@ -446,44 +453,44 @@ namespace BPASmartClient.SCADAControl

}
}
/// <summary>
/// 按钮类型
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click(object sender, RoutedEventArgs e)
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)
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)
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)
private void CheckBox_Unchecked(object sender,RoutedEventArgs e)
{

}


+ 4
- 1
SCADA.Test/MainWindow.xaml Vedi File

@@ -44,7 +44,7 @@
<TextBlock Margin="10,0,0,10" FontSize="16">消息名称</TextBlock>
<ComboBox x:Name="xxnc"></ComboBox>

<TextBlock Margin="10,0,0,10" FontSize="16">号</TextBlock>
<TextBlock Margin="10,0,0,10" FontSize="16">消息号</TextBlock>
<TextBox x:Name="ch">1</TextBox>

<TextBlock Margin="10,0,0,10" FontSize="16">标题</TextBlock>
@@ -53,6 +53,9 @@
<TextBlock Margin="10,0,0,10" FontSize="16">重量</TextBlock>
<TextBox x:Name="zl">35.23</TextBox>

<TextBlock Margin="10,0,0,10" FontSize="16">仓号说明</TextBlock>
<TextBox x:Name="cgs">35.23</TextBox>
<Button Margin="10,10,0,10" Width="100" Height="40" Click="Button_Click_2" >发送</Button>
</StackPanel>
</Border>


+ 1
- 0
SCADA.Test/MainWindow.xaml.cs Vedi File

@@ -138,6 +138,7 @@ namespace SCADA.Test
silosMessage.MessageID = ch.Text;
silosMessage.Value = zl.Text;
silosMessage.Title = bt.Text;
silosMessage.Text= cgs.Text;
Class_InnerMessageBus.GetInstance().PostMessage(this, xxnc.Text, silosMessage);

}


Caricamento…
Annulla
Salva