using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Serilog;
using SlnMesnac.WPF.Attribute;
using SlnMesnac.WPF.Page;
using SlnMesnac.WPF.Page.Generate;
using SlnMesnac.WPF.Page.ProductDetails;
using SlnMesnac.WPF.ViewModel.Base;
using System;
using System.Windows;
namespace SlnMesnac.WPF.ViewModel
{
[RegisterAsSingletonAttribute]
public partial class MainWindowViewModel : BaseViewModel
{
public readonly SerilogHelper _logger;
private readonly GenerateControl _generateControl;
private readonly IndexControl _indexControl;
private readonly DetailsEditControl _detailsEditControl;
#region 参数定义
///
/// PLC设备状态
///
[ObservableProperty]
private int plcStatus = 0;
///
/// 登录人员
///
[ObservableProperty]
private string otherInfo;
///
/// 系统标题
///
[ObservableProperty]
private string systemTitle = string.Empty;
[ObservableProperty]
public System.Windows.Controls.UserControl userContent = new System.Windows.Controls.UserControl();
///
/// 箱壳扫码器状态
///
[ObservableProperty]
private int _shellScannerStatus = 0;
///
/// 内胆扫码器状态
///
[ObservableProperty]
private int _boldScannerStatus = 0;
#endregion
public MainWindowViewModel(SerilogHelper logger,GenerateControl generateControl,IndexControl indexControl, DetailsEditControl detailsEditControl)
{
_logger = logger;
_generateControl = generateControl;
_indexControl = indexControl;
_detailsEditControl = detailsEditControl;
this.UserContent = _detailsEditControl;
}
///
/// 窗体控制
///
///
[RelayCommand]
[RequirePermission("FormControl")]
private void FormControl(object obj)
{
try
{
string controlType = obj as string;
switch (controlType)
{
// 关闭当前窗口
case "Exit":
//Environment.Exit(0);
Application.Current.Shutdown();
break;
case "Generate":
UserContent = _generateControl;
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)
{
_logger.Error("窗体控制逻辑异常", ex);
}
}
///
/// 界面跳转
///
[RelayCommand]
private void ControlOnClick(object obj)
{
try
{
string info = obj as string;
//UserContent = inStoreInfoControl;
}
catch (Exception ex)
{
_logger.Error("界面跳转逻辑异常", ex);
}
}
}
}