StatementPageViewModel.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if (SelectedEndDate < SelectedStartDate || SelectedStartDate == default)
  60. {
  61. MessageBox.Show("请选择正确的日期", "提示");
  62. return;
  63. }
  64. _infNew.Clear();
  65. var endTime = SelectedEndDate.AddDays(1);
  66. var res = repository.GetAllQuery<Information>(c => c.ProCode == ProCode && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  67. if (res[0].ProNo != "")
  68. { prono = res[0].ProNo; }
  69. else { prono = res[1].ProNo; }
  70. var list = repository.GetAllQuery<Information>(c => c.ProNo == prono && c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime);
  71. list.Reverse();
  72. var dtos = _mapper.Map<List<Information>>(list);
  73. _infNew.AddRange(dtos);
  74. InfNew = _infNew.Take(PageCount).ToList();
  75. MaxCount = _infNew.Count / PageCount + 1;
  76. }
  77. }
  78. }