You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
5.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Aucma.Core.SheetMetal.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Windows;
using System;
using log4net;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Collections.ObjectModel;
namespace Aucma.Core.SheetMetal.ViewModels
{
public partial class MainWindowViewModel : ObservableObject
{
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(MainWindowViewModel));
private IndexPage firstPage = new IndexPage();//首页
private LogPageView logPage = new LogPageView();//日志
private StatisticsPageView statisticsPage = new StatisticsPageView();//统计
public MainWindowViewModel()
{
UserContent = firstPage;
}
#region 更换界面
public System.Windows.Controls.UserControl _content;
public System.Windows.Controls.UserControl UserContent
{
get => _content;
set => SetProperty(ref _content, value);
}
#endregion
#region 窗口操作
/// <summary>
/// 窗口操作
/// </summary>
[RelayCommand]
private void FormControl(object obj)
{
try
{
string controlType = obj as string;
switch (controlType)
{
// 关闭当前窗口
case "Exit":
if (System.Windows.MessageBox.Show("确定要退出系统吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
{
Application.Current.Shutdown();
Environment.Exit(0);
}
break;
// 打开软盘
case "TabTip":
OpenOsk();
break;
// 还原 或者 最大化当前窗口
case "Normal":
if (Application.Current.MainWindow.WindowState == WindowState.Normal)
{
Application.Current.MainWindow.WindowState = WindowState.Maximized;
break;
}
if (Application.Current.MainWindow.WindowState == WindowState.Maximized)
{
Application.Current.MainWindow.WindowState = WindowState.Normal;
break;
}
break;
// 最小化当前窗口
case "Minimized":
Application.Current.MainWindow.WindowState = WindowState.Minimized;
break;
default:
break;
}
}
catch (Exception ex)
{
log.Error("窗体控制逻辑异常", ex);
}
}
#endregion
#region 打开软盘
/// <summary>
/// 打开软盘
/// </summary>
public static void OpenOsk()
{
Process proc = new Process();
proc.StartInfo.FileName = @"C:\Windows\System32\osk.exe";
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.Verb = "runas";
proc.Start();
}
#endregion
#region 界面切换
/// <summary>
/// 界面切换
/// </summary>
[RelayCommand]
private void SwitchPages(object obj)
{
string page = obj as string;
switch (page)
{
case "FirstPage":
UserContent = firstPage;
break;
case "LogPage":
UserContent = logPage;
break;
case "StatisticsPage":
UserContent = statisticsPage;
break;
default:
break;
}
}
#endregion
#region plc 状态
/// <summary>
/// UI plc 展示状态-文字
/// </summary>
public string _plcUIStatus;
public string PlcUIStatusWb
{
//get { return plcUIStatusWb; }
//set { plcUIStatusWb = value; RaisePropertyChanged("PlcUIStatusWb"); }
get => _plcUIStatus;
set => SetProperty(ref _plcUIStatus, value);
}
/// <summary>
/// UI plc 展示状态-颜色
/// </summary>
public string _plcUIColor;
public string PlcUIColor
{
//get { return plcUIColor; }
//set { plcUIColor = value; RaisePropertyChanged("PlcUIColor"); }
get => _plcUIColor;
set => SetProperty(ref _plcUIColor, value);
}
/// <summary>
/// UI plc 展示状态-图标
/// </summary>
public string _plcUIIcon;
public string PlcUIIcon
{
//get { return plcUIIcon; }
//set { plcUIIcon = value; RaisePropertyChanged("plcUIIcon"); }
get => _plcUIIcon;
set => SetProperty(ref _plcUIIcon, value);
}
/// <summary>
/// PLC连接状态-true:连接成功false:失败
/// </summary>
/// <param name="type"></param>
public void PlcState(bool type)
{
if (type)
{
PlcUIStatusWb = "PLC连接成功";
PlcUIColor = "White";
PlcUIIcon = "Assets/Images/正常.png";
}
else
{
PlcUIStatusWb = "PLC状态异常";
PlcUIColor = "Red";
PlcUIIcon = "Assets/Images/失败-01.png";
}
}
#endregion
}
}