833 lines
36 KiB
C#
833 lines
36 KiB
C#
using DM_Weight.Models;
|
|
using DM_Weight.msg;
|
|
using DM_Weight.Port;
|
|
using DM_Weight.select;
|
|
using DM_Weight.util;
|
|
using log4net;
|
|
using log4net.Repository.Hierarchy;
|
|
using Prism.Commands;
|
|
using Prism.Events;
|
|
using Prism.Mvvm;
|
|
using Prism.Regions;
|
|
using Prism.Services.Dialogs;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Media;
|
|
|
|
namespace DM_Weight.ViewModels
|
|
{
|
|
public class CheckOrderNewWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime
|
|
{
|
|
private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
|
|
|
|
private int _pageNum = 1;
|
|
public int PageNum
|
|
{
|
|
get => _pageNum;
|
|
set
|
|
{
|
|
SetProperty(ref _pageNum, value);
|
|
RequestData();
|
|
}
|
|
}
|
|
|
|
private int _pageCount = 1;
|
|
public int PageCount
|
|
{
|
|
get => _pageCount;
|
|
set
|
|
{
|
|
SetProperty(ref _pageCount, value);
|
|
}
|
|
}
|
|
|
|
private int _pageSize = 10;
|
|
public int PageSize
|
|
{
|
|
get => _pageSize;
|
|
set
|
|
{
|
|
SetProperty(ref _pageSize, value);
|
|
}
|
|
}
|
|
|
|
private int _totalCount = 0;
|
|
public int TotalCount
|
|
{
|
|
get => _totalCount;
|
|
set
|
|
{
|
|
SetProperty(ref _totalCount, value);
|
|
}
|
|
}
|
|
//所选药箱号
|
|
private int _drawerNo = -1;
|
|
|
|
public int DrawerNo
|
|
{
|
|
get => _drawerNo;
|
|
set => SetProperty(ref _drawerNo, value);
|
|
}
|
|
|
|
private string _orderDate = DateTime.Now.ToString("yyyy-MM-dd");
|
|
/// <summary>
|
|
/// 查询条件 处方日期
|
|
/// </summary>
|
|
public string OrderDate
|
|
{
|
|
get { return _orderDate; }
|
|
set
|
|
{
|
|
if (!String.IsNullOrEmpty(value))
|
|
{
|
|
SetProperty(ref _orderDate, DateTime.Parse(value).ToString("yyyy-MM-dd"));
|
|
}
|
|
else
|
|
{
|
|
SetProperty(ref _orderDate, value);
|
|
}
|
|
|
|
RequestData();
|
|
}
|
|
}
|
|
private bool _isEnable = true;
|
|
public bool IsEnable { get => _isEnable; set => SetProperty(ref _isEnable, value); }
|
|
private int _status = 0;
|
|
public int Status { get => _status; set { SetProperty(ref _status, value); } }
|
|
|
|
|
|
|
|
private List<OrderInfo> _ordersList = new List<OrderInfo>();
|
|
public List<OrderInfo> OrderInfoList
|
|
{
|
|
get => _ordersList;
|
|
set => SetProperty(ref _ordersList, value);
|
|
}
|
|
|
|
private List<TotalDrug>? _totalDrugList = new List<TotalDrug>();
|
|
public List<TotalDrug>? TotalDrugList
|
|
{
|
|
get => _totalDrugList;
|
|
set => SetProperty(ref _totalDrugList, value);
|
|
}
|
|
|
|
private OrderInfo _selectOrderInfo;
|
|
public OrderInfo selectOrderInfo { get => _selectOrderInfo; set => SetProperty(ref _selectOrderInfo, value); }
|
|
|
|
|
|
private Brush _button1Color = Brushes.White;
|
|
public Brush Button1Color
|
|
{
|
|
get => _button1Color;
|
|
set => SetProperty(ref _button1Color, value);
|
|
}
|
|
private Brush _button2Color = Brushes.White;
|
|
public Brush Button2Color
|
|
{
|
|
get => _button2Color;
|
|
set => SetProperty(ref _button2Color, value);
|
|
}
|
|
private Brush _button3Color = Brushes.White;
|
|
public Brush Button3Color
|
|
{
|
|
get => _button3Color;
|
|
set => SetProperty(ref _button3Color, value);
|
|
}
|
|
private Brush _button4Color = Brushes.White;
|
|
public Brush Button4Color
|
|
{
|
|
get => _button4Color;
|
|
set => SetProperty(ref _button4Color, value);
|
|
}
|
|
private Brush _button5Color = Brushes.White;
|
|
public Brush Button5Color
|
|
{
|
|
get => _button5Color;
|
|
set => SetProperty(ref _button5Color, value);
|
|
}
|
|
private Brush _button6Color = Brushes.White;
|
|
public Brush Button6Color
|
|
{
|
|
get => _button6Color;
|
|
set => SetProperty(ref _button6Color, value);
|
|
}
|
|
private Brush _button7Color = Brushes.White;
|
|
public Brush Button7Color
|
|
{
|
|
get => _button7Color;
|
|
set => SetProperty(ref _button7Color, value);
|
|
}
|
|
private Brush _button8Color = Brushes.White;
|
|
public Brush Button8Color
|
|
{
|
|
get => _button8Color;
|
|
set => SetProperty(ref _button8Color, value);
|
|
}
|
|
private Brush _button9Color = Brushes.White;
|
|
public Brush Button9Color
|
|
{
|
|
get => _button9Color;
|
|
set => SetProperty(ref _button9Color, value);
|
|
}
|
|
private Brush _button10Color = Brushes.White;
|
|
public Brush Button10Color
|
|
{
|
|
get => _button10Color;
|
|
set => SetProperty(ref _button10Color, value);
|
|
}
|
|
private Brush _button11Color = Brushes.White;
|
|
public Brush Button11Color
|
|
{
|
|
get => _button11Color;
|
|
set => SetProperty(ref _button11Color, value);
|
|
}
|
|
private Brush _button12Color = Brushes.White;
|
|
public Brush Button12Color
|
|
{
|
|
get => _button12Color;
|
|
set => SetProperty(ref _button12Color, value);
|
|
}
|
|
private Brush _button13Color = Brushes.White;
|
|
public Brush Button13Color
|
|
{
|
|
get => _button13Color;
|
|
set => SetProperty(ref _button13Color, value);
|
|
}
|
|
private Brush _button14Color = Brushes.White;
|
|
public Brush Button14Color
|
|
{
|
|
get => _button14Color;
|
|
set => SetProperty(ref _button14Color, value);
|
|
}
|
|
private Brush _button15Color = Brushes.White;
|
|
public Brush Button15Color
|
|
{
|
|
get => _button15Color;
|
|
set => SetProperty(ref _button15Color, value);
|
|
}
|
|
private Brush _button16Color = Brushes.White;
|
|
public Brush Button16Color
|
|
{
|
|
get => _button16Color;
|
|
set => SetProperty(ref _button16Color, value);
|
|
}
|
|
private Brush _button17Color = Brushes.White;
|
|
public Brush Button17Color
|
|
{
|
|
get => _button17Color;
|
|
set => SetProperty(ref _button17Color, value);
|
|
}
|
|
private Brush _button18Color = Brushes.White;
|
|
public Brush Button18Color
|
|
{
|
|
get => _button18Color;
|
|
set => SetProperty(ref _button18Color, value);
|
|
}
|
|
|
|
IEventAggregator _eventAggregator;
|
|
private PortUtil _portUtil;
|
|
public CheckOrderNewWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator)
|
|
{
|
|
_portUtil = portUtil;
|
|
_eventAggregator = eventAggregator;
|
|
}
|
|
|
|
private string? _searchValue;
|
|
|
|
/// <summary>
|
|
/// 查询条件 查询字段值
|
|
/// </summary>
|
|
public string? SearchValue
|
|
{
|
|
get { return _searchValue; }
|
|
set
|
|
{
|
|
SetProperty(ref _searchValue, value);
|
|
RequestData();
|
|
}
|
|
}
|
|
void RequestData()
|
|
{
|
|
int totalCount = 0;
|
|
if (DrawerNo >= 0)
|
|
{
|
|
//查询当前药箱归属的药师
|
|
ChannelList currentList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.DrawerNo == DrawerNo + 1 && cl.MachineId == "DM5").First();//.Select(cl => cl.BelongUser).First();
|
|
string currentDrawerUser = currentList.BelongUser;
|
|
OrderInfoList = SqlSugarHelper.Db.Queryable<OrderInfo>()
|
|
.Includes(oi => oi.OrderDetailList, od => od.DrugInfo)
|
|
//.Includes(cl => cl.channelStocks, cs => cs.DrugInfo,di=>di.drugBase)
|
|
//.InnerJoin<OrderDetail>((oi, od) => oi.OrderNo == od.OrderNo)
|
|
//.InnerJoin<DrugInfo>((oi, od, di) => od.DrugId == di.DrugId.ToString())
|
|
.WhereIF(OrderDate != null, oi => oi.RecvDate.ToString("yyyy-MM-dd") == OrderDate)
|
|
.WhereIF(!String.IsNullOrEmpty(ConfigurationManager.AppSettings["storage"]), oi => oi.Pharmacy == ConfigurationManager.AppSettings["storage"])
|
|
.Where(oi => oi.DmStatus == 0)
|
|
.Where(oi => oi.HisDispFlag == 0)
|
|
.Where(oi => oi.CancelFlag == 0)
|
|
.Where(oi => oi.DoctorCode == currentDrawerUser)
|
|
.OrderBy(oi => oi.OrderId)
|
|
.ToPageList(PageNum, PageSize, ref totalCount);
|
|
|
|
if (OrderInfoList != null && OrderInfoList.Count() > 0)
|
|
{
|
|
OrderInfoList.ForEach(oi => oi.ItemIsChecked = true);
|
|
//TotalDrugList = OrderInfoList.Where(oi => oi.ItemIsChecked).GroupBy(oi => oi.OrderDetailList.DrugInfo.DrugName).Select(oi => new TotalDrug { DrugName = oi.Key, TotalCount = oi.Sum(item => item.OrderDetailList.Quantity) }).ToList();
|
|
TotalDrugList = OrderInfoList.Where(oi => oi.ItemIsChecked).SelectMany(OrderDetailList => OrderDetailList.OrderDetailList).GroupBy(item => item.DrugInfo.DrugName).Select(group => new TotalDrug { DrugName = group.Key, TotalCount = group.Sum(item => item.Quantity) }).ToList();
|
|
|
|
}
|
|
else
|
|
{
|
|
TotalDrugList = null;
|
|
}
|
|
|
|
TotalCount = totalCount;
|
|
PageCount = (int)Math.Ceiling((double)TotalCount / PageSize);
|
|
if (Convert.ToDateTime(currentList.EffDate).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
|
|
{
|
|
switch (DrawerNo)
|
|
{
|
|
case 1:
|
|
_button1Color = Brushes.Yellow;
|
|
break;
|
|
case 2:
|
|
_button2Color = Brushes.Yellow;
|
|
break;
|
|
case 3:
|
|
_button3Color = Brushes.Yellow;
|
|
break;
|
|
case 4:
|
|
_button4Color = Brushes.Yellow;
|
|
break;
|
|
case 5:
|
|
_button5Color = Brushes.Yellow;
|
|
break;
|
|
case 6:
|
|
_button6Color = Brushes.Yellow;
|
|
break;
|
|
case 7:
|
|
_button7Color = Brushes.Yellow;
|
|
break;
|
|
case 8:
|
|
_button8Color = Brushes.Yellow;
|
|
break;
|
|
case 9:
|
|
_button9Color = Brushes.Yellow;
|
|
break;
|
|
case 10:
|
|
_button10Color = Brushes.Yellow;
|
|
break;
|
|
case 11:
|
|
_button11Color = Brushes.Yellow;
|
|
break;
|
|
case 12:
|
|
_button12Color = Brushes.Yellow;
|
|
break;
|
|
case 13:
|
|
_button13Color = Brushes.Yellow;
|
|
break;
|
|
case 14:
|
|
_button14Color = Brushes.Yellow;
|
|
break;
|
|
case 15:
|
|
_button15Color = Brushes.Yellow;
|
|
break;
|
|
case 16:
|
|
_button16Color = Brushes.Yellow;
|
|
break;
|
|
case 17:
|
|
_button17Color = Brushes.Yellow;
|
|
break;
|
|
case 18:
|
|
_button18Color = Brushes.Yellow;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
List<ChannelList> chlList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5").ToList();//.Select(cl => cl.BelongUser).First();
|
|
if (chlList != null && chlList.Count > 0)
|
|
{
|
|
for (int i = 0; i < chlList.Count; i++)
|
|
{
|
|
ChannelList chl = chlList[i];
|
|
if (Convert.ToDateTime(chl.EffDate).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
|
|
{
|
|
switch (chl.DrawerNo)
|
|
{
|
|
case 1:
|
|
Button1Color = Brushes.Yellow;
|
|
break;
|
|
case 2:
|
|
Button2Color = Brushes.Yellow;
|
|
break;
|
|
case 3:
|
|
Button3Color = Brushes.Yellow;
|
|
break;
|
|
case 4:
|
|
Button4Color = Brushes.Yellow;
|
|
break;
|
|
case 5:
|
|
Button5Color = Brushes.Yellow;
|
|
break;
|
|
case 6:
|
|
Button6Color = Brushes.Yellow;
|
|
break;
|
|
case 7:
|
|
Button7Color = Brushes.Yellow;
|
|
break;
|
|
case 8:
|
|
Button8Color = Brushes.Yellow;
|
|
break;
|
|
case 9:
|
|
Button9Color = Brushes.Yellow;
|
|
break;
|
|
case 10:
|
|
Button10Color = Brushes.Yellow;
|
|
break;
|
|
case 11:
|
|
Button11Color = Brushes.Yellow;
|
|
break;
|
|
case 12:
|
|
Button12Color = Brushes.Yellow;
|
|
break;
|
|
case 13:
|
|
Button13Color = Brushes.Yellow;
|
|
break;
|
|
case 14:
|
|
Button14Color = Brushes.Yellow;
|
|
break;
|
|
case 15:
|
|
Button15Color = Brushes.Yellow;
|
|
break;
|
|
case 16:
|
|
Button16Color = Brushes.Yellow;
|
|
break;
|
|
case 17:
|
|
Button17Color = Brushes.Yellow;
|
|
break;
|
|
case 18:
|
|
Button18Color = Brushes.Yellow;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public DelegateCommand RowSelected
|
|
{
|
|
get => new DelegateCommand(() =>
|
|
{
|
|
if (selectOrderInfo != null)
|
|
{
|
|
OrderInfoList = OrderInfoList.Select(x =>
|
|
{
|
|
if (x.OrderNo == selectOrderInfo.OrderNo)
|
|
{
|
|
x.ItemIsChecked = !x.ItemIsChecked;
|
|
}
|
|
return x;
|
|
}).ToList();
|
|
if (OrderInfoList != null && OrderInfoList.Count() > 0)
|
|
{
|
|
//TotalDrugList = OrderInfoList.Where(oi => oi.ItemIsChecked).GroupBy(oi => oi._OrderDetail.DrugInfo.DrugName).Select(oi => new TotalDrug { DrugName = oi.Key, TotalCount = oi.Sum(item => item._OrderDetail.Quantity) }).ToList();
|
|
|
|
TotalDrugList = OrderInfoList.Where(oi => oi.ItemIsChecked).SelectMany(OrderDetailList => OrderDetailList.OrderDetailList).GroupBy(item => item.DrugInfo.DrugName).Select(group => new TotalDrug { DrugName = group.Key, TotalCount = group.Sum(item => item.Quantity) }).ToList();
|
|
|
|
}
|
|
}
|
|
});
|
|
}
|
|
public DelegateCommand Query
|
|
{
|
|
get => new DelegateCommand(() =>
|
|
{
|
|
RequestData();
|
|
});
|
|
}
|
|
|
|
//确认
|
|
public DelegateCommand CheckOrder
|
|
{
|
|
get => new DelegateCommand(() =>
|
|
{
|
|
CheckOrderAction();
|
|
});
|
|
}
|
|
|
|
|
|
void CheckOrderAction()
|
|
{
|
|
var confirmData = OrderInfoList.Where(oi => oi.ItemIsChecked == true).ToList();
|
|
if (confirmData.Count > 0)
|
|
{
|
|
|
|
var f = SqlSugarHelper.Db.UseTran(() =>
|
|
{
|
|
string empChannelStock = string.Empty;
|
|
|
|
for (int i = 0; i < confirmData.Count; i++)
|
|
{
|
|
OrderInfo oi = confirmData[i];
|
|
|
|
//更新处方状态
|
|
if (oi.DmStatus == 0)
|
|
{
|
|
SqlSugarHelper.Db.Updateable(new OrderInfo()
|
|
{
|
|
DmStatus = 1,
|
|
OrderNo = oi.OrderNo
|
|
}).UpdateColumns(it => new { it.DmStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand();
|
|
|
|
SqlSugarHelper.Db.Insertable(new OrderFinish()
|
|
{
|
|
OrderNo = oi.OrderNo,
|
|
PatientId = oi.PatientId,
|
|
Pharmacy = oi.Pharmacy,
|
|
State = 1,
|
|
Operator = HomeWindowViewModel.Operator?.Nickname,
|
|
});
|
|
}
|
|
|
|
//Expression<Func<ChannelStock, bool>> updateExp = it => it.ManuNo == oi._OrderDetail.SetManuNo && it.EffDate == oi._OrderDetail.SetEffDate;
|
|
|
|
for (int j = 0; j < oi.OrderDetailList.Count; j++)
|
|
{
|
|
oi._OrderDetail = oi.OrderDetailList[j];
|
|
int drawerNo = DrawerNo + 1;
|
|
ChannelStock cs = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
|
.Where(cs => cs.DrugId == oi._OrderDetail.DrugId
|
|
&& cs.ManuNo == oi._OrderDetail.SetManuNo
|
|
&& cs.EffDate == oi._OrderDetail.SetEffDate
|
|
&& cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5")
|
|
&& cs.DrawerNo == drawerNo).First();
|
|
if (cs == null)
|
|
{
|
|
empChannelStock += $"{oi.OrderNo},{oi._OrderDetail.DrugId},{oi._OrderDetail.SetManuNo},{oi._OrderDetail.SetEffDate};";
|
|
continue;
|
|
}
|
|
cs.Quantity = cs.Quantity - oi._OrderDetail.Quantity;
|
|
// 更新数据 库存信息
|
|
SqlSugarHelper.Db.Updateable(cs).UpdateColumns(it => new { it.Quantity }).ExecuteCommand();
|
|
|
|
if (cs != null)
|
|
{
|
|
|
|
SqlSugarHelper.Db.Insertable(new MachineRecord()
|
|
{
|
|
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
|
DrawerNo = cs.DrawerNo,
|
|
ColNo = cs.ColNo,
|
|
DrugId = cs.DrugId,
|
|
ManuNo = cs.ManuNo,
|
|
EffDate = !String.IsNullOrEmpty(cs.EffDate) ? DateTime.ParseExact(cs.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
|
|
Operator = HomeWindowViewModel.Operator?.Id,
|
|
Reviewer = HomeWindowViewModel.Reviewer?.Id,
|
|
OperationTime = DateTime.Now,
|
|
Quantity = oi._OrderDetail.Quantity,
|
|
Type = 2,
|
|
InvoiceId = oi.OrderNo
|
|
//, StockQuantity = nowChannels.Sum(it => it.Quantity)
|
|
}).ExecuteCommand();
|
|
|
|
#region 记录 注射剂使用与交接记录报表
|
|
//查询发药时间
|
|
//MachineRecord SendMachineRecord = SqlSugarHelper.Db.Queryable<MachineRecord>().Where(mr => mr.DrawerNo == cs.DrawerNo && mr.Type == 2)
|
|
//.OrderByDescending(mr => mr.OperationTime)
|
|
//.First();
|
|
//string retUser = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cl.DrawerNo == cs.DrawerNo)
|
|
//.Select(cl => cl.BelongUser).First();
|
|
|
|
RejectionReport rejectionReport = SqlSugarHelper.Db.Queryable<RejectionReport>().Where(rp => rp.DrugId == cs.DrugId && rp.DrawerNo == cs.DrawerNo).OrderByDescending(rp => rp.SendDate).First();
|
|
|
|
//发药信息
|
|
//RejectionReport rejectionReport = new RejectionReport();
|
|
//rejectionReport.SendDate = SendMachineRecord.OperationTime;
|
|
//rejectionReport.SendUser = SendMachineRecord.Operator.ToString();
|
|
//rejectionReport.ReceiveUser = retUser;
|
|
rejectionReport.RealNum = cs.BaseQuantity;
|
|
|
|
//还药信息
|
|
rejectionReport.InfactNum = cs.BaseQuantity - oi._OrderDetail.Quantity;
|
|
rejectionReport.EmptyNum = oi._OrderDetail.Quantity;
|
|
rejectionReport.ReturnTime = DateTime.Now.ToString();
|
|
rejectionReport.ReturnUser = rejectionReport.SendUser;
|
|
rejectionReport.ReturnReceiveUser = rejectionReport.ReceiveUser;// SendMachineRecord.Operator.ToString();
|
|
rejectionReport.DrugId = oi._OrderDetail.DrugId;
|
|
rejectionReport.DrugName = oi._OrderDetail.DrugInfo.DrugName;
|
|
rejectionReport.DrugSpec = oi._OrderDetail.DrugInfo.DrugSpec;
|
|
|
|
rejectionReport.OperationTime = DateTime.Now;
|
|
|
|
int iRejectionReport = SqlSugarHelper.Db.Updateable(rejectionReport).ExecuteCommand();
|
|
|
|
#endregion
|
|
|
|
}
|
|
//保存账册
|
|
int iInsertResult = SqlSugarHelper.Db.Insertable(new AccountBookG2()
|
|
{
|
|
DrugId = oi._OrderDetail.DrugId,
|
|
Type = 2,
|
|
Department = oi.DeptName,
|
|
OrderNo = oi.OrderNo,
|
|
ManuNo = cs.ManuNo,
|
|
EffDate = cs.EffDate,
|
|
OutQuantity = oi._OrderDetail.Quantity,
|
|
UserId1 = HomeWindowViewModel.Operator?.Id,
|
|
UserId2 = HomeWindowViewModel.Reviewer?.Id,
|
|
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
|
CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
CreateTime = DateTime.Now,
|
|
InvoiceNo = oi.OrderNo
|
|
|
|
}).ExecuteCommand();
|
|
//修改凌晨生成的日结存与总结存数据
|
|
AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
|
|
.Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString()))
|
|
.Where(ab => ab.Type == 3)
|
|
.Where(ab => ab.DrugId == oi._OrderDetail.DrugId)
|
|
.Where(ab => ab.ManuNo == cs.ManuNo)
|
|
.Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
|
|
if (accountBookG2Day != null)
|
|
{
|
|
accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - oi._OrderDetail.Quantity;
|
|
SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
//生成日结存时可能没有该库位的绑定信息,需要写入日结存
|
|
int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2()
|
|
{
|
|
DrugId = oi._OrderDetail.DrugId,
|
|
Type = 3,
|
|
ManuNo = cs.ManuNo,
|
|
EffDate = cs.EffDate,
|
|
YQuantity = 0,
|
|
ManuStock = oi._OrderDetail.Quantity,
|
|
TotalStock = oi._OrderDetail.Quantity,
|
|
UserId1 = HomeWindowViewModel.Operator?.Id,
|
|
UserId2 = HomeWindowViewModel.Reviewer?.Id,
|
|
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
|
CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
InvoiceNo = "日结存"
|
|
}).ExecuteCommand();
|
|
if (iDayResult <= 0)
|
|
{
|
|
logger.Info($"未写入日结存数据{oi._OrderDetail.DrugId}-{cs.ManuNo}-{cs.EffDate}-{cs.Quantity}");
|
|
}
|
|
}
|
|
//修改凌晨生成的日结存与总结存数据
|
|
AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
|
|
.Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString()))
|
|
.Where(ab => ab.Type == 4)
|
|
.Where(ab => ab.DrugId == oi._OrderDetail.DrugId)
|
|
.Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
|
|
if (accountBookG2Total != null)
|
|
{
|
|
accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - oi._OrderDetail.Quantity;
|
|
SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
//生成总结存时可能没有该库位的绑定信息,需要写入总结存
|
|
int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2()
|
|
{
|
|
DrugId = oi._OrderDetail.DrugId,
|
|
Type = 4,
|
|
YQuantity = 0,
|
|
ManuStock = oi._OrderDetail.Quantity,
|
|
TotalStock = oi._OrderDetail.Quantity,
|
|
UserId1 = HomeWindowViewModel.Operator?.Id,
|
|
UserId2 = HomeWindowViewModel.Reviewer?.Id,
|
|
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
|
CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
InvoiceNo = "总结存"
|
|
}).ExecuteCommand();
|
|
if (iTotalResult <= 0)
|
|
{
|
|
logger.Info($"未写入总结存数据{oi._OrderDetail.DrugId}-{oi._OrderDetail.Quantity}");
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(empChannelStock))
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = $"所选处方对应药品批次效期无库存{empChannelStock}",
|
|
Type = MsgType.ERROR,
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
logger.Info($"所选处方对应药品批次效期无库存{empChannelStock}");
|
|
throw new Exception("事务回滚");
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
if (f.Data)
|
|
{
|
|
RequestData();
|
|
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;
|
|
}
|
|
else
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "请勾选要核对的处方数据",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 选择药箱,打开药箱
|
|
/// </summary>
|
|
public DelegateCommand<string> UpdateDrawerNo
|
|
{
|
|
get => new DelegateCommand<string>(OpenBoxAction);
|
|
}
|
|
|
|
public bool KeepAlive => false;
|
|
|
|
public async void OpenBoxAction(string strDrawerNo)
|
|
{
|
|
DrawerNo = Convert.ToInt32(strDrawerNo);
|
|
MachineRecord machineRecord = new MachineRecord();
|
|
machineRecord.MachineId = "DM5";
|
|
machineRecord.DrawerNo = DrawerNo;
|
|
machineRecord.Operator = HomeWindowViewModel.Operator?.Id;
|
|
machineRecord.OperationTime = DateTime.Now;
|
|
machineRecord.Type = 55;
|
|
machineRecord.InvoiceId = $"打开{DrawerNo + 1}号药箱";
|
|
|
|
|
|
if (DrawerNo > 0)
|
|
{
|
|
DrawerNo -= 1;
|
|
RequestData();
|
|
Status = 1;
|
|
_portUtil.SpeakAsync($"正在打开{DrawerNo + 1}号药箱");
|
|
logger.Info($"正在打开{DrawerNo + 1}号药箱");
|
|
//记录开药箱日志
|
|
SqlSugarHelper.Db.Insertable(machineRecord).ExecuteCommand();
|
|
ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo);
|
|
}
|
|
}
|
|
|
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|
{
|
|
RequestData();
|
|
//_eventAggregator.GetEvent<PortUtilEvent>().Subscribe(DoMyPrismEvent);
|
|
}
|
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
|
{
|
|
// 取消消息订阅
|
|
//_eventAggregator.GetEvent<PortUtilEvent>().Unsubscribe(DoMyPrismEvent);
|
|
}
|
|
//void DoMyPrismEvent(DeviceMsg msg)
|
|
//{
|
|
// switch (msg.EventType)
|
|
// {
|
|
// // 药箱打开
|
|
// case EventType.DRAWEROPEN:
|
|
// if (Status == 1)
|
|
// {
|
|
// Status = 2;
|
|
// }
|
|
// //记录开药箱日志
|
|
// SqlSugarHelper.Db.Insertable(new MachineRecord()
|
|
// {
|
|
// MachineId = "DM5",
|
|
// DrawerNo = _portUtil.DrawerNo,
|
|
// Operator = HomeWindowViewModel.Operator?.Id,
|
|
// OperationTime = DateTime.Now,
|
|
// Type = 55,
|
|
// InvoiceId = $"打开{DrawerNo}号药箱",
|
|
// }).ExecuteCommand();
|
|
// _portUtil.GetBoxStatus();
|
|
// break;
|
|
// // 药箱关闭
|
|
// case EventType.DRAWERCLOSE:
|
|
// //记录药箱操作日志
|
|
// SqlSugarHelper.Db.Insertable(new MachineRecord()
|
|
// {
|
|
// MachineId = "DM5",
|
|
// DrawerNo = _portUtil.DrawerNo,
|
|
// Operator = HomeWindowViewModel.Operator?.Id,
|
|
// OperationTime = DateTime.Now,
|
|
// Type = 55,
|
|
// InvoiceId = "药箱关闭",
|
|
// }).ExecuteCommand();
|
|
|
|
// if (Status == 2)
|
|
// {
|
|
// Status = 3;
|
|
// }
|
|
// _portUtil.Operate = false;
|
|
// break;
|
|
// // 打开失败
|
|
// case EventType.OPENERROR:
|
|
// AlertMsg alertMsg = new AlertMsg
|
|
// {
|
|
// Message = msg.Message,
|
|
// Type = MsgType.ERROR
|
|
// };
|
|
// _eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
|
|
// Status = 0;
|
|
|
|
// //记录药箱操作日志
|
|
// SqlSugarHelper.Db.Insertable(new MachineRecord()
|
|
// {
|
|
// MachineId = "DM5",
|
|
// DrawerNo = _portUtil.DrawerNo,
|
|
// Operator = HomeWindowViewModel.Operator?.Id,
|
|
// OperationTime = DateTime.Now,
|
|
// Type = 55,
|
|
// InvoiceId = "药箱打开失败",
|
|
// }).ExecuteCommand();
|
|
// _portUtil.Operate = false;
|
|
// break;
|
|
// }
|
|
//}
|
|
}
|
|
public class TotalDrug
|
|
{
|
|
public string DrugName { get; set; }
|
|
public int TotalCount { get; set; }
|
|
}
|
|
}
|