TFLH/FeiYu/MainWindow.xaml.cs
2026-08-06 09:50:46 +08:00

160 lines
4.6 KiB
C#

using ControlzEx.Theming;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 ViewModel;
using Views;
using Community;
using Model;
using System.Threading;
namespace FeiYu
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : MetroWindow
{
/// <summary>
/// 主逻辑对象
/// </summary>
MainWindowVM MVM { get; set; }
public MainWindow()
{
InitializeComponent();
MyMessageBox.MetroWin = this;
MVM = new MainWindowVM(this);
this.DataContext = MVM;
ThemeManager.Current.ChangeTheme(this, BackgroundThemeList[0] + "." + ThemeList[MVM.SystemPar.SystemTheme]);
}
PwdAlter pwdAlter { get; set; }
/// <summary>
/// 密码修改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menPwdAlter_Click(object sender, RoutedEventArgs e)
{
pwdAlter = new PwdAlter();
pwdAlter.DataContext = this.DataContext;
pwdAlter.ShowDialog();
}
#region 切换主题
//主题色
List<string> ThemeList = new List<string>() { "Red", "Green", "Blue", "Purple", "Orange", "Lime", "Emerald", "Teal", "Cyan", "Cobalt", "Indigo", "Violet", "Pink", "Magenta", "Crimson", "Amber", "Yellow", "Brown", "Olive", "Steel", "Mauve", "Taupe", "Sienna" };
//背景色
List<string> BackgroundThemeList = new List<string>() { "Light", "Dark" };
/// <summary>
/// 切换主题
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SubjectSwitch(object sender, RoutedEventArgs e)
{
MVM.SystemPar.SystemTheme++;
if (MVM.SystemPar.SystemTheme == ThemeList.Count - 1)
{
MVM.SystemPar.SystemTheme = 0;
}
ThemeManager.Current.ChangeTheme(this, BackgroundThemeList[0] + "." + ThemeList[MVM.SystemPar.SystemTheme]);
}
int systemBackgroundNumber = 0;
/// <summary>
/// 切换背景
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BackgroundSwitch(object sender, RoutedEventArgs e)
{
systemBackgroundNumber++;
MVM.SystemPar.SystemBackgroundPath = @"Resources/" + systemBackgroundNumber + ".jpg";
if (systemBackgroundNumber >= 32)
{
systemBackgroundNumber = 0;
}
}
#endregion
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
MVM.Close(0);
if (MVM.CloseRes == MessageDialogResult.Negative)
{
e.Cancel = true;
}
}
private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
{
Login ss = new Login(this.MVM);
if(!(bool)ss.ShowDialog())
{
if (MVM.User==null)
{
MVM.Close(0);
}
}
}
private void SwitchUser_Click(object sender, RoutedEventArgs e)
{
Login ss = new Login(this.MVM);
if (!(bool)ss.ShowDialog())
{
if (MVM.User == null)
{
MVM.Close(0);
}
}
}
/// <summary>
/// 切换系统设置模式
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menSystemSet_Click(object sender, RoutedEventArgs e)
{
if (MVM.AllVis == Visibility.Collapsed)
{
PwdInput pwdInput = new PwdInput();
pwdInput.DataContext = this.DataContext;
pwdInput.ShowDialog();
}
else
{
MVM.AllVis = Visibility.Collapsed;
MVM.SelectTabItem = MVM.TabItemList[0];
}
}
}
}