|
- using BeDesignerSCADA.Common;
- using BeDesignerSCADA.Controls;
- using BeDesignerSCADA.View;
- using BPASmart.Model;
- 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.Concurrent;
- 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.Controls;
- using System.Windows.Data;
- 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 变量
- /// <summary>
- /// 变量管理器地址
- /// </summary>
- public string VariablePath = string.Empty;
-
- /// <summary>
- /// 是否正在运行状态
- /// </summary>
- 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");
- }
- }
-
- /// <summary>
- /// 画布是否显示
- /// </summary>
- private Visibility _CanvasPanelVisibility;
- public Visibility CanvasPanelVisibility
- {
- get
- {
- return _CanvasPanelVisibility;
- }
- set
- {
- if (_CanvasPanelVisibility == value)
- return;
- _CanvasPanelVisibility = value;
- OnPropertyChanged("CanvasPanelVisibility");
- }
- }
-
- /// <summary>
- /// 运行代码是否显示
- /// </summary>
- private Visibility _RunCanvasVisibility;
- public Visibility RunCanvasVisibility
- {
- get
- {
- return _RunCanvasVisibility;
- }
- set
- {
- if (_RunCanvasVisibility == value)
- return;
- _RunCanvasVisibility = value;
- OnPropertyChanged("RunCanvasVisibility");
- }
- }
-
- /// <summary>
- /// 当前代码Xaml
- /// </summary>
- private string _XamlCode;
- public string XamlCode
- {
- get
- {
- return _XamlCode;
- }
- set
- {
- if (_XamlCode == value)
- return;
- _XamlCode = value;
- OnPropertyChanged("XamlCode");
- }
- }
-
- /// <summary>
- /// 选中控件
- /// </summary>
- private FrameworkElement _CanSelectedItem;
- public FrameworkElement CanSelectedItem
- {
- get
- {
- return _CanSelectedItem;
- }
- set
- {
- if (_CanSelectedItem == value)
- return;
- _CanSelectedItem = value;
- OnPropertyChanged("CanSelectedItem");
- }
- }
-
- /// <summary>
- /// 设备名称集合
- /// </summary>
- private ObservableCollection<string> _DevNameList;
- public ObservableCollection<string> DevNameList
- {
- get
- {
- return _DevNameList;
- }
- set
- {
- _DevNameList = value;
- OnPropertyChanged("DevNameList");
- }
- }
-
- /// <summary>
- /// 设备变量集合
- /// </summary>
- private ObservableCollection<string> _DevValueList;
- public ObservableCollection<string> DevValueList
- {
- get
- {
- return _DevValueList;
- }
- set
- {
- _DevValueList = value;
- OnPropertyChanged("DevValueList");
- }
- }
- #endregion
-
- #region 命令
- /// <summary>
- /// 启动或者停止
- /// </summary>
- public RelayCommand RunUiCommand { get; set; }
- /// <summary>
- /// 编辑
- /// </summary>
- public RelayCommand EditCommand { get; set; }
- #endregion
-
- #region 常用函数
- /// <summary>
- /// 显示当前xaml代码
- /// </summary>
- public void ShowCode(TextEditor textEditor)
- {
- textEditor.Text = canvasPanel.Save();
- }
- #endregion
-
- #region 脚本编辑数据
- /// <summary>
- /// 当前编辑界面
- /// </summary>
- public CanvasPanel canvasPanel;
- /// <summary>
- /// 当前运行界面
- /// </summary>
- public RunCanvas runCanvas;
-
- /// <summary>
- /// 加载
- /// </summary>
- /// <param name="obj"></param>
- public void Loaded(object objCan, object objRun)
- {
- canvasPanel = objCan as CanvasPanel;
-
- runCanvas = objRun as RunCanvas;
- }
-
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="obj"></param>
- 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;
- }
-
- /// <summary>
- /// 子控件编辑
- /// </summary>
- /// <param name="obj"></param>
- public void ChildEdit(object obj)
- {
- string xml = ChildEditWindow.ShowEdit(((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).Value?.ToString());
- ((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).Value = xml;
- }
-
- /// <summary>
- /// 绑定编辑
- /// </summary>
- /// <param name="obj"></param>
- public void BingEdit(object obj)
- {
- //父控件
- Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid _property = (Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid)((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).ParentElement;
- //选中控件
- string controlname = _property.SelectedObjectName;//名称
- Type type = _property.SelectedObjectType;//类型
- object selectpro = _property.SelectedProperty;
-
-
- object selectControl= _property.SelectedObject;//对象
- string selectProName= _property.SelectedProperty.ToString();
-
- //选中属性
- DependencyProperty dependencyProperty = PropertyHelper.GetDependencyProperties(selectControl)?.ToList().Find(x => x.Name == selectProName);
- if (dependencyProperty != null)
- {
- string _binding = PropertyBindingWindow.ShowEdit(dependencyProperty, (selectControl as FrameworkElement));
- if (!string.IsNullOrEmpty(_binding))
- {
- Binding bindingText = new Binding() { Mode = BindingMode.TwoWay, Path = new PropertyPath(_binding) };
- (selectControl as FrameworkElement).SetBinding(dependencyProperty, bindingText);
- }
- else
- {
- BindingOperations.ClearBinding((selectControl as FrameworkElement), dependencyProperty);
- }
- }
- }
-
- /// <summary>
- /// 清除绑定
- /// </summary>
- /// <param name="obj"></param>
- public void ClearBingEdit(object obj)
- {
- //父控件
- Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid _property = (Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid)((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).ParentElement;
- //选中控件
- string controlname = _property.SelectedObjectName;//名称
- Type type = _property.SelectedObjectType;//类型
- object selectpro = _property.SelectedProperty;
-
-
- object selectControl = _property.SelectedObject;//对象
- string selectProName = _property.SelectedProperty.ToString();
-
- //选中属性
- DependencyProperty dependencyProperty = PropertyHelper.GetDependencyProperties(selectControl)?.ToList().Find(x => x.Name == selectProName);
- if (dependencyProperty != null)
- {
- BindingOperations.ClearBinding((selectControl as FrameworkElement), dependencyProperty);
- }
- }
-
- /// <summary>
- /// 图片选择路径
- /// </summary>
- /// <param name="obj"></param>
- 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
-
-
- }
- }
|