using AutoMapper; using HandyControl.Data; using LogoForceTestApp.Modules.MainModule.Models; using Prism.Commands; using Prism.Mvvm; using Repository; using Repository.Entiies; using Serilog; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace LogoForceTestApp.Modules.MainModule.ViewModels { internal class QualityTracingViewModel : BindableBase { public List InfNew { get; set; } private readonly IMapper _mapper; private readonly List _infNew; public int PageIndex { get; set; } = 1; public int MaxCount { get; set; } = 1; public int PageCount { get; set; } = 20; public DateTime SelectedStartDate { get; set; } public DateTime SelectedEndDate { get; set; } public DelegateCommand> PageUpdatedCmd => new(PageUpdated); private readonly IRepository repository; public string OperatorCode { get; set; } public DelegateCommand QueryCommand { get; set; } public QualityTracingViewModel(IMapper mapper, IRepository repository) { SelectedStartDate = DateTime.Today; SelectedEndDate = DateTime.Today; InfNew = new List(); _infNew=new List(); _mapper = mapper; // QueryCommand = new DelegateCommand(query); this.repository = repository; } /// /// 页码改变 /// private void PageUpdated(FunctionEventArgs info) { InfNew = _infNew.Skip((info.Info - 1) * PageCount).Take(PageCount).Reverse().ToList(); } public int GeneralTime { get; set; } public int AllNumber { get; set; } private void query() { if (SelectedEndDate < SelectedStartDate || SelectedStartDate == default) { MessageBox.Show("请选择正确的日期", "提示"); return; } _infNew.Clear(); var endTime = SelectedEndDate.AddDays(1); var list = repository.GetAllQuery(c => c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate&& c.CreateTime <= endTime); //var list = repository.GetAllQuery(c => c.OperatorCode == OperatorCode && c.CreateTime >= DateTime.Today); GeneralTime = list.Sum(c => c.SpendTime);//个人生产总时间 AllNumber = list.Count();//个人生产总量 list.Reverse(); var dtos = _mapper.Map>(list); _infNew.AddRange(dtos); InfNew = _infNew.Take(PageCount).ToList(); MaxCount =_infNew.Count / PageCount + 1; } } }