QualityTracingViewModel.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.Collections.ObjectModel;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. using System.Windows.Documents;
  17. namespace LogoForceTestApp.Modules.MainModule.ViewModels
  18. {
  19. internal class QualityTracingViewModel : BindableBase
  20. {
  21. public List<Information> InfNew { get; set; }
  22. private readonly IMapper _mapper;
  23. private readonly List<Information> _infNew;
  24. public int PageIndex { get; set; } = 1;
  25. public int MaxCount { get; set; } = 1;
  26. public int PageCount { get; set; } = 20;
  27. public DateTime SelectedStartDate { get; set; }
  28. public DateTime SelectedEndDate { get; set; }
  29. public DelegateCommand<FunctionEventArgs<int>> PageUpdatedCmd => new(PageUpdated);
  30. private readonly IRepository repository;
  31. public string FindContent { get; set; }
  32. public DelegateCommand QueryCommand { get; set; }
  33. #region 价钱
  34. public double P60_Price { get; set; }
  35. public double P70_Price { get; set; }
  36. public double P80_Price { get; set; }
  37. public double P90_Price { get; set; }
  38. public double T29_Price { get; set; }
  39. public double DH88_Price { get; set; }
  40. public double QL1_Price { get; set; }
  41. public double P60Num { get; set; }
  42. public double P70Num { get; set; }
  43. public double P80Num { get; set; }
  44. public double P90Num { get; set; }
  45. public double T29Num { get; set; }
  46. public double DH88Num { get; set; }
  47. public double QL1Num { get; set; }
  48. public double Money { get; set; }
  49. public DelegateCommand ShowMoneyCommand { get; set; }
  50. public string SelectedNames { get; set; }
  51. public ObservableCollection<string> ChoiceNames { get; set; }
  52. #endregion
  53. string prono;
  54. public QualityTracingViewModel(IMapper mapper, IRepository repository)
  55. {
  56. SelectedStartDate = DateTime.Today;
  57. SelectedEndDate = DateTime.Today;
  58. InfNew = new List<Information>();
  59. _infNew=new List<Information>();
  60. _mapper = mapper;
  61. //
  62. QueryCommand = new DelegateCommand(query);
  63. ShowMoneyCommand = new DelegateCommand(ShowMoney);
  64. this.repository = repository;
  65. ChoiceNames = new ObservableCollection<string>();
  66. ChoiceNames.Add("人员ID");
  67. ChoiceNames.Add("工作机台");
  68. ChoiceNames.Add("产品码");
  69. }
  70. private void ShowMoney()
  71. {
  72. Money = P60_Price * P60Num + P70_Price * P70Num + P80_Price * P80Num + P90_Price * P90Num
  73. + T29_Price * T29Num + DH88_Price * DH88Num + QL1_Price * QL1Num;
  74. }
  75. /// <summary>
  76. /// 页码改变
  77. /// </summary>
  78. private void PageUpdated(FunctionEventArgs<int> info)
  79. {
  80. InfNew = _infNew.Skip((info.Info - 1) * PageCount).Take(PageCount).Reverse().ToList();
  81. }
  82. public double GeneralTime { get; set; }
  83. public int AllNumber { get; set; }
  84. private void query()
  85. {
  86. if (SelectedEndDate < SelectedStartDate || SelectedStartDate == default)
  87. {
  88. MessageBox.Show("请选择正确的日期", "提示");
  89. return;
  90. }
  91. _infNew.Clear();
  92. var endTime = SelectedEndDate.AddDays(1);
  93. List<Information> list = new List<Information>();
  94. if (FindContent != "")
  95. {
  96. if (SelectedNames == "人员ID")
  97. {
  98. list = repository.GetAllQuery<Information>(c => c.OperatorCode == FindContent && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  99. GeneralTime = list.Sum(c => c.SpendTime);//个人生产总时间
  100. AllNumber = list.Count();//个人生产总量
  101. }
  102. if (SelectedNames == "工作机台")
  103. {
  104. list = repository.GetAllQuery<Information>(c => c.WorkDev == FindContent && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  105. GeneralTime = list.Sum(c => c.SpendTime);//个人生产总时间
  106. AllNumber = list.Count();//个人生产总量
  107. }
  108. if (SelectedNames == "产品码")
  109. {
  110. var res = repository.GetAllQuery<Information>(c => c.ProCode == FindContent && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  111. if (res.Count!=0)
  112. {
  113. if (res[0].ProNo != "")
  114. { prono = res[0].ProNo; }
  115. else { prono = res[1].ProNo; }
  116. }
  117. list = repository.GetAllQuery<Information>(c => c.ProNo == prono && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  118. }
  119. }
  120. //var res_60 = repository.GetAllQuery<Information>(c => c.ProType=="P60"&&c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  121. //P60Num = res_60.Count();
  122. //var res_70 = repository.GetAllQuery<Information>(c => c.ProType == "P70" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  123. //P70Num = res_70.Count();
  124. //var res_80 = repository.GetAllQuery<Information>(c => c.ProType == "P80" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  125. //P80Num = res_80.Count();
  126. //var res_90 = repository.GetAllQuery<Information>(c => c.ProType == "P90" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  127. //P90Num = res_90.Count();
  128. //var res_T29 = repository.GetAllQuery<Information>(c => c.ProType == "T29" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  129. //T29Num = res_T29.Count();
  130. //var res_DH88 = repository.GetAllQuery<Information>(c => c.ProType == "DH-88" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  131. //DH88Num = res_DH88.Count();
  132. //var res_QL1 = repository.GetAllQuery<Information>(c => c.ProType == "QL-1" && c.OperatorCode == OperatorCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  133. //QL1Num = res_QL1.Count();
  134. list.Reverse();
  135. var dtos = _mapper.Map<List<Information>>(list);
  136. _infNew.AddRange(dtos);
  137. InfNew = _infNew.Take(PageCount).ToList();
  138. MaxCount =_infNew.Count / PageCount + 1;
  139. }
  140. }
  141. }