301 lines
11 KiB
C#
301 lines
11 KiB
C#
using Prism.Commands;
|
||
using Prism.Mvvm;
|
||
using Prism.Regions;
|
||
using Prism.Services.Dialogs;
|
||
using SqlSugar;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Documents;
|
||
using DM_Weight.Models;
|
||
using DM_Weight.Report;
|
||
using DM_Weight.select;
|
||
using DM_Weight.util;
|
||
using System.ComponentModel;
|
||
using System.Windows.Data;
|
||
using System.Runtime.InteropServices;
|
||
using System.Threading;
|
||
using log4net.Repository.Hierarchy;
|
||
using log4net;
|
||
|
||
namespace DM_Weight.ViewModels
|
||
{
|
||
public class StockListWindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime
|
||
{
|
||
//public static StockListWindowViewModel vm;
|
||
public string drugId;
|
||
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 string? _searchValue;
|
||
|
||
/// <summary>
|
||
/// 查询条件 查询字段值
|
||
/// </summary>
|
||
public string? SearchValue
|
||
{
|
||
get { return _searchValue; }
|
||
set
|
||
{
|
||
SetProperty(ref _searchValue, value);
|
||
RequestData();
|
||
}
|
||
}
|
||
IDialogService _dialogService;
|
||
////private SqlSugarScope SqlSugarHelper.Db;
|
||
private readonly ILog logger = LogManager.GetLogger(typeof(StockListWindowViewModel));
|
||
public StockListWindowViewModel(IDialogService dialogService)
|
||
{
|
||
logger.Info("进入StockListWindowViewModel构造函数");
|
||
_dialogService = dialogService;
|
||
////this.SqlSugarHelper.Db = sqlSugarScope;
|
||
//vm = this;
|
||
}
|
||
private ChannelStock? _selectedChannel;
|
||
|
||
public ChannelStock? SelectedChannel
|
||
{
|
||
get => _selectedChannel;
|
||
set => SetProperty(ref _selectedChannel, value);
|
||
}
|
||
|
||
private List<ChannelStock>? _channelStocks = new();
|
||
|
||
public List<ChannelStock>? ChannelStocks
|
||
{
|
||
get => _channelStocks;
|
||
set => SetProperty(ref _channelStocks, value);
|
||
}
|
||
|
||
public DelegateCommand BindingChannelDialog
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
DialogParameters dialogParameters = new DialogParameters();
|
||
//DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelDialog", dialogParameters, DoDialogResult, "RootDialog");
|
||
DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelNewDialog", dialogParameters, DoDialogResult, "RootDialog");
|
||
});
|
||
}
|
||
|
||
|
||
public DelegateCommand QueryCommand
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
RequestData();
|
||
});
|
||
}
|
||
/// <summary>
|
||
/// 导出账册
|
||
/// </summary>
|
||
public DelegateCommand DownloadAccountBook
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
AccountAction();
|
||
});
|
||
}
|
||
private void AccountAction()
|
||
{
|
||
DialogParameters dialogParameters = new DialogParameters();
|
||
dialogParameters.Add("Stock", drugId);
|
||
DialogServiceExtensions.ShowDialogHost(_dialogService, "StockListAccountDialog", dialogParameters, "RootDialog");
|
||
}
|
||
|
||
private void DoDialogResult(IDialogResult dialogResult)
|
||
{
|
||
// 委托 被动执行 被子窗口执行
|
||
// dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态
|
||
//if (dialogResult.Result == ButtonResult.OK)
|
||
//{
|
||
RequestData();
|
||
//}
|
||
//MessageBox.Show("返回值:" + dialogResult.Result.ToString());
|
||
}
|
||
|
||
public DelegateCommand Download
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
GridReportUtil.PrintReportStock();
|
||
});
|
||
}
|
||
|
||
public DelegateCommand<object> ClickCommand
|
||
{
|
||
get => new DelegateCommand<object>((SelectedChannel) =>
|
||
{
|
||
if (SelectedChannel != null)
|
||
{
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
public bool KeepAlive => true;
|
||
|
||
|
||
|
||
//这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作
|
||
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
|
||
{
|
||
continuationCallback(true);
|
||
}
|
||
private List<DrugInfo>? _drugs = new();
|
||
|
||
public List<DrugInfo>? Drugs
|
||
{
|
||
get => _drugs;
|
||
set => SetProperty(ref _drugs, value);
|
||
}
|
||
private DrugInfo? _drug;
|
||
|
||
public DrugInfo? Drug
|
||
{
|
||
get => _drug;
|
||
set => SetProperty(ref _drug, value);
|
||
}
|
||
|
||
public void RequestData()
|
||
{
|
||
logger.Info("开始StockListWindowViewModel_查询数据");
|
||
//ChannelStocks.Clear();
|
||
//List<ChannelStock> q = new List<ChannelStock>();
|
||
//Task.Factory.StartNew(() =>
|
||
//{
|
||
// List<ChannelStock> q = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
||
// .Includes<DrugInfo>(cs => cs.DrugInfo)
|
||
// .InnerJoin<ChannelList>((cs, cl) => cs.Chnguid == cl.Id && cs.DrugId == cl.DrugId)
|
||
// .Where(cs => cs.DrawerType == 1)
|
||
// .Where(cs => cs.DrugId != null)
|
||
// .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1"))
|
||
|
||
// .WhereIF(!String.IsNullOrEmpty(SearchValue), cs => cs.DrugInfo.DrugName == SearchValue)
|
||
// .OrderBy(cs => cs.DrawerNo)
|
||
// .OrderBy(cs => cs.ColNo)
|
||
// .OrderBy(cs => cs.DrugId)
|
||
// .ToList();
|
||
////});
|
||
//ChannelStocks = q.Select(it => { it.CheckQuantity = it.Quantity; return it; }).ToList();
|
||
//ICollectionView vw = CollectionViewSource.GetDefaultView(q);
|
||
//vw.GroupDescriptions.Add(new PropertyGroupDescription("DrugInfo"));
|
||
//ChannelStocks = q;
|
||
|
||
//List<DrugInfo> q = SqlSugarHelper.Db.Queryable<DrugInfo>()
|
||
// .Includes<ChannelStock>(di => di.channelStocks.Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null).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;
|
||
|
||
List<DrugInfo> q = SqlSugarHelper.Db.Queryable<DrugInfo>()
|
||
.Includes<ChannelStock>(di => di.channelStocks.Where(cs => cs.DrawerType == 1)
|
||
.WhereIF(App.SingleModel, cs => cs.DrawerNo <= 2) //单人登录开前8个抽屉,双人登录开后8个抽屉
|
||
.WhereIF(!(App.SingleModel), cs => cs.DrawerNo > 2)
|
||
.Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null).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))
|
||
.WhereIF(App.SingleModel, di => di.channelStocks.Any(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null&&cs.DrawerNo <= 8&& cs.DrawerType == 1))
|
||
.WhereIF(!(App.SingleModel), di => di.channelStocks.Any(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null&&cs.DrawerNo > 8&& cs.DrawerType == 1))
|
||
.OrderBy(cs => cs.DrugId)
|
||
.ToList();
|
||
Drugs = q;
|
||
|
||
logger.Info("结束StockListWindowViewModel_查询数据");
|
||
}
|
||
|
||
//接收导航传过来的参数 现在是在此处初始化了表格数据
|
||
public void OnNavigatedTo(NavigationContext navigationContext)
|
||
{
|
||
logger.Info("进入StockListWindowViewModel_OnNavigatedTo");
|
||
//RequestData();
|
||
Task.Factory.StartNew(() => RequestData());
|
||
logger.Info("结束StockListWindowViewModel_OnNavigatedTo");
|
||
}
|
||
|
||
|
||
//每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建
|
||
public bool IsNavigationTarget(NavigationContext navigationContext)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
//这个方法用于拦截请求
|
||
public void OnNavigatedFrom(NavigationContext navigationContext)
|
||
{
|
||
|
||
}
|
||
public DelegateCommand RowSelected
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
//if (ChannelStocks != null)
|
||
//{
|
||
// SelectMachineRecords = ChannelStocks.Select(x =>
|
||
// {
|
||
// x.IsSelected = !x.IsSelected;
|
||
// return x;
|
||
// }).ToList();
|
||
|
||
|
||
//}
|
||
});
|
||
}
|
||
}
|
||
}
|