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.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Documents; 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 FindContent { get; set; } public DelegateCommand QueryCommand { get; set; } #region 价钱 public double P60_Price { get; set; } public double P70_Price { get; set; } public double P80_Price { get; set; } public double P90_Price { get; set; } public double T29_Price { get; set; } public double DH88_Price { get; set; } public double QL1_Price { get; set; } public double P60Num { get; set; } public double P70Num { get; set; } public double P80Num { get; set; } public double P90Num { get; set; } public double T29Num { get; set; } public double DH88Num { get; set; } public double QL1Num { get; set; } public double Money { get; set; } public DelegateCommand ShowMoneyCommand { get; set; } public string SelectedNames { get; set; } public ObservableCollection ChoiceNames { get; set; } #endregion string prono; public QualityTracingViewModel(IMapper mapper, IRepository repository) { SelectedStartDate = DateTime.Today; SelectedEndDate = DateTime.Today; InfNew = new List(); _infNew=new List(); _mapper = mapper; // QueryCommand = new DelegateCommand(query); ShowMoneyCommand = new DelegateCommand(ShowMoney); this.repository = repository; ChoiceNames = new ObservableCollection(); ChoiceNames.Add("人员ID"); ChoiceNames.Add("工作机台"); ChoiceNames.Add("产品码"); } private void ShowMoney() { Money = P60_Price * P60Num + P70_Price * P70Num + P80_Price * P80Num + P90_Price * P90Num + T29_Price * T29Num + DH88_Price * DH88Num + QL1_Price * QL1Num; } /// /// 页码改变 /// private void PageUpdated(FunctionEventArgs info) { InfNew = _infNew.Skip((info.Info - 1) * PageCount).Take(PageCount).Reverse().ToList(); } public double 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); List list = new List(); if (FindContent != "") { if (SelectedNames == "人员ID") { list = repository.GetAllQuery(c => c.OperatorCode == FindContent && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); GeneralTime = list.Sum(c => c.SpendTime);//个人生产总时间 AllNumber = list.Count();//个人生产总量 } if (SelectedNames == "工作机台") { list = repository.GetAllQuery(c => c.WorkDev == FindContent && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); GeneralTime = list.Sum(c => c.SpendTime);//个人生产总时间 AllNumber = list.Count();//个人生产总量 } if (SelectedNames == "产品码") { var res = repository.GetAllQuery(c => c.ProCode == FindContent && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); if (res.Count!=0) { if (res[0].ProNo != "") { prono = res[0].ProNo; } else { prono = res[1].ProNo; } } list = repository.GetAllQuery(c => c.ProNo == prono && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); } } //var res_60 = repository.GetAllQuery(c => c.ProType=="P60"&&c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); //P60Num = res_60.Count(); //var res_70 = repository.GetAllQuery(c => c.ProType == "P70" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); //P70Num = res_70.Count(); //var res_80 = repository.GetAllQuery(c => c.ProType == "P80" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); //P80Num = res_80.Count(); //var res_90 = repository.GetAllQuery(c => c.ProType == "P90" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); //P90Num = res_90.Count(); //var res_T29 = repository.GetAllQuery(c => c.ProType == "T29" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); //T29Num = res_T29.Count(); //var res_DH88 = repository.GetAllQuery(c => c.ProType == "DH-88" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); //DH88Num = res_DH88.Count(); //var res_QL1 = repository.GetAllQuery(c => c.ProType == "QL-1" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime); //QL1Num = res_QL1.Count(); list.Reverse(); var dtos = _mapper.Map>(list); _infNew.AddRange(dtos); InfNew = _infNew.Take(PageCount).ToList(); MaxCount =_infNew.Count / PageCount + 1; } } }