Browse Source

添加关机退出按钮

master
sc 2 months ago
parent
commit
8db7de1d3c
  1. 2
      MainWindow.xaml
  2. 10
      View/EngineerSetView.xaml
  3. 21
      View/EngineerSetView.xaml.cs
  4. 6
      ViewModel/MainWindowViewModel.cs

2
MainWindow.xaml

@ -8,7 +8,7 @@
xmlns:viewmodel="clr-namespace:DyeingComputer.ViewModel" xmlns:viewmodel="clr-namespace:DyeingComputer.ViewModel"
d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}" d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
mc:Ignorable="d" mc:Ignorable="d"
Title="SUNLIGHT 838 b0.0.1 (2024/08/10)" Title="SUNLIGHT838"
Height="720" Width="1280" Height="720" Width="1280"
WindowState ="Maximized" WindowState ="Maximized"
WindowStyle="None"> WindowStyle="None">

10
View/EngineerSetView.xaml

@ -17,8 +17,8 @@
<TextBlock Name="RX" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="30" Width="100" Margin="5,0,0,0"/> <TextBlock Name="RX" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="30" Width="100" Margin="5,0,0,0"/>
<TextBlock Name="TX" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="30" Width="100" Margin="200,0,0,0"/> <TextBlock Name="TX" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="30" Width="100" Margin="200,0,0,0"/>
<DataGrid x:Name="_set" AutoGenerateColumns="False" FontSize="15" <DataGrid x:Name="_set" AutoGenerateColumns="False" FontSize="15" ColumnHeaderHeight="40" Width="600"
ColumnHeaderHeight="40" Width="400" HorizontalAlignment="Right" Margin="0,10,10,200" Background="{x:Null}" > HorizontalAlignment="Right" Margin="0,10,10,200" Background="{x:Null}" >
<DataGrid.RowStyle > <DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}"> <Style TargetType="{x:Type DataGridRow}">
<Setter Property="Height" Value="30" /> <Setter Property="Height" Value="30" />
@ -49,12 +49,14 @@
</DataGrid.CellStyle> </DataGrid.CellStyle>
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn Header="Key" Binding="{Binding Key}" Width="*"/> <DataGridTextColumn Header="Key" Binding="{Binding Key}" Width="*"/>
<DataGridTextColumn Header="Type" Binding="{Binding Value}" Width="*"/> <DataGridTextColumn Header="Type" Binding="{Binding Value}" Width="200"/>
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<Button Content="{x:Static lang:Resources.Shutdown}" x:Name="Shutdown" FontSize="20" HorizontalAlignment="Right" Height="40" Margin="0,0,10,10" <Button Content="{x:Static lang:Resources.Shutdown}" x:Name="Shutdown" FontSize="20" HorizontalAlignment="Right" Height="40" Margin="0,0,20,20"
VerticalAlignment="Bottom" Width="200" Background="White" Click="Shutdown_Click"/> VerticalAlignment="Bottom" Width="200" Background="White" Click="Shutdown_Click"/>
<Button Content="{x:Static lang:Resources.Quit}" x:Name="Quit" FontSize="20" HorizontalAlignment="Right" Height="40" Margin="0,0,300,20"
VerticalAlignment="Bottom" Width="200" Background="White" Click="Quit_Click"/>
</Grid> </Grid>
</UserControl> </UserControl>

21
View/EngineerSetView.xaml.cs

@ -1,6 +1,7 @@
using DyeingComputer.ViewModel; using DyeingComputer.ViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -22,6 +23,7 @@ namespace DyeingComputer.View
/// </summary> /// </summary>
public partial class EngineerSetView : UserControl public partial class EngineerSetView : UserControl
{ {
int _S=0;
public EngineerSetView() public EngineerSetView()
{ {
InitializeComponent(); InitializeComponent();
@ -70,6 +72,10 @@ namespace DyeingComputer.View
RX.Text = MainWindowViewModel.RX.ToString(); RX.Text = MainWindowViewModel.RX.ToString();
TX.Text = MainWindowViewModel.TX.ToString(); TX.Text = MainWindowViewModel.TX.ToString();
_S++;
if (_S > 60)
{
_S = 0;
var displayData = MainWindowViewModel.Hardware.Select(kvp => new AdvancedDictionaryEntry var displayData = MainWindowViewModel.Hardware.Select(kvp => new AdvancedDictionaryEntry
{ {
Key = kvp.Key, Key = kvp.Key,
@ -77,6 +83,18 @@ namespace DyeingComputer.View
}).ToList(); }).ToList();
_set.ItemsSource = displayData; _set.ItemsSource = displayData;
} }
}
private void Quit_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show(Properties.Resources.Quit, "800", MessageBoxButton.YesNo);
if (messageBoxResult == MessageBoxResult.No) return;
if (messageBoxResult == MessageBoxResult.Yes)
{
// Application.Current.Shutdown();
System.Environment.Exit(0);//退出
}
}
private void Shutdown_Click(object sender, RoutedEventArgs e) private void Shutdown_Click(object sender, RoutedEventArgs e)
{ {
@ -85,7 +103,8 @@ namespace DyeingComputer.View
if (messageBoxResult == MessageBoxResult.Yes) if (messageBoxResult == MessageBoxResult.Yes)
{ {
// Application.Current.Shutdown(); // Application.Current.Shutdown();
System.Environment.Exit(0);//退出 //System.Environment.Exit(0);//退出
Process.Start("shutdown", "/s /t 10");
} }
} }

6
ViewModel/MainWindowViewModel.cs

@ -725,11 +725,11 @@ namespace DyeingComputer.ViewModel
hardwareItem.Update(); // 更新硬件信息:cite[2] hardwareItem.Update(); // 更新硬件信息:cite[2]
foreach (var sensor in hardwareItem.Sensors) foreach (var sensor in hardwareItem.Sensors)
{ {
if (sensor.SensorType == SensorType.Temperature && sensor.Value.HasValue) // if (sensor.SensorType == SensorType.Temperature && sensor.Value.HasValue)
{ {
//Console.WriteLine($"{hardwareItem.Name} - {sensor.Name}: {sensor.Value.Value}°C"); //Console.WriteLine($"{hardwareItem.Name} - {sensor.Name}: {sensor.Value.Value}°C");
// 实际应用中,你可能需要将这里的数据绑定到UI控件或存储起来 // 实际应用中,你可能需要将这里的数据绑定到UI控件或存储起来
Hardware.Add(sensor.Name, sensor.Value.Value); Hardware.Add(sensor.Name+":"+sensor.SensorType, sensor.Value.Value);
} }
} }
} }
@ -752,7 +752,7 @@ namespace DyeingComputer.ViewModel
if (timer1s_ >= 2) { timer1s_ =0; Tick_Event_1S(); } if (timer1s_ >= 2) { timer1s_ =0; Tick_Event_1S(); }
if (timer5s_ >=10) { timer5s_ = 0; Tick_Event_5S(); } if (timer5s_ >=10) { timer5s_ = 0; Tick_Event_5S(); }
if (timer60s_ >= 20) { timer60s_ = 0; Tick_Event_60S(); } if (timer60s_ >= 120) { timer60s_ = 0; Tick_Event_60S(); }
if (LINK_OK) IO_data(); if (LINK_OK) IO_data();
} }
void Chart() void Chart()

Loading…
Cancel
Save