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; using GalaSoft.MvvmLight.Command; using HighWayIot.Log4net; using System; using System.Diagnostics; using System.IO; 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(); public MainViewModel() { ControlOnClickCommand = new RelayCommand(obj => ControlOnClick(obj)); OpenSystemKeyboardCommand = new RelayCommand(OpenSystemKeyboard); FormControlCommand = new RelayCommand(obj => FormControl(obj)); UserContent = inStoreInfoControl; } #region 参数定义 /// /// PLC设备状态 /// private int _PlcStatus = 0; public int PlcStatus { get { return _PlcStatus; } set { _PlcStatus = value; RaisePropertyChanged(nameof(PlcStatus)); } } /// /// 箱壳扫码器状态 /// private int _ShellScannerStatus = 0; public int ShellScannerStatus { get { return _ShellScannerStatus; } set { _ShellScannerStatus = value; RaisePropertyChanged(nameof(ShellScannerStatus)); } } /// /// 内胆扫码器状态 /// 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 事件定义 /// /// 界面跳转按钮事件 /// public RelayCommand ControlOnClickCommand { get; set; } /// /// 打开系统键盘 /// public RelayCommand OpenSystemKeyboardCommand { get; set; } /// /// 窗体控制 /// public RelayCommand FormControlCommand { get; set; } #endregion /// /// 界面跳转 /// 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; break; case "logInfo": UserContent = logInfoControl; break; default: UserContent = inStoreInfoControl; break; } } catch (Exception ex) { logHelper.Error("界面跳转逻辑异常", ex); } } /// /// 打开系统键盘 /// private void OpenSystemKeyboard() { try { var commonFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles); //程序集目标平台为X86时,获取到的是x86的Program Files,但TabTip.exe始终在Program Files目录下 if (commonFilesPath.Contains("Program Files (x86)")) { commonFilesPath = commonFilesPath.Replace("Program Files (x86)", "Program Files"); } string tabTipPath = Path.Combine(commonFilesPath, @"microsoft shared\ink\TabTip.exe"); if (File.Exists(tabTipPath)) { ProcessStartInfo psi = new ProcessStartInfo { FileName = tabTipPath, UseShellExecute = true, CreateNoWindow = true }; Process.Start(psi); } } catch (Exception ex) { logHelper.Error("打开系统键盘逻辑异常", ex); MessageBox.Show($"系统键盘打开异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } } /// /// 窗体控制 /// /// private 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); } } } }