系统配置存入数据库进行中
This commit is contained in:
parent
57f870ae49
commit
56be63db49
|
|
@ -215,11 +215,11 @@
|
||||||
Background="#333333" Foreground="White" HorizontalAlignment="Center" Margin="0,30,0,0"/>
|
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"/>
|
<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">
|
<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>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ public partial class ConfigPage : Page
|
||||||
public ConfigPage(LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
|
public ConfigPage(LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
InitializeLevelData();
|
|
||||||
log = logService;
|
log = logService;
|
||||||
db = databaseService;
|
db = databaseService;
|
||||||
even = eventService;
|
even = eventService;
|
||||||
|
|
@ -37,6 +36,9 @@ public partial class ConfigPage : Page
|
||||||
InitializeSensorData();
|
InitializeSensorData();
|
||||||
// 主传感器选择
|
// 主传感器选择
|
||||||
LoadMainSensorSelectionFromDb();
|
LoadMainSensorSelectionFromDb();
|
||||||
|
// 等级
|
||||||
|
InitializeLevelData();
|
||||||
|
|
||||||
|
|
||||||
// 注册等级标签按钮点击事件
|
// 注册等级标签按钮点击事件
|
||||||
LevelTabUnder.Click += LevelTab_Click;
|
LevelTabUnder.Click += LevelTab_Click;
|
||||||
|
|
@ -50,7 +52,7 @@ public partial class ConfigPage : Page
|
||||||
LevelTabOver.Click += LevelTab_Click;
|
LevelTabOver.Click += LevelTab_Click;
|
||||||
|
|
||||||
// 默认选中 Under
|
// 默认选中 Under
|
||||||
LevelTabUnder.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
|
//LevelTabUnder.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -304,36 +306,85 @@ public partial class ConfigPage : Page
|
||||||
|
|
||||||
|
|
||||||
#region 第五部分 等级
|
#region 第五部分 等级
|
||||||
|
|
||||||
// 初始化等级数据
|
// 初始化等级数据
|
||||||
private void InitializeLevelData()
|
private void InitializeLevelData()
|
||||||
{
|
{
|
||||||
levelData = new Dictionary<string, LevelInfo>();
|
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" };
|
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)
|
foreach (var tab in tabs)
|
||||||
{
|
{
|
||||||
// 默认数据和 Under 一样
|
var sensorRank = sensorsRank.FirstOrDefault(s => s.Name == tab);
|
||||||
levelData[tab] = new LevelInfo
|
if (sensorRank != null)
|
||||||
{
|
{
|
||||||
Low = "-0.0090",
|
levelData[tab] = sensorRank;
|
||||||
High = "0.0090",
|
}
|
||||||
Mark = "标记",
|
else
|
||||||
Status = "NG"
|
{
|
||||||
};
|
// 没有数据库记录则初始化默认值
|
||||||
|
levelData[tab] = new LevelInfo
|
||||||
|
{
|
||||||
|
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)
|
private void LevelTab_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is Button btn && btn.Tag is string tabName)
|
if (sender is Button btn && btn.Tag is string tabName)
|
||||||
{
|
{
|
||||||
// 保存当前显示的数据到上一个等级
|
// 保存当前等级修改
|
||||||
SaveCurrentLevelData();
|
SaveCurrentLevelData();
|
||||||
|
|
||||||
// 更新标签按钮样式
|
// 更新标签样式
|
||||||
UpdateTabStyles(btn);
|
UpdateTabStyles(btn);
|
||||||
|
|
||||||
// 加载选中等级的数据
|
// 加载新等级
|
||||||
LoadLevelData(tabName);
|
LoadLevelData(tabName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -342,38 +393,35 @@ public partial class ConfigPage : Page
|
||||||
private void SaveCurrentLevelData()
|
private void SaveCurrentLevelData()
|
||||||
{
|
{
|
||||||
string currentTab = GetCurrentSelectedTab();
|
string currentTab = GetCurrentSelectedTab();
|
||||||
if (currentTab == null) return;
|
if (currentTab == null || !levelData.ContainsKey(currentTab))
|
||||||
|
return;
|
||||||
|
|
||||||
foreach (var child in LevelInfoPanel.Children)
|
var data = levelData[currentTab];
|
||||||
{
|
|
||||||
if (child is Grid g)
|
// 直接取命名控件的值最稳妥
|
||||||
{
|
if (LowerLimitTextBlock != null)
|
||||||
foreach (var element in g.Children)
|
data.Low = LowerLimitTextBlock.Text ?? "0.0";
|
||||||
{
|
|
||||||
if (element is TextBox tb && Grid.GetColumn(tb) == 2 && Grid.GetRow(tb) == 1)
|
if (HighLimitTextBox != null)
|
||||||
{
|
data.High = HighLimitTextBox.Text ?? "0.0";
|
||||||
levelData[currentTab].Low = tb.Text;
|
|
||||||
}
|
if (UnitMarkTextBlock != null)
|
||||||
if (element is Border br && Grid.GetColumn(br) == 3 && Grid.GetRow(br) == 1)
|
data.Mark = UnitMarkTextBlock.Text ?? "NG";
|
||||||
{
|
|
||||||
if (br.Child is TextBlock tblock)
|
|
||||||
levelData[currentTab].Status = tblock.Text;
|
|
||||||
}
|
|
||||||
// 如果你后续要保存 High 或 Mark,可以在这里添加
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前选中的标签名
|
// 获取当前选中的标签名
|
||||||
private string GetCurrentSelectedTab()
|
private string GetCurrentSelectedTab()
|
||||||
{
|
{
|
||||||
foreach (var child in ((Grid)LevelTabUnder.Parent).Children)
|
if (LevelTabUnder?.Parent is Grid grid)
|
||||||
{
|
{
|
||||||
if (child is Button b && b.Background is SolidColorBrush brush)
|
foreach (var child in grid.Children)
|
||||||
{
|
{
|
||||||
if (brush.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
if (child is Button b && b.Background is SolidColorBrush brush)
|
||||||
return b.Tag?.ToString();
|
{
|
||||||
|
var activeColor = (Color)ColorConverter.ConvertFromString("#E6F3FF");
|
||||||
|
if (brush.Color == activeColor)
|
||||||
|
return b.Tag?.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -382,47 +430,24 @@ public partial class ConfigPage : Page
|
||||||
// 更新等级标签按钮样式
|
// 更新等级标签按钮样式
|
||||||
private void UpdateTabStyles(Button selectedBtn)
|
private void UpdateTabStyles(Button selectedBtn)
|
||||||
{
|
{
|
||||||
foreach (var child in ((Grid)LevelTabUnder.Parent).Children)
|
if (selectedBtn?.Parent is Grid grid)
|
||||||
{
|
{
|
||||||
if (child is Button b)
|
foreach (var child in grid.Children)
|
||||||
{
|
{
|
||||||
b.Background = (b == selectedBtn)
|
if (child is Button b)
|
||||||
? 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)
|
b.Background = (b == selectedBtn)
|
||||||
{
|
? new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF")) // 选中浅蓝
|
||||||
tb.Text = data.Low;
|
: new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0")); // 未选灰
|
||||||
}
|
|
||||||
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
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user