652 lines
27 KiB
C#
652 lines
27 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;
|
||
using System.Windows.Threading;
|
||
using System.Windows;
|
||
using System.Reflection.PortableExecutable;
|
||
|
||
namespace DM_Weight.ViewModels
|
||
{
|
||
public class BindingChannelNewDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime
|
||
{
|
||
|
||
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;
|
||
////private SqlSugarScope SqlSugarHelper.Db;
|
||
public static BindingChannelNewDialogViewModel vm;
|
||
public BindingChannelNewDialogViewModel(IEventAggregator eventAggregator, PortUtil portUtil//, ScreenUtil screenUtil
|
||
)
|
||
{
|
||
_eventAggregator = eventAggregator;
|
||
_portUtil = portUtil;
|
||
//_screenUtil = screenUtil;
|
||
////this.SqlSugarHelper.Db = sqlSugarScope;
|
||
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 List<DrugInfo>? _drugInfos;
|
||
public List<DrugInfo>? DrugInfos
|
||
{
|
||
get => _drugInfos;
|
||
set => SetProperty(ref _drugInfos, value);
|
||
}
|
||
////拼音码对应药品实体
|
||
//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 根据药品拼音码查询药品名称
|
||
|
||
|
||
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,';',manufactory)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) || di.DrugId.Contains(text)).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList();
|
||
|
||
}
|
||
//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);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 渲染标签状态
|
||
/// </summary>
|
||
private bool _status = false;
|
||
public bool Status
|
||
{
|
||
get => _status;
|
||
set => SetProperty(ref _status, 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;
|
||
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,';',manufactory) as drug_name_spec FROM `drug_info` d";
|
||
DrugInfos = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList();
|
||
|
||
}
|
||
|
||
private void GetChannelsByDrawerNo()
|
||
{
|
||
Channels?.Clear();
|
||
int totalCount = 0;
|
||
var list = SqlSugarHelper.Db.Queryable<ChannelList>()
|
||
.Includes<DrugInfo>(cl => cl.Drug)
|
||
.WhereIF(App.SingleModel, cl => cl.DrawerNo <= 2) //单人登录开前8个抽屉,双人登录开后8个抽屉
|
||
.WhereIF(!(App.SingleModel), cl => cl.DrawerNo > 2)
|
||
.Includes<ChannelStock>(cs => cs.channelStocks)
|
||
.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);
|
||
if (list != null && list.Count > 0)
|
||
{
|
||
for (int i = 0; i < list.Count; i++)
|
||
{
|
||
if (list[i].channelStocks != null && list[i].channelStocks.Count > 0)
|
||
{
|
||
for (int j = 0; j < list[i].channelStocks.Count; j++)
|
||
{
|
||
list[i].totalCount += list[i].channelStocks[j].Quantity;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
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();
|
||
SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo }).ExecuteCommand();
|
||
|
||
int deleteNum = SqlSugarHelper.Db.Deleteable<ChannelStock>()
|
||
.Where(cs => cs.Chnguid.Equals(item.Id) && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"])).ExecuteCommand();
|
||
//插入channel_stock表数据
|
||
SqlSugarHelper.Db.Insertable(new ChannelStock()
|
||
{
|
||
Quantity = 0,
|
||
Chnguid = item.Id,
|
||
DrawerNo = item.DrawerNo,
|
||
ColNo = item.ColNo,
|
||
DrugId = item.DrugId,
|
||
DrawerType = item.DrawerType,
|
||
BoardType = item.BoardType,
|
||
Id = Guid.NewGuid().ToString(),
|
||
MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"
|
||
}).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.Length > 10 ? DrugInfo.Manufactory.Substring(0, 10) : 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);
|
||
}
|
||
//_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)
|
||
{
|
||
if (c > 1)
|
||
{
|
||
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
||
SnackbarMessageQueue.Enqueue("同一药品不可绑多个库位");
|
||
return;
|
||
}
|
||
//else
|
||
//{
|
||
// 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"))
|
||
// .Where(cs=>cs.DrawerNo=)
|
||
// .Count();
|
||
|
||
// if (count > 0)
|
||
// {
|
||
// SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
||
// SnackbarMessageQueue.Enqueue("该药品已绑定库位,不可绑定多个库位");
|
||
// return;
|
||
// }
|
||
//}
|
||
|
||
for (int i = 0; i < SelectChannels.Count; i++)
|
||
{
|
||
var item = SelectChannels[i];
|
||
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"))
|
||
.Where(cs => cs.DrawerNo == item.DrawerNo)
|
||
.Count();
|
||
|
||
if (count > 0)
|
||
{
|
||
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
||
SnackbarMessageQueue.Enqueue("该药品已绑定库位,不可绑定多个库位");
|
||
return;
|
||
}
|
||
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.EffDate = String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate);
|
||
SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo }).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.Length > 10 ? DrugInfo.Manufactory.Substring(0, 10) : 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);
|
||
}
|
||
}
|
||
|
||
|
||
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;
|
||
SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId }).ExecuteCommand();
|
||
SqlSugarHelper.Db.Updateable<ChannelStock>().SetColumns(it => new ChannelStock { DrugId = null, ManuNo = null, EffDate = null }).Where(it => it.Chnguid == item.Id).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("所选库位中无可解绑药品");
|
||
}
|
||
});
|
||
}
|
||
/// <summary>
|
||
/// 渲染标签
|
||
/// </summary>
|
||
public DelegateCommand ResetLabelCommand
|
||
{
|
||
get => new DelegateCommand(ResetLabelMethod, () => Status == false);
|
||
}
|
||
private void ResetLabelMethod()
|
||
{
|
||
if (Channels != null)
|
||
{
|
||
Task t = new Task(() =>
|
||
{
|
||
var SelectChannels = Channels.FindAll(item => item.IsSelected && item.BoardType == 5);
|
||
var c = SelectChannels.Count;
|
||
if (c > 0)
|
||
{
|
||
Status = true;
|
||
SelectChannels.ForEach(item =>
|
||
{
|
||
if (item.DrugId == null)
|
||
{
|
||
// 清除显示屏库位信息
|
||
_portUtil.ClearContent(item.DrawerNo, item.ColNo);
|
||
Thread.Sleep(200);
|
||
_portUtil.ShowContent(item.DrawerNo, item.ColNo);
|
||
Thread.Sleep(200);
|
||
}
|
||
else
|
||
{
|
||
DrugInfo drugSelected = item.Drug ?? new DrugInfo();
|
||
_portUtil.WindowName = "BindingChannelDialog";
|
||
// 向显示屏写入库位信息
|
||
_portUtil.WriteChannelInfo(1, drugSelected.DrugName ?? "", item.DrawerNo, item.ColNo);
|
||
Thread.Sleep(200);
|
||
_portUtil.WriteChannelInfo(2, drugSelected.DrugSpec ?? "", item.DrawerNo, item.ColNo);
|
||
Thread.Sleep(200);
|
||
_portUtil.WriteChannelInfo(8, drugSelected.Manufactory == null ? "" : drugSelected.Manufactory.Length > 10 ? drugSelected.Manufactory.Substring(0, 10) : drugSelected.Manufactory, item.DrawerNo, item.ColNo);
|
||
Thread.Sleep(200);
|
||
_portUtil.ShowContent(item.DrawerNo, item.ColNo);
|
||
Thread.Sleep(200);
|
||
_portUtil.WriteQuantity(item.DrawerNo, item.ColNo, item.totalCount);
|
||
Thread.Sleep(200);
|
||
}
|
||
});
|
||
}
|
||
else
|
||
{
|
||
Application.Current.Dispatcher.Invoke(() =>
|
||
{
|
||
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
||
SnackbarMessageQueue.Enqueue("未选择库位或所选库位无标签");
|
||
});
|
||
|
||
}
|
||
});
|
||
t.Start();
|
||
t.ContinueWith(task =>
|
||
{
|
||
if (Status.Equals(true))
|
||
{
|
||
Status = false;
|
||
Application.Current.Dispatcher.Invoke(() =>
|
||
{
|
||
|
||
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676"));
|
||
SnackbarMessageQueue.Enqueue("操作完成!");
|
||
GetChannelsByDrawerNo();
|
||
});
|
||
}
|
||
});
|
||
}
|
||
}
|
||
//static Task TaskSleep()
|
||
//{
|
||
// //await Task.Delay(200);
|
||
// Thread.Sleep(200);
|
||
//}
|
||
public DelegateCommand BtnCloseCommand
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
//DialogParameters parameters = new DialogParameters();
|
||
//parameters.Add("",);
|
||
// 关闭当前窗口
|
||
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
||
});
|
||
}
|
||
|
||
public bool KeepAlive => true;
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|