2023-11-13 13:25:46 +08:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2024-09-12 18:01:56 +08:00
|
|
|
|
|
|
|
|
|
//取药人(科室)
|
|
|
|
|
private string receivePerson;
|
|
|
|
|
public string ReceivePerson
|
|
|
|
|
{
|
|
|
|
|
get => receivePerson;
|
|
|
|
|
set => SetProperty(ref receivePerson, value);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-13 13:25:46 +08:00
|
|
|
|
private PortUtil _portUtil;
|
|
|
|
|
IEventAggregator _eventAggregator;
|
2024-08-29 16:11:06 +08:00
|
|
|
|
IDialogService _dialogService;
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//private SqlSugarScope SqlSugarHelper.Db;
|
2023-11-27 15:35:22 +08:00
|
|
|
|
public OrderTakeDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService DialogService, SqlSugarScope sqlSugarScope)
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
|
|
|
|
_dialogService = DialogService;
|
|
|
|
|
_portUtil = portUtil;
|
|
|
|
|
_eventAggregator = eventAggregator;
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//this.SqlSugarHelper.Db = sqlSugarScope;
|
2023-11-13 13:25:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//IGrouping<int, ChannelStock> groupingBefore = enumerator.Current;
|
|
|
|
|
//int DrawerNoBefore = groupingBefore.Key;
|
2023-11-13 13:25:46 +08:00
|
|
|
|
if (enumerator.MoveNext())
|
|
|
|
|
{
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//IGrouping<int, ChannelStock> groupingAfter = enumerator.Current;
|
|
|
|
|
//int DrawerNoAfter = groupingAfter.Key;
|
|
|
|
|
//if (DrawerNoBefore < 9 && DrawerNoAfter > 8)
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
2024-02-04 13:35:45 +08:00
|
|
|
|
Thread.Sleep(80);
|
2023-11-13 13:25:46 +08:00
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-27 15:35:22 +08:00
|
|
|
|
public void RequestData()
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
2024-08-29 16:11:06 +08:00
|
|
|
|
orderDetails = SqlSugarHelper.Db.Queryable<OrderDetail>()
|
2025-03-21 14:42:32 +08:00
|
|
|
|
//.Includes<DrugInfo>(od => od.DrugInfo)
|
2024-08-29 16:11:06 +08:00
|
|
|
|
.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)
|
2025-03-21 14:42:32 +08:00
|
|
|
|
.Where(od => od.OrderNo == OrderInfo.OrderNo&&od.DetailStatus==0)
|
|
|
|
|
.Select(od => new OrderDetail
|
|
|
|
|
{
|
|
|
|
|
Id = od.Id,
|
|
|
|
|
DrugId = od.DrugId,
|
|
|
|
|
SetEffDate = od.SetEffDate,
|
|
|
|
|
SetManuNo = od.SetManuNo,
|
|
|
|
|
OrderNo = od.OrderNo,
|
|
|
|
|
Quantity = SqlFunc.AggregateSum(od.Quantity)
|
|
|
|
|
})
|
|
|
|
|
.GroupBy(od => new { od.DrugId, od.SetEffDate, od.SetManuNo })
|
2024-08-29 16:11:06 +08:00
|
|
|
|
.ToList();
|
2023-11-13 13:25:46 +08:00
|
|
|
|
|
|
|
|
|
List<ChannelStock> channelStocks = new List<ChannelStock>();
|
|
|
|
|
List<string> msg = new List<string>();
|
|
|
|
|
for (int i = 0; i < orderDetails.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
OrderDetail orderDetail = orderDetails[i];
|
|
|
|
|
|
2024-09-29 16:58:56 +08:00
|
|
|
|
//bool bAdmin=false;
|
|
|
|
|
////有开后8个抽屉的权限
|
|
|
|
|
//if(App.CurrentFaUserList.Role.LastEightChecked=="1")
|
|
|
|
|
//{
|
|
|
|
|
// bAdmin = true;
|
|
|
|
|
//}
|
2024-02-04 13:35:45 +08:00
|
|
|
|
List<ChannelStock> HasQChannels = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
2023-11-13 13:25:46 +08:00
|
|
|
|
.Includes<DrugInfo>(cs => cs.DrugInfo)
|
2024-02-04 13:35:45 +08:00
|
|
|
|
.InnerJoin<ChannelList>((cs, cl) => cs.Chnguid == cl.Id && cs.DrugId == cl.DrugId)
|
2023-11-13 13:25:46 +08:00
|
|
|
|
.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)
|
2025-01-02 13:48:01 +08:00
|
|
|
|
.WhereIF(App.SingleModel, cs => cs.DrawerNo <= 2) //单人登录开前2个抽屉,双人登录开后14个抽屉
|
|
|
|
|
.WhereIF(!(App.SingleModel), cs => cs.DrawerNo > 2)
|
2023-11-13 13:25:46 +08:00
|
|
|
|
.OrderBy(cs => cs.EffDate)
|
2025-06-10 16:14:33 +08:00
|
|
|
|
//.OrderBy(cs => cs.DrawerNo)
|
|
|
|
|
//.OrderBy(cs => cs.ManuNo)
|
|
|
|
|
.OrderBy(cs=>cs.FillTime)
|
2023-11-13 13:25:46 +08:00
|
|
|
|
.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
|
|
|
|
|
{
|
2025-03-21 14:42:32 +08:00
|
|
|
|
msg.Add($"药品【{HasQChannels[0].DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】");
|
2023-11-13 13:25:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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");
|
2024-08-29 16:11:06 +08:00
|
|
|
|
|
2023-11-13 13:25:46 +08:00
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 + "号抽屉");
|
|
|
|
|
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//List<ChannelStock> singleChannels = channelStocks.FindAll(it => it.BoardType != 1);
|
2024-03-18 16:53:47 +08:00
|
|
|
|
List<ChannelStock> singleChannels = new List<ChannelStock>();
|
|
|
|
|
for (int i = 0; i < channelStocks.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
ChannelStock copy = TransExpV2<ChannelStock, ChannelStock>.Trans(channelStocks[i]);
|
|
|
|
|
singleChannels.Add(copy);
|
|
|
|
|
}
|
2024-08-29 16:11:06 +08:00
|
|
|
|
singleChannels = singleChannels
|
2024-02-04 13:35:45 +08:00
|
|
|
|
.GroupBy(it => new { it.DrawerNo, it.ColNo })
|
|
|
|
|
.Select(it =>
|
|
|
|
|
{
|
|
|
|
|
var ret = it.First();
|
|
|
|
|
ret.Quantity = it.Sum(it => it.Quantity);
|
|
|
|
|
ret.TakeQuantity = it.Sum(it => it.TakeQuantity);
|
|
|
|
|
return ret;
|
|
|
|
|
})
|
|
|
|
|
.ToList()
|
|
|
|
|
.FindAll(it => it.BoardType != 1);
|
2023-11-13 13:25:46 +08:00
|
|
|
|
|
|
|
|
|
// 发送取药数量
|
|
|
|
|
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;
|
2024-02-04 13:35:45 +08:00
|
|
|
|
_portUtil.ColNos = new int[] { };// singleChannels.Select(it => it.ColNo).ToArray();
|
|
|
|
|
//_portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray();
|
2023-11-13 13:25:46 +08:00
|
|
|
|
_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)
|
|
|
|
|
{
|
2025-03-14 14:04:10 +08:00
|
|
|
|
|
2023-11-13 13:25:46 +08:00
|
|
|
|
string InvoiceId = OrderInfo.OrderNo;
|
2024-02-04 13:35:45 +08:00
|
|
|
|
var f = SqlSugarHelper.Db.UseTran(() =>
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
2024-02-04 13:35:45 +08:00
|
|
|
|
SqlSugarHelper.Db.Updateable(new OrderInfo()
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
|
|
|
|
DmStatus = 1,
|
|
|
|
|
OrderNo = OrderInfo.OrderNo
|
|
|
|
|
}).UpdateColumns(it => new { it.DmStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand();
|
|
|
|
|
|
2025-03-21 14:42:32 +08:00
|
|
|
|
//SqlSugarHelper.Db.Insertable(new OrderFinish()
|
|
|
|
|
//{
|
|
|
|
|
// OrderNo = OrderInfo.OrderNo,
|
|
|
|
|
// PatientId = OrderInfo.PatientId,
|
|
|
|
|
// Pharmacy = OrderInfo.Pharmacy,
|
|
|
|
|
// State = 1,
|
|
|
|
|
// Operator = HomeWindowViewModel.Operator?.Nickname,
|
|
|
|
|
//});
|
2023-11-13 13:25:46 +08:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < record.Count; i++)
|
|
|
|
|
{
|
2025-03-14 14:04:10 +08:00
|
|
|
|
int ordinalNum = SqlSugarHelper.Db.Queryable<MachineRecord>()
|
2025-03-14 14:46:38 +08:00
|
|
|
|
.Where(mr => mr.OperationTime.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")&&mr.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1"))
|
2025-03-14 14:04:10 +08:00
|
|
|
|
.Max(mr => mr.OrdinalNum);
|
2023-11-13 13:25:46 +08:00
|
|
|
|
ChannelStock it = record[i];
|
|
|
|
|
// 更新数据 库存信息
|
2024-02-04 13:35:45 +08:00
|
|
|
|
SqlSugarHelper.Db.Updateable(new ChannelStock()
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
|
|
|
|
Quantity = it.Quantity - it.TakeQuantity,
|
|
|
|
|
ManuNo = it.ManuNo,
|
|
|
|
|
EffDate = it.EffDate,
|
|
|
|
|
Id = it.Id,
|
|
|
|
|
}).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand();
|
|
|
|
|
// 获取更新完库存后的药品库存
|
2024-02-04 13:35:45 +08:00
|
|
|
|
List<ChannelStock> nowChannels = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
2023-11-13 13:25:46 +08:00
|
|
|
|
.Where(cs => cs.MachineId.Equals(it.MachineId))
|
|
|
|
|
.Where(cs => cs.DrugId.Equals(it.DrugId))
|
|
|
|
|
.Where(cs => cs.DrawerType == 1)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
// 保存数据 出库记录
|
2024-02-04 13:35:45 +08:00
|
|
|
|
SqlSugarHelper.Db.Insertable(new MachineRecord()
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
|
|
|
|
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),
|
2024-02-04 13:35:45 +08:00
|
|
|
|
ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity),
|
|
|
|
|
SupplierDept = ConfigurationManager.AppSettings["receiveDept"].ToString(),
|
2024-09-12 18:01:56 +08:00
|
|
|
|
ReceiveDept = OrderInfo.DeptName,
|
2025-03-14 14:04:10 +08:00
|
|
|
|
ReceivePerson = ReceivePerson,
|
2025-03-18 17:20:40 +08:00
|
|
|
|
OrdinalNum = ordinalNum<=0?1:ordinalNum+ 1,
|
2023-11-13 13:25:46 +08:00
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
}
|
2025-03-21 14:42:32 +08:00
|
|
|
|
//更新处方明细状态为已取药1
|
|
|
|
|
List<OrderDetail> orderDetailLst = SqlSugarHelper.Db.Queryable<OrderDetail>().Where(od => od.OrderNo == OrderInfo.OrderNo && od.DetailStatus == 0).ToList();
|
|
|
|
|
if (orderDetailLst != null && orderDetailLst.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
orderDetailLst.ForEach(od => od.DetailStatus = 1);
|
|
|
|
|
SqlSugarHelper.Db.Updateable(orderDetailLst).UpdateColumns(it => new { it.DetailStatus }).ExecuteCommand();
|
|
|
|
|
}
|
2023-11-13 13:25:46 +08:00
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
if (f.Data)
|
|
|
|
|
{
|
|
|
|
|
// 更新屏显库存
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//List<ChannelStock> singleChannels = record.FindAll(it => it.BoardType != 1);
|
|
|
|
|
List<ChannelStock> singleChannels = record.Where(it => it.BoardType != 1)
|
|
|
|
|
.GroupBy(it => it.ColNo)
|
|
|
|
|
.Select(it =>
|
|
|
|
|
{
|
|
|
|
|
var ret = it.First();
|
|
|
|
|
//ret.Quantity = it.Sum(itx => itx.Quantity);
|
|
|
|
|
//ret.AddQuantity = it.Sum(itx => itx.AddQuantity);
|
|
|
|
|
return ret;
|
|
|
|
|
}).ToList();
|
|
|
|
|
//if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5)
|
|
|
|
|
//{
|
2024-08-29 16:11:06 +08:00
|
|
|
|
//singleChannels.ForEach(it =>
|
|
|
|
|
//{
|
|
|
|
|
// _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity);
|
|
|
|
|
//});
|
2024-02-04 13:35:45 +08:00
|
|
|
|
//}
|
2024-08-29 16:11:06 +08:00
|
|
|
|
if (singleChannels.Count > 0)
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
2024-02-04 13:35:45 +08:00
|
|
|
|
for (int i = 0; i < singleChannels.Count; i++)
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
2024-02-04 13:35:45 +08:00
|
|
|
|
if (singleChannels[i].BoardType == 5)
|
|
|
|
|
{
|
2025-05-27 14:01:29 +08:00
|
|
|
|
List<ChannelStock> csList = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
|
|
|
|
.Where(cs => cs.MachineId == singleChannels[i].MachineId)
|
|
|
|
|
.Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo)
|
|
|
|
|
.Where(cs => cs.ColNo == singleChannels[i].ColNo&&cs.Quantity>0).OrderBy(cs => cs.EffDate).ToList();
|
|
|
|
|
|
|
|
|
|
if (csList != null && csList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
int totalQuantity = csList.Sum(c => c.Quantity);
|
|
|
|
|
|
|
|
|
|
//SqlSugarHelper.Db.Queryable<ChannelStock>()
|
|
|
|
|
// .Where(cs => cs.MachineId == singleChannels[i].MachineId)
|
|
|
|
|
// .Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo)
|
|
|
|
|
// .Where(cs => cs.ColNo == singleChannels[i].ColNo)
|
|
|
|
|
// .Sum(it => it.Quantity);
|
|
|
|
|
|
|
|
|
|
_portUtil.WriteChannelInfo(5, csList[0].EffDate == null ? "" : csList[0].EffDate, csList[0].DrawerNo, csList[0].ColNo);
|
|
|
|
|
Thread.Sleep(200);
|
|
|
|
|
_portUtil.WriteChannelInfo(6, csList[0].ManuNo == null ? "" : csList[0].ManuNo, csList[0].DrawerNo, csList[0].ColNo);
|
|
|
|
|
Thread.Sleep(200);
|
|
|
|
|
_portUtil.ShowContent(csList[0].DrawerNo, csList[0].ColNo);
|
|
|
|
|
Thread.Sleep(200);
|
|
|
|
|
//将库位多批次的总库存数更新标签
|
|
|
|
|
_portUtil.WriteQuantity(csList[i].DrawerNo, csList[i].ColNo, totalQuantity);
|
|
|
|
|
Thread.Sleep(200);
|
|
|
|
|
}
|
2024-02-04 13:35:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-13 13:25:46 +08:00
|
|
|
|
}
|
|
|
|
|
AlertMsg alertMsg = new AlertMsg
|
|
|
|
|
{
|
|
|
|
|
Message = "抽屉取药完成,库存已更新",
|
|
|
|
|
Type = MsgType.SUCCESS,
|
|
|
|
|
};
|
|
|
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
|
|
|
}
|
2024-08-29 16:11:06 +08:00
|
|
|
|
if (!f.IsSuccess)
|
2023-11-13 13:25:46 +08:00
|
|
|
|
{
|
|
|
|
|
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(() =>
|
|
|
|
|
{
|
|
|
|
|
_portUtil.ResetData();
|
|
|
|
|
Status = 0;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 13:35:45 +08:00
|
|
|
|
public bool KeepAlive => true;
|
2023-11-13 13:25:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|