change -人员登录逻辑完成

main
frankiecao 1 year ago
commit d845dd4004

@ -7,6 +7,7 @@
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" />
<ProjectReference Include="..\SlnMesnac.Rfid\SlnMesnac.Rfid.csproj" />
</ItemGroup>

@ -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();
}
/// <summary>
/// 结束打卡
/// </summary>
public void CloseRfid()
{
_utils.StopScan();
}
///// <summary>
///// 获取标签信息
///// </summary>
//private void GetTagInfo()
//{
// utils.pushReceiveDataEvent += (bytes, str) =>
// {
// Console.WriteLine($"收到打卡信息:{str}");
// };
//}
///// <summary>
///// 获取员工信息
///// </summary>
//public string GetStaffInfo()
//{
// staffInfo = baseStaffInfoService.GetStaffByCardIdAsync(highRfid.GetTagInfo()).ToString();
// return staffInfo;
//}
}
}

@ -13,7 +13,7 @@ namespace SlnMesnac.Model.domain
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "obj_id", IsPrimaryKey = true)]
[SugarColumn(ColumnName = "obj_id", IsPrimaryKey = true,IsIdentity =true)]
public int ObjId { get; set; }
/// <summary>
@ -55,26 +55,26 @@ namespace SlnMesnac.Model.domain
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(ColumnName = "created_by")]
public string CreatedBy { get; set; }
[SugarColumn(ColumnName = "create_by")]
public string CreateBy { get; set; }
/// <summary>
/// 打卡时间
/// </summary>
[SugarColumn(ColumnName = "created_time")]
public string CreatedTime { get; set; }
[SugarColumn(ColumnName = "create_time")]
public string CreateTime { get; set; }
/// <summary>
/// 更新人
/// </summary>
[SugarColumn(ColumnName = "updated_by")]
public string UpdatedBy { get; set; }
[SugarColumn(ColumnName = "update_by")]
public string UpdateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
[SugarColumn(ColumnName = "updated_time")]
public string UpdatedTime { get; set; }
[SugarColumn(ColumnName = "update_time")]
public string UpdateTime { get; set; }
}
}

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SlnMesnac.Model.dto
{
public class StaffAttendance
{
/// <summary>
/// 员工ID
/// </summary>
public string staffId { get; set; }
/// <summary>
/// 员工姓名
/// </summary>
public string staffName { get; set; }
/// <summary>
/// 打卡类型
/// </summary>
public string attendanceType { get; set; }
/// <summary>
/// 班组编号
/// </summary>
public string teamCode { get; set; }
}
}

@ -15,7 +15,7 @@ namespace SlnMesnac.Repository.service
List<RecordStaffAttendance> GetRecordStaffAttendances();
/// <summary>
/// 验证添加用户信息,有一个错误时进行回滚
/// 验证添加员工打卡记录
/// </summary>
/// <param name="recordStaffAttendances"></param>
/// <returns></returns>

@ -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<RecordStaffAttendance> records)
{
bool result = false;

@ -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>();
hidUtils.Initial();
hidUtils.pushReceiveDataEvent += (bytes, str) =>
{
Console.WriteLine($"收到打卡信息:{str}");
};
//var hidUtils = ServiceProvider.GetService<HidUtils>();
//hidUtils.Initial();
}
/// <summary>
@ -78,7 +73,7 @@ namespace SlnMesnac.WPF
var hidUtils = ServiceProvider.GetService<HidUtils>();
hidUtils.Close();
//hidUtils.StopScan();
hidUtils.StopScan();
Log.Information($"系统退出,当前时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
// 释放资源

@ -26,6 +26,8 @@ namespace SlnMesnac.WPF
InitializeComponent();
this.DataContext = new MainWindowViewModel();
}
}
}

@ -91,7 +91,7 @@
<Border.Effect>
<DropShadowEffect Color="#1254AB" Direction="270" BlurRadius="10" ShadowDepth="5" Opacity="0.5"/>
</Border.Effect>
<TextBlock Text="{Binding StaffInfo}" FontSize="20" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding StaffIdText}" FontSize="20" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Column="2">
<TextBlock Text="打卡状态" FontSize="20" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,20,0"/>
@ -100,6 +100,7 @@
<Border.Effect>
<DropShadowEffect Color="#1254AB" Direction="270" BlurRadius="10" ShadowDepth="5" Opacity="0.5"/>
</Border.Effect>
<TextBlock Text="{Binding CheckStatus}" FontSize="20" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</Grid>
</Border>
@ -129,35 +130,42 @@
<Border.Effect>
<DropShadowEffect Color="#1254AB" Direction="270" BlurRadius="10" ShadowDepth="5" Opacity="0.5"/>
</Border.Effect>
<DataGrid Name="dataGrid" ItemsSource="{Binding RfidInfoDataGrid}" Background="Transparent"
FontSize="15" ColumnHeaderHeight="30"
<DataGrid Name="dataGrid" ItemsSource="{Binding RecordStaffAttendanceDataGrid}" Background="Transparent"
FontSize="15" ColumnHeaderHeight="30" LoadingRow="dgvMH_LoadingRow"
RowHeight="30" AutoGenerateColumns="False" RowHeaderWidth="0"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="0" CanUserAddRows="False"
Foreground="#FFFFFF" SelectedItem="{Binding SelectedDataItem}">
<!--resourceStyle 399行修改选中字体颜色-->
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding baggageTagCode}" Header="序号" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding baggageTagCode}" Header="员工ID" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding baggageTagCode}" Header="员工姓名" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<!--<DataGridTextColumn Binding="{Binding date,StringFormat=\{0:yyyy-MM-dd\}}" Header="工单编号" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>-->
<DataGridTextColumn Binding="{Binding flightData}" Header="员工类型" Width="3*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<!--<DataGridTextColumn Binding="{Binding hualway}" Header="性别" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>-->
<DataGridTextColumn Binding="{Binding baggageTagCode}" Header="卡号" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding baggageTagCode}" Header="班组编号" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<!--<DataGridTextColumn Binding="{Binding baggageTagCode}" Header="手机号" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>-->
<DataGridTemplateColumn Header="操作" Width="2*" >
<DataGridTemplateColumn Width="55" Header="序号" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<WrapPanel>
<!--<Button Content="查看" FontSize="12" CommandParameter="{Binding ID}" Margin="0 2 0 2" Command="{Binding DataContext.MoveUpCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid }}" />-->
<!--<Button Content="执行" FontSize="12" CommandParameter="{Binding ID}" Margin="2 2 0 2" Command="{Binding DataContext.MoveDownCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid }}" />-->
<Button Content="取消" FontSize="12" CommandParameter="{Binding ID}" Margin="2 2 0 2" Background="#df4642" BorderBrush="#df4642" Command="{Binding DataContext.DeletePlanCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid }}" />
<!--<Button Content="下传" FontSize="12" CommandParameter="{Binding ID}" Margin="2 2 0 2" Command="{Binding DataContext.MoveDownCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid }}" />-->
</WrapPanel>
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGridRow}}, Path=Header}" FontSize="18" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding ObjId}" Header="序号1" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" Visibility="Collapsed"/>
<DataGridTextColumn Binding="{Binding StaffId}" Header="员工ID" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding CreateBy}" Header="员工姓名" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<!--<DataGridTextColumn Binding="{Binding date,StringFormat=\{0:yyyy-MM-dd\}}" Header="工单编号" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>-->
<DataGridTextColumn Binding="{Binding AttendanceType}" Header="打卡类型" Width="3*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<!--<DataGridTextColumn Binding="{Binding hualway}" Header="性别" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>-->
<!--<DataGridTextColumn Binding="{Binding baggageTagCode}" Header="卡号" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>-->
<DataGridTextColumn Binding="{Binding TeamCode}" Header="班组编号" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<!--<DataGridTextColumn Binding="{Binding baggageTagCode}" Header="手机号" Width="2*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>-->
<!--<DataGridTemplateColumn Header="操作" Width="2*" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<WrapPanel>
--><!--<Button Content="查看" FontSize="12" CommandParameter="{Binding ID}" Margin="0 2 0 2" Command="{Binding DataContext.MoveUpCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid }}" />-->
<!--<Button Content="执行" FontSize="12" CommandParameter="{Binding ID}" Margin="2 2 0 2" Command="{Binding DataContext.MoveDownCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid }}" />--><!--
<Button Content="取消" FontSize="12" CommandParameter="{Binding ID}" Margin="2 2 0 2" Background="#df4642" BorderBrush="#df4642" Command="{Binding DataContext.DeletePlanCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid }}" />
--><!--<Button Content="下传" FontSize="12" CommandParameter="{Binding ID}" Margin="2 2 0 2" Command="{Binding DataContext.MoveDownCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid }}" />--><!--
</WrapPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>-->
</DataGrid.Columns>
</DataGrid>
</Border>

@ -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();
}
}
}

@ -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));
}
}
}

@ -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 参数定义
///// <summary>
///// PLC设备状态
@ -92,6 +99,10 @@ namespace SlnMesnac.WPF.ViewModel
ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj));
FormControlCommand = new RelayCommand<object>(x => FormControl(x));
//RfidHandleBusniess rfidHandleBusniess = new RfidHandleBusniess(hidUtils,_baseStaffService);
}
/// <summary>

Loading…
Cancel
Save