134 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			134 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using log4net;
							 | 
						|||
| 
								 | 
							
								using Prism.Commands;
							 | 
						|||
| 
								 | 
							
								using Prism.Events;
							 | 
						|||
| 
								 | 
							
								using Prism.Mvvm;
							 | 
						|||
| 
								 | 
							
								using Prism.Regions;
							 | 
						|||
| 
								 | 
							
								using Prism.Services.Dialogs;
							 | 
						|||
| 
								 | 
							
								using System;
							 | 
						|||
| 
								 | 
							
								using System.Collections.Generic;
							 | 
						|||
| 
								 | 
							
								using System.Linq;
							 | 
						|||
| 
								 | 
							
								using System.Text;
							 | 
						|||
| 
								 | 
							
								using System.Threading.Tasks;
							 | 
						|||
| 
								 | 
							
								using System.Windows;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.Finger;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.Models;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.msg;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.Port;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.util;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace DM_Weight.ViewModels
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public class FingerprintDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private readonly ILog logger = LogManager.GetLogger(typeof(FingerprintDialogViewModel));
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private FingerprintUtil _fingerprintUtil;
							 | 
						|||
| 
								 | 
							
								        EventAggregator _eventAggregator;
							 | 
						|||
| 
								 | 
							
								        public FingerprintDialogViewModel(FingerprintUtil fingerprintUtil, EventAggregator eventAggregator)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            _fingerprintUtil = fingerprintUtil;
							 | 
						|||
| 
								 | 
							
								            _eventAggregator = eventAggregator;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public UserList UserList { get; set; }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public Dictionary<string, int> FingerIndexs
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                Dictionary<string, int> l = new Dictionary<string, int>();
							 | 
						|||
| 
								 | 
							
								                l.Add("左小拇指", 0);
							 | 
						|||
| 
								 | 
							
								                l.Add("左无名指", 1);
							 | 
						|||
| 
								 | 
							
								                l.Add("左中指", 2);
							 | 
						|||
| 
								 | 
							
								                l.Add("左食指", 3);
							 | 
						|||
| 
								 | 
							
								                l.Add("左大拇指", 4);
							 | 
						|||
| 
								 | 
							
								                l.Add("右小拇指", 5);
							 | 
						|||
| 
								 | 
							
								                l.Add("右无名指", 6);
							 | 
						|||
| 
								 | 
							
								                l.Add("右中指", 7);
							 | 
						|||
| 
								 | 
							
								                l.Add("右食指", 8);
							 | 
						|||
| 
								 | 
							
								                l.Add("右大拇指", 9);
							 | 
						|||
| 
								 | 
							
								                return l;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private int _fingerIndex = 0;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public event Action<IDialogResult> RequestClose;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public int FingerIndex
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => _fingerIndex;
							 | 
						|||
| 
								 | 
							
								            set => SetProperty(ref _fingerIndex, value);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public bool KeepAlive => false;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private int _status = 0;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public int Status
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => _status;
							 | 
						|||
| 
								 | 
							
								            set => SetProperty(ref _status, value);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public string Title => "录入指纹";
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public DelegateCommand StartInsert
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => new DelegateCommand(() => {
							 | 
						|||
| 
								 | 
							
								                Status = 1;
							 | 
						|||
| 
								 | 
							
								                _fingerprintUtil.SaveUser(UserList);
							 | 
						|||
| 
								 | 
							
								                _fingerprintUtil.SaveFingerprint(UserList.Id, FingerIndex);
							 | 
						|||
| 
								 | 
							
								                RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
							 | 
						|||
| 
								 | 
							
								            }, () => Status == 0).ObservesProperty(() => Status);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public DelegateCommand CancelCommand
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => new DelegateCommand(() =>
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                // 关闭当前窗口
							 | 
						|||
| 
								 | 
							
								                RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
							 | 
						|||
| 
								 | 
							
								            });
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public bool CanCloseDialog()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return true;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public void OnDialogClosed()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            _eventAggregator.GetEvent<FingerprintEvent>().Unsubscribe(RegEvent1);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public void OnDialogOpened(IDialogParameters parameters)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            UserList = parameters.GetValue<UserList>("User");
							 | 
						|||
| 
								 | 
							
								            _eventAggregator.GetEvent<FingerprintEvent>().Subscribe(RegEvent1);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        void RegEvent1(FingerprintMsg msg)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            logger.Info(msg.ToString()); ;
							 | 
						|||
| 
								 | 
							
								            if (Status == 1)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                if (msg.Message.Equals("INS_FINGER"))
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    if (msg.Result)
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        Status = 0;
							 | 
						|||
| 
								 | 
							
								                        // 关闭当前窗口
							 | 
						|||
| 
								 | 
							
								                        RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |