QualityTracingViewModel.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #region 价钱
  32. public double P60_Price { get; set; }
  33. public double P70_Price { get; set; }
  34. public double P80_Price { get; set; }
  35. public double P90_Price { get; set; }
  36. public double T29_Price { get; set; }
  37. public double DH88_Price { get; set; }
  38. public double QL1_Price { get; set; }
  39. public double P60Num { get; set; }
  40. public double P70Num { get; set; }
  41. public double P80Num { get; set; }
  42. public double P90Num { get; set; }
  43. public double T29Num { get; set; }
  44. public double DH88Num { get; set; }
  45. public double QL1Num { get; set; }
  46. public double Money { get; set; }
  47. public DelegateCommand ShowMoneyCommand { get; set; }
  48. #endregion
  49. public QualityTracingViewModel(IMapper mapper, IRepository repository)
  50. {
  51. SelectedStartDate = DateTime.Today;
  52. SelectedEndDate = DateTime.Today;
  53. InfNew = new List<Information>();
  54. _infNew=new List<Information>();
  55. _mapper = mapper;
  56. //
  57. QueryCommand = new DelegateCommand(query);
  58. ShowMoneyCommand = new DelegateCommand(ShowMoney);
  59. this.repository = repository;
  60. }
  61. private void ShowMoney()
  62. {
  63. Money = P60_Price * P60Num + P70_Price * P70Num + P80_Price * P80Num + P90_Price * P90Num
  64. + T29_Price * T29Num + DH88_Price * DH88Num + QL1_Price * QL1Num;
  65. }
  66. /// <summary>
  67. /// 页码改变
  68. /// </summary>
  69. private void PageUpdated(FunctionEventArgs<int> info)
  70. {
  71. InfNew = _infNew.Skip((info.Info - 1) * PageCount).Take(PageCount).Reverse().ToList();
  72. }
  73. public double GeneralTime { get; set; }
  74. public int AllNumber { get; set; }
  75. private void query()
  76. {
  77. if (SelectedEndDate < SelectedStartDate || SelectedStartDate == default)
  78. {
  79. MessageBox.Show("请选择正确的日期", "提示");
  80. return;
  81. }
  82. _infNew.Clear();
  83. var endTime = SelectedEndDate.AddDays(1);
  84. var list = repository.GetAllQuery<Information>(c => c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate&& c.CreateTime <= endTime);
  85. GeneralTime = list.Sum(c => c.SpendTime);//个人生产总时间
  86. AllNumber = list.Count();//个人生产总量
  87. var res_60 = repository.GetAllQuery<Information>(c => c.ProType=="P60"&&c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  88. P60Num = res_60.Count();
  89. var res_70 = repository.GetAllQuery<Information>(c => c.ProType == "P70" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  90. P70Num = res_70.Count();
  91. var res_80 = repository.GetAllQuery<Information>(c => c.ProType == "P80" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  92. P80Num = res_80.Count();
  93. var res_90 = repository.GetAllQuery<Information>(c => c.ProType == "P90" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  94. P90Num = res_90.Count();
  95. var res_T29 = repository.GetAllQuery<Information>(c => c.ProType == "T29" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  96. T29Num = res_T29.Count();
  97. var res_DH88 = repository.GetAllQuery<Information>(c => c.ProType == "DH-88" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  98. DH88Num = res_DH88.Count();
  99. var res_QL1 = repository.GetAllQuery<Information>(c => c.ProType == "QL-1" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  100. QL1Num = res_QL1.Count();
  101. list.Reverse();
  102. var dtos = _mapper.Map<List<Information>>(list);
  103. _infNew.AddRange(dtos);
  104. InfNew = _infNew.Take(PageCount).ToList();
  105. MaxCount =_infNew.Count / PageCount + 1;
  106. }
  107. }
  108. }