StatementPageViewModel.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using OxyPlot.Axes;
  2. using OxyPlot.Legends;
  3. using OxyPlot.Series;
  4. using OxyPlot;
  5. using Prism.Commands;
  6. using Prism.Ioc;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Prism.Mvvm;
  13. using Repository;
  14. using Repository.Entiies;
  15. using System.Data;
  16. using System.Windows.Forms;
  17. using TickStyle = OxyPlot.Axes.TickStyle;
  18. using AutoMapper;
  19. using HandyControl.Data;
  20. namespace LogoForceTestApp.Modules.MainModule.ViewModels
  21. {
  22. public class StatementPageViewModel : BindableBase
  23. {
  24. public List<Information> InfNew { get; set; }
  25. private readonly IMapper _mapper;
  26. private readonly List<Information> _infNew;
  27. public int PageIndex { get; set; } = 1;
  28. public int MaxCount { get; set; } = 1;
  29. public int PageCount { get; set; } = 20;
  30. public DateTime SelectedStartDate { get; set; }
  31. public DateTime SelectedEndDate { get; set; }
  32. public DelegateCommand<FunctionEventArgs<int>> PageUpdatedCmd => new(PageUpdated);
  33. private readonly IRepository repository;
  34. public string ProCode { get; set; }
  35. public DelegateCommand QueryCommand { get; set; }
  36. public StatementPageViewModel(IMapper mapper, IRepository repository)
  37. {
  38. SelectedStartDate = DateTime.Today;
  39. SelectedEndDate = DateTime.Today;
  40. InfNew = new List<Information>();
  41. _infNew = new List<Information>();
  42. _mapper = mapper;
  43. //
  44. QueryCommand = new DelegateCommand(query);
  45. this.repository = repository;
  46. }
  47. /// <summary>
  48. /// 页码改变
  49. /// </summary>
  50. private void PageUpdated(FunctionEventArgs<int> info)
  51. {
  52. InfNew = _infNew.Skip((info.Info - 1) * PageCount).Take(PageCount).Reverse().ToList();
  53. }
  54. public double GeneralTime { get; set; }
  55. public int AllNumber { get; set; }
  56. string prono;
  57. private void query()
  58. {
  59. try
  60. {
  61. if (SelectedEndDate < SelectedStartDate || SelectedStartDate == default)
  62. {
  63. MessageBox.Show("请选择正确的日期", "提示");
  64. return;
  65. }
  66. _infNew.Clear();
  67. var endTime = SelectedEndDate.AddDays(1);
  68. if (ProCode != "")
  69. {
  70. var res = repository.GetAllQuery<Information>(c => c.ProCode == ProCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  71. if (res[0].ProNo != "")
  72. { prono = res[0].ProNo; }
  73. else { prono = res[1].ProNo; }
  74. var list = repository.GetAllQuery<Information>(c => c.ProNo == prono && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  75. list.Reverse();
  76. var dtos = _mapper.Map<List<Information>>(list);
  77. _infNew.AddRange(dtos);
  78. }
  79. InfNew = _infNew.Take(PageCount).ToList();
  80. MaxCount = _infNew.Count / PageCount + 1;
  81. }
  82. catch (Exception ex)
  83. {
  84. MessageBox.Show("StatementPage:" + ex.Message);
  85. }
  86. }
  87. }
  88. }