using DM_Weight.Models; using DM_Weight.util; using Prism.Commands; using Prism.Events; using Prism.Mvvm; using Prism.Regions; using SqlSugar; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DM_Weight.ViewModels { internal class MachineRecordWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime { private int _pageNum = 1; public int PageNum { get => _pageNum; set { SetProperty(ref _pageNum, value); RequestData(); } } private int _pageCount = 1; public int PageCount { get => _pageCount; set { SetProperty(ref _pageCount, value); } } private int _pageSize = 8; public int PageSize { get => _pageSize; set { SetProperty(ref _pageSize, value); } } private int _totalCount = 0; public int TotalCount { get => _totalCount; set { SetProperty(ref _totalCount, value); } } private DateTime? _startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); public DateTime? StartDate { get => _startDate; set { if (value != null) { SetProperty(ref _startDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0)); } else { SetProperty(ref _startDate, value); } RequestData(); } } private DateTime? _endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); public DateTime? EndDate { get => _endDate; set { if (value != null) { TimeSpan ershisi = new TimeSpan(23, 59, 59); SetProperty(ref _endDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0, 23, 59, 59)); } else { SetProperty(ref _endDate, value); } RequestData(); } } private List? machineRecords; public List? MachineRecords { get { return machineRecords; } set { SetProperty(ref machineRecords, value); } } public DelegateCommand Query { get => new DelegateCommand(() => { RequestData(); }); } public bool KeepAlive => false; public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { //查询表格数据 RequestData(); } void RequestData() { int totalCount = 0; string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM5"; MachineRecords = SqlSugarHelper.Db.Queryable() .Includes(mr => mr.DrugInfo) .Includes(mr => mr.User) .Where(mr => mr.MachineId == machineId) .WhereIF(StartDate != null, (mr) => mr.OperationTime > StartDate) .WhereIF(EndDate != null, (mr) => mr.OperationTime < EndDate).OrderByDescending(mr=>mr.OperationTime) .ToPageList(PageNum, PageSize, ref totalCount); //.ToList(); TotalCount = totalCount; } } }