diff --git a/SlnMesnac.Business/business/DatabaseHandleBusniess.cs b/SlnMesnac.Business/business/DatabaseHandleBusniess.cs index d687c0c..f4e48c1 100644 --- a/SlnMesnac.Business/business/DatabaseHandleBusniess.cs +++ b/SlnMesnac.Business/business/DatabaseHandleBusniess.cs @@ -56,6 +56,7 @@ namespace SlnMesnac.Business.business OrderCode = orderCode, MaterialCode = orderInfo.MaterialCode, MaterialName = orderInfo.MaterialName, + BeginTime =DateTime.Now.ToString(), StationCode = stationCode, DeviceCode = deviceCode, PlanAmount = orderInfo.OrderAmount, @@ -115,8 +116,8 @@ namespace SlnMesnac.Business.business StationCode = prodPlanInfo.StationCode, StaffId = item.StaffId, CompleteAmount = prodPlanDetail.CompleteAmount, - PlanBeginDate = prodPlanInfo.BeginTime, - PlanEndDate = prodPlanInfo.EndTime, + PlanBeginDate = prodPlanDetail.BeginTime, + PlanEndDate = prodPlanDetail.EndTime, CreatedBy = prodPlanInfo.CreatedBy, CreatedTime = prodPlanDetail.BeginTime, UpdatedBy = prodPlanInfo.UpdatedBy, @@ -152,6 +153,30 @@ namespace SlnMesnac.Business.business return _prodPlanInfoService.GetPlanInfoByConditions(orderCode,"","", stationCode,"0").FirstOrDefault(); } + /// + /// 更新订单信息状态 + /// + /// + /// + public void UpdateOrderInfoStatus(string orderCode,string status) + { + _prodOrderInfoService.UpdateOrderInfoStatus(orderCode,status); + } + + /// + /// 删除对应批次的明细和执行人信息 + /// + /// + /// + public void DeleteTheBatchDetailAndExecuter(string planCode,int batch) + { + if (planCode != "" && batch != 0) + { + bool result = _prodPlanDetailService.DeleteTheBatchNumberByPlanCode(planCode, batch); + _prodPlanExecuteUserService.DeleteByPlanCodeAndTheBatchNumber(planCode, batch); + } + } + ///// ///// 查询所有计划工位 ///// diff --git a/SlnMesnac.Business/business/RfidHandleBusniess.cs b/SlnMesnac.Business/business/RfidHandleBusniess.cs index 2004cc2..dc8e8a4 100644 --- a/SlnMesnac.Business/business/RfidHandleBusniess.cs +++ b/SlnMesnac.Business/business/RfidHandleBusniess.cs @@ -26,6 +26,8 @@ namespace SlnMesnac.Business.business private List members = new List(); public static string stationCode = ""; public static List stationList; + public static string staffId = ""; + public static string theNewAmount = ""; public RfidHandleBusniess(IRecordStaffAttendanceService recordStaffAttendanceService, IRecordStaffCommuteService recordStaffCommuteService, IRecordStaffRealTimeService recordStaffRealTimeService) { @@ -57,6 +59,28 @@ namespace SlnMesnac.Business.business return _recordStaffAttendanceService.GetRecordStaffAttendances(stationCode); } + /// + /// 处理并插入打卡记录(强退) + /// + /// + /// + /// + public List HandleAndInsertRemove(BaseStaffInfo staff, int isCheckOn) + { + RecordStaffAttendance recordStaffAttendance = new RecordStaffAttendance + { + StaffId = staff.StaffId, + AttendanceType = isCheckOn.ToString(), + TeamCode = staff.TeamCode, + Remark = staffId, + CreateBy = staff.StaffName, + CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + StationCode = stationCode + }; + _recordStaffAttendanceService.Insert(recordStaffAttendance); + return _recordStaffAttendanceService.GetRecordStaffAttendances(stationCode); + } + /// /// 处理上下班记录 /// diff --git a/SlnMesnac.Repository/service/Impl/ProdOrderInfoServiceImpl.cs b/SlnMesnac.Repository/service/Impl/ProdOrderInfoServiceImpl.cs index 49b95eb..5686b2d 100644 --- a/SlnMesnac.Repository/service/Impl/ProdOrderInfoServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/ProdOrderInfoServiceImpl.cs @@ -35,5 +35,33 @@ namespace SlnMesnac.Repository.service.Impl } return prodOrderInfo; } + + /// + /// 更新订单状态 + /// + /// + /// + /// + public void UpdateOrderInfoStatus(string orderCode, string status) + { + try + { + var prodOrderInfo = _rep.GetFirst(x => x.OrderCode == orderCode); + if (prodOrderInfo != null) + { + prodOrderInfo.OrderStatus = status; // 更新订单状态 + _rep.Update(prodOrderInfo); // 假设有一个Update方法来保存更改 + } + else + { + _logger.LogWarning($"未找到订单号为 {orderCode} 的订单信息"); + } + } + catch (Exception ex) + { + _logger.LogError($"更新订单状态异常:{ex.Message}"); + } + } + } } diff --git a/SlnMesnac.Repository/service/Impl/ProdPlanDetailServiceImpl.cs b/SlnMesnac.Repository/service/Impl/ProdPlanDetailServiceImpl.cs index d5eda1d..adafd0a 100644 --- a/SlnMesnac.Repository/service/Impl/ProdPlanDetailServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/ProdPlanDetailServiceImpl.cs @@ -68,5 +68,26 @@ namespace SlnMesnac.Repository.service.Impl } return result; } + + /// + /// 删除工单里的某个批次 + /// + /// + /// + /// + public bool DeleteTheBatchNumberByPlanCode(string planCode, int batch) + { + bool result = false; + try + { + ProdPlanDetail temp = _rep.AsQueryable().Where(x => x.PlanCode == planCode && x.BatchNumber == batch).OrderByDescending(x => x.ObjId).First(); + result = _rep.Delete(temp); + } + catch (Exception ex) + { + _logger.LogError($"根据计划编号删指定锅数的数据异常{ex.Message}"); + } + return result; + } } } diff --git a/SlnMesnac.Repository/service/Impl/ProdPlanExecuteUserServiceImpl.cs b/SlnMesnac.Repository/service/Impl/ProdPlanExecuteUserServiceImpl.cs index 9548c82..65caa51 100644 --- a/SlnMesnac.Repository/service/Impl/ProdPlanExecuteUserServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/ProdPlanExecuteUserServiceImpl.cs @@ -13,6 +13,31 @@ namespace SlnMesnac.Repository.service.Impl public ProdPlanExecuteUserServiceImpl(Repository repository, ILogger logger) : base(repository) { _logger = logger; - } + } + + /// + /// 根据计划号和批次号删除所有执行信息 + /// + /// + /// + /// + public bool DeleteByPlanCodeAndTheBatchNumber(string planCode, int batch) + { + bool result = false; + try + { + List prodPlanExecuteUsers = _rep.AsQueryable().Where(x => x.PlanCode == planCode && x.BatchNumber == batch).ToList(); + foreach (var execute in prodPlanExecuteUsers) + { + _rep.Delete(execute); + } + result = true; + } + catch (Exception ex) + { + _logger.LogError($"根据计划编号删指定锅数的数据异常{ex.Message}"); + } + return result; + } } } diff --git a/SlnMesnac.Repository/service/Impl/ProdPlanInfoServiceImpl.cs b/SlnMesnac.Repository/service/Impl/ProdPlanInfoServiceImpl.cs index 56dd8d7..b1a136c 100644 --- a/SlnMesnac.Repository/service/Impl/ProdPlanInfoServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/ProdPlanInfoServiceImpl.cs @@ -53,7 +53,7 @@ namespace SlnMesnac.Repository.service.Impl .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 || x.PlanStatus == "4") + .WhereIF(!string.IsNullOrEmpty(planStatus), x => x.PlanStatus == planStatus) .OrderByDescending(x => x.ObjId) .ToList(); return planInfoList; @@ -85,7 +85,8 @@ namespace SlnMesnac.Repository.service.Impl ProdPLanInfo prodPLan = new ProdPLanInfo(); try {//只显示未执行的 - prodPLan = _rep.GetFirst(x => x.OrderCode == orderCode && x.StationCode == stationCode && x.PlanStatus == "0" || x.PlanStatus == "4"); + prodPLan = _rep.GetFirst(x => x.OrderCode == orderCode && x.StationCode == stationCode); + //&& (x.PlanStatus == "0" || x.PlanStatus == "4") } catch (Exception ex) { diff --git a/SlnMesnac.Repository/service/ProdOrderInfoService.cs b/SlnMesnac.Repository/service/ProdOrderInfoService.cs index 04cbe30..63713cf 100644 --- a/SlnMesnac.Repository/service/ProdOrderInfoService.cs +++ b/SlnMesnac.Repository/service/ProdOrderInfoService.cs @@ -9,5 +9,6 @@ namespace SlnMesnac.Repository.service public interface ProdOrderInfoService : IBaseService { ProdOrderInfo GetProdOrderInfoByOrderCode(string orderCode); + public void UpdateOrderInfoStatus(string orderCode,string status); } } diff --git a/SlnMesnac.Repository/service/ProdPlanDetailService.cs b/SlnMesnac.Repository/service/ProdPlanDetailService.cs index 7041782..4ece434 100644 --- a/SlnMesnac.Repository/service/ProdPlanDetailService.cs +++ b/SlnMesnac.Repository/service/ProdPlanDetailService.cs @@ -36,5 +36,12 @@ namespace SlnMesnac.Repository.service /// /// bool DeleteByPlanCodeBatchNumber(string planCode, int number); + + /// + /// 产出对应工单里的某个批次 + /// + /// + /// + bool DeleteTheBatchNumberByPlanCode(string planCode, int batch); } } diff --git a/SlnMesnac.Repository/service/ProdPlanExecuteUserService.cs b/SlnMesnac.Repository/service/ProdPlanExecuteUserService.cs index 2cbdb34..7825676 100644 --- a/SlnMesnac.Repository/service/ProdPlanExecuteUserService.cs +++ b/SlnMesnac.Repository/service/ProdPlanExecuteUserService.cs @@ -8,6 +8,12 @@ namespace SlnMesnac.Repository.service { public interface ProdPlanExecuteUserService : IBaseService { - + /// + /// 根据计划号和批次号删除所有执行信息 + /// + /// + /// + /// + bool DeleteByPlanCodeAndTheBatchNumber(string planCode, int batch); } } diff --git a/SlnMesnac.WPF/SlnMesnac.WPF.csproj b/SlnMesnac.WPF/SlnMesnac.WPF.csproj index 2692cd3..ac696f4 100644 --- a/SlnMesnac.WPF/SlnMesnac.WPF.csproj +++ b/SlnMesnac.WPF/SlnMesnac.WPF.csproj @@ -1,7 +1,7 @@  - Exe + WinExe net6.0-windows enable true diff --git a/SlnMesnac.WPF/UserControls/ExecutePage.xaml b/SlnMesnac.WPF/UserControls/ExecutePage.xaml index 2c1bcc2..a5dfdb5 100644 --- a/SlnMesnac.WPF/UserControls/ExecutePage.xaml +++ b/SlnMesnac.WPF/UserControls/ExecutePage.xaml @@ -123,13 +123,13 @@ - + + + - - - - diff --git a/SlnMesnac.WPF/UserControls/FirstItemVisibilityConverter.cs b/SlnMesnac.WPF/UserControls/FirstItemVisibilityConverter.cs new file mode 100644 index 0000000..1dd794e --- /dev/null +++ b/SlnMesnac.WPF/UserControls/FirstItemVisibilityConverter.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +public class FirstItemVisibilityConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var items = parameter as System.Collections.IList; + + if (items != null && items.Count > 0) + { + int index = items.IndexOf(value); + return index == 0 ? Visibility.Visible : Visibility.Collapsed; + } + + return Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} diff --git a/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs b/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs index 99fd716..cacf0df 100644 --- a/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/EmployeeLoginViewModel.cs @@ -52,7 +52,7 @@ namespace SlnMesnac.WPF.ViewModel public static bool isOnDuty = false;//是否有班组当班 private List uniqueStrings = new List(); private List timestamps = new List(); - //private BaseStaffInfo user; + private BaseStaffInfo user; /// /// 按钮文字转换事件 @@ -290,7 +290,11 @@ namespace SlnMesnac.WPF.ViewModel var result = ExtractStrings(SelectedItem); RfidHandleBusniess.stationCode = result.Item1; stationName = result.Item2; + //ExecuteViewModel.stationTextBlock = stationName; + TransmitStationNameAction?.Invoke(stationName); isSelectedStationCode = true; + TransmitUserDelegateEvent?.Invoke(); + ShowStaffAttendances(null, isCheckOn); MessageBox.Show("已确认工位:" + stationName); } else @@ -314,7 +318,7 @@ namespace SlnMesnac.WPF.ViewModel if (RemoveConfirmViewModel.times == 1) { var theUser = baseStaffService.GetStaffInfoByStaffId(staffId); - _rfidHandleBusniess.HandleAndInsertStaffAttendance(theUser, 2); + _rfidHandleBusniess.HandleAndInsertRemove(theUser, 2); var list = _rfidHandleBusniess.HandleAndInsertStaffRealTime(theUser, 2); if (list.Count>=0) { @@ -323,6 +327,7 @@ namespace SlnMesnac.WPF.ViewModel RecordStaffRealTimeDataGrid.Clear(); list.ForEach(item => { RecordStaffRealTimeDataGrid.Add(item); }); })); + _rfidHandleBusniess.HandleStaffCommute(user, 1); } if(list.Count == 0) { @@ -355,7 +360,7 @@ namespace SlnMesnac.WPF.ViewModel // Additional logic for processing the unique string goes here if (isUse) { - var user = baseStaffService.GetStaffInfoByCardId(cleanStr); + user = baseStaffService.GetStaffInfoByCardId(cleanStr); if (user != null) { RecordStaffAttendance recordStaffAttendance = _recordStaffAttendanceService.GetRecordStaffAttendanceByStaffId(user.StaffId, RfidHandleBusniess.stationCode); @@ -523,7 +528,7 @@ namespace SlnMesnac.WPF.ViewModel } /// - /// 30分钟内过滤重复str + /// 5秒内过滤重复str /// /// /// @@ -531,7 +536,7 @@ namespace SlnMesnac.WPF.ViewModel { for (int i = 0; i < uniqueStrings.Count; i++) { - if (uniqueStrings[i] == str && (DateTime.Now - timestamps[i]).TotalSeconds < 30) + if (uniqueStrings[i] == str && (DateTime.Now - timestamps[i]).TotalSeconds < 5) { return true; } diff --git a/SlnMesnac.WPF/ViewModel/ExecuteViewModel.cs b/SlnMesnac.WPF/ViewModel/ExecuteViewModel.cs index 3fff773..7df3538 100644 --- a/SlnMesnac.WPF/ViewModel/ExecuteViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/ExecuteViewModel.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Components.Forms; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Protocols; using NVelocity.Util.Introspection; using SlnMesnac.Business; @@ -30,6 +31,7 @@ namespace SlnMesnac.WPF.ViewModel { public class ExecuteViewModel : INotifyPropertyChanged { + private readonly ILogger _logger; public ObservableCollection OrderCodeComboBoxItems { get; set; } public ObservableCollection PlanCodeComboBoxItems { get; set; } public ObservableCollection MaterialNameComboBoxItems { get; set; } @@ -39,16 +41,23 @@ namespace SlnMesnac.WPF.ViewModel private List prodPlanInfos; private ProdPlanDetailService _prodPlanDetailService; private IRecordStaffAttendanceService _recordStaffAttendanceService; + private IRecordStaffRealTimeService _recordStaffRealTimeService; private IBaseStaffService _baseStaffService; //private string StationCode; private string DeviceCode; private string ProcessCode; public static bool isComplete = true; + public static string theStartTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//记录每个明细的开始时间 + public static string intervalvalTime = "2023-11-11 00:00:00"; + public static int stations = 0; + private string theOrderCode = ""; private ProdPLanInfo pLanInfo; private ProdPLanInfo haveInfo; private SerialPortBusiness _serialPortBusiness; private string executeText = "待执行"; private int isSearch = 0; + public static string lastReportTime; + //public static string batchNums = "";//批次 #region 定义命令 /// @@ -75,6 +84,11 @@ namespace SlnMesnac.WPF.ViewModel /// 执行命令 /// public ICommand ExecuteCommand { get; private set; } + + /// + /// 撤回命令 + /// + public ICommand WithdrawCommand { get; private set; } #endregion #region 定义委托 @@ -132,10 +146,10 @@ namespace SlnMesnac.WPF.ViewModel /// 工位 /// private string stationTextBlock; - public string StationTextBox + public string StationTextBox { get { return stationTextBlock; } - set { stationTextBlock = value; new PropertyChangedEventArgs(nameof(StationTextBox)); } + set { stationTextBlock = value; OnPropertyChanged("StationTextBox"); } } /// @@ -148,6 +162,19 @@ namespace SlnMesnac.WPF.ViewModel set { prodPLanInfoDataGrid = value; OnPropertyChanged("ProdPLanInfoDataGrid"); } } + /// + /// 工单计划选中行 + /// + public ProdPLanInfo _selectedRow; + public ProdPLanInfo SelectedRow + { + get { return _selectedRow; } + set + { + _selectedRow = value; OnPropertyChanged(nameof(SelectedRow)); + } + } + /// /// DetailDataGrid /// @@ -159,15 +186,15 @@ namespace SlnMesnac.WPF.ViewModel } /// - /// 选中行 + /// 工单明细选中行 /// - public ProdPLanInfo _selectedRow; - public ProdPLanInfo SelectedRow + public ProdPlanDetail _selectedDetialRow; + public ProdPlanDetail SelectedDetailRow { - get { return _selectedRow; } + get { return _selectedDetialRow; } set { - _selectedRow = value; OnPropertyChanged(nameof(SelectedRow)); + _selectedDetialRow = value; OnPropertyChanged(nameof(SelectedDetailRow)); } } @@ -194,11 +221,11 @@ namespace SlnMesnac.WPF.ViewModel /// /// 原料Text /// - private string materialCodeText; - public string MaterialCodeText + private string materialNameText; + public string MaterialNameText { - get { return materialCodeText; } - set { materialCodeText = value; OnPropertyChanged("MaterialCodeText"); } + get { return materialNameText; } + set { materialNameText = value; OnPropertyChanged("MaterialNameText"); } } /// @@ -220,13 +247,25 @@ namespace SlnMesnac.WPF.ViewModel get { return stationCodeText; } set { stationCodeText = value; OnPropertyChanged("StationCodeText"); } } + + /// + /// 批次号 + /// + private string batchNumbers; + public string BatchNumbers + { + get { return batchNumbers; } + set { batchNumbers = value; OnPropertyChanged("BatchNumbers"); } + } #endregion public ExecuteViewModel() { + _logger = App.ServiceProvider.GetService>(); _prodPlanInfoService = App.ServiceProvider.GetService(); _prodPlanDetailService = App.ServiceProvider.GetService(); _recordStaffAttendanceService = App.ServiceProvider.GetService(); + _recordStaffRealTimeService = App.ServiceProvider.GetService(); _RfidHandleBusniess = App.ServiceProvider.GetService(); _baseStaffService = App.ServiceProvider.GetService(); _serialPortBusiness = App.ServiceProvider.GetService(); @@ -235,7 +274,7 @@ namespace SlnMesnac.WPF.ViewModel .SetBasePath(System.AppContext.BaseDirectory) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = configurationBuilder.Build(); - pLanInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions("", "", "", "", "1").FirstOrDefault(); + pLanInfo = _prodPlanInfoService.GetPlanInfoByConditions("", "", "", "", "1").FirstOrDefault(); Refresh(pLanInfo); havePlanOnDuty(); // 从配置文件中获取ProductLineNameTextBlock的值 @@ -246,6 +285,10 @@ namespace SlnMesnac.WPF.ViewModel //}; //StationList = ConvertStringToList(StationCodes); //RfidHandleBusniess.stationCode = StationCodes; + EmployeeLoginViewModel.TransmitStationNameAction += stationName => + { + updateStationName(stationName); + }; DeviceCode = configuration.GetSection("AppConfig")["DeviceCode"]; ProcessCode = configuration.GetSection("AppConfig")["ProcessCode"]; HandoverCommand = new RelayCommand(Handover); @@ -253,12 +296,47 @@ namespace SlnMesnac.WPF.ViewModel TechnologicalInformationCommand = new RelayCommand(TechnologicalInformation); SearchCommand = new RelayCommand(Search); ExecuteCommand = new RelayCommand(Execute); + WithdrawCommand = new RelayCommand(Withdraw); ProductionReportViewModel.RefreshDelegateEvent += Refresh; EmployeeLoginViewModel.TransmitUserDelegateEvent += ShowTeamMember; //SerialPortBusiness.ReceivedBarcodeInfoEvent += HandleOrderCode; MainWindowViewModel.TransferOrderCodeEvent += HandleOrderCode; } + /// + /// 撤回 + /// + /// + private void Withdraw() + { + //BatchNumbers = batchNums; + MainWindowViewModel.wins = 2; + var removeConfirmWin = new RemoveConfirmWin(); + removeConfirmWin.Owner = Application.Current.MainWindow; + removeConfirmWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; + removeConfirmWin.ShowDialog(); + if (RemoveConfirmViewModel.times == 1) + { + //当前正在执行的工单的单号和产量 + string planCode = pLanInfo.PlanCode; + int batch = _selectedDetialRow.BatchNumber; + //删除planInfo对应产量 + pLanInfo = _prodPlanInfoService.GetPlanInfoByConditions("", "", "", "", "1").FirstOrDefault(); + double planNum = double.Parse(pLanInfo.CompleteAmount); + double detailNum = double.Parse(_selectedDetialRow.CompleteAmount); + pLanInfo.CompleteAmount = (planNum - detailNum).ToString(); + _prodPlanInfoService.Update(pLanInfo); + //删除对应批次的明细和执行人信息 + _databaseHandleBusniess.DeleteTheBatchDetailAndExecuter(planCode, batch); + //刷新 + Refresh(pLanInfo); + } + MainWindowViewModel.wins = 1; + } + + /// + /// 是否有计划正在执行 + /// private void havePlanOnDuty() { haveInfo = _prodPlanInfoService.GetPlanInfoByConditions("", "", "", "", "1").FirstOrDefault(); @@ -271,6 +349,15 @@ namespace SlnMesnac.WPF.ViewModel } } + /// + /// 更新工位名称 + /// + /// + private void updateStationName(string stationName) + { + StationTextBox = EmployeeLoginViewModel.stationName; + } + /// /// 换班弹窗 /// @@ -289,7 +376,7 @@ namespace SlnMesnac.WPF.ViewModel { if (RfidHandleBusniess.stationCode != "") { - pLanInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions("", "", "", RfidHandleBusniess.stationCode, "1").FirstOrDefault(); + pLanInfo = _prodPlanInfoService.GetPlanInfoByConditions("", "", "", RfidHandleBusniess.stationCode, "1").FirstOrDefault(); if (pLanInfo != null) { MainWindowViewModel.wins = 3; @@ -297,8 +384,13 @@ namespace SlnMesnac.WPF.ViewModel reportWin.Owner = Application.Current.MainWindow; // 设置父窗口为当前主窗口 reportWin.WindowStartupLocation = WindowStartupLocation.CenterScreen; // 让窗体出现在屏幕中央 reportWin.ShowDialog();//窗体出现后禁止后面的用户控件 + Search(); Refresh(pLanInfo); ShowTeamMember(); + if (stations >= 3) + { + _databaseHandleBusniess.UpdateOrderInfoStatus(theOrderCode, "2"); + } MainWindowViewModel.wins = 1; } else @@ -337,7 +429,8 @@ namespace SlnMesnac.WPF.ViewModel /// private void Search() { - if (EmployeeLoginViewModel.isOnDuty == true) + var staffList = _recordStaffRealTimeService.Query().ToList(); + if (staffList.Count > 0) { //在这里执行其他操作,可以通过InputText获取用户输入的信息 //Console.WriteLine("用户输入的信息:" + OrderCodeTextBox + PlanCodeTextBox + MaterialCodeTextBox); @@ -364,10 +457,13 @@ namespace SlnMesnac.WPF.ViewModel /// private void HandleOrderCode(string orderCode) { + theOrderCode = orderCode; if (isComplete) { if (isSearch == 1) { + //更新当前工单状态 + _databaseHandleBusniess.UpdateOrderInfoStatus(orderCode,"1"); //判断当前工位的工单编号是否存在 var plan = _prodPlanInfoService.GetProdPLanInfoByOrderCode(RfidHandleBusniess.stationCode, orderCode); if (plan == null)//不存在,就在生产工单表中新增一条当前工位的订单,且执行状态改为4,重新检索,并高亮这条工单,执行按钮可用 @@ -393,10 +489,10 @@ namespace SlnMesnac.WPF.ViewModel } Search(); } - else - { - MessageBox.Show("请先检索工单!"); - } + //else + //{ + // MessageBox.Show("请先检索工单!"); + //} } else { @@ -415,33 +511,43 @@ namespace SlnMesnac.WPF.ViewModel { 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 + try { - 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; + // 将当前记录存为实体,可以通过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表里插入一条数据 + if (pLanInfo.CompleteAmount == "0.00") + { + 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; + } + catch (Exception ex) + { + _logger.LogError("执行异常", ex); + } } else { @@ -461,7 +567,7 @@ namespace SlnMesnac.WPF.ViewModel var planDetail = planDetails.FirstOrDefault(); PlanCodeText = planDetail.PlanCode; OrderCodeText = pLanInfo.OrderCode; - MaterialCodeText = planDetail.MaterialCode; + MaterialNameText = pLanInfo.MaterialName; StationCodeText = pLanInfo.StationCode; System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => { diff --git a/SlnMesnac.WPF/ViewModel/ProductionReportViewModel.cs b/SlnMesnac.WPF/ViewModel/ProductionReportViewModel.cs index b9c05c5..b00ee15 100644 --- a/SlnMesnac.WPF/ViewModel/ProductionReportViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/ProductionReportViewModel.cs @@ -47,8 +47,13 @@ namespace SlnMesnac.WPF.ViewModel ConfirmCommand = new RelayCommand(Confirm); EndPlanCommand = new RelayCommand(EndPlan); ContinueCommand = new RelayCommand(Continue); + PauseCommand = new RelayCommand(Pause); EndButtonColor = "Red"; Init(); + if (RfidHandleBusniess.theNewAmount != "") + { + NewAmountText = RfidHandleBusniess.theNewAmount; + } } private void Init() @@ -131,6 +136,11 @@ namespace SlnMesnac.WPF.ViewModel } #endregion + /// + /// 暂停 + /// + public ICommand PauseCommand { get; set; } + /// /// 继续 /// @@ -146,62 +156,80 @@ namespace SlnMesnac.WPF.ViewModel /// private void Confirm() { - if(EmployeeLoginViewModel.isOnDuty == true)//是否有班组当班,无当班时操作无效 + DateTime startTime = DateTime.Parse(ExecuteViewModel.intervalvalTime); + if ((DateTime.Now - startTime).TotalMinutes > 15) { - string newAmount = NewAmountText; - if (newAmount != null) + if (EmployeeLoginViewModel.isOnDuty == true)//是否有班组当班,无当班时操作无效 { - bool isNum = true; - foreach (char x in newAmount) + string newAmount = NewAmountText; + RfidHandleBusniess.theNewAmount = NewAmountText; + if (newAmount != "") { - if (!char.IsNumber(x) && x != '.') + bool isNum = true; + foreach (char x in newAmount) { - isNum = false; + if (!char.IsNumber(x) && x != '.') + { + isNum = false; + } } - } - if (isNum) - { - //将新增产量加到实际产量中 - currentAmountDouble = Convert.ToDouble(planInfo.CompleteAmount); - newAmountDouble = Convert.ToDouble(newAmount); - result = currentAmountDouble + newAmountDouble; - //planDetail = new ProdPlanDetail(); - planDetail.CompleteAmount = newAmountDouble.ToString(); - planInfo.CompleteAmount = result.ToString(); - planDetail.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - 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 = "已提交!"; - RefreshDelegateEvent?.Invoke(planInfo); - ExecuteViewModel.isComplete = true; - complateRate = GetComplateRate(result, PlanAmountText); - if (complateRate > 0.9) + if (isNum) { - EndButtonColor = "#FF11B514"; + HintText = "请撤回最新工单明细!"; + //将新增产量加到实际产量中 + currentAmountDouble = Convert.ToDouble(planInfo.CompleteAmount); + newAmountDouble = Convert.ToDouble(newAmount); + result = currentAmountDouble + newAmountDouble; + //planDetail = new ProdPlanDetail(); + planDetail.CompleteAmount = newAmountDouble.ToString(); + planInfo.CompleteAmount = result.ToString(); + if (planDetail.EndTime == null)//第一条明细 + { + planDetail.BeginTime = ExecuteViewModel.theStartTime; + } + else + { + planDetail.BeginTime = planDetail.EndTime; + } + planDetail.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + ExecuteViewModel.intervalvalTime = planDetail.EndTime; + planDetail.BatchNumber += 1; + //ExecuteViewModel.batchNums = planDetail.BatchNumber.ToString(); + //保存工单的执行人员 + List realTimes = _databaseHandleBusniess.GetRecordStaffRealTimes(); + _prodPlanDetailService.Insert(planDetail); + _prodPlanInfoService.Update(planInfo); + _databaseHandleBusniess.InsertPlanExecuteUser(planInfo, planDetail, realTimes); + Refresh(); + HintText = "已提交!"; + RefreshDelegateEvent?.Invoke(planInfo); + //ExecuteViewModel.isComplete = true; + complateRate = GetComplateRate(result, PlanAmountText); + if (complateRate > 0.9) + { + EndButtonColor = "#FF11B514"; + } + } + else + { + //提示框提示错误信息 + HintText = "输入有误,请输入阿拉伯数字!"; } } else { - //提示框提示错误信息 - HintText = "输入有误,请输入阿拉伯数字!"; + HintText = "不能为空!"; } } else { - HintText = "不能为空!"; + HintText = "没有班组当班,无法执行此操作!"; } } else { - HintText = "没有班组当班,无法执行此操作!"; - } + HintText = "当前工单距离上次提交不足15分钟!"; + } } /// @@ -221,8 +249,9 @@ namespace SlnMesnac.WPF.ViewModel //_prodPlanDetailService.Insert(planDetail); planInfo.PlanStatus = "2"; planInfo.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - double planAmountDouble = Convert.ToDouble(planDetail.PlanAmount); - double completeAmountDouble = Convert.ToDouble(planDetail.CompleteAmount); + double planAmountDouble = Convert.ToDouble(planInfo.PlanAmount); + double completeAmountDouble = Convert.ToDouble(planInfo.CompleteAmount); + ExecuteViewModel.isComplete = true; if (planAmountDouble == completeAmountDouble) { planInfo.CompFlag = "0";//正常完成 @@ -236,6 +265,7 @@ namespace SlnMesnac.WPF.ViewModel planInfo.CompFlag = "2";//超额完成 } _prodPlanInfoService.Update(planInfo); + ExecuteViewModel.stations += 1; } //关闭窗口 Application.Current.Windows.OfType().First().Close(); @@ -257,6 +287,19 @@ namespace SlnMesnac.WPF.ViewModel Application.Current.Windows.OfType().First().Close(); } + /// + /// 暂停工单 + /// + private void Pause() + { + //将当前的工单更新为待执行 + planInfo.PlanStatus = "4"; + _prodPlanInfoService.Update(planInfo); + ExecuteViewModel.isComplete = true; + //关闭窗口 + Application.Current.Windows.OfType().First().Close(); + } + /// /// 获取完成率 diff --git a/SlnMesnac.WPF/ViewModel/RemoveConfirmViewModel.cs b/SlnMesnac.WPF/ViewModel/RemoveConfirmViewModel.cs index 0e23c43..df61a2c 100644 --- a/SlnMesnac.WPF/ViewModel/RemoveConfirmViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/RemoveConfirmViewModel.cs @@ -13,6 +13,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; +using SlnMesnac.Business.business; namespace SlnMesnac.WPF.ViewModel { @@ -75,6 +76,7 @@ namespace SlnMesnac.WPF.ViewModel { HintText = "成功!"; times++; + RfidHandleBusniess.staffId = user.StaffId; } else { @@ -86,6 +88,11 @@ namespace SlnMesnac.WPF.ViewModel HintText = "没有匹配的员工,打卡失败!"; } } + else + { + HintText = "已成功,请勿重打!"; + times = 1; + } } }; } diff --git a/SlnMesnac.WPF/Views/ProductionReportWin.xaml b/SlnMesnac.WPF/Views/ProductionReportWin.xaml index d519b18..6798a93 100644 --- a/SlnMesnac.WPF/Views/ProductionReportWin.xaml +++ b/SlnMesnac.WPF/Views/ProductionReportWin.xaml @@ -139,21 +139,24 @@ + - - + -