147 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			147 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C#
		
	
	
	
using DM_Weight.Models;
 | 
						|
using DM_Weight.util;
 | 
						|
using log4net;
 | 
						|
using log4net.Repository.Hierarchy;
 | 
						|
using Prism.Commands;
 | 
						|
using Prism.Mvvm;
 | 
						|
using Prism.Regions;
 | 
						|
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Configuration;
 | 
						|
using System.Linq;
 | 
						|
using System.Text;
 | 
						|
using System.Threading.Tasks;
 | 
						|
 | 
						|
namespace DM_Weight.ViewModels
 | 
						|
{
 | 
						|
    public class WSDRecordWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime
 | 
						|
    {
 | 
						|
        private readonly ILog logger = LogManager.GetLogger(typeof(WSDRecordWindowViewModel));
 | 
						|
        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<TemperatureHumidityInfo>? _temperatureHumidityInfos;
 | 
						|
 | 
						|
        public List<TemperatureHumidityInfo>? TemperatureHumidityInfos
 | 
						|
        {
 | 
						|
            get { return _temperatureHumidityInfos; }
 | 
						|
            set { SetProperty(ref _temperatureHumidityInfos, value); }
 | 
						|
        }
 | 
						|
        public DelegateCommand Query
 | 
						|
        {
 | 
						|
            get => new DelegateCommand(() =>
 | 
						|
            {
 | 
						|
                RequestData();
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
        public bool KeepAlive => false;
 | 
						|
 | 
						|
        void RequestData()
 | 
						|
        {
 | 
						|
            int totalCount = 0;
 | 
						|
            string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM5";
 | 
						|
            TemperatureHumidityInfos = SqlSugarHelper.Db.Queryable<TemperatureHumidityInfo>()
 | 
						|
                .Where(mr => mr.GroupNo == machineId)
 | 
						|
                .WhereIF(StartDate != null, (mr) => mr.AddTime > StartDate)
 | 
						|
                .WhereIF(EndDate != null, (mr) => mr.AddTime < EndDate).OrderByDescending(mr => mr.AddTime)
 | 
						|
                .ToPageList(PageNum, PageSize, ref totalCount);
 | 
						|
            //.ToList();
 | 
						|
            TotalCount = totalCount;
 | 
						|
        }
 | 
						|
 | 
						|
        public void OnNavigatedTo(NavigationContext navigationContext)
 | 
						|
        {
 | 
						|
            logger.Info("进入OnNavigatedTo");
 | 
						|
            RequestData();
 | 
						|
            logger.Info("结束");
 | 
						|
        }
 | 
						|
 | 
						|
        public bool IsNavigationTarget(NavigationContext navigationContext)
 | 
						|
        {
 | 
						|
            return true;
 | 
						|
        }
 | 
						|
 | 
						|
        public void OnNavigatedFrom(NavigationContext navigationContext)
 | 
						|
        {
 | 
						|
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |