255 lines
8.0 KiB
C#
255 lines
8.0 KiB
C#
|
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.Speech.Synthesis;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows;
|
|||
|
using DM_Weight.Models;
|
|||
|
using DM_Weight.msg;
|
|||
|
using DM_Weight.Port;
|
|||
|
using DM_Weight.select;
|
|||
|
using DM_Weight.util;
|
|||
|
|
|||
|
namespace DM_Weight.ViewModels
|
|||
|
{
|
|||
|
public class ReturnDrugWindow2ViewModel : 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);
|
|||
|
}
|
|||
|
}
|
|||
|
//刷新
|
|||
|
public DelegateCommand Query
|
|||
|
{
|
|||
|
get => new DelegateCommand(() =>
|
|||
|
{
|
|||
|
RequestData();
|
|||
|
});
|
|||
|
}
|
|||
|
IDialogService _dialogService;
|
|||
|
|
|||
|
private DelegateCommand _rowSelected;
|
|||
|
|
|||
|
public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(OpenOrderDialog);
|
|||
|
|
|||
|
public ReturnDrugWindow2ViewModel(IDialogService DialogService)
|
|||
|
{
|
|||
|
_dialogService = DialogService;
|
|||
|
}
|
|||
|
|
|||
|
public static List<OrderTakeSelect> StaticOrderTakeSelects = new()
|
|||
|
{
|
|||
|
new OrderTakeSelect
|
|||
|
{
|
|||
|
Code = "OrderNo",
|
|||
|
Name = "处方号"
|
|||
|
},
|
|||
|
new OrderTakeSelect
|
|||
|
{
|
|||
|
Code = "PatientId",
|
|||
|
Name = "患者编号"
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
private List<OrderTakeSelect> _orderTakeSelects = StaticOrderTakeSelects;
|
|||
|
|
|||
|
public List<OrderTakeSelect> OrderTakeSelects
|
|||
|
{
|
|||
|
get { return _orderTakeSelects; }
|
|||
|
set
|
|||
|
{
|
|||
|
SetProperty(ref _orderTakeSelects, value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private OrderTakeSelect _selectedItem = StaticOrderTakeSelects[0];
|
|||
|
/// <summary>
|
|||
|
/// 查询条件 查询字段
|
|||
|
/// </summary>
|
|||
|
public OrderTakeSelect SelectedItem
|
|||
|
{
|
|||
|
get { return _selectedItem; }
|
|||
|
set
|
|||
|
{
|
|||
|
SetProperty(ref _selectedItem, value);
|
|||
|
RequestData();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private OrderInfo? _selectedOrder;
|
|||
|
|
|||
|
public OrderInfo? SelectedOrder
|
|||
|
{
|
|||
|
get { return _selectedOrder; }
|
|||
|
set
|
|||
|
{
|
|||
|
SetProperty(ref _selectedOrder, value);
|
|||
|
|
|||
|
//OpenOrderDialog();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private string _orderDate = DateTime.Now.ToString("yyyy-MM-dd");
|
|||
|
/// <summary>
|
|||
|
/// 查询条件 处方日期
|
|||
|
/// </summary>
|
|||
|
public string OrderDate
|
|||
|
{
|
|||
|
get { return _orderDate; }
|
|||
|
set
|
|||
|
{
|
|||
|
if (!String.IsNullOrEmpty(value))
|
|||
|
{
|
|||
|
SetProperty(ref _orderDate, DateTime.Parse(value).ToString("yyyy-MM-dd"));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SetProperty(ref _orderDate, value);
|
|||
|
}
|
|||
|
|
|||
|
RequestData();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private string? _searchValue;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 查询条件 查询字段值
|
|||
|
/// </summary>
|
|||
|
public string? SearchValue
|
|||
|
{
|
|||
|
get { return _searchValue; }
|
|||
|
set
|
|||
|
{
|
|||
|
SetProperty(ref _searchValue, value);
|
|||
|
RequestData();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private List<OrderInfo> _orderInfos = new();
|
|||
|
|
|||
|
public List<OrderInfo> OrderInfos { get { return _orderInfos; } set { SetProperty(ref _orderInfos, value); } }
|
|||
|
|
|||
|
public bool KeepAlive => false;
|
|||
|
|
|||
|
public async void OpenOrderDialog()
|
|||
|
{
|
|||
|
//if (SelectedOrder != null && SelectedOrder.DmStatus == 0 && SelectedOrder.CancelFlag == 0 && SelectedOrder.HisDispFlag == 0)
|
|||
|
if (SelectedOrder != null && SelectedOrder.DmStatus == 1 && SelectedOrder.CancelFlag == 1 && SelectedOrder.HisDispFlag == 1)
|
|||
|
{
|
|||
|
// 此处延时1毫秒,等待页面渲染
|
|||
|
await Task.Delay(TimeSpan.FromMilliseconds(1));
|
|||
|
DialogParameters dialogParameters = new DialogParameters();
|
|||
|
dialogParameters.Add("orderInfo", SelectedOrder);
|
|||
|
DialogServiceExtensions.ShowDialogHost(_dialogService, "OrderReturnDialog", dialogParameters, DoDialogResult, "RootDialog");
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void DoDialogResult(IDialogResult dialogResult)
|
|||
|
{
|
|||
|
// 委托 被动执行 被子窗口执行
|
|||
|
// dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态
|
|||
|
if (dialogResult.Result == ButtonResult.OK)
|
|||
|
{
|
|||
|
SelectedOrder = null;
|
|||
|
RequestData();
|
|||
|
}
|
|||
|
//MessageBox.Show("返回值:" + dialogResult.Result.ToString());
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作
|
|||
|
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
|
|||
|
{
|
|||
|
continuationCallback(true);
|
|||
|
}
|
|||
|
|
|||
|
public void RequestData()
|
|||
|
{
|
|||
|
OrderInfos.Clear();
|
|||
|
int totalCount = 0;
|
|||
|
List<OrderInfo> queryData = SqlSugarHelper.Db.Queryable<OrderInfo>()
|
|||
|
.InnerJoin<OrderDetail>((oi, od) => oi.OrderNo == od.OrderNo)
|
|||
|
.InnerJoin(SqlSugarHelper.Db.Queryable<ChannelStock>().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (oi, od, t) => od.DrugId == t.DrugId)
|
|||
|
.WhereIF(OrderDate != null, oi => oi.OrderDate.ToString("yyyy-MM-dd") == OrderDate)
|
|||
|
.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("OrderNo"), oi => oi.OrderNo == SearchValue)
|
|||
|
.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PatientId"), oi => oi.PatientId == SearchValue)
|
|||
|
.WhereIF(!String.IsNullOrEmpty(ConfigurationManager.AppSettings["storage"]), oi => oi.Pharmacy == ConfigurationManager.AppSettings["storage"])
|
|||
|
.Where(oi => oi.DmStatus == 1)
|
|||
|
.Where(oi => oi.HisDispFlag == 1)
|
|||
|
.Where(oi => oi.CancelFlag == 1)
|
|||
|
.GroupBy(oi => oi.OrderDate)
|
|||
|
.Select(oi => oi)
|
|||
|
.ToPageList(PageNum, PageSize, ref totalCount);
|
|||
|
//.ToList();
|
|||
|
OrderInfos = queryData;
|
|||
|
TotalCount = totalCount;
|
|||
|
PageCount = (int)Math.Ceiling((double)TotalCount / PageSize);
|
|||
|
}
|
|||
|
|
|||
|
//接收导航传过来的参数 现在是在此处初始化了表格数据
|
|||
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|||
|
{
|
|||
|
RequestData();
|
|||
|
}
|
|||
|
|
|||
|
//每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建
|
|||
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
//这个方法用于拦截请求
|
|||
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|