QualityTracingViewModel.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using AutoMapper;
  2. using HandyControl.Data;
  3. using LogoForceTestApp.Modules.MainModule.Models;
  4. using Prism.Commands;
  5. using Prism.Mvvm;
  6. using Repository;
  7. using Repository.Entiies;
  8. using Serilog;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. namespace LogoForceTestApp.Modules.MainModule.ViewModels
  16. {
  17. internal class QualityTracingViewModel : BindableBase
  18. {
  19. public List<Information> InfNew { get; set; }
  20. private readonly IMapper _mapper;
  21. private readonly List<Information> _infNew;
  22. public int PageIndex { get; set; } = 1;
  23. public int MaxCount { get; set; } = 1;
  24. public int PageCount { get; set; } = 20;
  25. public DateTime SelectedStartDate { get; set; }
  26. public DateTime SelectedEndDate { get; set; }
  27. public DelegateCommand<FunctionEventArgs<int>> PageUpdatedCmd => new(PageUpdated);
  28. private readonly IRepository repository;
  29. public string OperatorCode { get; set; }
  30. public DelegateCommand QueryCommand { get; set; }
  31. public QualityTracingViewModel(IMapper mapper, IRepository repository)
  32. {
  33. SelectedStartDate = DateTime.Today;
  34. SelectedEndDate = DateTime.Today;
  35. InfNew = new List<Information>();
  36. _infNew=new List<Information>();
  37. _mapper = mapper;
  38. //
  39. QueryCommand = new DelegateCommand(query);
  40. this.repository = repository;
  41. }
  42. /// <summary>
  43. /// 页码改变
  44. /// </summary>
  45. private void PageUpdated(FunctionEventArgs<int> info)
  46. {
  47. InfNew = _infNew.Skip((info.Info - 1) * PageCount).Take(PageCount).Reverse().ToList();
  48. }
  49. public int GeneralTime { get; set; }
  50. public int AllNumber { get; set; }
  51. private void query()
  52. {
  53. if (SelectedEndDate < SelectedStartDate || SelectedStartDate == default)
  54. {
  55. MessageBox.Show("请选择正确的日期", "提示");
  56. return;
  57. }
  58. _infNew.Clear();
  59. var endTime = SelectedEndDate.AddDays(1);
  60. var list = repository.GetAllQuery<Information>(c => c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate&& c.CreateTime <= endTime);
  61. //var list = repository.GetAllQuery<Information>(c => c.OperatorCode == OperatorCode && c.CreateTime >= DateTime.Today);
  62. GeneralTime = list.Sum(c => c.SpendTime);//个人生产总时间
  63. AllNumber = list.Count();//个人生产总量
  64. list.Reverse();
  65. var dtos = _mapper.Map<List<Information>>(list);
  66. _infNew.AddRange(dtos);
  67. InfNew = _infNew.Take(PageCount).ToList();
  68. MaxCount =_infNew.Count / PageCount + 1;
  69. }
  70. }
  71. }