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.

184 lines
5.8 KiB
C#

using ConsoleApp;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SlnMesnac.Business.business;
using SlnMesnac.Common;
using SlnMesnac.Repository.service;
using SlnMesnac.WPF.Page;
using SlnMesnac.WPF.Page.Generate;
using System;
using System.Windows;
using System.Windows.Controls;
namespace SlnMesnac.WPF.ViewModel
{
public class MainWindowViewModel: ViewModelBase
{
private readonly ILogger<MainWindowViewModel> _logger;
//代码生成
private readonly GenerateControl generateControl = new GenerateControl();
private readonly EmployeeLoginPage _employeeLoginPage = new EmployeeLoginPage();
private readonly ExecutePage _executePage = new ExecutePage();
private IBaseStaffService _baseStaffService;
public delegate void UIDCodeDelegate(string code);
public event UIDCodeDelegate UIDCodeDelegateEvent;
#region 参数定义
///// <summary>
///// PLC设备状态
///// </summary>
//private int _PlcStatus = 0;
//public int PlcStatus
//{
// get { return _PlcStatus; }
// set { _PlcStatus = value; RaisePropertyChanged(nameof(PlcStatus)); }
//}
/// <summary>
/// 打卡机状态
/// </summary>
private int _ShellScannerStatus = 0;
public int ShellScannerStatus
{
get { return _ShellScannerStatus; }
set { _ShellScannerStatus = value; RaisePropertyChanged(nameof(ShellScannerStatus)); }
}
/// <summary>
/// 扫码枪状态
/// </summary>
private int _BoldScannerStatus = 0;
public int BoldScannerStatus
{
get { return _BoldScannerStatus; }
set { _BoldScannerStatus = value; RaisePropertyChanged(nameof(BoldScannerStatus)); }
}
public System.Windows.Controls.UserControl _content;
public System.Windows.Controls.UserControl UserContent
{
get { return _content; }
set
{
_content = value;
RaisePropertyChanged(nameof(UserContent));
}
}
#endregion
#region 事件定义
/// <summary>
/// 界面跳转按钮事件
/// </summary>
public RelayCommand<object> ControlOnClickCommand { get; set; }
/// <summary>
/// 打开系统键盘
/// </summary>
public RelayCommand OpenSystemKeyboardCommand { get; set; }
/// <summary>
/// 窗体控制
/// </summary>
public RelayCommand<object> FormControlCommand { get; set; }
#endregion
public MainWindowViewModel()
{
//UserContent = _employeeLoginPage;
UserContent = _executePage;
_logger = App.ServiceProvider.GetService<ILogger<MainWindowViewModel>>();
var info = App.ServiceProvider.GetService<StringChange>();
ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj));
FormControlCommand = new RelayCommand<object>(x => FormControl(x));
//RfidHandleBusniess rfidHandleBusniess = new RfidHandleBusniess(hidUtils,_baseStaffService);
}
/// <summary>
/// 窗体控制
/// </summary>
/// <param name="obj"></param>
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.LogError("窗体控制逻辑异常", ex);
}
}
/// <summary>
/// 界面跳转
/// </summary>
private void ControlOnClick(object obj)
{
try
{
string info = obj as string;
//UserContent = inStoreInfoControl;
switch (info)
{
case "Execute":
UserContent = _executePage;
break;
case "Employee":
UserContent = _employeeLoginPage;
break;
default:
UserContent = _executePage;
break;
}
}
catch (Exception ex)
{
_logger.LogError("界面跳转逻辑异常", ex);
}
}
}
}