12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using AutoMapper;
- using HandyControl.Controls;
- using LogForceTestApp.Modules.MainModule.Models;
- using LogoForceTestApp.Modules.MainModule.Models;
- using Prism.Commands;
- using Prism.Mvvm;
- using Repository;
- using Repository.Entiies;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace LogoForceTestApp.Modules.MainModule.ViewModels
- {
- public class DataPageViewModel:BindableBase
- {
- private readonly IMapper _mapper;
- private readonly IRepository _repository;
- //private readonly List<TestResultDto> _logModels;
- private readonly List<Information> _logModels;
- public DateTime SelectedStartDate { get; set; }
- public DateTime SelectedEndDate { get; set; }
- //public List<TestResultDto> LogModels { get; set; }
- public List<Information> LogModels { get; set; }
- public int PageIndex { get; set; } = 1;
- public int MaxCount { get; set; } = 1;
- public int PageCount { get; set; } = 20;
- public int AllPro { get; set; }
- public DelegateCommand QueryCommand { get; set; }
- public DataPageViewModel(IMapper mapper, IRepository repository)
- {
-
- _mapper = mapper;
- _repository = repository;
-
- SelectedStartDate = DateTime.Today;
- SelectedEndDate = DateTime.Today;
- //LogModels = new List<TestResultDto>();
- LogModels = new List<Information>();
- _mapper = mapper;
- _repository = repository;
- //_logModels = new List<TestResultDto>();
- _logModels = new List<Information>();
- InitData().Await();
- QueryCommand = new DelegateCommand(async () =>
- {
- await QueryData();
- });
- }
-
- private async Task InitData()
- {
- var dateTimeToday = DateTime.Today;
- //var logs = await _repository.GetAllQueryAsync<TestResult>(c => c.Datetime >= dateTimeToday);
- var logs = await _repository.GetAllQueryAsync<Information>(c => c.CreateTime >= dateTimeToday);
- //var dtos = _mapper.Map<List<TestResultDto>>(logs);
- var dtos = _mapper.Map<List<Information>>(logs);
- dtos.Reverse();
- _logModels.AddRange(dtos);
- LogModels = _logModels.Take(PageCount).ToList();
- MaxCount = _logModels.Count / PageCount + 1;
- }
- private async Task QueryData()
- {
- if (SelectedEndDate < SelectedStartDate || SelectedStartDate == default)
- {
- MessageBox.Show("请选择正确的日期", "提示");
- return;
- }
- _logModels.Clear();
- var endTime = SelectedEndDate.AddDays(1);
- //var logs = (await _repository.GetAllQueryAsync<TestResult>(c => c.Datetime >= SelectedStartDate && c.Datetime <= endTime));
- var logs = (await _repository.GetAllQueryAsync<Information>(c => c.CreateTime >= SelectedStartDate && c.CreateTime <= endTime));
- logs.Reverse();
- AllPro = logs.Count();//当日生产总量
- //var dtos = _mapper.Map<List<TestResultDto>>(logs);
- var dtos = _mapper.Map<List<Information>>(logs);
- _logModels.AddRange(dtos);
- LogModels = _logModels.Take(PageCount).ToList();
- MaxCount = _logModels.Count / PageCount + 1;
- }
- }
- }
|