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.
Aucma.Scada/Aucma.Scada.UI/viewModel/MainViewModel.cs

231 lines
7.5 KiB
C#

using Aucma.Scada.UI.Page.AssemblyPlan;
using Aucma.Scada.UI.Page.InStoreInfo;
using Aucma.Scada.UI.Page.InventoryInfo;
using Aucma.Scada.UI.Page.OutStoreInfo;
using Aucma.Scada.UI.Page.TaskInfo;
using GalaSoft.MvvmLight;
1 year ago
using GalaSoft.MvvmLight.Command;
using HighWayIot.Log4net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Aucma.Scada.UI.viewModel
{
public class MainViewModel : ViewModelBase
{
private LogHelper logHelper = LogHelper.Instance;
private readonly LogInfoControl logInfoControl = new LogInfoControl();
private readonly InStoreInfoControl inStoreInfoControl = new InStoreInfoControl();
private readonly OutStoreInfoControl outStoreInfoControl = new OutStoreInfoControl();
private readonly TaskInfoControl taskInfoControl = new TaskInfoControl();
private readonly InventoryInfoControl inventoryInfoControl = new InventoryInfoControl();
private readonly AssemblyPlanControl assemblyPlanControl = new AssemblyPlanControl();
1 year ago
public MainViewModel()
{
//FormControlCommand = new RelayCommand<object>(obj=> FormControl(obj));
//OpenSystemKeyboardCommand = new RelayCommand(OpenSystemKeyboard);
UserContent = inStoreInfoControl;
1 year ago
}
#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
1 year ago
{
get { return _BoldScannerStatus; }
set { _BoldScannerStatus = value; RaisePropertyChanged(nameof(BoldScannerStatus)); }
1 year ago
}
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>
private RelayCommand<object> _controlOnClickCommand;
public RelayCommand<object> ControlOnClickCommand
{
get
{
if (_controlOnClickCommand == null)
_controlOnClickCommand = new RelayCommand<object>(obj=> ControlOnClick(obj));
return _controlOnClickCommand;
}
set { _controlOnClickCommand = value; RaisePropertyChanged(nameof(ControlOnClickCommand)); }
}
/// <summary>
/// 逻辑实现
/// </summary>
private void ControlOnClick(object obj)
{
try
{
string info = obj as string;
switch (info)
{
case "instoreInfo":
UserContent = inStoreInfoControl;
break;
case "outstoreInfo":
UserContent = outStoreInfoControl;
break;
case "taskInfo":
UserContent = taskInfoControl;
break;
case "inventoryInfo":
UserContent = inventoryInfoControl;
break;
case "assemblyPlan":
UserContent = assemblyPlanControl;
1 year ago
break;
case "logInfo":
UserContent = logInfoControl;
break;
default:
UserContent = inStoreInfoControl;
1 year ago
break;
}
}catch(Exception ex)
{
logHelper.Error("界面跳转逻辑异常", ex);
}
}
/// <summary>
/// 打开系统键盘
/// </summary>
private RelayCommand _openSystemKeyboardCommand;
public RelayCommand OpenSystemKeyboardCommand
{
get
{
if (_openSystemKeyboardCommand == null)
_openSystemKeyboardCommand = new RelayCommand(OpenSystemKeyboard);
return _openSystemKeyboardCommand;
}
set { _openSystemKeyboardCommand = value; RaisePropertyChanged(nameof(OpenSystemKeyboardCommand)); }
}
/// <summary>
/// 逻辑实现
/// </summary>
public void OpenSystemKeyboard()
{
try
{
MessageBox.Show("打开系统键盘");
}catch(Exception ex)
{
logHelper.Error("打开系统键盘逻辑异常", ex);
}
}
/// <summary>
/// 窗体控制
/// </summary>
private RelayCommand<object> _formControlCommand;
public RelayCommand<object> FormControlCommand
{
get
{
if (_formControlCommand == null)
_formControlCommand = new RelayCommand<object>(obj => FormControl(obj));
return _formControlCommand;
}
set { _formControlCommand = value; RaisePropertyChanged(nameof(FormControlCommand)); }
}
/// <summary>
/// 逻辑实现
/// </summary>
/// <param name="obj"></param>
public void FormControl(object obj)
{
try
{
string controlType = obj as string;
switch (controlType)
{
// 关闭当前窗口
case "Exit":
//Environment.Exit(0);
Application.Current.Shutdown();
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)
{
logHelper.Error("窗体控制逻辑异常", ex);
}
}
#endregion
}
}