| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Ioc;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Windows;
- using TeamAAS_VP.Core;
- using TeamAAS_VP.Core.Lights;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Views;
- using TeamAAS_VP.Views.User;
- namespace TeamAAS_VP.ViewModels.User
- {
- public class CardLoginWindowViewModel : BindableBase
- {
- #region 字段
- IRegionManager _regionManager;
- IRegionNavigationService _regionNavigationService;
- IContainerProvider _container;
- IDialogService _dialogService;
- IEventAggregator _eventAggregator;
- IConfigService _configService;
- System.Net.Http.HttpClient httpClient;
- #endregion
- #region 属性
- private string _Name;
- public string Name
- {
- get { return _Name; }
- set { SetProperty(ref _Name, value); }
- }
- private string _Password;
- public string Password
- {
- get { return _Password; }
- set { SetProperty(ref _Password, value); }
- }
- public bool IsLocal { get; private set; }
- public CardLoginWindow View { get; set; }
- //正在登录中
- private bool _IsLogining;
- public bool IsLogining
- {
- get { return _IsLogining; }
- set { SetProperty(ref _IsLogining, value); }
- }
- private int _PageIndex;
- public int PageIndex
- {
- get { return _PageIndex; }
- set { SetProperty(ref _PageIndex, value); }
- }
- private Visibility _CardBtnVisibility = Visibility.Visible;
- public Visibility CardBtnVisibility
- {
- get { return _CardBtnVisibility; }
- set { SetProperty(ref _CardBtnVisibility, value); }
- }
- public SerialPortProtocol serialPortProtocol { get; set; }
- #endregion
- #region 命令
- private DelegateCommand _LoginCommand;
- public DelegateCommand LoginCommand =>
- _LoginCommand ?? (_LoginCommand = new DelegateCommand(ExecuteLoginCommand, CanExecuteLoginCommand).ObservesProperty(() => Name).ObservesProperty(() => Password).ObservesProperty(() => IsLogining));
- private DelegateCommand _CloseCommand;
- public DelegateCommand CloseCommand =>
- _CloseCommand ?? (_CloseCommand = new DelegateCommand(ExecuteCloseCommand));
- private DelegateCommand<string> _TransitionerCommand;
- public DelegateCommand<string> TransitionerCommand =>
- _TransitionerCommand ?? (_TransitionerCommand = new DelegateCommand<string>(ExecuteTransitionerCommand));
- private DelegateCommand _LoadedCommand;
- public DelegateCommand LoadedCommand =>
- _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
- #endregion
- #region 事件
- #endregion
- public CardLoginWindowViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService, IConfigService configService)
- {
- _regionManager = regionManager;
- _regionNavigationService = regionNavigationService;
- _container = container;
- _dialogService = dialogService;
- _configService = configService;
- _eventAggregator = ea;
- if (httpClient == null)
- {
- httpClient = new System.Net.Http.HttpClient();
- }
- }
- #region 方法
- /// <summary>
- /// 加载
- /// </summary>
- async void ExecuteLoadedCommand()
- {
- //获取刷卡器配置
- var cardConfig = _configService.GetCardReaderConfig();
- //创建刷卡器通讯
- serialPortProtocol = new SerialPortProtocol(cardConfig);
- serialPortProtocol.DataReceived += CardSerial_DataReceived;
- await serialPortProtocol.ConnectAsync();
- }
- private async void CardSerial_DataReceived(object sender, string code)
- {
- if (PageIndex == 0)
- {
- if (string.IsNullOrEmpty(code))
- {
- return;
- }
-
- }
- }
- public void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- serialPortProtocol?.Dispose();
- }
- async void ExecuteLoginCommand()
- {
- IsLogining = true;
- try
- {
-
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- IsLogining = false;
- }
- }
- bool CanExecuteLoginCommand()
- {
- return !string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Password) && !IsLogining;
- }
- void ExecuteCloseCommand()
- {
- View.DialogResult = false;
- }
- void ExecuteTransitionerCommand(string parameter)
- {
- PageIndex = int.Parse(parameter);
- }
- public void SetModel(bool isAdmin)
- {
- PageIndex = isAdmin ? 1 : 0;
- CardBtnVisibility = isAdmin ? Visibility.Collapsed : Visibility.Visible;
- }
- #endregion
- }
- }
|