change - PLC参数配置

master
wenjy 2 years ago
parent 1a3078f68b
commit fa896fd9ba

@ -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; }
}
}

@ -62,6 +62,7 @@
<Compile Include="DAO\SysClient.cs" />
<Compile Include="DAO\SysUserInfo.cs" />
<Compile Include="DTO\AppConfigDto.cs" />
<Compile Include="DTO\ParamValueDto.cs" />
<Compile Include="DTO\ProDownRecordDto.cs" />
<Compile Include="DTO\SingalStep.cs" />
<Compile Include="DTO\ViewModelDto.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);
/// <summary>
/// 写INI文件
@ -77,5 +79,25 @@ namespace MaterialTraceabilityUI.Common
{
IniWriteValue(Section, null, null);
}
public List<string> ReadKeys(String SectionName)
{
return ReadKeys(SectionName, this.path);
}
public List<string> ReadKeys(string SectionName, string iniFilename)
{
List<string> result = new List<string>();
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;
}
}
}

@ -171,40 +171,116 @@
</TabItem>
</TabControl>
<Button Content="修改" Width="130" Height="50" BorderThickness="0" Background="#007DFA" Foreground="White" x:Name="SaveConfigInfo" HorizontalAlignment="Left" Margin="1093,454,0,0" VerticalAlignment="Top" Click="SaveConfigInfo_Click" RenderTransformOrigin="0.923,0.493"/>
<GroupBox Header="系统参数" HorizontalAlignment="Left" Height="490" Margin="40,11,0,0" VerticalAlignment="Top" Width="394">
<Grid Margin="-6,1,6,-47.667">
<!--PLC地址 PlcAddress-->
<Label Content="PLC地址" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="68,12,0,467"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamPlcAddress" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,10,0,478"/>
<!--MachineID-->
<Label Content="设备编号:" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="68,62,0,417"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamMachineID" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,62,0,426"/>
<!--ProcessID-->
<Label Content="工序编号:" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="79,112,0,367"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamProcessID" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,112,0,376"/>
<!--resource-->
<Label Content="资源号:" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="92,163,0,316"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamResource" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,163,0,325"/>
<!--operation-->
<Label Content="操作号:" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="92,215,0,264"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamOperation" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,215,0,273"/>
<!--operationByA-->
<Label Content="A面操作" x:Name="operationByA" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="79,263,0,216"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamOperationByA" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,263,0,225"/>
<!--operationByB-->
<Label Content="B面操作" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="79,305,0,174"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamOperationByB" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,303,0,185" RenderTransformOrigin="0.523,1.5"/>
<!--isMesFlag-->
<Label Content="MES标识" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="68,343,0,136"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamIsMesFlag" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,352,0,136" RenderTransformOrigin="0.523,1.5"/>
<!--plcSingalReadTime-->
<Label Content="PLC读取时间" Height="35" FontSize="18" Foreground="#007DFA" Width="138" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="41,389,0,90"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamPlcSingalReadTime" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,398,0,90" RenderTransformOrigin="0.523,1.5"/>
<!--mes接口超时时间,单位ms-->
<Label Content="MES接口超时时间" Height="35" FontSize="18" Foreground="#007DFA" Width="165" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="3,429,0,50"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamMesWebServiceTimeOut" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,438,0,50" RenderTransformOrigin="0.523,1.5"/>
</Grid>
</GroupBox>
<TabControl HorizontalAlignment="Left" Height="490" Margin="40,21,0,0" VerticalAlignment="Top" Width="394">
<TabItem Header="系统参数">
<Grid Margin="-6,1,6,-47.667">
<!--PLC地址 PlcAddress-->
<Label Content="PLC地址" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="68,12,0,467"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamPlcAddress" HorizontalAlignment="Left" VerticalAlignment="Top" Width="199" Margin="168,10,0,0"/>
<!--MachineID-->
<Label Content="设备编号:" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="68,62,0,417"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamMachineID" HorizontalAlignment="Left" VerticalAlignment="Top" Width="199" Margin="168,60,0,0"/>
<!--ProcessID-->
<Label Content="工序编号:" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="79,112,0,367"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamProcessID" HorizontalAlignment="Left" VerticalAlignment="Top" Width="199" Margin="168,110,0,0"/>
<!--resource-->
<Label Content="资源号:" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="92,163,0,316"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamResource" HorizontalAlignment="Left" VerticalAlignment="Top" Width="199" Margin="168,161,0,0"/>
<!--operation-->
<Label Content="操作号:" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="92,215,0,264"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamOperation" HorizontalAlignment="Left" VerticalAlignment="Top" Width="199" Margin="168,213,0,0"/>
<!--operationByA-->
<Label Content="A面操作" x:Name="operationByA" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="79,263,0,216"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamOperationByA" HorizontalAlignment="Left" VerticalAlignment="Top" Width="199" Margin="168,261,0,0"/>
<!--operationByB-->
<Label Content="B面操作" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="79,305,0,174"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamOperationByB" HorizontalAlignment="Left" VerticalAlignment="Top" Width="199" Margin="168,303,0,0" RenderTransformOrigin="0.523,1.5"/>
<!--isMesFlag-->
<Label Content="MES标识" Height="35" FontSize="18" Foreground="#007DFA" Width="100" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="68,343,0,136"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamIsMesFlag" HorizontalAlignment="Left" VerticalAlignment="Top" Width="199" Margin="168,345,0,0" RenderTransformOrigin="0.523,1.5"/>
<!--plcSingalReadTime-->
<Label Content="PLC读取时间" Height="35" FontSize="18" Foreground="#007DFA" Width="138" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="41,389,0,90"/>
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamPlcSingalReadTime" HorizontalAlignment="Left" VerticalAlignment="Top" Width="199" Margin="168,387,0,0" RenderTransformOrigin="0.523,1.5"/>
<!--mes接口超时时间,单位ms-->
<Label Content="MES接口超时时间" Height="35" FontSize="18" Foreground="#007DFA" Width="165" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="1.347,-4.605" Margin="3,429,0,50"/>
<!--<TextBox Height="26" FontSize="18" x:Name="AppConfigParamMesWebServiceTimeOut" HorizontalAlignment="Left" VerticalAlignment="Center" Width="199" Margin="168,438,0,50" RenderTransformOrigin="0.523,1.5"/>-->
<TextBox Height="26" FontSize="18" x:Name="AppConfigParamMesWebServiceTimeOut" HorizontalAlignment="Left" VerticalAlignment="Top" Width="199" Margin="168,431,0,0"/>
</Grid>
</TabItem>
<TabItem Header="PLC参数">
<Grid>
<Border Grid.Row="1" Margin="0,5,0,0" BorderBrush="#007DFA" BorderThickness="1" CornerRadius="0" Background="Transparent">
<DataGrid x:Name="PlcParamValue" Style="{DynamicResource DataGridStyle}" ColumnHeaderHeight="22" RowHeight="20" AutoGenerateColumns="False" RowHeaderWidth="0" GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="0">
<DataGrid.Resources>
<Style x:Key="DataGridStyle" TargetType="DataGrid">
<Setter Property="AlternationCount" Value="2"/>
<Setter Property="ColumnHeaderStyle" Value="{DynamicResource DataGridColumnHeaderStyle}"/>
<Setter Property="CellStyle" Value="{DynamicResource DataGridCellStyle}"/>
<Setter Property="RowStyle" Value="{DynamicResource DataGridRowStyle}"/>
</Style>
<Style x:Key="DataGridColumnHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Background" Value="White"/>
</Style>
<Style x:Key="DataGridRowStyle" TargetType="{x:Type DataGridRow}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Grid x:Name="DGR_Border" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1"/>
<DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderBrush" Value="#00BCD4"/>
</Trigger>
<Trigger Property="AlternationIndex" Value="0">
<Setter Property="Background" Value="#E9F3FD"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsNewItem" Value="True">
<Setter Property="Margin" Value="{Binding NewItemMargin, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Gray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding paramName}" Header="参数名" Width="*"/>
<DataGridTextColumn Binding="{Binding paramValue}" Header="参数值" Width="*"/>
</DataGrid.Columns>
</DataGrid>
</Border>
</Grid>
</TabItem>
</TabControl>
</Grid>
</UserControl>

@ -1,4 +1,5 @@
using MaterialTraceability.Business;
using MaterialTraceability.Entity.DTO;
using MaterialTraceabilityUI.Common;
using System;
using System.Collections.Generic;
@ -27,11 +28,26 @@ namespace MaterialTraceabilityUI
/// </summary>
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<ParamValueDto> plcParamValues = this.PlcParamValue.ItemsSource as List<ParamValueDto>;
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<string> plcParamValues = inifile2.ReadKeys(iniSection);
List<ParamValueDto> paramValues = new List<ParamValueDto>();
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;
}
}
}

Loading…
Cancel
Save