You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sln.Wcs/Sln_Wpf/MainWindow.xaml.cs

140 lines
4.3 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Text;
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 System.Windows.Threading;
using Sln_Wpf.Page;
namespace Sln_Wpf
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private bool _isMaximized = false;
private DeviceInfo _deviceInfoView;
private WarehouseInfo _warehouseInfoView;
private MainPage _mainPage;
private TaskInfo _taskInfo;
public MainWindow()
{
InitializeComponent();
// 初始化时钟,每秒更新一次
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Timer_Tick;
timer.Start();
_mainPage = new MainPage();
MainContentArea.Content = _mainPage;
// 立即显示当前时间
UpdateClock();
}
private void Timer_Tick(object sender, EventArgs e)
{
UpdateClock();
}
private void UpdateClock()
{
// 格式化显示当前时间
ClockText.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
// 窗口拖拽功能
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
{
this.DragMove();
}
}
// 最小化按钮
private void BtnMinimize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
// 全屏/恢复按钮
private void BtnMaximizeRestore_Click(object sender, RoutedEventArgs e)
{
if (_isMaximized)
{
this.WindowState = WindowState.Normal;
_isMaximized = false;
BtnMaximizeRestore.Content = "□";
BtnMaximizeRestore.ToolTip = "全屏";
}
else
{
this.WindowState = WindowState.Maximized;
_isMaximized = true;
BtnMaximizeRestore.Content = "❐";
BtnMaximizeRestore.ToolTip = "恢复";
}
}
// 关闭按钮
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
// 可在此添加关闭前的确认逻辑
var result = MessageBox.Show("确定要退出WCS平台吗", "退出确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
Application.Current.Shutdown();
}
}
// 设备信息按钮点击事件
private void BtnDeviceInfo_Click(object sender, RoutedEventArgs e)
{
if (_deviceInfoView == null)
{
_deviceInfoView = new DeviceInfo();
}
// 将内容区域切换为设备信息视图
MainContentArea.Content = _deviceInfoView;
}
// 仓库信息按钮点击事件
private void BtnWarehouseInfo_Click(object sender, RoutedEventArgs e)
{
if (_warehouseInfoView == null)
{
_warehouseInfoView = new WarehouseInfo();
}
// 将内容区域切换为仓库信息视图
MainContentArea.Content = _warehouseInfoView;
}
// 任务管理按钮点击事件
private void BtnTaskManage_Click(object sender, RoutedEventArgs e)
{
if (_taskInfo == null)
{
_taskInfo = new TaskInfo();
}
// 将内容区域切换为仓库信息视图
MainContentArea.Content = _taskInfo;
}
private void BtnMainPage_Click(object sender, RoutedEventArgs e)
{
if (_mainPage == null)
{
_mainPage = new MainPage();
}
// 将内容区域切换为设备信息视图
MainContentArea.Content = _mainPage;
}
}
}