Browse Source

变量管理器设置

样式分支
pry 2 years ago
parent
commit
0406fdf6ce
13 changed files with 200 additions and 201 deletions
  1. +2
    -8
      BPASmart.ConfigurationSoftware/App.xaml.cs
  2. +1
    -0
      BPASmart.ConfigurationSoftware/FileHelper.cs
  3. +52
    -12
      BPASmart.ConfigurationSoftware/MainWindowViewModel.cs
  4. +1
    -0
      BPASmart.ConfigurationSoftware/NewPageView.xaml.cs
  5. +31
    -31
      BPASmart.ConfigurationSoftware/ProjectModel.cs
  6. +16
    -0
      BPASmart.Model/LocalPar.cs
  7. +35
    -0
      BPASmart.Model/ProjectModel.cs
  8. +25
    -30
      BPASmart.VariableManager/App.xaml.cs
  9. +29
    -0
      BPASmart.VariableManager/FileConfigModel.cs
  10. +3
    -4
      BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs
  11. +1
    -112
      BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs
  12. +2
    -2
      BPASmart.VariableManager/Views/CommunicationSetView.xaml.cs
  13. +2
    -2
      BPASmart.VariableManager/Views/VariableConfig.xaml.cs

+ 2
- 8
BPASmart.ConfigurationSoftware/App.xaml.cs View File

@@ -1,4 +1,5 @@
using BPA.Helper; using BPA.Helper;
using BPASmart.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration; using System.Configuration;
@@ -21,14 +22,7 @@ namespace BPASmart.ConfigurationSoftware
{ {
var res = e.Args[0]; var res = e.Args[0];
Json<ProjectModel>.Read(res); Json<ProjectModel>.Read(res);

var rrr = Json<ProjectModel>.Data.Pages.OrderBy(p => p.Key).ToDictionary(p => p.Key, s => s.Value);
rrr?.ToList()?.ForEach(item =>
{
MessageBox.Show(item.Key);
});


var pages = Json<ProjectModel>.Data.Pages.OrderBy(p => p.Key).ToDictionary(p => p.Key, s => s.Value);
} }
MainWindow window = new MainWindow(); MainWindow window = new MainWindow();
window.Show(); window.Show();


+ 1
- 0
BPASmart.ConfigurationSoftware/FileHelper.cs View File

@@ -1,4 +1,5 @@
using BPA.Helper; using BPA.Helper;
using BPASmart.Model;
using Microsoft.Win32; using Microsoft.Win32;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;


+ 52
- 12
BPASmart.ConfigurationSoftware/MainWindowViewModel.cs View File

@@ -14,11 +14,51 @@ using BeDesignerSCADA;
using BeDesignerSCADA.Controls; using BeDesignerSCADA.Controls;
using System.Windows; using System.Windows;
using System.Reflection; using System.Reflection;
using System.Collections.Concurrent;


namespace BPASmart.ConfigurationSoftware namespace BPASmart.ConfigurationSoftware
{ {
public class MainWindowViewModel : NoticeBase public class MainWindowViewModel : NoticeBase
{ {

//public ushort CalcCRC(byte[] bytes)
//{
// ushort uiCrcValue = 0xffff;
// ushort polynomial = 0x8408;
// for (int i = 0; i < bytes.Length; i++)
// {
// uiCrcValue = (ushort)(uiCrcValue ^ bytes[i]);
// for (int m = 0; m < 8; m++)
// {
// if ((uiCrcValue & 0x0001) == 1)
// {
// uiCrcValue = (ushort)((uiCrcValue >> 1) ^ polynomial);
// }
// else
// {
// uiCrcValue = (ushort)(uiCrcValue >> 1);
// }
// }
// }
// return uiCrcValue;
//}

//public byte[] GetCrc(ushort value, bool IsReverse = true)
//{
// byte[] bytes = new byte[2];
// if (IsReverse)
// {
// bytes[0] = (byte)value;
// bytes[1] = (byte)(value >> 8);
// }
// else
// {
// bytes[1] = (byte)value;
// bytes[0] = (byte)(value >> 8);
// }
// return bytes;
//}

public MainWindowViewModel() public MainWindowViewModel()
{ {
Init(); Init();
@@ -58,18 +98,16 @@ namespace BPASmart.ConfigurationSoftware


OpenVarManagerCommand = new RelayCommand(() => OpenVarManagerCommand = new RelayCommand(() =>
{ {
//if (File.Exists(Global.VarManagerPath))
//{
// Process[] pro = Process.GetProcesses();
// if (pro?.ToList().FirstOrDefault(p => p.ProcessName.Contains("BPASmart.VariableManager")) == null)
// {
// Process.Start(Global.VarManagerPath);
// }
//}

VariableManager.App.Start(Json<ProjectModel>.Data.ProjectPath);


Json<LocalPar>.Data.ProjectPath = Json<ProjectModel>.Data.ProjectPath;
Json<LocalPar>.Save();
if (File.Exists(Global.VarManagerPath))
{
Process[] pro = Process.GetProcesses();
if (pro?.ToList().FirstOrDefault(p => p.ProcessName.Contains("BPASmart.VariableManager")) == null)
{
Process.Start(Global.VarManagerPath);
}
}
}); });


SelectedPageCommand = new RelayCommand<object>((o) => SelectedPageCommand = new RelayCommand<object>((o) =>
@@ -122,6 +160,8 @@ namespace BPASmart.ConfigurationSoftware
{ {
string path = Json<ProjectModel>.Data.ProjectPath; string path = Json<ProjectModel>.Data.ProjectPath;
string name = Json<ProjectModel>.Data.ProjectName; string name = Json<ProjectModel>.Data.ProjectName;
var pages = Json<ProjectModel>.Data.Pages.OrderBy(p => p.Key).ToDictionary(p => p.Key, s => s.Value);
if (pages != null) Json<ProjectModel>.Data.Pages = pages;
Json<ProjectModel>.Save($"{path}\\{name}.project"); Json<ProjectModel>.Save($"{path}\\{name}.project");
} }




+ 1
- 0
BPASmart.ConfigurationSoftware/NewPageView.xaml.cs View File

@@ -1,4 +1,5 @@
using BPA.Helper; using BPA.Helper;
using BPASmart.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;


+ 31
- 31
BPASmart.ConfigurationSoftware/ProjectModel.cs View File

@@ -1,35 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Runtime.Serialization;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//using System.Collections.Concurrent;
//using System.Runtime.Serialization;


namespace BPASmart.ConfigurationSoftware
{
public class ProjectModel
{
/// <summary>
/// 项目名称
/// </summary>
public string ProjectName { get; set; }
//namespace BPASmart.ConfigurationSoftware
//{
// public class ProjectModel
// {
// /// <summary>
// /// 项目名称
// /// </summary>
// public string ProjectName { get; set; }


/// <summary>
/// 项目路径
/// </summary>
public string ProjectPath { get; set; }
// /// <summary>
// /// 项目路径
// /// </summary>
// public string ProjectPath { get; set; }


/// <summary>
/// 页面集合
/// key 是页面名称
/// value 是页面路径
/// </summary>
public ConcurrentDictionary<string, string> Pages { get; set; } = new ConcurrentDictionary<string, string>();
// /// <summary>
// /// 页面集合
// /// key 是页面名称
// /// value 是页面路径
// /// </summary>
// public Dictionary<string, string> Pages { get; set; } = new Dictionary<string, string>();


/// <summary>
/// 变量表配置路径
/// </summary>
public string VariableTabPath { get; set; }
}
}
// /// <summary>
// /// 变量表配置路径
// /// </summary>
// public string VariableTabPath { get; set; }
// }
//}

+ 16
- 0
BPASmart.Model/LocalPar.cs View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmart.Model
{
public class LocalPar
{
/// <summary>
/// 项目路径
/// </summary>
public string ProjectPath { get; set; } = string.Empty;
}
}

+ 35
- 0
BPASmart.Model/ProjectModel.cs View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Runtime.Serialization;

namespace BPASmart.Model
{
public class ProjectModel
{
/// <summary>
/// 项目名称
/// </summary>
public string ProjectName { get; set; }

/// <summary>
/// 项目路径
/// </summary>
public string ProjectPath { get; set; }

/// <summary>
/// 页面集合
/// key 是页面名称
/// value 是页面路径
/// </summary>
public Dictionary<string, string> Pages { get; set; } = new Dictionary<string, string>();

/// <summary>
/// 变量表配置路径
/// </summary>
public string VariableTabPath { get; set; }
}
}

+ 25
- 30
BPASmart.VariableManager/App.xaml.cs View File

@@ -20,11 +20,13 @@ namespace BPASmart.VariableManager
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
public static string ConstPath = string.Empty;
//public static string ConstPath = string.Empty;
public static Window MainWindow; public static Window MainWindow;
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {
base.OnStartup(e); base.OnStartup(e);
Json<LocalPar>.Read();
FileConfigModel.ConstPath = Json<LocalPar>.Data.ProjectPath;
DataRead(); DataRead();
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
MenuInit(); MenuInit();
@@ -35,19 +37,7 @@ namespace BPASmart.VariableManager


} }


public static void Start(string path)
{
ConstPath = path;
DataRead();
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
MenuInit();
MainView mv = new MainView();
mv.WindowState = WindowState.Normal;
MainWindow = mv;
mv.Show();
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{ {
DataSave(); DataSave();
} }
@@ -58,7 +48,7 @@ namespace BPASmart.VariableManager
DataSave(); DataSave();
} }


private static void MenuInit()
private void MenuInit()
{ {
#region 设备管理 #region 设备管理
ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>(); ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>();
@@ -113,7 +103,7 @@ namespace BPASmart.VariableManager


} }


private static SubMenumodel AddSubMenuModel(string s)
private SubMenumodel AddSubMenuModel(string s)
{ {
return new SubMenumodel() return new SubMenumodel()
{ {
@@ -124,24 +114,29 @@ namespace BPASmart.VariableManager
}; };
} }


static string path
{
get
{
string path = $"{ConstPath}\\AccessFile\\JSON";
Directory.CreateDirectory(path);
return $"{ConstPath}\\AccessFile\\JSON\\CommunicationPar.json";
}
}

private static void DataSave()
//static string path
//{
// get
// {
// string ReturnValue = null;
// if (Directory.Exists(ConstPath))
// {
// string path = $"{ConstPath}\\AccessFile\\JSON";
// Directory.CreateDirectory(path);
// ReturnValue = $"{ConstPath}\\AccessFile\\JSON\\CommunicationPar.json";
// }
// return ReturnValue;
// }
//}

private void DataSave()
{ {
Json<CommunicationPar>.Save(path);
Json<CommunicationPar>.Save(FileConfigModel.GetPath);
} }


private static void DataRead()
private void DataRead()
{ {
Json<CommunicationPar>.Read(path);
Json<CommunicationPar>.Read(FileConfigModel.GetPath);
} }
} }




+ 29
- 0
BPASmart.VariableManager/FileConfigModel.cs View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmart.VariableManager
{
public class FileConfigModel
{
public static string ConstPath = string.Empty;

public static string GetPath
{
get
{
string ReturnValue = null;
if (Directory.Exists(ConstPath))
{
string path = $"{ConstPath}\\AccessFile\\JSON";
Directory.CreateDirectory(path);
ReturnValue = $"{ConstPath}\\AccessFile\\JSON\\CommunicationPar.json";
}
return ReturnValue;
}
}
}
}

+ 3
- 4
BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs View File

@@ -8,9 +8,8 @@ using System.Collections.ObjectModel;
using Microsoft.Toolkit.Mvvm.Input; using Microsoft.Toolkit.Mvvm.Input;
using BPASmart.VariableManager.Views; using BPASmart.VariableManager.Views;
using System.Windows; using System.Windows;
using BPASmartClient.Helper;
using BPA.Helper;
using BPASmart.Model; using BPASmart.Model;
//using BPASmartClient.Model;
using System.IO.Ports; using System.IO.Ports;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@@ -21,12 +20,12 @@ namespace BPASmart.VariableManager.ViewModels
{ {
public CommunicationSetViewModel() public CommunicationSetViewModel()
{ {
Json<CommunicationPar>.Read();
Json<CommunicationPar>.Read(FileConfigModel.GetPath);
communicationDevices = Json<CommunicationPar>.Data.CommunicationDevices; communicationDevices = Json<CommunicationPar>.Data.CommunicationDevices;
DataListInit(); DataListInit();
NewConnectCommand = new RelayCommand(() => { NewConnect(); }); NewConnectCommand = new RelayCommand(() => { NewConnect(); });
RemoveDeviceCommand = new RelayCommand<object>(RemoveDevice); RemoveDeviceCommand = new RelayCommand<object>(RemoveDevice);
SaveConnectSetCommand = new RelayCommand(() => { Json<CommunicationPar>.Save(); });
SaveConnectSetCommand = new RelayCommand(() => { Json<CommunicationPar>.Save(FileConfigModel.GetPath); });


DelegationNotifi.GetInstance.AddDeviceVerify = new Func<DeviceManagermentResult, bool>((p) => DelegationNotifi.GetInstance.AddDeviceVerify = new Func<DeviceManagermentResult, bool>((p) =>
{ {


+ 1
- 112
BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs View File

@@ -9,7 +9,7 @@ using Microsoft.Toolkit.Mvvm.Input;
using BPASmart.Model; using BPASmart.Model;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using BPASmartClient.Helper;
using BPA.Helper;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Ubiety.Dns.Core.Records; using Ubiety.Dns.Core.Records;
@@ -275,19 +275,6 @@ namespace BPASmart.VariableManager.ViewModels
public RelayCommand<object> RemoveCommand { get; set; } public RelayCommand<object> RemoveCommand { get; set; }
#endregion #endregion


//private void SetValue<TArray>(TArray[] arrays, ReadDataModel readDataModel, ushort by)
//{
// for (int i = 0; i < arrays.Length; i++)
// {
// int varIndex = Array.FindIndex(varialeInfos.ToArray(), p => p.RealAddress == (readDataModel.StartAddress + (i * by)).ToString());
// if (varIndex >= 0 && varIndex < varialeInfos.Count)
// {
// varialeInfos.ElementAt(varIndex).CurrentValue = arrays[i].ToString();
// }
// }

//}

private void SetValue(Array arrays, ReadDataModel readDataModel, EDataType eDataType) private void SetValue(Array arrays, ReadDataModel readDataModel, EDataType eDataType)
{ {
if (arrays != null) if (arrays != null)
@@ -301,107 +288,9 @@ namespace BPASmart.VariableManager.ViewModels
varialeInfos.ElementAt(varIndex).CurrentValue = arrays.GetValue(i)?.ToString(); varialeInfos.ElementAt(varIndex).CurrentValue = arrays.GetValue(i)?.ToString();
} }
} }




//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)).ToString());
// if (varIndex >= 0 && varIndex < tempArray.Length)
// {
// Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels.ElementAt(varIndex).CurrentValue = arrays.GetValue(i)?.ToString();
// }
// }
// var Devicename = Json<CommunicationPar>.Data.CommunicationDevices[index].DeviceName;
// List<ReeisDataModel> reeisDataModels = new List<ReeisDataModel>();
// Json<CommunicationPar>.Data.CommunicationDevices[index].VarTableModels.ToList().ForEach(tempVar =>
// {
// if (tempVar.VarName.Length > 0)
// {
// reeisDataModels.Add(new ReeisDataModel()
// {
// VarName = tempVar.VarName,
// VarVaule = tempVar.CurrentValue,
// DataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.DataType)
// });
// }
// });
// RedisHelper.GetInstance.SetValue($"{Devicename}", reeisDataModels);
//}
} }
} }


//private Dictionary<EDataType, List<ReadDataModel>> GetReadDataModels()
//{
// Dictionary<EDataType, List<ReadDataModel>> readDataModels = new Dictionary<EDataType, List<ReadDataModel>>();
// varialeInfos.GroupBy(p => p.DataType)?.ToList()?.ForEach(tempVar =>
// {
// if (tempVar.Key != null && tempVar.Key.Length > 0)
// {
// 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();
// List<int> RealAddresss = new List<int>();
// variableInfos.ToList()?.ForEach(item => { if (int.TryParse(item.RealAddress, out int add)) RealAddresss.Add(add); });
// int count = 0;
// if (res != null)
// {
// int address = RealAddresss.Min();
// int startAddress = address;
// for (int i = 0; i < res.Count; i++)
// {
// if (int.TryParse(res.ElementAt(i).RealAddress, out int TempAddress))
// {
// if (TempAddress == address)
// {
// count++;
// address += by;
// }
// else
// {
// ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
// count = 1;
// address = TempAddress + by;
// startAddress = TempAddress;
// }
// }

// }
// ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
// }
// return ReturnValue;
//}



/// <summary> /// <summary>
/// 下拉列表初始化 /// 下拉列表初始化
/// </summary> /// </summary>


+ 2
- 2
BPASmart.VariableManager/Views/CommunicationSetView.xaml.cs View File

@@ -1,5 +1,5 @@
using BPASmart.Model; using BPASmart.Model;
using BPASmartClient.Helper;
using BPA.Helper;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -30,7 +30,7 @@ namespace BPASmart.VariableManager.Views


private void CommunicationSetView_Unloaded(object sender, RoutedEventArgs e) private void CommunicationSetView_Unloaded(object sender, RoutedEventArgs e)
{ {
Json<CommunicationPar>.Save();
Json<CommunicationPar>.Save(FileConfigModel.GetPath);
} }
} }
} }

+ 2
- 2
BPASmart.VariableManager/Views/VariableConfig.xaml.cs View File

@@ -1,6 +1,6 @@
using BPASmart.Model; using BPASmart.Model;
using BPASmart.VariableManager.ViewModels; using BPASmart.VariableManager.ViewModels;
using BPASmartClient.Helper;
using BPA.Helper;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@@ -33,7 +33,7 @@ namespace BPASmart.VariableManager.Views


private void VariableConfig_Unloaded(object sender, RoutedEventArgs e) private void VariableConfig_Unloaded(object sender, RoutedEventArgs e)
{ {
Json<CommunicationPar>.Save();
Json<CommunicationPar>.Save(FileConfigModel.GetPath);
} }


private void VariableConfig_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) private void VariableConfig_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)


Loading…
Cancel
Save