138 lines
5.4 KiB
C#
138 lines
5.4 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Text;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using System.Windows;
|
||
|
|
using System.Windows.Controls;
|
||
|
|
using System.Windows.Data;
|
||
|
|
using System.Windows.Documents;
|
||
|
|
using System.Windows.Input;
|
||
|
|
using System.Windows.Media;
|
||
|
|
using System.Windows.Media.Imaging;
|
||
|
|
using System.Windows.Navigation;
|
||
|
|
using System.Windows.Shapes;
|
||
|
|
|
||
|
|
namespace WpfApp.src.view
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// ConfigPage.xaml 的交互逻辑
|
||
|
|
/// </summary>
|
||
|
|
public partial class ConfigPage : Page
|
||
|
|
{
|
||
|
|
// 传感器数据字典,存储每个传感器的公差设定值
|
||
|
|
private Dictionary<int, SensorToleranceData> sensorData;
|
||
|
|
|
||
|
|
public ConfigPage()
|
||
|
|
{
|
||
|
|
InitializeComponent();
|
||
|
|
InitializeSensorData();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 初始化传感器数据
|
||
|
|
private void InitializeSensorData()
|
||
|
|
{
|
||
|
|
sensorData = new Dictionary<int, SensorToleranceData>
|
||
|
|
{
|
||
|
|
{ 1, new SensorToleranceData { MaxTolerance = "9.00", BaseTolerance = "72.9410", MinTolerance = "-9.00" } },
|
||
|
|
{ 2, new SensorToleranceData { MaxTolerance = "8.50", BaseTolerance = "72.8500", MinTolerance = "-8.50" } },
|
||
|
|
{ 3, new SensorToleranceData { MaxTolerance = "7.80", BaseTolerance = "72.7800", MinTolerance = "-7.80" } },
|
||
|
|
{ 4, new SensorToleranceData { MaxTolerance = "6.90", BaseTolerance = "72.6900", MinTolerance = "-6.90" } }
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
// 传感器标签页点击事件处理
|
||
|
|
private void SensorTab_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
Button clickedButton = sender as Button;
|
||
|
|
if (clickedButton == null) return;
|
||
|
|
|
||
|
|
int sensorIndex = int.Parse(clickedButton.Tag.ToString());
|
||
|
|
|
||
|
|
// 保存当前传感器的数据
|
||
|
|
SaveCurrentSensorData();
|
||
|
|
|
||
|
|
// 更新标签页样式
|
||
|
|
UpdateTabStyles(sensorIndex);
|
||
|
|
|
||
|
|
// 加载选中传感器的数据
|
||
|
|
LoadSensorData(sensorIndex);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 保存当前传感器的数据
|
||
|
|
private void SaveCurrentSensorData()
|
||
|
|
{
|
||
|
|
// 获取当前选中的传感器索引
|
||
|
|
int currentSensorIndex = GetCurrentSelectedSensorIndex();
|
||
|
|
|
||
|
|
if (sensorData.ContainsKey(currentSensorIndex))
|
||
|
|
{
|
||
|
|
sensorData[currentSensorIndex].MaxTolerance = MaxToleranceTextBox.Text;
|
||
|
|
sensorData[currentSensorIndex].BaseTolerance = BaseToleranceTextBox.Text;
|
||
|
|
sensorData[currentSensorIndex].MinTolerance = MinToleranceTextBox.Text;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取当前选中的传感器索引
|
||
|
|
private int GetCurrentSelectedSensorIndex()
|
||
|
|
{
|
||
|
|
if (SensorTab1.Background is SolidColorBrush brush1 && brush1.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||
|
|
return 1;
|
||
|
|
if (SensorTab2.Background is SolidColorBrush brush2 && brush2.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||
|
|
return 2;
|
||
|
|
if (SensorTab3.Background is SolidColorBrush brush3 && brush3.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||
|
|
return 3;
|
||
|
|
if (SensorTab4.Background is SolidColorBrush brush4 && brush4.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||
|
|
return 4;
|
||
|
|
return 1; // 默认返回传感器1
|
||
|
|
}
|
||
|
|
|
||
|
|
// 更新标签页样式
|
||
|
|
private void UpdateTabStyles(int selectedIndex)
|
||
|
|
{
|
||
|
|
// 重置所有标签页样式
|
||
|
|
SensorTab1.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||
|
|
SensorTab2.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||
|
|
SensorTab3.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||
|
|
SensorTab4.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||
|
|
|
||
|
|
// 设置选中标签页样式
|
||
|
|
switch (selectedIndex)
|
||
|
|
{
|
||
|
|
case 1:
|
||
|
|
SensorTab1.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"));
|
||
|
|
break;
|
||
|
|
case 2:
|
||
|
|
SensorTab2.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"));
|
||
|
|
break;
|
||
|
|
case 3:
|
||
|
|
SensorTab3.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"));
|
||
|
|
break;
|
||
|
|
case 4:
|
||
|
|
SensorTab4.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"));
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 加载传感器数据
|
||
|
|
private void LoadSensorData(int sensorIndex)
|
||
|
|
{
|
||
|
|
if (sensorData.ContainsKey(sensorIndex))
|
||
|
|
{
|
||
|
|
var data = sensorData[sensorIndex];
|
||
|
|
MaxToleranceTextBox.Text = data.MaxTolerance;
|
||
|
|
BaseToleranceTextBox.Text = data.BaseTolerance;
|
||
|
|
MinToleranceTextBox.Text = data.MinTolerance;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 传感器公差数据类
|
||
|
|
public class SensorToleranceData
|
||
|
|
{
|
||
|
|
public string MaxTolerance { get; set; }
|
||
|
|
public string BaseTolerance { get; set; }
|
||
|
|
public string MinTolerance { get; set; }
|
||
|
|
}
|
||
|
|
}
|