HuNan_DM/DM_Weight/ViewModels/CheckRecordDetailDialogView...

202 lines
6.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DM_Weight.Models;
using DM_Weight.msg;
using DM_Weight.Port;
using DM_Weight.Report;
using DM_Weight.util;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace DM_Weight.ViewModels
{
public class CheckRecordDetailDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime
{
public string Title => "盘点记录明细";
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 string _optDate;
public string OptDate
{
get => _optDate;
set
{
SetProperty(ref _optDate, value);
}
}
private ObservableCollection<CheckRecordStock> _obsCheckRecordStock = new ObservableCollection<CheckRecordStock>();
public ObservableCollection<CheckRecordStock> obsCheckRecordStock
{
get => _obsCheckRecordStock;
set => SetProperty(ref _obsCheckRecordStock, value);
}
private CheckRecordStock _checkRecordStock = new CheckRecordStock();
public CheckRecordStock checkRecordStock
{
get => _checkRecordStock;
set => SetProperty(ref _checkRecordStock, value);
}
private List<CheckRecordStock>? _channelStocks = new();
public List<CheckRecordStock>? ChannelStocks
{
get => _channelStocks;
set => SetProperty(ref _channelStocks, value);
}
////private SqlSugarScope SqlSugarHelper.Db;
private PortUtil _portUtil;
IEventAggregator _eventAggregator;
public event Action<IDialogResult> RequestClose;
public CheckRecordDetailDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService dialogService)
{
////this.SqlSugarHelper.Db = sqlSugarScope;
_portUtil = portUtil;
_eventAggregator = eventAggregator;
}
public void RequestData()
{
ChannelStocks.Clear();
obsCheckRecordStock.Clear();
//string strSql = "SELECT optDate AS optdate,U.User_name AS operatorUser,R.User_name AS reviewerUser,Drug_ID AS drugId,Drug_name AS drugName FROM check_stock C LEFT JOIN user_list U ON C.operator=U.ID LEFT JOIN user_list R ON C.reviewer=R.ID WHERE 1=1";
//if (StartDate != null)
//{
// strSql += " AND C.optDate=@OPTSTARTDATE ";
//}
//strSql += " GROUP BY C.optdate,Drug_id ORDER BY C.OPTDATE DESC";
List<CheckRecordStock> checkList = SqlSugarHelper.Db.Queryable<CheckRecordStock>()
.Includes<DrugInfo>(cs => cs.DrugInfo)
.Where(cs => cs.optdate == OptDate).OrderByDescending(cs => cs.optdate)
.WhereIF(App.SingleModel, cs => cs.rowNo <= 2) //单人登录开前2个抽屉双人登录开后14个抽屉
.WhereIF(!(App.SingleModel), cs => cs.rowNo > 2)
.ToList();
ICollectionView vw = CollectionViewSource.GetDefaultView(checkList);
vw.GroupDescriptions.Add(new PropertyGroupDescription("DrugInfo"));
obsCheckRecordStock = new ObservableCollection<CheckRecordStock>(checkList);
ChannelStocks = checkList;
}
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
if (parameters.ContainsKey("OptDate"))
{
OptDate = parameters.GetValue<string>("OptDate");
}
RequestData();
}
public DelegateCommand BtnCloseCommand {
get => new DelegateCommand(() =>
{
// 关闭当前窗口
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
});
}
public bool KeepAlive => true;
}
}