|
|
|
@ -1,32 +1,44 @@
|
|
|
|
|
using GalaSoft.MvvmLight;
|
|
|
|
|
using ConsoleApp;
|
|
|
|
|
using GalaSoft.MvvmLight;
|
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
|
|
|
|
using HslCommunication;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SlnMesnac.Business.business;
|
|
|
|
|
using SlnMesnac.Common;
|
|
|
|
|
using SlnMesnac.Model.domain;
|
|
|
|
|
using SlnMesnac.Model.dto;
|
|
|
|
|
using SlnMesnac.Repository.service;
|
|
|
|
|
using SlnMesnac.Repository.service.Impl;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using static Microsoft.WindowsAPICodePack.Shell.PropertySystem.SystemProperties.System;
|
|
|
|
|
|
|
|
|
|
namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
{
|
|
|
|
|
public class EmployeeLoginViewModel : ViewModelBase,INotifyPropertyChanged
|
|
|
|
|
public class EmployeeLoginViewModel : INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
private readonly RfidHandleBusniess rfidHandle;
|
|
|
|
|
private readonly ILogger<EmployeeLoginViewModel> _logger;
|
|
|
|
|
private readonly RfidHandleBusniess _rfidHandleBusniess;
|
|
|
|
|
private IBaseStaffService baseStaffService;
|
|
|
|
|
private IRecordStaffAttendanceService _recordStaffAttendanceService;
|
|
|
|
|
private string _checkInButtonText = "上班打卡";
|
|
|
|
|
private string _checkOutButtonText = "下班打卡";
|
|
|
|
|
public string _isCheckInButtonEnabled;
|
|
|
|
|
private string _isCheckOutButtonEnabled;
|
|
|
|
|
private string _checkInButtonColor;
|
|
|
|
|
private string _checkOutButtonColor = "#009999";
|
|
|
|
|
private int isCheckOn = 0;
|
|
|
|
|
private HidUtils hidUtils = new HidUtils();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按钮文字转换事件
|
|
|
|
@ -45,9 +57,64 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
/// 结束命令
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ICommand OverCommand { get; private set; }
|
|
|
|
|
private string _checkInButtonText = "上班打卡";
|
|
|
|
|
private string _checkOutButtonText = "下班打卡";
|
|
|
|
|
|
|
|
|
|
public EmployeeLoginViewModel()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
CheckInCommand = new RelayCommand(CheckIn);
|
|
|
|
|
CheckOutCommand = new RelayCommand(CheckOut);
|
|
|
|
|
OverCommand = new RelayCommand(Over);
|
|
|
|
|
baseStaffService = App.ServiceProvider.GetService<IBaseStaffService>();
|
|
|
|
|
_recordStaffAttendanceService = App.ServiceProvider.GetService<IRecordStaffAttendanceService>();
|
|
|
|
|
_rfidHandleBusniess = App.ServiceProvider.GetService<RfidHandleBusniess>();
|
|
|
|
|
//_rfidHandleBusniess.InstructionInfoDataGridEvent += RefreshRfidInfo;
|
|
|
|
|
IsCheckInButtonEnabled = "True";
|
|
|
|
|
IsCheckOutButtonEnabled = "True";
|
|
|
|
|
CheckInButtonColor = "#009999";
|
|
|
|
|
CheckOutButtonColor = "#009999";
|
|
|
|
|
Init();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Init()
|
|
|
|
|
{
|
|
|
|
|
hidUtils.Initial();
|
|
|
|
|
hidUtils.pushReceiveDataEvent += (bytes, str) =>
|
|
|
|
|
{
|
|
|
|
|
str = str.ToString().Replace(" ", "");
|
|
|
|
|
BaseStaffInfo user = baseStaffService.GetStaffInfoByCardId(str);
|
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
StaffIdText = user.StaffId;
|
|
|
|
|
CheckStatus = user.StaffName + " " + user.TeamCode + " 打卡成功!";
|
|
|
|
|
RecordStaffAttendance recordStaffAttendance = new RecordStaffAttendance
|
|
|
|
|
{
|
|
|
|
|
StaffId = user.StaffId,
|
|
|
|
|
AttendanceType = isCheckOn.ToString(),
|
|
|
|
|
TeamCode = user.TeamCode,
|
|
|
|
|
Remark = user.Remark,
|
|
|
|
|
CreateBy = user.StaffName,
|
|
|
|
|
CreateTime = DateTime.Now.ToString("HH:mm:ss"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_recordStaffAttendanceService.Insert(recordStaffAttendance);
|
|
|
|
|
var list = _recordStaffAttendanceService.GetRecordStaffAttendances();
|
|
|
|
|
|
|
|
|
|
System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () =>
|
|
|
|
|
{
|
|
|
|
|
RecordStaffAttendanceDataGrid.Clear();
|
|
|
|
|
list.ForEach(item => { RecordStaffAttendanceDataGrid.Add(item); });
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
StaffIdText = "未配置";
|
|
|
|
|
CheckStatus = "没有匹配的员工,打卡失败!";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上班打卡文本
|
|
|
|
|
/// </summary>
|
|
|
|
@ -126,31 +193,52 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EmployeeLoginViewModel()
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 员工id
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string staffId;
|
|
|
|
|
public string StaffIdText
|
|
|
|
|
{
|
|
|
|
|
CheckInCommand = new RelayCommand(CheckIn);
|
|
|
|
|
CheckOutCommand = new RelayCommand(CheckOut);
|
|
|
|
|
OverCommand = new RelayCommand(Over);
|
|
|
|
|
rfidHandle = App.ServiceProvider.GetService<RfidHandleBusniess>();
|
|
|
|
|
baseStaffService = App.ServiceProvider.GetService<IBaseStaffService>();
|
|
|
|
|
IsCheckInButtonEnabled = "True";
|
|
|
|
|
IsCheckOutButtonEnabled = "True";
|
|
|
|
|
CheckInButtonColor = "#009999";
|
|
|
|
|
CheckOutButtonColor = "#009999";
|
|
|
|
|
get { return staffId; }
|
|
|
|
|
set { staffId = value; OnPropertyChanged("StaffIdText"); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打卡状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string checkStatus;
|
|
|
|
|
public string CheckStatus
|
|
|
|
|
{
|
|
|
|
|
get { return checkStatus; }
|
|
|
|
|
set { checkStatus = value; OnPropertyChanged("CheckStatus"); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<RecordStaffAttendance> item = new ObservableCollection<RecordStaffAttendance>();
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
private ObservableCollection<RecordStaffAttendance> recordStaffAttendanceDataGrid=new ObservableCollection<RecordStaffAttendance>();
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<RecordStaffAttendance> RecordStaffAttendanceDataGrid
|
|
|
|
|
{
|
|
|
|
|
get { return recordStaffAttendanceDataGrid; }
|
|
|
|
|
set { recordStaffAttendanceDataGrid = value; OnPropertyChanged("RecordStaffAttendanceDataGrid"); }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上班打卡事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void CheckIn()
|
|
|
|
|
{
|
|
|
|
|
isCheckOn = 0;
|
|
|
|
|
if (CheckInButtonText == "上班打卡")
|
|
|
|
|
{
|
|
|
|
|
// 执行上班打卡逻辑
|
|
|
|
|
CheckInButtonText = "结束打卡";
|
|
|
|
|
IsCheckOutButtonEnabled = "False"; // Disable CheckOutButton
|
|
|
|
|
CheckOutButtonColor = "Gray";
|
|
|
|
|
rfidHandle.CheckIn();
|
|
|
|
|
hidUtils.StartScan();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -158,7 +246,7 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
CheckInButtonText = "上班打卡";
|
|
|
|
|
IsCheckOutButtonEnabled = "True"; // Enable CheckOutButton
|
|
|
|
|
CheckOutButtonColor = "#009999";
|
|
|
|
|
rfidHandle.CloseRfid();
|
|
|
|
|
hidUtils.StopScan();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -167,23 +255,22 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void CheckOut()
|
|
|
|
|
{
|
|
|
|
|
isCheckOn = 1;
|
|
|
|
|
if (CheckOutButtonText == "下班打卡")
|
|
|
|
|
{
|
|
|
|
|
// 执行下班打卡逻辑
|
|
|
|
|
CheckOutButtonText = "结束打卡";
|
|
|
|
|
IsCheckInButtonEnabled = "False"; // Disable CheckInButton
|
|
|
|
|
//IsCheckOutButtonEnabled = "True";
|
|
|
|
|
CheckInButtonColor = "Gray";
|
|
|
|
|
rfidHandle.CheckOut();
|
|
|
|
|
hidUtils.StartScan();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// 执行结束打卡逻辑
|
|
|
|
|
CheckOutButtonText = "下班打卡";
|
|
|
|
|
IsCheckInButtonEnabled = "True"; // Enable CheckInButton
|
|
|
|
|
//IsCheckOutButtonEnabled="False";
|
|
|
|
|
CheckInButtonColor = "#009999";
|
|
|
|
|
rfidHandle.CloseRfid();
|
|
|
|
|
hidUtils.StopScan();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -196,5 +283,12 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
CheckInButtonText = "上班打卡";
|
|
|
|
|
CheckOutButtonText = "下班打卡";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|