123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- 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;
- using System.Data.SqlClient;
- using Prism.Ioc;
- using System.ComponentModel;
- using DryIoc;
- using System.Linq;
- namespace LogoForceTestApp.ViewModels
- {
- public class MainWindowViewModel : BindableBase
- {
- private string _title = "浙江德盾智能科技有限公司";
- private readonly IRegionManager _regionManager;
- private readonly IEventAggregator _eventAggregator;
- private readonly IRepository _repository;
- private readonly IWritableOptions<AppSettings> _appSettings;
- private readonly IContainerProvider _container;
- private MulProductModel _Products;
- public MulProductModel Products
- {
- get { return _Products; }
- set { SetProperty(ref _Products, value); }
- }
- 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); }
- }
- private ProductModel _CurrentProduct;
- public ProductModel CurrentProduct
- {
- get { return _CurrentProduct; }
- set { SetProperty(ref _CurrentProduct, 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 SopCommand { get; set; }
- public DelegateCommand AccountCommand { get; set; }
- public DelegateCommand StatementPageCommand { get; set; }
- public Brush LoinBrush { get; set; }
- public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator,
- IRepository repository,IWritableOptions<AppSettings> appSettings,IContainerProvider container)
- {
- _container= container;
- 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);
- SopCommand = new DelegateCommand(GoSopPage);
- AccountCommand = new DelegateCommand(GoAccountPage);
- StatementPageCommand= new DelegateCommand(GoStatementPage);
- _regionManager = regionManager;
- _eventAggregator = eventAggregator;
- _repository = repository;
- _appSettings = appSettings;
- 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();
- });
- //Products = _container.Resolve<MulProductModel>();
- //if (Products==null)
- //{
- // Products = new MulProductModel();
- //}
- //Products.LoadParame();
- //CurrentProduct = Products.ProductCollection.FirstOrDefault(p=>p.Name=="123");
- //Products.ProductCollection.Add(new ProductModel() { Name="123"});
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题1");
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题2");
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题3");
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题4");
- //Products.ProductCollection.Add(new ProductModel() { Name = "321" });
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题1");
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题2");
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题3");
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题4");
- //Products.ProductCollection.Add(new ProductModel() { Name = "234" });
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题1");
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题2");
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题3");
- //Products.ProductCollection[Products.ProductCollection.Count - 1].QuestionType1.Add("问题4");
- }
- private async void GoAccountPage()
- {
- 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(AccountPage));
- }
- finally
- {
- await _repository.AddAsync(paramLog);
- }
- }
- private async void GoSopPage()
- {
- 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(SopPage));
- }
- finally
- {
- await _repository.AddAsync(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 GoStatementPage()
- {
- var paramLog = new ParamLog
- {
- Id = Guid.NewGuid(),
- OperateAction = OperateAction.Navigate,
- Occured = DateTime.UtcNow,
- OperateObject = nameof(StatementPage),
- 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(StatementPage));
- paramLog.Content = "导航成功";
- }
- 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.Black;
- }
- }
- 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 void GoMainPage()
- {
- var paramLog = new ParamLog
- {
- Id = Guid.NewGuid(),
- OperateAction = OperateAction.Navigate,
- Occured = DateTime.UtcNow,
- OperateObject = "MainPage",
- UserName = string.IsNullOrWhiteSpace(CurrentUser.CurrentUserName) ? "游客" :
- CurrentUser.CurrentUserName
- };
- _regionManager.RequestNavigate(RegionNames.ContentRegion, "MainPage");
- paramLog.Content = "导航成功";
- _repository.Add(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);
- }
-
- }
- }
- }
|