77 lines
2.5 KiB
C#
77 lines
2.5 KiB
C#
using AvalonDock.Layout;
|
||
using AvalonDock.Themes;
|
||
using Cowain.Bake.BLL;
|
||
using Cowain.Bake.Common;
|
||
using Cowain.Bake.Common.Enums;
|
||
using Cowain.Bake.Communication.Interface;
|
||
using Cowain.Bake.Model;
|
||
using System.Collections.Generic;
|
||
using System.Threading;
|
||
using System.Windows;
|
||
using Unity;
|
||
|
||
namespace Cowain.Bake.Main.Views
|
||
{
|
||
/// <summary>
|
||
/// MainWindow.xaml 的交互逻辑
|
||
/// </summary>
|
||
public partial class MainWindow : Window
|
||
{
|
||
public static LayoutDocument mainShowWindow; //为了设置Title,直接Binding无效
|
||
IUnityContainer _unityContainer = null;
|
||
List<Theme> _theme = new List<Theme>();
|
||
//public static MainWindowViewModel mainWindowModel = null;
|
||
public MainWindow(IUnityContainer unityContainer)
|
||
{
|
||
InitializeComponent();
|
||
_unityContainer = unityContainer;
|
||
mainShowWindow = showWindow;
|
||
_theme.Add(new MetroTheme()); //GenericTheme
|
||
_theme.Add(new AeroTheme());
|
||
_theme.Add(new Vs2013BlueTheme());
|
||
_theme.Add(new Vs2013DarkTheme());
|
||
_theme.Add(new Vs2013LightTheme());
|
||
_theme.Add(new ExpressionDarkTheme());
|
||
}
|
||
|
||
public void ChangeSkin(int i)
|
||
{
|
||
dockingManager.Theme = _theme[i]; //MetroTheme
|
||
}
|
||
|
||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||
{
|
||
}
|
||
void CloseAllHandle()
|
||
{
|
||
System.Collections.Generic.List<TDeviceConfig> plcList = _unityContainer.Resolve<DeviceConfigService>().GetConfig(EDeviceType.PLC);
|
||
foreach (var item in plcList)
|
||
{
|
||
IPLCDevice plc = _unityContainer.Resolve<IPLCDevice>(item.Name); //几个PLC,就实例化几个
|
||
|
||
if (null != plc && plc.IsConnect)
|
||
{
|
||
plc.Close();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||
{
|
||
// 执行窗体的 Closing 事件的逻辑
|
||
if (MessageBoxResult.OK == HandyControl.Controls.MessageBox.Ask("是否退出自动真空烘烤系统?", "退出"))
|
||
{
|
||
Global.AppExit = true;
|
||
CloseAllHandle();
|
||
//Thread.Sleep(3000);
|
||
//await Task.Delay(10000); async
|
||
e.Cancel = false;
|
||
}
|
||
else
|
||
{
|
||
e.Cancel = true;
|
||
}
|
||
}
|
||
}
|
||
}
|