This commit is contained in:
@@ -2,11 +2,15 @@
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<!--压力PLC-->
|
||||
<add key="PLC1_IP" value="192.168.1.100"/>
|
||||
<!--<add key="PLC1_IP" value="192.168.1.100"/>-->
|
||||
<add key="PLC1_IP" value="127.0.0.1"/>
|
||||
<add key="PLC1_Port" value="502"/>
|
||||
|
||||
<!--二氧化碳PLC-->
|
||||
<add key="PLC2_IP" value="192.168.1.100"/>
|
||||
<!--<add key="PLC2_IP" value="192.168.1.100"/>-->
|
||||
<add key="PLC2_IP" value="127.0.0.1"/>
|
||||
<add key="PLC2_Port" value="502"/>
|
||||
|
||||
<add key="Language" value="zh-CN"/>
|
||||
</appSettings>
|
||||
</configuration>
|
||||
2
App.xaml
2
App.xaml
@@ -22,7 +22,7 @@
|
||||
<!-- 鼠标指针 -->
|
||||
<Setter Property="Height" Value="40"/>
|
||||
<!-- 按钮高度 -->
|
||||
<Setter Property="Width" Value="180"/>
|
||||
<Setter Property="Width" Value="320"/>
|
||||
<!-- 按钮宽度 -->
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
|
||||
12
App.xaml.cs
12
App.xaml.cs
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Security.Principal;
|
||||
@@ -53,6 +54,17 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
RestartAsAdmin();
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
// 加载保存的语言
|
||||
string savedLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
||||
var resourceDict = new ResourceDictionary
|
||||
{
|
||||
Source = new Uri($"/Resources/Strings.{savedLanguage}.xaml", UriKind.Relative)
|
||||
};
|
||||
|
||||
Current.Resources.MergedDictionaries.Clear();
|
||||
Current.Resources.MergedDictionaries.Add(resourceDict);
|
||||
|
||||
}
|
||||
|
||||
private bool IsRunAsAdmin()
|
||||
|
||||
54
Main.xaml
54
Main.xaml
@@ -1,14 +1,51 @@
|
||||
<Window x:Class="ShanghaiEnvironmentalTechnology.Main"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="睡眠呼吸暂停治疗面桌多功能测试仪"
|
||||
Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen"
|
||||
>
|
||||
<!-- 背景色 -->
|
||||
Title="{DynamicResource WindowTitle}"
|
||||
Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<Window.Resources>
|
||||
<Style x:Key="ControlCombStyle" TargetType="ComboBox">
|
||||
<Setter Property="Background" Value="#FF4A86E8"/>
|
||||
<Setter Property="Foreground" Value="Orange" />
|
||||
<Setter Property="FontSize" Value="16"/>
|
||||
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Height" Value="32"/>
|
||||
<Setter Property="Width" Value="100"/>
|
||||
<Setter Property="Margin" Value="4"/>
|
||||
</Style>
|
||||
<Style x:Key="ControlCombItemStyle" TargetType="ComboBoxItem">
|
||||
<Setter Property="Background" Value="#FF4A86E8"/>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
<Setter Property="FontSize" Value="16"/>
|
||||
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Height" Value="32"/>
|
||||
<Setter Property="Width" Value="80"/>
|
||||
<Setter Property="Margin" Value="4"/>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<!-- 右上角语言选择下拉框 -->
|
||||
<ComboBox Name="cmbMaterial"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Margin="10,10,10,0"
|
||||
Width="100"
|
||||
Style="{StaticResource ControlCombStyle}"
|
||||
SelectionChanged="cmbMaterial_SelectionChanged">
|
||||
<ComboBoxItem Style="{StaticResource ControlCombItemStyle}">中文</ComboBoxItem>
|
||||
<ComboBoxItem Style="{StaticResource ControlCombItemStyle}">English</ComboBoxItem>
|
||||
</ComboBox>
|
||||
|
||||
<!-- 标题文本(带呼吸动画) -->
|
||||
<TextBlock x:Name="BreathingText"
|
||||
Text="睡眠呼吸暂停治疗面桌多功能测试仪"
|
||||
Text="{DynamicResource WindowTitle}"
|
||||
FontSize="24"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center"
|
||||
@@ -21,7 +58,8 @@
|
||||
</TextBlock.RenderTransform>
|
||||
</TextBlock>
|
||||
|
||||
<Button Content="进入"
|
||||
<!-- 底部进入按钮 -->
|
||||
<Button Content="{DynamicResource Deformation7}"
|
||||
Width="100"
|
||||
Height="40"
|
||||
HorizontalAlignment="Center"
|
||||
@@ -29,9 +67,9 @@
|
||||
Margin="0,0,0,30"
|
||||
Style="{StaticResource MyButtonStyle}"
|
||||
Click="Button_Click"/>
|
||||
<!-- 设置Click事件 -->
|
||||
</Grid>
|
||||
|
||||
<!-- 窗口加载时启动标题缩放动画(呼吸效果) -->
|
||||
<Window.Triggers>
|
||||
<EventTrigger RoutedEvent="Window.Loaded">
|
||||
<BeginStoryboard>
|
||||
@@ -48,4 +86,4 @@
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</Window.Triggers>
|
||||
</Window>
|
||||
</Window>
|
||||
41
Main.xaml.cs
41
Main.xaml.cs
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -30,6 +31,27 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
ImageBrush brush = new ImageBrush();
|
||||
brush.ImageSource = new BitmapImage(new Uri(imagePath, UriKind.Absolute));
|
||||
this.Background = brush;
|
||||
|
||||
|
||||
// 设置语言选择框的默认选中项
|
||||
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
||||
|
||||
foreach (ComboBoxItem item in cmbMaterial.Items)
|
||||
{
|
||||
if ((currentLanguage == "zh-CN" && item.Content.ToString() == "中文") ||
|
||||
(currentLanguage == "en-US" && item.Content.ToString() == "English"))
|
||||
{
|
||||
cmbMaterial.SelectedItem = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(currentLanguage))
|
||||
ResourceManager.SwitchLanguage(currentLanguage);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,5 +68,24 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
|
||||
this.Close(); // 如果您希望在打开新窗口时关闭当前窗口
|
||||
}
|
||||
|
||||
|
||||
private void cmbMaterial_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
string selectedText = (cmbMaterial.SelectedItem as ComboBoxItem)?.Content.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(selectedText))
|
||||
return;
|
||||
|
||||
if (selectedText == "中文" || selectedText == "Chinese")
|
||||
{
|
||||
ResourceManager.SwitchLanguage("zh-CN");
|
||||
}
|
||||
else if (selectedText == "English")
|
||||
{
|
||||
ResourceManager.SwitchLanguage("en-US");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Window x:Class="ShanghaiEnvironmentalTechnology.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="上海稻燃健康科技有限公司" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen"
|
||||
Title="" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen"
|
||||
>
|
||||
<Grid Margin="20" Cursor="">
|
||||
<Grid.RowDefinitions>
|
||||
@@ -15,25 +15,25 @@
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Text="上海稻燃健康科技有限公司"
|
||||
<TextBlock Text=""
|
||||
FontSize="24"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,10,0,20"/>
|
||||
|
||||
<Button Content="排气流测试"
|
||||
<Button Content="{ DynamicResource WindowTitle1}"
|
||||
Grid.Row="1"
|
||||
Style="{StaticResource MyButtonStyle}" Click="Button_Click"/>
|
||||
<Button Content="气阻测试"
|
||||
<Button Content="{ DynamicResource WindowTitle2}"
|
||||
Grid.Row="2"
|
||||
Style="{StaticResource MyButtonStyle}" Click="Button1_Click"/>
|
||||
<Button Content="防室息阀测试"
|
||||
<Button Content="{ DynamicResource WindowTitle3}"
|
||||
Grid.Row="3"
|
||||
Style="{StaticResource MyButtonStyle}" Click="Button2_Click" Cursor="Hand" />
|
||||
<Button Content="单一故障吸阻力测试"
|
||||
<Button Content="{ DynamicResource WindowTitle4}"
|
||||
Grid.Row="4"
|
||||
Style="{StaticResource MyButtonStyle}" Click="Button3_Click"/>
|
||||
<Button Content="二氧化碳重呼吸吸测试"
|
||||
<Button Content="{ DynamicResource WindowTitle5}"
|
||||
Grid.Row="5"
|
||||
Style="{StaticResource MyButtonStyle}" Click="Button4_Click"/>
|
||||
|
||||
|
||||
45
Resources/ResourceManager.cs
Normal file
45
Resources/ResourceManager.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
public class ResourceManager
|
||||
{
|
||||
//public static void SwitchLanguage(string culture)
|
||||
//{
|
||||
// var uri = new Uri($"/Resources/Strings.{culture}.xaml", UriKind.Relative);
|
||||
// var resourceDict = Application.LoadComponent(uri) as ResourceDictionary;
|
||||
|
||||
// Application.Current.Resources.MergedDictionaries.Clear();
|
||||
// Application.Current.Resources.MergedDictionaries.Add(resourceDict);
|
||||
//}
|
||||
|
||||
public static void SwitchLanguage(string culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 保存到App.config
|
||||
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
config.AppSettings.Settings["Language"].Value = culture;
|
||||
config.Save(ConfigurationSaveMode.Modified);
|
||||
ConfigurationManager.RefreshSection("appSettings");
|
||||
|
||||
// 切换语言
|
||||
var resourceDict = new ResourceDictionary
|
||||
{
|
||||
Source = new Uri($"/Resources/Strings.{culture}.xaml", UriKind.Relative)
|
||||
};
|
||||
|
||||
Application.Current.Resources.MergedDictionaries.Clear();
|
||||
Application.Current.Resources.MergedDictionaries.Add(resourceDict);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"切换语言失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 在SelectionChanged中使用
|
||||
|
||||
|
||||
151
Resources/Strings.en-US.xaml
Normal file
151
Resources/Strings.en-US.xaml
Normal file
@@ -0,0 +1,151 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
<!-- 窗口标题 -->
|
||||
<system:String x:Key="WindowTitle">Sleep Apnea Treatment Mask Multi-functional Tester</system:String>
|
||||
<system:String x:Key="WindowTitle1">Exhaust flow test</system:String>
|
||||
<system:String x:Key="WindowTitle2">Air resistance test</system:String>
|
||||
<system:String x:Key="WindowTitle3">Asphyxiation prevention valve test</system:String>
|
||||
<system:String x:Key="WindowTitle4">Single fault air resistance test</system:String>
|
||||
<system:String x:Key="WindowTitle5">Carbon dioxide re-breathing inhalation test</system:String>
|
||||
|
||||
<!-- 实时显示区域 -->
|
||||
<system:String x:Key="RealTimeDisplay">Adjust the set pressure, and the corresponding flow rate at this time</system:String>
|
||||
<system:String x:Key="CurrentTest">Set the pressure:</system:String>
|
||||
<system:String x:Key="Setting">Setting</system:String>
|
||||
<system:String x:Key="TriggerDisplacement">Calibration pressure</system:String>
|
||||
<system:String x:Key="CurrentPosition">Real-time traffic flow:</system:String>
|
||||
|
||||
<system:String x:Key="RealTimePressure">Real-time Pressure:</system:String>
|
||||
<system:String x:Key="EndDisplacement">Record traffic</system:String>
|
||||
<system:String x:Key="Deformation">Homepage</system:String>
|
||||
<!-- 测试结果区域 -->
|
||||
<system:String x:Key="TestResults">Nasal and oral pressure:</system:String>
|
||||
<system:String x:Key="Deformation1">Set the flow rate:</system:String>
|
||||
<system:String x:Key="Deformation2">Connection port calibration</system:String>
|
||||
<system:String x:Key="Deformation3">Calibration</system:String>
|
||||
<system:String x:Key="Deformation4">settings</system:String>
|
||||
<system:String x:Key="Deformation5">Real-time traffic</system:String>
|
||||
<system:String x:Key="Deformation6">Record air resistance</system:String>
|
||||
<system:String x:Key="Report">报表</system:String>
|
||||
|
||||
<system:String x:Key="Deformation test results">Test stopped</system:String>
|
||||
|
||||
<system:String x:Key="Deformation7">Enter</system:String>
|
||||
<system:String x:Key="Deformation8">8# Deformation</system:String>
|
||||
<system:String x:Key="Deformation9">9# Deformation</system:String>
|
||||
<system:String x:Key="Deformation10">10# Deformation</system:String>
|
||||
<system:String x:Key="TestSpeedLabel">Test Speed</system:String>
|
||||
<system:String x:Key="SetPressureLabel">Set Pressure</system:String>
|
||||
<!-- 参数设置区域 -->
|
||||
<system:String x:Key="ParameterSettings">Parameter Settings</system:String>
|
||||
<system:String x:Key="TestSpeed">Test Speed</system:String>
|
||||
<system:String x:Key="TestDisplacement">Test Displacement</system:String>
|
||||
<system:String x:Key="TriggerValue">Trigger Value</system:String>
|
||||
<system:String x:Key="SetPressure">Set Pressure</system:String>
|
||||
<system:String x:Key="ResetDistance">Reset Down Distance</system:String>
|
||||
<system:String x:Key="TestCount">Test Count Setting</system:String>
|
||||
<system:String x:Key="Maximumforcevaluetestresult(N)">Test initiation</system:String>
|
||||
<system:String x:Key="Deformationtestresults(mm)">Test stopped</system:String>
|
||||
<system:String x:Key="Next">Air resistance test</system:String>
|
||||
<!-- 按钮文本 -->
|
||||
<system:String x:Key="Reset">Reset</system:String>
|
||||
<system:String x:Key="Test">Test</system:String>
|
||||
<system:String x:Key="Stop">Stop</system:String>
|
||||
<system:String x:Key="Up">Up</system:String>
|
||||
<system:String x:Key="Down">Down</system:String>
|
||||
<system:String x:Key="Zero">Zero</system:String>
|
||||
<!-- 底部导航 -->
|
||||
<system:String x:Key="PositionToPressure">Position to Pressure</system:String>
|
||||
<system:String x:Key="PressureToDisplacement">Pressure to Displacement</system:String>
|
||||
<system:String x:Key="PeakTest">Peak Test</system:String>
|
||||
<system:String x:Key="ViewReport">View Report</system:String>
|
||||
<system:String x:Key="ViewCurve">View Curve</system:String>
|
||||
<system:String x:Key="BtnZhText">中文</system:String>
|
||||
<system:String x:Key="BtnEnText">English</system:String>
|
||||
<system:String x:Key="Test Date">Test Date:</system:String>
|
||||
<system:String x:Key="Calibration">Calibration</system:String>
|
||||
<system:String x:Key="Test Time">Test Time:</system:String>
|
||||
<system:String x:Key="Sample No">Sample No:</system:String>
|
||||
<system:String x:Key="Systemparameter">System Parameter</system:String>
|
||||
<system:String x:Key="Test speed (mm/min)">Test speed (mm/min)</system:String>
|
||||
<system:String x:Key="Workstation curve description">Workstation curve description:</system:String>
|
||||
<system:String x:Key="Test Status">Test Status</system:String>
|
||||
<system:String x:Key="Experimental Report">Experimental Report</system:String>
|
||||
<system:String x:Key="Constant pressure (N)">Constant pressure (N)</system:String>
|
||||
<system:String x:Key="All workstation tests have been completed">All workstation tests have been completed</system:String>
|
||||
|
||||
<system:String x:Key="RealTimeData">real time data</system:String>
|
||||
<system:String x:Key="PressureDeformationCurve">Pressure-deformation relationship curve</system:String>
|
||||
<!-- Other Text Resources -->
|
||||
<system:String x:Key="ReturnButton">Return</system:String>
|
||||
<system:String x:Key="SystemParameters">System Parameters Settings</system:String>
|
||||
<system:String x:Key="DeviceParameters">Device Parameters</system:String>
|
||||
<system:String x:Key="ResetSpeed">Reset Speed</system:String>
|
||||
<system:String x:Key="ManualSpeed">Manual Speed</system:String>
|
||||
<system:String x:Key="PressureCoefficient">Pressure Coefficient</system:String>
|
||||
<system:String x:Key="PressureProtection">Pressure Protection</system:String>
|
||||
<system:String x:Key="Language">Language</system:String>
|
||||
<system:String x:Key="StatusBarText">System Parameters Settings - Modify with caution</system:String>
|
||||
|
||||
<!-- Units -->
|
||||
<system:String x:Key="Unit_mm_min">mm/min</system:String>
|
||||
<system:String x:Key="Unit_N_V">N/V</system:String>
|
||||
<system:String x:Key="Unit_N">N</system:String>
|
||||
<system:String x:Key="WindowTitle7">System Parameters Settings</system:String>
|
||||
<!-- Language Options -->
|
||||
<system:String x:Key="Chinese">Chinese</system:String>
|
||||
<system:String x:Key="English">English</system:String>
|
||||
|
||||
<system:String x:Key="ROUNDS">ROUNDS</system:String>
|
||||
<system:String x:Key="TestPeakValue">Test Peak Value</system:String>
|
||||
<system:String x:Key="MaximumPressure">Maximum Pressure</system:String>
|
||||
|
||||
<system:String x:Key="Maximum stroke soft limit">Maximum Stroke Soft Limit</system:String>
|
||||
|
||||
<system:String x:Key="Peak force test result(N)">Connection port pressure:</system:String>
|
||||
<system:String x:Key="It has been crushed">It Has Been Crushed</system:String>
|
||||
<system:String x:Key="The force value determines the pressure difference">Differential Pressure</system:String>
|
||||
|
||||
|
||||
|
||||
<!-- 基本信息 -->
|
||||
<system:String x:Key="TestDate">Test Date:</system:String>
|
||||
<system:String x:Key="TestTime">Test Time:</system:String>
|
||||
<system:String x:Key="Experimenter">Experimenter:</system:String>
|
||||
<system:String x:Key="SampleNumber">Sample No.:</system:String>
|
||||
|
||||
<!-- 报表分区标题 -->
|
||||
<system:String x:Key="PositionToPressureMaxForce">Position to Pressure (Max Force)</system:String>
|
||||
<system:String x:Key="PositionToPressureDeformation">Position to Pressure (Deformation)</system:String>
|
||||
<system:String x:Key="PressureToDisplacementDeformation">Pressure to Displacement (Deformation)</system:String>
|
||||
<system:String x:Key="PeakTestPeakForce">Peak Test (Peak Force)</system:String>
|
||||
<system:String x:Key="PeakTestDeformation">Peak Test (Deformation)</system:String>
|
||||
|
||||
<!-- 结果表格标题 -->
|
||||
<system:String x:Key="MaxForce">Max Force</system:String>
|
||||
|
||||
<!-- 按钮文本 -->
|
||||
<system:String x:Key="Back">Back</system:String>
|
||||
<system:String x:Key="Print">Print</system:String>
|
||||
<system:String x:Key="Export">Export</system:String>
|
||||
<system:String x:Key="Save">Save</system:String>
|
||||
<system:String x:Key="Close">Close</system:String>
|
||||
|
||||
|
||||
<system:String x:Key="1# Maximum Force Value (N)">1# Maximum Force Value (N)</system:String>
|
||||
<system:String x:Key="2# Maximum Force Value (N)">2# Maximum Force Value (N)</system:String>
|
||||
<system:String x:Key="3# Maximum Force Value (N)">3# Maximum Force Value (N)</system:String>
|
||||
<system:String x:Key="4# Maximum Force Value (N)">4# Maximum Force Value (N)</system:String>
|
||||
<system:String x:Key="5# Maximum Force Value (N)">5# Maximum Force Value (N)</system:String>
|
||||
|
||||
|
||||
<system:String x:Key="6# Maximum Force Value (N)">6# Maximum Force Value (N)</system:String>
|
||||
<system:String x:Key="7# Maximum Force Value (N)">7# Maximum Force Value (N)</system:String>
|
||||
<system:String x:Key="8# Maximum Force Value (N)">8# Maximum Force Value (N)</system:String>
|
||||
<system:String x:Key="9# Maximum Force Value (N)">9# Maximum Force Value (N)</system:String>
|
||||
<system:String x:Key="10# Maximum Force Value (N)">10# Maximum Force Value (N)</system:String>
|
||||
<system:String x:Key="Peak test (peak force)">Peak test (peak force)</system:String>
|
||||
|
||||
|
||||
</ResourceDictionary>
|
||||
153
Resources/Strings.zh-CN.xaml
Normal file
153
Resources/Strings.zh-CN.xaml
Normal file
@@ -0,0 +1,153 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
<!-- 窗口标题 -->
|
||||
<system:String x:Key="WindowTitle">睡眠呼吸暂停治疗面罩多功能测试仪</system:String>
|
||||
<system:String x:Key="WindowTitle1">排气流测试</system:String>
|
||||
<system:String x:Key="WindowTitle2">气阻测试</system:String>
|
||||
<system:String x:Key="WindowTitle3">防室息阀测试</system:String>
|
||||
<system:String x:Key="WindowTitle4">单一故障吸阻力测试</system:String>
|
||||
<system:String x:Key="WindowTitle5">二氧化碳重呼吸吸测试</system:String>
|
||||
<!-- 实时显示区域 -->
|
||||
<system:String x:Key="RealTimeDisplay">提示: 调节设定压力,该时的流量</system:String>
|
||||
<system:String x:Key="CurrentTest">设定压力:</system:String>
|
||||
<system:String x:Key="Setting">设置</system:String>
|
||||
<system:String x:Key="TriggerDisplacement">校准压力</system:String>
|
||||
|
||||
<system:String x:Key="CurrentPosition">实时流量</system:String>
|
||||
|
||||
<system:String x:Key="RealTimePressure">实时压力</system:String>
|
||||
|
||||
<system:String x:Key="EndDisplacement">记录流量</system:String>
|
||||
<system:String x:Key="Deformation">主页</system:String>
|
||||
<system:String x:Key="Maximumforcevaluetestresult(N)">测试启动</system:String>
|
||||
<system:String x:Key="Deformation test results">测试停止</system:String>
|
||||
<system:String x:Key="Peak force test result(N)">连接口压力:</system:String>
|
||||
<!-- 测试结果区域 -->
|
||||
<system:String x:Key="TestResults">鼻口压力:</system:String>
|
||||
<system:String x:Key="Next">气阻测试</system:String>
|
||||
<system:String x:Key="Deformation1">设定流量</system:String>
|
||||
<system:String x:Key="Deformation2">连接口校准</system:String>
|
||||
<system:String x:Key="Deformation3">校准</system:String>
|
||||
<system:String x:Key="Deformation4">设置</system:String>
|
||||
<system:String x:Key="Deformation5">实时流量</system:String>
|
||||
<system:String x:Key="Deformation6">记录气阻</system:String>
|
||||
|
||||
<system:String x:Key="Report">报表</system:String>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<system:String x:Key="Deformation7">进入</system:String>
|
||||
<system:String x:Key="Deformation8">8#形变量</system:String>
|
||||
<system:String x:Key="Deformation9">9#形变量</system:String>
|
||||
<system:String x:Key="Deformation10">10#形变量</system:String>
|
||||
<system:String x:Key="TestSpeedLabel">测试速度</system:String>
|
||||
<system:String x:Key="SetPressureLabel">定压压力</system:String>
|
||||
<system:String x:Key="It has been crushed">已压破</system:String>
|
||||
<system:String x:Key="The force value determines the pressure difference">力值判断压差</system:String>
|
||||
<!-- 参数设置区域 -->
|
||||
<system:String x:Key="ParameterSettings">参数设置</system:String>
|
||||
<system:String x:Key="TestSpeed">测试速度</system:String>
|
||||
<system:String x:Key="TestDisplacement">测试位移</system:String>
|
||||
<system:String x:Key="TriggerValue">触发值</system:String>
|
||||
<system:String x:Key="SetPressure">设置压力</system:String>
|
||||
<system:String x:Key="ResetDistance">复位向下距离</system:String>
|
||||
<system:String x:Key="TestCount">测试次数设置</system:String>
|
||||
<!-- 按钮文本 -->
|
||||
<system:String x:Key="Reset">复位</system:String>
|
||||
<system:String x:Key="Test">测试</system:String>
|
||||
<system:String x:Key="Stop">停止</system:String>
|
||||
<system:String x:Key="Up">上升</system:String>
|
||||
<system:String x:Key="Down">下降</system:String>
|
||||
<system:String x:Key="Zero">清零</system:String>
|
||||
<!-- 底部导航 -->
|
||||
<system:String x:Key="PositionToPressure">定位移测压力</system:String>
|
||||
<system:String x:Key="PressureToDisplacement">定压力测位移</system:String>
|
||||
<system:String x:Key="PeakTest">峰值测试</system:String>
|
||||
<system:String x:Key="ViewReport">查看报表</system:String>
|
||||
<system:String x:Key="ViewCurve">查看曲线</system:String>
|
||||
<system:String x:Key="BtnZhText">中文</system:String>
|
||||
<system:String x:Key="BtnEnText">English</system:String>
|
||||
<system:String x:Key="Calibration">校准</system:String>
|
||||
<system:String x:Key="Test Date">测试日期:</system:String>
|
||||
<system:String x:Key="Test Time">测试时间:</system:String>
|
||||
<system:String x:Key="Sample No">测试时间:</system:String>
|
||||
<system:String x:Key="Test Status">测试状态:</system:String>
|
||||
<system:String x:Key="Workstation curve description">工位曲线说明:</system:String>
|
||||
<system:String x:Key="All workstation tests have been completed">全部工位测试完成</system:String>
|
||||
<system:String x:Key="PressureDeformationCurve">压力-变形量关系曲线</system:String>
|
||||
<system:String x:Key="RealTimeData">实时数据</system:String>
|
||||
|
||||
<!-- 其他文本资源 -->
|
||||
<system:String x:Key="ReturnButton">返回</system:String>
|
||||
<system:String x:Key="SystemParameters">系统参数设置</system:String>
|
||||
<system:String x:Key="DeviceParameters">设备参数</system:String>
|
||||
<system:String x:Key="ResetSpeed">上下电机复位速度</system:String>
|
||||
<system:String x:Key="ManualSpeed">上下手动速度</system:String>
|
||||
<system:String x:Key="PressureCoefficient">压力系数</system:String>
|
||||
<system:String x:Key="PressureProtection">压力保护</system:String>
|
||||
<system:String x:Key="Language">语言</system:String>
|
||||
<system:String x:Key="StatusBarText">系统参数设置 - 请谨慎修改</system:String>
|
||||
<system:String x:Key="WindowTitle7">系统参数设置</system:String>
|
||||
<!-- 单位 -->
|
||||
<system:String x:Key="Unit_mm_min">mm/min</system:String>
|
||||
<system:String x:Key="Unit_N_V">N/V</system:String>
|
||||
<system:String x:Key="Unit_N">N</system:String>
|
||||
|
||||
<!-- 语言选项 -->
|
||||
<system:String x:Key="Chinese">中文</system:String>
|
||||
<system:String x:Key="English">English</system:String>
|
||||
|
||||
<system:String x:Key="ROUNDS">第</system:String>
|
||||
<system:String x:Key="Systemparameter">系统参数</system:String>
|
||||
<system:String x:Key="TestPeakValue">试验峰值</system:String>
|
||||
<system:String x:Key="MaximumPressure">最大压力</system:String>
|
||||
|
||||
<system:String x:Key="Maximum stroke soft limit">最大行程软限位</system:String>
|
||||
|
||||
|
||||
<!-- 基本信息 -->
|
||||
<system:String x:Key="TestDate">测试日期:</system:String>
|
||||
<system:String x:Key="TestTime">测试时间:</system:String>
|
||||
<system:String x:Key="Experimenter">实验员:</system:String>
|
||||
<system:String x:Key="SampleNumber">样品编号:</system:String>
|
||||
|
||||
<!-- 报表分区标题 -->
|
||||
<system:String x:Key="PositionToPressureMaxForce">定位移测压力(最大力值)</system:String>
|
||||
<system:String x:Key="PositionToPressureDeformation">定位移测压力(变形量)</system:String>
|
||||
<system:String x:Key="PressureToDisplacementDeformation">定压力测位移(变形量)</system:String>
|
||||
<system:String x:Key="PeakTestPeakForce">峰值测试(峰值力)</system:String>
|
||||
<system:String x:Key="PeakTestDeformation">峰值测试(变形量)</system:String>
|
||||
<system:String x:Key="Experimental Report">实验报表</system:String>
|
||||
|
||||
<!-- 结果表格标题 -->
|
||||
<system:String x:Key="MaxForce">最大力值</system:String>
|
||||
|
||||
<!-- 按钮文本 -->
|
||||
<system:String x:Key="Back">返回</system:String>
|
||||
<system:String x:Key="Print">打印</system:String>
|
||||
<system:String x:Key="Export">导出</system:String>
|
||||
<system:String x:Key="Save">保存</system:String>
|
||||
<system:String x:Key="Close">关闭</system:String>
|
||||
<system:String x:Key="Test speed (mm/min)">测试速度(mm/min)</system:String>
|
||||
<system:String x:Key="Constant pressure (N)">定压压力(N)</system:String>
|
||||
<system:String x:Key="1# Maximum Force Value (N)">1#最大力值(N)</system:String>
|
||||
<system:String x:Key="2# Maximum Force Value (N)">2#最大力值(N)</system:String>
|
||||
<system:String x:Key="3# Maximum Force Value (N)">3#最大力值(N)</system:String>
|
||||
<system:String x:Key="4# Maximum Force Value (N)">4#最大力值(N)</system:String>
|
||||
<system:String x:Key="5# Maximum Force Value (N)">5#最大力值(N)</system:String>
|
||||
|
||||
<system:String x:Key="6# Maximum Force Value (N)">6#最大力值(N)</system:String>
|
||||
<system:String x:Key="7# Maximum Force Value (N)">7#最大力值(N)</system:String>
|
||||
<system:String x:Key="8# Maximum Force Value (N)">8#最大力值(N)</system:String>
|
||||
<system:String x:Key="9# Maximum Force Value (N)">9#最大力值(N)</system:String>
|
||||
<system:String x:Key="10# Maximum Force Value (N)">10#最大力值(N)</system:String>
|
||||
|
||||
|
||||
<system:String x:Key="Peak test (peak force)">峰值测试(峰值力)</system:String>
|
||||
|
||||
|
||||
</ResourceDictionary>
|
||||
30
Window1.xaml
30
Window1.xaml
@@ -2,7 +2,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:av="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="av" x:Class="ShanghaiEnvironmentalTechnology.Window1"
|
||||
Title="排气流量测试"
|
||||
Title="{DynamicResource WindowTitle1}"
|
||||
Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
|
||||
|
||||
<Window.Resources>
|
||||
@@ -75,56 +75,56 @@
|
||||
|
||||
<Grid Margin="20">
|
||||
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Width="800">
|
||||
<TextBlock Text="排气流量测试"
|
||||
<TextBlock Text="{DynamicResource WindowTitle1}"
|
||||
FontSize="36"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,20"/>
|
||||
|
||||
<TextBlock Text="提示: 调节设定压力,该时的流量"
|
||||
<TextBlock Text="{DynamicResource RealTimeDisplay}"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,30"/>
|
||||
|
||||
<StackPanel Orientation="Vertical" Margin="0,0,0,20">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10">
|
||||
<TextBlock Text="设定压力:" VerticalAlignment="Center" Foreground="Black"/>
|
||||
|
||||
<TextBlock Text="{DynamicResource CurrentTest}" VerticalAlignment="Center" Foreground="Black"/>
|
||||
|
||||
<TextBox x:Name="SettingPaTextBox" Width="120" Margin="10,0" Style="{StaticResource MyTextBoxStyle}"
|
||||
IsReadOnly="True"
|
||||
InputScope="Number" PreviewTextInput="SettingPaTextBox_PreviewTextInput" />
|
||||
|
||||
|
||||
<TextBlock Text="pa" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<Button Content="设置" Style="{StaticResource MyButtonStyle}" Click="SettingPaTextBox_MouseLeave"/>
|
||||
<Button Content="{DynamicResource Setting}" Style="{StaticResource MyButtonStyle}" Click="SettingPaTextBox_MouseLeave"/>
|
||||
<!--<Button Content="确定" Style="{StaticResource MyButtonStyle}"/>-->
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10">
|
||||
<TextBlock Text="实时压力:" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<TextBlock Text="{DynamicResource RealTimePressure}" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<TextBox x:Name="RealTimePressureTextBox" Width="120" Margin="10,0" Style="{StaticResource MyTextBoxStyle}" IsReadOnly="True" IsEnabled="True"/>
|
||||
<TextBlock Text="pa" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<Button Content="校准压力" Style="{StaticResource MyButtonStyle}" Click="Button_Click"/>
|
||||
<Button Content="{DynamicResource TriggerDisplacement}" Width="180" Style="{StaticResource MyButtonStyle}" Click="Button_Click"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Vertical" Margin="0,20">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10">
|
||||
<TextBlock Text="实时流量:" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<TextBlock Text="{DynamicResource CurrentPosition}" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<TextBlock x:Name="txtFolw" Text="???" Margin="10,0" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<TextBlock Text="L/min" VerticalAlignment="Center" Foreground="Black"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10">
|
||||
<Button Content="记录流量" Style="{StaticResource MyButtonStyle}" Click="Button_Click_4"/>
|
||||
<Button Content="{DynamicResource EndDisplacement}" Width="150" Style="{StaticResource MyButtonStyle}" Click="Button_Click_4"/>
|
||||
<TextBlock x:Name="saveFlowTxt" Text="???" Margin="10,0" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<TextBlock Text="L/min" VerticalAlignment="Center" Foreground="Black"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,30">
|
||||
<Button Content="主页" Style="{StaticResource MyButtonStyle}" Click="Button_Click_1"/>
|
||||
<Button x:Name="TestStartButton" Content="测试启动" Style="{StaticResource MyButtonStyle}" Click="Button_Click_2"/>
|
||||
<Button Content="测试停止" Style="{StaticResource MyButtonStyle}" Click="Button_Click_3" />
|
||||
<Button Content="记录画面" Style="{StaticResource MyButtonStyle}" Click="Button_Click_5" />
|
||||
<Button Content="{DynamicResource Deformation}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_1"/>
|
||||
<Button x:Name="TestStartButton" Content="{DynamicResource Maximumforcevaluetestresult(N)}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_2"/>
|
||||
<Button Content="{DynamicResource Deformation test results}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_3" />
|
||||
<Button Content="{DynamicResource ViewReport}" Width="150" Style="{StaticResource MyButtonStyle}" Click="Button_Click_5" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
128
Window1.xaml.cs
128
Window1.xaml.cs
@@ -1,7 +1,8 @@
|
||||
using Microsoft.Win32;
|
||||
using Modbus.Device;
|
||||
using Modbus;
|
||||
using Modbus.Device;
|
||||
using OfficeOpenXml;
|
||||
using OxyPlot;
|
||||
using Sunny.UI;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
@@ -177,19 +178,36 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
bool[] result = _modbusMaster?.ReadCoils(0x01, 61, 1);
|
||||
bool isTestRunning = result != null && result.Length > 0 && result[0];
|
||||
|
||||
TestStartButton.Dispatcher.Invoke(() =>
|
||||
string testStartButtonText = "";
|
||||
string ButtonStatus = "";
|
||||
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
||||
if (currentLanguage == "en-US")
|
||||
{
|
||||
if (isTestRunning)
|
||||
{
|
||||
TestStartButton.Content = "测试启动成功";
|
||||
TestStartButton.Foreground = Brushes.LightGreen;
|
||||
}
|
||||
else
|
||||
{
|
||||
TestStartButton.Content = "测试启动";
|
||||
TestStartButton.Foreground = Brushes.White;
|
||||
}
|
||||
});
|
||||
testStartButtonText = "Test Start Success";
|
||||
ButtonStatus = "Test initiation";
|
||||
}
|
||||
else if (currentLanguage == "zh-CN")
|
||||
{
|
||||
testStartButtonText = "测试启动成功";
|
||||
ButtonStatus = "测试启动";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TestStartButton.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (isTestRunning)
|
||||
{
|
||||
TestStartButton.Content = testStartButtonText;
|
||||
TestStartButton.Foreground = Brushes.LightGreen;
|
||||
}
|
||||
else
|
||||
{
|
||||
TestStartButton.Content = ButtonStatus;
|
||||
TestStartButton.Foreground = Brushes.White;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -253,14 +271,43 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
#endregion
|
||||
|
||||
#region UI更新(统一线程安全处理)
|
||||
|
||||
private void UpdateConnectionTextUI(System.Windows.Controls.TextBox textBox, string value)
|
||||
{
|
||||
// 获取当前语言(默认中文)
|
||||
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
||||
|
||||
// 多语言提示信息
|
||||
string disconnectMsg = currentLanguage == "en-US" ? "Connection disconnected" : "连接断开";
|
||||
|
||||
// 安全更新UI
|
||||
UpdateUiSafely(() =>
|
||||
textBox.Text = IsModbusConnected() ? value : disconnectMsg
|
||||
);
|
||||
}
|
||||
|
||||
private void UpdateConnectionTextUI(System.Windows.Controls.TextBlock textBox, string value)
|
||||
{
|
||||
// 获取当前语言(默认中文)
|
||||
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
||||
|
||||
// 多语言提示信息
|
||||
string disconnectMsg = currentLanguage == "en-US" ? "Connection disconnected" : "连接断开";
|
||||
|
||||
// 安全更新UI
|
||||
UpdateUiSafely(() =>
|
||||
textBox.Text = IsModbusConnected() ? value : disconnectMsg
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新实时压力UI
|
||||
/// </summary>
|
||||
private void UpdatePressureUI(string value)
|
||||
{
|
||||
UpdateUiSafely(() =>
|
||||
RealTimePressureTextBox.Text = IsModbusConnected() ? value : "连接断开"
|
||||
);
|
||||
UpdateConnectionTextUI(RealTimePressureTextBox, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -268,33 +315,27 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
/// </summary>
|
||||
private void UpdateSettingUI(string value)
|
||||
{
|
||||
UpdateUiSafely(() =>
|
||||
SettingPaTextBox.Text = IsModbusConnected() ? value : "连接断开"
|
||||
);
|
||||
UpdateConnectionTextUI(SettingPaTextBox, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新实时流量UI
|
||||
/// </summary>
|
||||
private void UpdateFlowPressureUI(string value)
|
||||
{
|
||||
UpdateUiSafely(() =>
|
||||
txtFolw.Text = IsModbusConnected() ? value : "连接断开"
|
||||
);
|
||||
}
|
||||
private void UpdateStartPressureUI(string value)
|
||||
{
|
||||
UpdateUiSafely(() =>
|
||||
TestStartButton.Content = IsModbusConnected() ? value : "连接断开"
|
||||
);
|
||||
UpdateConnectionTextUI(txtFolw, value);
|
||||
}
|
||||
//private void UpdateStartPressureUI(string value)
|
||||
//{
|
||||
// UpdateUiSafely(() =>
|
||||
// TestStartButton.Content = IsModbusConnected() ? value : "连接断开"
|
||||
// );
|
||||
//}
|
||||
/// <summary>
|
||||
/// 更新实时流量UI
|
||||
/// </summary>
|
||||
private void UpdateFlowFlowUI(string value)
|
||||
{
|
||||
UpdateUiSafely(() =>
|
||||
saveFlowTxt.Text = IsModbusConnected() ? value : "连接断开"
|
||||
);
|
||||
UpdateConnectionTextUI(saveFlowTxt, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -504,7 +545,7 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Excel导出失败,请检查文件是否被占用", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
//MessageBox.Show("Excel导出失败,请检查文件是否被占用", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
|
||||
@@ -527,7 +568,7 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
|
||||
// 用户取消选择则返回
|
||||
bool? result = saveDialog.ShowDialog(); if (!(result ?? false)) return false;
|
||||
|
||||
|
||||
|
||||
// EPPlus 许可设置(.NET 8 必须显式设置)
|
||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial; // 非商业用途
|
||||
@@ -718,12 +759,12 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
WriteLog($"{logMsg} - 地址:{coilAddress},状态:{value}");
|
||||
if (!string.IsNullOrEmpty(successMsg))
|
||||
{
|
||||
ShowSuccess(successMsg);
|
||||
//ShowSuccess(successMsg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError(failMsg);
|
||||
//ShowError(failMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -855,9 +896,9 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
}
|
||||
|
||||
// 消息提示封装
|
||||
private void ShowSuccess(string msg) => MessageBox.Show(msg, "成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
private void ShowWarning(string msg) => MessageBox.Show(msg, "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
private void ShowError(string msg) => MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
//private void ShowSuccess(string msg) => MessageBox.Show(msg, "成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
private void ShowWarning(string msg) => MessageBox.Show(msg, "Instruction", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
private void ShowError(string msg) => MessageBox.Show(msg, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -886,5 +927,16 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshLanguage()
|
||||
{
|
||||
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
||||
}
|
||||
|
||||
private string GetLocalizedString(string key)
|
||||
{
|
||||
var resource = Application.Current.TryFindResource(key);
|
||||
return resource?.ToString() ?? key;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Window2.xaml
36
Window2.xaml
@@ -1,7 +1,7 @@
|
||||
<Window x:Class="ShanghaiEnvironmentalTechnology.Window2"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="气阻测试" Height="768" Width="1024"
|
||||
Title="{DynamicResource Next}" Height="768" Width="1024"
|
||||
Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
|
||||
|
||||
<Window.Resources>
|
||||
@@ -71,15 +71,15 @@
|
||||
</Window.Resources>
|
||||
|
||||
<Grid Margin="20">
|
||||
<TextBlock Text="测100L/min和50L/min流量下的气阻" FontSize="18" HorizontalAlignment="Left" Margin="0,0,0,0" Foreground="Black"/>
|
||||
<TextBlock Text="" FontSize="18" HorizontalAlignment="Left" Margin="0,0,0,0" Foreground="Black"/>
|
||||
<StackPanel VerticalAlignment="Top" HorizontalAlignment="Center" Width="1366">
|
||||
|
||||
<TextBlock Text="气阻测试" FontSize="24" FontWeight="Bold" HorizontalAlignment="Center" Margin="0,0,0,20" Foreground="Black"/>
|
||||
<TextBlock Text="{DynamicResource Next}" FontSize="24" FontWeight="Bold" HorizontalAlignment="Center" Margin="0,0,0,20" Foreground="Black"/>
|
||||
|
||||
<StackPanel Orientation="Vertical" Margin="0,10" HorizontalAlignment="Center">
|
||||
|
||||
<Grid Margin="0,10" HorizontalAlignment="Center" Width="400">
|
||||
|
||||
|
||||
<Grid Margin="0,10" HorizontalAlignment="Center" Width="Auto">
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120"/>
|
||||
<!-- 标签列 -->
|
||||
@@ -89,14 +89,14 @@
|
||||
<!-- 按钮列 -->
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Text="连接口压力:" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<TextBlock Text="{DynamicResource Peak force test result(N)}" VerticalAlignment="Center" Foreground="Black" Margin="-120"/>
|
||||
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBox Name="RealTimePressureTextBox" Width="80" Style="{StaticResource MyTextBoxStyle}" IsEnabled="false"/>
|
||||
<TextBlock Text="pa" VerticalAlignment="Center" Foreground="Black" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="2" Content="连接口校准" Style="{StaticResource MyButtonStyle}" Click="Button_Click" HorizontalAlignment="Left"/>
|
||||
<Button Grid.Column="2" Content="{DynamicResource Deformation2}" Width="250" Style="{StaticResource MyButtonStyle}" Click="Button_Click" HorizontalAlignment="Left"/>
|
||||
</Grid>
|
||||
|
||||
<!-- 鼻口压力行 -->
|
||||
@@ -107,14 +107,14 @@
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Text="鼻口压力:" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<TextBlock Text="{DynamicResource TestResults}" VerticalAlignment="Center" Foreground="Black" Margin="-120"/>
|
||||
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBox Name="NoseTxt" Width="80" Style="{StaticResource MyTextBoxStyle}" Foreground="Black" IsEnabled="false"/>
|
||||
<TextBlock Text="pa" VerticalAlignment="Center" Foreground="Black" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="2" Content="校准" Style="{StaticResource MyButtonStyle}" Click="Button_Click_1" HorizontalAlignment="Left"/>
|
||||
<Button Grid.Column="2" Content="{DynamicResource Deformation3}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_1" HorizontalAlignment="Left"/>
|
||||
</Grid>
|
||||
|
||||
<!-- 设定流量行 -->
|
||||
@@ -125,24 +125,24 @@
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Text="设定流量:" VerticalAlignment="Center" Foreground="Black"/>
|
||||
<TextBlock Text="{DynamicResource Deformation1}" VerticalAlignment="Center" Foreground="Black" Margin="-60"/>
|
||||
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBox Name="FowlTxt1" Width="80" Style="{StaticResource MyTextBoxStyle}" Foreground="Black" IsReadOnly="True"/>
|
||||
<TextBlock Text="L/min" VerticalAlignment="Center" Foreground="Black" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="2" Content="设置" Style="{StaticResource MyButtonStyle}" Click="Button_Click_7" HorizontalAlignment="Left"/>
|
||||
<Button Grid.Column="2" Content="{DynamicResource Deformation4}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_7" HorizontalAlignment="Left"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Text="实时流量:" FontSize="20" HorizontalAlignment="Center" Margin="0,20" Foreground="Black"/>
|
||||
<TextBlock Text="{DynamicResource Deformation5}" FontSize="20" HorizontalAlignment="Center" Margin="0,20" Foreground="Black"/>
|
||||
<TextBlock x:Name="flowTxt" Text="???" FontSize="24" Foreground="Red" HorizontalAlignment="Center"/>
|
||||
<TextBlock Text="L/min" HorizontalAlignment="Center" Foreground="Black"/>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,20" HorizontalAlignment="Center">
|
||||
|
||||
<Button Content="记录气阻" Style="{StaticResource MyButtonStyle}" Click="Button_Click_2" />
|
||||
<Button Content="{DynamicResource Deformation6}" Style="{StaticResource MyButtonStyle}" Width="180" Click="Button_Click_2" />
|
||||
|
||||
|
||||
<TextBox Name="AirTxt" Width="80" Margin="10,0" Style="{StaticResource MyTextBoxStyle}" IsEnabled="False"/>
|
||||
@@ -150,10 +150,10 @@
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,30">
|
||||
<Button Content="主页" Style="{StaticResource MyButtonStyle}" Click="Button_Click_3"/>
|
||||
<Button Name="TestStartButton" Content="测试启动" Style="{StaticResource MyButtonStyle}" Click="Button_Click_4"/>
|
||||
<Button Content="测试停止" Style="{StaticResource MyButtonStyle}" Click="Button_Click_5" />
|
||||
<Button Content="记录画面" Style="{StaticResource MyButtonStyle}" Click="Button_Click_6"/>
|
||||
<Button Content="{DynamicResource Deformation}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_3"/>
|
||||
<Button Name="TestStartButton" Content="{DynamicResource Maximumforcevaluetestresult(N)}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_4"/>
|
||||
<Button Content="{DynamicResource Deformation test results}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_5" />
|
||||
<Button Content="{DynamicResource ViewReport}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_6"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
@@ -239,16 +239,33 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
bool[] result = _modbusMaster?.ReadCoils(0x01, 81, 1);
|
||||
bool isTestRunning = result != null && result.Length > 0 && result[0];
|
||||
|
||||
string testStartButtonText = "";
|
||||
string ButtonStatus = "";
|
||||
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
||||
if (currentLanguage == "en-US")
|
||||
{
|
||||
testStartButtonText = "Test Start Success";
|
||||
ButtonStatus = "Test initiation";
|
||||
}
|
||||
else if (currentLanguage == "zh-CN")
|
||||
{
|
||||
testStartButtonText = "测试启动成功";
|
||||
ButtonStatus = "测试启动";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TestStartButton.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (isTestRunning)
|
||||
{
|
||||
TestStartButton.Content = "测试启动成功";
|
||||
TestStartButton.Content = testStartButtonText;
|
||||
TestStartButton.Foreground = Brushes.LightGreen;
|
||||
}
|
||||
else
|
||||
{
|
||||
TestStartButton.Content = "测试启动";
|
||||
TestStartButton.Content = ButtonStatus;
|
||||
TestStartButton.Foreground = Brushes.White;
|
||||
}
|
||||
});
|
||||
@@ -317,13 +334,49 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
#endregion
|
||||
|
||||
#region UI更新(线程安全处理)
|
||||
|
||||
|
||||
|
||||
private void UpdateConnectionTextUI(System.Windows.Controls.TextBox textBox, string value)
|
||||
{
|
||||
// 获取当前语言(默认中文)
|
||||
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
||||
|
||||
// 多语言提示信息
|
||||
string disconnectMsg = currentLanguage == "en-US" ? "Connection disconnected" : "连接断开";
|
||||
|
||||
// 安全更新UI
|
||||
UpdateUiSafely(() =>
|
||||
textBox.Text = IsModbusConnected() ? value : disconnectMsg
|
||||
);
|
||||
}
|
||||
|
||||
private void UpdateConnectionTextUI(System.Windows.Controls.TextBlock textBox, string value)
|
||||
{
|
||||
// 获取当前语言(默认中文)
|
||||
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
|
||||
|
||||
// 多语言提示信息
|
||||
string disconnectMsg = currentLanguage == "en-US" ? "Connection disconnected" : "连接断开";
|
||||
|
||||
// 安全更新UI
|
||||
UpdateUiSafely(() =>
|
||||
textBox.Text = IsModbusConnected() ? value : disconnectMsg
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新连接口压力UI
|
||||
/// </summary>
|
||||
private void UpdatePressureUI(string value)
|
||||
{
|
||||
UpdateUiSafely(() =>
|
||||
RealTimePressureTextBox.Text = IsModbusConnected() ? value : "连接断开"
|
||||
UpdateConnectionTextUI(RealTimePressureTextBox, value)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -333,7 +386,7 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
private void UpdateNoseUI(string value)
|
||||
{
|
||||
UpdateUiSafely(() =>
|
||||
NoseTxt.Text = IsModbusConnected() ? value : "连接断开"
|
||||
UpdateConnectionTextUI(NoseTxt, value)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -343,7 +396,7 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
private void UpdateFlowUI(string value)
|
||||
{
|
||||
UpdateUiSafely(() =>
|
||||
flowTxt.Text = IsModbusConnected() ? value : "连接断开"
|
||||
UpdateConnectionTextUI(flowTxt, value)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -470,7 +523,7 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Excel导出失败,请检查文件是否被占用", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
//MessageBox.Show("Excel导出失败,请检查文件是否被占用", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
|
||||
@@ -493,7 +546,7 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
|
||||
// 用户取消选择则返回
|
||||
bool? result = saveDialog.ShowDialog(); if (!(result ?? false)) return false;
|
||||
|
||||
|
||||
|
||||
// EPPlus 许可设置(.NET 8 必须显式设置)
|
||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial; // 非商业用途
|
||||
|
||||
@@ -895,91 +895,7 @@ namespace ShanghaiEnvironmentalTechnology
|
||||
#endregion
|
||||
|
||||
#region
|
||||
///// <summary>
|
||||
///// 呼吸比设置(OutTxt和InTxt)
|
||||
///// </summary>
|
||||
//private async void Button_Click(object sender, RoutedEventArgs e)
|
||||
//{
|
||||
// if (!IsModbusConnected())
|
||||
// {
|
||||
// ShowError("Modbus TCP 未连接");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // 输入验证
|
||||
// if (!int.TryParse(OutTxt.Text.Trim(), out int outValue) ||
|
||||
// !int.TryParse(InTxt.Text.Trim(), out int inValue))
|
||||
// {
|
||||
// ShowWarning("请输入有效的整数");
|
||||
// return;
|
||||
// }
|
||||
// if (outValue < 0 || outValue > 10000 || inValue < 0 || inValue > 10000)
|
||||
// {
|
||||
// ShowWarning("值范围应为 0~10000");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// try
|
||||
// {
|
||||
// // 显示操作中状态
|
||||
// OutTxt.Text = "操作中...";
|
||||
// InTxt.Text = "操作中...";
|
||||
|
||||
// // 写入两个非连续寄存器
|
||||
// _modbusMaster.WriteSingleRegister(0x01, _outAddress, (ushort)outValue);
|
||||
// _modbusMaster.WriteSingleRegister(0x01, _inAddress, (ushort)inValue);
|
||||
|
||||
// await Task.Delay(300); // 等待PLC处理
|
||||
// RefreshFlowPressure(); // 刷新显示
|
||||
|
||||
// ShowSuccess($"设置呼吸比: {outValue}-{inValue}");
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// ShowError($"设置失败: {ex.Message}");
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// OutTxt.Text = outValue.ToString();
|
||||
// InTxt.Text = inValue.ToString();
|
||||
// }
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// 潮气量设置(moistureTxt)
|
||||
///// </summary>
|
||||
//private async void Button_Click_1(object sender, RoutedEventArgs e)
|
||||
//{
|
||||
// await WriteSingleRegisterWithUI(
|
||||
// inputControl: moistureTxt,
|
||||
// registerAddress: _moistureTxtAddress,
|
||||
// successMessage: value => $"设置潮气量: {value} L"
|
||||
// );
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// 呼吸频率设置(respiratoryRateTxt)
|
||||
///// </summary>
|
||||
//private async void Button_Click_2(object sender, RoutedEventArgs e)
|
||||
//{
|
||||
// await WriteSingleRegisterWithUI(
|
||||
// inputControl: respiratoryRateTxt,
|
||||
// registerAddress: _respiratoryRateAddress,
|
||||
// successMessage: value => $"设置呼吸频率: {value}"
|
||||
// );
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// 频率系数设置(frequencyTxt)
|
||||
///// </summary>
|
||||
//private async void Button_Click_3(object sender, RoutedEventArgs e)
|
||||
//{
|
||||
// await WriteSingleRegisterWithUI(
|
||||
// inputControl: frequencyTxt,
|
||||
// registerAddress: _frequencyAddress,
|
||||
// successMessage: value => $"设置频率系数: {value}"
|
||||
// );
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 返回主窗口
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34728.123
|
||||
# Visual Studio Version 18
|
||||
VisualStudioVersion = 18.2.11408.102 d18.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "睡眠多功能", "睡眠多功能.csproj", "{BC48015F-9837-4AEB-91B7-FB7085706537}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "睡眠呼吸暂停治疗面罩多功能测试仪", "睡眠呼吸暂停治疗面罩多功能测试仪.csproj", "{BC48015F-9837-4AEB-91B7-FB7085706537}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
Reference in New Issue
Block a user