add:点名历史查看

This commit is contained in:
CJK_mkp
2025-11-08 18:01:56 +08:00
parent 4b2f29442a
commit a8dcbd4af0
4 changed files with 258 additions and 1 deletions
@@ -856,6 +856,21 @@ namespace Ink_Canvas
}
}
private void ViewHistory_Click(object sender, RoutedEventArgs e)
{
try
{
// 打开历史记录查看窗口
var historyWindow = new RollCallHistoryWindow();
historyWindow.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show($"打开历史记录失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
LogHelper.WriteLogToFile($"打开历史记录失败: {ex.Message}", LogHelper.LogType.Error);
}
}
private void LoadNamesFromFile()
{
try
+13 -1
View File
@@ -418,7 +418,7 @@
Foreground="{DynamicResource NewRollCallWindowButtonForeground}"/>
</Button>
<Button x:Name="ClearListBtn" Width="90" Height="40" Background="{DynamicResource NewRollCallWindowButtonBackground}"
BorderThickness="0" Click="ClearList_Click" Cursor="Hand">
BorderThickness="0" Click="ClearList_Click" Cursor="Hand" Margin="0,0,10,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="8">
@@ -429,6 +429,18 @@
<TextBlock Text="清空名单" FontSize="14"
Foreground="{DynamicResource NewRollCallWindowButtonForeground}"/>
</Button>
<Button x:Name="ViewHistoryBtn" Width="90" Height="40" Background="{DynamicResource NewRollCallWindowButtonBackground}"
BorderThickness="0" Click="ViewHistory_Click" Cursor="Hand">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="8">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="查看历史" FontSize="14"
Foreground="{DynamicResource NewRollCallWindowButtonForeground}"/>
</Button>
</StackPanel>
</StackPanel>
</Grid>
@@ -0,0 +1,46 @@
<Window x:Class="Ink_Canvas.RollCallHistoryWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Ink_Canvas"
mc:Ignorable="d" FontFamily="Microsoft YaHei UI" ui:WindowHelper.UseModernWindowStyle="True"
WindowStartupLocation="CenterScreen"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" Topmost="True"
Title="Ink Canvas 抽奖 - 点名历史记录" Height="500" Width="400"
Loaded="Window_Loaded">
<Window.Resources>
<!-- 主题资源 -->
<SolidColorBrush x:Key="RollCallHistoryWindowBackground" Color="White"/>
<SolidColorBrush x:Key="RollCallHistoryWindowForeground" Color="Black"/>
<SolidColorBrush x:Key="RollCallHistoryWindowButtonBackground" Color="#F4F4F5"/>
<SolidColorBrush x:Key="RollCallHistoryWindowButtonForeground" Color="Black"/>
<SolidColorBrush x:Key="RollCallHistoryWindowBorderBrush" Color="#E4E4E7"/>
</Window.Resources>
<Grid Background="{DynamicResource RollCallHistoryWindowBackground}">
<Label Content="点名历史记录"
Margin="10"
Foreground="{DynamicResource RollCallHistoryWindowForeground}"
FontFamily="Microsoft YaHei UI"/>
<TextBox Name="TextBoxHistory"
FontFamily="Microsoft YaHei UI"
VerticalScrollBarVisibility="Auto"
AcceptsReturn="True"
IsReadOnly="True"
Margin="10,40,10,50"
Background="{DynamicResource RollCallHistoryWindowBackground}"
Foreground="{DynamicResource RollCallHistoryWindowForeground}"
BorderBrush="{DynamicResource RollCallHistoryWindowBorderBrush}"/>
<Button Margin="10"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Content="关闭"
FontFamily="Microsoft YaHei UI"
Width="100"
Click="Button_Click"
Background="{DynamicResource RollCallHistoryWindowButtonBackground}"
Foreground="{DynamicResource RollCallHistoryWindowButtonForeground}"
BorderBrush="{DynamicResource RollCallHistoryWindowBorderBrush}"/>
</Grid>
</Window>
@@ -0,0 +1,184 @@
using Ink_Canvas.Helpers;
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using Newtonsoft.Json;
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
namespace Ink_Canvas
{
/// <summary>
/// Interaction logic for RollCallHistoryWindow.xaml
/// </summary>
public partial class RollCallHistoryWindow : Window
{
public RollCallHistoryWindow()
{
InitializeComponent();
AnimationsHelper.ShowWithSlideFromBottomAndFade(this, 0.25);
ApplyTheme();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LoadHistory();
}
private void LoadHistory()
{
try
{
string configsFolder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs");
string historyJsonPath = System.IO.Path.Combine(configsFolder, "RollCallHistory.json");
if (!File.Exists(historyJsonPath))
{
TextBoxHistory.Text = "暂无历史记录";
return;
}
string jsonContent = File.ReadAllText(historyJsonPath);
var historyData = JsonConvert.DeserializeObject<RollCallHistoryData>(jsonContent);
if (historyData == null || historyData.History == null || historyData.History.Count == 0)
{
TextBoxHistory.Text = "暂无历史记录";
return;
}
// 按时间倒序显示(最新的在上方)
// 由于历史记录是按时间顺序添加的,所以直接反转即可
var reversedHistory = historyData.History.ToList();
reversedHistory.Reverse();
// 显示历史记录,每行一个
TextBoxHistory.Text = string.Join(Environment.NewLine, reversedHistory);
// 显示统计信息
int totalCount = historyData.History.Count;
string lastUpdate = historyData.LastUpdate.ToString("yyyy-MM-dd HH:mm:ss");
string header = $"共 {totalCount} 条记录,最后更新:{lastUpdate}\n\n";
TextBoxHistory.Text = header + TextBoxHistory.Text;
}
catch (Exception ex)
{
TextBoxHistory.Text = $"加载历史记录失败: {ex.Message}";
LogHelper.WriteLogToFile($"加载点名历史记录失败: {ex.Message}", LogHelper.LogType.Error);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void ApplyTheme()
{
try
{
if (MainWindow.Settings != null)
{
ApplyTheme(MainWindow.Settings);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"应用历史记录窗口主题出错: {ex.Message}", LogHelper.LogType.Error);
}
}
private void ApplyTheme(Settings settings)
{
try
{
if (settings.Appearance.Theme == 0) // 浅色主题
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Light);
ApplyThemeResources("Light");
}
else if (settings.Appearance.Theme == 1) // 深色主题
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Dark);
ApplyThemeResources("Dark");
}
else // 跟随系统主题
{
bool isSystemLight = IsSystemThemeLight();
if (isSystemLight)
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Light);
ApplyThemeResources("Light");
}
else
{
iNKORE.UI.WPF.Modern.ThemeManager.SetRequestedTheme(this, iNKORE.UI.WPF.Modern.ElementTheme.Dark);
ApplyThemeResources("Dark");
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"应用历史记录窗口主题出错: {ex.Message}", LogHelper.LogType.Error);
}
}
private void ApplyThemeResources(string theme)
{
try
{
var resources = this.Resources;
if (theme == "Light")
{
// 应用浅色主题资源
resources["RollCallHistoryWindowBackground"] = new SolidColorBrush(Color.FromRgb(255, 255, 255));
resources["RollCallHistoryWindowForeground"] = new SolidColorBrush(Color.FromRgb(24, 24, 27));
resources["RollCallHistoryWindowButtonBackground"] = new SolidColorBrush(Color.FromRgb(244, 244, 245));
resources["RollCallHistoryWindowButtonForeground"] = new SolidColorBrush(Color.FromRgb(24, 24, 27));
resources["RollCallHistoryWindowBorderBrush"] = new SolidColorBrush(Color.FromRgb(228, 228, 231));
}
else
{
// 应用深色主题资源
resources["RollCallHistoryWindowBackground"] = new SolidColorBrush(Color.FromRgb(31, 31, 31)); // #1f1f1f
resources["RollCallHistoryWindowForeground"] = new SolidColorBrush(Colors.White);
resources["RollCallHistoryWindowButtonBackground"] = new SolidColorBrush(Color.FromRgb(42, 42, 42)); // #2a2a2a
resources["RollCallHistoryWindowButtonForeground"] = new SolidColorBrush(Colors.White);
resources["RollCallHistoryWindowBorderBrush"] = new SolidColorBrush(Color.FromRgb(224, 224, 224)); // #E0E0E0
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"应用历史记录窗口主题资源出错: {ex.Message}", LogHelper.LogType.Error);
}
}
private bool IsSystemThemeLight()
{
var light = false;
try
{
var registryKey = Microsoft.Win32.Registry.CurrentUser;
var themeKey = registryKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
if (themeKey != null)
{
var value = themeKey.GetValue("AppsUseLightTheme");
if (value != null)
{
light = (int)value == 1;
}
themeKey.Close();
}
}
catch
{
// 如果无法读取注册表,默认使用浅色主题
light = true;
}
return light;
}
}
}