Frm_Main.xaml.cs 3.52 KB
using HHWCS.Model;
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.Shapes;

namespace HHWCSHost.View
{
    /// <summary>
    /// Frm_Main.xaml 的交互逻辑
    /// </summary>
    public partial class Frm_Main : Window
    {
        //所有子窗口
        Dictionary<string, Window> windows = new Dictionary<string, Window>();

        public Frm_Main()
        {
            InitializeComponent();
            InitMenu();
            InitStatusBar();
        }

        private void InitStatusBar()
        {
            statusBar.Items.Add("欢迎:"+AppCommon.User.UserName+" 登录时间:"+DateTime.Now.ToString());
        }

        private void InitMenu()
        {
            //构建菜单
            //系统
            MenuItem menu_sys = new MenuItem();
            menu_sys.Header = "系统";
            MenuItem menu_sys_exit = new MenuItem();
            menu_sys_exit.Header = "退出";
            menu_sys_exit.Click += Menu_sys_exit_Click;
            menu_sys.Items.Add(menu_sys_exit);

            //设备
            MenuItem menu_device = new MenuItem();
            menu_device.Header = "设备管理";
            MenuItem menu_device_info = new MenuItem();
            menu_device_info.Header = "设备信息管理";
            menu_device_info.Click += Menu_device_info_Click;
            menu_device.Items.Add(menu_device_info);

            //任务
            MenuItem menu_task = new MenuItem();
            menu_task.Header = "任务管理";
            MenuItem menu_task_info = new MenuItem();
            menu_task_info.Header = "任务查看";
            menu_task_info.Click += Menu_task_info_Click;
            menu_task.Items.Add(menu_task_info);


            menu.Items.Add(menu_sys);
            menu.Items.Add(menu_device);
            menu.Items.Add(menu_task);
        }

        private void Menu_task_info_Click(object sender, RoutedEventArgs e)
        {
            Frm_TaskInfo frm_TaskInfo =(Frm_TaskInfo)windows.FirstOrDefault(t => t.Key == "frm_taskinfo").Value;
            if (frm_TaskInfo == null)
            {
                frm_TaskInfo = new Frm_TaskInfo();
                windows.Add("frm_taskinfo", frm_TaskInfo);
            }
            frm_TaskInfo.Show();
            if (frm_TaskInfo.WindowState == WindowState.Minimized)
                frm_TaskInfo.WindowState = WindowState.Normal;
            frm_TaskInfo.Activate();

        }

        private void Menu_device_info_Click(object sender, RoutedEventArgs e)
        {
            Frm_DeviceInfo frm_DeviceInfo = (Frm_DeviceInfo)windows.FirstOrDefault(t => t.Key == "frm_DeviceInfo").Value;
            if (frm_DeviceInfo == null)
            {
                frm_DeviceInfo = new Frm_DeviceInfo();
                windows.Add("frm_DeviceInfo", frm_DeviceInfo);
            }
            frm_DeviceInfo.Show();
            if (frm_DeviceInfo.WindowState == WindowState.Minimized)
                frm_DeviceInfo.WindowState = WindowState.Normal;
            frm_DeviceInfo.Activate();
        }

        private void Menu_sys_exit_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            Application.Current.Shutdown();
        }
    }
}