123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- using LogoForceTestApp.Modules.MainModule.Enums;
- using LogoForceTestApp.Modules.MainModule.Models;
- using LogoForceTestApp.Core;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using System.Windows.Media;
- using LogoForceTestApp.Modules.MainModule.Views;
- using System;
- using HandyControl.Controls;
- using Repository.Entiies;
- using Repository;
- using Team.Utility;
- using System.Reflection;
- namespace LogoForceTestApp.ViewModels
- {
- public class MainWindowViewModel : BindableBase
- {
- private string _title = "LogoForceTestApp";
- private readonly IRegionManager _regionManager;
- private readonly IEventAggregator _eventAggregator;
- private readonly IRepository _repository;
- private readonly IWritableOptions<AppSettings> _appSettings;
- public string Title
- {
- get { return _title; }
- set { SetProperty(ref _title, value); }
- }
- private RunResultState _runResultState;
- public RunResultState Jugement
- {
- get { return _runResultState; }
- set { SetProperty(ref _runResultState, value); }
- }
- public string LoginMessage { get; set; }
- public DelegateCommand LogCommand { get; set; }
- public DelegateCommand DataCommand { get; set; }
- public DelegateCommand GoMainPageCommand { get; set; }
- public DelegateCommand LoginCommand { get; set; }
- public DelegateCommand SettingCommand { get; set; }
- public DelegateCommand OperationLogPageCommand { get; set; }
- public DelegateCommand Tracing { get; set; }
- public DelegateCommand SignInCommand { get; set; }
- public Brush LoinBrush { get; set; }
- public string LineName { get; set; }
- public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator,
- IRepository repository,IWritableOptions<AppSettings> appSettings)
- {
- var version=Assembly.GetExecutingAssembly().GetName().Version;
- Title = Title+"-" + version.ToString();
- DataCommand = new DelegateCommand(GoDataPage);
- GoMainPageCommand = new DelegateCommand(GoMainPage);
- LogCommand = new DelegateCommand(GoLogPage);
- LoginCommand = new DelegateCommand(Login);
- SettingCommand = new DelegateCommand(GoSettingPage);
- OperationLogPageCommand = new DelegateCommand(GoOperationLogPage);
- Tracing = new DelegateCommand(GoQualityTracing);
- SignInCommand = new DelegateCommand(GoSignInPage);
- _regionManager = regionManager;
- _eventAggregator = eventAggregator;
- _repository = repository;
- _appSettings = appSettings;
- LineName = _appSettings.Value.MachineName;
- if (string.IsNullOrWhiteSpace(_appSettings.Value.Process))
- {
- _appSettings.Update(c =>
- {
- c.Process = "FI_PP";
- });
- }
- if (string.IsNullOrWhiteSpace(_appSettings.Value.Builds))
- {
- _appSettings.Update(c =>
- {
- c.Builds = "RAMP";
- });
- }
- if (string.IsNullOrWhiteSpace(_appSettings.Value.Project))
- {
- _appSettings.Update(c =>
- {
- c.Project = "X1930";
- });
- }
- if (string.IsNullOrWhiteSpace(_appSettings.Value.Part))
- {
- _appSettings.Update(c =>
- {
- c.Part = "TC";
- });
- }
- if (string.IsNullOrWhiteSpace(_appSettings.Value.INSPECTION_PROGRAM_NAME))
- {
- _appSettings.Update(c =>
- {
- c.INSPECTION_PROGRAM_NAME = "FS_Color_Gloss";
- });
- }
- if (string.IsNullOrWhiteSpace(_appSettings.Value.AIM_UNIQUE))
- {
- _appSettings.Update(c =>
- {
- c.AIM_UNIQUE = "V1.0";
- });
- }
- if (string.IsNullOrWhiteSpace(_appSettings.Value.AimName))
- {
- _appSettings.Update(c =>
- {
- c.AimName = "L1-1";
- });
- }
- _eventAggregator.GetEvent<ResultEvent>().Subscribe(c =>
- {
- Jugement = c;
- });
- UpdateLoginMessage();
- _eventAggregator.GetEvent<LoginSuccessEvent>().Subscribe(result =>
- {
- UpdateLoginMessage();
- });
- }
- private void GoSignInPage()
- {
- var paramLog = new ParamLog
- {
- Id = Guid.NewGuid(),
- OperateAction = OperateAction.Navigate,
- Occured = DateTime.UtcNow,
- OperateObject = nameof(SignInPage),
- UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
- CurrentUser.CurrentUserName
- };
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(SignInPage));
- paramLog.Content = "导航成功";
- _repository.Add(paramLog);
- }
- private async void GoQualityTracing()
- {
- var paramLog = new ParamLog
- {
- Id = Guid.NewGuid(),
- OperateAction = OperateAction.Navigate,
- Occured = DateTime.UtcNow,
- OperateObject = nameof(LoginPage),
- UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
- CurrentUser.CurrentUserName
- };
- try
- {
- if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
- {
- paramLog.Content = "权限不足失败";
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
- return;
- }
- paramLog.Content = "导航成功";
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(QualityTracing));
- }
- finally
- {
- await _repository.AddAsync(paramLog);
- }
-
- }
- private async void GoOperationLogPage()
- {
- var paramLog = new ParamLog
- {
- Id = Guid.NewGuid(),
- OperateAction = OperateAction.Navigate,
- Occured = DateTime.UtcNow,
- OperateObject = nameof(OperationLogPage),
- UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
- CurrentUser.CurrentUserName
- };
- try
- {
- if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
- {
- paramLog.Content = "权限不足失败";
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
- return;
- }
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(OperationLogPage));
- paramLog.Content = "导航成功";
- }
- finally
- {
- await _repository.AddAsync(paramLog);
- }
- }
- private async void GoSettingPage()
- {
- var paramLog = new ParamLog
- {
- Id = Guid.NewGuid(),
- OperateAction = OperateAction.Navigate,
- Occured = DateTime.UtcNow,
- OperateObject = "SettingPage",
- UserName=string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName)?"游客":
- CurrentUser.CurrentUserName
- };
- try
- {
-
- if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
- {
- paramLog.Content = "无权限,跳转登录界面";
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
- return;
- }
- if (CurrentUser.CurrentUserName == Role.Operator.ToString())
- {
- paramLog.Content = "权限不足";
- Growl.Info($"权限不足,请切换工程师权限");
- return;
- }
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(ParamPage));
- paramLog.Content = "导航成功";
- }
- finally
- {
- await _repository.AddAsync(paramLog);
- }
-
- }
- private void UpdateLoginMessage()
- {
- if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
- {
- LoginMessage = "未登录";
- LoinBrush = Brushes.Red;
- }
- else
- {
- LoginMessage = $"{CurrentUser.CurrentUserName}";
- LoinBrush = Brushes.Blue;
- }
- }
- private void Login()
- {
- var paramLog = new ParamLog
- {
- Id = Guid.NewGuid(),
- OperateAction = OperateAction.Navigate,
- Occured = DateTime.UtcNow,
- OperateObject = "LoginPage",
- UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
- CurrentUser.CurrentUserName
- };
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
- paramLog.Content = "导航成功";
- _repository.Add(paramLog);
- }
- private async void GoLogPage()
- {
- var paramLog = new ParamLog
- {
- Id = Guid.NewGuid(),
- OperateAction = OperateAction.Navigate,
- Occured = DateTime.UtcNow,
- OperateObject = "LoginPage",
- UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
- CurrentUser.CurrentUserName
- };
- try
- {
- if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
- {
- paramLog.Content = "权限不足失败";
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
- return;
- }
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LogPage));
- paramLog.Content = "导航成功";
- }
- finally
- {
- await _repository.AddAsync(paramLog);
- }
-
- }
- private async void GoMainPage()
- {
- var paramLog = new ParamLog
- {
- Id = Guid.NewGuid(),
- OperateAction = OperateAction.Navigate,
- Occured = DateTime.UtcNow,
- OperateObject = "MainPage",
- UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
- CurrentUser.CurrentUserName
- };
- try
- {
- if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
- {
- paramLog.Content = "权限不足失败";
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
- return;
- }
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(MainPage));
- paramLog.Content = "导航成功";
- }
- finally
- {
- await _repository.AddAsync(paramLog);
- }
- }
- private async void GoDataPage()
- {
- var paramLog = new ParamLog
- {
- Id = Guid.NewGuid(),
- OperateAction = OperateAction.Navigate,
- Occured = DateTime.UtcNow,
- OperateObject = nameof(LoginPage),
- UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
- CurrentUser.CurrentUserName
- };
- try
- {
- if (string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName))
- {
- paramLog.Content = "权限不足失败";
- _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(LoginPage));
- return;
- }
- paramLog.Content = "导航成功";
- _regionManager.RequestNavigate(RegionNames.ContentRegion, "DataPage");
- }
- finally
- {
- await _repository.AddAsync(paramLog);
- }
-
- }
- }
- }
|