WinMain.xaml.cs
2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using HHECS.Bll;
using HHECS.Model;
using HHECS.View.Win;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting;
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.Shapes;
namespace HHECS.View
{
/// <summary>
/// Main.xaml 的交互逻辑
/// </summary>
public partial class WinMain : BaseWindow
{
public Dictionary<string, Window> ChildrenWin { get; set; } = new Dictionary<string, Window>();
public WinMain()
{
InitializeComponent();
this.WindowState = WindowState.Maximized;
this.Lab1.Content = $"欢迎:{AppSession.User.UserName} {DateTime.Now.ToLocalTime()}";
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
AppSession.Bll.Combine(AppSession.MenuOperations.Where(t=>t.ParentId==null).ToList(), AppSession.Bll.GetAllMenuOperation().Data.Where(t=>t.MenuType=="目录"||t.MenuType=="菜单").ToList());
MenuMain.ItemsSource = AppSession.MenuOperations.Where(t => t.ParentId == null).ToList();
}
private void Window_Closed(object sender, EventArgs e)
{
Application.Current.Shutdown();
}
private void MenuMain_Checked(object sender, RoutedEventArgs e)
{
try
{
MenuOperation menu = (MenuOperation)((MenuItem)e.OriginalSource).Header;
var win = ChildrenWin.FirstOrDefault(t => t.Key == menu.Url).Value;
if (String.IsNullOrWhiteSpace(menu?.Url) || menu.Url == "#")
{
return;
}
if (win == null)
{
win = (Window)Activator.CreateInstance(null, menu.Url).Unwrap();
ChildrenWin.Add(menu.Url, win);
}
win.Show();
if (win.WindowState == WindowState.Minimized)
win.WindowState = WindowState.Normal;
win.Activate();
}
catch (Exception ex)
{
LogExecute.WriteExceptionLog("打开菜单",ex);
MessageBox.Show("打开菜单出现异常!");
}
}
}
}