281 lines
8.9 KiB
C#
281 lines
8.9 KiB
C#
using MaterialDesignThemes.Wpf;
|
||
using SamplePre.Models.Tables;
|
||
using SamplePre.UIWpf;
|
||
using SamplePre.UIWpf.ConfigManager;
|
||
using SamplePre.UIWpf.ParamManager;
|
||
using SamplePre.UIWpf.QueryManager;
|
||
using SamplePre.UIWpf.SampleManager;
|
||
using SamplePreSystem.UI;
|
||
using SamplePreSystem.UI.ConfigManager;
|
||
using SamplePreSystem.UI.ViewModel.Login;
|
||
using SamplePreSystem.UI.Views;
|
||
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.Animation;
|
||
using System.Windows.Media.Imaging;
|
||
using System.Windows.Shapes;
|
||
|
||
namespace SamplePreSystemApp
|
||
{
|
||
/// <summary>
|
||
/// AppMainView.xaml 的交互逻辑
|
||
/// </summary>
|
||
public partial class AppMainView : Window
|
||
{
|
||
|
||
private bool _isMaximized = false; // 窗口是否最大化
|
||
private Rect _normalWindowRect; // 记录还原时的位置大小
|
||
|
||
private MonitorView monitorView;
|
||
|
||
public AppMainView()
|
||
{
|
||
InitializeComponent();
|
||
|
||
AppMainViewModel vm = new AppMainViewModel();
|
||
this.DataContext = vm;
|
||
|
||
var view = CollectionViewSource.GetDefaultView(vm.MenuBars) as ListCollectionView;
|
||
//按照Name分组
|
||
view.GroupDescriptions.Add(new PropertyGroupDescription("description"));
|
||
}
|
||
|
||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||
{
|
||
MaximizeWindow();
|
||
|
||
//打开样品监控
|
||
OpenSampleMonitor();
|
||
}
|
||
|
||
private void btnMin_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
this.WindowState = WindowState.Minimized;
|
||
//MaximizeWindow();
|
||
}
|
||
|
||
private void btnMax_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
|
||
MaximizeWindow();
|
||
}
|
||
|
||
private void btnClose_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
|
||
if (MessageBox.Show("是否退出系统?", "退出提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
this.Close();
|
||
}
|
||
|
||
}
|
||
|
||
private void btnUserInfo_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
// 打开用户信息窗口
|
||
UserInfoWindow userInfoWindow = new UserInfoWindow();
|
||
userInfoWindow.ShowDialog();
|
||
}
|
||
|
||
|
||
|
||
public void MaximizeWindow()
|
||
{
|
||
if (_isMaximized)
|
||
{
|
||
// 还原
|
||
this.WindowState = WindowState.Normal;
|
||
this.Left = _normalWindowRect.Left;
|
||
this.Top = _normalWindowRect.Top;
|
||
this.Width = _normalWindowRect.Width;
|
||
this.Height = _normalWindowRect.Height;
|
||
//BtnMaximize.Content = new PackIcon { Kind = PackIconKind.WindowMaximize, Width = 16, Height = 16, Foreground = Brushes.White };
|
||
}
|
||
else
|
||
{
|
||
// 先记录当前位置
|
||
_normalWindowRect = new Rect(this.Left, this.Top, this.Width, this.Height);
|
||
|
||
// 工作区最大化(不挡任务栏)
|
||
var workArea = SystemParameters.WorkArea;
|
||
this.Left = workArea.Left;
|
||
this.Top = workArea.Top;
|
||
this.Width = workArea.Width;
|
||
this.Height = workArea.Height;
|
||
//BtnMaximize.Content = new PackIcon { Kind = PackIconKind.WindowRestore, Width = 16, Height = 16, Foreground = Brushes.White };
|
||
}
|
||
_isMaximized = !_isMaximized;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 拖拽标题栏
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ColorZone_MouseMove(object sender, MouseEventArgs e)
|
||
{
|
||
if (e.LeftButton == MouseButtonState.Pressed)
|
||
{
|
||
this.DragMove();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打开功能界面
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void FuncListbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||
{
|
||
|
||
// 获取 ListBox 本身
|
||
ListBox listBox = sender as ListBox;
|
||
|
||
// 获取选中项
|
||
var selectedItem = listBox.SelectedItem as MenuBarFuc;
|
||
|
||
//this.txt_currFunc.Text = selectedItem.name;
|
||
|
||
switch (selectedItem.id)
|
||
{
|
||
case 5:
|
||
|
||
OpenSampleMonitor();
|
||
break;
|
||
case 6:
|
||
this.MainFrame.Navigate(new SampleExecView());
|
||
break;
|
||
case 8:
|
||
this.MainFrame.Navigate(new SampleQueryView());
|
||
|
||
break;
|
||
case 9:
|
||
break;
|
||
case 10:
|
||
this.MainFrame.Navigate(new ParamManagerView());
|
||
break;
|
||
case 11:
|
||
this.MainFrame.Navigate(new ActionManagerView());
|
||
break;
|
||
case 12:
|
||
this.MainFrame.Navigate(new SopManagerView());
|
||
break;
|
||
case 13:
|
||
this.MainFrame.Navigate(new UsersView());
|
||
break;
|
||
case 14:
|
||
this.MainFrame.Navigate(new RoleView());
|
||
break;
|
||
case 15:
|
||
this.MainFrame.Navigate(new SysConfigMangerView());
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打开首页,监控界面
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnMonitor_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
OpenSampleMonitor();
|
||
}
|
||
|
||
public void OpenSampleMonitor()
|
||
{
|
||
if (monitorView == null)
|
||
{
|
||
monitorView = new MonitorView();
|
||
}
|
||
this.MainFrame.Navigate(monitorView);
|
||
}
|
||
|
||
// 收缩菜单:宽度=0,内容隐藏
|
||
private void MenuToggleButton_Checked(object sender, RoutedEventArgs e)
|
||
{
|
||
MenuContent.Visibility = Visibility.Collapsed;
|
||
MenuContainer.BeginAnimation(Grid.WidthProperty, new DoubleAnimation(0, TimeSpan.FromMilliseconds(200)));
|
||
|
||
//MenuToggleButton.Foreground = new SolidColorBrush(Color.FromArgb(1,0,113,203));
|
||
|
||
|
||
MenuToggleButton.Foreground = new SolidColorBrush(Color.FromRgb(0, 113, 203));
|
||
|
||
|
||
}
|
||
|
||
// 展开菜单:宽度=220,内容显示
|
||
private void MenuToggleButton_Unchecked(object sender, RoutedEventArgs e)
|
||
{
|
||
MenuContainer.BeginAnimation(Grid.WidthProperty, new DoubleAnimation(200, TimeSpan.FromMilliseconds(200)));
|
||
MenuContent.Visibility = Visibility.Visible;
|
||
MenuToggleButton.Foreground = new SolidColorBrush(Colors.White);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 分组标题点击事件 → 折叠/展开子项
|
||
/// </summary>
|
||
private void GroupHeader_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||
{
|
||
// 获取点击的标题容器
|
||
var border = sender as Border;
|
||
if (border == null) return;
|
||
|
||
// 获取箭头图标
|
||
var icon = FindVisualChild<PackIcon>(border);
|
||
// 获取子项容器
|
||
var itemsPresenter = FindVisualChild<ItemsPresenter>(border.Parent as FrameworkElement);
|
||
if (icon == null || itemsPresenter == null) return;
|
||
|
||
// 切换折叠/展开状态
|
||
if (icon.Tag.ToString() == "Expanded")
|
||
{
|
||
// 折叠
|
||
icon.Kind = PackIconKind.ChevronRight;
|
||
icon.Tag = "Collapsed";
|
||
itemsPresenter.Visibility = Visibility.Collapsed;
|
||
}
|
||
else
|
||
{
|
||
// 展开
|
||
icon.Kind = PackIconKind.ChevronDown;
|
||
icon.Tag = "Expanded";
|
||
itemsPresenter.Visibility = Visibility.Visible;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 可视化树查找子元素(通用工具方法)
|
||
/// </summary>
|
||
private T FindVisualChild<T>(DependencyObject parent) where T : DependencyObject
|
||
{
|
||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
||
{
|
||
var child = VisualTreeHelper.GetChild(parent, i);
|
||
if (child is T result) return result;
|
||
var childResult = FindVisualChild<T>(child);
|
||
if (childResult != null) return childResult;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
}
|
||
}
|