Bläddra i källkod

更新

样式分支
fyf 2 år sedan
förälder
incheckning
b553414ee6
7 ändrade filer med 216 tillägg och 40 borttagningar
  1. +8
    -2
      BPASmartClient.DATABUS/Class_DataBus.cs
  2. +13
    -1
      BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml.cs
  3. +83
    -32
      BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs
  4. +2
    -1
      BPASmartClient.SCADAControl/Themes/Generic.xaml
  5. +2
    -4
      BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs
  6. +84
    -0
      BeDesignerSCADA/ViewModel/DataBusModel.cs
  7. +24
    -0
      BeDesignerSCADA/ViewModel/MainViewModelNew.cs

+ 8
- 2
BPASmartClient.DATABUS/Class_DataBus.cs Visa fil

@@ -32,7 +32,14 @@ namespace BPASmartClient.DATABUS
/// <summary>
/// API数据
/// </summary>
public ConcurrentDictionary<string,string> Dic_APIData = new ConcurrentDictionary<string,string>();
public ConcurrentDictionary<string,string> Dic_APIData = new ConcurrentDictionary<string,string>();
#endregion

#region 配置数据


//Json<CommunicationPar>.Read();
#endregion
}

@@ -42,7 +49,6 @@ namespace BPASmartClient.DATABUS
public string VarName { get; set; }
public string VarVaule { get; set; }
public string DataType { get; set; }

}

}

+ 13
- 1
BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml.cs Visa fil

@@ -88,7 +88,6 @@ namespace BPASmartClient.SCADAControl.CustomerControls
if (IsExecuteState)
{
Register();
//Style = null;
}
}
}
@@ -301,6 +300,19 @@ namespace BPASmartClient.SCADAControl.CustomerControls
public static readonly DependencyProperty CodeProperty =
DependencyProperty.Register("Code",typeof(string),typeof(TheAPI),new PropertyMetadata(_code));
[Category("数据绑定")]
public bool IsRun
{
get { return (bool)GetValue(RunProperty); }
set { SetValue(RunProperty, value); }
}
public static readonly DependencyProperty RunProperty =
DependencyProperty.Register("IsRun", typeof(bool), typeof(TheAPI), new PropertyMetadata(false, new PropertyChangedCallback(onIsRunChanged)));
private static void onIsRunChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as TheAPI)?.IsRunRefresh();
public void IsRunRefresh()
{
//测试运行
}
[Category("数据绑定")]
public string GenerateData
{
get { return (string)GetValue(GenerateDataProperty); }


+ 83
- 32
BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs Visa fil

@@ -33,23 +33,34 @@ namespace BPASmartClient.SCADAControl.CustomerControls
public TheDataGrid()
{
InitializeComponent();
ResourceDictionary languageResDic = new ResourceDictionary();
languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
this.Resources.MergedDictionaries.Add(languageResDic);
//MinWidth = 100;
//MinHeight = 100;
//Width = 100;
//Height = 100;
//ResourceDictionary languageResDic = new ResourceDictionary();
//languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml", UriKind.RelativeOrAbsolute);
//this.Resources.MergedDictionaries.Add(languageResDic);
MinWidth = 100;
MinHeight = 100;
Width = 100;
Height = 100;
this.Loaded += TheDataGrid_Loaded; ;
}

public DataSouceModel ItemsString
private void TheDataGrid_Loaded(object sender, RoutedEventArgs e)
{
get { return (DataSouceModel)GetValue(ItemsStringProperty); }
set { SetValue(ItemsStringProperty,value); }
TabItems.CollectionChanged += TabItems_CollectionChanged;
}

public static readonly DependencyProperty ItemsStringProperty =
DependencyProperty.Register("ItemsString",typeof(DataSouceModel),typeof(TheDataGrid),new PropertyMetadata(new DataSouceModel()));
private void TabItems_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (TabItems.Count > 0)
{
try
{
TabItemsStr = JsonConvert.SerializeObject(TabItems);
}
catch (Exception ex)
{
}
}
}

public string ControlType => "控件";

@@ -67,12 +78,24 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
}
}

DispatcherTimer timer = new DispatcherTimer();
/// <summary>
/// 注册需要处理的事件
/// </summary>
public void Register()
{
if (!string.IsNullOrEmpty(TabItemsStr))
{
try
{
TabItems = JsonConvert.DeserializeObject<ObservableCollection<列显示设置>>(TabItemsStr);
}
catch (Exception ex)
{

}
}

if (DataSouceType == DataTypeEnum.API接口)
{
@@ -95,6 +118,22 @@ namespace BPASmartClient.SCADAControl.CustomerControls


#region 数据绑定模块
[Category("名称[自动生成]")]
private string TabItemsStr
{
get { return (string)GetValue(TabItemsStrProperty); }
set { SetValue(TabItemsStrProperty, value); }
}
private static readonly DependencyProperty TabItemsStrProperty =
DependencyProperty.Register("TabItemsStr", typeof(string), typeof(TheDataGrid), new PropertyMetadata(string.Empty));
[Category("集合")]
public ObservableCollection<列显示设置> TabItems
{
get { return (ObservableCollection<列显示设置>)GetValue(TabItemsProperty); }
set { SetValue(TabItemsProperty, value); }
}
private static readonly DependencyProperty TabItemsProperty =
DependencyProperty.Register("TabItems", typeof(ObservableCollection<列显示设置>), typeof(TheDataGrid), new PropertyMetadata(new ObservableCollection<列显示设置>()));
public event EventHandler PropertyChange; //声明一个事件
[Category("数据绑定-数据来源")]
public DataTypeEnum DataSouceType
@@ -119,9 +158,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
set { SetValue(DataSouceInformationProperty,value); }
}
public static readonly DependencyProperty DataSouceInformationProperty =
DependencyProperty.Register("DataSouceInformation",typeof(string),typeof(TheDataGrid),new PropertyMetadata(string.Empty));


DependencyProperty.Register("DataSouceInformation",typeof(string),typeof(TheDataGrid),new PropertyMetadata("api0"));
[Category("数据绑定")]
public string FDataSouce
{
@@ -173,14 +210,17 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
try
{
//Dictionary<string, object> keys= JsonConvert.DeserializeObject<Dictionary<string, object>>(GenerateData);
//List<Dictionary<string, object>> obj2 = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(keys["data"].ToString());
ItemsString = JsonConvert.DeserializeObject<DataSouceModel>(GenerateData);
Dictionary<string, object> keys= JsonConvert.DeserializeObject<Dictionary<string, object>>(GenerateData);
List<Dictionary<string, object>> obj2 = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(keys["data"].ToString());
//ItemsString = JsonConvert.DeserializeObject<DataSouceModel>(GenerateData);
// 运行时进行项目绑定
Binding binding = new Binding();
binding.RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.Self };
binding.Path = new PropertyPath("ItemsString.data");
SetBinding(ItemsSourceProperty,binding);
//this.AutoGenerateColumns = false;
this.CanUserAddRows = false;
this.CanUserDeleteRows = false;
this.RowHeaderWidth = 0;
this.GridLinesVisibility = DataGridGridLinesVisibility.None;
//this.BorderThickness = new Thickness(0);
this.ItemsSource = ListToDataTable(obj2).DefaultView;
}
catch (Exception ex)
{
@@ -198,6 +238,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls
{
if (arrayList.Count > 0)
{

foreach (Dictionary<string, object> dictionary in arrayList)
{
if (dictionary.Keys.Count<string>() == 0)
@@ -205,20 +247,31 @@ namespace BPASmartClient.SCADAControl.CustomerControls
result = dataTable;
return result;
}

if (TabItems == null || TabItems.Count == 0)
{
foreach (string current in dictionary.Keys)
{
TabItems.Add(new 列显示设置 { 列标题 = current, 是否显示 = true, 显示名称 = current });
}
}

//在第一次循环时确定datatable的列名,后续循环无需再更改
if (dataTable.Columns.Count == 0)
{
//此处仅考虑一层json字符串的形式,多层结构需要深入得到叶子节点的key
foreach (string current in dictionary.Keys)
foreach (var current in TabItems)
{
dataTable.Columns.Add(current);//, dictionary[current].GetType());
if(current.是否显示)
dataTable.Columns.Add(current.显示名称);//, dictionary[current].GetType());
}
}
//每次循环增加datatable的Rows
DataRow dataRow = dataTable.NewRow();
foreach (string current in dictionary.Keys)
foreach (var current in TabItems)
{
dataRow[current] = dictionary[current];
if (current.是否显示)
dataRow[current.显示名称] = dictionary[current.列标题];
}
dataTable.Rows.Add(dataRow); //循环添加行到DataTable中
}
@@ -235,12 +288,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls

}

public class DataSouceModel
public class 列显示设置
{
public List<object> data {get; set; }
public DataSouceModel()
{
data = new List<object>();
}
public string 列标题 { get; set; }
public string 显示名称 { get; set; }
public bool 是否显示 { get; set; }
}
}

+ 2
- 1
BPASmartClient.SCADAControl/Themes/Generic.xaml Visa fil

@@ -1137,10 +1137,11 @@
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Foreground" Value="#abf4ff" />
<Setter Property="BorderBrush" Value="#abf4ff" />
<Setter Property="FontSize" Value="10" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">


+ 2
- 4
BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs Visa fil

@@ -35,7 +35,7 @@ namespace BeDesignerSCADA.Controls
/// 布局文件路径
/// </summary>
public string Path=string.Empty;
public string VariablePath = string.Empty;
MainViewModelNew viewModel = new MainViewModelNew();
public MainCanvasPanel(string _Path)
{
@@ -60,7 +60,6 @@ namespace BeDesignerSCADA.Controls
// var controls = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o => o.Name);
// CtlList.ItemsSource = controls;
//}

#region 位置调整
/// <summary>
/// 左对齐
@@ -182,7 +181,6 @@ namespace BeDesignerSCADA.Controls
{
cav.Load(path);


DoubleAnimation da = new DoubleAnimation(-200, 0, new Duration(TimeSpan.FromMilliseconds(250)));
da.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
CanvasTranslate.BeginAnimation(TranslateTransform.XProperty, da);
@@ -212,7 +210,7 @@ namespace BeDesignerSCADA.Controls
{
try
{
VariablePath = path;
viewModel.VariablePath = path;
}
catch (Exception ex)
{


+ 84
- 0
BeDesignerSCADA/ViewModel/DataBusModel.cs Visa fil

@@ -0,0 +1,84 @@
using BPASmart.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeDesignerSCADA.ViewModel
{
public class DataBusModel
{
#region 单例模式
public static DataBusModel dataBus = null;

public static DataBusModel GetInstance()
{
if (dataBus == null)
{
dataBus = new DataBusModel();
}
return dataBus;
}
#endregion

#region 变量
/// <summary>
/// 变量地址保存
/// key:地址
/// value:变量
/// </summary>
private ConcurrentDictionary<string, CommunicationPar> _KeyValues { get; set; } = new ConcurrentDictionary<string, CommunicationPar>();
public ConcurrentDictionary<string, CommunicationPar> KeyValues
{
get
{
return _KeyValues;
}
set
{
_KeyValues = value;

}
}
#endregion
/// <summary>
/// 刷新界面
/// </summary>
public Action<string> RefreshTheVariableManagerAction;
/// <summary>
/// 刷新界面管理器
/// </summary>
/// <param name="path"></param>
public bool RefreshVariableManager(string path="")
{
bool IsSucess=false;
try
{
if (File.Exists(path))
{
CommunicationPar val = JsonConvert.DeserializeObject<CommunicationPar>(File.ReadAllText(path));
if (val != null)
{
if (KeyValues == null)
{
KeyValues = new ConcurrentDictionary<string, CommunicationPar>();
}
KeyValues[path] = val;
RefreshTheVariableManagerAction?.Invoke(path);
IsSucess = true;
}
}
}
catch (Exception ex)
{

}
return IsSucess;
}

}
}

+ 24
- 0
BeDesignerSCADA/ViewModel/MainViewModelNew.cs Visa fil

@@ -35,9 +35,15 @@ namespace BeDesignerSCADA.ViewModel
{
IsRunning = !IsRunning;
});
DataBusModel.GetInstance().RefreshTheVariableManagerAction += RefreshTheVariableManagerActionHader;
}

#region 变量
/// <summary>
/// 变量管理器地址
/// </summary>
public string VariablePath = string.Empty;

/// <summary>
/// 是否正在运行状态
/// </summary>
@@ -195,6 +201,24 @@ namespace BeDesignerSCADA.ViewModel
{
textEditor.Text = canvasPanel.Save();
}
/// <summary>
/// 刷新变量
/// </summary>
/// <param name="path"></param>
public void RefreshTheVariableManagerActionHader(string path)
{
try
{
if (path == VariablePath && !string.IsNullOrEmpty(VariablePath))
{
}
}
catch (Exception ex)
{

}
}
#endregion

#region 脚本编辑数据


Laddar…
Avbryt
Spara