495 lines
19 KiB
C#
495 lines
19 KiB
C#
|
using MaterialDesignThemes.Wpf;
|
|||
|
using Prism.Commands;
|
|||
|
using Prism.Events;
|
|||
|
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.Media;
|
|||
|
using DM_Weight.Models;
|
|||
|
using DM_Weight.msg;
|
|||
|
using DM_Weight.Port;
|
|||
|
using DM_Weight.util;
|
|||
|
using log4net;
|
|||
|
using System.Threading;
|
|||
|
using System.Reflection.Metadata.Ecma335;
|
|||
|
|
|||
|
namespace DM_Weight.ViewModels
|
|||
|
{
|
|||
|
public class BindingChannelNewDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime
|
|||
|
{
|
|||
|
public static BindingChannelNewDialogViewModel vm;
|
|||
|
public string Title => "库位绑定";
|
|||
|
|
|||
|
public event Action<IDialogResult> RequestClose;
|
|||
|
|
|||
|
private int _drawerNo = 0;
|
|||
|
|
|||
|
|
|||
|
private SolidColorBrush _colorBrush;
|
|||
|
|
|||
|
public SolidColorBrush SnackbarBackground
|
|||
|
{
|
|||
|
get => _colorBrush;
|
|||
|
set => SetProperty(ref _colorBrush, value);
|
|||
|
}
|
|||
|
|
|||
|
private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3));
|
|||
|
|
|||
|
public ISnackbarMessageQueue SnackbarMessageQueue
|
|||
|
{
|
|||
|
get => _snackbarMessageQueue;
|
|||
|
set => SetProperty(ref _snackbarMessageQueue, value);
|
|||
|
}
|
|||
|
|
|||
|
IEventAggregator _eventAggregator;
|
|||
|
PortUtil _portUtil;
|
|||
|
//ScreenUtil _screenUtil;
|
|||
|
|
|||
|
public BindingChannelNewDialogViewModel(IEventAggregator eventAggregator, PortUtil portUtil//, ScreenUtil screenUtil
|
|||
|
)
|
|||
|
{
|
|||
|
_eventAggregator = eventAggregator;
|
|||
|
_portUtil = portUtil;
|
|||
|
//_screenUtil = screenUtil;
|
|||
|
vm = this;
|
|||
|
}
|
|||
|
|
|||
|
public int DrawerNo
|
|||
|
{
|
|||
|
get => _drawerNo;
|
|||
|
set
|
|||
|
{
|
|||
|
SetProperty(ref _drawerNo, value);
|
|||
|
GetChannelsByDrawerNo();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private DrugInfo? _drugInfo;
|
|||
|
|
|||
|
public DrugInfo? DrugInfo
|
|||
|
{
|
|||
|
get => _drugInfo;
|
|||
|
set
|
|||
|
{
|
|||
|
SetProperty(ref _drugInfo, value);
|
|||
|
//if (_drugInfo != null)
|
|||
|
//{
|
|||
|
// DrugManuNos = _drugInfo.DrugManuNos.OrderByDescending(dm => dm.ManuNo).ToList();
|
|||
|
//}
|
|||
|
}
|
|||
|
}
|
|||
|
//拼音码对应药品实体
|
|||
|
//private DrugInfo? _durgInfo_for_py;
|
|||
|
//public DrugInfo? DrugInfo_Py
|
|||
|
//{
|
|||
|
// get => _durgInfo_for_py;
|
|||
|
// set
|
|||
|
// {
|
|||
|
|
|||
|
// SetProperty(ref _durgInfo_for_py, value);
|
|||
|
// if (_durgInfo_for_py != null)
|
|||
|
// {
|
|||
|
// DrugInfos = GetDrugByDrugPY(_durgInfo_for_py.PyCode);
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// DrugInfos = GetDrugByDrugPY("");
|
|||
|
// }
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
//#region 根据药品拼音码查询药品名称
|
|||
|
//private List<DrugInfo> GetDrugByDrugPY(string pycode)
|
|||
|
//{
|
|||
|
// List<DrugInfo> DrugList = null;
|
|||
|
// if (!string.IsNullOrEmpty(pycode))
|
|||
|
// {
|
|||
|
// DrugList = SqlSugarHelper.Db.Queryable<DrugInfo>().Includes<DrugManuNo>(di => di.DrugManuNos).Where(di => di.PyCode.Contains(pycode)).OrderBy(di => di.DrugId).ToList();
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// DrugList = SqlSugarHelper.Db.Queryable<DrugInfo>().Includes<DrugManuNo>(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList();
|
|||
|
// }
|
|||
|
// return DrugList;
|
|||
|
//}
|
|||
|
//private List<DrugInfo>? _drugInfos_py;
|
|||
|
//public List<DrugInfo>? DrugInfos_PY
|
|||
|
//{
|
|||
|
// get => _drugInfos_py;
|
|||
|
// set => SetProperty(ref _drugInfos_py, value);
|
|||
|
//}
|
|||
|
//#endregion 根据药品拼音码查询药品名称
|
|||
|
|
|||
|
|
|||
|
private List<DrugInfo>? _drugInfos;
|
|||
|
|
|||
|
public List<DrugInfo>? DrugInfos
|
|||
|
{
|
|||
|
get => _drugInfos;
|
|||
|
set => SetProperty(ref _drugInfos, value);
|
|||
|
}
|
|||
|
|
|||
|
//private DrugManuNo? _drugManuNo;
|
|||
|
|
|||
|
//public DrugManuNo? DrugManuNo
|
|||
|
//{
|
|||
|
// get => _drugManuNo;
|
|||
|
// set => SetProperty(ref _drugManuNo, value);
|
|||
|
//}
|
|||
|
//private List<DrugManuNo>? _drugManuNos;
|
|||
|
|
|||
|
//public List<DrugManuNo>? DrugManuNos
|
|||
|
//{
|
|||
|
// get => _drugManuNos;
|
|||
|
// set => SetProperty(ref _drugManuNos, value);
|
|||
|
//}
|
|||
|
|
|||
|
|
|||
|
private List<ChannelList>? _channels;
|
|||
|
|
|||
|
public List<ChannelList>? Channels
|
|||
|
{
|
|||
|
get => _channels;
|
|||
|
set => SetProperty(ref _channels, value);
|
|||
|
}
|
|||
|
|
|||
|
private int _totalCount = 0;
|
|||
|
public int TotalCount { get => _totalCount; set => SetProperty(ref _totalCount, value); }
|
|||
|
|
|||
|
private int _pageNum = 1;
|
|||
|
public int PageNum
|
|||
|
{
|
|||
|
get => _pageNum;
|
|||
|
set
|
|||
|
{
|
|||
|
SetProperty(ref _pageNum, value);
|
|||
|
GetChannelsByDrawerNo();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public bool CanCloseDialog()
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public void OnDialogClosed()
|
|||
|
{
|
|||
|
_eventAggregator.GetEvent<PortUtilEvent>().Unsubscribe(DoMyPrismEvent);
|
|||
|
}
|
|||
|
|
|||
|
private void GetAllDrugInfos()
|
|||
|
{
|
|||
|
var list = SqlSugarHelper.Db.Queryable<DrugInfo>().Includes<DrugManuNo>(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList();
|
|||
|
DrugInfos = list;
|
|||
|
//DrugInfos_PY = list;
|
|||
|
}
|
|||
|
|
|||
|
private void GetChannelsByDrawerNo()
|
|||
|
{
|
|||
|
Channels?.Clear();
|
|||
|
int totalCount = 0;
|
|||
|
var list = SqlSugarHelper.Db.Queryable<ChannelList>()
|
|||
|
.Includes<DrugInfo>(cl => cl.Drug)
|
|||
|
//.Includes<ChannelStock>(cs => cs.channelStock)
|
|||
|
.WhereIF(DrawerNo > 0, cl => cl.DrawerNo == DrawerNo)
|
|||
|
.Where(cl => cl.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1"))
|
|||
|
.OrderBy(cl => cl.DrawerNo)
|
|||
|
.OrderBy(cl => cl.ColNo)
|
|||
|
.ToPageList(PageNum, PageSize, ref totalCount);
|
|||
|
Channels = list;
|
|||
|
TotalCount = totalCount;
|
|||
|
}
|
|||
|
public void OnDialogOpened(IDialogParameters parameters)
|
|||
|
{
|
|||
|
if (parameters.ContainsKey("DrawerNo"))
|
|||
|
{
|
|||
|
DrawerNo = parameters.GetValue<int>("DrawerNo");
|
|||
|
}
|
|||
|
GetAllDrugInfos();
|
|||
|
GetChannelsByDrawerNo();
|
|||
|
_eventAggregator.GetEvent<PortUtilEvent>().Subscribe(DoMyPrismEvent);
|
|||
|
}
|
|||
|
public DelegateCommand Query
|
|||
|
{
|
|||
|
get => new DelegateCommand(() =>
|
|||
|
{
|
|||
|
GetChannelsByDrawerNo();
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public DelegateCommand BindingDrug
|
|||
|
{
|
|||
|
get => new DelegateCommand(async () =>
|
|||
|
{
|
|||
|
|
|||
|
var SelectChannels = Channels.FindAll(item => item.IsSelected);
|
|||
|
|
|||
|
if (SelectChannels.All(it => it.DrawerType != 1))
|
|||
|
{
|
|||
|
if (SelectChannels.Count == 1)
|
|||
|
{
|
|||
|
if (DrugInfo != null)
|
|||
|
{
|
|||
|
int count = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cs => cs.DrugId.Equals(DrugInfo.DrugId.ToString())).Where(cs => cs.DrawerType != 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).Count();
|
|||
|
if (count == 0)
|
|||
|
{
|
|||
|
var item = SelectChannels[0];
|
|||
|
|
|||
|
if (item.DrugId == null || !DrugInfo.DrugId.ToString().Equals(item.DrugId))
|
|||
|
{
|
|||
|
item.PosNo = 0;
|
|||
|
}
|
|||
|
item.DrugId = DrugInfo.DrugId.ToString();
|
|||
|
item.DrugSpec= DrugInfo.DrugSpec.ToString();
|
|||
|
SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo,it.DrugSpec }).ExecuteCommand();
|
|||
|
GetChannelsByDrawerNo();
|
|||
|
|
|||
|
if (item.BoardType == 5)
|
|||
|
{
|
|||
|
_portUtil.WindowName = "BindingChannelDialog";
|
|||
|
// 向显示屏写入库位信息
|
|||
|
_portUtil.WriteChannelInfo(1, DrugInfo.DrugName, item.DrawerNo, item.ColNo);
|
|||
|
await Task.Delay(200);
|
|||
|
_portUtil.WriteChannelInfo(2, DrugInfo.DrugSpec, item.DrawerNo, item.ColNo);
|
|||
|
await Task.Delay(200);
|
|||
|
_portUtil.WriteChannelInfo(8, DrugInfo.Manufactory, item.DrawerNo, item.ColNo);
|
|||
|
await Task.Delay(200);
|
|||
|
//_portUtil.WriteChannelInfo(6, DrugManuNo.EffDate==null?"": DrugManuNo.EffDate, item.DrawerNo, item.ColNo);
|
|||
|
//await Task.Delay(200);
|
|||
|
//_portUtil.WriteChannelInfo(5, DrugManuNo.ManuNo, item.DrawerNo, item.ColNo);
|
|||
|
//await Task.Delay(200);
|
|||
|
_portUtil.ShowContent(item.DrawerNo, item.ColNo);
|
|||
|
}
|
|||
|
if(item.BoardType==35)
|
|||
|
{
|
|||
|
_portUtil.ClearContentMethod(item.DrawerNo,item.ColNo);
|
|||
|
}
|
|||
|
//_screenUtil.SetStockInfo(item, 1);
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
|||
|
SnackbarMessageQueue.Enqueue($"药品【{DrugInfo.DrugName}】已经绑定了回收库位不可再次绑定");
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
|||
|
SnackbarMessageQueue.Enqueue("请选择库位需要绑定的药品信息");
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
|||
|
SnackbarMessageQueue.Enqueue("每种药品只能绑定一个回收库位");
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//if (DrugInfo != null && DrugManuNo != null)
|
|||
|
//{
|
|||
|
|
|||
|
var c = SelectChannels.Count;
|
|||
|
|
|||
|
if (c > 0)
|
|||
|
{
|
|||
|
for (int i = 0; i < SelectChannels.Count; i++)
|
|||
|
{
|
|||
|
var item = SelectChannels[i];
|
|||
|
var channelStock = SqlSugarHelper.Db.Queryable<ChannelStock>().Where(cs => cs.Chnguid == item.Id&&cs.Quantity>0).ToList();
|
|||
|
if(channelStock.Count>0)
|
|||
|
{
|
|||
|
//有库存,不能解绑
|
|||
|
|
|||
|
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
|||
|
SnackbarMessageQueue.Enqueue($"库位{item.DrawerNo}-{item.ColNo}中还存在药品,不能绑定其他药品");
|
|||
|
continue;
|
|||
|
}
|
|||
|
if (item.DrugId == null || !DrugInfo.DrugId.ToString().Equals(item.DrugId))
|
|||
|
{
|
|||
|
item.PosNo = 0;
|
|||
|
}
|
|||
|
|
|||
|
item.DrugId = DrugInfo.DrugId.ToString();
|
|||
|
//item.ManuNo = DrugManuNo.ManuNo;
|
|||
|
item.Drug = DrugInfo;
|
|||
|
item.DrugSpec = DrugInfo.DrugSpec.ToString();
|
|||
|
//item.EffDate = String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate);
|
|||
|
SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo,it.DrugSpec }).ExecuteCommand();
|
|||
|
|
|||
|
if (item.BoardType == 5)
|
|||
|
{
|
|||
|
_portUtil.WindowName = "BindingChannelDialog";
|
|||
|
// 向显示屏写入库位信息
|
|||
|
_portUtil.WriteChannelInfo(1, DrugInfo.DrugName, item.DrawerNo, item.ColNo);
|
|||
|
//await Task.Delay(200);
|
|||
|
Thread.Sleep(200);
|
|||
|
_portUtil.WriteChannelInfo(2, DrugInfo.DrugSpec, item.DrawerNo, item.ColNo);
|
|||
|
//await Task.Delay(200);
|
|||
|
Thread.Sleep(200);
|
|||
|
_portUtil.WriteChannelInfo(8, DrugInfo.Manufactory, item.DrawerNo, item.ColNo);
|
|||
|
//await Task.Delay(200);
|
|||
|
Thread.Sleep(200);
|
|||
|
//_portUtil.WriteChannelInfo(6, DrugManuNo.ManuNo, item.DrawerNo, item.ColNo);
|
|||
|
//await Task.Delay(200);
|
|||
|
//Thread.Sleep(200);
|
|||
|
//_portUtil.WriteChannelInfo(5, String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate), item.DrawerNo, item.ColNo);
|
|||
|
////await Task.Delay(200);
|
|||
|
//Thread.Sleep(200);
|
|||
|
_portUtil.ShowContent(item.DrawerNo, item.ColNo);
|
|||
|
}
|
|||
|
|
|||
|
if (item.BoardType == 35)
|
|||
|
{
|
|||
|
_portUtil.WindowName = "BindingChannelDialog";
|
|||
|
_portUtil.ClearContentMethod(item.DrawerNo,item.ColNo);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
GetChannelsByDrawerNo();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
|||
|
SnackbarMessageQueue.Enqueue("所选库位中无可绑定库位【库位还存在药品】");
|
|||
|
}
|
|||
|
//}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
|||
|
// SnackbarMessageQueue.Enqueue("请选择库位需要绑定的药品及批次信息");
|
|||
|
//}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
public DelegateCommand RemoveBinding
|
|||
|
{
|
|||
|
get => new DelegateCommand(async () =>
|
|||
|
{
|
|||
|
var SelectChannels = Channels.FindAll(item => item.IsSelected && item.DrugId != null);
|
|||
|
var c = SelectChannels.Count;
|
|||
|
if (c > 0)
|
|||
|
{
|
|||
|
|
|||
|
SelectChannels.ForEach(async item =>
|
|||
|
{
|
|||
|
var channelStock = SqlSugarHelper.Db.Queryable<ChannelStock>().Where(cs => cs.Chnguid == item.Id && cs.Quantity > 0).ToList();
|
|||
|
if (channelStock.Count > 0)
|
|||
|
{
|
|||
|
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
|||
|
SnackbarMessageQueue.Enqueue("所选库位中无可解绑药品【库位还存在药品】");
|
|||
|
//该药品下的批次还有库存则不能解绑
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
item.DrugId = null;
|
|||
|
//item.ManuNo = null;
|
|||
|
//item.EffDate = null;
|
|||
|
item.Drug = null;
|
|||
|
item.DrugSpec = null;
|
|||
|
SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId,it.DrugSpec }).ExecuteCommand();
|
|||
|
if (item.BoardType == 5)
|
|||
|
{
|
|||
|
// 清除显示屏库位信息
|
|||
|
_portUtil.ClearContent(item.DrawerNo, item.ColNo);
|
|||
|
await Task.Delay(200);
|
|||
|
_portUtil.ShowContent(item.DrawerNo, item.ColNo);
|
|||
|
}
|
|||
|
|
|||
|
//_screenUtil.SetStockInfo(item, 1);
|
|||
|
});
|
|||
|
GetChannelsByDrawerNo();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
|||
|
SnackbarMessageQueue.Enqueue("所选库位中无可解绑药品");
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
public DelegateCommand BtnCloseCommand
|
|||
|
{
|
|||
|
get => new DelegateCommand(() =>
|
|||
|
{
|
|||
|
//DialogParameters parameters = new DialogParameters();
|
|||
|
//parameters.Add("",);
|
|||
|
// 关闭当前窗口
|
|||
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
public bool KeepAlive => false;
|
|||
|
string message = string.Empty;
|
|||
|
private void DoMyPrismEvent(DeviceMsg msg)
|
|||
|
{
|
|||
|
if (msg.WindowName == "BindingChannelDialog")
|
|||
|
{
|
|||
|
switch (msg.EventType)
|
|||
|
{
|
|||
|
case EventType.OPENERROR:
|
|||
|
AlertMsg alertMsg = new AlertMsg
|
|||
|
{
|
|||
|
Message = msg.Message,
|
|||
|
Type = MsgType.ERROR,
|
|||
|
};
|
|||
|
if (message != msg.Message)
|
|||
|
{
|
|||
|
message = msg.Message;
|
|||
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
public void UpdateComboBoxItems(string text)
|
|||
|
{
|
|||
|
string str = @"SELECT d.drug_id,d.py_code,d.drug_barcode,d.drug_name,d.drug_brand_name,d.drug_spec,d.dosage,d.pack_unit,
|
|||
|
d.manufactory,d.max_stock,CONCAT(drug_name,' ',drug_spec)as drug_name_spec FROM `drug_info` d";
|
|||
|
if (string.IsNullOrEmpty(text))
|
|||
|
{
|
|||
|
DrugInfos = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList();
|
|||
|
return;
|
|||
|
}
|
|||
|
if (DrugInfos != null)
|
|||
|
{
|
|||
|
DrugInfos.Clear();
|
|||
|
}
|
|||
|
DrugInfos = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(str).Where(di => di.DrugName.Contains(text) || di.PyCode.Contains(text)).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|