using ConsoleApp; using Microsoft.Extensions.DependencyInjection; using SlnMesnac.Model.domain; using SlnMesnac.Repository.service; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace SlnMesnac.WPF.ViewModel { public class HandOverViewModel : INotifyPropertyChanged { //private HidUtils hidUtils = new HidUtils(); private IBaseStaffService _baseStaffService; private int times; /// /// 按钮文字转换事件 /// public event PropertyChangedEventHandler PropertyChanged; public HandOverViewModel() { Init(); _baseStaffService = App.ServiceProvider.GetService(); } #region /// /// 员工id /// private string staffIdText; public string StaffIdText { get { return staffIdText; } set { staffIdText = value; OnPropertyChanged("StaffIdText"); } } /// /// 员工名称 /// private string staffNameText; public string StaffNameText { get { return staffNameText; } set { staffNameText = value; OnPropertyChanged("StaffNameText"); } } /// /// 员工类型 /// private string staffTypeText; public string StaffTypeText { get { return staffTypeText; } set { staffTypeText = value; OnPropertyChanged("StaffTypeText"); } } /// /// 班组编号 /// private string teamCodeText; public string TeamCodeText { get { return teamCodeText; } set { teamCodeText = value; OnPropertyChanged("TeamCodeText"); } } /// /// 提示信息 /// private string hintText; public string HintText { get { return hintText; } set { hintText = value; OnPropertyChanged("HintText"); } } /// /// 信息 /// private string messageText; public string MessageText { get { return messageText; } set { messageText = value; OnPropertyChanged("MessageText"); } } #endregion /// /// 初始化 /// private void Init() { var hidUtils = EmployeeLoginViewModel.hidUtils; // hidUtils.Initial(); hidUtils.StartScan(); hidUtils.pushReceiveDataEvent += (bytes, str) => { if (times < 2) { str = str.ToString().Replace(" ", ""); BaseStaffInfo user = _baseStaffService.GetStaffInfoByCardId(str); if (user != null) { string staffType = user.StaffType; if (staffType == "1") { //显示记录 StaffIdText = user.StaffId; StaffNameText = user.StaffName; StaffTypeText = user.StaffType; TeamCodeText = user.TeamCode; //数量+1 times++; } else { HintText = "打卡人员非班长,打卡无效!"; } } else { HintText = "没有匹配的员工,打卡失败!"; } } }; } public void OnPropertyChanged([CallerMemberName] string propertyName = "") { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }