230 lines
7.7 KiB
C#
230 lines
7.7 KiB
C#
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 SqlSugar;
|
||
using log4net;
|
||
|
||
namespace DM_Weight.ViewModels
|
||
{
|
||
public class ReturnDrugWindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime
|
||
{
|
||
private readonly ILog logger = LogManager.GetLogger(typeof(ReturnDrugWindowViewModel));
|
||
IDialogService _dialogService;
|
||
|
||
private DelegateCommand _rowSelected;
|
||
|
||
public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(OpenOrderDialog);
|
||
|
||
public ReturnDrugWindowViewModel(IDialogService DialogService)
|
||
{
|
||
logger.Info($"用户【{HomeWindowViewModel.Operator?.Nickname}】进入ReturnDrugWindowViewModel构造函数");
|
||
_dialogService = DialogService;
|
||
}
|
||
//刷新
|
||
public DelegateCommand Query
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
RequestData();
|
||
});
|
||
}
|
||
|
||
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 = "药品编码"
|
||
}
|
||
};
|
||
|
||
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);
|
||
RequestData();
|
||
}
|
||
}
|
||
|
||
private MachineRecord? _selectedRecord;
|
||
|
||
public MachineRecord? SelectedRecord
|
||
{
|
||
get { return _selectedRecord; }
|
||
set
|
||
{
|
||
SetProperty(ref _selectedRecord, value);
|
||
|
||
//OpenOrderDialog();
|
||
}
|
||
}
|
||
|
||
|
||
private string _queryDate = DateTime.Now.ToString("yyyy-MM-dd");
|
||
/// <summary>
|
||
/// 查询条件 处方日期
|
||
/// </summary>
|
||
public string QueryDate
|
||
{
|
||
get { return _queryDate; }
|
||
set
|
||
{
|
||
if (!String.IsNullOrEmpty(value))
|
||
{
|
||
SetProperty(ref _queryDate, DateTime.Parse(value).ToString("yyyy-MM-dd"));
|
||
}
|
||
else
|
||
{
|
||
SetProperty(ref _queryDate, value);
|
||
}
|
||
|
||
RequestData();
|
||
}
|
||
}
|
||
|
||
private string? _searchValue;
|
||
|
||
/// <summary>
|
||
/// 查询条件 查询字段值
|
||
/// </summary>
|
||
public string? SearchValue
|
||
{
|
||
get { return _searchValue; }
|
||
set
|
||
{
|
||
SetProperty(ref _searchValue, value);
|
||
RequestData();
|
||
}
|
||
}
|
||
|
||
private List<MachineRecord> _machineRecords = new();
|
||
|
||
public List<MachineRecord> MachineRecords { get { return _machineRecords; } set { SetProperty(ref _machineRecords, value); } }
|
||
|
||
|
||
public async void OpenOrderDialog()
|
||
{
|
||
if (SelectedRecord != null)
|
||
{
|
||
// 此处延时1毫秒,等待页面渲染
|
||
await Task.Delay(TimeSpan.FromMilliseconds(1));
|
||
|
||
DialogParameters dialogParameters = new DialogParameters();
|
||
dialogParameters.Add("record", SelectedRecord);
|
||
DialogServiceExtensions.ShowDialogHost(_dialogService, "ReturnDrugDialog", dialogParameters, DoDialogResult, "RootDialog");
|
||
|
||
}
|
||
|
||
}
|
||
|
||
private void DoDialogResult(IDialogResult dialogResult)
|
||
{
|
||
// 委托 被动执行 被子窗口执行
|
||
// dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态
|
||
//if (dialogResult.Result == ButtonResult.OK)
|
||
{
|
||
SelectedRecord = null;
|
||
RequestData();
|
||
}
|
||
//MessageBox.Show("返回值:" + dialogResult.Result.ToString());
|
||
}
|
||
|
||
public bool KeepAlive => false;
|
||
|
||
//这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作
|
||
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
|
||
{
|
||
continuationCallback(true);
|
||
}
|
||
|
||
|
||
public void RequestData()
|
||
{
|
||
List<MachineRecord> queryData = SqlSugarHelper.Db.Queryable<MachineRecord>()
|
||
.Includes<DrugInfo>(mr => mr.DrugInfo)
|
||
.Includes<UserList>(mr => mr.User)
|
||
.Where(mr => mr.Type == 2)
|
||
.Where(mr => mr.Status < 2)
|
||
.Where(mr => mr.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1"))
|
||
//.WhereIF(QueryDate != null, mr => mr.OperationTime.ToString("yyyy-MM-dd") == QueryDate)
|
||
.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (mr) => mr.DrugInfo.DrugId.ToString().Contains(SearchValue))
|
||
.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (mr) => mr.DrugInfo.DrugName.Contains(SearchValue))
|
||
.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (mr) => mr.DrugInfo.PyCode.Contains(SearchValue))
|
||
.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (mr) => mr.DrugInfo.DrugBarcode.Contains(SearchValue))
|
||
.OrderBy(mr => mr.Operator != HomeWindowViewModel.Operator.Id)
|
||
.OrderBy(mr => mr.Operator)
|
||
.OrderBy(mr =>mr.OperationTime,OrderByType.Desc)
|
||
|
||
.ToList();
|
||
MachineRecords = queryData;
|
||
}
|
||
|
||
//接收导航传过来的参数 现在是在此处初始化了表格数据
|
||
public void OnNavigatedTo(NavigationContext navigationContext)
|
||
{
|
||
logger.Info($"用户【{HomeWindowViewModel.Operator?.Nickname}】进入OnNavigatedTo请求数据线程");
|
||
Task.Factory.StartNew(() =>
|
||
{
|
||
logger.Info($"用户【{HomeWindowViewModel.Operator?.Nickname}】进入OnNavigatedTo请求数据线程");
|
||
RequestData();
|
||
logger.Info($"用户【{HomeWindowViewModel.Operator?.Nickname}】结束OnNavigatedTo请求数据线程");
|
||
});
|
||
logger.Info($"用户【{HomeWindowViewModel.Operator?.Nickname}】结束OnNavigatedTo请求数据线程");
|
||
}
|
||
|
||
//每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建
|
||
public bool IsNavigationTarget(NavigationContext navigationContext)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
//这个方法用于拦截请求
|
||
public void OnNavigatedFrom(NavigationContext navigationContext)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|