diff --git a/SlnMesnac.Business/business/DatabaseHandleBusniess.cs b/SlnMesnac.Business/business/DatabaseHandleBusniess.cs index 029e95e..ea8a170 100644 --- a/SlnMesnac.Business/business/DatabaseHandleBusniess.cs +++ b/SlnMesnac.Business/business/DatabaseHandleBusniess.cs @@ -1,7 +1,9 @@ using SlnMesnac.Model.domain; using SlnMesnac.Repository.service; +using SqlSugar; using System; using System.Collections.Generic; +using System.Linq; using System.Text; namespace SlnMesnac.Business.business @@ -9,72 +11,183 @@ namespace SlnMesnac.Business.business public class DatabaseHandleBusniess { private ProdPlanInfoService _prodPlanInfoService; + private ProdPlanExecuteUserService _prodPlanExecuteUserService; + private ProdOrderInfoService _prodOrderInfoService; + private IRecordStaffRealTimeService _recordStaffRealTimeService; private List prodPlanInfos; - public DatabaseHandleBusniess(ProdPlanInfoService prodPlanInfoService) + public DatabaseHandleBusniess(ProdPlanInfoService prodPlanInfoService, ProdOrderInfoService prodOrderInfoService, ProdPlanExecuteUserService prodPlanExecuteUserService,IRecordStaffRealTimeService recordStaffRealTimeService) { _prodPlanInfoService = prodPlanInfoService; + _prodOrderInfoService = prodOrderInfoService; prodPlanInfos = _prodPlanInfoService.GetRecordStaffAttendances(); + _prodPlanExecuteUserService = prodPlanExecuteUserService; + _recordStaffRealTimeService = recordStaffRealTimeService; } /// - /// 查询所有计划工位 + /// 根据订单编号查询订单信息 /// + /// /// - public List GetProductLineCodes() + public ProdOrderInfo GetProdOrderInfoByOrderCode(string orderCode) { - - List productLineCodes = new List(); - foreach (var prodPlanInfo in prodPlanInfos) - { - productLineCodes.Add(prodPlanInfo.StationCode); - } - return productLineCodes; + return _prodOrderInfoService.GetProdOrderInfoByOrderCode(orderCode); } /// - /// 查询所有工单编号 + /// 添加新的工单信息 /// - /// - public List GetPlanCodes() + /// + /// + public void AddNewPlanInfo(string? orderCode,string? stationCode,string? deviceCode,string? processCode,string? importFlag) { - - List planCodes = new List(); - foreach (var prodPlanInfo in prodPlanInfos) + var orderInfo = GetProdOrderInfoByOrderCode(orderCode); + string randomString = GenerateRandomString(14); + _prodPlanInfoService.Insert(new ProdPLanInfo() { - planCodes.Add(prodPlanInfo.PlanCode); + PlanCode = orderCode + randomString, + OrderCode = orderCode, + MaterialCode = orderInfo.MaterialCode, + MaterialName = orderInfo.MaterialName, + StationCode = stationCode, + DeviceCode = deviceCode, + PlanAmount = orderInfo.OrderAmount, + CompleteAmount = orderInfo.CompleteAmount, + PlanStatus = "4", + ProcessCode = processCode, + ImportFlag = importFlag + }); + } + + /// + /// 生成随机字符串 + /// + /// + /// + private string GenerateRandomString(int length) + { + const string chars = "abcdefghijklmnopqrstuvwxyz0123456789"; + Random random = new Random(); + StringBuilder result = new StringBuilder(); + + for (int i = 0; i < length; i++) + { + result.Append(chars[random.Next(chars.Length)]); } - return planCodes; + + return result.ToString(); } /// - /// 查询所有订单编号 + /// 更新订单状态 /// - /// - public List GetOrderCodes() + /// + /// + /// + /// + /// + /// + public void UpdatePlanStatus(string orderCode, string stationCode, string deviceCode, string processCode, string status) { - - List orderCodes = new List(); - foreach (var prodPlanInfo in prodPlanInfos) - { - orderCodes.Add(prodPlanInfo.OrderCode); - } - return orderCodes; + _prodPlanInfoService.UpdatePlanStatus(orderCode, stationCode, deviceCode, processCode, status); } /// - /// 查询所有物料名称 + /// 插入工单执行人员信息 + /// + public void InsertPlanExecuteUser(ProdPLanInfo prodPlanInfo,ProdPlanDetail prodPlanDetail,List realTimes) + { + foreach (var item in realTimes) + { + ProdPlanExecuteUser prodPlanExecuteUser = new ProdPlanExecuteUser() + { + PlanCode = prodPlanInfo.PlanCode, + OrderCode = prodPlanInfo.OrderCode, + ProcessCode = prodPlanInfo.ProcessCode, + StationCode = prodPlanInfo.StationCode, + StaffId = item.StaffId, + CompleteAmount = prodPlanDetail.CompleteAmount, + PlanBeginDate = prodPlanInfo.BeginTime, + PlanEndDate = prodPlanInfo.EndTime, + CreatedBy = prodPlanInfo.CreatedBy, + CreatedTime = prodPlanInfo.CreatedTime, + UpdatedBy = prodPlanInfo.UpdatedBy, + UpdatedTime = prodPlanInfo.UpdatedTime, + BatchNumber = prodPlanDetail.BatchNumber + }; + _prodPlanExecuteUserService.Insert(prodPlanExecuteUser); + } + } + + /// + /// 查询所有工单执行人员信息 /// /// - public List GetMaterialNames() + public List GetRecordStaffRealTimes() { - - List materialNames = new List(); - foreach (var prodPlanInfo in prodPlanInfos) - { - materialNames.Add(prodPlanInfo.MaterialName); - } - return materialNames; + var list = _recordStaffRealTimeService.Query(); + return list; } + + ///// + ///// 查询所有计划工位 + ///// + ///// + //public List GetProductLineCodes() + //{ + + // List productLineCodes = new List(); + // foreach (var prodPlanInfo in prodPlanInfos) + // { + // productLineCodes.Add(prodPlanInfo.StationCode); + // } + // return productLineCodes; + //} + + ///// + ///// 查询所有工单编号 + ///// + ///// + //public List GetPlanCodes() + //{ + + // List planCodes = new List(); + // foreach (var prodPlanInfo in prodPlanInfos) + // { + // planCodes.Add(prodPlanInfo.PlanCode); + // } + // return planCodes; + //} + + ///// + ///// 查询所有订单编号 + ///// + ///// + //public List GetOrderCodes() + //{ + + // List orderCodes = new List(); + // foreach (var prodPlanInfo in prodPlanInfos) + // { + // orderCodes.Add(prodPlanInfo.OrderCode); + // } + // return orderCodes; + //} + + ///// + ///// 查询所有物料名称 + ///// + ///// + //public List GetMaterialNames() + //{ + + // List materialNames = new List(); + // foreach (var prodPlanInfo in prodPlanInfos) + // { + // materialNames.Add(prodPlanInfo.MaterialName); + // } + // return materialNames; + //} } } diff --git a/SlnMesnac.Business/business/RfidHandleBusniess.cs b/SlnMesnac.Business/business/RfidHandleBusniess.cs index d8d5ae1..3d50a64 100644 --- a/SlnMesnac.Business/business/RfidHandleBusniess.cs +++ b/SlnMesnac.Business/business/RfidHandleBusniess.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; using System.Threading; using ConsoleApp; @@ -19,15 +20,17 @@ namespace SlnMesnac.Business.business { private IRecordStaffAttendanceService _recordStaffAttendanceService; private IRecordStaffCommuteService _recordStaffCommuteService; + private IRecordStaffRealTimeService _recordStaffRealTimeService; private string currentTime; private string teamMembers = null; private List members = new List(); + public static string stationCode = ""; - - public RfidHandleBusniess(IRecordStaffAttendanceService recordStaffAttendanceService, IRecordStaffCommuteService recordStaffCommuteService) + public RfidHandleBusniess(IRecordStaffAttendanceService recordStaffAttendanceService, IRecordStaffCommuteService recordStaffCommuteService, IRecordStaffRealTimeService recordStaffRealTimeService) { this._recordStaffAttendanceService = recordStaffAttendanceService; this._recordStaffCommuteService = recordStaffCommuteService; + this._recordStaffRealTimeService = recordStaffRealTimeService; } @@ -46,10 +49,11 @@ namespace SlnMesnac.Business.business TeamCode = staff.TeamCode, Remark = staff.Remark, CreateBy = staff.StaffName, - CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + StationCode = stationCode }; _recordStaffAttendanceService.Insert(recordStaffAttendance); - return _recordStaffAttendanceService.GetRecordStaffAttendances(); + return _recordStaffAttendanceService.GetRecordStaffAttendances(stationCode); } /// @@ -83,23 +87,62 @@ namespace SlnMesnac.Business.business } } - public string SpliceTeamMember(BaseStaffInfo baseStaffInfo) + /// + /// + /// + /// + /// + public string SpliceTeamMember() { - RecordStaffAttendance recordStaffAttendance = _recordStaffAttendanceService.GetRecordStaffAttendanceByStaffId(baseStaffInfo.StaffId); - string type = recordStaffAttendance.AttendanceType; - if (type == "0")//上班,添加员工名字转成字符串 + //RecordStaffAttendance recordStaffAttendance = _recordStaffAttendanceService.GetRecordStaffAttendanceByStaffId(baseStaffInfo.StaffId,stationCode); + List recordStaffRealTimeList = _recordStaffRealTimeService.GetRecordStaffRealTime(stationCode); + //string type = recordStaffAttendance.AttendanceType; + //if (type == "0")//上班,添加员工名字转成字符串 + //{ + // members.Add(baseStaffInfo.StaffName); // Add the staff member's name to the list + // teamMembers = string.Join(" // ", members); // Convert the list of names to a string separated by commas + //} + //else if (type == "1")//下班,删除下班员工的名字再转为字符串 + //{ + // members.Remove(baseStaffInfo.StaffName); // Remove the staff member's name from the list + // teamMembers = string.Join(" // ", members); // Convert the updated list of names to a string separated by commas + //} + foreach(var item in recordStaffRealTimeList) { - members.Add(baseStaffInfo.StaffName); // Add the staff member's name to the list - teamMembers = string.Join("| ", members); // Convert the list of names to a string separated by commas + teamMembers += item.CreateBy + " / "; } - else if (type == "1")//下班,删除下班员工的名字再转为字符串 - { - members.Remove(baseStaffInfo.StaffName); // Remove the staff member's name from the list - teamMembers = string.Join("| ", members); // Convert the updated list of names to a string separated by commas - } - return teamMembers; } + /// + /// 处理并插入实时打卡记录 + /// + /// + /// + public List HandleAndInsertStaffRealTime(BaseStaffInfo staff,int isCheckOn) + { + if (isCheckOn == 0) + { + RecordStaffRealTime recordStaffRealTime = new RecordStaffRealTime + { + StaffId = staff.StaffId, + AttendanceType = isCheckOn.ToString(), + TeamCode = staff.TeamCode, + Remark = staff.Remark, + CreateBy = staff.StaffName, + CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + StationCode = stationCode + }; + _recordStaffRealTimeService.Insert(recordStaffRealTime); + } + else if(isCheckOn == 1 || isCheckOn == 2) + { + var realTime = _recordStaffRealTimeService.Query(recordStaffRealTime => recordStaffRealTime.StaffId == staff.StaffId + && recordStaffRealTime.StationCode == stationCode + && recordStaffRealTime.AttendanceType == "0").FirstOrDefault(); + _recordStaffRealTimeService.Delete(realTime); + } + return _recordStaffRealTimeService.GetRecordStaffRealTime(stationCode); + } } } diff --git a/SlnMesnac.Business/business/SerialPortBusiness.cs b/SlnMesnac.Business/business/SerialPortBusiness.cs new file mode 100644 index 0000000..1509176 --- /dev/null +++ b/SlnMesnac.Business/business/SerialPortBusiness.cs @@ -0,0 +1,242 @@ +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO.Ports; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Linq; +using SlnMesnac.Model.domain; +using SlnMesnac.Model.dto; +using System.Text.Json.Nodes; + +namespace SlnMesnac.Business +{ + public class SerialPortBusiness + { + + private static readonly object _object = new object(); + + private SerialPort _serialPort; + + + public delegate void RefreshSerialPortDeviceStatus(int isFlag); + public event RefreshSerialPortDeviceStatus RefreshSerialPortDeviceStatusEvent; + + /// + /// 刷新日志内容 + /// + public delegate void RefreshLogMessage(string message); + public event RefreshLogMessage RefreshLogMessageEvent; + + //public delegate void ReceivedMeterConfigInfo(ElectricMeterInfoDto electricMeterInfo, List electricMeterConfigInfos); + //public event ReceivedMeterConfigInfo ReceivedMeterConfigInfoEvent; + + public delegate void ReceivedBarcodeInfo(string barcodeInfo); + public static event ReceivedBarcodeInfo? ReceivedBarcodeInfoEvent; + + //public delegate void ReceivedGatewayConfigInfo(GatewayInfoDto gatewayInfoDto); + //public event ReceivedGatewayConfigInfo ReceivedGatewayConfigInfoEvent; + + /// + /// 获取系统内的串口 + /// + /// + public void GetSerialPorts(out List serialPorts) + { + serialPorts = SerialPort.GetPortNames().ToList(); + } + + /// + /// 打开串口 + /// + /// 串口号 + /// 波特率 + /// 校验位None = 0,Odd = 1, Even = 2,Mark = 3,Space = 4, + /// 数据位 + /// 停止位 + public void OpenSerialPort(string serialPort, int baudRate, int parity, int dataBits, int stopBits) + { + if (string.IsNullOrEmpty(serialPort)) + { + throw new ArgumentException("串口号不能为空"); + } + + _serialPort = new SerialPort(serialPort, baudRate, (System.IO.Ports.Parity)parity, dataBits, (StopBits)stopBits); + _serialPort.DataReceived += SerialPortDataReceived; + _serialPort.Open(); + + RefreshSerialPortDeviceStatusEvent?.Invoke(1); + } + + /// + /// 关闭串口 + /// + /// + public void CloseSerialPort() + { + if (_serialPort == null) + { + throw new ArgumentException("串口实例为空"); + } + + _serialPort.Close(); + + RefreshSerialPortDeviceStatusEvent?.Invoke(2); + } + + /// + /// 发送数据 + /// + /// + /// + public void SendMessage(string message) + { + try + { + if (message == null) + { + throw new ArgumentException("发送内容为空"); + } + //RefreshLogMessageEvent?.Invoke($"发送指令:{message}"); + if(_serialPort != null && _serialPort.IsOpen) + { + _serialPort.Write(message); + RefreshLogMessageEvent?.Invoke("发送成功"); + } + else + { + RefreshLogMessageEvent?.Invoke("串口未打开,无法发送数据"); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + } + + /// + /// 串口数据接收 + /// + /// + /// + private void SerialPortDataReceived(object sender, SerialDataReceivedEventArgs e) + { + try + { + lock (string.Empty) + { + Thread.Sleep(50); + SerialPort sp = (SerialPort)sender; + // 读取字节数据 + int bytesToRead = _serialPort.BytesToRead; + byte[] buffer = new byte[bytesToRead]; + sp.Read(buffer, 0, bytesToRead); + string data = System.Text.Encoding.ASCII.GetString(buffer); + if (!string.IsNullOrEmpty(data)) + { + RefreshLogMessageEvent?.Invoke("Received data: " + data); + ReceivedBarcodeInfoEvent?.Invoke(data); + //Analys(data); + } + } + } + catch (Exception ex) + { + Console.WriteLine("接收数据时发生错误: " + ex.Message); + } + } + + ///// + ///// 解析数据 + ///// + ///// + //public void Analys(string jsonStr) + //{ + // try + // { + // if (jsonStr.Contains("OK")) + // { + // RefreshLogMessageEvent?.Invoke($"修改成功"); + // return; + // } + // else if (jsonStr.Contains("Error")) + // { + // RefreshLogMessageEvent?.Invoke($"修改失败"); + // return; + // } + // else if (jsonStr.Contains("MeterSerialNumber")) //电表信息 + // { + + // #region 判断JSON格式合法性,获取第一个}为结尾,避免硬件返回多余数据 + // int lastBraceIndex = jsonStr.IndexOf('}'); + + // if (lastBraceIndex != -1) + // { + // jsonStr = jsonStr.Substring(0, lastBraceIndex + 1); + + // } + // else + // { + // RefreshLogMessageEvent?.Invoke($"设备信息指令有误:{jsonStr}"); + // return; + // } + // #endregion + + // RefreshLogMessageEvent?.Invoke($"解析电表设备信息:{jsonStr}"); + // if (!string.IsNullOrEmpty(jsonStr)) + // { + // var jsonObject = JObject.Parse(jsonStr); + + // ElectricMeterInfoDto electricMeterInfo = JsonConvert.DeserializeObject(jsonObject.ToString()); + + // AnalysMeterConfig(jsonObject, ref electricMeterInfo, out List electricMeterConfigInfos); + + // ReceivedMeterConfigInfoEvent?.Invoke(electricMeterInfo, electricMeterConfigInfos); + // } + // }else if (jsonStr.Contains("NaturalGas")) + // { + // RefreshLogMessageEvent?.Invoke($"解析网关设备信息:{jsonStr}"); + // GatewayInfoDto gatewayInfo = JsonConvert.DeserializeObject(jsonStr); + // ReceivedGatewayConfigInfoEvent?.Invoke(gatewayInfo); + // } + + // } + // catch (Exception ex) + // { + // RefreshLogMessageEvent?.Invoke($"解析逻辑异常:{ex.Message};原始数据:{jsonStr}"); + // } + //} + + ///// + ///// 解析子表配置信息 + ///// + ///// + ///// + ///// + //private void AnalysMeterConfig(JObject jsonObject, ref ElectricMeterInfoDto electricMeterInfo, out List electricMeterConfigInfos) + //{ + // electricMeterConfigInfos = new List(); + // foreach (var property in jsonObject.Properties()) + // { + // if (electricMeterInfo.GetType().GetProperty(property.Name) == null) + // { + // string proValue = property.Value.ToObject(); + // string[] proValueArray = proValue.Split(","); + + // if (proValueArray.Length == 4) + // { + // ElectricMeterConfigInfo electricMeterConfigInfo = new ElectricMeterConfigInfo(); + // electricMeterConfigInfo.PointName = property.Name; + // electricMeterConfigInfo.InitialAddress = proValueArray[0]; + // electricMeterConfigInfo.Length = Convert.ToInt32(proValueArray[1]); + // electricMeterConfigInfo.Rate = proValueArray[2]; + // electricMeterConfigInfo.DataType = Convert.ToInt32(proValueArray[3]); + // electricMeterConfigInfos.Add(electricMeterConfigInfo); + // } + // } + // } + //} + } +} diff --git a/SlnMesnac.Common/SlnMesnac.Common.csproj b/SlnMesnac.Common/SlnMesnac.Common.csproj index 3b8369c..a2b4bfa 100644 --- a/SlnMesnac.Common/SlnMesnac.Common.csproj +++ b/SlnMesnac.Common/SlnMesnac.Common.csproj @@ -13,7 +13,7 @@ - C:\Users\Administrator\Desktop\信明橡塑\测试文件\ConsoleApp\Library\HighRFIDSendCardDLL.dll + ..\..\HighRFIDSendCardDLL.dll diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs index 1cfc66e..a555c23 100644 --- a/SlnMesnac.Config/AppConfig.cs +++ b/SlnMesnac.Config/AppConfig.cs @@ -52,7 +52,6 @@ namespace SlnMesnac.Config /// public List rfidConfig { get; set; } - /// /// Redis配置 /// diff --git a/SlnMesnac.Model/SlnMesnac.Model.csproj b/SlnMesnac.Model/SlnMesnac.Model.csproj index 4f9d9b5..8c27fcb 100644 --- a/SlnMesnac.Model/SlnMesnac.Model.csproj +++ b/SlnMesnac.Model/SlnMesnac.Model.csproj @@ -9,4 +9,10 @@ + + + C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF\PresentationFramework.dll + + + diff --git a/SlnMesnac.Model/domain/ProdOrderInfo.cs b/SlnMesnac.Model/domain/ProdOrderInfo.cs new file mode 100644 index 0000000..af7d143 --- /dev/null +++ b/SlnMesnac.Model/domain/ProdOrderInfo.cs @@ -0,0 +1,109 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; + +namespace SlnMesnac.Model.domain +{ + [SugarTable("prod_order_info"), TenantAttribute("mes")] + [DataContract(Name = "ProdOrderInfo erp订单信息")] + public class ProdOrderInfo + { + /// + /// + /// + [SugarColumn(ColumnName = "obj_id", IsPrimaryKey = true)] + public int ObjId { get; set; } + + /// + /// ERP订单编号 + /// + [SugarColumn(ColumnName = "order_code")] + public string OrderCode { get; set; } + + /// + /// 物料编号 + /// + [SugarColumn(ColumnName = "material_code")] + public string MaterialCode { get; set; } + + /// + /// 物料名称 + /// + [SugarColumn(ColumnName = "material_name")] + public string MaterialName { get; set; } + + /// + /// 订单计划数量 + /// + [SugarColumn(ColumnName = "order_amount")] + public string OrderAmount { get; set; } + + /// + /// 完成数量 + /// + [SugarColumn(ColumnName = "complete_amount")] + public string CompleteAmount { get; set; } + + /// + /// 订单类型 + /// + [SugarColumn(ColumnName = "order_type")] + public string OrderType { get; set; } + + /// + /// 订单类型 + /// + [SugarColumn(ColumnName = "order_status")] + public string OrderStatus { get; set; } + + /// + /// 计划开始时间 + /// + [SugarColumn(ColumnName = "begin_date")] + public string BeginDate { get; set; } + + /// + /// 计划完成时间 + /// + [SugarColumn(ColumnName = "end_date")] + public string EndDate { get; set; } + + /// + /// 实际开始时间 + /// + [SugarColumn(ColumnName = "real_begin_date")] + public string RealBeginDate { get; set; } + + /// + /// 实际完成时间 + /// + [SugarColumn(ColumnName = "real_end_date")] + public string RealEndDate { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "created_time")] + public string CreatedTime { get; set; } + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "updated_by")] + public string UpdatedBy { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "updated_time")] + public string UpdatedTime { get; set; } + } +} diff --git a/SlnMesnac.Model/domain/ProdPLanInfo.cs b/SlnMesnac.Model/domain/ProdPLanInfo.cs index ecbf709..2310f2c 100644 --- a/SlnMesnac.Model/domain/ProdPLanInfo.cs +++ b/SlnMesnac.Model/domain/ProdPLanInfo.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; } /// @@ -112,10 +112,40 @@ namespace SlnMesnac.Model.domain [SugarColumn(ColumnName = "device_code")] public string DeviceCode { get; set; } + /// + /// 计划开始时间 + /// + [SugarColumn(ColumnName = "plan_begin_time")] + public string PlanBeginTime { get; set; } + + /// + /// 计划结束时间 + /// + [SugarColumn(ColumnName = "plan_end_time")] + public string PlanEndTime { get; set; } + /// /// 工单状态 /// [SugarColumn(ColumnName = "plan_status")] public string PlanStatus { get; set; } + + /// + /// 班组 + /// + [SugarColumn(ColumnName = "classes")] + public string Classes { get; set; } + + /// + /// 工序编号 + /// + [SugarColumn(ColumnName = "process_code")] + public string ProcessCode { get; set; } + + /// + /// 导入类型 + /// + [SugarColumn(ColumnName = "import_flag")] + public string ImportFlag { get; set; } } } diff --git a/SlnMesnac.Model/domain/ProdPlanDetail.cs b/SlnMesnac.Model/domain/ProdPlanDetail.cs index 19390d2..41aa1c5 100644 --- a/SlnMesnac.Model/domain/ProdPlanDetail.cs +++ b/SlnMesnac.Model/domain/ProdPlanDetail.cs @@ -93,5 +93,11 @@ namespace SlnMesnac.Model.domain /// [SugarColumn(ColumnName = "updated_time")] public string UpdatedTime { get; set; } + + /// + /// 批次号锅数 + /// + [SugarColumn(ColumnName = "batch_number")] + public int BatchNumber { get; set; } } } diff --git a/SlnMesnac.Model/domain/ProdPlanExecuteUser.cs b/SlnMesnac.Model/domain/ProdPlanExecuteUser.cs new file mode 100644 index 0000000..1598275 --- /dev/null +++ b/SlnMesnac.Model/domain/ProdPlanExecuteUser.cs @@ -0,0 +1,97 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; + +namespace SlnMesnac.Model.domain +{ + [SugarTable("prod_plan_execute_user"), TenantAttribute("mes")] + [DataContract(Name = "ProdPlanExecuteUser 员工信息")] + public class ProdPlanExecuteUser + { + /// + /// + /// + [SugarColumn(ColumnName = "obj_id", IsPrimaryKey = true, IsIdentity = true)] + public int ObjId { get; set; } + + /// + /// 订单编号 + /// + [SugarColumn(ColumnName = "order_code")] + public string OrderCode { get; set; } + + /// + /// 工单编号 + /// + [SugarColumn(ColumnName = "plan_code")] + public string PlanCode { get; set;} + + /// + /// 工序编号 + /// + [SugarColumn(ColumnName = "process_code")] + public string ProcessCode { get; set; } + + /// + /// 工位编号 + /// + [SugarColumn(ColumnName = "station_code")] + public string StationCode { get; set; } + + /// + /// 员工编号 + /// + [SugarColumn(ColumnName = "staff_id")] + public string StaffId { get; set; } + + /// + /// 完成数量 + /// + [SugarColumn(ColumnName = "complete_amount")] + public string CompleteAmount { get; set; } + + /// + /// 工单明细开始时间 + /// + [SugarColumn(ColumnName = "plan_begin_date")] + public string PlanBeginDate { get; set; } + + /// + /// 工单明细结束时间 + /// + [SugarColumn(ColumnName = "plan_end_date")] + public string PlanEndDate { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "created_time")] + public string CreatedTime { get; set; } + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "updated_by")] + public string UpdatedBy { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "updated_time")] + public string UpdatedTime { get; set; } + + /// + /// 批次号锅数 + /// + [SugarColumn(ColumnName = "batch_number")] + public int BatchNumber { get; set; } + } +} diff --git a/SlnMesnac.Model/domain/RecordStaffAttendance.cs b/SlnMesnac.Model/domain/RecordStaffAttendance.cs index 36b8841..8cc0c66 100644 --- a/SlnMesnac.Model/domain/RecordStaffAttendance.cs +++ b/SlnMesnac.Model/domain/RecordStaffAttendance.cs @@ -77,5 +77,17 @@ namespace SlnMesnac.Model.domain /// [SugarColumn(ColumnName = "update_time")] public string UpdateTime { get; set; } + + /// + /// 机台编号 + /// + [SugarColumn(ColumnName = "machine_code")] + public string MachineCode { get; set; } + + /// + /// 工位编号 + /// + [SugarColumn(ColumnName = "station_code")] + public string StationCode { get; set; } } } diff --git a/SlnMesnac.Model/domain/RecordStaffRealTime.cs b/SlnMesnac.Model/domain/RecordStaffRealTime.cs new file mode 100644 index 0000000..91a5a7e --- /dev/null +++ b/SlnMesnac.Model/domain/RecordStaffRealTime.cs @@ -0,0 +1,92 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; + +namespace SlnMesnac.Model.domain +{ + [SugarTable("record_staff_real_time"), TenantAttribute("mes")] + [DataContract(Name = "RecordStaffRealTime 员工实时打卡记录")] + public class RecordStaffRealTime + { + /// + /// + /// + [SugarColumn(ColumnName = "obj_id", IsPrimaryKey = true, IsIdentity = true)] + public int ObjId { get; set; } + + /// + /// 员工id + /// + [SugarColumn(ColumnName = "staff_id")] + public string StaffId { get; set; } + + /// + /// 打卡类型 + /// + [SugarColumn(ColumnName = "attendance_type")] + public string AttendanceType { get; set; } + + /// + /// 班组编号 + /// + [SugarColumn(ColumnName = "team_code")] + public string TeamCode { get; set; } + + /// + /// 班次 + /// + [SugarColumn(ColumnName = "classes")] + public string Classes { get; set; } + + /// + /// 备注 + /// + [SugarColumn(ColumnName = "remark")] + public string Remark { get; set; } + + /// + /// 是否标识 + /// + [SugarColumn(ColumnName = "is_flag")] + public string IsFlag { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "create_by")] + public string CreateBy { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "create_time")] + public string CreateTime { get; set; } + + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "update_by")] + public string UpdateBy { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "update_time")] + public string UpdateTime { get; set; } + + /// + /// 机台编号 + /// + [SugarColumn(ColumnName = "machine_code")] + public string MachineCode { get; set; } + + /// + /// 工位编号 + /// + [SugarColumn(ColumnName = "station_code")] + public string StationCode { get; set; } + } +} diff --git a/SlnMesnac.Repository/service/IBaseStaffService.cs b/SlnMesnac.Repository/service/IBaseStaffService.cs index 0a6b049..04aa696 100644 --- a/SlnMesnac.Repository/service/IBaseStaffService.cs +++ b/SlnMesnac.Repository/service/IBaseStaffService.cs @@ -22,6 +22,13 @@ namespace SlnMesnac.Repository.service /// BaseStaffInfo GetStaffInfoByCardId(string cardId); + /// + /// 通过员工号获取员工信息 + /// + /// + /// + BaseStaffInfo GetStaffInfoByStaffId(string staffId); + /// /// 找出班组的班长 /// diff --git a/SlnMesnac.Repository/service/IRecordStaffAttendanceService.cs b/SlnMesnac.Repository/service/IRecordStaffAttendanceService.cs index 06dde45..85ac13f 100644 --- a/SlnMesnac.Repository/service/IRecordStaffAttendanceService.cs +++ b/SlnMesnac.Repository/service/IRecordStaffAttendanceService.cs @@ -12,14 +12,14 @@ namespace SlnMesnac.Repository.service /// 获取记录员工打卡信息 /// /// - List GetRecordStaffAttendances(); + List GetRecordStaffAttendances(string stationCode); /// /// 根据员工id查询 /// /// /// - RecordStaffAttendance GetRecordStaffAttendanceByStaffId(string staffId); + RecordStaffAttendance GetRecordStaffAttendanceByStaffId(string staffId,string stationCode); /// /// 验证添加员工打卡记录 diff --git a/SlnMesnac.Repository/service/IRecordStaffRealTimeService.cs b/SlnMesnac.Repository/service/IRecordStaffRealTimeService.cs new file mode 100644 index 0000000..3bd85a4 --- /dev/null +++ b/SlnMesnac.Repository/service/IRecordStaffRealTimeService.cs @@ -0,0 +1,18 @@ +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Repository.service +{ + public interface IRecordStaffRealTimeService : IBaseService + { + /// + /// 获取指定工位的实时打卡记录 + /// + /// + /// + List GetRecordStaffRealTime(string stationCode); + } +} diff --git a/SlnMesnac.Repository/service/Impl/BaseStaffServiceImpl.cs b/SlnMesnac.Repository/service/Impl/BaseStaffServiceImpl.cs index d49c425..b745d05 100644 --- a/SlnMesnac.Repository/service/Impl/BaseStaffServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/BaseStaffServiceImpl.cs @@ -48,6 +48,20 @@ namespace SlnMesnac.Repository.service.Impl return staffInfo; } + public BaseStaffInfo GetStaffInfoByStaffId(string staffId) + { + BaseStaffInfo staffInfo = null; + try + { + staffInfo = base._rep.GetFirst(x => x.StaffId == staffId); + } + catch (Exception ex) + { + _logger.LogError($"根据卡号获取员工信息异常:{ex.Message}"); + } + return staffInfo; + } + /// /// 获取所有的员工信息 /// diff --git a/SlnMesnac.Repository/service/Impl/ProdOrderInfoServiceImpl.cs b/SlnMesnac.Repository/service/Impl/ProdOrderInfoServiceImpl.cs new file mode 100644 index 0000000..49b95eb --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/ProdOrderInfoServiceImpl.cs @@ -0,0 +1,39 @@ +using Microsoft.Extensions.Logging; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SlnMesnac.Repository.service.Impl +{ + public class ProdOrderInfoServiceImpl : BaseServiceImpl, ProdOrderInfoService + { + private ILogger _logger; + public ProdOrderInfoServiceImpl(Repository rep, ILogger logger) : base(rep) + { + _logger = logger; + } + + /// + /// 根据订单号查询订单信息 + /// + /// + /// + /// + public ProdOrderInfo GetProdOrderInfoByOrderCode(string orderCode) + { + ProdOrderInfo prodOrderInfo = new ProdOrderInfo(); + try + { + prodOrderInfo = _rep.GetFirst(x => x.OrderCode == orderCode); + } + catch (Exception ex) + { + _logger.LogError($"根据订单号查询订单信息异常{ex.Message}"); + } + return prodOrderInfo; + } + } +} diff --git a/SlnMesnac.Repository/service/Impl/ProdPlanExecuteUserServiceImpl.cs b/SlnMesnac.Repository/service/Impl/ProdPlanExecuteUserServiceImpl.cs new file mode 100644 index 0000000..83d767d --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/ProdPlanExecuteUserServiceImpl.cs @@ -0,0 +1,18 @@ +using Microsoft.Extensions.Logging; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Repository.service.Impl +{ + public class ProdPlanExecuteUserServiceImpl: BaseServiceImpl, ProdPlanExecuteUserService + { + private ILogger _logger; + public ProdPlanExecuteUserServiceImpl(Repository repository, ILogger logger) : base(repository) + { + _logger = logger; + } + } +} diff --git a/SlnMesnac.Repository/service/Impl/ProdPlanInfoServiceImpl.cs b/SlnMesnac.Repository/service/Impl/ProdPlanInfoServiceImpl.cs index 3fafdfc..642e647 100644 --- a/SlnMesnac.Repository/service/Impl/ProdPlanInfoServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/ProdPlanInfoServiceImpl.cs @@ -26,14 +26,15 @@ namespace SlnMesnac.Repository.service.Impl /// /// /// - public List GetRecordStaffAttendancesByConditions(string? orderCode, string? planCode, string? materialCode, string? stationCode,string? planStatus) + public List GetRecordStaffAttendancesByConditions(string? orderCode, string? planCode, string? materialCode, string? stationCode, string? planStatus) { List recordStaffAttendances = new List(); List planInfoList = _rep.AsQueryable().WhereIF(!string.IsNullOrEmpty(orderCode), x => x.OrderCode == orderCode) .WhereIF(!string.IsNullOrEmpty(planCode), x => x.PlanCode == planCode) .WhereIF(!string.IsNullOrEmpty(materialCode), x => x.MaterialCode == materialCode) .WhereIF(!string.IsNullOrEmpty(stationCode), x => x.StationCode == stationCode) - .WhereIF(!string.IsNullOrEmpty(planStatus),x => x.PlanStatus == planStatus) + .WhereIF(!string.IsNullOrEmpty(planStatus), x => x.PlanStatus == planStatus || x.PlanStatus == "4") + .OrderByDescending(x => x.ObjId) .ToList(); return planInfoList; } @@ -52,5 +53,53 @@ namespace SlnMesnac.Repository.service.Impl } return pLanInfos; } + + /// + /// 根据工单号获取此工单 + /// + /// + /// + /// + public ProdPLanInfo GetProdPLanInfoByOrderCode(string stationCode, string orderCode) + { + ProdPLanInfo prodPLan = new ProdPLanInfo(); + try + { + prodPLan = _rep.GetFirst(x => x.OrderCode == orderCode && x.StationCode == stationCode); + } + catch (Exception ex) + { + _logger.LogError($"根据工单号获取此工单异常{ex.Message}"); + } + return prodPLan; + } + + /// + /// 更新工单状态 + /// + /// + /// + /// + /// + /// + /// + public bool UpdatePlanStatus(string orderCode, string stationCode, string deviceCode, string processCode, string status) + { + bool result = false; + try + { + var planInfo = _rep.GetFirst(x => x.OrderCode == orderCode && x.StationCode == stationCode && x.DeviceCode == deviceCode && x.ProcessCode == processCode); + if (planInfo != null) + { + planInfo.PlanStatus = status; + result = _rep.Update(planInfo); + } + } + catch (Exception ex) + { + _logger.LogError($"修改计划状态异常:{ex.Message}"); + } + return result; + } } } diff --git a/SlnMesnac.Repository/service/Impl/RecordStaffAttendanceServiceImpl.cs b/SlnMesnac.Repository/service/Impl/RecordStaffAttendanceServiceImpl.cs index b5924bd..82fb053 100644 --- a/SlnMesnac.Repository/service/Impl/RecordStaffAttendanceServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/RecordStaffAttendanceServiceImpl.cs @@ -17,12 +17,18 @@ namespace SlnMesnac.Repository.service.Impl _logger = logger; } - public List GetRecordStaffAttendances() + /// + /// 获取员工上班打卡信息 + /// + /// + /// + /// + public List GetRecordStaffAttendances(string stationCode) { List records = null; try { - records = base._rep.GetList(); + records = base._rep.GetList(x=>x.StationCode == stationCode && x.AttendanceType == "0"); records = records.OrderByDescending(x => x.CreateTime).Take(20).ToList(); } catch (Exception ex) @@ -32,9 +38,11 @@ namespace SlnMesnac.Repository.service.Impl return records; } - public RecordStaffAttendance GetRecordStaffAttendanceByStaffId(string staffId) + public RecordStaffAttendance GetRecordStaffAttendanceByStaffId(string staffId,string stationCode) { - RecordStaffAttendance recordStaffAttendances = _rep.AsQueryable().Where(x => x.StaffId == staffId).OrderByDescending(x => x.CreateTime).First(); + RecordStaffAttendance recordStaffAttendances = _rep.AsQueryable().Where(x => x.StaffId == staffId) + .Where(x => x.StationCode == stationCode) + .OrderByDescending(x => x.CreateTime).First(); if (recordStaffAttendances != null) { return recordStaffAttendances; diff --git a/SlnMesnac.Repository/service/Impl/RecordStaffRealTimeServiceImpl.cs b/SlnMesnac.Repository/service/Impl/RecordStaffRealTimeServiceImpl.cs new file mode 100644 index 0000000..f7b3a48 --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/RecordStaffRealTimeServiceImpl.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.Logging; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SlnMesnac.Repository.service.Impl +{ + public class RecordStaffRealTimeServiceImpl : BaseServiceImpl, IRecordStaffRealTimeService + { + private readonly ILogger _logger; + + public RecordStaffRealTimeServiceImpl(Repository rep, ILogger logger) : base(rep) + { + _logger = logger; + } + + /// + /// 获取指定工位的实时打卡记录 + /// + /// + /// + /// + public List GetRecordStaffRealTime(string stationCode) + { + List records = null; + try + { + records = base._rep.GetList(x => x.StationCode == stationCode && x.AttendanceType == "0"); + records = records.OrderByDescending(x => x.CreateTime).Take(20).ToList(); + } + catch (Exception ex) + { + _logger.LogError($"获取员工实时打卡记录异常{ex.Message}"); + } + return records; + } + } +} diff --git a/SlnMesnac.Repository/service/ProdOrderInfoService.cs b/SlnMesnac.Repository/service/ProdOrderInfoService.cs new file mode 100644 index 0000000..04cbe30 --- /dev/null +++ b/SlnMesnac.Repository/service/ProdOrderInfoService.cs @@ -0,0 +1,13 @@ +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Repository.service +{ + public interface ProdOrderInfoService : IBaseService + { + ProdOrderInfo GetProdOrderInfoByOrderCode(string orderCode); + } +} diff --git a/SlnMesnac.Repository/service/ProdPlanExecuteUserService.cs b/SlnMesnac.Repository/service/ProdPlanExecuteUserService.cs new file mode 100644 index 0000000..be566c9 --- /dev/null +++ b/SlnMesnac.Repository/service/ProdPlanExecuteUserService.cs @@ -0,0 +1,12 @@ +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Repository.service +{ + public interface ProdPlanExecuteUserService: IBaseService + { + } +} diff --git a/SlnMesnac.Repository/service/ProdPlanInfoService.cs b/SlnMesnac.Repository/service/ProdPlanInfoService.cs index e54044b..48ba22e 100644 --- a/SlnMesnac.Repository/service/ProdPlanInfoService.cs +++ b/SlnMesnac.Repository/service/ProdPlanInfoService.cs @@ -19,5 +19,22 @@ namespace SlnMesnac.Repository.service /// /// List GetRecordStaffAttendancesByConditions(string orderCode,string planCode,string materialCode, string stationCode, string planStatus); + + /// + /// 根据工单编号获取此工单 + /// + /// + /// + ProdPLanInfo GetProdPLanInfoByOrderCode(string stationCode,string planCode); + + /// + /// 更新工单状态 + /// + /// + /// + /// + /// + /// + public bool UpdatePlanStatus(string orderCode, string stationCode, string deviceCode, string processCode, string status); } } diff --git a/SlnMesnac.Repository/service/base/BaseServiceImpl.cs b/SlnMesnac.Repository/service/base/BaseServiceImpl.cs index 2227110..33dde69 100644 --- a/SlnMesnac.Repository/service/base/BaseServiceImpl.cs +++ b/SlnMesnac.Repository/service/base/BaseServiceImpl.cs @@ -128,7 +128,7 @@ namespace SlnMesnac.Repository.service.@base } try { - return _rep.DeleteById(model); + return _rep.Delete(model); } catch (Exception ex) { diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml index 6363af9..434c7ea 100644 --- a/SlnMesnac.WPF/MainWindow.xaml +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -48,8 +48,9 @@ - - + + + + + + diff --git a/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs b/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs index cb87e22..aed6269 100644 --- a/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs @@ -10,6 +10,7 @@ using SlnMesnac.Model.domain; using SlnMesnac.Model.dto; using SlnMesnac.Repository.service; using SlnMesnac.Repository.service.Impl; +using SlnMesnac.WPF.Views; using SqlSugar; using System; using System.Collections.Generic; @@ -19,6 +20,7 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; +using System.Windows; using System.Windows.Input; using static Microsoft.WindowsAPICodePack.Shell.PropertySystem.SystemProperties.System; @@ -34,6 +36,7 @@ namespace SlnMesnac.WPF.ViewModel private string _checkInButtonText = "上班打卡"; private string _checkOutButtonText = "下班打卡"; public string _isCheckInButtonEnabled; + public string _isRemoveButtonEnabled; private string _isCheckOutButtonEnabled; private string _checkInButtonColor; private string _checkOutButtonColor = "#009999"; @@ -44,6 +47,7 @@ namespace SlnMesnac.WPF.ViewModel public static bool isOnDuty = false;//是否有班组当班 private List uniqueStrings = new List(); private List timestamps = new List(); + private BaseStaffInfo user; /// /// 按钮文字转换事件 @@ -64,12 +68,19 @@ namespace SlnMesnac.WPF.ViewModel /// public ICommand OverCommand { get; private set; } + /// + /// 删除命令 + /// + public ICommand RemoveCommand { get; private set; } + /// /// /// /// - public delegate void TransmitUser(BaseStaffInfo staffInfo); + public delegate void TransmitUser(); public static event TransmitUser TransmitUserDelegateEvent; + + public static Action? _transmitToRemoveConfigAction; #endregion public EmployeeLoginViewModel() @@ -77,6 +88,7 @@ namespace SlnMesnac.WPF.ViewModel hidUtils = new HidUtils(); CheckInCommand = new RelayCommand(CheckIn); CheckOutCommand = new RelayCommand(CheckOut); + RemoveCommand = new RelayCommand(Remove); OverCommand = new RelayCommand(Over); baseStaffService = App.ServiceProvider.GetService(); _recordStaffAttendanceService = App.ServiceProvider.GetService(); @@ -90,102 +102,146 @@ namespace SlnMesnac.WPF.ViewModel Init(); } + + /// + /// 主动移除 + /// + private void Remove(string staffId) + { + MainWindowViewModel.wins = 2; + if (isUse == false) + { + var removeConfirmWin = new RemoveConfirmWin(); + removeConfirmWin.Owner = Application.Current.MainWindow; + removeConfirmWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; + removeConfirmWin.ShowDialog(); + if (RemoveConfirmViewModel.times == 1) + { + var theUser = baseStaffService.GetStaffInfoByStaffId(staffId); + _rfidHandleBusniess.HandleAndInsertStaffAttendance(theUser, 2); + var list = _rfidHandleBusniess.HandleAndInsertStaffRealTime(theUser, 2); + System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => + { + RecordStaffRealTimeDataGrid.Clear(); + list.ForEach(item => { RecordStaffRealTimeDataGrid.Add(item); }); + })); + } + EmployeeLoginViewModel._transmitToRemoveConfigAction -= _transmitToRemoveConfigAction; + } + else + { + MessageBox.Show("正在打卡不能强退!"); + } + } private void Init() { hidUtils.Initial(); hidUtils.pushReceiveDataEvent += (bytes, str) => { - string cleanStr = str.ToString().Replace(" ", ""); - StatusText = StaffIdText = CheckStatus = null; - if (!IsDuplicate(cleanStr))//过滤重复str + if (MainWindowViewModel.wins == 1) { - uniqueStrings.Add(cleanStr); - timestamps.Add(DateTime.Now); - // Additional logic for processing the unique string goes here - if (isUse) + string cleanStr = str.ToString().Replace(" ", ""); + StatusText = StaffIdText = CheckStatus = null; + if (!IsDuplicate(cleanStr))//过滤重复str { - BaseStaffInfo user = baseStaffService.GetStaffInfoByCardId(cleanStr); - if (user != null) + uniqueStrings.Add(cleanStr); + timestamps.Add(DateTime.Now); + // Additional logic for processing the unique string goes here + if (isUse) { - RecordStaffAttendance recordStaffAttendance = _recordStaffAttendanceService.GetRecordStaffAttendanceByStaffId(user.StaffId); - if (recordStaffAttendance != null) + user = baseStaffService.GetStaffInfoByCardId(cleanStr); + if (user != null) { - var createTime = recordStaffAttendance.CreateTime; - var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - TimeSpan timeDiff = DateTime.Parse(nowTime) - DateTime.Parse(createTime); - if (timeDiff.TotalHours >= 10)// + RecordStaffAttendance recordStaffAttendance = _recordStaffAttendanceService.GetRecordStaffAttendanceByStaffId(user.StaffId, RfidHandleBusniess.stationCode); + if (recordStaffAttendance != null) { - if (recordStaffAttendance.AttendanceType == "1") //下班卡 + var createTime = recordStaffAttendance.CreateTime; + var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + TimeSpan timeDiff = DateTime.Parse(nowTime) - DateTime.Parse(createTime); + if (timeDiff.TotalHours >= 10)// { - if (recordStaffAttendance.AttendanceType == status.ToString()) + if (recordStaffAttendance.AttendanceType == "1") //下班卡 { - StatusText = "未打上班卡,请联系管理员!"; + if (recordStaffAttendance.AttendanceType == status.ToString() || recordStaffAttendance.AttendanceType == "2") + { + StatusText = "未打上班卡,请联系管理员!"; + } } - } - else if (recordStaffAttendance.AttendanceType == "0") - { - if (recordStaffAttendance.AttendanceType == status.ToString()) + else if (recordStaffAttendance.AttendanceType == "0") { - StatusText = "未打下班卡,请联系管理员!"; + if (recordStaffAttendance.AttendanceType == status.ToString()) + { + StatusText = "未打下班卡,请联系管理员!"; + } } - } - StaffIdText = user.StaffId; - CheckStatus = user.StaffName + " " + user.TeamCode + " 打卡成功!"; - var list = _rfidHandleBusniess.HandleAndInsertStaffAttendance(user, isCheckOn); - System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => - { - RecordStaffAttendanceDataGrid.Clear(); - list.ForEach(item => { RecordStaffAttendanceDataGrid.Add(item); }); - })); - _rfidHandleBusniess.HandleStaffCommute(user, isCheckOn); - } - else - { - if (recordStaffAttendance.AttendanceType != status.ToString()) - { StaffIdText = user.StaffId; CheckStatus = user.StaffName + " " + user.TeamCode + " 打卡成功!"; - var list = _rfidHandleBusniess.HandleAndInsertStaffAttendance(user, isCheckOn); + _rfidHandleBusniess.HandleAndInsertStaffAttendance(user, isCheckOn); + var list = _rfidHandleBusniess.HandleAndInsertStaffRealTime(user, isCheckOn); System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => { - RecordStaffAttendanceDataGrid.Clear(); - list.ForEach(item => { RecordStaffAttendanceDataGrid.Add(item); }); + RecordStaffRealTimeDataGrid.Clear(); + list.ForEach(item => { RecordStaffRealTimeDataGrid.Add(item); }); })); _rfidHandleBusniess.HandleStaffCommute(user, isCheckOn); } else { - StatusText = "请勿重复打卡!"; + if (recordStaffAttendance.AttendanceType != status.ToString()) + { + StaffIdText = user.StaffId; + CheckStatus = user.StaffName + " " + user.TeamCode + " 打卡成功!"; + _rfidHandleBusniess.HandleAndInsertStaffAttendance(user, isCheckOn); + var list = _rfidHandleBusniess.HandleAndInsertStaffRealTime(user, isCheckOn); + System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => + { + RecordStaffRealTimeDataGrid.Clear(); + list.ForEach(item => { RecordStaffRealTimeDataGrid.Add(item); }); + })); + _rfidHandleBusniess.HandleStaffCommute(user, isCheckOn); + } + else + { + StatusText = "请勿重复打卡!"; + } } - } + } + else + { + StaffIdText = user.StaffId; + CheckStatus = "打卡成功!"; + _rfidHandleBusniess.HandleAndInsertStaffAttendance(user, isCheckOn); + var list = _rfidHandleBusniess.HandleAndInsertStaffRealTime(user, isCheckOn); + System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => + { + RecordStaffRealTimeDataGrid.Clear(); + list.ForEach(item => { RecordStaffRealTimeDataGrid.Add(item); }); + })); + _rfidHandleBusniess.HandleStaffCommute(user, isCheckOn); + } } else { - StaffIdText = user.StaffId; - CheckStatus = "打卡成功!"; - var list = _rfidHandleBusniess.HandleAndInsertStaffAttendance(user, isCheckOn); - System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => - { - RecordStaffAttendanceDataGrid.Clear(); - list.ForEach(item => { RecordStaffAttendanceDataGrid.Add(item); }); - })); - _rfidHandleBusniess.HandleStaffCommute(user, isCheckOn); + StaffIdText = "未配置"; + CheckStatus = "没有匹配的员工,打卡失败!"; } } - else - { - StaffIdText = "未配置"; - CheckStatus = "没有匹配的员工,打卡失败!"; - } - TransmitUserDelegateEvent?.Invoke(user); + } + else + { + StaffIdText = "已打卡,请勿重复!"; } } - else + else if (MainWindowViewModel.wins == 2) { - StaffIdText = "已打卡,请勿重复!"; + _transmitToRemoveConfigAction(str); } - }; + else if (MainWindowViewModel.wins == 3) + { + + } + }; } public HidUtils getHidUtil() @@ -308,12 +364,12 @@ namespace SlnMesnac.WPF.ViewModel /// /// DataGrid /// - private ObservableCollection recordStaffAttendanceDataGrid = new ObservableCollection(); + private ObservableCollection recordStaffRealTimeDataGrid = new ObservableCollection(); - public ObservableCollection RecordStaffAttendanceDataGrid + public ObservableCollection RecordStaffRealTimeDataGrid { - get { return recordStaffAttendanceDataGrid; } - set { recordStaffAttendanceDataGrid = value; OnPropertyChanged("RecordStaffAttendanceDataGrid"); } + get { return recordStaffRealTimeDataGrid; } + set { recordStaffRealTimeDataGrid = value; OnPropertyChanged("RecordStaffRealTimeDataGrid"); } } #endregion @@ -341,6 +397,7 @@ namespace SlnMesnac.WPF.ViewModel CheckInButtonText = "上班打卡"; IsCheckOutButtonEnabled = "True"; // Enable CheckOutButton CheckOutButtonColor = "#009999"; + TransmitUserDelegateEvent?.Invoke(); hidUtils.StopScan(); isCheckOn = 1; isUse = false; @@ -359,7 +416,7 @@ namespace SlnMesnac.WPF.ViewModel isCheckOn = 1; isUse = true; status = 1; - CheckOutButtonText = "结束打卡"; + CheckOutButtonText = "结束打卡"; IsCheckInButtonEnabled = "False"; // Disable CheckInButton CheckInButtonColor = "Gray"; hidUtils.StartScan(); diff --git a/SlnMesnac.WPF/ViewModel/ExecuteViewModel.cs b/SlnMesnac.WPF/ViewModel/ExecuteViewModel.cs index ee61f86..099bc99 100644 --- a/SlnMesnac.WPF/ViewModel/ExecuteViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/ExecuteViewModel.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components.Forms; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Protocols; +using SlnMesnac.Business; using SlnMesnac.Business.business; using SlnMesnac.Model.domain; using SlnMesnac.Model.dto; @@ -32,20 +33,22 @@ namespace SlnMesnac.WPF.ViewModel public ObservableCollection PlanCodeComboBoxItems { get; set; } public ObservableCollection MaterialNameComboBoxItems { get; set; } private RfidHandleBusniess _RfidHandleBusniess; + private DatabaseHandleBusniess _databaseHandleBusniess; private ProdPlanInfoService _prodPlanInfoService; private List prodPlanInfos; private ProdPlanDetailService _prodPlanDetailService; private IRecordStaffAttendanceService _recordStaffAttendanceService; private IBaseStaffService _baseStaffService; private string StationCode; + private string DeviceCode; + private string ProcessCode; public static bool isComplete = true; private ProdPLanInfo pLanInfo; + private SerialPortBusiness _serialPortBusiness; + private string executeText = "待执行"; + private int isSearch = 0; - /// - /// 按钮文字转换事件 - /// - public event PropertyChangedEventHandler PropertyChanged = delegate { }; - + #region 定义命令 /// /// 检索命令 /// @@ -70,171 +73,19 @@ namespace SlnMesnac.WPF.ViewModel /// 执行命令 /// public ICommand ExecuteCommand { get; private set; } - - #region 委托 - public delegate void RefreshDelegate(ProdPLanInfo pLanInfo); - public static event RefreshDelegate? RefreshEvent; #endregion - public ExecuteViewModel() - { - _prodPlanInfoService = App.ServiceProvider.GetService(); - _prodPlanDetailService = App.ServiceProvider.GetService(); - _recordStaffAttendanceService = App.ServiceProvider.GetService(); - _RfidHandleBusniess = App.ServiceProvider.GetService(); - _baseStaffService = App.ServiceProvider.GetService(); - IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() - .SetBasePath(System.AppContext.BaseDirectory) - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); - IConfigurationRoot configuration = configurationBuilder.Build(); - pLanInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions("", "", "", "", "1").FirstOrDefault(); - Refresh(pLanInfo); - // 从配置文件中获取ProductLineNameTextBlock的值 - stationTextBlock = configuration.GetSection("AppConfig")["ProductLineName"]; - StationCode = configuration.GetSection("AppConfig")["ProductLineCode"]; - HandoverCommand = new RelayCommand(Handover); - ProductionReportCommand = new RelayCommand(ProductionReport); - TechnologicalInformationCommand = new RelayCommand(TechnologicalInformation); - SearchCommand = new RelayCommand(Search); - ExecuteCommand = new RelayCommand(Execute); - ProductionReportViewModel.RefreshDelegateEvent += Refresh; - EmployeeLoginViewModel.TransmitUserDelegateEvent += ShowTeamMember; - } + #region 定义委托 + public delegate void RefreshDelegate(ProdPLanInfo pLanInfo); + public static event RefreshDelegate? RefreshEvent; /// - /// 换班弹窗 + /// 按钮文字转换事件 /// - private void Handover() - { - var handOverWin = new HandOverWin(); - handOverWin.Owner = Application.Current.MainWindow; // 设置父窗口为当前主窗口 - handOverWin.WindowStartupLocation = WindowStartupLocation.CenterScreen; // 让窗体出现在屏幕中央 - handOverWin.ShowDialog();//窗体出现后禁止后面的用户控件 - - } + public event PropertyChangedEventHandler PropertyChanged = delegate { }; + #endregion - /// - /// 报工弹窗 - /// - private void ProductionReport() - { - var reportWin = new ProductionReportWin(); - reportWin.Owner = Application.Current.MainWindow; // 设置父窗口为当前主窗口 - reportWin.WindowStartupLocation = WindowStartupLocation.CenterScreen; // 让窗体出现在屏幕中央 - reportWin.ShowDialog();//窗体出现后禁止后面的用户控件 - } - - /// - /// 工艺信息弹窗,单例模式保证只显示一个 - /// - private static TechnologicalWin instance; - private void TechnologicalInformation() - { - if (instance == null) - { - instance = new TechnologicalWin(); - instance.WindowStartupLocation = WindowStartupLocation.CenterScreen; - instance.Closed += (sender, e) => { instance = null; }; // 窗口关闭时重置instance为null,以便下次可以重新打开窗口 - instance.Show(); - } - else - { - instance.Focus(); // 如果窗口已经存在,则将焦点放在该窗口上 - } - } - - - /// - /// 检索事件 - /// - private void Search() - { - // 在这里执行其他操作,可以通过InputText获取用户输入的信息 - //Console.WriteLine("用户输入的信息:" + OrderCodeTextBox + PlanCodeTextBox + MaterialCodeTextBox); - //ProductLineNameTextBlock = ConfigurationManager.AppSettings["ProductLineNameTextBlock"]; - List list = _prodPlanInfoService.GetRecordStaffAttendancesByConditions(OrderCodeTextBox, PlanCodeTextBox, MaterialCodeTextBox, StationCode,"0"); - System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => - { - ProdPLanInfoDataGrid.Clear(); - list.ForEach(item => - { - ProdPLanInfoDataGrid.Add(item); - }); - })); - } - - /// - /// 新增的执行事件 - /// - private void Execute() - { - //判断是否有班组当班,查询打卡记录表,4小时内最后一次打卡类型为上班的班组 - if(EmployeeLoginViewModel.isOnDuty == true) - { - if (isComplete)//判断是否完成,未完成不能执行其他工单 - { - // 将当前记录存为实体,可以通过parameter获取当前记录的信息 - string orderCode = _selectedRow.OrderCode.ToString(); - string planCode = _selectedRow.PlanCode.ToString(); - pLanInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions(orderCode, planCode, "", "", "0").First(); - RecordStaffAttendance currentRecord = _recordStaffAttendanceService.GetLastestOnRecord(); - BaseStaffInfo staffInfo = _baseStaffService.GetMonitorByTeamCode(currentRecord.TeamCode); - RecordStaffAttendance nextRecord = _recordStaffAttendanceService.GetLastestOffRecord(); - // 向detail表里插入一条数据 - ProdPlanDetail prodPlanDetail = new ProdPlanDetail - { - PlanCode = pLanInfo.PlanCode, - MaterialCode = pLanInfo.MaterialCode, - PlanAmount = pLanInfo.PlanAmount, - CompleteAmount = pLanInfo.CompleteAmount, - BeginTime = DateTime.Now.ToString(), - CurrentStaffId = staffInfo.StaffId - //NextStaffId = nextRecord.StaffId, - }; - _prodPlanDetailService.Insert(prodPlanDetail); - //按钮文字变成执行中并锁定,其他的订单执行按钮也禁用 - pLanInfo.BeginTime = DateTime.Now.ToString(); - pLanInfo.PlanStatus = "1"; - _prodPlanInfoService.Update(pLanInfo); - Search(); - //查明细表显示出来 - Refresh(pLanInfo); - isComplete = false; - } - } - } - - //刷新明细 - private void Refresh(ProdPLanInfo pLanInfo) - { - if(pLanInfo != null) - { - ProdPlanDetail planDetail = _prodPlanDetailService.GetPlanDetailsByPlanCode(pLanInfo.PlanCode); - PlanCodeText = planDetail.PlanCode; - OrderCodeText = pLanInfo.OrderCode; - MaterialCodeText = planDetail.MaterialCode; - StationCodeText = pLanInfo.StationCode; - System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => - { - ProdPLanDetailDataGrid.Clear(); - ProdPLanDetailDataGrid.Add(planDetail); - })); - } - } - - /// - /// 显示班组成员 - /// - /// - private void ShowTeamMember(BaseStaffInfo baseStaffInfo) - { - if(baseStaffInfo != null) - { - TeamMember = _RfidHandleBusniess.SpliceTeamMember(baseStaffInfo); - } - } - - #region + #region 定义属性 /// /// 班组成员 /// @@ -359,6 +210,216 @@ namespace SlnMesnac.WPF.ViewModel } #endregion + public ExecuteViewModel() + { + _prodPlanInfoService = App.ServiceProvider.GetService(); + _prodPlanDetailService = App.ServiceProvider.GetService(); + _recordStaffAttendanceService = App.ServiceProvider.GetService(); + _RfidHandleBusniess = App.ServiceProvider.GetService(); + _baseStaffService = App.ServiceProvider.GetService(); + _serialPortBusiness = App.ServiceProvider.GetService(); + _databaseHandleBusniess = App.ServiceProvider.GetService(); + IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() + .SetBasePath(System.AppContext.BaseDirectory) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); + IConfigurationRoot configuration = configurationBuilder.Build(); + pLanInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions("", "", "", "", "1").FirstOrDefault(); + Refresh(pLanInfo); + // 从配置文件中获取ProductLineNameTextBlock的值 + stationTextBlock = configuration.GetSection("AppConfig")["ProductLineName"]; + StationCode = configuration.GetSection("AppConfig")["StationCode"]; + RfidHandleBusniess.stationCode = StationCode; + DeviceCode = configuration.GetSection("AppConfig")["DeviceCode"]; + ProcessCode = configuration.GetSection("AppConfig")["ProcessCode"]; + HandoverCommand = new RelayCommand(Handover); + ProductionReportCommand = new RelayCommand(ProductionReport); + TechnologicalInformationCommand = new RelayCommand(TechnologicalInformation); + SearchCommand = new RelayCommand(Search); + ExecuteCommand = new RelayCommand(Execute); + ProductionReportViewModel.RefreshDelegateEvent += Refresh; + EmployeeLoginViewModel.TransmitUserDelegateEvent += ShowTeamMember; + //SerialPortBusiness.ReceivedBarcodeInfoEvent += HandleOrderCode; + MainWindowViewModel.TransferOrderCodeEvent += HandleOrderCode; + } + + /// + /// 换班弹窗 + /// + private void Handover() + { + var handOverWin = new HandOverWin(); + handOverWin.Owner = Application.Current.MainWindow; // 设置父窗口为当前主窗口 + handOverWin.WindowStartupLocation = WindowStartupLocation.CenterScreen; // 让窗体出现在屏幕中央 + handOverWin.ShowDialog();//窗体出现后禁止后面的用户控件 + } + + /// + /// 报工弹窗 + /// + private void ProductionReport() + { + MainWindowViewModel.wins = 3; + var reportWin = new ProductionReportWin(); + reportWin.Owner = Application.Current.MainWindow; // 设置父窗口为当前主窗口 + reportWin.WindowStartupLocation = WindowStartupLocation.CenterScreen; // 让窗体出现在屏幕中央 + reportWin.ShowDialog();//窗体出现后禁止后面的用户控件 + } + + /// + /// 工艺信息弹窗,单例模式保证只显示一个 + /// + private static TechnologicalWin instance; + private void TechnologicalInformation() + { + if (instance == null) + { + instance = new TechnologicalWin(); + instance.WindowStartupLocation = WindowStartupLocation.CenterScreen; + instance.Closed += (sender, e) => { instance = null; }; // 窗口关闭时重置instance为null,以便下次可以重新打开窗口 + instance.Show(); + } + else + { + instance.Focus(); // 如果窗口已经存在,则将焦点放在该窗口上 + } + } + + + /// + /// 检索事件 + /// + private void Search() + { + if (EmployeeLoginViewModel.isOnDuty == true) + { + //在这里执行其他操作,可以通过InputText获取用户输入的信息 + //Console.WriteLine("用户输入的信息:" + OrderCodeTextBox + PlanCodeTextBox + MaterialCodeTextBox); + //ProductLineNameTextBlock = ConfigurationManager.AppSettings["ProductLineNameTextBlock"]; + List list = _prodPlanInfoService.GetRecordStaffAttendancesByConditions(OrderCodeTextBox, PlanCodeTextBox, MaterialCodeTextBox, StationCode, "0"); + System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => + { + ProdPLanInfoDataGrid.Clear(); + list.ForEach(item => + { + ProdPLanInfoDataGrid.Add(item); + }); + })); + isSearch = 1; + } + else + { + MessageBox.Show("没有班组上班,请先打卡上班!"); + } + } + + /// + /// 根据订单单号判断是否存在, + /// + private void HandleOrderCode(string orderCode) + { + if (isComplete) + { + if (isSearch == 1) + { + //判断当前工位的工单编号是否存在 + var plan = _prodPlanInfoService.GetProdPLanInfoByOrderCode(StationCode, orderCode); + if (plan == null)//不存在,就在生产工单表中新增一条当前工位的订单,且执行状态改为4,重新检索,并高亮这条工单,执行按钮可用 + { + _databaseHandleBusniess.AddNewPlanInfo(orderCode,StationCode,DeviceCode,ProcessCode,"0"); + } + else//存在,将本条数据的执行状态改为4高亮这条工单,执行按钮可用 + { + _databaseHandleBusniess.UpdatePlanStatus(orderCode,StationCode,DeviceCode,ProcessCode,"4"); + } + Search(); + } + else + { + MessageBox.Show("请先检索工单!"); + } + } + else + { + MessageBox.Show("请先完成当前工单!"); + } + } + + + /// + /// 新增的执行事件 + /// + private void Execute() + { + //判断是否有班组当班,查询打卡记录表,4小时内最后一次打卡类型为上班的班组 + if(EmployeeLoginViewModel.isOnDuty == true) + { + if (isComplete)//判断是否完成,未完成不能执行其他工单 + { + // 将当前记录存为实体,可以通过parameter获取当前记录的信息 + string orderCode = _selectedRow.OrderCode.ToString(); + string planCode = _selectedRow.PlanCode.ToString(); + pLanInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions(orderCode, planCode, "", "", "0").First(); + RecordStaffAttendance currentRecord = _recordStaffAttendanceService.GetLastestOnRecord(); + BaseStaffInfo staffInfo = _baseStaffService.GetMonitorByTeamCode(currentRecord.TeamCode); + RecordStaffAttendance nextRecord = _recordStaffAttendanceService.GetLastestOffRecord(); + // 向detail表里插入一条数据 + ProdPlanDetail prodPlanDetail = new ProdPlanDetail + { + PlanCode = pLanInfo.PlanCode, + MaterialCode = pLanInfo.MaterialCode, + PlanAmount = pLanInfo.PlanAmount, + CompleteAmount = pLanInfo.CompleteAmount, + BeginTime = DateTime.Now.ToString(), + CurrentStaffId = staffInfo.StaffId + //NextStaffId = nextRecord.StaffId, + }; + _prodPlanDetailService.Insert(prodPlanDetail); + //按钮文字变成执行中并锁定,其他的订单执行按钮也禁用 + pLanInfo.BeginTime = DateTime.Now.ToString(); + pLanInfo.PlanStatus = "1"; + _prodPlanInfoService.Update(pLanInfo); + Search(); + //查明细表显示出来 + Refresh(pLanInfo); + isComplete = false; + } + else + { + MessageBox.Show("请先完成当前工单!"); + } + } + } + + //刷新明细 + private void Refresh(ProdPLanInfo pLanInfo) + { + if(pLanInfo != null) + { + ProdPlanDetail planDetail = _prodPlanDetailService.GetPlanDetailsByPlanCode(pLanInfo.PlanCode); + if (planDetail != null) + { + PlanCodeText = planDetail.PlanCode; + OrderCodeText = pLanInfo.OrderCode; + MaterialCodeText = planDetail.MaterialCode; + StationCodeText = pLanInfo.StationCode; + System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => + { + ProdPLanDetailDataGrid.Clear(); + ProdPLanDetailDataGrid.Add(planDetail); + })); + } + } + } + + /// + /// 显示班组成员 + /// + /// + private void ShowTeamMember() + { + TeamMember = _RfidHandleBusniess.SpliceTeamMember(); + } + public void OnPropertyChanged([CallerMemberName] string propertyName = "") { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); diff --git a/SlnMesnac.WPF/ViewModel/HandOverViewModel.cs b/SlnMesnac.WPF/ViewModel/HandOverViewModel.cs index 5099de2..d9e6204 100644 --- a/SlnMesnac.WPF/ViewModel/HandOverViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/HandOverViewModel.cs @@ -44,6 +44,7 @@ namespace SlnMesnac.WPF.ViewModel HandoverCommand = new RelayCommand(Handover); Init(); _baseStaffService = App.ServiceProvider.GetService(); + } /// @@ -55,60 +56,62 @@ namespace SlnMesnac.WPF.ViewModel { planDetail = _prodPlanDetailService.GetPlanDetailsByPlanCode(planInfo.PlanCode); //_recordStaffAttendanceService.GetLastestOffRecord(); - PlanAmountText = planDetail.PlanAmount.ToString(); - CompleteAmountText = planDetail.CompleteAmount.ToString(); - var hidUtils = EmployeeLoginViewModel.hidUtils; + //PlanAmountText = planDetail.PlanAmount.ToString(); + //CompleteAmountText = planDetail.CompleteAmount.ToString(); //hidUtils.Initial(); - hidUtils.StartScan(); - hidUtils.pushReceiveDataEvent += (bytes, str) => - { - if (times < 2)//打卡超过2次无效 - { - str = str.ToString().Replace(" ", ""); - BaseStaffInfo user = _baseStaffService.GetStaffInfoByCardId(str); - if (user != null) - { - string staffType = user.StaffType; - if (staffType == "1")//判断是否为班长 - { - if (times == 0 && planDetail.CurrentStaffId == user.StaffId) - { - //显示记录 - StaffIdText = user.StaffId; - StaffNameText = user.StaffName; - StaffTypeText = user.StaffType; - TeamCodeText = user.TeamCode; - //数量+1 - times++; - } - else if (times == 1) - { - StaffIdText = user.StaffId; - //判断是否为下一班组长 - planDetail.CurrentStaffId = user.StaffId; - StaffNameText = user.StaffName; - StaffTypeText = user.StaffType; - TeamCodeText = user.TeamCode; - _prodPlanDetailService.Insert(planDetail);//更换班组长后插入一条明细记录 - //数量+1 - times++; - } - else - { - HintText = "当前班组长先打卡!"; - } - } - else - { - HintText = "打卡人员非班长,打卡无效!"; - } - } - else - { - HintText = "没有匹配的员工,打卡失败!"; - } - } - }; + //EmployeeLoginViewModel.hidUtils.StartScan(); + //EmployeeLoginViewModel.hidUtils.pushReceiveDataEvent += (bytes, str) => + //{ + // if (MainWindowViewModel.wins == 3) + // { + // if (times < 2)//打卡超过2次无效 + // { + // str = str.ToString().Replace(" ", ""); + // BaseStaffInfo user = _baseStaffService.GetStaffInfoByCardId(str); + // if (user != null) + // { + // string staffType = user.StaffType; + // if (staffType == "1")//判断是否为班长 + // { + // if (times == 0 && planDetail.CurrentStaffId == user.StaffId) + // { + // //显示记录 + // StaffIdText = user.StaffId; + // StaffNameText = user.StaffName; + // StaffTypeText = user.StaffType; + // TeamCodeText = user.TeamCode; + // //数量+1 + // times++; + // } + // else if (times == 1) + // { + // StaffIdText = user.StaffId; + // //判断是否为下一班组长 + // planDetail.CurrentStaffId = user.StaffId; + // StaffNameText = user.StaffName; + // StaffTypeText = user.StaffType; + // TeamCodeText = user.TeamCode; + // _prodPlanDetailService.Insert(planDetail);//更换班组长后插入一条明细记录 + // //数量+1 + // times++; + // } + // else + // { + // HintText = "当前班组长先打卡!"; + // } + // } + // else + // { + // HintText = "打卡人员非班长,打卡无效!"; + // } + // } + // else + // { + // HintText = "没有匹配的员工,打卡失败!"; + // } + // } + // } + //}; } } @@ -205,7 +208,9 @@ namespace SlnMesnac.WPF.ViewModel if(times == 2) { //在工单明细插入一条,记录两个班长 + EmployeeLoginViewModel.hidUtils.StopScan(); //关闭窗口 + MainWindowViewModel.wins = 1; Application.Current.Windows.OfType().First().Close(); } else diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs index 925a892..080e0eb 100644 --- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs @@ -1,8 +1,10 @@ using ConsoleApp; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using SlnMesnac.Business; using SlnMesnac.Business.business; using SlnMesnac.Common; using SlnMesnac.Repository.service; @@ -10,11 +12,13 @@ using SlnMesnac.WPF.Page; using SlnMesnac.WPF.Page.Generate; using System; using System.ComponentModel; +using System.IO.Ports; using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Timers; using System.Windows; using System.Windows.Controls; +using System.Windows.Input; using System.Windows.Threading; namespace SlnMesnac.WPF.ViewModel @@ -31,7 +35,19 @@ namespace SlnMesnac.WPF.ViewModel private System.Timers.Timer timer; public delegate void UIDCodeDelegate(string code); public event UIDCodeDelegate UIDCodeDelegateEvent; - + private SerialPortBusiness serialPortBusiness; + private string serialPort; + private int baudRate; + private int parity; + private int dataBits; + private int stopBits; + public static int wins = 1;//1为人员登录,2为强退确认,3为交接换班 + + #region 委托定义 + public delegate void TransferOrderCode(string orderCode); + public static event TransferOrderCode? TransferOrderCodeEvent; + #endregion + #region 参数定义 ///// ///// PLC设备状态 @@ -53,18 +69,36 @@ namespace SlnMesnac.WPF.ViewModel // set { _clockStatus = value; RaisePropertyChanged(nameof(ClockStatus)); } //} - ///// - ///// 扫码枪状态 - ///// - //private int _codeGunStatus = 0; - //public int CodeGunStatus - //{ - // get { return _codeGunStatus; } - // set { _codeGunStatus = value; RaisePropertyChanged(nameof(CodeGunStatus)); } - //} + /// + /// 扫码枪状态 + /// + private int _codeGunStatus = 0; + public int CodeGunStatus + { + get { return _codeGunStatus; } + set + { + _codeGunStatus = value; + OnPropertyChanged("CodeGunStatus"); + } + } + + /// + /// 订单号框 + /// + private string orderCodeText; + public string OrderCodeText + { + get { return orderCodeText; } + set + { + orderCodeText = value; + OnPropertyChanged("OrderCodeText"); + } + } + public System.Windows.Controls.UserControl _content; - public System.Windows.Controls.UserControl UserContent { get { return _content; } @@ -92,13 +126,38 @@ namespace SlnMesnac.WPF.ViewModel /// 窗体控制 /// public RelayCommand FormControlCommand { get; set; } + + /// + /// 连接 + /// + public ICommand ConnectCommand { get; set; } + + /// + /// 断开 + /// + public ICommand BreakCommand { get; set; } + + /// + /// 确认 + /// + public ICommand ConfirmCommand { get; set; } #endregion public MainWindowViewModel() { //UserContent = _employeeLoginPage; + IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() + .SetBasePath(System.AppContext.BaseDirectory) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); + IConfigurationRoot configuration = configurationBuilder.Build(); + serialPort = configuration.GetSection("AppConfig")["serialPort"]; + baudRate = Convert.ToInt32(configuration.GetSection("AppConfig")["baudRate"]); + parity = Convert.ToInt32(configuration.GetSection("AppConfig")["parity"]); + dataBits = Convert.ToInt32(configuration.GetSection("AppConfig")["dataBits"]); + stopBits = Convert.ToInt32(configuration.GetSection("AppConfig")["stopBits"]); UserContent = _executePage; _logger = App.ServiceProvider.GetService>(); + serialPortBusiness = App.ServiceProvider.GetService(); var info = App.ServiceProvider.GetService(); ControlOnClickCommand = new RelayCommand(obj => ControlOnClick(obj)); OpenSystemKeyboardCommand = new RelayCommand(obj => OpenSystemKeyboard(obj)); @@ -106,6 +165,24 @@ namespace SlnMesnac.WPF.ViewModel timer = new System.Timers.Timer(1000); // 1 second interval timer.Elapsed += Timer_Tick; timer.Enabled = true; + this.Init(); + ConnectCommand = new RelayCommand(OpenSerialPort); + BreakCommand = new RelayCommand(CloseSerialPort); + ConfirmCommand = new RelayCommand(Confirm); + SerialPortBusiness.ReceivedBarcodeInfoEvent += info => + { + info = OrderCodeText; + }; + } + + /// + /// 确认 + /// + /// + private void Confirm() + { + string orderCode = OrderCodeText; + TransferOrderCodeEvent?.Invoke(orderCode); } /// @@ -113,7 +190,7 @@ namespace SlnMesnac.WPF.ViewModel /// public event PropertyChangedEventHandler PropertyChanged; - #region 参数 + #region 定义参数 /// /// 当前时间 /// @@ -123,6 +200,13 @@ namespace SlnMesnac.WPF.ViewModel get { return _currentTimeText; } set { _currentTimeText = value; OnPropertyChanged("CurrentTimeText"); } } + + private int _serialPortDeviceStatus = 0; + public int SerialPortDeviceStatus + { + get { return _serialPortDeviceStatus; } + set { _serialPortDeviceStatus = value; OnPropertyChanged("SerialPortDeviceStatus"); } + } #endregion /// @@ -172,6 +256,81 @@ namespace SlnMesnac.WPF.ViewModel } } + /// + /// 初始串口 + /// + private void Init() + { + this.serialPortBusiness.RefreshSerialPortDeviceStatusEvent += isFlag => + { + + App.Current.Dispatcher.BeginInvoke((Action)(() => + { + SerialPortDeviceStatus = isFlag; + })); + }; + } + + /// + /// 打开串口 + /// + private void OpenSerialPort() + { + try + { + this.GetParity(out int parity); + this.serialPortBusiness.OpenSerialPort(serialPort, baudRate, parity, dataBits, stopBits); + } + catch (Exception ex) + { + _logger.LogError($"打开串口通讯异常:{ex.Message}"); + } + } + + /// + /// 关闭串口 + /// + private void CloseSerialPort() + { + try + { + this.serialPortBusiness.CloseSerialPort(); + } + catch (Exception ex) + { + _logger.LogError($"关闭串口通讯异常:{ex.Message}"); + } + } + + /// + /// 转换校验位 + /// + /// + private void GetParity(out int parity) + { + switch (serialPort) + { + case "None": + parity = 0; + break; + case "Odd": + parity = 1; + break; + case "Even": + parity = 2; + break; + case "Mark": + parity = 3; + break; + case "Space": + parity = 4; + break; + default: + parity = 0; + break; + } + } + /// /// 打开系统键盘 /// diff --git a/SlnMesnac.WPF/ViewModel/ProductionReportViewModel.cs b/SlnMesnac.WPF/ViewModel/ProductionReportViewModel.cs index 0352b15..10eb0cf 100644 --- a/SlnMesnac.WPF/ViewModel/ProductionReportViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/ProductionReportViewModel.cs @@ -1,5 +1,6 @@ using GalaSoft.MvvmLight.Command; using Microsoft.Extensions.DependencyInjection; +using SlnMesnac.Business.business; using SlnMesnac.Model.domain; using SlnMesnac.Repository.service; using SlnMesnac.WPF.Views; @@ -19,6 +20,7 @@ namespace SlnMesnac.WPF.ViewModel { private ProdPlanInfoService _prodPlanInfoService; private ProdPlanDetailService _prodPlanDetailService; + private DatabaseHandleBusniess _databaseHandleBusniess; private ProdPLanInfo planInfo; private ProdPlanDetail planDetail; @@ -37,6 +39,7 @@ namespace SlnMesnac.WPF.ViewModel { _prodPlanDetailService = App.ServiceProvider.GetService(); _prodPlanInfoService = App.ServiceProvider.GetService(); + _databaseHandleBusniess = App.ServiceProvider.GetService(); ConfirmCommand = new RelayCommand(Confirm); EndPlanCommand = new RelayCommand(EndPlan); Init(); @@ -54,7 +57,7 @@ namespace SlnMesnac.WPF.ViewModel { planDetail = _prodPlanDetailService.GetPlanDetailsByPlanCode(planInfo.PlanCode); PlanAmountText = planDetail.PlanAmount.ToString(); - CompleteAmountText = planDetail.CompleteAmount.ToString(); + CompleteAmountText = planInfo.CompleteAmount.ToString(); } else { @@ -62,7 +65,7 @@ namespace SlnMesnac.WPF.ViewModel } } - #region + #region 定义属性 /// /// 计划数量Text /// @@ -130,13 +133,18 @@ namespace SlnMesnac.WPF.ViewModel if (isNum) { //将新增产量加到实际产量中 - double currentAmountDouble = Convert.ToDouble(planDetail.CompleteAmount); + double currentAmountDouble = Convert.ToDouble(planInfo.CompleteAmount); double newAmountDouble = Convert.ToDouble(newAmount); double result = currentAmountDouble + newAmountDouble; - planDetail.CompleteAmount = result.ToString(); + planDetail.CompleteAmount = newAmountDouble.ToString(); planInfo.CompleteAmount = result.ToString(); - _prodPlanDetailService.Update(planDetail); + planDetail.BatchNumber += 1; + planInfo.PlanStatus = "4"; + //保存工单的执行人员 + List realTimes = _databaseHandleBusniess.GetRecordStaffRealTimes(); + _prodPlanDetailService.Insert(planDetail); _prodPlanInfoService.Update(planInfo); + _databaseHandleBusniess.InsertPlanExecuteUser(planInfo, planDetail, realTimes); Refresh(); NewAmountText = null; HintText = "已提交!"; @@ -168,7 +176,7 @@ namespace SlnMesnac.WPF.ViewModel if (planDetail != null && planInfo != null) { planDetail.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - _prodPlanDetailService.Update(planDetail); + _prodPlanDetailService.Insert(planDetail); planInfo.PlanStatus = "2"; planInfo.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); double planAmountDouble = Convert.ToDouble(planDetail.PlanAmount); diff --git a/SlnMesnac.WPF/ViewModel/RemoveConfirmViewModel.cs b/SlnMesnac.WPF/ViewModel/RemoveConfirmViewModel.cs new file mode 100644 index 0000000..0e23c43 --- /dev/null +++ b/SlnMesnac.WPF/ViewModel/RemoveConfirmViewModel.cs @@ -0,0 +1,106 @@ +using ConsoleApp; +using GalaSoft.MvvmLight.Command; +using Microsoft.Extensions.DependencyInjection; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service; +using SlnMesnac.WPF.Views; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; + +namespace SlnMesnac.WPF.ViewModel +{ + public class RemoveConfirmViewModel : INotifyPropertyChanged + { + private IBaseStaffService _baseStaffService; + private IRecordStaffAttendanceService _recordStaffAttendanceService; + public static int times = 0; + + /// + /// 按钮文字转换事件 + /// + public event PropertyChangedEventHandler PropertyChanged = delegate { }; + public void OnPropertyChanged([CallerMemberName] string propertyName = "") + { + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + + #region 定义属性 + /// + /// 提示信息 + /// + private string hintText; + public string HintText + { + get { return hintText; } + set { hintText = value; OnPropertyChanged("HintText"); } + } + #endregion + + public RemoveConfirmViewModel() + { + HintText = ""; + times = 0; + _baseStaffService = App.ServiceProvider.GetService(); + _recordStaffAttendanceService = App.ServiceProvider.GetService(); + Init(); + ConfirmCommand = new RelayCommand(Confirm); + } + + /// + /// 初始化 + /// + private void Init() + { + //hidUtils.Initial(); + EmployeeLoginViewModel.hidUtils.StartScan(); + EmployeeLoginViewModel._transmitToRemoveConfigAction += (str) => + { + if (MainWindowViewModel.wins == 2) + { + str = str.ToString().Replace(" ", ""); + BaseStaffInfo user = _baseStaffService.GetStaffInfoByCardId(str); + if (times < 1) + { + if (user != null) + { + string staffType = user.StaffType; + if (staffType == "1")//判断是否为班长,判断后续是否为当前班组的班长 + { + HintText = "成功!"; + times++; + } + else + { + HintText = "非班组长,无效!"; + } + } + else + { + HintText = "没有匹配的员工,打卡失败!"; + } + } + } + }; + } + + /// + /// 确认 + /// + public ICommand ConfirmCommand { get; private set; } + private void Confirm() + { + //在工单明细插入一条,记录两个班长 + EmployeeLoginViewModel.hidUtils.StopScan(); + //关闭窗口 + Application.Current.Windows.OfType().First().Close(); + MainWindowViewModel.wins = 1; + } + } +} diff --git a/SlnMesnac.WPF/Views/RemoveConfirmWin.xaml b/SlnMesnac.WPF/Views/RemoveConfirmWin.xaml new file mode 100644 index 0000000..14e55a1 --- /dev/null +++ b/SlnMesnac.WPF/Views/RemoveConfirmWin.xaml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + +