diff --git a/src/view/ConfigPage.xaml.cs b/src/view/ConfigPage.xaml.cs index a9e2e74..7bc3f98 100644 --- a/src/view/ConfigPage.xaml.cs +++ b/src/view/ConfigPage.xaml.cs @@ -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,27 +11,160 @@ namespace WpfApp.src.view /// public partial class ConfigPage : Page { - // 传感器数据字典,存储每个传感器的公差设定值 + // 等级数据字典,每个等级对应 LevelInfo + private Dictionary levelData; private Dictionary 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[] 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() { sensorData = new Dictionary - { - { 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" } } - }; + { + { 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) { @@ -58,13 +182,12 @@ namespace WpfApp.src.view // 加载选中传感器的数据 LoadSensorData(sensorIndex); } - // 保存当前传感器的数据 private void SaveCurrentSensorData() { // 获取当前选中的传感器索引 int currentSensorIndex = GetCurrentSelectedSensorIndex(); - + if (sensorData.ContainsKey(currentSensorIndex)) { sensorData[currentSensorIndex].MaxTolerance = MaxToleranceTextBox.Text; @@ -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; } } + }