From b030e5923ac9aa0972ac038c9cbeab650b74ba53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Wed, 21 Sep 2022 09:34:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=AE=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmart.ConfigurationSoftware/App.xaml | 3 +- BPASmart.ConfigurationSoftware/App.xaml.cs | 27 +++++- .../BPASmart.ConfigurationSoftware.csproj | 11 +++ BPASmart.ConfigurationSoftware/FileHelper.cs | 88 ++++++++++++++++++ .../MainWindowViewModel.cs | 40 +++++--- BPASmart.ConfigurationSoftware/fyf.ico | Bin 0 -> 4286 bytes BPASmartClient.S7Net/SiemensHelper.cs | 11 ++- 7 files changed, 165 insertions(+), 15 deletions(-) create mode 100644 BPASmart.ConfigurationSoftware/FileHelper.cs create mode 100644 BPASmart.ConfigurationSoftware/fyf.ico diff --git a/BPASmart.ConfigurationSoftware/App.xaml b/BPASmart.ConfigurationSoftware/App.xaml index d9999060..5537954f 100644 --- a/BPASmart.ConfigurationSoftware/App.xaml +++ b/BPASmart.ConfigurationSoftware/App.xaml @@ -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"> diff --git a/BPASmart.ConfigurationSoftware/App.xaml.cs b/BPASmart.ConfigurationSoftware/App.xaml.cs index 36d2ed7b..cc3e269a 100644 --- a/BPASmart.ConfigurationSoftware/App.xaml.cs +++ b/BPASmart.ConfigurationSoftware/App.xaml.cs @@ -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 /// 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.Read(res); + + var rrr = Json.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); + } } } diff --git a/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj b/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj index 444235a8..7378c67c 100644 --- a/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj +++ b/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj @@ -6,8 +6,19 @@ enable true true + fyf.ico + + + + + + + PreserveNewest + + + diff --git a/BPASmart.ConfigurationSoftware/FileHelper.cs b/BPASmart.ConfigurationSoftware/FileHelper.cs new file mode 100644 index 00000000..bd851deb --- /dev/null +++ b/BPASmart.ConfigurationSoftware/FileHelper.cs @@ -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.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); + } + +} + diff --git a/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs b/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs index 4661f7b4..d4b24a38 100644 --- a/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs +++ b/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs @@ -21,7 +21,7 @@ namespace BPASmart.ConfigurationSoftware { public MainWindowViewModel() { - + Init(); ActionManage.GetInstance.Register(new Action((o) => { Pages.Add(o.ToString()); @@ -43,11 +43,9 @@ namespace BPASmart.ConfigurationSoftware Directory.CreateDirectory(path); Json.Data.ProjectPath = path; Json.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((o) => { - string path = $"{Global.ProjectPath}\\{Global.PageDirectoryName}\\{o.ToString()}.lay"; - mainCanvasPanels.Add(new MainCanvasPageModel() + string path = $"{Json.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.Data.ProjectName != null && Json.Data.ProjectName.Length > 0) + { + Head = Json.Data.ProjectName; + } + + if (Json.Data.Pages?.Count > 0) + { + for (int i = 0; i < Json.Data.Pages.Count; i++) + { + Pages.Add(Json.Data.Pages.ElementAt(i).Key); + } + } + + } + public void Save() { string path = Json.Data.ProjectPath; diff --git a/BPASmart.ConfigurationSoftware/fyf.ico b/BPASmart.ConfigurationSoftware/fyf.ico new file mode 100644 index 0000000000000000000000000000000000000000..346bbc6ca2a20235e7105d7fe7b5e70698805fb8 GIT binary patch literal 4286 zcmb_f2~bp57Ja645@kw8EJc{<-v}+pDk|U_QL)$G-GEzgUl47h0=9_31s9x(Nk-IB zL;qd@5fwqB#sx*XX>i2_T$)ypUBHTCnM@{D(DBXrXr{_4izzFEb!q8_f9^l`ob&D{ zqzC?ac@h3QIs7L=1`Ey4P$y2S1GZBq-QtG=K41Ue9?WbgF)1d#ttj9p@ICbA zB&!ah2dWcqpgPIsY@KY|CpZO;)6TNI<0w-Pet4@*x{8Zp?dVzaiz|R5ry*S`Fy#9c z3@O$MNYNsO7-b$kfgf&WBhpQZ2@wYQ)IftQt`4)HoMd^0PQ2zS=71i$=HLtbQJf+( zon!ZgbIPoqJhonKA)LyHSMxhq@B5)-9YfBnVo2$FL62kc%y95v$x#n}ZefE9&FrY& zMmd{`9;iV!=LhsK4qBL`6R&;tb`FVp#h%{4F9HY8asOscr4Q9d=k(C4-;dvMaWrW? zJ%ZF11e2QV08+KjmsmG=k#nmB;U_grLBTwxDsP(bOtx}x&>1no45n;C57Z!^e#0Q2 z*%vzKr;{XC>%{ALEulDhPIWSp40A?|$uTA9w2pq4&9D#{a}pMpU>!&^ue@6_Ty=mY5WuZa@#zC|6e+ zr$XW8MF|7TXzC2K#9T&&!e|$Eq zrlBar@!&v!SgnQzo;5KK#!}mI`R4>_@NUVEQAk3Foy=rfr0}H4yZo*AT`7mpo;2HVI3u5q@#3f zLR)coXVdXvv^GDm3LLBj2Pv2T>OJ{FiooqmqTtqdOBi}|KBIvS(k#kA3N4yU3VAQ+ zV1Pk3y9zu|^Z@+Sq&I%pd=;~B1qV^!AO#$x>Q%;jdUX!f$K?NNh&{T*5PJyN}lI5bQWtFdU~Zm13!KNEo?9=0{)Cls6r3* zM!BjDUZ8r}TrDSA3I3CLE#5^B?mFqVft>7XcyjlNw{xgP4*`4@z?Y=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F|H3J+p!ILN8NzeB4;o1DI^5{tL zkMM&Weo$jq`DfWCFN$omoLt6uBAZWOXKcb8GQa_N7{~981iA3OmG_?!F{JHWSk2pA<=$QWP{++(Lnw9?M_Ia11V0SJ-npAm_;K%Gb@xL9uyHQoY~b@iO#b6JQf)aS{Bm0J9*S52MH(&hLY+#s4yW?n-In g$CTo~uLy~JPKYaCAAF(z@dv+Mm&f3-x-fzLA9GS*Pyhe` literal 0 HcmV?d00001 diff --git a/BPASmartClient.S7Net/SiemensHelper.cs b/BPASmartClient.S7Net/SiemensHelper.cs index c5926b92..18e1c347 100644 --- a/BPASmartClient.S7Net/SiemensHelper.cs +++ b/BPASmartClient.S7Net/SiemensHelper.cs @@ -32,7 +32,16 @@ namespace BPASmartClient.S7Net public TResult Read(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)