WinMain.xaml.cs 2.44 KB
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("打开菜单出现异常!");
            }
        }
    }
}