HuNan_DM_MultiBatch/DM_Weight/ViewModels/ChangeShiftsRecordWindowVie...

162 lines
4.8 KiB
C#
Raw Normal View History

2023-11-13 14:00:30 +08:00
using DM_Weight.Models;
using DM_Weight.util;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
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 ChangeShiftsRecordWindowViewModel: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 List<MachineRecord>? machineRecords;
public List<MachineRecord>? MachineRecords
{
get { return machineRecords; }
set { SetProperty(ref machineRecords, value); }
}
public bool KeepAlive => false;
IDialogService _dialogService;
//交接班
public DelegateCommand ShiftsCommand => new DelegateCommand(ShiftsAction);
private void ShiftsAction()
{
DialogParameters dialogParameters = new DialogParameters();
DialogServiceExtensions.ShowDialogHost(_dialogService, "ChangeShiftsDialog", dialogParameters, DoDialogResult, "RootDialog");
}
private void DoDialogResult(IDialogResult dialogResult)
{
RequestData();
}
public ChangeShiftsRecordWindowViewModel(IDialogService dialogService)
{
_dialogService= dialogService;
}
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;
}
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
{
continuationCallback(true);
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
//查询表格数据
RequestData();
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
}
}