XiangTan_DM/DM_Weight/ViewModels/MachineRecordWindowViewMode...

210 lines
5.6 KiB
C#
Raw Permalink Normal View History

2024-12-03 13:22:42 +08:00
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using DM_Weight.Models;
using DM_Weight.Port;
using DM_Weight.Report;
using DM_Weight.util;
using gregn6Lib;
using Newtonsoft.Json;
using System.IO;
using System.Configuration;
namespace DM_Weight.ViewModels
{
public class MachineRecordWindowViewModel : BindableBase, IConfirmNavigationRequest, 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 int _type;
public int Type
{
get { return _type; }
set
{
SetProperty(ref _type, value);
}
}
private List<MachineRecord>? machineRecords;
public List<MachineRecord>? MachineRecords
{
get { return machineRecords; }
set { SetProperty(ref machineRecords, value); }
}
public MachineRecordWindowViewModel()
{
}
public bool KeepAlive => false;
public DelegateCommand Query
{
get => new DelegateCommand(() =>
{
RequestData();
});
}
public DelegateCommand Download
{
get => new DelegateCommand(() =>
{
GridReportUtil.PrintReportMechineRecord(Type, StartDate, EndDate);
});
}
public DelegateCommand DownloadAccountBook
{
get => new DelegateCommand(() =>
{
GridReportUtil.PrintReportAccountBook(StartDate, EndDate);
});
}
void ReportInitialize()
{
}
//这个方法用于拦截请求,continuationCallback(true)就是不拦截continuationCallback(false)拦截本次操作
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
{
continuationCallback(true);
}
//接收导航传过来的参数
public void OnNavigatedTo(NavigationContext navigationContext)
{
//取出Type决定页面显示内容
Type = navigationContext.Parameters.GetValue<int>("Type");
//查询表格数据
RequestData();
}
void RequestData()
{
int totalCount = 0;
string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1";
MachineRecords = SqlSugarHelper.Db.Queryable<MachineRecord>()
.Includes<DrugInfo>(mr => mr.DrugInfo)
.Includes<UserList>(mr => mr.User)
.Where(mr => mr.MachineId == machineId)
.WhereIF(Type == 3, (mr) => new int[] { 31, 32 }.Contains(mr.Type))
.WhereIF(Type != 3, (mr) => mr.Type == Type )
.WhereIF(StartDate !=null, (mr) => mr.OperationTime > StartDate)
.WhereIF(EndDate!=null, (mr) => mr.OperationTime < EndDate)
//.Select(mr => mr)
.ToPageList(PageNum, PageSize, ref totalCount);
//.ToList();
TotalCount = totalCount;
}
//每次导航的时候该实列用不用重新创建true是不重新创建,false是重新创建
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
//这个方法用于拦截请求
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
}
}