XiangTan_DM/DM_Weight/ViewModels/ChangeShiftsListWindowViewM...

191 lines
5.8 KiB
C#

using DM_Weight.Models;
using DM_Weight.msg;
using DM_Weight.Port;
using DM_Weight.Report;
using DM_Weight.util;
using log4net;
using Prism.Commands;
using Prism.Events;
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 ChangeShiftsListWindowViewModel : 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<HkcChangeShifts>? hkcChangeShifts;
public List<HkcChangeShifts>? HkcChangeShifts
{
get { return hkcChangeShifts; }
set { SetProperty(ref hkcChangeShifts, value); }
}
public bool KeepAlive => true;
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 DelegateCommand Download => new DelegateCommand(DownloadAction);
private void DownloadAction()
{
GridReportUtil.PrintChangeShiftsReport(StartDate, EndDate);
}
////private SqlSugarScope SqlSugarHelper.Db;
public ChangeShiftsListWindowViewModel(IDialogService dialogService)
{
_dialogService = dialogService;
////this.SqlSugarHelper.Db = sqlSugarScope;
}
void RequestData()
{
int totalCount = 0;
string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1";
string sqlStr = @"SELECT c.id,c.OptDate,u.User_Name as fromoperator,u2.User_Name fromrviewer,u3.User_Name as tooperator,u4.User_Name as toreviewer,
c.todate,c.State from hkc_changeshifts c LEFT JOIN user_list u on c.fromoperator=u.user_id
LEFT JOIN user_list u2 on c.fromrviewer=u2.user_id LEFT JOIN user_list u3 on c.tooperator=u3.user_id
left join user_list u4 on c.toreviewer=u4.user_id where c.machine_id=@machineId ";
if (StartDate != null)
{
sqlStr += " and c.optdate>=@starOptDate ";
}
if (EndDate != null)
{
sqlStr += " and c.optdate<=@endOptDate ";
}
sqlStr += " group by c.id";
HkcChangeShifts = SqlSugarHelper.Db.SqlQueryable<dynamic>(sqlStr)
.AddParameters(new
{
machineId = machineId,
starOptDate = StartDate,
endOptDate = EndDate
})
.Select(it => new HkcChangeShifts())
//.Select("*")
.ToPageList(PageNum, PageSize, ref totalCount);
TotalCount = totalCount;
}
public DelegateCommand Query => new DelegateCommand(RequestData);
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)
{
}
}
}