766 lines
35 KiB
C#
766 lines
35 KiB
C#
using log4net;
|
|
using Microsoft.Xaml.Behaviors;
|
|
using NetTaste;
|
|
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.Speech.Synthesis;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using DM_Weight.Models;
|
|
using DM_Weight.msg;
|
|
using DM_Weight.Port;
|
|
using DM_Weight.select;
|
|
using DM_Weight.util;
|
|
using System.Threading;
|
|
using System.Windows.Markup;
|
|
|
|
namespace DM_Weight.ViewModels
|
|
{
|
|
public class OrderTakeDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime
|
|
{
|
|
private readonly ILog logger = LogManager.GetLogger(typeof(OrderTakeDialogViewModel));
|
|
public string Title => "处方取药";
|
|
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
private static readonly DateTime Jan1st1970 = new DateTime
|
|
(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
private PortUtil _portUtil;
|
|
IEventAggregator _eventAggregator;
|
|
IDialogService _dialogService;
|
|
public OrderTakeDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService DialogService)
|
|
{
|
|
_dialogService = DialogService;
|
|
_portUtil = portUtil;
|
|
_eventAggregator = eventAggregator;
|
|
}
|
|
|
|
void DoMyPrismEvent(DeviceMsg msg)
|
|
{
|
|
|
|
if (msg.WindowName == "OrderTakeDrugWindow")
|
|
{
|
|
IGrouping<int, ChannelStock> grouping = enumerator.Current;
|
|
int DrawerNo = grouping.Key;
|
|
List<ChannelStock> channelStocks = grouping.ToList();
|
|
|
|
switch (msg.EventType)
|
|
{
|
|
// 抽屉打开
|
|
case EventType.DRAWEROPEN:
|
|
|
|
|
|
if (Status == 1)
|
|
{
|
|
if (channelStocks[0].process == 1)
|
|
{
|
|
channelStocks.ForEach(it => it.process = 2);
|
|
}
|
|
}
|
|
|
|
break;
|
|
// 抽屉关闭
|
|
case EventType.DRAWERCLOSE:
|
|
if (Status == 1)
|
|
{
|
|
if (channelStocks[0].process == 2)
|
|
{
|
|
channelStocks.ForEach(it => it.process = 3);
|
|
}
|
|
IGrouping<int, ChannelStock> groupingBefore = enumerator.Current;
|
|
int DrawerNoBefore = groupingBefore.Key;
|
|
if (enumerator.MoveNext())
|
|
{
|
|
IGrouping<int, ChannelStock> groupingAfter = enumerator.Current;
|
|
int DrawerNoAfter = groupingAfter.Key;
|
|
if (DrawerNoBefore < 9 && DrawerNoAfter > 8)
|
|
{
|
|
Thread.Sleep(50);
|
|
}
|
|
OpenOneByOne();
|
|
}
|
|
// 已经全部取出
|
|
else
|
|
{
|
|
Status = 3;
|
|
}
|
|
}
|
|
break;
|
|
// 数量变化
|
|
case EventType.UPDATEQUANTITY:
|
|
if (Status == 1)
|
|
{
|
|
logger.Info($"抽屉【{DrawerNo}】库位取药数量【{msg.Quantitys}】");
|
|
}
|
|
break;
|
|
// 打开失败
|
|
case EventType.OPENERROR:
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = msg.Message,
|
|
Type = MsgType.ERROR,
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
Status = 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private int _status = 0;
|
|
|
|
public int Status
|
|
{
|
|
get => _status; set => SetProperty(ref _status, value);
|
|
}
|
|
|
|
private OrderInfo? _orderInfo;
|
|
|
|
|
|
public OrderInfo? OrderInfo
|
|
{
|
|
get => _orderInfo;
|
|
set => SetProperty(ref _orderInfo, value);
|
|
}
|
|
|
|
private List<OrderDetail> orderDetails { get; set; }
|
|
|
|
private List<ChannelStock> _channelStocks;
|
|
|
|
public List<ChannelStock> ChannelStocks
|
|
{
|
|
get => _channelStocks;
|
|
set => SetProperty(ref _channelStocks, value);
|
|
}
|
|
|
|
private IEnumerable<IGrouping<int, ChannelStock>> enumerable;
|
|
private IEnumerator<IGrouping<int, ChannelStock>> enumerator;
|
|
|
|
|
|
public bool CanCloseDialog()
|
|
{
|
|
return Status == 0;
|
|
}
|
|
|
|
public void OnDialogClosed()
|
|
{
|
|
// 取消消息订阅
|
|
_eventAggregator.GetEvent<PortUtilEvent>().Unsubscribe(DoMyPrismEvent);
|
|
}
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
{
|
|
_eventAggregator.GetEvent<PortUtilEvent>().Subscribe(DoMyPrismEvent);
|
|
OrderInfo o = parameters.GetValue<OrderInfo>("orderInfo");
|
|
OrderInfo = o;
|
|
RequestData();
|
|
}
|
|
|
|
public async void RequestData()
|
|
{
|
|
orderDetails = SqlSugarHelper.Db.Queryable<OrderDetail>()
|
|
.Includes<DrugInfo>(od => od.DrugInfo)
|
|
.InnerJoin(SqlSugarHelper.Db.Queryable<ChannelStock>().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (od, t) => od.DrugId == t.DrugId)
|
|
.Where(od => od.OrderNo == OrderInfo.OrderNo)
|
|
.ToList();
|
|
|
|
List<ChannelStock> channelStocks = new List<ChannelStock>();
|
|
List<string> msg = new List<string>();
|
|
for (int i = 0; i < orderDetails.Count; i++)
|
|
{
|
|
OrderDetail orderDetail = orderDetails[i];
|
|
|
|
List<ChannelStock> HasQChannels = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
|
.Includes<DrugInfo>(cs => cs.DrugInfo)
|
|
.Where(cs => cs.Quantity > 0)
|
|
.Where(cs => cs.DrawerType == 1)
|
|
.Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1"))
|
|
.WhereIF(!string.IsNullOrEmpty(orderDetail.SetEffDate), cs => cs.EffDate.Equals(orderDetail.SetEffDate))
|
|
.WhereIF(!string.IsNullOrEmpty(orderDetail.SetManuNo), cs => cs.ManuNo.Equals(orderDetail.SetManuNo))
|
|
.Where(cs => cs.DrugId == orderDetail.DrugId)
|
|
.OrderBy(cs => cs.EffDate)
|
|
.OrderBy(cs => cs.DrawerNo)
|
|
.ToList();
|
|
int total = HasQChannels.Sum(it => it.Quantity);
|
|
int TakeQ = orderDetail.Quantity;
|
|
// 说明数量足够
|
|
if (total >= TakeQ)
|
|
{
|
|
for (int j = 0; TakeQ > 0; j++)
|
|
{
|
|
ChannelStock stock = HasQChannels[j];
|
|
if (TakeQ > stock.Quantity)
|
|
{
|
|
stock.TakeQuantity = stock.Quantity;
|
|
channelStocks.Add(stock);
|
|
TakeQ -= stock.Quantity;
|
|
}
|
|
else
|
|
{
|
|
stock.TakeQuantity = TakeQ;
|
|
channelStocks.Add(stock);
|
|
TakeQ = 0;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
msg.Add($"药品【{orderDetail.DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】");
|
|
}
|
|
}
|
|
if (msg.Count > 0)
|
|
{
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
//MessageBox.Show(string.Join("\n", msg));
|
|
DialogParameters dialogParameters = new DialogParameters();
|
|
dialogParameters.Add("msgInfo", msg);
|
|
DialogServiceExtensions.ShowDialogHost(_dialogService, "ShowMessageDialog", dialogParameters, "RootDialog");
|
|
|
|
}
|
|
else
|
|
{
|
|
channelStocks.Sort((a, b) =>
|
|
{
|
|
if ((a.DrawerNo - b.DrawerNo) == 0)
|
|
{
|
|
return a.ColNo - b.ColNo;
|
|
}
|
|
return a.DrawerNo - b.DrawerNo;
|
|
});
|
|
ChannelStocks = channelStocks;
|
|
|
|
|
|
}
|
|
}
|
|
public DelegateCommand OpenDrawer
|
|
{
|
|
get => new DelegateCommand(async () =>
|
|
{
|
|
if (Status == 0)
|
|
{
|
|
enumerable = ChannelStocks.GroupBy(cs => cs.DrawerNo, cs => cs);
|
|
enumerator = enumerable.GetEnumerator();
|
|
enumerator.MoveNext();
|
|
Status = 1;
|
|
OpenOneByOne();
|
|
}
|
|
|
|
});
|
|
}
|
|
public DelegateCommand OpenDrawer_New
|
|
{
|
|
get => new DelegateCommand(async () =>
|
|
{
|
|
OpenDrawerAction();
|
|
|
|
});
|
|
}
|
|
async Task OpenDrawerAction()
|
|
{
|
|
this.Status = 1;
|
|
// 解析需要打开的抽屉列表
|
|
//List<OrderTakeVo> drawerNos = this.data.GroupBy(it => it.ChannelStock.DrawerNo).Select(it => it.First()).ToList();
|
|
|
|
// 根据抽屉类型来决定打开前是否需要查询数量
|
|
var promiseUtil = new PromiseUtil<int>();
|
|
enumerable = ChannelStocks.GroupBy(cs => cs.DrawerNo, cs => cs);
|
|
enumerator = enumerable.GetEnumerator();
|
|
|
|
_portUtil.WindowName = "OrderTakeDrugWindow";
|
|
_portUtil.BoardType = ChannelStocks.Count > 0 ? ChannelStocks[0].BoardType : 1;
|
|
_portUtil.ColNos = ChannelStocks.Select(it => it.ColNo).ToArray();
|
|
enumerator.MoveNext();
|
|
|
|
await promiseUtil.taskAsyncLoop(500, 0, async (options, next, stop) =>
|
|
{
|
|
//var orderTakeVo = drawerNos[options._data];
|
|
//orderTakeVo.ChannelStock.DrawerNo;
|
|
IGrouping<int, ChannelStock> groupingStock = enumerator.Current;
|
|
var drawerNo = groupingStock.Key;
|
|
_portUtil.DrawerNo = groupingStock.Key;
|
|
int[] BeforeQuantity = new int[] { };
|
|
List<ChannelStock> channelStocks = groupingStock.ToList();
|
|
try
|
|
{
|
|
if (this.Status == 0)
|
|
{
|
|
stop();
|
|
}
|
|
// 开启抽屉
|
|
else if (this.Status == 1)
|
|
{
|
|
// 储物箱直接开
|
|
if (channelStocks[0].BoardType == 4)
|
|
{
|
|
if (channelStocks[0].DrawerState == 0)
|
|
{
|
|
byte[] resultOpen = await _portUtil.OpenStorage();
|
|
|
|
int[] rOpen = resultOpen.Select(it => Convert.ToInt32(it)).ToArray();
|
|
if (rOpen[4] != 0)
|
|
{
|
|
logger.Info($"储物箱使能成功");
|
|
channelStocks[0].DrawerState = 1;
|
|
next();
|
|
}
|
|
else
|
|
{
|
|
string _WindowName = "OrderTakeDialog";
|
|
// 重新初始化数据
|
|
_portUtil.ResetData();
|
|
// 指令发送错误,未打开
|
|
// 返回消息 抽屉打开失败
|
|
_eventAggregator.GetEvent<PortUtilEvent>().Publish(new util.DeviceMsg()
|
|
{
|
|
EventType = util.EventType.OPENERROR,
|
|
WindowName = "OrderTakeDialog",
|
|
Message = "储物箱使能失败"
|
|
});
|
|
logger.Info($"储物箱使能失败");
|
|
stop();
|
|
}
|
|
|
|
}
|
|
if (channelStocks[0].DrawerState == 1)
|
|
{
|
|
// 查询锁状态
|
|
byte[] resultBackDoor = await _portUtil.BackDoorState();
|
|
|
|
int[] rBackDoor = resultBackDoor.Select(it => Convert.ToInt32(it)).ToArray();
|
|
int[] lockStates = _portUtil.CheckStorageStatus(rBackDoor.Skip(3).Take(2).ToArray());
|
|
int[] lightStates = _portUtil.CheckStorageStatus(rBackDoor.Skip(5).Take(2).ToArray());
|
|
// 锁处于关闭状态
|
|
if (lockStates[Convert.ToInt32(ConfigurationManager.AppSettings["StorageBoxAddr"]) - 1] == 0)
|
|
{
|
|
// 锁还未打开过
|
|
if (_portUtil.statue == 0)
|
|
{
|
|
// 指示灯不闪烁了,说明规定时间内没有开锁,需要给前台提示
|
|
if (lightStates[Convert.ToInt32(ConfigurationManager.AppSettings["StorageBoxAddr"]) - 1] == 0)
|
|
{
|
|
// 打开失败
|
|
logger.Info($"储物箱指示灯不闪烁,使能过期");
|
|
enumerator.MoveNext();
|
|
next();
|
|
}
|
|
else
|
|
{
|
|
channelStocks[0].DrawerState = 1;
|
|
next();
|
|
}
|
|
}
|
|
else if (_portUtil.statue == 1)
|
|
{
|
|
|
|
// 锁是打开状态现在关闭了,说明操作完成了,告诉前台锁已关闭
|
|
_portUtil.statue = 2;
|
|
logger.Info($"储物箱关闭");
|
|
if (options._data == (enumerable.Count() - 1))
|
|
{
|
|
_portUtil.SpeakAsync($"取药完成,请,点击完成按钮进行确认");
|
|
this.Status = 3;
|
|
channelStocks[0].DrawerState = 0;
|
|
stop();
|
|
}
|
|
else
|
|
{
|
|
channelStocks[0].DrawerState = 0;
|
|
enumerator.MoveNext();
|
|
next();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 外置抽屉
|
|
else
|
|
{
|
|
if (channelStocks[0].DrawerType == 3)
|
|
{
|
|
if (channelStocks[0].BoardType == 2)
|
|
{
|
|
if (channelStocks[0].DrawerState == 0)
|
|
{
|
|
byte[] buffer = await _portUtil.OpenRecover();
|
|
int[] r = buffer.Select(it => Convert.ToInt32(it)).ToArray();
|
|
if ((_portUtil.ColNos[0] > 3 && r[4] == 1) || (_portUtil.ColNos[0] < 4 && r[3] == 1))
|
|
{
|
|
logger.Info($"回收箱打开成功");
|
|
channelStocks[0].DrawerState = 1;
|
|
next();
|
|
}
|
|
else
|
|
{
|
|
logger.Info($"回收箱打开失败");
|
|
stop();
|
|
}
|
|
|
|
}
|
|
if(channelStocks[0].DrawerState == 1)
|
|
{
|
|
// 查询是否关闭状态
|
|
byte[] buffer = await _portUtil.CheckRecoverStatus();
|
|
int[] r = buffer.Select(it => Convert.ToInt32(it)).ToArray();
|
|
|
|
logger.Info($"GeRecoverStatus{string.Join(",", r)}");
|
|
|
|
// 回收箱关闭成功
|
|
if ((_portUtil.ColNos[0] > 3 && r[4] == 0) || (_portUtil.ColNos[0] < 4 && r[3] == 0))
|
|
{
|
|
logger.Info($"回收箱关闭");
|
|
// 查询数量
|
|
byte[] bytes = await _portUtil.CheckRecoverQuantity();
|
|
|
|
int[] r1 = bytes.Select(it => Convert.ToInt32(it)).ToArray();
|
|
// 返回消息库位关闭,放入空瓶数量
|
|
int[] quantitys = r1.Skip(3).Take(3).ToArray();
|
|
int index = _portUtil.ColNos[0] % 3 > 0 ? _portUtil.ColNos[0] % 3 - 1 : 2;
|
|
|
|
// 指定库位放入的药品数量
|
|
int InCount = quantitys[index];
|
|
logger.Info($"回收板数量变化【{string.Join(",", quantitys)}】");
|
|
|
|
enumerator.MoveNext();
|
|
next();
|
|
}
|
|
else
|
|
{
|
|
// 查询是否关闭状态
|
|
await Task.Delay(200);
|
|
next();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (channelStocks[0].DrawerState == 0)
|
|
{
|
|
// 判断是否为单支抽屉
|
|
if (channelStocks[0].BoardType == 2)
|
|
{
|
|
byte[] quantity = await _portUtil.CheckQuantityByDrawer();
|
|
BeforeQuantity = quantity.Select(it => Convert.ToInt32(it)).ToArray().Skip(3).Take(9).ToArray();
|
|
logger.Info($"单支抽屉,开抽屉前检测数量【{string.Join(",", BeforeQuantity)}】");
|
|
|
|
await _portUtil.HasLightOnByCol();
|
|
}
|
|
// 药盒
|
|
if (channelStocks[0].BoardType == 3)
|
|
{
|
|
// 药盒指示灯使能
|
|
await _portUtil.BoxLockLightOn();
|
|
}
|
|
if (channelStocks[0].BoardType == 6)
|
|
{
|
|
// 药盒指示灯使能
|
|
await _portUtil.BoxLockLightOn2();
|
|
}
|
|
byte[] buffer = await _portUtil.OpenDrawer();
|
|
int[] r = buffer.Select(it => Convert.ToInt32(it)).ToArray();
|
|
|
|
logger.Info($"OpenDrawer{string.Join(",", r)}");
|
|
if (_portUtil.DrawerState(r))
|
|
{
|
|
_portUtil.SpeakAsync($"{drawerNo}号抽屉已经打开,请,取药");
|
|
channelStocks[0].DrawerState = 1;
|
|
next();
|
|
}
|
|
else
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = $"抽屉【{drawerNo}】打开失败,请检测硬件",
|
|
Type = MsgType.ERROR,
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
|
|
logger.Info($"抽屉打开失败");
|
|
_portUtil.ResetData();
|
|
stop();
|
|
}
|
|
}
|
|
// 检测状态
|
|
else if (channelStocks[0].DrawerState == 1)
|
|
{
|
|
// 查询抽屉是否为关闭状态
|
|
byte[] buffer = await _portUtil.CheckDrawerStatus();
|
|
|
|
int[] r = buffer.Select(it => Convert.ToInt32(it)).ToArray();
|
|
|
|
logger.Info($"GetDrawerStatus{string.Join(",", r)}");
|
|
// 抽屉没有关闭
|
|
if (_portUtil.DrawerState(r))
|
|
{
|
|
if (channelStocks[0].BoardType == 2)
|
|
{
|
|
byte[] quantity = await _portUtil.CheckQuantityByDrawer();
|
|
int[] AfterQuantity = quantity.Select(it => Convert.ToInt32(it)).ToArray().Skip(3).Take(9).ToArray();
|
|
logger.Info($"AfterQuantity{string.Join(",", AfterQuantity)}");
|
|
logger.Info($"单支抽屉,抽屉未关检测数量【{string.Join(",", AfterQuantity)}】");
|
|
|
|
ChannelStocks.ForEach(cl =>
|
|
{
|
|
if (cl.DrawerNo == drawerNo)
|
|
{
|
|
logger.Info($"单支抽屉【{drawerNo}】,应取药品数量【{cl.Quantity}】,现实取数量【{BeforeQuantity[cl.ColNo - 1] - AfterQuantity[cl.ColNo - 1]}】");
|
|
}
|
|
|
|
});
|
|
}
|
|
next(); // continue iteration
|
|
}
|
|
else
|
|
{
|
|
ChannelStocks.ForEach(cl =>
|
|
{
|
|
if (cl.DrawerNo == drawerNo)
|
|
{
|
|
cl.TakeQuantity = cl.Quantity;
|
|
|
|
}
|
|
});
|
|
channelStocks[0].DrawerState = 2;
|
|
if (options._data == (enumerable.Count() - 1))
|
|
{
|
|
_portUtil.SpeakAsync($"取药完成,请,点击完成按钮进行确认");
|
|
this.Status = 3;
|
|
channelStocks[0].DrawerState = 0;
|
|
stop();
|
|
}
|
|
else
|
|
{
|
|
options._data += 1;
|
|
channelStocks[0].DrawerState = 0;
|
|
enumerator.MoveNext();
|
|
next();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
//_portUtil.ResetData();
|
|
logger.Info($"处方取药发生错误,{e.Message}"); AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = $"处方取药发生错误{e.Message}",
|
|
Type = MsgType.ERROR,
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
|
|
stop();
|
|
}
|
|
});
|
|
}
|
|
private void OpenOneByOne()
|
|
{
|
|
IGrouping<int, ChannelStock> grouping = enumerator.Current;
|
|
int DrawerNo = grouping.Key;
|
|
List<ChannelStock> channelStocks = grouping.ToList();
|
|
channelStocks.ForEach(it => it.process = 1);
|
|
_portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉");
|
|
|
|
|
|
List<ChannelStock> singleChannels = channelStocks.FindAll(it => it.BoardType != 1);
|
|
|
|
// 发送取药数量
|
|
singleChannels.ForEach(it =>
|
|
{
|
|
try
|
|
{
|
|
|
|
_portUtil.TakeQuantity(DrawerNo, it.ColNo, it.TakeQuantity, it.Quantity - it.TakeQuantity);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = $"打开抽屉异常{ex.Message}",
|
|
Type = MsgType.ERROR,
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
});
|
|
|
|
_portUtil.WindowName = "OrderTakeDrugWindow";
|
|
_portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1;
|
|
_portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray();
|
|
_portUtil.DrawerNo = DrawerNo;
|
|
_portUtil.Start();
|
|
}
|
|
|
|
private bool _isFinishClick = false;
|
|
// 完成按钮
|
|
public DelegateCommand TakeFinish
|
|
{
|
|
get => new DelegateCommand(() =>
|
|
{
|
|
if (!_isFinishClick)
|
|
{
|
|
_isFinishClick = true;
|
|
List<ChannelStock> record = ChannelStocks.FindAll(it => it.TakeQuantity > 0).ToList();
|
|
if (record.Count > 0)
|
|
{
|
|
string InvoiceId = OrderInfo.OrderNo;
|
|
var f = SqlSugarHelper.Db.UseTran(() =>
|
|
{
|
|
SqlSugarHelper.Db.Updateable(new OrderInfo()
|
|
{
|
|
DmStatus = 1,
|
|
OrderNo = OrderInfo.OrderNo
|
|
}).UpdateColumns(it => new { it.DmStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand();
|
|
|
|
SqlSugarHelper.Db.Insertable(new OrderFinish()
|
|
{
|
|
OrderNo = OrderInfo.OrderNo,
|
|
PatientId = OrderInfo.PatientId,
|
|
Pharmacy = OrderInfo.Pharmacy,
|
|
State = 1,
|
|
Operator = HomeWindowViewModel.Operator?.Nickname,
|
|
});
|
|
|
|
for (int i = 0; i < record.Count; i++)
|
|
{
|
|
ChannelStock it = record[i];
|
|
// 更新数据 库存信息
|
|
SqlSugarHelper.Db.Updateable(new ChannelStock()
|
|
{
|
|
Quantity = it.Quantity - it.TakeQuantity,
|
|
ManuNo = it.ManuNo,
|
|
EffDate = it.EffDate,
|
|
Id = it.Id,
|
|
}).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand();
|
|
// 获取更新完库存后的药品库存
|
|
List<ChannelStock> nowChannels = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
|
.Where(cs => cs.MachineId.Equals(it.MachineId))
|
|
.Where(cs => cs.DrugId.Equals(it.DrugId))
|
|
.Where(cs => cs.DrawerType == 1)
|
|
.ToList();
|
|
|
|
// 保存数据 出库记录
|
|
SqlSugarHelper.Db.Insertable(new MachineRecord()
|
|
{
|
|
MachineId = it.MachineId,
|
|
DrawerNo = it.DrawerNo,
|
|
ColNo = it.ColNo,
|
|
DrugId = it.DrugId,
|
|
ManuNo = it.ManuNo,
|
|
EffDate = !String.IsNullOrEmpty(it.EffDate) ? DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
|
|
Operator = HomeWindowViewModel.Operator?.Id,
|
|
Reviewer = HomeWindowViewModel.Reviewer?.Id,
|
|
OperationTime = DateTime.Now,
|
|
Quantity = it.TakeQuantity,
|
|
Type = 2,
|
|
InvoiceId = InvoiceId,
|
|
StockQuantity = nowChannels.Sum(it => it.Quantity)
|
|
}).ExecuteCommand();
|
|
}
|
|
return true;
|
|
});
|
|
if (f.Data)
|
|
{
|
|
// 更新屏显库存
|
|
List<ChannelStock> singleChannels = record.FindAll(it => it.BoardType != 1);
|
|
if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5)
|
|
{
|
|
singleChannels.ForEach(it =>
|
|
{
|
|
_portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity);
|
|
});
|
|
}
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "抽屉取药完成,库存已更新",
|
|
Type = MsgType.SUCCESS,
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
if (!f.IsSuccess)
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "抽屉取药完成,库存更新失败!",
|
|
Type = MsgType.ERROR,
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
Status = 0;
|
|
_isFinishClick = false;
|
|
//RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
}
|
|
else
|
|
{
|
|
_isFinishClick = false;
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "没有填写取药数量",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
public long CurrentTimeMillis()
|
|
{
|
|
return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
|
|
}
|
|
|
|
// 取消按钮
|
|
public DelegateCommand CancleTake
|
|
{
|
|
get => new DelegateCommand(() =>
|
|
{
|
|
//Status = 0;
|
|
//_portUtil.statue = 0;
|
|
//_portUtil.ResetData();
|
|
|
|
|
|
if (Status != 0)
|
|
{
|
|
_portUtil.ResetData();
|
|
Status = 0;
|
|
}
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
});
|
|
}
|
|
|
|
public DelegateCommand BtnCloseCommand
|
|
{
|
|
get => new DelegateCommand(() =>
|
|
{
|
|
if (Status != 0)
|
|
{
|
|
_portUtil.ResetData();
|
|
Status = 0;
|
|
}
|
|
//DialogParameters parameters = new DialogParameters();
|
|
//parameters.Add("",);
|
|
// 关闭当前窗口
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
});
|
|
}
|
|
|
|
public bool KeepAlive => false;
|
|
}
|
|
}
|