123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using AutoMapper;
- using BizService;
- using BlankApp1.Common;
- using BlankApp1.Views;
- using Microsoft.Extensions.Logging;
- using Model.Dto;
- using PLCTool.Common;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Threading.Tasks;
- using System.Windows;
- namespace BlankApp1.ViewModels
- {
- public class MainWindowViewModel : BindableBase, IConfigureService
- {
- private readonly ILogger _logger;
- private readonly IRegionManager _regionManager;
- private readonly IMapper _mapper;
- private string _title = "Prism Application";
- private IRegionNavigationJournal journal;
- public string Title
- {
- get { return _title; }
- set { SetProperty(ref _title, value); }
- }
- public MainWindowViewModel(IRegionManager regionManager,ILogger logger,IProductService productService, IMapper mapper)
- {
- this._regionManager = regionManager;
- this._logger = logger;
- this._mapper = mapper;
-
- ButtonNavigateCommand = new DelegateCommand<string>(ButtonNavigate);
- BackCommand = new DelegateCommand(GoBack);
- NextCommand = new DelegateCommand(GoNext);
- JudgePLC();
- logger.LogInformation("info");
- logger.LogError("error");
- //_regionManager.Regions["MeunRegion"].RequestNavigate("TreeMenuView");
- }
- private void GoNext()
- {
- if(journal.CanGoForward)
- journal.GoForward();
- }
- private void GoBack()
- {
- if(journal.CanGoBack)
- journal.GoBack();
- }
- private void ButtonNavigate(string strPar)
- {
- if (strPar == null || string.IsNullOrWhiteSpace(strPar))
- {
- return;
- }
- //导航页面
- _regionManager.Regions["ContentRegion"].RequestNavigate(strPar,arg=>
- {
- journal=arg.Context.NavigationService.Journal;
- });
- }
- /// <summary>
- /// 配置首页初始化参数,这个Configure是实现的接口IConfigureService中定义的方法;
- /// </summary>
- public void Configure()
- {
- //默认进入简报页面
- _regionManager.Regions["ContentRegion"].RequestNavigate("LogView");
- _regionManager.Regions["MenuRegion"].RequestNavigate("TreeMenuView");
- _regionManager.Regions["ContentRegion"].RequestNavigate("StatisticsView");
-
-
-
- }
- /// <summary>
- /// 连接PLC
- /// </summary>
- private void JudgePLC()
- {
-
- Task.Run(async () =>
- {
- while (true)
- {
-
- //更新界面上的值
- Application.Current.Dispatcher.Invoke(() =>
- {
- PLCIsConnect = PLCCom.GetInstance().IsConnectPLC();
- });
- await Task.Delay(5000);
- }
- });
-
- }
- #region 命令绑定
- public DelegateCommand<string> ButtonNavigateCommand { set; get; }
- public DelegateCommand NextCommand { set; get; }
- public DelegateCommand BackCommand { set; get; }
- #endregion
- #region 数据绑定
- private bool plcIsConnect = false;
- public bool PLCIsConnect
- {
- get { return plcIsConnect; }
- set { plcIsConnect = value; RaisePropertyChanged(); }
- }
- #endregion
- }
- }
|