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 HandOverViewModel : INotifyPropertyChanged { private IBaseStaffService _baseStaffService; private ProdPlanInfoService _prodPlanInfoService; private ProdPlanDetailService _prodPlanDetailService; private IRecordStaffAttendanceService _recordStaffAttendanceService; private ProdPLanInfo planInfo; private ProdPlanDetail planDetail; private int times; #region /// /// 按钮文字转换事件 /// public event PropertyChangedEventHandler PropertyChanged = delegate { }; #endregion public HandOverViewModel() { _prodPlanDetailService = App.ServiceProvider.GetService(); _prodPlanInfoService = App.ServiceProvider.GetService(); _recordStaffAttendanceService = App.ServiceProvider.GetService(); planInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions("", "", "", "", "1").FirstOrDefault(); HandoverCommand = new RelayCommand(Handover); Init(); _baseStaffService = App.ServiceProvider.GetService(); } /// /// 初始化 /// private void Init() { if(planInfo != null) { planDetail = _prodPlanDetailService.GetPlanDetailsByPlanCode(planInfo.PlanCode); //_recordStaffAttendanceService.GetLastestOffRecord(); //PlanAmountText = planDetail.PlanAmount.ToString(); //CompleteAmountText = planDetail.CompleteAmount.ToString(); //hidUtils.Initial(); //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 = "没有匹配的员工,打卡失败!"; // } // } // } //}; } } #region 参数 /// /// 计划数量Text /// private string planAmountText; public string PlanAmountText { get { return planAmountText; } set { planAmountText = value; OnPropertyChanged("PlanAmountText"); } } /// /// 完成数量Text /// private string completeAmountText; public string CompleteAmountText { get { return completeAmountText; } set { completeAmountText = value; OnPropertyChanged("CompleteAmountText"); } } /// /// 员工id /// private string staffIdText; public string StaffIdText { get { return staffIdText; } set { staffIdText = value; OnPropertyChanged("StaffIdText"); } } /// /// 员工名称 /// private string staffNameText; public string StaffNameText { get { return staffNameText; } set { staffNameText = value; OnPropertyChanged("StaffNameText"); } } /// /// 员工类型 /// private string staffTypeText; public string StaffTypeText { get { return staffTypeText; } set { staffTypeText = value; OnPropertyChanged("StaffTypeText"); } } /// /// 班组编号 /// private string teamCodeText; public string TeamCodeText { get { return teamCodeText; } set { teamCodeText = value; OnPropertyChanged("TeamCodeText"); } } /// /// 提示信息 /// private string hintText; public string HintText { get { return hintText; } set { hintText = value; OnPropertyChanged("HintText"); } } /// /// 信息 /// private string messageText; public string MessageText { get { return messageText; } set { messageText = value; OnPropertyChanged("MessageText"); } } #endregion /// /// 确认交班 /// public ICommand HandoverCommand { get; private set; } private void Handover() { //判断两个班长是否都已打卡 if(times == 2) { //在工单明细插入一条,记录两个班长 EmployeeLoginViewModel.hidUtils.StopScan(); //关闭窗口 MainWindowViewModel.wins = 1; Application.Current.Windows.OfType().First().Close(); } else { HintText = "有人未打卡,请检查!"; } } public void OnPropertyChanged([CallerMemberName] string propertyName = "") { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }