diff --git a/SlnMesnac.Business/SlnMesnac.Business.csproj b/SlnMesnac.Business/SlnMesnac.Business.csproj
index 4e2cf5e..d27063c 100644
--- a/SlnMesnac.Business/SlnMesnac.Business.csproj
+++ b/SlnMesnac.Business/SlnMesnac.Business.csproj
@@ -7,6 +7,7 @@
+
diff --git a/SlnMesnac.Business/business/RfidHandleBusniess.cs b/SlnMesnac.Business/business/RfidHandleBusniess.cs
index aecf886..8d209a6 100644
--- a/SlnMesnac.Business/business/RfidHandleBusniess.cs
+++ b/SlnMesnac.Business/business/RfidHandleBusniess.cs
@@ -3,8 +3,12 @@ using System.Collections.Generic;
using System.Text;
using System.Threading;
using ConsoleApp;
+using KdbndpTypes;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Common;
+using SlnMesnac.Model.domain;
+using SlnMesnac.Model.dto;
+using SlnMesnac.Repository.service;
namespace SlnMesnac.Business.business
{
@@ -14,11 +18,14 @@ namespace SlnMesnac.Business.business
public class RfidHandleBusniess
{
private readonly HidUtils _utils;
+ private IBaseStaffService _baseStaffService;
+ public string _uidCode = "";
+
-
- public RfidHandleBusniess(HidUtils utils)
+ public RfidHandleBusniess(HidUtils utils,IBaseStaffService baseStaffService)
{
this._utils = utils;
+ this._baseStaffService = baseStaffService;
}
string staffInfo = "";
@@ -39,33 +46,5 @@ namespace SlnMesnac.Business.business
{
_utils.StartScan();
}
-
- ///
- /// 结束打卡
- ///
- public void CloseRfid()
- {
- _utils.StopScan();
- }
-
- /////
- ///// 获取标签信息
- /////
- //private void GetTagInfo()
- //{
- // utils.pushReceiveDataEvent += (bytes, str) =>
- // {
- // Console.WriteLine($"收到打卡信息:{str}");
- // };
- //}
- /////
- ///// 获取员工信息
- /////
- //public string GetStaffInfo()
- //{
- // staffInfo = baseStaffInfoService.GetStaffByCardIdAsync(highRfid.GetTagInfo()).ToString();
- // return staffInfo;
- //}
-
}
}
diff --git a/SlnMesnac.Model/domain/RecordStaffAttendance.cs b/SlnMesnac.Model/domain/RecordStaffAttendance.cs
index f93d35d..bbe47aa 100644
--- a/SlnMesnac.Model/domain/RecordStaffAttendance.cs
+++ b/SlnMesnac.Model/domain/RecordStaffAttendance.cs
@@ -13,7 +13,7 @@ namespace SlnMesnac.Model.domain
///
///
///
- [SugarColumn(ColumnName = "obj_id", IsPrimaryKey = true)]
+ [SugarColumn(ColumnName = "obj_id", IsPrimaryKey = true,IsIdentity =true)]
public int ObjId { get; set; }
///
@@ -55,26 +55,26 @@ namespace SlnMesnac.Model.domain
///
/// 创建人
///
- [SugarColumn(ColumnName = "created_by")]
- public string CreatedBy { get; set; }
+ [SugarColumn(ColumnName = "create_by")]
+ public string CreateBy { get; set; }
///
/// 打卡时间
///
- [SugarColumn(ColumnName = "created_time")]
- public string CreatedTime { get; set; }
+ [SugarColumn(ColumnName = "create_time")]
+ public string CreateTime { get; set; }
///
/// 更新人
///
- [SugarColumn(ColumnName = "updated_by")]
- public string UpdatedBy { get; set; }
+ [SugarColumn(ColumnName = "update_by")]
+ public string UpdateBy { get; set; }
///
/// 更新时间
///
- [SugarColumn(ColumnName = "updated_time")]
- public string UpdatedTime { get; set; }
+ [SugarColumn(ColumnName = "update_time")]
+ public string UpdateTime { get; set; }
}
}
diff --git a/SlnMesnac.Model/dto/StaffAttendance.cs b/SlnMesnac.Model/dto/StaffAttendance.cs
new file mode 100644
index 0000000..34ed76f
--- /dev/null
+++ b/SlnMesnac.Model/dto/StaffAttendance.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace SlnMesnac.Model.dto
+{
+ public class StaffAttendance
+ {
+ ///
+ /// 员工ID
+ ///
+ public string staffId { get; set; }
+
+ ///
+ /// 员工姓名
+ ///
+ public string staffName { get; set; }
+
+ ///
+ /// 打卡类型
+ ///
+ public string attendanceType { get; set; }
+
+ ///
+ /// 班组编号
+ ///
+ public string teamCode { get; set; }
+ }
+}
diff --git a/SlnMesnac.Repository/service/IRecordStaffAttendanceService.cs b/SlnMesnac.Repository/service/IRecordStaffAttendanceService.cs
index 920c114..4fa93d6 100644
--- a/SlnMesnac.Repository/service/IRecordStaffAttendanceService.cs
+++ b/SlnMesnac.Repository/service/IRecordStaffAttendanceService.cs
@@ -15,7 +15,7 @@ namespace SlnMesnac.Repository.service
List GetRecordStaffAttendances();
///
- /// 验证添加用户信息,有一个错误时进行回滚
+ /// 验证添加员工打卡记录
///
///
///
diff --git a/SlnMesnac.Repository/service/Impl/RecordStaffAttendanceServiceImpl.cs b/SlnMesnac.Repository/service/Impl/RecordStaffAttendanceServiceImpl.cs
index 132d24e..3340024 100644
--- a/SlnMesnac.Repository/service/Impl/RecordStaffAttendanceServiceImpl.cs
+++ b/SlnMesnac.Repository/service/Impl/RecordStaffAttendanceServiceImpl.cs
@@ -22,6 +22,7 @@ namespace SlnMesnac.Repository.service.Impl
try
{
records = base._rep.GetList();
+ records.Reverse();
}
catch (Exception ex)
{
@@ -30,6 +31,7 @@ namespace SlnMesnac.Repository.service.Impl
return records;
}
+
public bool InsertRecordStaffAttendance(List records)
{
bool result = false;
diff --git a/SlnMesnac.WPF/App.xaml.cs b/SlnMesnac.WPF/App.xaml.cs
index 1d18174..9afea26 100644
--- a/SlnMesnac.WPF/App.xaml.cs
+++ b/SlnMesnac.WPF/App.xaml.cs
@@ -48,13 +48,8 @@ namespace SlnMesnac.WPF
var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/";
Log.Information($"系统初始化完成,日志存放路径:{appConfig.logPath}");
- var hidUtils = ServiceProvider.GetService();
- hidUtils.Initial();
- hidUtils.pushReceiveDataEvent += (bytes, str) =>
- {
- Console.WriteLine($"收到打卡信息:{str}");
- };
-
+ //var hidUtils = ServiceProvider.GetService();
+ //hidUtils.Initial();
}
///
@@ -78,7 +73,7 @@ namespace SlnMesnac.WPF
var hidUtils = ServiceProvider.GetService();
hidUtils.Close();
- //hidUtils.StopScan();
+ hidUtils.StopScan();
Log.Information($"系统退出,当前时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
// 释放资源
diff --git a/SlnMesnac.WPF/MainWindow.xaml.cs b/SlnMesnac.WPF/MainWindow.xaml.cs
index 2139374..88a84ce 100644
--- a/SlnMesnac.WPF/MainWindow.xaml.cs
+++ b/SlnMesnac.WPF/MainWindow.xaml.cs
@@ -26,6 +26,8 @@ namespace SlnMesnac.WPF
InitializeComponent();
this.DataContext = new MainWindowViewModel();
+
+
}
}
}
diff --git a/SlnMesnac.WPF/UserControls/EmployeeLoginPage.xaml b/SlnMesnac.WPF/UserControls/EmployeeLoginPage.xaml
index fddd41b..c6fa6f0 100644
--- a/SlnMesnac.WPF/UserControls/EmployeeLoginPage.xaml
+++ b/SlnMesnac.WPF/UserControls/EmployeeLoginPage.xaml
@@ -91,7 +91,7 @@
-
+
@@ -100,6 +100,7 @@
+
@@ -129,35 +130,42 @@
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SlnMesnac.WPF/UserControls/EmployeeLoginPage.xaml.cs b/SlnMesnac.WPF/UserControls/EmployeeLoginPage.xaml.cs
index d04d042..225be8f 100644
--- a/SlnMesnac.WPF/UserControls/EmployeeLoginPage.xaml.cs
+++ b/SlnMesnac.WPF/UserControls/EmployeeLoginPage.xaml.cs
@@ -57,5 +57,10 @@ namespace SlnMesnac.WPF.Page
//hIDMode.ConnectRfidHid();
//timer.Start();
}
+
+ private void dgvMH_LoadingRow(object sender, DataGridRowEventArgs e)
+ {
+ e.Row.Header = (e.Row.GetIndex() + 1).ToString();
+ }
}
}
diff --git a/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs b/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs
index 9c1964c..d5ac524 100644
--- a/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs
+++ b/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs
@@ -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 _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();
+
///
/// 按钮文字转换事件
@@ -45,9 +57,64 @@ namespace SlnMesnac.WPF.ViewModel
/// 结束命令
///
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();
+ _recordStaffAttendanceService = App.ServiceProvider.GetService();
+ _rfidHandleBusniess = App.ServiceProvider.GetService();
+ //_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
///
/// 上班打卡文本
///
@@ -126,31 +193,52 @@ namespace SlnMesnac.WPF.ViewModel
}
}
- public EmployeeLoginViewModel()
+ ///
+ /// 员工id
+ ///
+ private string staffId;
+ public string StaffIdText
{
- CheckInCommand = new RelayCommand(CheckIn);
- CheckOutCommand = new RelayCommand(CheckOut);
- OverCommand = new RelayCommand(Over);
- rfidHandle = App.ServiceProvider.GetService();
- baseStaffService = App.ServiceProvider.GetService();
- IsCheckInButtonEnabled = "True";
- IsCheckOutButtonEnabled = "True";
- CheckInButtonColor = "#009999";
- CheckOutButtonColor = "#009999";
+ get { return staffId; }
+ set { staffId = value; OnPropertyChanged("StaffIdText"); }
}
+ ///
+ /// 打卡状态
+ ///
+ private string checkStatus;
+ public string CheckStatus
+ {
+ get { return checkStatus; }
+ set { checkStatus = value; OnPropertyChanged("CheckStatus"); }
+ }
+
+ private ObservableCollection item = new ObservableCollection();
+
+ //
+ private ObservableCollection recordStaffAttendanceDataGrid=new ObservableCollection();
+
+ public ObservableCollection RecordStaffAttendanceDataGrid
+ {
+ get { return recordStaffAttendanceDataGrid; }
+ set { recordStaffAttendanceDataGrid = value; OnPropertyChanged("RecordStaffAttendanceDataGrid"); }
+
+ }
+ #endregion
+
///
/// 上班打卡事件
///
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
///
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));
+ }
}
}
diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs
index e63c64c..a42b6af 100644
--- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs
+++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs
@@ -1,8 +1,11 @@
-using GalaSoft.MvvmLight;
+using ConsoleApp;
+using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
+using SlnMesnac.Business.business;
using SlnMesnac.Common;
+using SlnMesnac.Repository.service;
using SlnMesnac.WPF.Page;
using SlnMesnac.WPF.Page.Generate;
using System;
@@ -19,7 +22,11 @@ namespace SlnMesnac.WPF.ViewModel
private readonly GenerateControl generateControl = new GenerateControl();
private readonly EmployeeLoginPage _employeeLoginPage = new EmployeeLoginPage();
private readonly ExecutePage _executePage = new ExecutePage();
+ private IBaseStaffService _baseStaffService;
+ public delegate void UIDCodeDelegate(string code);
+ public event UIDCodeDelegate UIDCodeDelegateEvent;
+
#region 参数定义
/////
///// PLC设备状态
@@ -92,6 +99,10 @@ namespace SlnMesnac.WPF.ViewModel
ControlOnClickCommand = new RelayCommand