HKC/DM_Weight/ViewModels/SurgeryTakeWindowViewModel.cs

231 lines
6.9 KiB
C#
Raw Normal View History

using DM_Weight.Models;
using DM_Weight.msg;
using DM_Weight.select;
using DM_Weight.util;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.ViewModels
{
public class SurgeryTakeWindowViewModel : 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);
}
}
IDialogService _dialogService;
IEventAggregator _eventAggregator;
private DelegateCommand _rowSelected;
public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(OpenOrderDialog);
public SurgeryTakeWindowViewModel(IDialogService DialogService, IEventAggregator eventAggregator)
{
_dialogService = DialogService;
_eventAggregator = eventAggregator;
}
public static List<OrderTakeSelect> StaticOrderTakeSelects = new()
{
new OrderTakeSelect
{
Code = "OrderNo",
Name = "手术号"
}
};
private SurgicalSchedule? _selectedSurgicalSchedule;
public SurgicalSchedule? SelectedSurgicalSchedule
{
get { return _selectedSurgicalSchedule; }
set
{
SetProperty(ref _selectedSurgicalSchedule, value);
//OpenOrderDialog();
}
}
private string _scheduleTime = DateTime.Now.ToString("yyyy-MM-dd");
/// <summary>
/// 查询条件 手术计划开始时间
/// </summary>
public string ScheduleTime
{
get { return _scheduleTime; }
set
{
if (!String.IsNullOrEmpty(value))
{
SetProperty(ref _scheduleTime, DateTime.Parse(value).ToString("yyyy-MM-dd"));
}
else
{
SetProperty(ref _scheduleTime, value);
}
RequestData();
}
}
private string? _searchValue;
/// <summary>
/// 查询条件 查询字段值
/// </summary>
public string? SearchValue
{
get { return _searchValue; }
set
{
SetProperty(ref _searchValue, value);
RequestData();
}
}
private List<SurgicalSchedule> _surgicalSchedule = new();
public List<SurgicalSchedule> _SurgicalSchedule { get { return _surgicalSchedule; } set { SetProperty(ref _surgicalSchedule, value); } }
public bool KeepAlive => false;
public async void OpenOrderDialog()
{
if (SelectedSurgicalSchedule != null && SelectedSurgicalSchedule.DmStatus == 0 && SelectedSurgicalSchedule.HisState == 1)
{
// 此处延时1毫秒等待页面渲染
await Task.Delay(TimeSpan.FromMilliseconds(1));
DialogParameters dialogParameters = new DialogParameters();
dialogParameters.Add("SurgeryInfo", SelectedSurgicalSchedule);
DialogServiceExtensions.ShowDialogHost(_dialogService, "SurgeryTakeDialog", dialogParameters, DoDialogResult, "RootDialog");
}
}
private void DoDialogResult(IDialogResult dialogResult)
{
// 委托 被动执行 被子窗口执行
// dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态
//if(dialogResult.Result == ButtonResult.OK)
//{
SelectedSurgicalSchedule = null;
RequestData();
//}
//MessageBox.Show("返回值:" + dialogResult.Result.ToString());
}
//这个方法用于拦截请求,continuationCallback(true)就是不拦截continuationCallback(false)拦截本次操作
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
{
continuationCallback(true);
}
/// <summary>
/// 录入手术
/// </summary>
public DelegateCommand AddSurgeryCommand
{
get => new DelegateCommand(() => {
DialogServiceExtensions.ShowDialogHost(_dialogService, "AddSurgeryDialog", null, DoDialogResult, "RootDialog");
});
}
public DelegateCommand QueryCommand
{
get => new DelegateCommand(() =>
{
RequestData();
});
}
public void RequestData()
{
_SurgicalSchedule.Clear();
int totalCount = 0;
List<SurgicalSchedule> queryData = SqlSugarHelper.Db.Queryable<SurgicalSchedule>()
.WhereIF(ScheduleTime != null, ss => ss.ScheduleTime.ToString("yyyy-MM-dd") == ScheduleTime)
.WhereIF(!String.IsNullOrEmpty(SearchValue), ss => ss.OperationId == SearchValue)
.Where(ss => ss.DmStatus == 0)
.Where(ss => ss.HisState == 1)
.GroupBy(ss => ss.OperationId)
.ToPageList(PageNum, PageSize, ref totalCount);
_SurgicalSchedule = queryData;
TotalCount = totalCount;
PageCount = (int)Math.Ceiling((double)TotalCount / PageSize);
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
// 取消消息订阅
_eventAggregator.GetEvent<PortUtilEvent>().Unsubscribe(DoMyPrismEvent);
}
void DoMyPrismEvent(DeviceMsg msg)
{
if (msg.EventType == EventType.CODESCAN)
{
SearchValue = msg.Code;
}
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
_eventAggregator.GetEvent<PortUtilEvent>().Subscribe(DoMyPrismEvent);
RequestData();
}
}
}