Browse Source

变量配置表修改

样式分支
pry 2 years ago
parent
commit
3642f25212
21 changed files with 182 additions and 118 deletions
  1. +2
    -0
      BPASmart.ConfigurationSoftware/App.xaml.cs
  2. +3
    -8
      BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj
  3. +15
    -15
      BPASmart.ConfigurationSoftware/BasicInformation.cs
  4. +76
    -76
      BPASmart.ConfigurationSoftware/FileHelper.cs
  5. +0
    -0
      BPASmart.ConfigurationSoftware/Images/fyf.ico
  6. +14
    -1
      BPASmart.ConfigurationSoftware/Servers/ServiceCenter.cs
  7. +0
    -0
      BPASmart.ConfigurationSoftware/View/MainWindow.xaml
  8. +0
    -0
      BPASmart.ConfigurationSoftware/View/MainWindow.xaml.cs
  9. +0
    -0
      BPASmart.ConfigurationSoftware/View/NewPageView.xaml
  10. +0
    -0
      BPASmart.ConfigurationSoftware/View/NewPageView.xaml.cs
  11. +0
    -0
      BPASmart.ConfigurationSoftware/View/NewProjectView.xaml
  12. +0
    -0
      BPASmart.ConfigurationSoftware/View/NewProjectView.xaml.cs
  13. +0
    -0
      BPASmart.ConfigurationSoftware/ViewModel/MainWindowViewModel.cs
  14. +4
    -4
      BPASmart.ConfigurationSoftware/ViewModel/NewProjectViewModel.cs
  15. +19
    -0
      BPASmart.Model/ExpandMethod.cs
  16. +1
    -1
      BPASmart.PageLoad/BPASmart.PageLoad.csproj
  17. +1
    -1
      BPASmart.Server/BPASmart.Server.csproj
  18. +1
    -1
      BPASmart.VariableManager/BPASmart.VariableManager.csproj
  19. +32
    -5
      BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs
  20. +13
    -5
      BPASmart.VariableManager/Views/VariableConfig.xaml
  21. +1
    -1
      ComputerTestDemo/ComputerTestDemo.csproj

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

@@ -21,6 +21,7 @@ namespace BPASmart.ConfigurationSoftware
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Json<LocalPar>.Read();
if (e.Args != null && e.Args.Length == 1)
{
var res = e.Args[0];
@@ -34,6 +35,7 @@ namespace BPASmart.ConfigurationSoftware
protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
Json<LocalPar>.Save();
}
}
}

+ 3
- 8
BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj View File

@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>fyf.ico</ApplicationIcon>
<ApplicationIcon>Images\fyf.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
@@ -14,13 +14,13 @@
</ItemGroup>

<ItemGroup>
<Content Include="fyf.ico">
<Content Include="Images\fyf.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.11" />
<PackageReference Include="BPA.Helper" Version="1.0.15" />
</ItemGroup>

<ItemGroup>
@@ -32,11 +32,6 @@
<ProjectReference Include="..\BPASmart.VariableManager\BPASmart.VariableManager.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="ViewModel\" />
<Folder Include="View\" />
</ItemGroup>

<ItemGroup>
<Reference Include="Interop.IWshRuntimeLibrary">
<HintPath>..\BPASmartClient.Helper\obj\Debug\net6.0\Interop.IWshRuntimeLibrary.dll</HintPath>


+ 15
- 15
BPASmart.ConfigurationSoftware/BasicInformation.cs View File

@@ -1,18 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

namespace BPASmart.ConfigurationSoftware
{
public class BasicInformation
{
/// <summary>
/// 项目上次保存的目录
/// </summary>
public string ProjectDefaultPath { get; set; } = string.Empty;
//namespace BPASmart.ConfigurationSoftware
//{
// public class BasicInformation
// {
// /// <summary>
// /// 项目上次保存的目录
// /// </summary>
// public string ProjectDefaultPath { get; set; } = string.Empty;


}
}
// }
//}

+ 76
- 76
BPASmart.ConfigurationSoftware/FileHelper.cs View File

@@ -1,89 +1,89 @@
using BPA.Helper;
using BPASmart.Model;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using BPA.Helper;
//using BPASmart.Model;
//using Microsoft.Win32;
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Runtime.InteropServices;
//using System.Text;
//using System.Threading.Tasks;
//using System.Windows.Forms;

namespace BPASmart.ConfigurationSoftware
{
public class FileHelper
{
//namespace BPASmart.ConfigurationSoftware
//{
// public class FileHelper
// {

private volatile static FileHelper _Instance;
public static FileHelper GetInstance => _Instance ?? (_Instance = new FileHelper());
private FileHelper() { }
// private volatile static FileHelper _Instance;
// public static FileHelper GetInstance => _Instance ?? (_Instance = new FileHelper());
// private FileHelper() { }

public void RegisterOpenFileType()
{
string icoFile = System.Windows.Forms.Application.StartupPath + $"\\fyf.ico";
string DirectoryPath = $"{Json<ProjectModel>.Data.ProjectPath}\\Images";
Directory.CreateDirectory(DirectoryPath);
File.Copy(icoFile, $"{DirectoryPath}\\fyf.ico");
RegisterFileType(".project", "HBL", ".project", System.Windows.Forms.Application.ExecutablePath, $"{DirectoryPath}\\fyf.ico");
}
// public void RegisterOpenFileType()
// {
// string icoFile = System.Windows.Forms.Application.StartupPath + $"\\Images\\fyf.ico";
// string DirectoryPath = $"{Json<ProjectModel>.Data.ProjectPath}\\Images";
// Directory.CreateDirectory(DirectoryPath);
// File.Copy(icoFile, $"{DirectoryPath}\\fyf.ico");
// RegisterFileType(".project", "HBL", ".project", System.Windows.Forms.Application.ExecutablePath, $"{DirectoryPath}\\fyf.ico");
// }

private void RegisterFileType(string typeName, string fileType, string fileContent, string app, string ico)
{
string toolPath = app;//工具启动路径
string extension = typeName;//fileType = "自定义文件类型";
// private void RegisterFileType(string typeName, string fileType, string fileContent, string app, string ico)
// {
// string toolPath = app;//工具启动路径
// string extension = typeName;//fileType = "自定义文件类型";

//fileContent = "AAAA";
//获取信息
RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(extension);
if (registryKey != null)
{
try
{
RegistryKey _Regkey = Registry.ClassesRoot.OpenSubKey("", true);
// //fileContent = "AAAA";
// //获取信息
// RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(extension);
// if (registryKey != null)
// {
// try
// {
// RegistryKey _Regkey = Registry.ClassesRoot.OpenSubKey("", true);

RegistryKey _VRPkey = _Regkey.OpenSubKey(extension);
if (_VRPkey != null) _Regkey.DeleteSubKeyTree(extension, true);
if (_VRPkey != null) _Regkey.DeleteSubKeyTree("Exec");
}
catch (Exception e)
{
// RegistryKey _VRPkey = _Regkey.OpenSubKey(extension);
// if (_VRPkey != null) _Regkey.DeleteSubKeyTree(extension, false);
// if (_VRPkey != null) _Regkey.DeleteSubKeyTree("Exec");
// }
// catch (Exception e)
// {

}
}
// }
// }

if (registryKey != null && registryKey.OpenSubKey("shell") != null && registryKey.OpenSubKey("shell").OpenSubKey("open") != null &&
registryKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command") != null)
{
var varSub = registryKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command");
var varValue = varSub.GetValue("");
// if (registryKey != null && registryKey.OpenSubKey("shell") != null && registryKey.OpenSubKey("shell").OpenSubKey("open") != null &&
// registryKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command") != null)
// {
// var varSub = registryKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command");
// var varValue = varSub.GetValue("");

if (Equals(varValue, toolPath + " \"%1\""))
{
return;
}
}
// if (Equals(varValue, toolPath + " \"%1\""))
// {
// return;
// }
// }

//文件注册
registryKey = Registry.ClassesRoot.CreateSubKey(extension);
registryKey.SetValue("", fileType);
registryKey.SetValue("Content Type", fileContent);
//设置默认图标
RegistryKey iconKey = registryKey.CreateSubKey("DefaultIcon");
//iconKey.SetValue("", Application.StartupPath + $"\\{ico}.ico");
iconKey.SetValue("", ico);
iconKey.Close();
//设置默认打开程序路径
registryKey = registryKey.CreateSubKey("shell\\open\\command");
registryKey.SetValue("", toolPath + " \"%1\"");
//关闭
registryKey.Close();
SHChangeNotify(0x8000000, 0, IntPtr.Zero, IntPtr.Zero);
}
// //文件注册
// registryKey = Registry.ClassesRoot.CreateSubKey(extension);
// registryKey.SetValue("", fileType);
// registryKey.SetValue("Content Type", fileContent);
// //设置默认图标
// RegistryKey iconKey = registryKey.CreateSubKey("DefaultIcon");
// //iconKey.SetValue("", Application.StartupPath + $"\\{ico}.ico");
// iconKey.SetValue("", ico);
// iconKey.Close();
// //设置默认打开程序路径
// registryKey = registryKey.CreateSubKey("shell\\open\\command");
// registryKey.SetValue("", toolPath + " \"%1\"");
// //关闭
// registryKey.Close();
// SHChangeNotify(0x8000000, 0, IntPtr.Zero, IntPtr.Zero);
// }

[DllImport("shell32.dll")]
public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
}
// [DllImport("shell32.dll")]
// public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
// }

}
//}


BPASmart.ConfigurationSoftware/fyf.ico → BPASmart.ConfigurationSoftware/Images/fyf.ico View File


BPASmart.ConfigurationSoftware/ServiceCenter.cs → BPASmart.ConfigurationSoftware/Servers/ServiceCenter.cs View File

@@ -167,11 +167,24 @@ namespace BPASmart.ConfigurationSoftware
ProjectNameChange?.Invoke(objModel.ProjectName);
FileConfigModel.ConstPath = $"{path}";
Save();
FileHelper.GetInstance.RegisterOpenFileType();
//FileHelper.GetInstance.RegisterOpenFileType();
RegisterOpenFileType();
}
}
}

/// <summary>
/// 注册使用默认应用程序打开自定义文件
/// </summary>
private void RegisterOpenFileType()
{
string icoFile = System.Windows.Forms.Application.StartupPath + $"\\Images\\fyf.ico";
string DirectoryPath = $"{Json<ProjectModel>.Data.ProjectPath}\\Images";
Directory.CreateDirectory(DirectoryPath);
File.Copy(icoFile, $"{DirectoryPath}\\fyf.ico");
SystemHelper.GetInstance.RegisterOpenFileType("project", "HBL", System.Windows.Forms.Application.ExecutablePath, $"{DirectoryPath}\\fyf.ico");
}

/// <summary>
/// 打开新建页面弹窗
/// </summary>

BPASmart.ConfigurationSoftware/MainWindow.xaml → BPASmart.ConfigurationSoftware/View/MainWindow.xaml View File


BPASmart.ConfigurationSoftware/MainWindow.xaml.cs → BPASmart.ConfigurationSoftware/View/MainWindow.xaml.cs View File


BPASmart.ConfigurationSoftware/NewPageView.xaml → BPASmart.ConfigurationSoftware/View/NewPageView.xaml View File


BPASmart.ConfigurationSoftware/NewPageView.xaml.cs → BPASmart.ConfigurationSoftware/View/NewPageView.xaml.cs View File


BPASmart.ConfigurationSoftware/NewProjectView.xaml → BPASmart.ConfigurationSoftware/View/NewProjectView.xaml View File


BPASmart.ConfigurationSoftware/NewProjectView.xaml.cs → BPASmart.ConfigurationSoftware/View/NewProjectView.xaml.cs View File


BPASmart.ConfigurationSoftware/MainWindowViewModel.cs → BPASmart.ConfigurationSoftware/ViewModel/MainWindowViewModel.cs View File


BPASmart.ConfigurationSoftware/NewProjectViewModel.cs → BPASmart.ConfigurationSoftware/ViewModel/NewProjectViewModel.cs View File

@@ -16,16 +16,16 @@ namespace BPASmart.ConfigurationSoftware
{
public NewProjectViewModel()
{
Json<BasicInformation>.Read();
NewData.ProjectPath = Json<BasicInformation>.Data.ProjectDefaultPath;
//Json<BasicInformation>.Read();
NewData.ProjectPath = Json<LocalPar>.Data.ProjectDefaultPath;
OpenBrowserDialogCommand = new RelayCommand(() =>
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
NewData.ProjectPath = folderBrowserDialog.SelectedPath;
Json<BasicInformation>.Data.ProjectDefaultPath = NewData.ProjectPath;
Json<BasicInformation>.Save();
Json<LocalPar>.Data.ProjectDefaultPath = NewData.ProjectPath;
//Json<LocalPar>.Save();
}
});


+ 19
- 0
BPASmart.Model/ExpandMethod.cs View File

@@ -37,6 +37,25 @@ namespace BPASmart.Model
return 1;
}

public static string ToSystemData(this EDataType eData)
{
switch (eData)
{
case EDataType.Bool: return "bool";
case EDataType.Byte: return "byte";
case EDataType.Int: return "short";
case EDataType.Word: return "ushort";
case EDataType.Dint: return "int";
case EDataType.Dword: return "uint";
case EDataType.Float: return "float";
case EDataType.Double: return "double";
case EDataType.String: return "string";
default:
break;
}
return default;
}

/// <summary>
/// 获取Modbus Tcp 连续变量数据的组对象
/// </summary>


+ 1
- 1
BPASmart.PageLoad/BPASmart.PageLoad.csproj View File

@@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.11" />
<PackageReference Include="BPA.Helper" Version="1.0.15" />
</ItemGroup>

<ItemGroup>


+ 1
- 1
BPASmart.Server/BPASmart.Server.csproj View File

@@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="BPA.Communication" Version="1.0.19" />
<PackageReference Include="BPA.Helper" Version="1.0.11" />
<PackageReference Include="BPA.Helper" Version="1.0.15" />
</ItemGroup>

<ItemGroup>


+ 1
- 1
BPASmart.VariableManager/BPASmart.VariableManager.csproj View File

@@ -30,7 +30,7 @@

<ItemGroup>
<PackageReference Include="BPA.Communication" Version="1.0.19" />
<PackageReference Include="BPA.Helper" Version="1.0.11" />
<PackageReference Include="BPA.Helper" Version="1.0.15" />
</ItemGroup>

<ItemGroup>


+ 32
- 5
BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs View File

@@ -21,21 +21,18 @@ namespace BPASmart.VariableManager.ViewModels
{
public class VariableConfigViewModel : NoticeBase
{
//PipeClient pipeClient = new PipeClient(PipeTopic.PipeName);
private int varialeInfosIndex = -1;
ICommunicationDevice DeviceType;
public VariableConfigViewModel(string o)
{
//pipeClient.StartPipeStream();
//MessageLog.GetInstance.NotifyShow = new Action<string>((o) => { if (pipeClient.IsConnected) pipeClient.SendCommand(o); });
ServiceCenter.GetInstance.Init();

DataInit(o);
VarNameChanged();

SaveCommand = new RelayCommand(() => { ServiceCenter.GetInstance.VarSave(); });

//DelegationNotifi.GetInstance.VariableSave = new Action(() => { Json<CommunicationPar>.Save(); });
GenerateEntityClassCommand = new RelayCommand(() => { GenerateEntityClass(); });

StartMotionCommand = new RelayCommand(() =>
{
switch (ButtonContext)
@@ -76,6 +73,34 @@ namespace BPASmart.VariableManager.ViewModels
});
}

private void GenerateEntityClass()
{
StringBuilder sb = new StringBuilder();
string deviceName = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(varialeInfosIndex).DeviceName;
sb.Append("using System;\r\n");
sb.Append("using System.Text;\r\n");
sb.Append("using System.Linq;\r\n");
sb.Append("namespace ProjectName\r\n");
sb.Append("{\r\n");
sb.Append($"public class {deviceName}\r\n");
sb.Append("{\r\n");
Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(varialeInfosIndex).VarTableModels.ToList().ForEach(item =>
{
if (!string.IsNullOrEmpty(item.VarName))
{
sb.Append("/// <summary>\r\n");
sb.Append($"/// {item.VarName}\r\n");
sb.Append("/// <summary>\r\n");
sb.Append($"public {item.DataType.ToEnum<EDataType>().ToSystemData()} {item.VarName}");
sb.Append("{get;set;}\r\n \r\n");
}
});
sb.Append("}\r\n");
sb.Append("}\r\n");
TextHelper.GetInstance.WriteTextInfo(sb.ToString(), $"{deviceName}.cs", "EntityClass");

}

private void DataInit(string o)
{
varialeInfosIndex = Array.FindIndex(Json<CommunicationPar>.Data.CommunicationDevices.ToArray(), p => p.DeviceName == o);
@@ -281,6 +306,8 @@ namespace BPASmart.VariableManager.ViewModels
public RelayCommand StartMotionCommand { get; set; }

public RelayCommand<object> RemoveCommand { get; set; }

public RelayCommand GenerateEntityClassCommand { get; set; }
#endregion

private void SetValue(Array arrays, ReadDataModel readDataModel, EDataType eDataType)


+ 13
- 5
BPASmart.VariableManager/Views/VariableConfig.xaml View File

@@ -155,6 +155,14 @@
</Grid.RowDefinitions>

<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<Button
Width="150"
Height="40"
Margin="10,0,10,0"
Command="{Binding GenerateEntityClassCommand}"
Content="生成实体类"
FontSize="20"
Style="{StaticResource ImageButtonStyle}" />
<Button
Width="150"
Height="40"
@@ -248,7 +256,7 @@
<!--#endregion-->

<Grid Grid.Row="2">
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<ItemsControl ItemsSource="{Binding varialeInfos}">
<ItemsControl.ItemTemplate>
<DataTemplate>
@@ -274,9 +282,9 @@

<Grid Grid.Column="1" KeyDown="TextBox_KeyDown">
<TextBox
IsEnabled="{Binding DataContext.IsEnable, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
Width="{Binding DataContext.NameWidth, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
Foreground="{Binding IsRedundant, Converter={StaticResource tabConvert}}"
IsEnabled="{Binding DataContext.IsEnable, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
Style="{StaticResource InputTextboxStyle}"
TabIndex="{Binding ID}"
Text="{Binding VarName}" />
@@ -288,10 +296,10 @@

<TextBox
Grid.Column="2"
IsEnabled="{Binding DataContext.IsEnable, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
KeyDown="TextBox_KeyDown"
Width="{Binding DataContext.AddressWidth, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
Foreground="{Binding IsRedundant, Converter={StaticResource tabConvert}}"
IsEnabled="{Binding DataContext.IsEnable, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
KeyDown="TextBox_KeyDown"
Style="{StaticResource InputTextboxStyle}"
TabIndex="{Binding ID}"
Text="{Binding Address}" />
@@ -304,9 +312,9 @@
BorderThickness="1"
FontFamily="楷体"
FontSize="20"
IsEnabled="{Binding DataContext.IsEnable,RelativeSource={RelativeSource AncestorType=ItemsControl,Mode=FindAncestor}}"
Foreground="{Binding IsRedundant, Converter={StaticResource tabConvert}}"
IsEditable="False"
IsEnabled="{Binding DataContext.IsEnable, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
ItemsSource="{Binding DataContext.dataType, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
SelectedValue="{Binding DataType}"
Style="{StaticResource ComboBoxStyle}"


+ 1
- 1
ComputerTestDemo/ComputerTestDemo.csproj View File

@@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="BPA.Communication" Version="1.0.19" />
<PackageReference Include="BPA.Helper" Version="1.0.11" />
<PackageReference Include="BPA.Helper" Version="1.0.15" />
</ItemGroup>

<ItemGroup>


Loading…
Cancel
Save