系统配置进行中

This commit is contained in:
YONGYE 2025-10-14 13:11:49 +08:00
parent 4b5ac96b7c
commit a2fffbff37

View File

@ -1,17 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using guoke;
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;
using System.Collections.Generic;
namespace WpfApp.src.view
{
@ -20,15 +11,149 @@ namespace WpfApp.src.view
/// </summary>
public partial class ConfigPage : Page
{
// 传感器数据字典,存储每个传感器的公差设定值
// 等级数据字典,每个等级对应 LevelInfo
private Dictionary<string, LevelInfo> levelData;
private Dictionary<int, SensorToleranceData> sensorData;
public ConfigPage()
{
InitializeComponent();
InitializeLevelData();
InitializeSensorData();
// 注册等级标签按钮点击事件
LevelTabUnder.Click += LevelTab_Click;
LevelTabA.Click += LevelTab_Click;
LevelTabB.Click += LevelTab_Click;
LevelTabC.Click += LevelTab_Click;
LevelTabD.Click += LevelTab_Click;
LevelTabE.Click += LevelTab_Click;
LevelTabF.Click += LevelTab_Click;
LevelTabG.Click += LevelTab_Click;
LevelTabOver.Click += LevelTab_Click;
// 默认选中 Under
LevelTabUnder.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
}
// 初始化等级数据
private void InitializeLevelData()
{
levelData = new Dictionary<string, LevelInfo>();
string[] tabs = { "Under", "A", "B", "C", "D", "E", "F", "G", "Over" };
foreach (var tab in tabs)
{
// 默认数据和 Under 一样
levelData[tab] = new LevelInfo
{
Low = "-0.0090",
High = "0.0090",
Mark = "标记",
Status = "NG"
};
}
}
// 等级标签按钮点击事件
private void LevelTab_Click(object sender, RoutedEventArgs e)
{
if (sender is Button btn && btn.Tag is string tabName)
{
// 保存当前显示的数据到上一个等级
SaveCurrentLevelData();
// 更新标签按钮样式
UpdateTabStyles(btn);
// 加载选中等级的数据
LoadLevelData(tabName);
}
}
// 保存当前显示的等级数据
private void SaveCurrentLevelData()
{
string currentTab = GetCurrentSelectedTab();
if (currentTab == null) return;
foreach (var child in LevelInfoPanel.Children)
{
if (child is Grid g)
{
foreach (var element in g.Children)
{
if (element is TextBox tb && Grid.GetColumn(tb) == 2 && Grid.GetRow(tb) == 1)
{
levelData[currentTab].Low = tb.Text;
}
if (element is Border br && Grid.GetColumn(br) == 3 && Grid.GetRow(br) == 1)
{
if (br.Child is TextBlock tblock)
levelData[currentTab].Status = tblock.Text;
}
// 如果你后续要保存 High 或 Mark可以在这里添加
}
}
}
}
// 获取当前选中的标签名
private string GetCurrentSelectedTab()
{
foreach (var child in ((Grid)LevelTabUnder.Parent).Children)
{
if (child is Button b && b.Background is SolidColorBrush brush)
{
if (brush.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
return b.Tag?.ToString();
}
}
return null;
}
// 更新等级标签按钮样式
private void UpdateTabStyles(Button selectedBtn)
{
foreach (var child in ((Grid)LevelTabUnder.Parent).Children)
{
if (child is Button b)
{
b.Background = (b == selectedBtn)
? new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"))
: new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
}
}
}
// 加载等级数据到界面
private void LoadLevelData(string tabName)
{
if (!levelData.ContainsKey(tabName)) return;
var data = levelData[tabName];
foreach (var child in LevelInfoPanel.Children)
{
if (child is Grid g)
{
foreach (var element in g.Children)
{
if (element is TextBox tb && Grid.GetColumn(tb) == 2 && Grid.GetRow(tb) == 1)
{
tb.Text = data.Low;
}
if (element is Border br && Grid.GetColumn(br) == 3 && Grid.GetRow(br) == 1)
{
if (br.Child is TextBlock tblock)
tblock.Text = data.Status;
}
// High 或 Mark 可在此扩展
}
}
}
}
// 初始化传感器数据
private void InitializeSensorData()
{
@ -40,7 +165,6 @@ namespace WpfApp.src.view
{ 4, new SensorToleranceData { MaxTolerance = "6.90", BaseTolerance = "72.6900", MinTolerance = "-6.90" } }
};
}
// 传感器标签页点击事件处理
private void SensorTab_Click(object sender, RoutedEventArgs e)
{
@ -58,7 +182,6 @@ namespace WpfApp.src.view
// 加载选中传感器的数据
LoadSensorData(sensorIndex);
}
// 保存当前传感器的数据
private void SaveCurrentSensorData()
{
@ -73,6 +196,7 @@ namespace WpfApp.src.view
}
}
// 获取当前选中的传感器索引
private int GetCurrentSelectedSensorIndex()
{
@ -125,6 +249,18 @@ namespace WpfApp.src.view
MinToleranceTextBox.Text = data.MinTolerance;
}
}
}
// 等级信息数据类
public class LevelInfo
{
public string Low { get; set; }
public string High { get; set; }
public string Mark { get; set; }
public string Status { get; set; }
}
// 传感器公差数据类
@ -134,4 +270,5 @@ namespace WpfApp.src.view
public string BaseTolerance { get; set; }
public string MinTolerance { get; set; }
}
}