系统配置存入数据库进行中
This commit is contained in:
parent
57f870ae49
commit
56be63db49
|
|
@ -215,11 +215,11 @@
|
|||
Background="#333333" Foreground="White" HorizontalAlignment="Center" Margin="0,30,0,0"/>
|
||||
|
||||
<!-- 数值行 -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="下限" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,30,0,0" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" x:Name="LowerLimitTextBlock" Text="下限" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,30,0,0" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="<" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="16" Margin="0,30,0,0"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="2" Text="-0.0090" Height="30" Background="#E6F3FF" HorizontalAlignment="Center" Width="100" Margin="0,30,0,0"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="2" x:Name="HighLimitTextBox" Text="-0.0090" Height="30" Background="#E6F3FF" HorizontalAlignment="Center" Width="100" Margin="0,30,0,0"/>
|
||||
<Border Grid.Row="1" Grid.Column="3" Background="#CCCCCC" Height="30" Width="50" Margin="0,30,0,0">
|
||||
<TextBlock Text="NG" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
|
||||
<TextBlock x:Name="UnitMarkTextBlock" Text="NG" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ public partial class ConfigPage : Page
|
|||
public ConfigPage(LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeLevelData();
|
||||
log = logService;
|
||||
db = databaseService;
|
||||
even = eventService;
|
||||
|
|
@ -37,6 +36,9 @@ public partial class ConfigPage : Page
|
|||
InitializeSensorData();
|
||||
// 主传感器选择
|
||||
LoadMainSensorSelectionFromDb();
|
||||
// 等级
|
||||
InitializeLevelData();
|
||||
|
||||
|
||||
// 注册等级标签按钮点击事件
|
||||
LevelTabUnder.Click += LevelTab_Click;
|
||||
|
|
@ -50,7 +52,7 @@ public partial class ConfigPage : Page
|
|||
LevelTabOver.Click += LevelTab_Click;
|
||||
|
||||
// 默认选中 Under
|
||||
LevelTabUnder.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
|
||||
//LevelTabUnder.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -304,36 +306,85 @@ public partial class ConfigPage : Page
|
|||
|
||||
|
||||
#region 第五部分 等级
|
||||
|
||||
// 初始化等级数据
|
||||
private void InitializeLevelData()
|
||||
{
|
||||
levelData = new Dictionary<string, LevelInfo>();
|
||||
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
if (scope == null)
|
||||
{
|
||||
MessageBox.Show("SqlSugarScope 获取失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
string productName = "DFPV C15TE"; // TODO: 根据实际选择的产品替换
|
||||
string[] tabs = { "Under", "A", "B", "C", "D", "E", "F", "G", "Over" };
|
||||
|
||||
// 从数据库查询该产品的等级数据
|
||||
var sensorsRank = scope.Queryable<LevelInfo>()
|
||||
.Where(s => s.ProductName == productName)
|
||||
.ToList();
|
||||
|
||||
// 初始化每个等级
|
||||
foreach (var tab in tabs)
|
||||
{
|
||||
// 默认数据和 Under 一样
|
||||
var sensorRank = sensorsRank.FirstOrDefault(s => s.Name == tab);
|
||||
if (sensorRank != null)
|
||||
{
|
||||
levelData[tab] = sensorRank;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 没有数据库记录则初始化默认值
|
||||
levelData[tab] = new LevelInfo
|
||||
{
|
||||
Low = "-0.0090",
|
||||
High = "0.0090",
|
||||
Mark = "标记",
|
||||
Status = "NG"
|
||||
Name = tab,
|
||||
Low = "0.0",
|
||||
High = "0.0",
|
||||
Mark = "NG",
|
||||
Status = "NG",
|
||||
ProductName = productName
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 默认加载第一个等级
|
||||
LoadLevelData(tabs[0]);
|
||||
}
|
||||
|
||||
// 加载数据到界面
|
||||
private void LoadLevelData(string sensorIndex)
|
||||
{
|
||||
if (!levelData.ContainsKey(sensorIndex))
|
||||
return;
|
||||
|
||||
var data = levelData[sensorIndex];
|
||||
|
||||
// 加强防护,防止 NullReferenceException
|
||||
if (LowerLimitTextBlock != null)
|
||||
LowerLimitTextBlock.Text = data.Low ?? "下限";
|
||||
|
||||
if (HighLimitTextBox != null)
|
||||
HighLimitTextBox.Text = data.High ?? "0.0";
|
||||
|
||||
if (UnitMarkTextBlock != null)
|
||||
UnitMarkTextBlock.Text = data.Mark ?? "NG";
|
||||
}
|
||||
|
||||
// 等级标签按钮点击事件
|
||||
private void LevelTab_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button btn && btn.Tag is string tabName)
|
||||
{
|
||||
// 保存当前显示的数据到上一个等级
|
||||
// 保存当前等级修改
|
||||
SaveCurrentLevelData();
|
||||
|
||||
// 更新标签按钮样式
|
||||
// 更新标签样式
|
||||
UpdateTabStyles(btn);
|
||||
|
||||
// 加载选中等级的数据
|
||||
// 加载新等级
|
||||
LoadLevelData(tabName);
|
||||
}
|
||||
}
|
||||
|
|
@ -342,87 +393,61 @@ public partial class ConfigPage : Page
|
|||
private void SaveCurrentLevelData()
|
||||
{
|
||||
string currentTab = GetCurrentSelectedTab();
|
||||
if (currentTab == null) return;
|
||||
if (currentTab == null || !levelData.ContainsKey(currentTab))
|
||||
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,可以在这里添加
|
||||
}
|
||||
}
|
||||
}
|
||||
var data = levelData[currentTab];
|
||||
|
||||
// 直接取命名控件的值最稳妥
|
||||
if (LowerLimitTextBlock != null)
|
||||
data.Low = LowerLimitTextBlock.Text ?? "0.0";
|
||||
|
||||
if (HighLimitTextBox != null)
|
||||
data.High = HighLimitTextBox.Text ?? "0.0";
|
||||
|
||||
if (UnitMarkTextBlock != null)
|
||||
data.Mark = UnitMarkTextBlock.Text ?? "NG";
|
||||
}
|
||||
|
||||
// 获取当前选中的标签名
|
||||
private string GetCurrentSelectedTab()
|
||||
{
|
||||
foreach (var child in ((Grid)LevelTabUnder.Parent).Children)
|
||||
if (LevelTabUnder?.Parent is Grid grid)
|
||||
{
|
||||
foreach (var child in grid.Children)
|
||||
{
|
||||
if (child is Button b && b.Background is SolidColorBrush brush)
|
||||
{
|
||||
if (brush.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
var activeColor = (Color)ColorConverter.ConvertFromString("#E6F3FF");
|
||||
if (brush.Color == activeColor)
|
||||
return b.Tag?.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 更新等级标签按钮样式
|
||||
private void UpdateTabStyles(Button selectedBtn)
|
||||
{
|
||||
foreach (var child in ((Grid)LevelTabUnder.Parent).Children)
|
||||
if (selectedBtn?.Parent is Grid grid)
|
||||
{
|
||||
foreach (var child in grid.Children)
|
||||
{
|
||||
if (child is Button b)
|
||||
{
|
||||
b.Background = (b == selectedBtn)
|
||||
? new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"))
|
||||
: new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||||
? 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 可在此扩展
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user