123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- 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<Information> InfNew { get; set; }
- private readonly IMapper _mapper;
- private readonly List<Information> _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<FunctionEventArgs<int>> 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<string> ChoiceNames { get; set; }
- #endregion
- string prono;
- public QualityTracingViewModel(IMapper mapper, IRepository repository)
- {
- SelectedStartDate = DateTime.Today;
- SelectedEndDate = DateTime.Today;
- InfNew = new List<Information>();
- _infNew=new List<Information>();
- _mapper = mapper;
-
- //
- QueryCommand = new DelegateCommand(query);
- ShowMoneyCommand = new DelegateCommand(ShowMoney);
- this.repository = repository;
- ChoiceNames = new ObservableCollection<string>();
- 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;
- }
- /// <summary>
- /// 页码改变
- /// </summary>
- private void PageUpdated(FunctionEventArgs<int> 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<Information> list = new List<Information>();
- if (FindContent != "")
- {
- if (SelectedNames == "人员ID")
- {
- list = repository.GetAllQuery<Information>(c => c.OperatorCode == FindContent && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
- GeneralTime = list.Sum(c => c.SpendTime);//个人生产总时间
- AllNumber = list.Count();//个人生产总量
- }
- if (SelectedNames == "工作机台")
- {
- list = repository.GetAllQuery<Information>(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<Information>(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<Information>(c => c.ProNo == prono && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
- }
- }
- //var res_60 = repository.GetAllQuery<Information>(c => c.ProType=="P60"&&c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
- //P60Num = res_60.Count();
- //var res_70 = repository.GetAllQuery<Information>(c => c.ProType == "P70" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
- //P70Num = res_70.Count();
- //var res_80 = repository.GetAllQuery<Information>(c => c.ProType == "P80" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
- //P80Num = res_80.Count();
- //var res_90 = repository.GetAllQuery<Information>(c => c.ProType == "P90" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
- //P90Num = res_90.Count();
- //var res_T29 = repository.GetAllQuery<Information>(c => c.ProType == "T29" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
- //T29Num = res_T29.Count();
- //var res_DH88 = repository.GetAllQuery<Information>(c => c.ProType == "DH-88" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
- //DH88Num = res_DH88.Count();
- //var res_QL1 = repository.GetAllQuery<Information>(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<Information>>(list);
- _infNew.AddRange(dtos);
- InfNew = _infNew.Take(PageCount).ToList();
- MaxCount =_infNew.Count / PageCount + 1;
- }
-
- }
-
- }
|