From fa896fd9baa400ccdc397fc897016cade651b148 Mon Sep 17 00:00:00 2001 From: wenjy Date: Sat, 18 Mar 2023 20:05:59 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20PLC=E5=8F=82=E6=95=B0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DTO/ParamValueDto.cs | 15 ++ .../MaterialTraceability.Entity.csproj | 1 + .../Common/IniFileHelper.cs | 22 +++ MaterialTraceabilityUI/ConfigInfo.xaml | 146 +++++++++++++----- MaterialTraceabilityUI/ConfigInfo.xaml.cs | 39 ++++- 5 files changed, 187 insertions(+), 36 deletions(-) create mode 100644 MaterialTraceability.Entity/DTO/ParamValueDto.cs diff --git a/MaterialTraceability.Entity/DTO/ParamValueDto.cs b/MaterialTraceability.Entity/DTO/ParamValueDto.cs new file mode 100644 index 0000000..3143d8a --- /dev/null +++ b/MaterialTraceability.Entity/DTO/ParamValueDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MaterialTraceability.Entity.DTO +{ + public class ParamValueDto + { + public string paramName { get; set; } + + public string paramValue { get; set; } + } +} diff --git a/MaterialTraceability.Entity/MaterialTraceability.Entity.csproj b/MaterialTraceability.Entity/MaterialTraceability.Entity.csproj index f310f0b..38d6c7c 100644 --- a/MaterialTraceability.Entity/MaterialTraceability.Entity.csproj +++ b/MaterialTraceability.Entity/MaterialTraceability.Entity.csproj @@ -62,6 +62,7 @@ + diff --git a/MaterialTraceabilityUI/Common/IniFileHelper.cs b/MaterialTraceabilityUI/Common/IniFileHelper.cs index 9870f61..5455c66 100644 --- a/MaterialTraceabilityUI/Common/IniFileHelper.cs +++ b/MaterialTraceabilityUI/Common/IniFileHelper.cs @@ -29,6 +29,8 @@ namespace MaterialTraceabilityUI.Common [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath); + [DllImport("kernel32", EntryPoint = "GetPrivateProfileString")] + private static extern uint GetPrivateProfileStringA(string section, string key,string def, Byte[] retVal, int size, string filePath); /// /// 写INI文件 @@ -77,5 +79,25 @@ namespace MaterialTraceabilityUI.Common { IniWriteValue(Section, null, null); } + + public List ReadKeys(String SectionName) + { + return ReadKeys(SectionName, this.path); + } + + public List ReadKeys(string SectionName, string iniFilename) + { + List result = new List(); + Byte[] buf = new Byte[65536]; + uint len = GetPrivateProfileStringA(SectionName, null, null, buf, buf.Length, iniFilename); + int j = 0; + for (int i = 0; i < len; i++) + if (buf[i] == 0) + { + result.Add(Encoding.Default.GetString(buf, j, i - j)); + j = i + 1; + } + return result; + } } } \ No newline at end of file diff --git a/MaterialTraceabilityUI/ConfigInfo.xaml b/MaterialTraceabilityUI/ConfigInfo.xaml index eebb8b0..ebd022f 100644 --- a/MaterialTraceabilityUI/ConfigInfo.xaml +++ b/MaterialTraceabilityUI/ConfigInfo.xaml @@ -171,40 +171,116 @@ private IniFileHelper inifile = new IniFileHelper(System.Environment.CurrentDirectory + "/MesConfig/App.InI"); private IniFileHelper inifile2 = new IniFileHelper(System.Environment.CurrentDirectory + "/App.InI"); + private AppConfigDto appConfig = AppConfigDto.Instance; + private string iniSection = ""; public ConfigInfo() { InitializeComponent(); - + switch(appConfig.processId) + { + case "TB": + iniSection = "TBPLcAddress"; + break; + case "LY_A": + iniSection = "LYPLcAddress"; + break; + case "MQ_A": + iniSection = "MQPLcAddress"; + break; + default: + break; + } } private void SaveConfigInfo_Click(object sender, RoutedEventArgs e) @@ -108,6 +124,15 @@ namespace MaterialTraceabilityUI inifile2.IniWriteValue("SystemConfig", "isMesFlag", this.AppConfigParamIsMesFlag.Text); inifile2.IniWriteValue("SystemConfig", "plcSingalReadTime", this.AppConfigParamPlcSingalReadTime.Text); inifile2.IniWriteValue("SystemConfig", "MesWebServiceTimeOut", this.AppConfigParamMesWebServiceTimeOut.Text); + + + List plcParamValues = this.PlcParamValue.ItemsSource as List; + + foreach(ParamValueDto item in plcParamValues) + { + inifile2.IniWriteValue(iniSection, item.paramName,item.paramValue); + } + MessageBox.Show("更新成功,重启生效"); } catch(Exception ex) @@ -188,6 +213,18 @@ namespace MaterialTraceabilityUI this.AppConfigParamOperationByA.Text = inifile2.IniReadValue("SystemConfig", "operationByA"); this.AppConfigParamOperationByB.Text = inifile2.IniReadValue("SystemConfig", "operationByB"); this.AppConfigParamMesWebServiceTimeOut.Text = inifile2.IniReadValue("SystemConfig", "MesWebServiceTimeOut"); + + //获取PLC配置 + List plcParamValues = inifile2.ReadKeys(iniSection); + List paramValues = new List(); + foreach(string item in plcParamValues) + { + ParamValueDto paramValueDto = new ParamValueDto(); + paramValueDto.paramName = item; + paramValueDto.paramValue = inifile2.IniReadValue(iniSection, item); + paramValues.Add(paramValueDto); + } + this.PlcParamValue.ItemsSource = paramValues; } } }