123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using AutoMapper;
- using HandyControl.Controls;
- using HandyControl.Data;
- 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.Text;
- using System.Threading.Tasks;
- namespace LogoForceTestApp.Modules.MainModule.ViewModels
- {
- public class OperationLogPageViewModel:BindableBase
- {
- private readonly List<ParamLogDto> _logModels;
- private readonly IMapper _mapper;
- private readonly IRepository _repository;
- public List<ParamLogDto> LogModels { get; set; }
- public int PageIndex { get; set; } = 1;
- public int MaxCount { get; set; } = 1;
- public int PageCount { get; set; } = 20;
- public DateTime SelectedStartDate { get; set; }
- public DateTime SelectedEndDate { get; set; }
- public DelegateCommand<FunctionEventArgs<int>> PageUpdatedCmd => new(PageUpdated);
- public DelegateCommand QueryCommand { get; set; }
- /// <summary>
- /// 页码改变
- /// </summary>
- private void PageUpdated(FunctionEventArgs<int> info)
- {
- LogModels = _logModels.Skip((info.Info - 1) * PageCount).Take(PageCount).Reverse().ToList();
- }
- public OperationLogPageViewModel(IMapper mapper,IRepository repository)
- {
- SelectedStartDate = DateTime.Today;
- SelectedEndDate = DateTime.Today;
- LogModels = new List<ParamLogDto>();
- _mapper = mapper;
- _repository = repository;
- _logModels = new List<ParamLogDto>();
- InitData().Await();
- QueryCommand = new DelegateCommand(async () =>
- {
- await QueryData();
- });
- }
- private async Task InitData()
- {
-
- var dateTimeToday = DateTime.Today;
- var logs = await _repository.GetAllQueryAsync<ParamLog>(c => c.Occured >= dateTimeToday);
- var dtos = _mapper.Map<List<ParamLogDto>>(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<ParamLog>(c => c.Occured >= SelectedStartDate && c.Occured <= endTime));
- logs.Reverse();
- var dtos = _mapper.Map<List<ParamLogDto>>(logs);
- _logModels.AddRange(dtos);
- LogModels = _logModels.Take(PageCount).ToList();
- MaxCount = _logModels.Count / PageCount + 1;
- }
- }
- public class ParamLogDto
- {
- public DateTime Occured { get; set; }
- public Guid Id { get; set; }
- public string Content { get; set; }
- public OperateAction OperateAction { get; set; }
- public string OperateObject { get; set; }
- public string UserName { get; set; }
- }
- }
|