@@ -0,0 +1,43 @@ | |||
<Application | |||
x:Class="BPASmart.DataServer.App" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:con="clr-namespace:BPASmartClient.CustomResource.Converters;assembly=BPASmartClient.CustomResource" | |||
xmlns:local="clr-namespace:BPASmart.DataServer"> | |||
<Application.Resources> | |||
<ResourceDictionary> | |||
<ResourceDictionary.MergedDictionaries> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/RecCheckBox.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/RecTitleBarButton.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/GlobalStyle.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/RecComboBox.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/RecIcoButtonStyle.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/RecToggleButton.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/BeveledRadioButtonStyle.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/DatePickeerDictionary.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/RecButtonStyle.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/TextBoxStyle.xaml" /> | |||
<ResourceDictionary> | |||
<con:ColorConverter x:Key="ColorConverter" /> | |||
<con:TextConverter x:Key="TextConverter" /> | |||
<con:VisibleTypeConverter x:Key="VisibleTypeConverter" /> | |||
<con:StatusConverter x:Key="StatusConverter" /> | |||
<con:StringToIconConverter x:Key="StringToIconConverter" /> | |||
<!--<locaCon:DataTableRedundantConverter x:Key="tabConvert" /> | |||
<locaCon:TextDisplayConvert x:Key="textDisplayConvert" /> | |||
<locaCon:DiscreteAlarmConvert x:Key="discreteAlarmConvert" /> | |||
<locaCon:AnalogAlarmConvert x:Key="analogAlarmConvert" /> | |||
<locaCon:IsEnableConvert x:Key="IsEnableConvert" />--> | |||
<SolidColorBrush x:Key="PoupTextblockColor" Color="#009dff" /> | |||
<SolidColorBrush x:Key="tabColor" Color="#FF2AB2E7" /> | |||
<SolidColorBrush x:Key="bordColor" Color="#332AB2E7" /> | |||
</ResourceDictionary> | |||
</ResourceDictionary.MergedDictionaries> | |||
</ResourceDictionary> | |||
</Application.Resources> | |||
</Application> |
@@ -0,0 +1,94 @@ | |||
using BPASmartClient.CustomResource.Pages.Enums; | |||
using BPASmartClient.CustomResource.Pages.Model; | |||
using BPASmartClient.CustomResource.Pages.View; | |||
using BPASmartClient.Helper; | |||
using BPASmartClient.Model; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.Configuration; | |||
using System.Data; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
using BPASmart.Server; | |||
using BPASmartClient.CustomResource.Pages.ViewModel; | |||
namespace BPASmart.DataServer | |||
{ | |||
/// <summary> | |||
/// Interaction logic for App.xaml | |||
/// </summary> | |||
public partial class App : Application | |||
{ | |||
public static Window MainWindow; | |||
protected override void OnStartup(StartupEventArgs e) | |||
{ | |||
base.OnStartup(e); | |||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; | |||
MenuInit(); | |||
MainView mv = new MainView(); | |||
mv.WindowState = WindowState.Normal; | |||
MainWindow = mv; | |||
mv.Show(); | |||
BPASmart.Server.Main.GetInstance.Init(); | |||
} | |||
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) | |||
{ | |||
//数据服务中心异常退出后自动重启 | |||
} | |||
protected override void OnExit(ExitEventArgs e) | |||
{ | |||
base.OnExit(e); | |||
} | |||
private void MenuInit() | |||
{ | |||
#region 消息中心 | |||
ObservableCollection<SubMenumodel> InfoLog = new ObservableCollection<SubMenumodel>(); | |||
InfoLog.Add(new SubMenumodel() | |||
{ | |||
SubMenuName = "消息日志", | |||
AssemblyName = "BPASmartClient.CustomResource", | |||
ToggleWindowPath = "Pages.View.DebugLogView", | |||
SubMenuVisibility = Visibility.Visible, | |||
}); | |||
MenuManage.GetInstance.menuModels.Add(new MenuModel() | |||
{ | |||
MainMenuIcon = "", | |||
MainMenuName = "消息中心", | |||
Alias = "Device Management", | |||
subMenumodels = InfoLog, | |||
}); | |||
#endregion | |||
} | |||
private SubMenumodel AddSubMenuModel(string s) | |||
{ | |||
return new SubMenumodel() | |||
{ | |||
SubMenuName = s, | |||
AssemblyName = "BPASmart.VariableManager", | |||
ToggleWindowPath = "Views.VariableConfig", | |||
SubMenuVisibility = Visibility.Visible, | |||
}; | |||
} | |||
private void DataSave() | |||
{ | |||
} | |||
private void DataRead() | |||
{ | |||
Json<CommunicationPar>.Read(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,10 @@ | |||
using System.Windows; | |||
[assembly: ThemeInfo( | |||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | |||
//(used if a resource is not found in the page, | |||
// or application resource dictionaries) | |||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | |||
//(used if a resource is not found in the page, | |||
// app, or any theme specific resource dictionaries) | |||
)] |
@@ -0,0 +1,15 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<OutputType>WinExe</OutputType> | |||
<TargetFramework>net6.0-windows</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<UseWPF>true</UseWPF> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmart.Server\BPASmart.Server.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.CustomResource\BPASmartClient.CustomResource.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +1,4 @@ | |||
using BPASmart.VariableManager.Enums; | |||
using BPASmart.Model; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
@@ -8,29 +8,19 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Models | |||
namespace BPASmart.Model | |||
{ | |||
public class AlarmSet : NoticeBase | |||
{ | |||
public AlarmSet() | |||
{ | |||
AnalogAlarmModels.Clear(); | |||
foreach (var item in Enum.GetNames(typeof(EAnalogAlarmType))) | |||
{ | |||
AnalogAlarmModels.Add(new AnalogAlarmModel() | |||
{ | |||
AlarmTag = item, | |||
SortTag = (EAnalogAlarmType)Enum.Parse(typeof(EAnalogAlarmType), item) | |||
}); | |||
} | |||
} | |||
/// <summary> | |||
/// 报警标签 | |||
/// </summary> | |||
public string AlarmTag { get { return _mAlarmTag; } set { _mAlarmTag = value; OnPropertyChanged(); } } | |||
private string _mAlarmTag = string.Empty; | |||
public EAlarmType AlarmType { get { return _mAlarmType; } set { _mAlarmType = value; OnPropertyChanged(); } } | |||
private EAlarmType _mAlarmType; | |||
/// <summary> | |||
/// 模拟量报警信息 | |||
/// </summary> | |||
@@ -42,9 +32,5 @@ namespace BPASmart.VariableManager.Models | |||
public DiscreteAlarmInfo DiscreteAlarmInfoSet { get { return _mDiscreteAlarmInfoSet; } set { _mDiscreteAlarmInfoSet = value; OnPropertyChanged(); } } | |||
private DiscreteAlarmInfo _mDiscreteAlarmInfoSet = new DiscreteAlarmInfo(); | |||
} | |||
} |
@@ -1,4 +1,4 @@ | |||
using BPASmart.VariableManager.Enums; | |||
using BPASmart.Model; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel.DataAnnotations; | |||
@@ -7,7 +7,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Models | |||
namespace BPASmart.Model | |||
{ | |||
/// <summary> | |||
/// 模拟量报警模块 |
@@ -0,0 +1,15 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
<Nullable>enable</Nullable> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" /> | |||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | |||
<PackageReference Include="System.IO.Ports" Version="6.0.0" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,66 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.Model | |||
{ | |||
public class AddressConvert | |||
{ | |||
private volatile static AddressConvert _Instance; | |||
public static AddressConvert GetInstance => _Instance ?? (_Instance = new AddressConvert()); | |||
private AddressConvert() { } | |||
public int PlcConverter(ICommunicationDevice device, string Address) | |||
{ | |||
int address = -1; | |||
if (Address != null && int.TryParse(Address, out int result)) return result; | |||
if (device != null && Address != null && Address.Length > 0) | |||
{ | |||
switch (device) | |||
{ | |||
case Invoance _tempInvoance: | |||
if (Address.ToUpper().Contains("LW") && Address.Length >= 3) | |||
{ | |||
var res = Address.Substring(2); | |||
if (res != null && int.TryParse(res, out int LwAddress)) return LwAddress; | |||
} | |||
break; | |||
case kinco _tempKinco: | |||
if (Address.ToUpper().Contains("M") && Address.Length >= 4) | |||
{ | |||
var res = Address.Substring(1).Split('.'); | |||
if (res != null && res.Length == 2) | |||
{ | |||
if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress)) | |||
{ | |||
if (ExitAddress >= 0 && ExitAddress <= 7) | |||
{ | |||
return (firstAddress * 8) + 320 + ExitAddress; | |||
} | |||
} | |||
} | |||
} | |||
else if ((Address.ToUpper().Contains("VW") || Address.ToUpper().Contains("VD")) && Address.Length >= 3) | |||
{ | |||
var res = Address.Substring(2); | |||
if (res != null && int.TryParse(res, out int tempAddress)) return (tempAddress / 2) + 100; | |||
} | |||
break; | |||
case KincoOneMachine _tempKincoOneMachine: | |||
if (Address.ToUpper().Contains("D") && Address.Length >= 2) | |||
{ | |||
var res = Address.Substring(1); | |||
if (res != null && int.TryParse(res, out int LwAddress)) return LwAddress; | |||
} | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
return address; | |||
} | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.Model | |||
{ | |||
/// <summary> | |||
/// 汇川PLC | |||
/// </summary> | |||
public class Invoance : ModbusTcp | |||
{ | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.Model | |||
{ | |||
/// <summary> | |||
/// 步科一体机 | |||
/// </summary> | |||
public class KincoOneMachine : ModbusTcp | |||
{ | |||
} | |||
} |
@@ -0,0 +1,47 @@ | |||
using BPASmart.Model; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.IO.Ports; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
namespace BPASmart.Model | |||
{ | |||
public class ModbusRtu : ICommunicationDevice | |||
{ | |||
/// <summary> | |||
/// 串口端口 | |||
/// </summary> | |||
public string ComSerialPort { get; set; } | |||
/// <summary> | |||
/// 波特率,110,300--115200(从300开始乘以2,直到结果等于115200) | |||
/// </summary> | |||
public string BaudRate { get; set; } = "9600"; | |||
/// <summary> | |||
/// 数据位,默认为 8 | |||
/// </summary> | |||
public int DataBit { get; set; } = 8; | |||
/// <summary> | |||
/// 停止位,默认为 1 | |||
/// </summary> | |||
public int StopBit { get; set; } = 1; | |||
/// <summary> | |||
/// 站号,默认为 1 | |||
/// </summary> | |||
public int StationNo { get; set; } = 1; | |||
/// <summary> | |||
/// 奇偶校验,无,奇校验,偶校验 | |||
/// </summary> | |||
public string Parity { get; set; } | |||
} | |||
} |
@@ -5,14 +5,10 @@ using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
namespace BPASmart.VariableManager.Models | |||
namespace BPASmart.Model | |||
{ | |||
public class ModbusTcp : ICommunicationDevice | |||
{ | |||
/// <summary> | |||
/// 显示/隐藏设置 | |||
/// </summary> | |||
//public Visibility ModbusTcpVisible { get; set; } = Visibility.Collapsed; | |||
/// <summary> | |||
/// IP地址 |
@@ -1,4 +1,4 @@ | |||
using BPASmart.VariableManager.Enums; | |||
using BPASmart.Model; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
@@ -7,19 +7,10 @@ using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
namespace BPASmart.VariableManager.Models | |||
namespace BPASmart.Model | |||
{ | |||
public class Siemens : ICommunicationDevice | |||
{ | |||
//public Siemens() | |||
//{ | |||
// Init(); | |||
//} | |||
/// <summary> | |||
/// 显示/隐藏设置 | |||
/// </summary> | |||
//public Visibility SiemensVisible { get; set; } = Visibility.Collapsed; | |||
/// <summary> | |||
/// IP地址 | |||
@@ -46,18 +37,6 @@ namespace BPASmart.VariableManager.Models | |||
/// </summary> | |||
public string PlcType { get; set; } | |||
//public ObservableCollection<string> PlcTypes { get; set; } = new ObservableCollection<string>(); | |||
//private void Init() | |||
//{ | |||
// PlcTypes.Clear(); | |||
// foreach (var item in Enum.GetNames(typeof(ESiemensPlcType))) | |||
// { | |||
// PlcTypes.Add(item.Substring(1)); | |||
// } | |||
//} | |||
} | |||
@@ -0,0 +1,15 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.Model | |||
{ | |||
/// <summary> | |||
/// 步科PLC | |||
/// </summary> | |||
public class kinco : ModbusTcp | |||
{ | |||
} | |||
} |
@@ -7,7 +7,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Models | |||
namespace BPASmart.Model | |||
{ | |||
public class CommunicationModel : NoticeBase | |||
{ | |||
@@ -33,6 +33,12 @@ namespace BPASmart.VariableManager.Models | |||
public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } } | |||
private string _mDeviceName; | |||
/// <summary> | |||
/// 通讯模块名称 | |||
/// </summary> | |||
public string ModelName { get { return _mModelName; } set { _mModelName = value; OnPropertyChanged(); } } | |||
private string _mModelName; | |||
/// <summary> | |||
/// 变量表数据 | |||
/// </summary> |
@@ -5,9 +5,9 @@ using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Collections.ObjectModel; | |||
namespace BPASmart.VariableManager.Models | |||
namespace BPASmart.Model | |||
{ | |||
internal class CommunicationPar | |||
public class CommunicationPar | |||
{ | |||
public ObservableCollection<CommunicationModel> CommunicationDevices { get; set; } = new ObservableCollection<CommunicationModel>(); | |||
} |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Models | |||
namespace BPASmart.Model | |||
{ | |||
public class DelegationNotifi | |||
{ | |||
@@ -37,10 +37,5 @@ namespace BPASmart.VariableManager.Models | |||
/// </summary> | |||
public Action<int> VarNameChanged { get; set; } | |||
/// <summary> | |||
/// 页面名称 | |||
/// </summary> | |||
public Action<string> PageName { get; set; } | |||
} | |||
} |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Models | |||
namespace BPASmart.Model | |||
{ | |||
public class DeviceManagermentResult | |||
{ |
@@ -5,9 +5,9 @@ using System.ComponentModel.DataAnnotations.Schema; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using BPASmart.VariableManager.Enums; | |||
using BPASmart.Model; | |||
namespace BPASmart.VariableManager.Models | |||
namespace BPASmart.Model | |||
{ | |||
/// <summary> | |||
/// 离散量报警信息 |
@@ -4,9 +4,9 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Enums | |||
namespace BPASmart.Model | |||
{ | |||
internal enum DisplayFormat | |||
public enum DisplayFormat | |||
{ | |||
二进制, | |||
十进制, |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Enums | |||
namespace BPASmart.Model | |||
{ | |||
/// <summary> | |||
/// 报警类型 |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Enums | |||
namespace BPASmart.Model | |||
{ | |||
/// <summary> | |||
/// 沿触发类型枚举 |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Enums | |||
namespace BPASmart.Model | |||
{ | |||
/// <summary> | |||
/// 模拟量报警类型 |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Enums | |||
namespace BPASmart.Model | |||
{ | |||
/// <summary> | |||
/// 数据类型枚举 |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Enums | |||
namespace BPASmart.Model | |||
{ | |||
public enum EDeviceType | |||
{ |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Enums | |||
namespace BPASmart.Model | |||
{ | |||
/// <summary> | |||
/// 判断操作符枚举 |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Enums | |||
namespace BPASmart.Model | |||
{ | |||
public enum EParity | |||
{ |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Enums | |||
namespace BPASmart.Model | |||
{ | |||
public enum ESiemensPlcType | |||
{ |
@@ -4,7 +4,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager | |||
namespace BPASmart.Model | |||
{ | |||
public interface ICommunicationDevice | |||
{ |
@@ -4,9 +4,10 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Models | |||
namespace BPASmart.Model | |||
{ | |||
public class VarTableModel : NoticeBase | |||
public interface IServer | |||
{ | |||
void Init(); | |||
} | |||
} |
@@ -7,7 +7,7 @@ using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
using System.Collections.ObjectModel; | |||
namespace BPASmart.VariableManager | |||
namespace BPASmart.Model | |||
{ | |||
public class NoticeBase : ObservableObject | |||
{ |
@@ -0,0 +1,13 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.Model | |||
{ | |||
public class PublishInfo | |||
{ | |||
public List<PublishModel> PublishModels { get; set; } = new List<PublishModel>(); | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.Model | |||
{ | |||
public class PublishModel | |||
{ | |||
public string DeviceName { get; set; } | |||
public string Address { get; set; } | |||
public string Value { get; set; } | |||
public int Sleep { get; set; } | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.Model | |||
{ | |||
public class ReadDataModel | |||
{ | |||
public ushort StartAddress { get; set; } | |||
public ushort Length { get; set; } | |||
} | |||
} |
@@ -0,0 +1,151 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel.DataAnnotations; | |||
using System.ComponentModel.DataAnnotations.Schema; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using BPASmart.Model; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using Newtonsoft.Json; | |||
using System.Collections.ObjectModel; | |||
using System.Windows; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
using System.Reflection; | |||
namespace BPASmart.Model | |||
{ | |||
public class VariableInfo : AlarmSet | |||
{ | |||
private ICommunicationDevice DeviceType; | |||
public VariableInfo(params object[] s) | |||
{ | |||
if (s != null && s.Length >= 0) | |||
{ | |||
DeviceType = s[0] as ICommunicationDevice; | |||
} | |||
CancelCommand = new RelayCommand(() => { IsOpen = false; }); | |||
ConfirmCommand = new RelayCommand(() => { IsOpen = false; }); | |||
} | |||
public int ID { get { return _mID; } set { _mID = value; OnPropertyChanged(); } } | |||
private int _mID; | |||
/// <summary> | |||
/// 变量名 | |||
/// </summary> | |||
public string VarName | |||
{ | |||
get { return _mVarName.Trim()?.Replace(" ", ""); } | |||
set | |||
{ | |||
_mVarName = value; | |||
OnPropertyChanged(); | |||
DelegationNotifi.GetInstance.VarNameChanged?.Invoke(_mID); | |||
} | |||
} | |||
private string _mVarName = string.Empty; | |||
/// <summary> | |||
/// 地址 | |||
/// </summary> | |||
public string Address | |||
{ | |||
get { return _mAddress.Trim()?.Replace(" ", "").ToUpper(); } | |||
set | |||
{ | |||
_mAddress = value; | |||
OnPropertyChanged(); | |||
int address = AddressConvert.GetInstance.PlcConverter(DeviceType, value); | |||
if (address >= 0) RealAddress = address; | |||
} | |||
} | |||
private string _mAddress = string.Empty; | |||
/// <summary> | |||
/// 实际地址 | |||
/// </summary> | |||
public int RealAddress { get; set; } | |||
/// <summary> | |||
/// 数据类型 | |||
/// </summary> | |||
public string DataType { get { return _mDataType; } set { _mDataType = value; OnPropertyChanged(); } } | |||
private string _mDataType = string.Empty; | |||
/// <summary> | |||
/// 是否启用报警 | |||
/// </summary> | |||
public bool IsEnableAlarm { get { return _mIsEnableAlarm; } set { _mIsEnableAlarm = value; OnPropertyChanged(); } } | |||
private bool _mIsEnableAlarm; | |||
/// <summary> | |||
/// 是否显示报警设置框 | |||
/// </summary> | |||
public bool IsOpen | |||
{ | |||
get { return _mIsOpen; } | |||
set | |||
{ | |||
_mIsOpen = value; | |||
OnPropertyChanged(); | |||
if (value) | |||
{ | |||
if (DataType != "Bool") | |||
{ | |||
AlarmType = EAlarmType.模拟量报警; | |||
if (AnalogAlarmModels == null || AnalogAlarmModels.Count <= 0) | |||
{ | |||
AnalogAlarmModels.Clear(); | |||
foreach (var item in Enum.GetNames(typeof(EAnalogAlarmType))) | |||
{ | |||
if (AnalogAlarmModels.FirstOrDefault(p => p.AlarmTag == item) == null) | |||
{ | |||
AnalogAlarmModels.Add(new AnalogAlarmModel() | |||
{ | |||
AlarmTag = item, | |||
SortTag = (EAnalogAlarmType)Enum.Parse(typeof(EAnalogAlarmType), item) | |||
}); | |||
} | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
AlarmType = EAlarmType.离散量报警; | |||
} | |||
} | |||
} | |||
} | |||
private bool _mIsOpen; | |||
/// <summary> | |||
/// 当前值 | |||
/// </summary> | |||
[Newtonsoft.Json.JsonIgnore] | |||
public string CurrentValue { get { return _mCurrentValue; } set { _mCurrentValue = value; OnPropertyChanged(); } } | |||
private string _mCurrentValue = string.Empty; | |||
/// <summary> | |||
/// 验证是否OK | |||
/// </summary> | |||
public bool IsRedundant { get { return _mIsRedundant; } set { _mIsRedundant = value; OnPropertyChanged(); } } | |||
private bool _mIsRedundant; | |||
/// <summary> | |||
/// 报警设置框取消操作 | |||
/// </summary> | |||
[Newtonsoft.Json.JsonIgnore] | |||
public RelayCommand CancelCommand { get; set; } | |||
/// <summary> | |||
/// 报警设置框确认按钮 | |||
/// </summary> | |||
[Newtonsoft.Json.JsonIgnore] | |||
public RelayCommand ConfirmCommand { get; set; } | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
<Nullable>enable</Nullable> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Communication" Version="1.0.8" /> | |||
<PackageReference Include="BPA.Helper" Version="1.0.6" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmart.Model\BPASmart.Model.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.Message\BPASmartClient.Message.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,174 @@ | |||
using BPASmart.Model; | |||
using BPA.Helper; | |||
using BPA.Communication; | |||
using Microsoft.EntityFrameworkCore.Metadata.Conventions; | |||
namespace BPASmart.Server | |||
{ | |||
internal class CommunicationServer : IServer | |||
{ | |||
public void Init() | |||
{ | |||
BPASmartClient.Message.MessageLog.GetInstance.ShowDebugLog("通讯模块初始化"); | |||
Json<CommunicationPar>.Data.CommunicationDevices.ToList()?.ForEach(item => | |||
{ | |||
#region 数据加载测试 | |||
#endregion | |||
ThreadManage.GetInstance().Start(new Action(() => | |||
{ | |||
switch (item.CommDevice) | |||
{ | |||
case ModbusRtu _modbusRtu: | |||
break; | |||
case ModbusTcp _modbusTcp: | |||
ModbusTcpMaster modbusTcpMaster = new ModbusTcpMaster(); | |||
modbusTcpMaster.ConnectOk = new Action(() => | |||
{ | |||
ThreadManage.GetInstance().StartLong(new Action(() => | |||
{ | |||
GetReadDataModels(item).ToList()?.ForEach(temp => | |||
{ | |||
switch (temp.Key) | |||
{ | |||
case EDataType.Bool: | |||
temp.Value?.ForEach(value => | |||
{ | |||
var res = modbusTcpMaster.ReadCoils(value.StartAddress, value.Length); | |||
SetValue(res, item.DeviceName, value, 1); | |||
}); | |||
break; | |||
case EDataType.Byte: | |||
break; | |||
case EDataType.Int: | |||
break; | |||
case EDataType.Word: | |||
temp.Value?.ForEach(value => | |||
{ | |||
var res = modbusTcpMaster.ReadHoldingRegisters(value.StartAddress, value.Length); | |||
SetValue(res, item.DeviceName, value, 1); | |||
}); | |||
break; | |||
case EDataType.Dint: | |||
break; | |||
case EDataType.Dword: | |||
temp.Value?.ForEach(value => | |||
{ | |||
var res = modbusTcpMaster.ReadHoldingRegisters(value.StartAddress, value.Length); | |||
SetValue(res, item.DeviceName, value, 2); | |||
}); | |||
break; | |||
case EDataType.Float: | |||
temp.Value?.ForEach(value => | |||
{ | |||
var res = modbusTcpMaster.ReadHoldingRegisters(value.StartAddress, value.Length); | |||
SetValue(res, item.DeviceName, value, 2); | |||
}); | |||
break; | |||
default: | |||
break; | |||
} | |||
}); | |||
Thread.Sleep(100); | |||
}), $"{item.DeviceName} 设备数据采集"); | |||
var DeviceModel = item; | |||
}); | |||
modbusTcpMaster.IsReconnect = true; | |||
modbusTcpMaster.ModbusTcpConnect(DeviceType.kinco_PLC, _modbusTcp.IP, _modbusTcp.PortNum); | |||
break; | |||
case Siemens _siemens: | |||
break; | |||
default: | |||
break; | |||
} | |||
}), $"{item.DeviceName} 初始化连接"); | |||
}); | |||
} | |||
private void SetValue<TArray>(TArray[] arrays, string DeviceName, ReadDataModel readDataModel, ushort by) | |||
{ | |||
if (arrays != null) | |||
{ | |||
int index = Array.FindIndex(Json<CommunicationPar>.Data.CommunicationDevices.ToArray(), p => p.DeviceName == DeviceName);//获取设备所在集合位置 | |||
if (index >= 0 && index < Json<CommunicationPar>.Data.CommunicationDevices.Count) | |||
{ | |||
var tempArray = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels.ToArray(); | |||
for (int i = 0; i < arrays.Length; i++) | |||
{ | |||
int varIndex = Array.FindIndex(tempArray, p => p.RealAddress == readDataModel.StartAddress + (i * by)); | |||
if (varIndex >= 0 && varIndex < tempArray.Length) | |||
{ | |||
Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels.ElementAt(varIndex).CurrentValue = arrays[i].ToString(); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
private Dictionary<EDataType, List<ReadDataModel>> GetReadDataModels(CommunicationModel communicationModel) | |||
{ | |||
Dictionary<EDataType, List<ReadDataModel>> readDataModels = new Dictionary<EDataType, List<ReadDataModel>>(); | |||
communicationModel.VarTableModels.GroupBy(p => p.DataType)?.ToList()?.ForEach(tempVar => | |||
{ | |||
if (tempVar.Key != null && tempVar.Key.Length > 0) | |||
{ | |||
int address = tempVar.Min(p => p.RealAddress); | |||
EDataType dataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.Key); | |||
switch (dataType) | |||
{ | |||
case EDataType.Bool: | |||
case EDataType.Byte: | |||
case EDataType.Int: | |||
case EDataType.Word: | |||
if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar)); | |||
break; | |||
case EDataType.Dint: | |||
case EDataType.Dword: | |||
case EDataType.Float: | |||
if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar, 2)); | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
}); | |||
return readDataModels; | |||
} | |||
private List<ReadDataModel> GetDataGroup(IGrouping<string, VariableInfo> variableInfos, int by = 1) | |||
{ | |||
List<ReadDataModel> ReturnValue = new List<ReadDataModel>(); | |||
var res = variableInfos?.OrderBy(p => p.RealAddress).ToList(); | |||
int count = 0; | |||
if (res != null) | |||
{ | |||
int address = variableInfos.Min(p => p.RealAddress); | |||
int startAddress = address; | |||
for (int i = 0; i < res.Count; i++) | |||
{ | |||
if (res.ElementAt(i).RealAddress == address) | |||
{ | |||
count++; | |||
address += by; | |||
} | |||
else | |||
{ | |||
ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count }); | |||
count = 1; | |||
address = res.ElementAt(i).RealAddress + by; | |||
startAddress = res.ElementAt(i).RealAddress; | |||
} | |||
} | |||
ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count }); | |||
} | |||
return ReturnValue; | |||
} | |||
} | |||
} |
@@ -0,0 +1,31 @@ | |||
using BPA.Helper; | |||
using BPASmart.Model; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Reflection; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.Server | |||
{ | |||
public class Main | |||
{ | |||
private volatile static Main _Instance; | |||
public static Main GetInstance => _Instance ?? (_Instance = new Main()); | |||
private Main() { } | |||
public void Init() | |||
{ | |||
Json<CommunicationPar>.Read(); | |||
Assembly.GetExecutingAssembly().GetTypes()?.ToList()?.ForEach(item => | |||
{ | |||
if (item.GetInterfaces().Contains(typeof(IServer))) | |||
{ | |||
(Activator.CreateInstance(item) as IServer)?.Init(); | |||
} | |||
}); | |||
} | |||
} | |||
} |
@@ -1,5 +1,4 @@ | |||
using BPASmart.VariableManager.Models; | |||
using BPASmartClient.CustomResource.Pages.Enums; | |||
using BPASmartClient.CustomResource.Pages.Enums; | |||
using BPASmartClient.CustomResource.Pages.Model; | |||
using BPASmartClient.CustomResource.Pages.View; | |||
using BPASmartClient.Helper; | |||
@@ -11,6 +10,7 @@ using System.Data; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
using BPASmart.Model; | |||
namespace BPASmart.VariableManager | |||
{ | |||
@@ -23,17 +23,29 @@ namespace BPASmart.VariableManager | |||
protected override void OnStartup(StartupEventArgs e) | |||
{ | |||
base.OnStartup(e); | |||
DataRead(); | |||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; | |||
MenuInit(); | |||
MainView mv = new MainView(); | |||
mv.WindowState = WindowState.Normal; | |||
MainWindow = mv; | |||
mv.Show(); | |||
} | |||
private void MenuInit() | |||
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) | |||
{ | |||
Json<CommunicationPar>.Read(); | |||
DataSave(); | |||
} | |||
protected override void OnExit(ExitEventArgs e) | |||
{ | |||
base.OnExit(e); | |||
DataSave(); | |||
} | |||
private void MenuInit() | |||
{ | |||
#region 设备管理 | |||
ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>(); | |||
DeviceMonitor.Add(new SubMenumodel() | |||
@@ -60,6 +72,17 @@ namespace BPASmart.VariableManager | |||
RecipeManage.Add(AddSubMenuModel(o.ToString())); | |||
}), "AddCommunicationDevice"); | |||
ActionManage.GetInstance.Register(new Action<object>((o) => | |||
{ | |||
if (o != null && o is CommunicationModel menumodel) | |||
{ | |||
var res = RecipeManage.FirstOrDefault(p => p.SubMenuName == menumodel.DeviceName); | |||
if (res != null) RecipeManage.Remove(res); | |||
} | |||
}), "RemoveCommunicationDevice"); | |||
Json<CommunicationPar>.Data.CommunicationDevices?.ToList()?.ForEach(item => | |||
{ | |||
RecipeManage.Add(AddSubMenuModel(item.DeviceName)); | |||
@@ -87,6 +110,16 @@ namespace BPASmart.VariableManager | |||
}; | |||
} | |||
private void DataSave() | |||
{ | |||
Json<CommunicationPar>.Save(); | |||
} | |||
private void DataRead() | |||
{ | |||
Json<CommunicationPar>.Read(); | |||
} | |||
} | |||
} |
@@ -7,6 +7,13 @@ | |||
<UseWPF>true</UseWPF> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Compile Remove="Servers\**" /> | |||
<EmbeddedResource Remove="Servers\**" /> | |||
<None Remove="Servers\**" /> | |||
<Page Remove="Servers\**" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Remove="Resources\Fonts\iconfont.ttf" /> | |||
<None Remove="Resources\Images\HBL.png" /> | |||
@@ -22,15 +29,7 @@ | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Folder Include="Servers\" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" /> | |||
<PackageReference Include="System.IO.Ports" Version="6.0.0" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmart.Model\BPASmart.Model.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.CustomResource\BPASmartClient.CustomResource.csproj" /> | |||
</ItemGroup> | |||
@@ -5,7 +5,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows.Data; | |||
using BPASmart.VariableManager.Enums; | |||
using BPASmart.Model; | |||
namespace BPASmart.VariableManager.Converter | |||
{ | |||
/// <summary> | |||
@@ -6,7 +6,8 @@ using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
using System.Windows.Data; | |||
using BPASmart.VariableManager.Models; | |||
using BPASmart.Model; | |||
namespace BPASmart.VariableManager.Converter | |||
{ | |||
@@ -18,7 +19,8 @@ namespace BPASmart.VariableManager.Converter | |||
if (type != null && parameter != null) | |||
{ | |||
if (type.Name == parameter.ToString()) | |||
string typeName = type.BaseType.Name == "Object" ? type.Name : type.BaseType.Name; | |||
if (typeName == parameter.ToString()) | |||
return Visibility.Visible; | |||
else | |||
return Visibility.Collapsed; | |||
@@ -1,43 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel.DataAnnotations; | |||
using System.ComponentModel.DataAnnotations.Schema; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Models | |||
{ | |||
/// <summary> | |||
/// 模拟量报警信息 | |||
/// </summary> | |||
[Table(nameof(AnalogAlarmInfo))] | |||
public class AnalogAlarmInfo | |||
{ | |||
//[Key] | |||
//public int Id { get; set; } | |||
///// <summary> | |||
///// 高高报警 | |||
///// </summary> | |||
//public AnalogAlarmModel Condition_HIHI_Value { get; set; } = new AnalogAlarmModel(); | |||
///// <summary> | |||
///// 高报警 | |||
///// </summary> | |||
//public AnalogAlarmModel Condition_HI_Value { get; set; } = new AnalogAlarmModel(); | |||
///// <summary> | |||
///// 低低报警 | |||
///// </summary> | |||
//public AnalogAlarmModel Condition_LOLO_Value { get; set; } = new AnalogAlarmModel(); | |||
///// <summary> | |||
///// 低报警 | |||
///// </summary> | |||
//public AnalogAlarmModel Condition_LO_Value { get; set; } = new AnalogAlarmModel(); | |||
//[ForeignKey("AlarmSetId")] | |||
//public int AlarmSetId { get; set; } | |||
//public AlarmSet AlarmSet { get; set; } | |||
} | |||
} |
@@ -1,88 +0,0 @@ | |||
using BPASmart.VariableManager.Enums; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.IO.Ports; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
namespace BPASmart.VariableManager.Models | |||
{ | |||
public class ModbusRtu : ICommunicationDevice | |||
{ | |||
//public ModbusRtu() | |||
//{ | |||
// Init(); | |||
//} | |||
/// <summary> | |||
/// 显示/隐藏设置 | |||
/// </summary> | |||
//public Visibility ModbusRtuVisible { get; set; } = Visibility.Collapsed; | |||
/// <summary> | |||
/// 串口端口 | |||
/// </summary> | |||
public string ComSerialPort { get; set; } | |||
/// <summary> | |||
/// 波特率,110,300--115200(从300开始乘以2,直到结果等于115200) | |||
/// </summary> | |||
public string BaudRate { get; set; } = "9600"; | |||
/// <summary> | |||
/// 数据位,默认为 8 | |||
/// </summary> | |||
public int DataBit { get; set; } = 8; | |||
/// <summary> | |||
/// 停止位,默认为 1 | |||
/// </summary> | |||
public int StopBit { get; set; } = 1; | |||
/// <summary> | |||
/// 站号,默认为 1 | |||
/// </summary> | |||
public int StationNo { get; set; } = 1; | |||
/// <summary> | |||
/// 奇偶校验,无,奇校验,偶校验 | |||
/// </summary> | |||
public string Parity { get; set; } | |||
//public ObservableCollection<string> Ports { get; set; } = new ObservableCollection<string>(); | |||
//public ObservableCollection<string> BaudRates { get; set; } = new ObservableCollection<string>(); | |||
//public ObservableCollection<string> Paritys { get; set; } = new ObservableCollection<string>(); | |||
//private void Init() | |||
//{ | |||
// Ports.Clear(); | |||
// foreach (var item in SerialPort.GetPortNames()) | |||
// { | |||
// Ports.Add(item); | |||
// } | |||
// BaudRates.Clear(); | |||
// BaudRates.Add("110"); | |||
// int initValue = 300; | |||
// for (int i = 0; i < 17; i++) | |||
// { | |||
// BaudRates.Add(initValue.ToString()); | |||
// initValue *= 2; | |||
// } | |||
// Paritys.Clear(); | |||
// foreach (var item in Enum.GetNames(typeof(EParity))) | |||
// { | |||
// Paritys.Add(item); | |||
// } | |||
//} | |||
} | |||
} |
@@ -1,52 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using System.Collections.ObjectModel; | |||
using BPASmart.VariableManager.Enums; | |||
using System.IO.Ports; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
using BPASmart.VariableManager.Models; | |||
namespace BPASmart.VariableManager.Models | |||
{ | |||
public class CommunicationSet : ObservableObject | |||
{ | |||
public CommunicationSet() | |||
{ | |||
RemoveCommand = new RelayCommand<object>((o) => { if (RemoveAction != null) RemoveAction(o); }); | |||
} | |||
public Action<object> RemoveAction { get; set; } | |||
public Siemens CommSiemens { get { return _mCommSiemens; } set { _mCommSiemens = value; OnPropertyChanged(); } } | |||
private Siemens _mCommSiemens = new Siemens(); | |||
public ModbusTcp CommModbusTcp { get { return _mCommModbusTcp; } set { _mCommModbusTcp = value; OnPropertyChanged(); } } | |||
private ModbusTcp _mCommModbusTcp = new ModbusTcp(); | |||
public ModbusRtu CommModbusRtu { get { return _mCommModbusRtu; } set { _mCommModbusRtu = value; OnPropertyChanged(); } } | |||
private ModbusRtu _mCommModbusRtu = new ModbusRtu(); | |||
/// <summary> | |||
/// 是否激活 | |||
/// </summary> | |||
public bool IsActive { get { return _mIsActive; } set { _mIsActive = value; OnPropertyChanged(); } } | |||
private bool _mIsActive; | |||
/// <summary> | |||
/// 新增设备名称 | |||
/// </summary> | |||
public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } } | |||
private string _mDeviceName; | |||
public RelayCommand<object> RemoveCommand { get; set; } | |||
} | |||
} |
@@ -1,27 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
namespace BPASmart.VariableManager.Models | |||
{ | |||
public class DeviceManagment : ObservableObject | |||
{ | |||
public string Content { get { return _mContent; } set { _mContent = value; OnPropertyChanged(); } } | |||
private string _mContent; | |||
public string CommandParameter { get { return _mCommandParameter; } set { _mCommandParameter = value; OnPropertyChanged(); } } | |||
private string _mCommandParameter; | |||
public string DeviceIco { get { return _mDeviceIco; } set { _mDeviceIco = value; OnPropertyChanged(); } } | |||
private string _mDeviceIco; | |||
public RelayCommand<object> NavChangedCommand { get; set; } | |||
} | |||
} |
@@ -1,26 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Models | |||
{ | |||
public class DynamicMenu | |||
{ | |||
/// <summary> | |||
/// 通讯设备菜单管理 | |||
/// </summary> | |||
public List<DeviceManagment> CommunDeviceManagments { get; set; } = new List<DeviceManagment>(); | |||
/// <summary> | |||
/// 变量菜单管理 | |||
/// </summary> | |||
public List<DeviceManagment> VariableManagments { get; set; } = new List<DeviceManagment>(); | |||
/// <summary> | |||
/// 变量监控菜单管理 | |||
/// </summary> | |||
public List<DeviceManagment> VariableMonitors { get; set; } = new List<DeviceManagment>(); | |||
} | |||
} |
@@ -1,80 +0,0 @@ | |||
using BPASmart.VariableManager.Enums; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
using Newtonsoft.Json; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.Models | |||
{ | |||
/// <summary> | |||
/// 属性绑定信息 | |||
/// </summary> | |||
public class PropBindInfo : VariableInfo | |||
{ | |||
//public PropBindInfo() | |||
//{ | |||
// ComboBoxItemInit(); | |||
// //CancelCommand = new RelayCommand(() => { IsOpen = false; }); | |||
// //ConfirmCommand = new RelayCommand(() => { IsOpen = false; }); | |||
//} | |||
///// <summary> | |||
///// 数据类型下拉列表 | |||
///// </summary> | |||
//public ObservableCollection<string> dataType { get; set; } = new ObservableCollection<string>(); | |||
///// <summary> | |||
///// 报警类型下拉列表 | |||
///// </summary> | |||
//public ObservableCollection<string> alarmType { get; set; } = new ObservableCollection<string>(); | |||
///// <summary> | |||
///// 报警设置窗离散量报警类型 | |||
///// </summary> | |||
//public ObservableCollection<string> PopupDiscreteAlarmType { get; set; } = new ObservableCollection<string>(); | |||
///// <summary> | |||
///// 是否显示报警设置框 | |||
///// </summary> | |||
//public bool IsOpen { get { return _mIsOpen; } set { _mIsOpen = value; OnPropertyChanged(); } } | |||
//private bool _mIsOpen; | |||
//public bool IsRedundant { get { return _mIsRedundant; } set { _mIsRedundant = value; OnPropertyChanged(); } } | |||
//private bool _mIsRedundant; | |||
///// <summary> | |||
///// 报警设置框取消操作 | |||
///// </summary> | |||
//public RelayCommand CancelCommand { get; set; } | |||
///// <summary> | |||
///// 报警设置框确认按钮 | |||
///// </summary> | |||
//public RelayCommand ConfirmCommand { get; set; } | |||
///// <summary> | |||
///// 下拉列表初始化 | |||
///// </summary> | |||
//private void ComboBoxItemInit() | |||
//{ | |||
// dataType.Clear(); | |||
// alarmType.Clear(); | |||
// PopupDiscreteAlarmType.Clear(); | |||
// string[] DataTypeNames = Enum.GetNames(typeof(EDataType)); | |||
// foreach (var item in DataTypeNames) { dataType.Add(item); } | |||
// string[] AlarmTypeNames = Enum.GetNames(typeof(EAlarmType)); | |||
// foreach (var item in AlarmTypeNames) { alarmType.Add(item); } | |||
// string[] PopupAlarmTypes = Enum.GetNames(typeof(EAlongTriggerType)); | |||
// foreach (var item in PopupAlarmTypes) { PopupDiscreteAlarmType.Add(item); } | |||
//} | |||
} | |||
} |
@@ -1,44 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using BPASmart.VariableManager.Enums; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
namespace BPASmart.VariableManager.Models | |||
{ | |||
internal class VarMonitorPropInfo : VariableInfo | |||
{ | |||
public VarMonitorPropInfo() | |||
{ | |||
Init(); | |||
} | |||
/// <summary> | |||
/// 数据显示格式 | |||
/// </summary> | |||
public string DataDisplayFormat { get { return _mDataDisplayFormat; } set { _mDataDisplayFormat = value; OnPropertyChanged(); } } | |||
private string _mDataDisplayFormat; | |||
/// <summary> | |||
/// 修改值 | |||
/// </summary> | |||
public string ModifyValue { get { return _mModifyValue; } set { _mModifyValue = value; OnPropertyChanged(); } } | |||
private string _mModifyValue; | |||
public ObservableCollection<string> DisplayFormat { get; set; } = new ObservableCollection<string>(); | |||
private void Init() | |||
{ | |||
DisplayFormat.Clear(); | |||
foreach (var item in Enum.GetNames(typeof(DisplayFormat))) | |||
{ | |||
DisplayFormat.Add(item); | |||
} | |||
} | |||
} | |||
} |
@@ -1,89 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel.DataAnnotations; | |||
using System.ComponentModel.DataAnnotations.Schema; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using BPASmart.VariableManager.Models; | |||
using BPASmart.VariableManager.Enums; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using Newtonsoft.Json; | |||
using System.Collections.ObjectModel; | |||
namespace BPASmart.VariableManager.Models | |||
{ | |||
public class VariableInfo : NoticeBase | |||
{ | |||
public int ID { get { return _mID; } set { _mID = value; OnPropertyChanged(); } } | |||
private int _mID; | |||
/// <summary> | |||
/// 变量名 | |||
/// </summary> | |||
public string VarName | |||
{ | |||
get { return _mVarName; } | |||
set | |||
{ | |||
_mVarName = value; | |||
OnPropertyChanged(); | |||
DelegationNotifi.GetInstance.VarNameChanged?.Invoke(_mID); | |||
} | |||
} | |||
private string _mVarName = string.Empty; | |||
/// <summary> | |||
/// 地址 | |||
/// </summary> | |||
public string Address { get { return _mAddress; } set { _mAddress = value; OnPropertyChanged(); } } | |||
private string _mAddress = string.Empty; | |||
/// <summary> | |||
/// 数据类型 | |||
/// </summary> | |||
public string DataType { get { return _mDataType; } set { _mDataType = value; OnPropertyChanged(); } } | |||
private string _mDataType = string.Empty; | |||
/// <summary> | |||
/// 是否启用报警 | |||
/// </summary> | |||
public bool IsEnableAlarm { get { return _mIsEnableAlarm; } set { _mIsEnableAlarm = value; OnPropertyChanged(); } } | |||
private bool _mIsEnableAlarm; | |||
/// <summary> | |||
/// 当前值 | |||
/// </summary> | |||
public string CurrentValue { get { return _mCurrentValue; } set { _mCurrentValue = value; OnPropertyChanged(); } } | |||
private string _mCurrentValue = string.Empty; | |||
/// <summary> | |||
/// 验证是否OK | |||
/// </summary> | |||
public bool IsRedundant { get { return _mIsRedundant; } set { _mIsRedundant = value; OnPropertyChanged(); } } | |||
private bool _mIsRedundant; | |||
/// <summary> | |||
/// 报警设置信息 | |||
/// </summary> | |||
public AlarmSet AlarmSetProp { get { return _mAlarmSetProp; } set { _mAlarmSetProp = value; OnPropertyChanged(); } } | |||
private AlarmSet _mAlarmSetProp = new AlarmSet(); | |||
/// <summary> | |||
/// 沿报警(上升沿,下降沿) | |||
/// </summary> | |||
//public string TrigAlarm { get { return _mTrigAlarm; } set { _mTrigAlarm = value; OnPropertyChanged(); } } | |||
//private string _mTrigAlarm = string.Empty; | |||
/// <summary> | |||
/// 报警信息 | |||
/// </summary> | |||
//public string AlarmInfo { get { return _mAlarmInfo; } set { _mAlarmInfo = value; OnPropertyChanged(); } } | |||
//private string _mAlarmInfo = string.Empty; | |||
//public ObservableCollection<AnalogAlarmModel> AnalogAlarmModels { get; set; } = new ObservableCollection<AnalogAlarmModel>(); | |||
} | |||
} |
@@ -9,8 +9,7 @@ using Microsoft.Toolkit.Mvvm.Input; | |||
using BPASmart.VariableManager.Views; | |||
using System.Windows; | |||
using BPASmartClient.Helper; | |||
using BPASmart.VariableManager.Models; | |||
using BPASmart.VariableManager.Enums; | |||
using BPASmart.Model; | |||
//using BPASmartClient.Model; | |||
using System.IO.Ports; | |||
using System.IO; | |||
@@ -29,13 +28,6 @@ namespace BPASmart.VariableManager.ViewModels | |||
RemoveDeviceCommand = new RelayCommand<object>(RemoveDevice); | |||
SaveConnectSetCommand = new RelayCommand(() => { Json<CommunicationPar>.Save(); }); | |||
//Json<CommunicationPar>.Read(); | |||
//foreach (var item in Json<CommunicationPar>.Data.CommunicationDevices) | |||
//{ | |||
// //item.RemoveAction = RemoveDevice; | |||
// Json<CommunicationPar>.Data.CommunicationDevices.Add(item); | |||
//} | |||
DelegationNotifi.GetInstance.AddDeviceVerify = new Func<DeviceManagermentResult, bool>((p) => | |||
{ | |||
return Json<CommunicationPar>.Data.CommunicationDevices.FirstOrDefault(s => s.DeviceName == p.DeviceName) == null; | |||
@@ -66,11 +58,12 @@ namespace BPASmart.VariableManager.ViewModels | |||
if (obj == null) | |||
{ | |||
CommunicationModel communicationObj = new CommunicationModel(); | |||
Type type = Assembly.Load("BPASmart.VariableManager").GetType($"BPASmart.VariableManager.Models.{ResultTag.DeviceType}"); | |||
Type type = Assembly.Load("BPASmart.Model").GetType($"BPASmart.Model.{ResultTag.DeviceType}"); | |||
//Type type = Assembly.Load("BPASmart.VariableManager").GetType($"BPASmart.VariableManager.Models.{ResultTag.DeviceType}"); | |||
var res = Activator.CreateInstance(type) as ICommunicationDevice; | |||
communicationObj.DeviceName = ResultTag.DeviceName; | |||
communicationObj.CommDevice = res; | |||
communicationObj.ModelName = type.Name; | |||
Json<CommunicationPar>.Data.CommunicationDevices.Add(communicationObj); | |||
ActionManage.GetInstance.Send("AddCommunicationDevice", ResultTag.DeviceName); | |||
} | |||
@@ -85,6 +78,7 @@ namespace BPASmart.VariableManager.ViewModels | |||
if (result != null) | |||
{ | |||
Json<CommunicationPar>.Data.CommunicationDevices.Remove(result); | |||
ActionManage.GetInstance.Send("RemoveCommunicationDevice", result); | |||
} | |||
} | |||
@@ -9,8 +9,7 @@ using System.Collections.ObjectModel; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
using Microsoft.Toolkit.Mvvm.Messaging; | |||
using System.Diagnostics; | |||
using BPASmart.VariableManager.Models; | |||
using BPASmart.VariableManager.Enums; | |||
using BPASmart.Model; | |||
using System.Reflection; | |||
namespace BPASmart.VariableManager.ViewModels | |||
@@ -1,210 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using BPASmart.VariableManager.Enums; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
using BPASmart.VariableManager.Models; | |||
using System.Diagnostics; | |||
using Microsoft.EntityFrameworkCore; | |||
using BPASmartClient.Helper; | |||
using System.Text.Json.Serialization; | |||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | |||
using Ubiety.Dns.Core.Records; | |||
namespace BPASmart.VariableManager.ViewModels | |||
{ | |||
public class VariableConfig : NoticeBase | |||
{ | |||
private int varialeInfosIndex = -1; | |||
public VariableConfig() | |||
{ | |||
ComboBoxItemInit(); | |||
ActionManage.GetInstance.Register(new Action<object[]>((p) => | |||
{ | |||
if (p != null && p.Length == 2) | |||
{ | |||
NameWidth = Convert.ToDouble(p[0]); | |||
AddressWidth = Convert.ToDouble(p[1]); | |||
} | |||
}), "TabGridSizeChanged"); | |||
DelegationNotifi.GetInstance.VariableSave = new Action(() => { SaveDataAsync(); }); | |||
DelegationNotifi.GetInstance.VarNameChanged = new Action<int>((p) => | |||
{ | |||
if ((p - 1) >= 0) | |||
{ | |||
if (varialeInfos?.Count >= p) | |||
{ | |||
if (varialeInfos.ElementAt(p - 1).VarName != null) | |||
{ | |||
if (varialeInfos.ElementAt(p - 1).VarName.Length > 0) | |||
{ | |||
if (varialeInfos.Count == p) AddRow(); | |||
} | |||
} | |||
} | |||
} | |||
}); | |||
DelegationNotifi.GetInstance.PageName = new Action<string>((o) => | |||
{ | |||
int index = Array.FindIndex(Json<CommunicationPar>.Data.CommunicationDevices.ToArray(), p => p.DeviceName == o); | |||
varialeInfosIndex = index; | |||
if (index >= 0 && index < Json<CommunicationPar>.Data.CommunicationDevices.Count) | |||
{ | |||
varialeInfos = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels; | |||
if (varialeInfos.Count <= 0) AddRow(); | |||
//varialeInfos.Add(new VariableInfo()); | |||
} | |||
}); | |||
GetLocalDataAsync(); | |||
CancelCommand = new RelayCommand(() => { IsOpen = false; }); | |||
ConfirmCommand = new RelayCommand(() => { IsOpen = false; }); | |||
} | |||
/// <summary> | |||
/// 异步获取本地数据 | |||
/// </summary> | |||
private Task<bool> GetLocalDataAsync() | |||
{ | |||
//SqlHelper<VariableInfo>.GetInstance.Database.EnsureCreated(); | |||
////多表查询 | |||
//var DataList = SqlHelper<VariableInfo>.GetInstance.DbObj.ToList(); | |||
//App.Current.Dispatcher.Invoke(new Action(() => { varialeInfos.Clear(); })); | |||
//foreach (var item in DataList) | |||
//{ | |||
// PropBindInfo propBindInfo = new PropBindInfo(); | |||
// propBindInfo.ID = item.ID; | |||
// propBindInfo.VarName = item.VarName; | |||
// propBindInfo.Address = item.Address; | |||
// propBindInfo.DataType = item.DataType; | |||
// propBindInfo.IsEnableAlarm = item.IsEnableAlarm; | |||
// propBindInfo.CurrentValue = item.CurrentValue; | |||
// var result = item.AlarmSetProp.AnalogAlarmModels.Where(p => p.AlarmSetId == item.ID).ToList(); | |||
// result = result?.OrderBy(p => p.SortTag).ToList(); | |||
// propBindInfo.AlarmSetProp.AnalogAlarmModels.Clear(); | |||
// result?.ForEach(p => { propBindInfo.AlarmSetProp.AnalogAlarmModels.Add(p); }); | |||
// propBindInfo.AlarmSetProp.DiscreteAlarmInfoSet = item.AlarmSetProp.DiscreteAlarmInfoSet; | |||
// App.Current?.Dispatcher.Invoke(new Action(() => { varialeInfos.Add(propBindInfo); })); | |||
//} | |||
//if (varialeInfos.Count <= 0) AddRow(); | |||
return Task.FromResult(true); | |||
} | |||
/// <summary> | |||
/// 异步保存数据 | |||
/// </summary> | |||
/// <returns></returns> | |||
private Task<bool> SaveDataAsync() | |||
{ | |||
return Task.FromResult(true); | |||
} | |||
/// <summary> | |||
/// 添加行 | |||
/// </summary> | |||
private void AddRow() | |||
{ | |||
App.Current.Dispatcher.Invoke(new Action(() => | |||
{ | |||
if (varialeInfosIndex >= 0 && varialeInfosIndex < Json<CommunicationPar>.Data.CommunicationDevices.Count) | |||
{ | |||
Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(varialeInfosIndex).VarTableModels.Add(new PropBindInfo() | |||
{ | |||
ID = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(varialeInfosIndex).VarTableModels.Count + 1, | |||
}); | |||
} | |||
//aaaa.Add(new aaa()); | |||
})); | |||
} | |||
#region 属性 | |||
public double NameWidth { get { return _mNameWidth; } set { _mNameWidth = value; OnPropertyChanged(); } } | |||
public double _mNameWidth; | |||
public double AddressWidth { get { return _mAddressWidth; } set { _mAddressWidth = value; OnPropertyChanged(); } } | |||
private double _mAddressWidth; | |||
/// <summary> | |||
/// 是否显示报警设置框 | |||
/// </summary> | |||
public bool IsOpen { get { return _mIsOpen; } set { _mIsOpen = value; OnPropertyChanged(); } } | |||
private bool _mIsOpen; | |||
#endregion | |||
#region 数据列表 | |||
/// <summary> | |||
/// 数据类型下拉列表 | |||
/// </summary> | |||
public ObservableCollection<string> dataType { get; set; } = new ObservableCollection<string>(); | |||
/// <summary> | |||
/// 报警类型下拉列表 | |||
/// </summary> | |||
public ObservableCollection<string> alarmType { get; set; } = new ObservableCollection<string>(); | |||
/// <summary> | |||
/// 报警设置窗离散量报警类型 | |||
/// </summary> | |||
public ObservableCollection<string> PopupDiscreteAlarmType { get; set; } = new ObservableCollection<string>(); | |||
/// <summary> | |||
/// 变量信息 | |||
/// </summary> | |||
public ObservableCollection<VariableInfo> varialeInfos { get; set; } | |||
public ObservableCollection<aaa> aaaa { get; set; } = new ObservableCollection<aaa>(); | |||
#endregion | |||
#region Command | |||
/// <summary> | |||
/// 报警设置框取消操作 | |||
/// </summary> | |||
public RelayCommand CancelCommand { get; set; } | |||
/// <summary> | |||
/// 报警设置框确认按钮 | |||
/// </summary> | |||
public RelayCommand ConfirmCommand { get; set; } | |||
public RelayCommand SaveCommand { get; set; } | |||
public RelayCommand StartMotionCommand { get; set; } | |||
#endregion | |||
/// <summary> | |||
/// 下拉列表初始化 | |||
/// </summary> | |||
private void ComboBoxItemInit() | |||
{ | |||
dataType.Clear(); | |||
alarmType.Clear(); | |||
PopupDiscreteAlarmType.Clear(); | |||
string[] DataTypeNames = Enum.GetNames(typeof(EDataType)); | |||
foreach (var item in DataTypeNames) { dataType.Add(item); } | |||
string[] AlarmTypeNames = Enum.GetNames(typeof(EAlarmType)); | |||
foreach (var item in AlarmTypeNames) { alarmType.Add(item); } | |||
string[] PopupAlarmTypes = Enum.GetNames(typeof(EAlongTriggerType)); | |||
foreach (var item in PopupAlarmTypes) { PopupDiscreteAlarmType.Add(item); } | |||
} | |||
} | |||
public class aaa | |||
{ | |||
} | |||
} |
@@ -0,0 +1,216 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
using BPASmart.Model; | |||
using System.Diagnostics; | |||
using Microsoft.EntityFrameworkCore; | |||
using BPASmartClient.Helper; | |||
using System.Text.Json.Serialization; | |||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | |||
using Ubiety.Dns.Core.Records; | |||
using System.Windows; | |||
namespace BPASmart.VariableManager.ViewModels | |||
{ | |||
public class VariableConfigViewModel : NoticeBase | |||
{ | |||
private int varialeInfosIndex = -1; | |||
ICommunicationDevice DeviceType; | |||
public VariableConfigViewModel(string o) | |||
{ | |||
varialeInfosIndex = Array.FindIndex(Json<CommunicationPar>.Data.CommunicationDevices.ToArray(), p => p.DeviceName == o); | |||
if (varialeInfosIndex >= 0 && varialeInfosIndex < Json<CommunicationPar>.Data.CommunicationDevices.Count) | |||
{ | |||
DeviceType = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(varialeInfosIndex).CommDevice; | |||
varialeInfos = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(varialeInfosIndex).VarTableModels; | |||
if (varialeInfos.Count <= 0) AddRow(); | |||
} | |||
ComboBoxItemInit(); | |||
ActionManage.GetInstance.Register(new Action<object[]>((p) => | |||
{ | |||
if (p != null && p.Length == 2) | |||
{ | |||
NameWidth = Convert.ToDouble(p[0]); | |||
AddressWidth = Convert.ToDouble(p[1]); | |||
} | |||
}), "TabGridSizeChanged"); | |||
DelegationNotifi.GetInstance.VarNameChanged = new Action<int>((p) => | |||
{ | |||
var result = varialeInfos.GroupBy(P => P.VarName).ToList(); | |||
if (result != null && result.Count < varialeInfos.Count) | |||
{ | |||
result.ForEach(x => | |||
{ | |||
if (x.Key.Length > 0) | |||
{ | |||
if (x.Count() > 1) | |||
{ | |||
x.ToList().ForEach(item => | |||
{ | |||
int index = Array.FindIndex(varialeInfos.ToArray(), p => p.VarName == item.VarName && p.ID == item.ID); | |||
if (index >= 0 && index < varialeInfos.Count) | |||
{ | |||
varialeInfos.ElementAt(index).IsRedundant = true; | |||
} | |||
}); | |||
} | |||
else if (x.Count() == 1) | |||
{ | |||
int index = Array.FindIndex(varialeInfos.ToArray(), p => p.VarName == x.ElementAt(0).VarName && p.ID == x.ElementAt(0).ID); | |||
if (index >= 0 && index < varialeInfos.Count) | |||
{ | |||
varialeInfos.ElementAt(index).IsRedundant = false; | |||
} | |||
} | |||
} | |||
}); | |||
} | |||
else | |||
{ | |||
for (int i = 0; i < varialeInfos.Count; i++) | |||
{ | |||
varialeInfos.ElementAt(i).IsRedundant = false; | |||
} | |||
} | |||
if ((p - 1) >= 0) | |||
{ | |||
if (varialeInfos?.Count >= p) | |||
{ | |||
//if (varialeInfos.ElementAt(p - 1).VarName != null) | |||
//{ | |||
if (varialeInfos.ElementAt(p - 1).VarName?.Length > 0) | |||
{ | |||
if (varialeInfos.Count == p) AddRow(); | |||
} | |||
//} | |||
} | |||
} | |||
}); | |||
StartMotionCommand = new RelayCommand(() => | |||
{ | |||
switch (ButtonContext) | |||
{ | |||
case "开始监控": | |||
TabName = "当前值"; | |||
CurrentVisibility = Visibility.Visible; | |||
RemoveButVisiblity = Visibility.Collapsed; | |||
ButtonContext = "停止监控"; | |||
break; | |||
case "停止监控": | |||
TabName = "操作"; | |||
CurrentVisibility = Visibility.Collapsed; | |||
RemoveButVisiblity = Visibility.Visible; | |||
ButtonContext = "开始监控"; | |||
break; | |||
default: | |||
break; | |||
} | |||
}); | |||
RemoveCommand = new RelayCommand<object>((o) => | |||
{ | |||
if (o != null && o is VariableInfo variable) | |||
{ | |||
varialeInfos.Remove(variable); | |||
} | |||
for (int i = 0; i < varialeInfos.Count; i++) | |||
{ | |||
varialeInfos.ElementAt(i).ID = i + 1; | |||
} | |||
}); | |||
} | |||
/// <summary> | |||
/// 添加行 | |||
/// </summary> | |||
private void AddRow() | |||
{ | |||
App.Current.Dispatcher.Invoke(new Action(() => | |||
{ | |||
if (varialeInfosIndex >= 0 && varialeInfosIndex < Json<CommunicationPar>.Data.CommunicationDevices.Count) | |||
{ | |||
varialeInfos.Add(new VariableInfo(DeviceType) { ID = varialeInfos.Count + 1 }); | |||
} | |||
})); | |||
} | |||
#region 属性 | |||
public double NameWidth { get { return _mNameWidth; } set { _mNameWidth = value; OnPropertyChanged(); } } | |||
public static double _mNameWidth; | |||
public double AddressWidth { get { return _mAddressWidth; } set { _mAddressWidth = value; OnPropertyChanged(); } } | |||
private static double _mAddressWidth; | |||
public string TabName { get { return _mTabName; } set { _mTabName = value; OnPropertyChanged(); } } | |||
private static string _mTabName = "操作"; | |||
public string ButtonContext { get { return _mButtonContext; } set { _mButtonContext = value; OnPropertyChanged(); } } | |||
private static string _mButtonContext = "开始监控"; | |||
public Visibility CurrentVisibility { get { return _mCurrentVisibility; } set { _mCurrentVisibility = value; OnPropertyChanged(); } } | |||
private static Visibility _mCurrentVisibility = Visibility.Collapsed; | |||
public Visibility RemoveButVisiblity { get { return _mRemoveButVisiblity; } set { _mRemoveButVisiblity = value; OnPropertyChanged(); } } | |||
private static Visibility _mRemoveButVisiblity = Visibility.Visible; | |||
#endregion | |||
#region 数据列表 | |||
/// <summary> | |||
/// 数据类型下拉列表 | |||
/// </summary> | |||
public ObservableCollection<string> dataType { get; set; } = new ObservableCollection<string>(); | |||
/// <summary> | |||
/// 报警设置窗离散量报警类型 | |||
/// </summary> | |||
public ObservableCollection<string> PopupDiscreteAlarmType { get; set; } = new ObservableCollection<string>(); | |||
/// <summary> | |||
/// 变量信息 | |||
/// </summary> | |||
public ObservableCollection<VariableInfo> varialeInfos { get; set; } | |||
#endregion | |||
#region Command | |||
public RelayCommand SaveCommand { get; set; } | |||
public RelayCommand StartMotionCommand { get; set; } | |||
public RelayCommand<object> RemoveCommand { get; set; } | |||
#endregion | |||
/// <summary> | |||
/// 下拉列表初始化 | |||
/// </summary> | |||
private void ComboBoxItemInit() | |||
{ | |||
dataType.Clear(); | |||
PopupDiscreteAlarmType.Clear(); | |||
string[] DataTypeNames = Enum.GetNames(typeof(EDataType)); | |||
foreach (var item in DataTypeNames) { dataType.Add(item); } | |||
string[] PopupAlarmTypes = Enum.GetNames(typeof(EAlongTriggerType)); | |||
foreach (var item in PopupAlarmTypes) { PopupDiscreteAlarmType.Add(item); } | |||
} | |||
} | |||
} |
@@ -1,75 +0,0 @@ | |||
using BPASmart.VariableManager.Models; | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmart.VariableManager.ViewModels | |||
{ | |||
internal class VariableMonitorViewModel : ObservableObject | |||
{ | |||
public VariableMonitorViewModel() | |||
{ | |||
GetLocalDataAsync(); | |||
} | |||
/// <summary> | |||
/// 异步获取本地数据 | |||
/// </summary> | |||
private Task<bool> GetLocalDataAsync() | |||
{ | |||
//var DataList = SqlHelper<VariableInfo>.GetInstance.DbObj.ToList(); | |||
//App.Current.Dispatcher.Invoke(new Action(() => { varialeInfos.Clear(); })); | |||
//foreach (var item in DataList) | |||
//{ | |||
// if (item.VarName?.Length > 0) | |||
// { | |||
// VarMonitorPropInfo varMonitorPropInfo = new VarMonitorPropInfo(); | |||
// varMonitorPropInfo.ID = item.ID; | |||
// varMonitorPropInfo.VarName = item.VarName; | |||
// varMonitorPropInfo.Address = item.Address; | |||
// varMonitorPropInfo.DataType = item.DataType; | |||
// varMonitorPropInfo.DataDisplayFormat = TypeEnum.DisplayFormat.十进制.ToString(); | |||
// App.Current?.Dispatcher.Invoke(new Action(() => { varialeInfos.Add(varMonitorPropInfo); })); | |||
// } | |||
//} | |||
return Task.FromResult(true); | |||
} | |||
/// <summary> | |||
/// 异步保存数据 | |||
/// </summary> | |||
/// <returns></returns> | |||
private Task<bool> SaveDataAsync() | |||
{ | |||
//SqlHelper<VariableInfo>.GetInstance.DbObj.RemoveRange(SqlHelper<VariableInfo>.GetInstance.DbObj.ToArray()); | |||
//foreach (var item in varialeInfos) | |||
//{ | |||
// SqlHelper<VariableInfo>.GetInstance.Add(new VariableInfo() | |||
// { | |||
// ID = item.ID, | |||
// VarName = item.VarName, | |||
// Address = item.Address, | |||
// DataType = item.DataType, | |||
// IsEnableAlarm = item.IsEnableAlarm, | |||
// CurrentValue = item.CurrentValue, | |||
// AlarmSetProp = item.AlarmSetProp, | |||
// }); | |||
//} | |||
//SqlHelper<VariableInfo>.GetInstance.Save(); | |||
return Task.FromResult(true); | |||
} | |||
/// <summary> | |||
/// 变量信息 | |||
/// </summary> | |||
public ObservableCollection<VarMonitorPropInfo> varialeInfos { get; set; } = new ObservableCollection<VarMonitorPropInfo>(); | |||
} | |||
} | |||
@@ -95,6 +95,9 @@ | |||
Name="cy" | |||
Height="180" | |||
Margin="0,0,0,30"> | |||
<!--<Grid.Background> | |||
<ImageBrush ImageSource="/Resources/Images/边框1.png" /> | |||
</Grid.Background>--> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="30" /> | |||
<RowDefinition /> | |||
@@ -110,14 +113,37 @@ | |||
<pry:TitleTextBlock Margin="2,2,0,0" /> | |||
<TextBlock | |||
<StackPanel | |||
Margin="5" | |||
HorizontalAlignment="Left" | |||
VerticalAlignment="Center" | |||
FontFamily="楷体" | |||
FontSize="20" | |||
Foreground="Aqua" | |||
Text="{Binding DeviceName}" /> | |||
Orientation="Horizontal"> | |||
<TextBlock | |||
Margin="0,0,10,0" | |||
FontFamily="楷体" | |||
FontSize="20" | |||
Foreground="Aqua" | |||
Text="{Binding DeviceName}" /> | |||
<TextBlock | |||
FontFamily="楷体" | |||
FontSize="20" | |||
Foreground="Yellow" | |||
Text="[" /> | |||
<TextBlock | |||
FontFamily="楷体" | |||
FontSize="20" | |||
Foreground="Yellow" | |||
Text="{Binding ModelName}" /> | |||
<TextBlock | |||
FontFamily="楷体" | |||
FontSize="20" | |||
Foreground="Yellow" | |||
Text="]" /> | |||
</StackPanel> | |||
</Grid> | |||
<!--#endregion--> | |||
@@ -1,4 +1,6 @@ | |||
using System; | |||
using BPASmart.Model; | |||
using BPASmartClient.Helper; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
@@ -23,9 +25,12 @@ namespace BPASmart.VariableManager.Views | |||
public CommunicationSetView() | |||
{ | |||
InitializeComponent(); | |||
this.Unloaded += CommunicationSetView_Unloaded; | |||
} | |||
private void CommunicationSetView_Unloaded(object sender, RoutedEventArgs e) | |||
{ | |||
Json<CommunicationPar>.Save(); | |||
} | |||
} | |||
} |
@@ -14,7 +14,7 @@ using System.Windows.Media.Imaging; | |||
using System.Windows.Shapes; | |||
using Microsoft.Toolkit.Mvvm.Messaging; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using BPASmart.VariableManager.Models; | |||
using BPASmart.Model; | |||
namespace BPASmart.VariableManager.Views | |||
{ | |||
@@ -8,13 +8,13 @@ | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:pry="clr-namespace:BPASmartClient.CustomResource.UserControls;assembly=BPASmartClient.CustomResource" | |||
xmlns:vm="clr-namespace:BPASmart.VariableManager.ViewModels" | |||
d:DesignHeight="450" | |||
d:DesignWidth="1000" | |||
d:DesignHeight="600" | |||
d:DesignWidth="1200" | |||
mc:Ignorable="d"> | |||
<UserControl.DataContext> | |||
<!--<UserControl.DataContext> | |||
<vm:VariableConfig /> | |||
</UserControl.DataContext> | |||
</UserControl.DataContext>--> | |||
<UserControl.Resources> | |||
@@ -159,8 +159,8 @@ | |||
Width="150" | |||
Height="40" | |||
Margin="10,0,10,0" | |||
Command="{Binding AddCommand}" | |||
Content="开始监控" | |||
Command="{Binding StartMotionCommand}" | |||
Content="{Binding ButtonContext}" | |||
FontSize="20" | |||
Style="{StaticResource ImageButtonStyle}" /> | |||
<Button | |||
@@ -230,15 +230,17 @@ | |||
Text="报警配置" /> | |||
<Grid Grid.Column="6"> | |||
<TextBlock Style="{StaticResource TitleTextblockStyle}" Text="当前值" /> | |||
<TextBlock Style="{StaticResource TitleTextblockStyle}" Text="{Binding TabName}" /> | |||
<Border | |||
BorderBrush="{StaticResource bordColor}" | |||
BorderThickness="1,0,1,0" | |||
Cursor="SizeWE" /> | |||
</Grid> | |||
<Border | |||
Grid.ColumnSpan="7" | |||
Grid.ColumnSpan="8" | |||
BorderBrush="{StaticResource bordColor}" | |||
BorderThickness="1,0,1,0" /> | |||
@@ -408,7 +410,7 @@ | |||
ItemsSource="{Binding DataContext.PopupDiscreteAlarmType, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}" | |||
SelectedIndex="1" | |||
Style="{StaticResource ComboBoxStyle}" | |||
Text="{Binding AlarmSetProp.DiscreteAlarmInfoSet.TrigAlarm}" /> | |||
Text="{Binding DiscreteAlarmInfoSet.TrigAlarm}" /> | |||
</Grid> | |||
<Grid> | |||
@@ -426,7 +428,7 @@ | |||
Grid.Column="1" | |||
Grid.ColumnSpan="2" | |||
Style="{StaticResource TextBoxStyle}" | |||
Text="{Binding AlarmSetProp.DiscreteAlarmInfoSet.AlarmInfo}" /> | |||
Text="{Binding DiscreteAlarmInfoSet.AlarmInfo}" /> | |||
</Grid> | |||
</StackPanel> | |||
@@ -448,7 +450,7 @@ | |||
Text="模拟量报警设置" /> | |||
</Grid> | |||
<ItemsControl ItemsSource="{Binding AlarmSetProp.AnalogAlarmModels}"> | |||
<ItemsControl ItemsSource="{Binding AnalogAlarmModels}"> | |||
<ItemsControl.ItemTemplate> | |||
<DataTemplate> | |||
<Grid Margin="0,0,0,8"> | |||
@@ -530,7 +532,7 @@ | |||
<Button | |||
Height="40" | |||
Margin="10,5,10,10" | |||
Command="{Binding DataContext.CancelCommand, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}" | |||
Command="{Binding CancelCommand}" | |||
Content="取消" | |||
FontFamily="楷体" | |||
FontSize="20" | |||
@@ -542,7 +544,7 @@ | |||
Grid.Column="1" | |||
Height="40" | |||
Margin="10,5,10,10" | |||
Command="{Binding DataContext.ConfirmCommand, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}" | |||
Command="{Binding ConfirmCommand}" | |||
Content="确认" | |||
FontFamily="楷体" | |||
FontSize="20" | |||
@@ -570,7 +572,17 @@ | |||
Background="Transparent" | |||
FontSize="14" | |||
Foreground="{Binding IsRedundant, Converter={StaticResource tabConvert}}" | |||
Text="{Binding ID}" /> | |||
Text="{Binding CurrentValue}" | |||
Visibility="{Binding DataContext.CurrentVisibility, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}" /> | |||
<Button | |||
Grid.Column="6" | |||
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}" | |||
CommandParameter="{Binding}" | |||
Content="删除" | |||
FontSize="16" | |||
Style="{StaticResource ControlButtonStyle}" | |||
Visibility="{Binding DataContext.RemoveButVisiblity, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}" /> | |||
<Border | |||
Grid.ColumnSpan="7" | |||
@@ -1,4 +1,5 @@ | |||
using BPASmart.VariableManager.Models; | |||
using BPASmart.Model; | |||
using BPASmart.VariableManager.ViewModels; | |||
using BPASmartClient.Helper; | |||
using System; | |||
using System.Collections.Generic; | |||
@@ -27,6 +28,12 @@ namespace BPASmart.VariableManager.Views | |||
{ | |||
InitializeComponent(); | |||
this.IsVisibleChanged += VariableConfig_IsVisibleChanged; | |||
this.Unloaded += VariableConfig_Unloaded; | |||
} | |||
private void VariableConfig_Unloaded(object sender, RoutedEventArgs e) | |||
{ | |||
Json<CommunicationPar>.Save(); | |||
} | |||
private void VariableConfig_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) | |||
@@ -38,7 +45,10 @@ namespace BPASmart.VariableManager.Views | |||
DelegationNotifi.GetInstance.VariableSave = null; | |||
DelegationNotifi.GetInstance.VarNameChanged = null; | |||
} | |||
else DelegationNotifi.GetInstance.PageName?.Invoke(this.Name); | |||
else | |||
{ | |||
this.DataContext = new VariableConfigViewModel(this.Name); | |||
} | |||
} | |||
private void TabGrid_SizeChanged(object sender, SizeChangedEventArgs e) | |||
@@ -1,284 +0,0 @@ | |||
<UserControl | |||
x:Class="BPASmart.VariableManager.Views.VariableMonitorView" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:local="clr-namespace:BPASmart.VariableManager.Views" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:vm="clr-namespace:BPASmart.VariableManager.ViewModels" | |||
d:DesignHeight="450" | |||
d:DesignWidth="1000" | |||
mc:Ignorable="d"> | |||
<UserControl.DataContext> | |||
<vm:VariableMonitorViewModel /> | |||
</UserControl.DataContext> | |||
<UserControl.Resources> | |||
<!--<ResourceDictionary Source="../Resource/Style/BasicStyle.xaml"> | |||
<ResourceDictionary.MergedDictionaries>--> | |||
<ResourceDictionary> | |||
<!--<convert:TextDisplayConvert x:Key="textDisplayConvert" /> | |||
<convert:IsEnableConvert x:Key="isEnableConvert" /> | |||
<convert:AnalogAlarmConvert x:Key="analogAlarmConvert" /> | |||
<convert:DiscreteAlarmConvert x:Key="discreteAlarmConvert" /> | |||
<convert:AlarmTypeTextConvert x:Key="alarmTypeTextConvert" />--> | |||
<SolidColorBrush x:Key="BorderSolid" Color="#5523CACA" /> | |||
<SolidColorBrush x:Key="FontColor" Color="#FF2AB2E7" /> | |||
<SolidColorBrush x:Key="TitleFontColor" Color="#ddd" /> | |||
<SolidColorBrush x:Key="CursorColor" Color="Aqua" /> | |||
<SolidColorBrush x:Key="TitleBorderColor" Color="#FF2AB2E7" /> | |||
<Style x:Key="TextBlockStyle" TargetType="TextBlock"> | |||
<Setter Property="FontFamily" Value="楷体" /> | |||
<Setter Property="FontSize" Value="18" /> | |||
<Setter Property="Foreground" Value="{StaticResource TextBlockForeground}" /> | |||
<Setter Property="VerticalAlignment" Value="Center" /> | |||
<Setter Property="HorizontalAlignment" Value="Center" /> | |||
</Style> | |||
<Style x:Key="TextBoxStyle" TargetType="TextBox"> | |||
<Setter Property="FontFamily" Value="楷体" /> | |||
<Setter Property="FontSize" Value="22" /> | |||
<Setter Property="Background" Value="Transparent" /> | |||
<Setter Property="Foreground" Value="{StaticResource TextBlockForeground}" /> | |||
<Setter Property="BorderBrush" Value="#FF23CACA" /> | |||
<Setter Property="CaretBrush" Value="Aqua" /> | |||
<Setter Property="VerticalAlignment" Value="Center" /> | |||
</Style> | |||
</ResourceDictionary> | |||
<!--</ResourceDictionary.MergedDictionaries> | |||
</ResourceDictionary>--> | |||
</UserControl.Resources> | |||
<Grid Margin="10"> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="35" /> | |||
<RowDefinition Height="40" /> | |||
<RowDefinition /> | |||
</Grid.RowDefinitions> | |||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal"> | |||
<!--<Button | |||
Width="140" | |||
Margin="0,0,20,0" | |||
Background="#FF19B7EC" | |||
Command="{Binding NewConnectCommand}" | |||
Content="开始监控" | |||
FontFamily="楷体" | |||
FontSize="18" | |||
Template="{StaticResource NewButtonTemp}"> | |||
<Button.Foreground> | |||
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> | |||
<GradientStop Color="#FFBB662A" /> | |||
<GradientStop Offset="1" Color="White" /> | |||
</LinearGradientBrush> | |||
</Button.Foreground> | |||
</Button>--> | |||
<!--<Button | |||
Width="140" | |||
Margin="0,0,20,0" | |||
Background="#FF19B7EC" | |||
Command="{Binding NewConnectCommand}" | |||
Content="停止监控" | |||
FontFamily="楷体" | |||
FontSize="18" | |||
Template="{StaticResource NewButtonTemp}"> | |||
<Button.Foreground> | |||
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> | |||
<GradientStop Color="#FFBB662A" /> | |||
<GradientStop Offset="1" Color="White" /> | |||
</LinearGradientBrush> | |||
</Button.Foreground> | |||
</Button>--> | |||
</StackPanel> | |||
<!--#region 表格标题栏设置--> | |||
<Grid Grid.Row="1" Margin="0 10 0 0" Background="#dd2AB2E7"> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition Width="0.3*" /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition Width="0.7*" /> | |||
<ColumnDefinition Width="0" /> | |||
<ColumnDefinition Width="0.7*" /> | |||
<ColumnDefinition Width="0.5*" /> | |||
<ColumnDefinition Width="0.5*" /> | |||
</Grid.ColumnDefinitions> | |||
<TextBlock | |||
Grid.Column="0" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="ID" /> | |||
<Grid Grid.Column="1"> | |||
<TextBlock | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="名称" /> | |||
<Border BorderBrush="{StaticResource TitleBorderColor}" BorderThickness="1,0,1,0" /> | |||
</Grid> | |||
<TextBlock | |||
Grid.Column="2" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="地址" /> | |||
<Grid Grid.Column="3"> | |||
<TextBlock | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="数据类型" /> | |||
<Border BorderBrush="{StaticResource TitleBorderColor}" BorderThickness="1,0,1,0" /> | |||
</Grid> | |||
<Grid Grid.Column="5"> | |||
<TextBlock | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="数据显示格式" /> | |||
<Border BorderBrush="{StaticResource TitleBorderColor}" BorderThickness="0,0,1,0" /> | |||
</Grid> | |||
<TextBlock | |||
Grid.Column="6" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="当前值" /> | |||
<TextBlock | |||
Grid.Column="7" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="修改值" /> | |||
</Grid> | |||
<!--#endregion--> | |||
<!--#region 表格数据显示--> | |||
<ScrollViewer | |||
Grid.Row="2" | |||
HorizontalScrollBarVisibility="Hidden" | |||
VerticalScrollBarVisibility="Hidden"> | |||
<ItemsControl ItemsSource="{Binding varialeInfos}"> | |||
<ItemsControl.ItemTemplate> | |||
<DataTemplate> | |||
<Grid> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition Width="0.3*" /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition Width="0.7*" /> | |||
<ColumnDefinition Width="0" /> | |||
<ColumnDefinition Width="0.7*" /> | |||
<ColumnDefinition Width="0.5*" /> | |||
<ColumnDefinition Width="0.5*" /> | |||
</Grid.ColumnDefinitions> | |||
<TextBlock | |||
Grid.Column="0" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
Background="Transparent" | |||
FontSize="14" | |||
Foreground="{StaticResource FontColor}" | |||
Text="{Binding ID}" /> | |||
<Grid Grid.Column="1"> | |||
<!--<TextBox | |||
Background="Transparent" | |||
CaretBrush="{StaticResource CursorColor}" | |||
Foreground="{StaticResource FontColor}" | |||
Style="{StaticResource InputTextboxStyle}" | |||
Text="{Binding VarName}" />--> | |||
<Border BorderBrush="{StaticResource BorderSolid}" BorderThickness="1,0,1,0" /> | |||
</Grid> | |||
<!--<TextBox | |||
Grid.Column="2" | |||
Background="Transparent" | |||
CaretBrush="{StaticResource CursorColor}" | |||
Foreground="{StaticResource FontColor}" | |||
Style="{StaticResource InputTextboxStyle}" | |||
Text="{Binding Address}" />--> | |||
<Grid Grid.Column="3"> | |||
<TextBlock | |||
Grid.Column="0" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
Background="Transparent" | |||
FontSize="14" | |||
Foreground="{StaticResource FontColor}" | |||
Text="{Binding DataType}" /> | |||
<Border BorderBrush="{StaticResource BorderSolid}" BorderThickness="1,0,1,0" /> | |||
</Grid> | |||
<Grid Grid.Column="5"> | |||
<ComboBox | |||
VerticalAlignment="Center" | |||
BorderBrush="Transparent" | |||
BorderThickness="1" | |||
FontFamily="楷体" | |||
FontSize="20" | |||
Foreground="{StaticResource FontColor}" | |||
IsEditable="False" | |||
ItemsSource="{Binding DisplayFormat}" | |||
SelectedValue="{Binding DataDisplayFormat}" | |||
Style="{StaticResource ComboBoxStyle}" | |||
Text="{Binding DataDisplayFormat}" /> | |||
<Border BorderBrush="{StaticResource BorderSolid}" BorderThickness="0,0,1,0" /> | |||
</Grid> | |||
<Grid Grid.Column="6"> | |||
<TextBlock | |||
Grid.Column="0" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
Background="Transparent" | |||
FontSize="14" | |||
Foreground="{StaticResource FontColor}" | |||
Text="{Binding CurrentValue}" /> | |||
<Border BorderBrush="{StaticResource BorderSolid}" BorderThickness="0,0,1,0" /> | |||
</Grid> | |||
<!--<TextBox | |||
Grid.Column="7" | |||
Background="Transparent" | |||
CaretBrush="{StaticResource CursorColor}" | |||
Foreground="{StaticResource FontColor}" | |||
Style="{StaticResource InputTextboxStyle}" | |||
Text="{Binding ModifyValue}" />--> | |||
<Border | |||
Grid.ColumnSpan="8" | |||
BorderBrush="{StaticResource BorderSolid}" | |||
BorderThickness="1" /> | |||
</Grid> | |||
</DataTemplate> | |||
</ItemsControl.ItemTemplate> | |||
</ItemsControl> | |||
</ScrollViewer> | |||
<!--#endregion--> | |||
</Grid> | |||
</UserControl> |
@@ -1,28 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
using System.Windows.Controls; | |||
using System.Windows.Data; | |||
using System.Windows.Documents; | |||
using System.Windows.Input; | |||
using System.Windows.Media; | |||
using System.Windows.Media.Imaging; | |||
using System.Windows.Navigation; | |||
using System.Windows.Shapes; | |||
namespace BPASmart.VariableManager.Views | |||
{ | |||
/// <summary> | |||
/// VariableMonitorView.xaml 的交互逻辑 | |||
/// </summary> | |||
public partial class VariableMonitorView : UserControl | |||
{ | |||
public VariableMonitorView() | |||
{ | |||
InitializeComponent(); | |||
} | |||
} | |||
} |
@@ -6,6 +6,12 @@ | |||
<Nullable>enable</Nullable> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" /> | |||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.0" /> | |||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.MessageName\BPASmartClient.MessageName.csproj" /> | |||
</ItemGroup> | |||
@@ -0,0 +1,137 @@ | |||
using Microsoft.CodeAnalysis; | |||
using Microsoft.CodeAnalysis.CSharp; | |||
using Microsoft.CodeAnalysis.Emit; | |||
using Microsoft.CSharp; | |||
using System; | |||
using System.CodeDom.Compiler; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Reflection; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.Compiler | |||
{ | |||
/// <summary> | |||
/// C#编译器 | |||
/// </summary> | |||
public class CSharpConfig | |||
{ | |||
#region 单例模式 | |||
public static CSharpConfig Instance = null; | |||
public static CSharpConfig GetInstance() | |||
{ | |||
if (Instance == null) | |||
{ | |||
Instance = new CSharpConfig(); | |||
} | |||
return Instance; | |||
} | |||
#endregion | |||
public CSharpConfig() | |||
{ | |||
} | |||
public object RunCSharp(string code,object[] objValue,string error = "") | |||
{ | |||
object strretu = string.Empty; | |||
try | |||
{ | |||
string funName = "main"; | |||
StringBuilder builder = new StringBuilder(); | |||
builder.Append("namespace YF \n{\n class CSharpConfigRun\n"); | |||
builder.Append(" {\n"); | |||
builder.Append(code); | |||
builder.Append(" }\n}\n"); | |||
SyntaxTree tree = CSharpSyntaxTree.ParseText(builder.ToString()); | |||
var compilation = | |||
CSharpCompilation.Create("YF") | |||
.AddReferences( | |||
MetadataReference.CreateFromFile( | |||
typeof(object).Assembly.Location) | |||
) | |||
.AddSyntaxTrees(tree) | |||
.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); | |||
EmitResult emitResult; | |||
byte[] dllBytes; | |||
using (var stream = new MemoryStream()) | |||
{ | |||
emitResult = compilation.Emit(stream); | |||
dllBytes = stream.ToArray(); | |||
} | |||
if (emitResult.Success) | |||
{ | |||
// Assembly assembly = Assembly.LoadFrom("d:\\test.dll"); | |||
Assembly assembly = Assembly.Load(dllBytes); | |||
var obj = assembly.CreateInstance("YF.CSharpConfigRun"); | |||
var method = obj.GetType().GetMethod("main",new Type[] { typeof(string) }); | |||
strretu = method.Invoke(obj,objValue); | |||
} | |||
//var providerOptions = new Dictionary<string,string>(); | |||
//providerOptions.Add("CompilerVersion","v4.0"); | |||
//CSharpCodeProvider compiler = new CSharpCodeProvider(providerOptions); | |||
//string output = Path.GetTempFileName(); | |||
//var cp = new CompilerParameters() { GenerateInMemory = true,OutputAssembly = output }; | |||
//cp.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location); | |||
//cp.ReferencedAssemblies.Add("Microsoft.CSharp.dll"); | |||
//cp.ReferencedAssemblies.Add("System.Core.dll"); | |||
//cp.ReferencedAssemblies.Add("Newtonsoft.Json.dll"); //添加引用 | |||
//cp.ReferencedAssemblies.Add("System.dll"); | |||
//cp.GenerateExecutable = false; | |||
//cp.EmbeddedResources.Clear(); | |||
//cp.LinkedResources.Clear(); | |||
//cp.Win32Resource = null; | |||
//cp.TreatWarningsAsErrors = false; | |||
//cp.WarningLevel = 4; | |||
//cp.TempFiles.KeepFiles = false; | |||
//CompilerResults cr = compiler.CompileAssemblyFromSource(cp,builder.ToString()); | |||
// 1.ICodeComplier | |||
// CSharpCodeProvider complier = new CSharpCodeProvider(); | |||
// // 2.CompilerParameters | |||
// CompilerParameters cp = new CompilerParameters(); | |||
// cp.ReferencedAssemblies.Add("System.dll"); //添加引用 | |||
//// cp.ReferencedAssemblies.Add("Newtonsoft.Json.dll"); //添加引用 | |||
// cp.GenerateExecutable = false; | |||
// cp.GenerateInMemory = true; | |||
// // 3.CompilerResults | |||
// CompilerResults cr = complier.CompileAssemblyFromSource(cp,builder.ToString()); | |||
//if (cr.Errors.HasErrors) | |||
//{ | |||
// foreach (CompilerError err in cr.Errors) | |||
// { | |||
// error += err.ErrorText + "\r\n"; | |||
// } | |||
//} | |||
//else | |||
//{ | |||
// // 通过反射,调用HelloWorld的实例 | |||
// Assembly objAssembly = cr.CompiledAssembly; | |||
// object objClass = objAssembly.CreateInstance("CSharpConfigRun"); | |||
// MethodInfo objFun = objClass.GetType().GetMethod(funName); | |||
// strretu = objFun.Invoke(objClass,objValue); | |||
//} | |||
} | |||
catch (Exception ex) | |||
{ | |||
error += ex.Message; | |||
} | |||
return strretu; | |||
} | |||
} | |||
} |
@@ -22,9 +22,9 @@ namespace BPASmartClient.Compiler | |||
/// 控件类型 | |||
/// </summary> | |||
string ControlType { get; } | |||
///// <summary> | |||
///// 消息名称 | |||
///// </summary> | |||
//ObservableCollection<EventReceiveMessage> EventNameList { get; } | |||
/// <summary> | |||
/// 属性改变 | |||
/// </summary> | |||
event EventHandler PropertyChange; //声明一个事件 | |||
} | |||
} |
@@ -1,6 +1,5 @@ | |||
using BPASmartClient.CustomResource.Pages.ViewModel; | |||
using BPASmartClient.Helper; | |||
//using BPASmartClient.Message; | |||
using BPASmartClient.Model; | |||
using System; | |||
using System.Collections.Concurrent; | |||
@@ -48,6 +47,15 @@ namespace BPASmartClient.CustomResource.Pages.Model | |||
} | |||
//public static void AnalogAlarm(dynamic Trigger, string info, dynamic HH = null, dynamic H = 0, dynamic L = 0, dynamic LL = 0) | |||
//{ | |||
//} | |||
/// <summary> | |||
/// 沿报警检测 | |||
/// </summary> | |||
@@ -1,14 +1,12 @@ | |||
<UserControl x:Class="BPASmartClient.CustomResource.Pages.View.PermissionConfigurationView" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:local="clr-namespace:BPASmartClient.CustomResource.Pages.View" | |||
Width="800" | |||
Height="450" | |||
mc:Ignorable="d"> | |||
<Grid> | |||
</Grid> | |||
<UserControl | |||
x:Class="BPASmartClient.CustomResource.Pages.View.PermissionConfigurationView" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:local="clr-namespace:BPASmartClient.CustomResource.Pages.View" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
Width="800" | |||
Height="450" | |||
mc:Ignorable="d"> | |||
<Grid /> | |||
</UserControl> |
@@ -1,12 +1,12 @@ | |||
<UserControl x:Class="BPASmartClient.CustomResource.Pages.View.RecipeQueueView" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:local="clr-namespace:BPASmartClient.CustomResource.Pages.View" | |||
mc:Ignorable="d" | |||
d:DesignHeight="450" d:DesignWidth="800"> | |||
<Grid> | |||
</Grid> | |||
<UserControl | |||
x:Class="BPASmartClient.CustomResource.Pages.View.RecipeQueueView" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:local="clr-namespace:BPASmartClient.CustomResource.Pages.View" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
d:DesignHeight="450" | |||
d:DesignWidth="800" | |||
mc:Ignorable="d"> | |||
<Grid /> | |||
</UserControl> |
@@ -59,38 +59,11 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel | |||
if (type?.BaseType.Name == "Window") ((Window)cti?.Invoke(null)).ShowDialog(); | |||
else if (type?.BaseType.Name == "UserControl") | |||
{ | |||
MainContent = null; | |||
MainContent = (FrameworkElement)cti?.Invoke(null); | |||
MainContent?.GetType()?.GetProperty("Name").SetValue(MainContent, menumodel.SubMenuName); | |||
} | |||
} | |||
//for (int i = 0; i < menuModels.Count; i++) | |||
//{ | |||
// var res = menuModels.ElementAt(i).subMenumodels.FirstOrDefault(p => p.ToggleWindowPath == obj.ToString()); | |||
// if (res != null) | |||
// { | |||
// DisplayName = res.SubMenuName; | |||
// var end = res.AssemblyName.Substring(res.AssemblyName.Length - 1); | |||
// var start = res.ToggleWindowPath.Substring(0, 1); | |||
// bool isAddPoint = end != "." && start != "."; | |||
// string point = isAddPoint ? "." : ""; | |||
// Type type = Assembly.Load(res.AssemblyName)?.GetType($"{res.AssemblyName}{point}{res.ToggleWindowPath}"); | |||
// ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes); | |||
// if (type?.BaseType.Name == "Window") | |||
// { | |||
// ((Window)cti?.Invoke(null)).ShowDialog(); | |||
// break; | |||
// } | |||
// else if (type?.BaseType.Name == "UserControl") | |||
// { | |||
// //ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes); | |||
// MainContent = (FrameworkElement)cti?.Invoke(null); | |||
// break; | |||
// } | |||
// } | |||
//} | |||
} | |||
private bool _status; | |||
/// <summary> | |||
@@ -138,38 +138,7 @@ namespace BPASmartClient.Message | |||
#endregion | |||
#region 查找设备ID | |||
/// <summary> | |||
/// 查询设备ID | |||
/// </summary> | |||
/// <returns></returns> | |||
public object ReturnDeviceID() | |||
{ | |||
object DeviceId = null; | |||
//StackTrace trace = new StackTrace(); | |||
//for (int i = 1; i < 10; i++) | |||
//{ | |||
// Type type = trace.GetFrame(i).GetMethod().ReflectedType; | |||
// try | |||
// { | |||
// object obj = Activator.CreateInstance(type); | |||
// if (obj is IPeripheral) | |||
// { | |||
// IPeripheral peripheral = obj as IPeripheral; | |||
// DeviceId = type?.GetProperty("DeviceId")?.GetValue(peripheral, null); | |||
// } | |||
// if (DeviceId != null) break; | |||
// } | |||
// catch (Exception ex) | |||
// { | |||
// } | |||
//} | |||
return DeviceId; | |||
} | |||
#endregion | |||
@@ -0,0 +1,35 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.MessageName.EnumHelp | |||
{ | |||
/// <summary> | |||
/// 数据来源类型 | |||
/// </summary> | |||
public enum DataTypeEnum | |||
{ | |||
/// <summary> | |||
/// POST接口,GET接口 | |||
/// </summary> | |||
API接口, | |||
/// <summary> | |||
/// 接收主题MQTT数据 | |||
/// </summary> | |||
MQTT, | |||
/// <summary> | |||
/// 本地数据推送 | |||
/// </summary> | |||
本地源, | |||
/// <summary> | |||
/// 特定服务推送数据 | |||
/// </summary> | |||
服务推送, | |||
/// <summary> | |||
/// 静态数据 | |||
/// </summary> | |||
静态数据 | |||
} | |||
} |
@@ -9,6 +9,9 @@ | |||
<ItemGroup> | |||
<None Remove="Fonts\ds-digib.ttf" /> | |||
<None Remove="Images\biogebj.png" /> | |||
<None Remove="Images\bj.png" /> | |||
<None Remove="Images\databj.png" /> | |||
<None Remove="Images\State0.png" /> | |||
<None Remove="Images\State1.png" /> | |||
<None Remove="Images\State11.png" /> | |||
@@ -42,6 +45,8 @@ | |||
<ItemGroup> | |||
<Resource Include="Fonts\ds-digib.ttf" /> | |||
<Resource Include="Images\bj.png" /> | |||
<Resource Include="Images\databj.png" /> | |||
<Resource Include="Images\State0.png" /> | |||
<Resource Include="Images\State1.png" /> | |||
<Resource Include="Images\State11.png" /> | |||
@@ -49,6 +54,7 @@ | |||
<Resource Include="Images\timericon.png" /> | |||
<Resource Include="Images\借出.png" /> | |||
<Resource Include="Images\光柱.png" /> | |||
<Resource Include="Images\biogebj.png" /> | |||
<Resource Include="Images\退出.png" /> | |||
</ItemGroup> | |||
@@ -34,4 +34,28 @@ namespace BPASmartClient.SCADAControl.Converters | |||
} | |||
} | |||
public class ItemsListObj:ObservableCollection<object> | |||
{ | |||
public ItemsListObj() | |||
{ | |||
AddCommand = new RelayCommand<object>(AddItem); | |||
DeleteCommand = new RelayCommand<object>(DeleteItem); | |||
} | |||
private void DeleteItem(object obj) | |||
{ | |||
if (obj!=null) | |||
Remove(obj); | |||
} | |||
public RelayCommand<object> AddCommand { get; } | |||
public RelayCommand<object> DeleteCommand { get; } | |||
private void AddItem(object txt) | |||
{ | |||
if (txt != null) | |||
Add(txt); | |||
} | |||
} | |||
} |
@@ -23,6 +23,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public class ArcGauge : Control, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public ArcGauge() | |||
{ | |||
Width = 300; | |||
@@ -14,6 +14,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public class DigitalNumber :Control, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public DigitalNumber() | |||
{ | |||
Width = 80; | |||
@@ -23,6 +23,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public partial class GraphArrow : UserControl, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public GraphArrow() | |||
{ | |||
InitializeComponent(); | |||
@@ -23,6 +23,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public partial class GraphStar : UserControl, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public GraphStar() | |||
{ | |||
InitializeComponent(); | |||
@@ -23,6 +23,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public class KnobButton : Slider, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
static KnobButton() | |||
{ | |||
DefaultStyleKeyProperty.OverrideMetadata(typeof(KnobButton), new FrameworkPropertyMetadata(typeof(KnobButton))); | |||
@@ -41,6 +41,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
Storyboard storyboard1 = new Storyboard(); | |||
#endregion | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public NewConveyorBelt() | |||
{ | |||
@@ -19,6 +19,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
{ | |||
public class NumberBox : TextBox, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
static NumberBox() | |||
{ | |||
DefaultStyleKeyProperty.OverrideMetadata(typeof(NumberBox), new FrameworkPropertyMetadata(typeof(NumberBox))); | |||
@@ -80,6 +80,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
} | |||
} | |||
} | |||
private void EventNameList_CollectionChanged(object? sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e) | |||
{ | |||
if (EventReceiveNameList.Count > 0) | |||
@@ -310,6 +311,81 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
private static readonly DependencyProperty EventSendNameListProperty = | |||
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(); | |||
#endregion | |||
#region 数据绑定模块 | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
[Category("数据绑定-数据来源")] | |||
public DataTypeEnum DataSouceType | |||
{ | |||
get { return (DataTypeEnum)GetValue(DataSouceTypeProperty); } | |||
set { SetValue(DataSouceTypeProperty,value); } | |||
} | |||
public static readonly DependencyProperty DataSouceTypeProperty = | |||
DependencyProperty.Register("DataSouceType",typeof(DataTypeEnum),typeof(Silos),new PropertyMetadata(DataTypeEnum.静态数据)); | |||
[Category("数据绑定-数据来源")] | |||
public int TimeCount | |||
{ | |||
get { return (int)GetValue(TimeCountProperty); } | |||
set { SetValue(TimeCountProperty,value); } | |||
} | |||
public static readonly DependencyProperty TimeCountProperty = | |||
DependencyProperty.Register("TimeCount",typeof(int),typeof(Silos),new PropertyMetadata(5)); | |||
[Category("数据绑定-数据来源")] | |||
public string DataSouceInformation | |||
{ | |||
get { return (string)GetValue(DataSouceInformationProperty); } | |||
set { SetValue(DataSouceInformationProperty,value); } | |||
} | |||
public static readonly DependencyProperty DataSouceInformationProperty = | |||
DependencyProperty.Register("DataSouceInformation",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty)); | |||
[Category("数据绑定")] | |||
public string FDataSouce | |||
{ | |||
get { return (string)GetValue(FDataSouceProperty); } | |||
set { SetValue(FDataSouceProperty,value); } | |||
} | |||
public static readonly DependencyProperty FDataSouceProperty = | |||
DependencyProperty.Register("FDataSouce",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty,new PropertyChangedCallback(onFDataSouceChanged))); | |||
private static void onFDataSouceChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as Silos)?.DataSouceRefresh(); | |||
public void DataSouceRefresh() | |||
{ | |||
try | |||
{ | |||
if (!string.IsNullOrEmpty(FDataSouce)) | |||
{ | |||
GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code,new object[] { FDataSouce }); | |||
if (PropertyChange != null) | |||
{ | |||
PropertyChange(this,null); | |||
} | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
public static string _code = " public string main(string message) \n { \n //请在此填写你的代码\n\n return message; \n }\n"; | |||
[Category("数据绑定")] | |||
public string Code | |||
{ | |||
get { return (string)GetValue(CodeProperty); } | |||
set { SetValue(CodeProperty,value); } | |||
} | |||
public static readonly DependencyProperty CodeProperty = | |||
DependencyProperty.Register("Code",typeof(string),typeof(Silos),new PropertyMetadata(_code)); | |||
[Category("数据绑定")] | |||
public string GenerateData | |||
{ | |||
get { return (string)GetValue(GenerateDataProperty); } | |||
set { SetValue(GenerateDataProperty,value); } | |||
} | |||
public static readonly DependencyProperty GenerateDataProperty = | |||
DependencyProperty.Register("GenerateData",typeof(string),typeof(Silos),new PropertyMetadata(string.Empty)); | |||
#endregion | |||
#region 发送事件名称集合 | |||
@@ -23,6 +23,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public class StatusLight : Control, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public StatusLight() | |||
{ | |||
Width = 80; | |||
@@ -26,6 +26,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
[TemplatePart(Name = TranslateX, Type = typeof(TranslateTransform))] | |||
public class SwitchButton : ToggleButton, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public SwitchButton() | |||
{ | |||
SetCurrentValue(WidthProperty, 120d); | |||
@@ -23,6 +23,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public partial class TheButton : Button, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public TheButton() | |||
{ | |||
InitializeComponent(); | |||
@@ -23,6 +23,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public partial class TheCheckBox : CheckBox, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public TheCheckBox() | |||
{ | |||
InitializeComponent(); | |||
@@ -23,6 +23,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public partial class TheComboBox : ComboBox, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public TheComboBox() | |||
{ | |||
InitializeComponent(); | |||
@@ -0,0 +1,10 @@ | |||
<DataGrid x:Class="BPASmartClient.SCADAControl.CustomerControls.TheDataGrid" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:local="clr-namespace:BPASmartClient.SCADAControl.CustomerControls" | |||
mc:Ignorable="d" | |||
Background="Transparent" | |||
d:DesignHeight="450" d:DesignWidth="800"> | |||
</DataGrid> |
@@ -0,0 +1,104 @@ | |||
using BPASmartClient.Compiler; | |||
using BPASmartClient.MessageName.接收消息Model.物料仓; | |||
using BPASmartClient.SCADAControl.Converters; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.ComponentModel; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
using System.Windows.Controls; | |||
using System.Windows.Data; | |||
using System.Windows.Documents; | |||
using System.Windows.Input; | |||
using System.Windows.Media; | |||
using System.Windows.Media.Imaging; | |||
using System.Windows.Navigation; | |||
using System.Windows.Shapes; | |||
namespace BPASmartClient.SCADAControl.CustomerControls | |||
{ | |||
/// <summary> | |||
/// TheDataGrid.xaml 的交互逻辑 | |||
/// </summary> | |||
public partial class TheDataGrid :DataGrid, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public TheDataGrid() | |||
{ | |||
InitializeComponent(); | |||
Style = Application.Current.Resources["DesignTheDataGrid"] as Style; | |||
MinWidth = 100; | |||
MinHeight = 100; | |||
ItemsString =new ItemsListObj() | |||
{ | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
}; | |||
} | |||
public ItemsListObj ItemsString | |||
{ | |||
get { return (ItemsListObj)GetValue(ItemsStringProperty); } | |||
set { SetValue(ItemsStringProperty,value); } | |||
} | |||
public static readonly DependencyProperty ItemsStringProperty = | |||
DependencyProperty.Register("ItemsString",typeof(ItemsListObj),typeof(TheDataGrid),new PropertyMetadata(null)); | |||
public string ControlType => "控件"; | |||
private bool isExecuteState; | |||
public bool IsExecuteState | |||
{ | |||
get { return isExecuteState; } | |||
set | |||
{ | |||
isExecuteState = value; | |||
if (IsExecuteState) | |||
{ | |||
Style = null; | |||
Register(); | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 注册需要处理的事件 | |||
/// </summary> | |||
public void Register() | |||
{ | |||
// 运行时进行项目绑定 | |||
Binding binding = new Binding(); | |||
binding.RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.Self }; | |||
binding.Path = new PropertyPath("ItemsString"); | |||
SetBinding(ItemsSourceProperty,binding); | |||
} | |||
private void MyButton_Click(object sender,RoutedEventArgs e) | |||
{ | |||
} | |||
} | |||
public class datalist | |||
{ | |||
public string Name { get; set; } | |||
public string Description { get; set; } | |||
public string Messgae { get; set; } | |||
} | |||
} |
@@ -22,6 +22,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public partial class TheGroupBox : GroupBox, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public TheGroupBox() | |||
{ | |||
InitializeComponent(); | |||
@@ -22,6 +22,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public partial class TheImage : Image, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public TheImage() | |||
{ | |||
InitializeComponent(); | |||
@@ -0,0 +1,11 @@ | |||
<ListBox x:Class="BPASmartClient.SCADAControl.CustomerControls.TheListBox" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:local="clr-namespace:BPASmartClient.SCADAControl.CustomerControls" | |||
mc:Ignorable="d" | |||
BorderBrush="Transparent" | |||
Background="Transparent" | |||
d:DesignHeight="450" d:DesignWidth="800"> | |||
</ListBox> |
@@ -0,0 +1,97 @@ | |||
using BPASmartClient.Compiler; | |||
using BPASmartClient.MessageName.接收消息Model.物料仓; | |||
using BPASmartClient.SCADAControl.Converters; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.ComponentModel; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
using System.Windows.Controls; | |||
using System.Windows.Data; | |||
using System.Windows.Documents; | |||
using System.Windows.Input; | |||
using System.Windows.Media; | |||
using System.Windows.Media.Imaging; | |||
using System.Windows.Navigation; | |||
using System.Windows.Shapes; | |||
namespace BPASmartClient.SCADAControl.CustomerControls | |||
{ | |||
/// <summary> | |||
/// TheListBox.xaml 的交互逻辑 | |||
/// </summary> | |||
public partial class TheListBox :ListBox, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public TheListBox() | |||
{ | |||
InitializeComponent(); | |||
Style = Application.Current.Resources["DesignTheListBox"] as Style; | |||
MinWidth = 100; | |||
MinHeight = 100; | |||
ItemsString = new ItemsListObj() | |||
{ | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"}, | |||
}; | |||
} | |||
public ItemsListObj ItemsString | |||
{ | |||
get { return (ItemsListObj)GetValue(ItemsStringProperty); } | |||
set { SetValue(ItemsStringProperty,value); } | |||
} | |||
public static readonly DependencyProperty ItemsStringProperty = | |||
DependencyProperty.Register("ItemsString",typeof(ItemsListObj),typeof(TheListBox),new PropertyMetadata(null)); | |||
public string ControlType => "控件"; | |||
private bool isExecuteState; | |||
public bool IsExecuteState | |||
{ | |||
get { return isExecuteState; } | |||
set | |||
{ | |||
isExecuteState = value; | |||
if (IsExecuteState) | |||
{ | |||
Style = null; | |||
Register(); | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 注册需要处理的事件 | |||
/// </summary> | |||
public void Register() | |||
{ | |||
// 运行时进行项目绑定 | |||
Binding binding = new Binding(); | |||
binding.RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.Self }; | |||
binding.Path = new PropertyPath("ItemsString"); | |||
SetBinding(ItemsSourceProperty,binding); | |||
} | |||
private void MyButton_Click(object sender,RoutedEventArgs e) | |||
{ | |||
} | |||
} | |||
} |
@@ -19,6 +19,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
{ | |||
public class TheRadioButton : RadioButton, IExecutable, IDisposable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public TheRadioButton() | |||
{ | |||
SetCurrentValue(ContentProperty, "单选按钮"); | |||
@@ -19,6 +19,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
{ | |||
public class TheSlider : Slider, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
static TheSlider() | |||
{ | |||
DefaultStyleKeyProperty.OverrideMetadata(typeof(TheSlider), new FrameworkPropertyMetadata(typeof(TheSlider))); | |||
@@ -22,6 +22,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public partial class TheTextBlock : TextBlock, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public TheTextBlock() | |||
{ | |||
InitializeComponent(); | |||
@@ -19,6 +19,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
{ | |||
public class TheTextBox : TextBox, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
static TheTextBox() | |||
{ | |||
DefaultStyleKeyProperty.OverrideMetadata(typeof(TheTextBox), new FrameworkPropertyMetadata(typeof(TheTextBox))); | |||
@@ -21,6 +21,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
{ | |||
public class TheTimer : Control, IExecutable, IDisposable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
public TheTimer() | |||
{ | |||
Width = 40; | |||
@@ -23,6 +23,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
/// </summary> | |||
public partial class TheToggleButton : ToggleButton, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
/// <summary> | |||
/// 开关按钮 | |||
/// </summary> | |||
@@ -14,6 +14,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
[TemplatePart(Name = ElementClip, Type = typeof(FrameworkElement))] | |||
public class WaveProgressBar : RangeBase, IExecutable | |||
{ | |||
public event EventHandler PropertyChange; //声明一个事件 | |||
private const string ElementWave = "PART_Wave"; | |||
private const string ElementClip = "PART_Clip"; | |||