381 lines
12 KiB
C#
381 lines
12 KiB
C#
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.Collections.ObjectModel;
|
||
using System.Configuration;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace DM_Weight.ViewModels
|
||
{
|
||
public class MultiOrderTakeDrugWindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime
|
||
{
|
||
public static MultiOrderTakeDrugWindowViewModel vm;
|
||
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;
|
||
|
||
|
||
public MultiOrderTakeDrugWindowViewModel(IDialogService DialogService, IEventAggregator eventAggregator)
|
||
{
|
||
_dialogService = DialogService;
|
||
_eventAggregator = eventAggregator;
|
||
vm = this;
|
||
}
|
||
|
||
//public static ObservableCollection<OrderTakeSelect> StaticOrderTakeSelects = new()
|
||
//{
|
||
// new OrderTakeSelect
|
||
// {
|
||
// Code = "OrderNo",
|
||
// Name = "处方号"
|
||
// },
|
||
// new OrderTakeSelect
|
||
// {
|
||
// Code = "PatientId",
|
||
// Name = "患者编号"
|
||
// }
|
||
//};
|
||
|
||
//private ObservableCollection<OrderTakeSelect> _orderTakeSelects = StaticOrderTakeSelects;
|
||
|
||
//public ObservableCollection<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();
|
||
// }
|
||
//}
|
||
|
||
/// <summary>
|
||
///全选
|
||
/// </summary>
|
||
private bool _allChecked = false;
|
||
public bool IsAllChecked
|
||
{
|
||
get { return _allChecked; }
|
||
set
|
||
{
|
||
SetProperty(ref _allChecked, value);
|
||
if (!IsItemCheck)
|
||
{
|
||
RequestData();
|
||
//根据全选或反选设置其后的选中状态
|
||
OrderInfos.ToList().ForEach(oi => oi.ItemIsChecked = _allChecked);
|
||
}
|
||
else
|
||
{
|
||
IsItemCheck = false;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
public bool _isItemCheck = false;
|
||
public bool IsItemCheck
|
||
{
|
||
get => _isItemCheck;
|
||
set
|
||
{
|
||
SetProperty(ref _isItemCheck, value);
|
||
if (OrderInfos.ToList().Where(od => od.ItemIsChecked == false).Count() <= 0)
|
||
{
|
||
IsAllChecked = true;
|
||
}
|
||
}
|
||
}
|
||
//private bool _itemIsChecked = false;
|
||
//public bool ItemIsChecked
|
||
//{
|
||
// get => _itemIsChecked;
|
||
// set
|
||
// {
|
||
// SetProperty(ref _itemIsChecked, value);
|
||
// }
|
||
//}
|
||
//多处方取药
|
||
public DelegateCommand BtnTakeOrder { get => new DelegateCommand(TakeByMultiOrder); }
|
||
private void TakeByMultiOrder()
|
||
{
|
||
OrderInfos = new ObservableCollection<OrderInfo>(OrderInfos.Where(o => o.ItemIsChecked == true).ToList());
|
||
if (OrderInfos != null && OrderInfos.Count() > 0)
|
||
{
|
||
// 此处延时1毫秒,等待页面渲染
|
||
//await Task.Delay(TimeSpan.FromMilliseconds(1));
|
||
DialogParameters dialogParameters = new DialogParameters();
|
||
dialogParameters.Add("orderInfo", OrderInfos);
|
||
DialogServiceExtensions.ShowDialogHost(_dialogService, "MultiOrderTakeDialog", dialogParameters, DoDialogResult, "RootDialog");
|
||
}
|
||
else
|
||
{
|
||
//请勾选要取药的处方信息
|
||
AlertMsg alertMsg = new AlertMsg
|
||
{
|
||
Message = "请勾选要取药的处方信息",
|
||
Type = MsgType.ERROR,
|
||
};
|
||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||
}
|
||
IsAllChecked = false;
|
||
}
|
||
|
||
private ObservableCollection<OrderInfo> _orderInfos = new();
|
||
|
||
public ObservableCollection<OrderInfo> OrderInfos
|
||
{
|
||
get { return _orderInfos; }
|
||
set
|
||
{
|
||
SetProperty(ref _orderInfos, value);
|
||
}
|
||
}
|
||
|
||
//部门
|
||
private ObservableCollection<OrderDepartment> _orderDepartments = new ObservableCollection<OrderDepartment>();
|
||
public ObservableCollection<OrderDepartment> OrderDepartments
|
||
{
|
||
get => _orderDepartments;
|
||
set
|
||
{
|
||
SetProperty(ref _orderDepartments, value);
|
||
}
|
||
}
|
||
|
||
private OrderDepartment _orderDepartment = new OrderDepartment();
|
||
public OrderDepartment OrderDepartment
|
||
{
|
||
get => _orderDepartment;
|
||
set
|
||
{
|
||
SetProperty(ref _orderDepartment, value);
|
||
RequestData();
|
||
}
|
||
}
|
||
|
||
|
||
public bool KeepAlive => false;
|
||
|
||
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 DelegateCommand QueryCommand
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
RequestData();
|
||
});
|
||
}
|
||
|
||
public void RequestData()
|
||
{
|
||
OrderInfos.Clear();
|
||
int totalCount = 0;
|
||
//string SearchValue = null;
|
||
//if (SearchValue != null)
|
||
//{
|
||
// strSearchValue = SearchValue.Trim().Replace("\r", "");
|
||
//}
|
||
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(!(OrderDepartment.DeptName.Equals("全部")), oi => oi.DeptName == OrderDepartment.DeptName)
|
||
//.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 == 0)
|
||
.Where(oi => oi.HisDispFlag == 0)
|
||
.Where(oi => oi.CancelFlag == 0)
|
||
.GroupBy(oi => oi.OrderDate)
|
||
.Select(oi => oi)
|
||
.ToPageList(PageNum, PageSize, ref totalCount);
|
||
//.ToList();
|
||
OrderInfos = new ObservableCollection<OrderInfo>(queryData);
|
||
|
||
if (OrderDepartments.Where(d => d.DeptName == "全部").ToList().Count <= 0)
|
||
{
|
||
OrderDepartment deptDefault = new OrderDepartment();
|
||
deptDefault.DeptName = "全部";
|
||
OrderDepartments.Add(deptDefault);
|
||
|
||
}
|
||
var orderDeparts = queryData.GroupBy(o=>o.DeptName).ToList();
|
||
for (int i = 0; i < orderDeparts.Count; i++)
|
||
{
|
||
OrderDepartment dept = new OrderDepartment();
|
||
if (orderDeparts[i].Key != null && orderDeparts[i].Key != string.Empty&& OrderDepartments.Where(d => d.DeptName == orderDeparts[i].Key).ToList().Count<=0)
|
||
{
|
||
dept.DeptName = orderDeparts[i].Key;
|
||
OrderDepartments.Add(dept);
|
||
}
|
||
}
|
||
TotalCount = totalCount;
|
||
PageCount = (int)Math.Ceiling((double)TotalCount / PageSize);
|
||
|
||
}
|
||
|
||
//接收导航传过来的参数 现在是在此处初始化了表格数据
|
||
public void OnNavigatedTo(NavigationContext navigationContext)
|
||
{
|
||
//_eventAggregator.GetEvent<PortUtilEvent>().Subscribe(DoMyPrismEvent);
|
||
RequestData();
|
||
}
|
||
|
||
//每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建
|
||
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;
|
||
//}
|
||
|
||
}
|
||
}
|
||
}
|