136 lines
4.5 KiB
C#
136 lines
4.5 KiB
C#
using Prism.Commands;
|
||
using Prism.Mvvm;
|
||
using Prism.Regions;
|
||
using Prism.Services.Dialogs;
|
||
using SqlSugar;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using DM_Weight.Models;
|
||
using DM_Weight.util;
|
||
using DM_Weight.Common;
|
||
|
||
namespace DM_Weight.ViewModels
|
||
{
|
||
public class ReturnEmptyWindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime
|
||
{
|
||
|
||
|
||
|
||
private List<ChannelStock>? _channelStocks;
|
||
|
||
public List<ChannelStock>? Channels
|
||
{
|
||
get { return _channelStocks; }
|
||
set { SetProperty(ref _channelStocks, value); }
|
||
}
|
||
|
||
private ChannelStock _channelStock;
|
||
|
||
public ChannelStock Channel
|
||
{
|
||
get { return _channelStock; }
|
||
set { SetProperty(ref _channelStock, value); }
|
||
}
|
||
|
||
IDialogService _dialogService;
|
||
public ReturnEmptyWindowViewModel(IDialogService dialogService)
|
||
{
|
||
_dialogService = dialogService;
|
||
}
|
||
|
||
public DelegateCommand RowSelected
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
|
||
if (Channel != null && Channel.DrugId == null)
|
||
{
|
||
DialogParameters dialogParameters = new DialogParameters();
|
||
dialogParameters.Add("DrawerNo", Channel.DrawerNo);
|
||
DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelDialog", dialogParameters, DoDialogResult, "RootDialog");
|
||
}
|
||
else if(Channel != null && Channel.CanReturnQuantity > 0)
|
||
{
|
||
DialogParameters dialogParameters = new DialogParameters();
|
||
dialogParameters.Add("channel", Channel);
|
||
DialogServiceExtensions.ShowDialogHost(_dialogService, "ReturnEmptyDialog", dialogParameters, DoDialogResult, "RootDialog");
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
private void DoDialogResult(IDialogResult dialogResult)
|
||
{
|
||
// 委托 被动执行 被子窗口执行
|
||
// dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态
|
||
RequestData();
|
||
//MessageBox.Show("返回值:" + dialogResult.Result.ToString());
|
||
}
|
||
|
||
public bool KeepAlive => false;
|
||
|
||
|
||
public DelegateCommand Query
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
RequestData();
|
||
});
|
||
}
|
||
|
||
//这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作
|
||
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
|
||
{
|
||
continuationCallback(true);
|
||
}
|
||
|
||
|
||
//接收导航传过来的参数
|
||
public void OnNavigatedTo(NavigationContext navigationContext)
|
||
{
|
||
//查询表格数据
|
||
RequestData();
|
||
}
|
||
|
||
void RequestData()
|
||
{
|
||
|
||
Channels = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
||
.LeftJoin<DrugInfo>((cs,di) => cs.DrugId == di.DrugId.ToString())
|
||
.Where((cs) => cs.DrawerType != (Int32)DrawerTypeEnum.drawerTypeOne)
|
||
.Select((cs, di) => new ChannelStock{
|
||
CanReturnQuantity = SqlFunc.Subqueryable<MachineRecord>().Where(mr => mr.DrugId == cs.DrugId).Where(mr => mr.Type == 2).Where(mr => mr.Status != 2).Select(mr => SqlFunc.IsNull(SqlFunc.AggregateSumNoNull(mr.Quantity - mr.ReturnQuantity1 - mr.ReturnQuantity2), 0)) ,
|
||
DrugInfo = new DrugInfo
|
||
{
|
||
DrugId = di.DrugId,
|
||
DrugName = di.DrugName,
|
||
DrugSpec = di.DrugSpec,
|
||
Manufactory = di.Manufactory,
|
||
PackUnit = di.PackUnit,
|
||
},
|
||
Quantity = cs.Quantity
|
||
}, true)
|
||
.OrderBy(cs => cs.DrawerNo)
|
||
.OrderBy(cs => cs.ColNo)
|
||
.ToList()
|
||
;
|
||
_ = Channels.Count;
|
||
}
|
||
|
||
//每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建
|
||
public bool IsNavigationTarget(NavigationContext navigationContext)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
//这个方法用于拦截请求
|
||
public void OnNavigatedFrom(NavigationContext navigationContext)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|