2023-11-13 13:25:46 +08:00
|
|
|
|
using Prism.Commands;
|
|
|
|
|
using Prism.Mvvm;
|
|
|
|
|
using Prism.Regions;
|
|
|
|
|
using Prism.Services.Dialogs;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using DM_Weight.Models;
|
|
|
|
|
using DM_Weight.select;
|
|
|
|
|
using DM_Weight.util;
|
|
|
|
|
using DM_Weight.msg;
|
|
|
|
|
using Prism.Events;
|
2023-11-27 15:35:22 +08:00
|
|
|
|
using SqlSugar;
|
2023-11-13 13:25:46 +08:00
|
|
|
|
|
|
|
|
|
namespace DM_Weight.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class SelfTakeDrugWindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime
|
|
|
|
|
{
|
|
|
|
|
IDialogService _dialogService;
|
|
|
|
|
IEventAggregator _eventAggregator;
|
|
|
|
|
|
|
|
|
|
public static List<OrderTakeSelect> StaticSelects = new()
|
|
|
|
|
{
|
|
|
|
|
new OrderTakeSelect
|
|
|
|
|
{
|
|
|
|
|
Code = "DrugName",
|
|
|
|
|
Name = "药品名称"
|
|
|
|
|
},
|
|
|
|
|
new OrderTakeSelect
|
|
|
|
|
{
|
|
|
|
|
Code = "PyCode",
|
|
|
|
|
Name = "拼音码"
|
|
|
|
|
},
|
|
|
|
|
new OrderTakeSelect
|
|
|
|
|
{
|
|
|
|
|
Code = "DrugBarcode",
|
|
|
|
|
Name = "药品条码"
|
|
|
|
|
},
|
|
|
|
|
new OrderTakeSelect
|
|
|
|
|
{
|
|
|
|
|
Code = "DrugId",
|
|
|
|
|
Name = "药品编码"
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//private SqlSugarScope SqlSugarHelper.Db;
|
2023-11-27 15:35:22 +08:00
|
|
|
|
public SelfTakeDrugWindowViewModel(IDialogService DialogService, IEventAggregator eventAggregator, SqlSugarScope sqlSugarScope)
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
|
|
|
|
_dialogService = DialogService;
|
|
|
|
|
_eventAggregator= eventAggregator;
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//this.SqlSugarHelper.Db = sqlSugarScope;
|
2023-11-13 13:25:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<OrderTakeSelect> _selects = StaticSelects;
|
|
|
|
|
|
|
|
|
|
public List<OrderTakeSelect> Selects
|
|
|
|
|
{
|
|
|
|
|
get { return _selects; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetProperty(ref _selects, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private OrderTakeSelect _selectedItem = StaticSelects[0];
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询条件 查询字段
|
|
|
|
|
/// </summary>
|
|
|
|
|
public OrderTakeSelect SelectedItem
|
|
|
|
|
{
|
|
|
|
|
get { return _selectedItem; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetProperty(ref _selectedItem, value);
|
|
|
|
|
RequestChannelData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string? _searchValue;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询条件 查询字段值
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string? SearchValue
|
|
|
|
|
{
|
|
|
|
|
get { return _searchValue; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetProperty(ref _searchValue, value);
|
|
|
|
|
RequestChannelData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<ChannelStock> _channelStocks = new();
|
|
|
|
|
|
|
|
|
|
public List<ChannelStock> ChannelStocks { get { return _channelStocks; } set { SetProperty(ref _channelStocks, value); } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DelegateCommand OpenSelfDialog
|
|
|
|
|
{
|
|
|
|
|
get => new DelegateCommand(() =>
|
|
|
|
|
{
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//List<ChannelStock> takeChannels = ChannelStocks.FindAll(it => it.TakeQuantity > 0).ToList();
|
|
|
|
|
|
|
|
|
|
List<ChannelStock> takeChannels = Drugs.Aggregate(new List<ChannelStock>(), (a, b) =>
|
|
|
|
|
{
|
|
|
|
|
a.AddRange(b.channelStocks.FindAll(it => it.TakeQuantity > 0).Select(cs => {
|
|
|
|
|
cs.DrugInfo = b;
|
|
|
|
|
return cs;
|
|
|
|
|
}).ToList());
|
|
|
|
|
return a;
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-13 13:25:46 +08:00
|
|
|
|
if (takeChannels.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
takeChannels.Sort((a, b) =>
|
|
|
|
|
{
|
|
|
|
|
if ((a.DrawerNo - b.DrawerNo) == 0)
|
|
|
|
|
{
|
|
|
|
|
return a.ColNo - b.ColNo;
|
|
|
|
|
}
|
|
|
|
|
return a.DrawerNo - b.DrawerNo;
|
|
|
|
|
});
|
|
|
|
|
DialogParameters dialogParameters = new DialogParameters();
|
|
|
|
|
dialogParameters.Add("ChannelStocks", takeChannels);
|
|
|
|
|
DialogServiceExtensions.ShowDialogHost(_dialogService, "SelfTakeDialog", dialogParameters, DoDialogResult, "RootDialog");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AlertMsg alertMsg = new AlertMsg
|
|
|
|
|
{
|
|
|
|
|
Message = "请填写取药数量",
|
|
|
|
|
Type = MsgType.ERROR
|
|
|
|
|
};
|
|
|
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 13:35:45 +08:00
|
|
|
|
public bool KeepAlive => true;
|
|
|
|
|
|
2023-11-13 13:25:46 +08:00
|
|
|
|
private void DoDialogResult(IDialogResult dialogResult)
|
|
|
|
|
{
|
|
|
|
|
// 委托 被动执行 被子窗口执行
|
|
|
|
|
// dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态
|
|
|
|
|
if (dialogResult.Result == ButtonResult.OK)
|
|
|
|
|
{
|
|
|
|
|
RequestChannelData();
|
|
|
|
|
}
|
|
|
|
|
//MessageBox.Show("返回值:" + dialogResult.Result.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作
|
|
|
|
|
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
|
|
|
|
|
{
|
|
|
|
|
continuationCallback(true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 13:35:45 +08:00
|
|
|
|
private List<DrugInfo> _drugs = new();
|
2023-11-13 13:25:46 +08:00
|
|
|
|
|
2024-02-04 13:35:45 +08:00
|
|
|
|
public List<DrugInfo> Drugs
|
|
|
|
|
{
|
|
|
|
|
get => _drugs;
|
|
|
|
|
set => SetProperty(ref _drugs, value);
|
|
|
|
|
}
|
|
|
|
|
private DrugInfo? _drug;
|
|
|
|
|
|
|
|
|
|
public DrugInfo? Drug
|
|
|
|
|
{
|
|
|
|
|
get => _drug;
|
|
|
|
|
set => SetProperty(ref _drug, value);
|
|
|
|
|
}
|
2023-11-13 13:25:46 +08:00
|
|
|
|
|
|
|
|
|
public void RequestChannelData()
|
|
|
|
|
{
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//List<ChannelStock> queryData = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
|
|
|
|
// .Includes<DrugInfo>(cs => cs.DrugInfo)
|
|
|
|
|
// .Where(cs => cs.DrugId != null)
|
|
|
|
|
// .Where(cs => cs.DrawerType == 1)
|
|
|
|
|
// .Where(cs => cs.Quantity > 0)
|
|
|
|
|
// .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1"))
|
|
|
|
|
// .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (cs) => cs.DrugId.Contains(SearchValue))
|
|
|
|
|
// .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugInfo.DrugName.Contains(SearchValue))
|
|
|
|
|
// .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.DrugInfo.PyCode.Contains(SearchValue))
|
|
|
|
|
// .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugInfo.DrugBarcode.Contains(SearchValue))
|
|
|
|
|
// .OrderBy(cs => cs.DrugId)
|
|
|
|
|
// .OrderBy(cs => cs.DrawerNo)
|
|
|
|
|
// .OrderBy(cs => cs.ColNo)
|
|
|
|
|
// .ToList();
|
|
|
|
|
//ChannelStocks = queryData;
|
|
|
|
|
List<DrugInfo> q = SqlSugarHelper.Db.Queryable<DrugInfo>()
|
|
|
|
|
.Includes<ChannelStock>(di => di.channelStocks.Where(cs => cs.DrawerType == 1)
|
2024-12-31 13:57:08 +08:00
|
|
|
|
.WhereIF(App.SingleModel, cs => cs.DrawerNo <= 1 ) //单人登录开前8个抽屉,双人登录开后8个抽屉
|
|
|
|
|
.WhereIF(!(App.SingleModel), cs => cs.DrawerNo > 1 )
|
2024-02-04 13:35:45 +08:00
|
|
|
|
.Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null&&cs.Quantity>0).OrderBy(cs => cs.DrawerNo).OrderBy(cs => cs.ColNo).ToList())
|
|
|
|
|
.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (cs) => cs.DrugId.Contains(SearchValue))
|
|
|
|
|
.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugName.Contains(SearchValue))
|
|
|
|
|
.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.PyCode.Contains(SearchValue))
|
|
|
|
|
.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugBarcode.Contains(SearchValue))
|
|
|
|
|
.Where(di => di.channelStocks.Any(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null))
|
|
|
|
|
|
|
|
|
|
.OrderBy(cs => cs.DrugId)
|
|
|
|
|
.ToList();
|
|
|
|
|
Drugs = q.Where(di => di.channelStocks.Count() > 0).ToList();
|
2023-11-13 13:25:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//接收导航传过来的参数 现在是在此处初始化了表格数据
|
|
|
|
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|
|
|
|
{
|
|
|
|
|
RequestChannelData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建
|
|
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//这个方法用于拦截请求
|
|
|
|
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|