From b738ddb406628fec1689c7daad9bd25e2fa6d490 Mon Sep 17 00:00:00 2001 From: fyf Date: Wed, 21 Sep 2022 15:31:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8F=B3=E4=BE=A7=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomerControls/NewConveyorBelt.xaml.cs | 57 +--- .../CustomerControls/Silos.xaml.cs | 105 ++------ .../CustomerControls/TheImage.xaml.cs | 4 +- .../Themes/Generic.xaml | 17 +- BeDesignerSCADA/Controls/MainCanvasPanel.xaml | 156 ++++++++--- .../Controls/MainCanvasPanel.xaml.cs | 42 ++- .../Converters/ColorToStringConverter.cs | 45 ++++ BeDesignerSCADA/MainWindow.xaml | 147 ++++++++--- BeDesignerSCADA/MainWindow.xaml.cs | 166 ++---------- BeDesignerSCADA/ViewModel/MainViewModel.cs | 6 +- BeDesignerSCADA/ViewModel/MainViewModelNew.cs | 243 ++++++++++++++++++ 11 files changed, 637 insertions(+), 351 deletions(-) create mode 100644 BeDesignerSCADA/Converters/ColorToStringConverter.cs create mode 100644 BeDesignerSCADA/ViewModel/MainViewModelNew.cs diff --git a/BPASmartClient.SCADAControl/CustomerControls/NewConveyorBelt.xaml.cs b/BPASmartClient.SCADAControl/CustomerControls/NewConveyorBelt.xaml.cs index 1def1f8d..07e44eb1 100644 --- a/BPASmartClient.SCADAControl/CustomerControls/NewConveyorBelt.xaml.cs +++ b/BPASmartClient.SCADAControl/CustomerControls/NewConveyorBelt.xaml.cs @@ -61,22 +61,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls private void NewConveyorBelt_Loaded(object sender, RoutedEventArgs e) { EventReceiveNameList.CollectionChanged += EventNameList_CollectionChanged; - EventSendNameList.CollectionChanged += EventSendNameList_CollectionChanged; - - } - private void EventSendNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e) - { - if (EventSendNameList.Count > 0) - { - try - { - EventSendNameListStr = JsonConvert.SerializeObject(EventSendNameList); - - } - catch (Exception ex) - { - } - } } private void EventNameList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { @@ -351,23 +335,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls public static readonly DependencyProperty EventReceiveNameListProperty = 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("名称[自动生成]")] - private string EventSendNameListStr - { - get { return (string)GetValue(EventSendNameListStrProperty); } - set { SetValue(EventSendNameListStrProperty,value); } - } - private static readonly DependencyProperty EventSendNameListStrProperty = - DependencyProperty.Register("EventSendNameListStr",typeof(string),typeof(NewConveyorBelt),new PropertyMetadata(string.Empty)); - [Category("消息发送名称集合")] - private ObservableCollection EventSendNameList - { - get { return (ObservableCollection)GetValue(EventSendNameListProperty); } - set { SetValue(EventSendNameListProperty,value); } - } - private static readonly DependencyProperty EventSendNameListProperty = - DependencyProperty.Register("EventSendNameList",typeof(ObservableCollection),typeof(NewConveyorBelt),new PropertyMetadata(new ObservableCollection(),new PropertyChangedCallback(onEventNameListChanged))); - #endregion #region 属性变更事件 @@ -385,17 +352,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls } } - if (!string.IsNullOrEmpty(EventSendNameListStr)) - { - try - { - EventSendNameList = JsonConvert.DeserializeObject>(EventSendNameListStr); - } - catch (Exception ex) - { - - } - } + List MessageNameNew = EventReceiveNameList?.Select(o => o.MeaageName.ToString())?.Distinct()?.ToList(); if (MessageNameL == null || !MessageNameNew.SequenceEqual(MessageNameL)) { @@ -479,17 +436,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls /// public void ReceiveNameRefresh() { - if (!string.IsNullOrEmpty(EventReceiveNameListStr)) - { - try - { - EventReceiveNameList = JsonConvert.DeserializeObject>(EventReceiveNameListStr); - } - catch (Exception ex) - { - - } - } + } #endregion } diff --git a/BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs b/BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs index 0db5e44c..8bc7d2d8 100644 --- a/BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs +++ b/BPASmartClient.SCADAControl/CustomerControls/Silos.xaml.cs @@ -66,22 +66,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls private void Silos_Loaded(object sender,RoutedEventArgs e) { EventReceiveNameList.CollectionChanged += EventNameList_CollectionChanged; - EventSendNameList.CollectionChanged += EventSendNameList_CollectionChanged; - } - - private void EventSendNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e) - { - if (EventSendNameList.Count > 0) - { - try - { - EventSendNameListStr = JsonConvert.SerializeObject(EventSendNameList); - - } - catch (Exception ex) - { - } - } } private void EventNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e) @@ -238,32 +222,32 @@ namespace BPASmartClient.SCADAControl.CustomerControls #region 属性 [Category("值设定")] - public string Value + public string KgValue { get { return (string)GetValue(ValueProperty); } set { SetValue(ValueProperty,value); } } public static readonly DependencyProperty ValueProperty = - DependencyProperty.Register("Value",typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); + DependencyProperty.Register("KgValue", 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 + public string WLText { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty,value); } } public static readonly DependencyProperty TextProperty = - DependencyProperty.Register("Text",typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); + DependencyProperty.Register("WLText", typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); [Category("值设定")] - public string Title + public string WLTitle { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty,value); } } public static readonly DependencyProperty TitleProperty = - DependencyProperty.Register("Title",typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); + DependencyProperty.Register("WLTitle", typeof(string),typeof(Silos),new PropertyMetadata(new PropertyChangedCallback(onTargetChanged))); [Category("值设定")] public int Direction @@ -296,24 +280,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls set { SetValue(EventReceiveNameListProperty,value); } } public static readonly DependencyProperty EventReceiveNameListProperty = - DependencyProperty.Register("EventReceiveNameList",typeof(ObservableCollection),typeof(Silos),new PropertyMetadata(new ObservableCollection(),new PropertyChangedCallback(onEventNameListChanged))); - [Category("名称[自动生成]")] - private string EventSendNameListStr - { - get { return (string)GetValue(EventSendNameListStrProperty); } - set { SetValue(EventSendNameListStrProperty,value); } - } - private static readonly DependencyProperty EventSendNameListStrProperty = - DependencyProperty.Register("EventSendNameListStr",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty)); - [Category("消息发送名称集合")] - private ObservableCollection EventSendNameList - { - get { return (ObservableCollection)GetValue(EventSendNameListProperty); } - set { SetValue(EventSendNameListProperty,value); } - } - 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(); + DependencyProperty.Register("EventReceiveNameList",typeof(ObservableCollection),typeof(Silos),new PropertyMetadata(new ObservableCollection())); #endregion #region 数据绑定模块 @@ -432,9 +399,9 @@ namespace BPASmartClient.SCADAControl.CustomerControls { if (textBlockValue != null && textBlockText != null && textBlockTitle != null) { - textBlockValue.Text = Value; - textBlockText.Text = Text; - textBlockTitle.Text = Title; + textBlockValue.Text = KgValue; + textBlockText.Text = WLText; + textBlockTitle.Text = WLTitle; } } @@ -475,30 +442,12 @@ namespace BPASmartClient.SCADAControl.CustomerControls } - /// - /// 数据名称变化事件 - /// - public void DataNameRefresh() - { - - } - /// /// 接收数据改变 /// public void ReceiveNameRefresh() { - if (!string.IsNullOrEmpty(EventReceiveNameListStr)) - { - try - { - EventReceiveNameList = JsonConvert.DeserializeObject>(EventReceiveNameListStr); - } - catch (Exception ex) - { - - } - } + } #endregion @@ -520,18 +469,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls } } - if (!string.IsNullOrEmpty(EventSendNameListStr)) - { - try - { - EventSendNameList = JsonConvert.DeserializeObject>(EventSendNameListStr); - } - catch (Exception ex) - { - - } - } - List MessageNameNew = EventReceiveNameList?.Select(o => o.MeaageName.ToString())?.Distinct()?.ToList(); if (MessageNameL == null || !MessageNameNew.SequenceEqual(MessageNameL)) { @@ -550,10 +487,12 @@ namespace BPASmartClient.SCADAControl.CustomerControls } } - timer.Interval = TimeSpan.FromMilliseconds(TimeCount); - timer.Tick += Timer_Tick; ; - timer.Start(); - + if (propertyBing.Count > 0) + { + timer.Interval = TimeSpan.FromMilliseconds(TimeCount); + timer.Tick += Timer_Tick; ; + timer.Start(); + } } private void Timer_Tick(object? sender,EventArgs e) @@ -612,9 +551,9 @@ namespace BPASmartClient.SCADAControl.CustomerControls //必对消息号: if (msg != null) { - Title = mode.Title; - Value = mode.Value; - Text = mode.Text; + WLTitle = mode.Title; + KgValue = mode.Value; + WLText = mode.Text; } } } @@ -648,7 +587,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls { EventSendMessage eventSend = new EventSendMessage(); eventSend.ControlName = this.Name; - eventSend.ControlTitle = this.Title; + eventSend.ControlTitle = this.WLTitle; eventSend.ControlSource = image.Tag.ToString(); eventSend.EventType = ControlEventType.MouseLeftButtonDown; eventSend.MeaageName = 出料单击事件; @@ -658,7 +597,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls { EventSendMessage eventSend = new EventSendMessage(); eventSend.ControlName = this.Name; - eventSend.ControlTitle = this.Title; + eventSend.ControlTitle = this.WLTitle; eventSend.ControlSource = image.Tag.ToString(); eventSend.EventType = ControlEventType.MouseLeftButtonDown; eventSend.MeaageName = 停止出料单击事件; diff --git a/BPASmartClient.SCADAControl/CustomerControls/TheImage.xaml.cs b/BPASmartClient.SCADAControl/CustomerControls/TheImage.xaml.cs index 4a09eb29..96023325 100644 --- a/BPASmartClient.SCADAControl/CustomerControls/TheImage.xaml.cs +++ b/BPASmartClient.SCADAControl/CustomerControls/TheImage.xaml.cs @@ -29,8 +29,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls InitializeComponent(); Stretch = Stretch.UniformToFill; //SetCurrentValue(SourceProperty, new BitmapImage(new Uri("pack://application:,,,/Images/借出.png", UriKind.Absolute))); - //Width = 120; - //Height = 40; + Width = 80; + Height = 80; } public string ControlType => "控件"; diff --git a/BPASmartClient.SCADAControl/Themes/Generic.xaml b/BPASmartClient.SCADAControl/Themes/Generic.xaml index 4d49e4d0..49bec208 100644 --- a/BPASmartClient.SCADAControl/Themes/Generic.xaml +++ b/BPASmartClient.SCADAControl/Themes/Generic.xaml @@ -295,6 +295,11 @@ + + + + + @@ -311,26 +316,26 @@ VerticalAlignment="Center" Cursor="Hand" FontSize="14" - Foreground="{DynamicResource ButtonSelectForeground}" + Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Content}" /> - + - + - + - + - + diff --git a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml index a66989f9..e1bdc996 100644 --- a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml +++ b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml @@ -25,15 +25,16 @@ + - - + + - - + + @@ -138,7 +139,7 @@ - + @@ -187,37 +188,129 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - - + + + + + + + + + + - + - - + + - + + + + + + + + + + + + + + + + + - @@ -225,33 +318,27 @@ - + - - - - - + - - - - - + @@ -282,12 +369,13 @@ - + diff --git a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs index 45b8b840..34437555 100644 --- a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs +++ b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs @@ -35,7 +35,8 @@ namespace BeDesignerSCADA.Controls /// 布局文件路径 /// public string Path=string.Empty; - MainViewModel viewModel = new MainViewModel(); + public string VariablePath = string.Empty; + MainViewModelNew viewModel = new MainViewModelNew(); public MainCanvasPanel(string _Path) { InitializeComponent(); @@ -204,6 +205,21 @@ namespace BeDesignerSCADA.Controls SaveBtn_Click(null, null); } /// + /// 传入变量管理器地址 + /// + /// + public void VariableManagerPath(string path) + { + try + { + VariablePath = path; + } + catch (Exception ex) + { + + } + } + /// /// 保存 /// /// @@ -272,6 +288,30 @@ namespace BeDesignerSCADA.Controls } } /// + /// 路径资源选择 + /// + /// + /// + private void LJToggleButton_Click(object sender, RoutedEventArgs e) + { + try + { + if (sender is ToggleButton) + { + ToggleButton toggle = (ToggleButton)sender; + Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem; + if (propertyGridCommand != null) + { + viewModel.SelectPath(propertyGridCommand); + } + } + } + catch (Exception ex) + { + + } + } + /// /// 变量选择 /// /// diff --git a/BeDesignerSCADA/Converters/ColorToStringConverter.cs b/BeDesignerSCADA/Converters/ColorToStringConverter.cs new file mode 100644 index 00000000..bfd91c9d --- /dev/null +++ b/BeDesignerSCADA/Converters/ColorToStringConverter.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; + +namespace BeDesignerSCADA.Converters +{ + [ValueConversion(typeof(string), typeof(System.Drawing.Color))] + public class ColorToStringConverter : IValueConverter + { + static ColorToStringConverter() + { + Instance = new ColorToStringConverter(); + } + + public static ColorToStringConverter Instance + { + get; + private set; + } + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if (value is System.Windows.Media.LinearGradientBrush) + { + return value;// == null ? null : ((System.Windows.Media.LinearGradientBrush)value); + } + else if (value is System.Windows.Media.ImageBrush) + { + return value;// == null ? null : ((System.Windows.Media.ImageBrush)value); + } + else + return value==null?null:((SolidColorBrush)value).Color; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return value == null ? null : new SolidColorBrush((System.Windows.Media.Color)value); + } + } +} diff --git a/BeDesignerSCADA/MainWindow.xaml b/BeDesignerSCADA/MainWindow.xaml index e97e6c6f..a6f20c9a 100644 --- a/BeDesignerSCADA/MainWindow.xaml +++ b/BeDesignerSCADA/MainWindow.xaml @@ -191,37 +191,129 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - - + + + + + + + + + + - + - - + + - + + + + + + + + + + + + + + + + + - @@ -229,33 +321,27 @@ - + - - - - - + - - - - - + @@ -278,7 +364,7 @@ ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window},Path=DataContext.DevValueList}"/> - + @@ -286,12 +372,13 @@ - + diff --git a/BeDesignerSCADA/MainWindow.xaml.cs b/BeDesignerSCADA/MainWindow.xaml.cs index 4f924e99..5901bf60 100644 --- a/BeDesignerSCADA/MainWindow.xaml.cs +++ b/BeDesignerSCADA/MainWindow.xaml.cs @@ -34,155 +34,17 @@ namespace BeDesignerSCADA public partial class MainWindow : Window { - MainViewModel viewModel=new MainViewModel(); + MainViewModelNew viewModel =new MainViewModelNew(); public MainWindow() { InitializeComponent(); this.DataContext = viewModel; viewModel.Loaded(cav, runCanvas); - //控件加载 Assembly assembly = Assembly.LoadFile($"{System.AppDomain.CurrentDomain.BaseDirectory}\\BPASmartClient.SCADAControl.dll"); //Assembly.GetExecutingAssembly(); var controls = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o=>o.Name); CtlList.ItemsSource = controls; - this.GotFocus += MainWindow_GotFocus; - this.LostFocus += MainWindow_LostFocus; } - private void MainWindow_LostFocus(object sender, RoutedEventArgs e) - { - System.Diagnostics.Trace.WriteLine("失去焦点:" + e.OriginalSource.ToString()); - // Console.WriteLine(e.OriginalSource.ToString()); - } - - private void MainWindow_GotFocus(object sender, RoutedEventArgs e) - { - System.Diagnostics.Trace.WriteLine("获得焦点:"+e.OriginalSource.ToString()); - - } - - #region 加载数据中心与事件中心 - /// - /// 加载数据中心 - /// - public void Loading() - { - //try - //{ - // Assembly assembly1 = Assembly.LoadFile($"{System.AppDomain.CurrentDomain.BaseDirectory}\\BPASmartClient.MessageName.dll"); - // Type type = assembly1.GetType("BPASmartClient.MessageName.MessageName"); - // var control = Activator.CreateInstance(type); - // var fildes = control.GetType().GetFields(); - // foreach (var fi in fildes) - // { - // EventModel eventModel = new EventModel(); - // eventModel.EventValue = fi.GetValue(control)?.ToString(); - // eventModel.EventName = fi.Name; - // foreach (var item in fi.CustomAttributes) - // { - // if (item.AttributeType.Name == "CategoryAttribute") - // { - // eventModel.Category = item.ConstructorArguments.Count() > 0 ? item.ConstructorArguments[0].Value?.ToString() : ""; - // } - // else if (item.AttributeType.Name == "DescriptionAttribute") - // { - // eventModel.Description = item.ConstructorArguments.Count() > 0 ? item.ConstructorArguments[0].Value?.ToString() : ""; - // } - // else if (item.AttributeType.Name == "BrowsableAttribute") - // { - // eventModel.Browsable = item.ConstructorArguments.Count() > 0 ? (bool)item.ConstructorArguments[0].Value : true; - // } - // } - // if (!string.IsNullOrEmpty(eventModel.Category)) - // { - // if (Class_DataBus.GetInstance().EventData.ContainsKey(eventModel.Category)) - // Class_DataBus.GetInstance().EventData[eventModel.Category].Add(eventModel); - // else - // { - // Class_DataBus.GetInstance().EventData[eventModel.Category] = new List { eventModel }; - // } - // } - // } - - - // type = assembly1.GetType("BPASmartClient.MessageName.DataName"); - // control = Activator.CreateInstance(type); - // fildes = control.GetType().GetFields(); - // foreach (var fi in fildes) - // { - // ALLModel aLLModel = new ALLModel(); - // aLLModel.DataValue = fi.GetValue(control)?.ToString(); - // aLLModel.DataName = fi.Name; - // foreach (var item in fi.CustomAttributes) - // { - // if (item.AttributeType.Name == "CategoryAttribute") - // { - // aLLModel.Category = item.ConstructorArguments.Count() > 0 ? item.ConstructorArguments[0].Value?.ToString() : ""; - // } - // else if (item.AttributeType.Name == "DescriptionAttribute") - // { - // aLLModel.Description = item.ConstructorArguments.Count() > 0 ? item.ConstructorArguments[0].Value?.ToString() : ""; - // } - // else if (item.AttributeType.Name == "BrowsableAttribute") - // { - // aLLModel.Browsable = item.ConstructorArguments.Count() > 0 ? (bool)item.ConstructorArguments[0].Value : true; - // } - // } - // if (!string.IsNullOrEmpty(aLLModel.Category)) - // { - // if (Class_DataBus.GetInstance().ALLData.ContainsKey(aLLModel.Category)) - // Class_DataBus.GetInstance().ALLData[aLLModel.Category].Add(aLLModel); - // else - // { - // Class_DataBus.GetInstance().ALLData[aLLModel.Category] = new List { aLLModel }; - // } - // } - - // } - - - //} - //catch (Exception ex) - //{ - // System.Windows.MessageBox.Show(ex.Message); - //} - } - /// - /// 加载本地文件 - /// - public void LoadFile() - { - //加载配置数据 - FJson.Read(); - viewModel.DevNameList = new System.Collections.ObjectModel.ObservableCollection(); - viewModel.DevValueList = new System.Collections.ObjectModel.ObservableCollection(); - FJson.Data.CommunicationDevices?.ToList().ForEach(data => - { - viewModel.DevNameList.Add(data.DeviceName); - data.VarTableModels?.ToList().ForEach((data) => { - - if(!viewModel.DevValueList.Contains(data.VarName) && !string.IsNullOrEmpty(data.VarName)) - viewModel.DevValueList.Add(data.VarName); - }); - }); - //CommunicationModel model = new CommunicationModel(); - //Type typeData = model.GetType(); - //PropertyInfo[] properties = typeData.GetProperties(); - //foreach (PropertyInfo property in properties) - //{ - // viewModel.DevValueList.Add(property.Name); - - //} - //ICommunicationDevice DeviceType; - //DeviceType = FJson.Data.CommunicationDevices.ElementAt(0).CommDevice; - //VariableInfo variable = new VariableInfo(DeviceType); - //PropertyInfo[] prope = variable.GetType().GetProperties(); - //foreach (var item in prope) - //{ - // viewModel.DevValueList.Add(item.Name); - //} - } - #endregion - #region 位置调整 /// /// 左对齐 @@ -367,6 +229,30 @@ namespace BeDesignerSCADA } } /// + /// 路径资源选择 + /// + /// + /// + private void LJToggleButton_Click(object sender, RoutedEventArgs e) + { + try + { + if (sender is ToggleButton) + { + ToggleButton toggle = (ToggleButton)sender; + Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem; + if (propertyGridCommand != null) + { + viewModel.SelectPath(propertyGridCommand); + } + } + } + catch (Exception ex) + { + + } + } + /// /// 变量选择 /// /// @@ -450,5 +336,7 @@ namespace BeDesignerSCADA Class_DataBus.GetInstance().Dic_DeviceData.Keys?.ToList().ForEach(key => { viewModel.DevNameList.Add(key); }); } #endregion + + } } diff --git a/BeDesignerSCADA/ViewModel/MainViewModel.cs b/BeDesignerSCADA/ViewModel/MainViewModel.cs index c37b2470..3084891c 100644 --- a/BeDesignerSCADA/ViewModel/MainViewModel.cs +++ b/BeDesignerSCADA/ViewModel/MainViewModel.cs @@ -202,6 +202,10 @@ namespace BeDesignerSCADA.ViewModel /// 启动或者停止 /// public RelayCommand RunUiCommand { get; set; } + /// + /// 编辑 + /// + public RelayCommand EditCommand { get; set; } #endregion #region 常用函数 @@ -466,7 +470,7 @@ namespace BeDesignerSCADA.ViewModel } #endregion - + Dictionary EventName = new Dictionary { {"Name","名称" }, {"Text","文本" }, diff --git a/BeDesignerSCADA/ViewModel/MainViewModelNew.cs b/BeDesignerSCADA/ViewModel/MainViewModelNew.cs new file mode 100644 index 00000000..f57ff337 --- /dev/null +++ b/BeDesignerSCADA/ViewModel/MainViewModelNew.cs @@ -0,0 +1,243 @@ +using BeDesignerSCADA.Common; +using BeDesignerSCADA.Controls; +using BeDesignerSCADA.View; +using BPASmartClient.Compiler; +using BPASmartClient.DATABUS; +using BPASmartClient.MessageName; +using BPASmartClient.MessageName.EnumHelp; +using BPASmartClient.MessageName.发送消息Model; +using BPASmartClient.MessageName.接收消息Model; +using ICSharpCode.AvalonEdit; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; +using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; + +namespace BeDesignerSCADA.ViewModel +{ + public class MainViewModelNew : ObservableObject + { + public MainViewModelNew() + { + IsRunning = false; + //启动 或者 停止 + RunUiCommand = new RelayCommand(() => + { + IsRunning = !IsRunning; + }); + } + + #region 变量 + /// + /// 是否正在运行状态 + /// + private bool _IsRunning = false; + public bool IsRunning + { + get + { + return _IsRunning; + } + set + { + _IsRunning = value; + if (value) + { + RunCanvasVisibility = Visibility.Visible; + CanvasPanelVisibility = Visibility.Hidden; + } + else + { + RunCanvasVisibility = Visibility.Hidden; + CanvasPanelVisibility = Visibility.Visible; + } + OnPropertyChanged("IsRunning"); + } + } + + /// + /// 画布是否显示 + /// + private Visibility _CanvasPanelVisibility; + public Visibility CanvasPanelVisibility + { + get + { + return _CanvasPanelVisibility; + } + set + { + if (_CanvasPanelVisibility == value) + return; + _CanvasPanelVisibility = value; + OnPropertyChanged("CanvasPanelVisibility"); + } + } + + /// + /// 运行代码是否显示 + /// + private Visibility _RunCanvasVisibility; + public Visibility RunCanvasVisibility + { + get + { + return _RunCanvasVisibility; + } + set + { + if (_RunCanvasVisibility == value) + return; + _RunCanvasVisibility = value; + OnPropertyChanged("RunCanvasVisibility"); + } + } + + /// + /// 当前代码Xaml + /// + private string _XamlCode; + public string XamlCode + { + get + { + return _XamlCode; + } + set + { + if (_XamlCode == value) + return; + _XamlCode = value; + OnPropertyChanged("XamlCode"); + } + } + + /// + /// 选中控件 + /// + private FrameworkElement _CanSelectedItem; + public FrameworkElement CanSelectedItem + { + get + { + return _CanSelectedItem; + } + set + { + if (_CanSelectedItem == value) + return; + _CanSelectedItem = value; + OnPropertyChanged("CanSelectedItem"); + } + } + + /// + /// 设备名称集合 + /// + private ObservableCollection _DevNameList; + public ObservableCollection DevNameList + { + get + { + return _DevNameList; + } + set + { + _DevNameList = value; + OnPropertyChanged("DevNameList"); + } + } + + /// + /// 设备变量集合 + /// + private ObservableCollection _DevValueList; + public ObservableCollection DevValueList + { + get + { + return _DevValueList; + } + set + { + _DevValueList = value; + OnPropertyChanged("DevValueList"); + } + } + #endregion + + #region 命令 + /// + /// 启动或者停止 + /// + public RelayCommand RunUiCommand { get; set; } + /// + /// 编辑 + /// + public RelayCommand EditCommand { get; set; } + #endregion + + #region 常用函数 + /// + /// 显示当前xaml代码 + /// + public void ShowCode(TextEditor textEditor) + { + textEditor.Text = canvasPanel.Save(); + } + #endregion + + #region 脚本编辑数据 + /// + /// 当前编辑界面 + /// + public CanvasPanel canvasPanel; + /// + /// 当前运行界面 + /// + public RunCanvas runCanvas; + /// + /// 加载 + /// + /// + public void Loaded(object objCan, object objRun) + { + canvasPanel = objCan as CanvasPanel; + + runCanvas = objRun as RunCanvas; + } + /// + /// 编辑 + /// + /// + public void Edit(object obj) + { + string result = JsEditWindow.ShowEdit(((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).Value?.ToString(), canvasPanel.GetAllExecChildren()); + ((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).Value = result; + } + /// + /// 图片选择路径 + /// + /// + public void SelectPath(object obj) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Filter = "图片|*.jpg;*.png;*.gif;*.jpeg;*.bmp"; + if (ofd.ShowDialog() == true) + { + ((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).Value = ofd.FileName; + } + } + #endregion + } +}