1415 lines
60 KiB
C#
1415 lines
60 KiB
C#
using DM_Weight.Models;
|
||
using DM_Weight.msg;
|
||
using DM_Weight.Port;
|
||
using DM_Weight.util;
|
||
using DM_Weight.Views;
|
||
using log4net;
|
||
using Prism.Commands;
|
||
using Prism.Events;
|
||
using Prism.Mvvm;
|
||
using Prism.Regions;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Timers;
|
||
using System.Windows.Media;
|
||
|
||
namespace DM_Weight.ViewModels
|
||
{
|
||
internal class CheckSelfOrderWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime
|
||
{
|
||
private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
|
||
//System.Timers.Timer CheckBoxStatusTimer;
|
||
private int _drawerType = -1;
|
||
|
||
public int DrawerType
|
||
{
|
||
get => _drawerType;
|
||
set => SetProperty(ref _drawerType, value);
|
||
}
|
||
public bool KeepAlive => false;
|
||
|
||
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 = 8;
|
||
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 bool _selfEnable = false;
|
||
//public bool SelfEnable { get => _selfEnable; set => SetProperty(ref _selfEnable, value); }
|
||
|
||
////名下药箱按钮显示内容
|
||
//private string _selfContent = "打开药箱";
|
||
//public string SelfContent { get => _selfContent; set => SetProperty(ref _selfContent, value); }
|
||
|
||
|
||
//开公共药箱按钮的显示状态
|
||
private bool _publicEnable = true;
|
||
public bool PublicEnable { get => _publicEnable; set => SetProperty(ref _publicEnable, value); }
|
||
|
||
//公共药箱按钮显示内容
|
||
private string _publicContent;
|
||
public string PublicContent { get => _publicContent; set => SetProperty(ref _publicContent, value); }
|
||
private string _orderDate = DateTime.Now.ToString("yyyy-MM-dd");
|
||
//名下药箱状态
|
||
private int _selfStatus = 0;
|
||
public int SelfStatus { get => _selfStatus; set => SetProperty(ref _selfStatus, value); }
|
||
//抽屉号列表
|
||
public static List<ChannelList> iList = new List<ChannelList>();
|
||
/// <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); }
|
||
|
||
#region 按钮颜色
|
||
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);
|
||
}
|
||
private bool _button1Enable = false;
|
||
public bool Button1Enable
|
||
{
|
||
get => _button1Enable;
|
||
set => SetProperty(ref _button1Enable, value);
|
||
}
|
||
private bool _button2Enable = false;
|
||
public bool Button2Enable
|
||
{
|
||
get => _button2Enable;
|
||
set => SetProperty(ref _button2Enable, value);
|
||
}
|
||
private bool _button3Enable = false;
|
||
public bool Button3Enable
|
||
{
|
||
get => _button3Enable;
|
||
set => SetProperty(ref _button3Enable, value);
|
||
}
|
||
private bool _button4Enable = false;
|
||
public bool Button4Enable
|
||
{
|
||
get => _button4Enable;
|
||
set => SetProperty(ref _button4Enable, value);
|
||
}
|
||
private bool _button5Enable = false;
|
||
public bool Button5Enable
|
||
{
|
||
get => _button5Enable;
|
||
set => SetProperty(ref _button5Enable, value);
|
||
}
|
||
private bool _button6Enable = false;
|
||
public bool Button6Enable
|
||
{
|
||
get => _button6Enable;
|
||
set => SetProperty(ref _button6Enable, value);
|
||
}
|
||
private bool _button7Enable = false;
|
||
public bool Button7Enable
|
||
{
|
||
get => _button7Enable;
|
||
set => SetProperty(ref _button7Enable, value);
|
||
}
|
||
private bool _button8Enable = false;
|
||
public bool Button8Enable
|
||
{
|
||
get => _button8Enable;
|
||
set => SetProperty(ref _button8Enable, value);
|
||
}
|
||
private bool _button9Enable = false;
|
||
public bool Button9Enable
|
||
{
|
||
get => _button9Enable;
|
||
set => SetProperty(ref _button9Enable, value);
|
||
}
|
||
private bool _button10Enable = false;
|
||
public bool Button10Enable
|
||
{
|
||
get => _button10Enable;
|
||
set => SetProperty(ref _button10Enable, value);
|
||
}
|
||
private bool _button11Enable = false;
|
||
public bool Button11Enable
|
||
{
|
||
get => _button11Enable;
|
||
set => SetProperty(ref _button11Enable, value);
|
||
}
|
||
private bool _button12Enable = false;
|
||
public bool Button12Enable
|
||
{
|
||
get => _button12Enable;
|
||
set => SetProperty(ref _button12Enable, value);
|
||
}
|
||
private bool _button13Enable = false;
|
||
public bool Button13Enable
|
||
{
|
||
get => _button13Enable;
|
||
set => SetProperty(ref _button13Enable, value);
|
||
}
|
||
private bool _button14Enable = false;
|
||
public bool Button14Enable
|
||
{
|
||
get => _button14Enable;
|
||
set => SetProperty(ref _button14Enable, value);
|
||
}
|
||
private bool _button15Enable = false;
|
||
public bool Button15Enable
|
||
{
|
||
get => _button15Enable;
|
||
set => SetProperty(ref _button15Enable, value);
|
||
}
|
||
private bool _button16Enable = false;
|
||
public bool Button16Enable
|
||
{
|
||
get => _button16Enable;
|
||
set => SetProperty(ref _button16Enable, value);
|
||
}
|
||
private bool _button17Enable = false;
|
||
public bool Button17Enable
|
||
{
|
||
get => _button17Enable;
|
||
set => SetProperty(ref _button17Enable, value);
|
||
}
|
||
private bool _button18Enable = false;
|
||
public bool Button18Enable
|
||
{
|
||
get => _button18Enable;
|
||
set => SetProperty(ref _button18Enable, value);
|
||
}
|
||
#endregion
|
||
//设置按钮颜色
|
||
private void SetBtnColor(int drawerNo)
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
//设置按钮可用状态
|
||
private void SetBtnEnable(int drawerNo, bool status)
|
||
{
|
||
switch (drawerNo)
|
||
{
|
||
case 1:
|
||
Button1Enable = status;
|
||
//SelfEnable=status;
|
||
break;
|
||
case 2:
|
||
Button2Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 3:
|
||
Button3Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 4:
|
||
Button4Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 5:
|
||
Button5Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 6:
|
||
Button6Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 7:
|
||
Button7Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 8:
|
||
Button8Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 9:
|
||
Button9Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 10:
|
||
Button10Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 11:
|
||
Button11Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 12:
|
||
Button12Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 13:
|
||
Button13Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 14:
|
||
Button14Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 15:
|
||
Button15Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 16:
|
||
Button16Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 17:
|
||
Button17Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
case 18:
|
||
Button18Enable = status;
|
||
//SelfEnable = status;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
////打开某个药箱时不可点击其他药箱按钮避免保存数据时减错药箱库存(确认或取消后按钮即可用)
|
||
//private void SetAllBtnEnableFalse()
|
||
//{
|
||
// Button1Enable = false;
|
||
// Button2Enable = false;
|
||
// Button3Enable = false;
|
||
// Button4Enable = false;
|
||
// Button5Enable = false;
|
||
// Button6Enable = false;
|
||
// Button7Enable = false;
|
||
// Button8Enable = false;
|
||
// Button9Enable = false;
|
||
// Button10Enable = false;
|
||
// Button11Enable = false;
|
||
// Button12Enable = false;
|
||
// Button13Enable = false;
|
||
// Button14Enable = false;
|
||
// Button15Enable = false;
|
||
// Button16Enable = false;
|
||
// Button17Enable = false;
|
||
// Button18Enable = false;
|
||
//}
|
||
IEventAggregator _eventAggregator;
|
||
//private PortUtil _portUtil;
|
||
|
||
SocketHelper _socketHelper;
|
||
public CheckSelfOrderWindowViewModel(IEventAggregator eventAggregator, SocketHelper socketHelper)
|
||
{
|
||
//_portUtil = portUtil;
|
||
_eventAggregator = eventAggregator;
|
||
_socketHelper = socketHelper;
|
||
}
|
||
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 && cl.MachineId == "DM5").First();//.Select(cl => cl.BelongUser).First();
|
||
DrawerType = currentList.DrawerType;
|
||
//string currentDrawerUser = currentList.BelongUser;
|
||
string currentDrawerUser = HomeWindowViewModel.Operator.UserBarcode;
|
||
OrderInfoList = SqlSugarHelper.Db.Queryable<OrderInfo>()
|
||
.Includes(oi => oi.OrderDetailList, od => od.DrugInfo)
|
||
.Includes(oi => oi.OrderDetailList, od => od.surgicalResidual)
|
||
//.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);
|
||
|
||
//OrderInfoList = SqlSugarHelper.Db.Queryable<OrderInfo>()
|
||
// .Includes(oi => oi.OrderDetailList, od => od.DrugInfo)
|
||
// .Includes(oi => oi.OrderDetailList, od => od.surgicalResidual)
|
||
// //.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 == 1)
|
||
// .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);
|
||
OrderInfoList.ForEach(oi => oi.OrderDetailList.ForEach(od => od.DrugInfo = od.DrugInfo ?? new DrugInfo()));
|
||
|
||
//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;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
GetUseBox();
|
||
//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"))
|
||
// {
|
||
// SetBtnColor(chl.DrawerNo);
|
||
// }
|
||
|
||
// //DrawerType== 1为公共药箱
|
||
// if (chl.DrawerType == 1)
|
||
// {
|
||
// SetBtnEnable(chl.DrawerNo);
|
||
// }
|
||
// if (!string.IsNullOrEmpty(chl.BelongUser) && chl.BelongUser == HomeWindowViewModel.Operator.UserBarcode)
|
||
// {
|
||
// if (DrawerType == -1)
|
||
// {
|
||
// DrawerType = chl.DrawerType;
|
||
// }
|
||
// SetBtnEnable(chl.DrawerNo);
|
||
// }
|
||
// }
|
||
//}
|
||
//查询当前药师下所有的待确认的单子
|
||
string currentDrawerUser = HomeWindowViewModel.Operator.UserBarcode;
|
||
OrderInfoList = SqlSugarHelper.Db.Queryable<OrderInfo>()
|
||
.Includes(oi => oi.OrderDetailList, od => od.DrugInfo)
|
||
.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);
|
||
OrderInfoList.ForEach(oi => oi.OrderDetailList.ForEach(od => od.DrugInfo = od.DrugInfo ?? new DrugInfo()));
|
||
//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);
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 选择药箱,打开药箱
|
||
/// </summary>
|
||
public DelegateCommand<string> UpdateDrawerNo
|
||
{
|
||
get => new DelegateCommand<string>(OpenBoxAction);
|
||
}
|
||
public void OpenBoxAction(string strDrawerNo)
|
||
{
|
||
//if (ModbusHelper.BoxOperate)
|
||
//{
|
||
// Task.Factory.StartNew(() => { ModbusHelper.SpeakAsync("请关闭药箱后再打开"); });
|
||
// return;
|
||
//}
|
||
if (_socketHelper.OpenStatus)
|
||
{
|
||
_socketHelper.speechSynthesizer.SpeakAsyncCancelAll();
|
||
_socketHelper.speechSynthesizer.Resume();
|
||
_socketHelper.SpeakAsync("请关闭手术间后再打开");
|
||
return;
|
||
}
|
||
//SetAllBtnEnableFalse();
|
||
DrawerNo = Convert.ToInt32(strDrawerNo);
|
||
//DrawerType = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerNo == Convert.ToInt32(strDrawerNo)).Select(cl => cl.DrawerType).First();
|
||
//SelfEnable = true;
|
||
//int listSelfState = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5")
|
||
// .WhereIf(cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).Select(cl => cl.DrawerState).First();
|
||
|
||
//int listDrawerState = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerType == this.DrawerType)
|
||
// .WhereIF(this.DrawerType == 0, cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).Select(cl => cl.DrawerState).First();
|
||
|
||
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}号手术间";
|
||
|
||
|
||
if (DrawerNo > 0)
|
||
{
|
||
RequestData();
|
||
Status = 1;
|
||
_socketHelper.speechSynthesizer.SpeakAsyncCancelAll();
|
||
_socketHelper.speechSynthesizer.Resume();
|
||
_socketHelper.SpeakAsync($"正在打开{DrawerNo}号手术间");
|
||
logger.Info($"正在打开{DrawerNo}号手术间");
|
||
//记录开药箱日志
|
||
SqlSugarHelper.Db.Insertable(machineRecord).ExecuteCommand();
|
||
//ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo-1);
|
||
try
|
||
{
|
||
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(DrawerNo - 1) });
|
||
_socketHelper.dateTime = DateTime.Now;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
AlertMsg alertMsg = new AlertMsg
|
||
{
|
||
Message = $"网口连接异常,正在重试{ex.Message}",
|
||
Type = MsgType.ERROR,
|
||
};
|
||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||
logger.Info($"网口连接异常,正在重试{ex.Message}");
|
||
return;
|
||
}
|
||
_socketHelper.OpenStatus = true;
|
||
//SetBtnEnable(DrawerNo, false);
|
||
//if (CheckBoxStatusTimer is null)
|
||
//{
|
||
// CheckBoxStatusTimer = new System.Timers.Timer();
|
||
//}
|
||
//if (!CheckBoxStatusTimer.Enabled)
|
||
//{
|
||
// CheckBoxStatusTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetAllBoxState);
|
||
// CheckBoxStatusTimer.Interval = 3000;
|
||
// CheckBoxStatusTimer.Start();
|
||
//}
|
||
//记录药箱打开时间
|
||
ChannelList channelList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerNo == DrawerNo).First();
|
||
if (channelList != null && (channelList.EffDate is null || Convert.ToDateTime(channelList.EffDate).ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd")))
|
||
{
|
||
|
||
channelList.EffDate = DateTime.Now.ToString();
|
||
SqlSugarHelper.Db.Updateable(channelList).UpdateColumns(it => new { it.EffDate }).ExecuteCommand();
|
||
}
|
||
//Task.Factory.StartNew(async () =>
|
||
//{
|
||
// bool loop = true;
|
||
// while (loop)
|
||
// {
|
||
// await Task.Delay(1000);
|
||
// bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
|
||
// bool state = Array.TrueForAll(boolsl, b => b == false);
|
||
// if (state)
|
||
// {
|
||
// loop = false;
|
||
// ModbusHelper.BoxOperate = false;
|
||
// }
|
||
// else
|
||
// {
|
||
// ModbusHelper.BoxOperate = true;
|
||
// //ModbusHelper.SpeakAsync("药箱已打开,请及时关闭");
|
||
// }
|
||
// }
|
||
//});
|
||
Thread.Sleep(200);
|
||
int iException = 0;
|
||
new PromiseUtil<int>().taskAsyncLoop(500, 0, async (options, next, stop) =>
|
||
{
|
||
try
|
||
{
|
||
if (_socketHelper.OpenStatus)
|
||
{
|
||
|
||
//bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
|
||
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = 0x33, functionCode = 4, delay = 2 });
|
||
|
||
//ModbusHelper.SpeakAsync($"i为{i};状态为:{_socketHelper.OpenStatus}");
|
||
//bool state = Array.TrueForAll(boolsl, b => b == false);
|
||
if (_socketHelper.OpenStatus)
|
||
{
|
||
//if (i == 0)
|
||
//{
|
||
// ModbusHelper.SpeakAsync("请及时关闭药箱");
|
||
// i = 10;
|
||
//}
|
||
next();
|
||
}
|
||
else
|
||
{
|
||
_socketHelper.IsMultiThread = false;
|
||
_socketHelper.dateTime = DateTime.Now;
|
||
stop();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_socketHelper.IsMultiThread = false;
|
||
_socketHelper.dateTime = DateTime.Now;
|
||
stop();
|
||
}
|
||
iException = 0;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
iException++;
|
||
if (iException >= 3)
|
||
{
|
||
_socketHelper.OpenStatus = false;
|
||
}
|
||
// _socketHelper.OpenStatus = false;
|
||
AlertMsg alertMsg = new AlertMsg
|
||
{
|
||
Message = $"网口连接异常,正在重试{ex.Message}",
|
||
Type = MsgType.ERROR,
|
||
};
|
||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||
logger.Info($"网口连接异常,正在重试{ex.Message}");
|
||
next();
|
||
}
|
||
});
|
||
}
|
||
//if (DrawerType == 1) //公共药箱
|
||
//{
|
||
// if (listDrawerState == 0)
|
||
// {
|
||
// SelfContent = "还公共药箱";
|
||
// }
|
||
// else
|
||
// {
|
||
// SelfContent = "取公共药箱";
|
||
// }
|
||
|
||
//}
|
||
//else
|
||
//{
|
||
// if (listDrawerState == 0)
|
||
// {
|
||
// SelfContent = "还名下药箱";
|
||
// }
|
||
// else
|
||
// {
|
||
// SelfContent = "取名下药箱";
|
||
// }
|
||
|
||
//}
|
||
|
||
}
|
||
//public DelegateCommand<string> OpenBoxDelegate
|
||
//{
|
||
// get => new DelegateCommand<string>((DrawerType) =>
|
||
// {
|
||
// SearchBox();
|
||
// }
|
||
// );
|
||
//}
|
||
//private void SearchBox()
|
||
//{
|
||
|
||
// SetAllBtnEnableFalse();
|
||
// iList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerType == this.DrawerType)
|
||
// .WhereIF(this.DrawerType == 0, cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).ToList();
|
||
// // .Select(cl => cl.DrawerNo).ToList();
|
||
// if (iList.Count > 0)
|
||
// {
|
||
// //_portUtil.SpeakAsync("正在打开药箱");
|
||
// //_portUtil.DrawerNo = iList[iNumber];
|
||
// //iNumber++;
|
||
// //_portUtil.OpenBox();
|
||
|
||
// for (int i = 0; i < iList.Count; i++)
|
||
// {
|
||
// ChannelList channelList = iList[i];
|
||
// //记录开药箱日志
|
||
// SqlSugarHelper.Db.Insertable(new MachineRecord()
|
||
// {
|
||
// MachineId = "DM5",
|
||
// DrawerNo = channelList.DrawerNo,
|
||
// Operator = HomeWindowViewModel.Operator?.Id,
|
||
// OperationTime = DateTime.Now,
|
||
// Type = 55,
|
||
// InvoiceId = $"打开{iList[i].DrawerNo}号药箱",
|
||
// OptionType = SelfContent.Substring(0, 1) == "取" ? 0 : 1
|
||
// }).ExecuteCommand();
|
||
// //记录药箱打开时间
|
||
// channelList.EffDate = DateTime.Now.ToString();
|
||
// channelList.DrawerState = SelfContent.Substring(0, 1) == "取" ? 0 : 1;
|
||
// SqlSugarHelper.Db.Updateable(channelList).UpdateColumns(it => new { it.EffDate, it.DrawerState }).ExecuteCommand();
|
||
|
||
// _portUtil.SpeakAsync($"正在打开{channelList.DrawerNo}号药箱");
|
||
// logger.Info($"正在打开{channelList.DrawerNo}号药箱");
|
||
// ModbusHelper.GetInstance().OpenBoxDoor(channelList.DrawerNo - 1);
|
||
// }
|
||
|
||
// SelfStatus = 0;
|
||
// PublicEnable = true;
|
||
// //SelfEnable = true;
|
||
// DrawerType = -1;
|
||
// }
|
||
//}
|
||
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(() =>
|
||
{
|
||
GetUseBox();
|
||
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,
|
||
DrawerCode = DrawerNo
|
||
}).UpdateColumns(it => new { it.DmStatus, it.DrawerCode }).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,
|
||
}).ExecuteCommand();
|
||
}
|
||
|
||
#region 麻醉师确认只修改单子状态为1,不减库存,等管理员操作时减库存
|
||
|
||
//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}");
|
||
// }
|
||
// }
|
||
|
||
//}
|
||
|
||
#endregion
|
||
|
||
}
|
||
//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);
|
||
RequestData();
|
||
}
|
||
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);
|
||
}
|
||
|
||
}
|
||
|
||
//取消
|
||
public DelegateCommand CancleTake
|
||
{
|
||
get => new DelegateCommand(() =>
|
||
{
|
||
GetUseBox();
|
||
});
|
||
}
|
||
private void GetUseBox()
|
||
{
|
||
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 (chl != null && chl.EffDate != null)
|
||
{
|
||
SetBtnColor(chl.DrawerNo);
|
||
}
|
||
|
||
//DrawerType== 1为公共药箱
|
||
if (chl.DrawerType == 1)
|
||
{
|
||
SetBtnEnable(chl.DrawerNo, true);
|
||
}
|
||
if (!string.IsNullOrEmpty(chl.BelongUser) && chl.BelongUser == HomeWindowViewModel.Operator.UserBarcode)
|
||
{
|
||
if (DrawerType == -1)
|
||
{
|
||
DrawerType = chl.DrawerType;
|
||
}
|
||
SetBtnEnable(chl.DrawerNo, true);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
public void OnNavigatedTo(NavigationContext navigationContext)
|
||
{
|
||
logger.Info("进入OnNavigatedTo");
|
||
RequestData();
|
||
logger.Info("结束RequestData");
|
||
//if(ModbusHelper.BoxOperate)
|
||
//{
|
||
// Task.Factory.StartNew(() => { ModbusHelper.SpeakAsync("请关闭药箱后再打开"); });
|
||
// return;
|
||
//}
|
||
////查询当前药师的第一个药箱号并打开该药箱
|
||
//int drawerNo = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).Select(cl => cl.DrawerNo).First();
|
||
//if (drawerNo > 0)
|
||
//{
|
||
//SetAllBtnEnableFalse();
|
||
//DrawerNo = drawerNo;
|
||
////进入页面打开当前用户的第一个药箱
|
||
////记录开药箱日志
|
||
//SqlSugarHelper.Db.Insertable(new MachineRecord()
|
||
//{
|
||
// MachineId = "DM5",
|
||
// DrawerNo = drawerNo,
|
||
// Operator = HomeWindowViewModel.Operator?.Id,
|
||
// OperationTime = DateTime.Now,
|
||
// Type = 55,
|
||
// InvoiceId = $"打开{drawerNo}号药箱",
|
||
// //OptionType = SelfContent.Substring(0, 1) == "取" ? 0 : 1
|
||
//}).ExecuteCommand();
|
||
|
||
//ModbusHelper.SpeakAsync($"正在打开{drawerNo}号药箱");
|
||
//logger.Info($"正在打开{drawerNo}号药箱");
|
||
//ModbusHelper.GetInstance().OpenBoxDoor(drawerNo - 1);
|
||
//SetBtnEnable(drawerNo, false);
|
||
//if (CheckBoxStatusTimer is null)
|
||
//{
|
||
// CheckBoxStatusTimer = new System.Timers.Timer();
|
||
//}
|
||
//if (!CheckBoxStatusTimer.Enabled)
|
||
//{
|
||
// CheckBoxStatusTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetAllBoxState);
|
||
// CheckBoxStatusTimer.Interval = 3000;
|
||
// CheckBoxStatusTimer.Start();
|
||
//}
|
||
//记录药箱打开时间
|
||
//ChannelList channelList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerNo == drawerNo).First();
|
||
//if (channelList != null && (channelList.EffDate is null || Convert.ToDateTime(channelList.EffDate).ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd")))
|
||
//{
|
||
|
||
// channelList.EffDate = DateTime.Now.ToString();
|
||
// SqlSugarHelper.Db.Updateable(channelList).UpdateColumns(it => new { it.EffDate }).ExecuteCommand();
|
||
//}
|
||
//Task.Factory.StartNew(async () =>
|
||
//{
|
||
// bool loop = true;
|
||
// while (loop)
|
||
// {
|
||
// await Task.Delay(4000);
|
||
// bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
|
||
// bool state = Array.TrueForAll(boolsl, b => b == false);
|
||
// if (state)
|
||
// {
|
||
// loop = false;
|
||
// ModbusHelper.BoxOperate = false;
|
||
// }
|
||
// else
|
||
// {
|
||
// ModbusHelper.BoxOperate = true;
|
||
// //ModbusHelper.SpeakAsync("药箱已打开,请及时关闭");
|
||
// }
|
||
// }
|
||
//});
|
||
//}
|
||
}
|
||
//private void GetAllBoxState(object sender, ElapsedEventArgs e)
|
||
//{
|
||
// //查询药箱是否关闭,如果已经关闭则按钮可用,可继续开该编号的药箱
|
||
// if (DrawerNo >= 0)
|
||
// {
|
||
// bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
||
// bool allFalse = Array.TrueForAll(boolArrs, b => b == false);
|
||
// if (allFalse)
|
||
// {
|
||
// if (CheckBoxStatusTimer.Enabled)
|
||
// {
|
||
// CheckBoxStatusTimer.Stop();
|
||
// }
|
||
// }
|
||
// //设置对应药箱按钮可用状态
|
||
// SetBtnEnable(DrawerNo, !boolArrs[DrawerNo]);
|
||
// }
|
||
//}
|
||
|
||
public bool IsNavigationTarget(NavigationContext navigationContext)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
public void OnNavigatedFrom(NavigationContext navigationContext)
|
||
{
|
||
// 取消消息订阅
|
||
//_eventAggregator.GetEvent<PortUtilEvent>().Unsubscribe(DoMyPrismEvent);
|
||
}
|
||
}
|
||
}
|