@@ -2,7 +2,6 @@ | |||
x:Class="BPASmart.ConfigurationSoftware.App" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:local="clr-namespace:BPASmart.ConfigurationSoftware" | |||
StartupUri="MainWindow.xaml"> | |||
xmlns:local="clr-namespace:BPASmart.ConfigurationSoftware"> | |||
<Application.Resources /> | |||
</Application> |
@@ -1,4 +1,5 @@ | |||
using System; | |||
using BPA.Helper; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Configuration; | |||
using System.Data; | |||
@@ -13,5 +14,29 @@ namespace BPASmart.ConfigurationSoftware | |||
/// </summary> | |||
public partial class App : Application | |||
{ | |||
protected override void OnStartup(StartupEventArgs e) | |||
{ | |||
base.OnStartup(e); | |||
if (e.Args != null && e.Args.Length == 1) | |||
{ | |||
var res = e.Args[0]; | |||
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); | |||
}); | |||
} | |||
MainWindow window = new MainWindow(); | |||
window.Show(); | |||
} | |||
protected override void OnExit(ExitEventArgs e) | |||
{ | |||
base.OnExit(e); | |||
} | |||
} | |||
} |
@@ -6,8 +6,19 @@ | |||
<Nullable>enable</Nullable> | |||
<UseWPF>true</UseWPF> | |||
<UseWindowsForms>true</UseWindowsForms> | |||
<ApplicationIcon>fyf.ico</ApplicationIcon> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<None Remove="fyf.ico" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Content Include="fyf.ico"> | |||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |||
</Content> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Helper" Version="1.0.8" /> | |||
</ItemGroup> | |||
@@ -0,0 +1,88 @@ | |||
using BPA.Helper; | |||
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 | |||
{ | |||
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"); | |||
} | |||
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); | |||
RegistryKey _VRPkey = _Regkey.OpenSubKey(extension); | |||
if (_VRPkey != null) _Regkey.DeleteSubKeyTree(extension, true); | |||
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 (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); | |||
} | |||
[DllImport("shell32.dll")] | |||
public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2); | |||
} | |||
} | |||
@@ -21,7 +21,7 @@ namespace BPASmart.ConfigurationSoftware | |||
{ | |||
public MainWindowViewModel() | |||
{ | |||
Init(); | |||
ActionManage.GetInstance.Register(new Action<object>((o) => | |||
{ | |||
Pages.Add(o.ToString()); | |||
@@ -43,11 +43,9 @@ namespace BPASmart.ConfigurationSoftware | |||
Directory.CreateDirectory(path); | |||
Json<ProjectModel>.Data.ProjectPath = path; | |||
Json<ProjectModel>.Data.ProjectName = objModel.ProjectName; | |||
//Global.ProjectPath = path; | |||
Head = objModel.ProjectName; | |||
//Global.ProjectName = objModel.ProjectName; | |||
Save(); | |||
FileHelper.GetInstance.RegisterOpenFileType(); | |||
} | |||
} | |||
}); | |||
@@ -76,17 +74,20 @@ namespace BPASmart.ConfigurationSoftware | |||
SelectedPageCommand = new RelayCommand<object>((o) => | |||
{ | |||
string path = $"{Global.ProjectPath}\\{Global.PageDirectoryName}\\{o.ToString()}.lay"; | |||
mainCanvasPanels.Add(new MainCanvasPageModel() | |||
string path = $"{Json<ProjectModel>.Data.ProjectPath}\\{Global.PageDirectoryName}\\{o.ToString()}.lay"; | |||
if (mainCanvasPanels.FirstOrDefault(p => p.PageName == o.ToString()) == null) | |||
{ | |||
MainCanvasPanelModel = new MainCanvasPanel(path), | |||
PageName = o.ToString(), | |||
}); | |||
mainCanvasPanels.Add(new MainCanvasPageModel() | |||
{ | |||
MainCanvasPanelModel = new MainCanvasPanel(path), | |||
PageName = o.ToString(), | |||
}); | |||
} | |||
var res = mainCanvasPanels.FirstOrDefault(p => p.PageName == o.ToString()); | |||
if (res != null) | |||
{ | |||
//ConstructorInfo cti = res.MainCanvasPanelModel.GetType()?.GetConstructor(System.Type.EmptyTypes); | |||
MainContent = res.MainCanvasPanelModel;// (FrameworkElement)cti?.Invoke(null); | |||
MainContent = res.MainCanvasPanelModel; | |||
} | |||
}); | |||
@@ -100,6 +101,23 @@ namespace BPASmart.ConfigurationSoftware | |||
}); | |||
} | |||
private void Init() | |||
{ | |||
if (Json<ProjectModel>.Data.ProjectName != null && Json<ProjectModel>.Data.ProjectName.Length > 0) | |||
{ | |||
Head = Json<ProjectModel>.Data.ProjectName; | |||
} | |||
if (Json<ProjectModel>.Data.Pages?.Count > 0) | |||
{ | |||
for (int i = 0; i < Json<ProjectModel>.Data.Pages.Count; i++) | |||
{ | |||
Pages.Add(Json<ProjectModel>.Data.Pages.ElementAt(i).Key); | |||
} | |||
} | |||
} | |||
public void Save() | |||
{ | |||
string path = Json<ProjectModel>.Data.ProjectPath; | |||
@@ -32,7 +32,16 @@ namespace BPASmartClient.S7Net | |||
public TResult Read<TResult>(string address) | |||
{ | |||
if (!IsConnected) return default; | |||
return (TResult)myPlc?.Read(address); | |||
var value = myPlc?.Read(address); | |||
if (typeof(TResult).Name == "Single") | |||
{ | |||
var obj = ((uint)value).ConvertToFloat(); | |||
return (TResult)Convert.ChangeType(obj, typeof(TResult)); | |||
} | |||
else | |||
{ | |||
return (TResult)Convert.ChangeType(value, typeof(TResult)); | |||
} | |||
} | |||
public bool[] ReadBools(int address, int count) | |||