diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index 3606165..7bfc8a8 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -173,6 +173,8 @@ namespace DM_Weight containerRegistry.RegisterForNavigation(); //管理员根据药箱进行核对处方 containerRegistry.RegisterForNavigation(); + //麻醉师核对其名下单子 + containerRegistry.RegisterForNavigation(); diff --git a/DM_Weight/Converter/StockStatusConverter.cs b/DM_Weight/Converter/StockStatusConverter.cs new file mode 100644 index 0000000..2d64cf7 --- /dev/null +++ b/DM_Weight/Converter/StockStatusConverter.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace DM_Weight.Converter +{ + internal class StockStatusConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + int status = int.Parse(value.ToString()); + if (parameter.ToString() == "EnableState") + { + if (status == 0) + { + return true; + } + else + { + return false; + } + } + if (parameter.ToString() == "TextState") + { + if (status == 0) + { + return "未取药"; + } + else + { + return "已取药待入库"; + } + } + return ""; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/DM_Weight/ViewModels/AdditionWindowViewModel.cs b/DM_Weight/ViewModels/AdditionWindowViewModel.cs index d3ce0fa..cabcd9f 100644 --- a/DM_Weight/ViewModels/AdditionWindowViewModel.cs +++ b/DM_Weight/ViewModels/AdditionWindowViewModel.cs @@ -122,6 +122,21 @@ namespace DM_Weight.ViewModels Id = jiaojie_it.Id, }).UpdateColumns(jiaojie_it => new { jiaojie_it.Quantity }).ExecuteCommand(); } + + List jiaojie = selectedStock.GroupBy(cs => cs.DrawerNo).Select(cs => cs.FirstOrDefault()).ToList(); + if (jiaojie != null && jiaojie.Count > 0) + { + for (int j = 0; j < jiaojie.Count; j++) + { + ChannelStock jiaojie_it = jiaojie[j]; + //更新交接柜状态为 已取药未入库 + SqlSugarHelper.Db.Updateable(new ChannelList() + { + State = 0, + Id = jiaojie_it.ChannelLst.Id + }).UpdateColumns(it => it.State).ExecuteCommand(); + } + } } }); } @@ -136,7 +151,14 @@ namespace DM_Weight.ViewModels { if (channelStock != null) { - channelStock.ChannelLst.IsSelected = !channelStock.ChannelLst.IsSelected; + if (channelStock.ChannelLst.State == 0) + { + channelStock.ChannelLst.IsSelected = !channelStock.ChannelLst.IsSelected; + } + else + { + return; + } if (channelStock != null && ChannelStocks != null) { ChannelStocks = ChannelStocks.Select(x => diff --git a/DM_Weight/ViewModels/CheckSelfOrderWindowViewModel.cs b/DM_Weight/ViewModels/CheckSelfOrderWindowViewModel.cs new file mode 100644 index 0000000..4f23f9e --- /dev/null +++ b/DM_Weight/ViewModels/CheckSelfOrderWindowViewModel.cs @@ -0,0 +1,1005 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.util; +using log4net; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace DM_Weight.ViewModels +{ + internal class CheckSelfOrderWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime + { + private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel)); + + 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 = 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 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"); + + /// + /// 查询条件 处方日期 + /// + 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 _ordersList = new List(); + public List OrderInfoList + { + get => _ordersList; + set => SetProperty(ref _ordersList, value); + } + + private List? _totalDrugList = new List(); + public List? 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); + } + 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); + } + + //设置按钮颜色 + 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) + { + switch (drawerNo) + { + case 1: + Button1Enable = true; + break; + case 2: + Button2Enable = true; + break; + case 3: + Button3Enable = true; + break; + case 4: + Button4Enable = true; + break; + case 5: + Button5Enable = true; + break; + case 6: + Button6Enable = true; + break; + case 7: + Button7Enable = true; + break; + case 8: + Button8Enable = true; + break; + case 9: + Button9Enable = true; + break; + case 10: + Button10Enable = true; + break; + case 11: + Button11Enable = true; + break; + case 12: + Button12Enable = true; + break; + case 13: + Button13Enable = true; + break; + case 14: + Button14Enable = true; + break; + case 15: + Button15Enable = true; + break; + case 16: + Button16Enable = true; + break; + case 17: + Button17Enable = true; + break; + case 18: + Button18Enable = true; + break; + default: + break; + } + } + IEventAggregator _eventAggregator; + private PortUtil _portUtil; + + public CheckSelfOrderWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator) + { + _portUtil = portUtil; + _eventAggregator = eventAggregator; + } + private string? _searchValue; + + /// + /// 查询条件 查询字段值 + /// + 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().Where(cl => cl.DrawerNo == DrawerNo + 1 && cl.MachineId == "DM5").First();//.Select(cl => cl.BelongUser).First(); + string currentDrawerUser = currentList.BelongUser; + OrderInfoList = SqlSugarHelper.Db.Queryable() + .Includes(oi => oi.OrderDetailList, od => od.DrugInfo) + //.Includes(cl => cl.channelStocks, cs => cs.DrugInfo,di=>di.drugBase) + //.InnerJoin((oi, od) => oi.OrderNo == od.OrderNo) + //.InnerJoin((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; + } + } + } + else + { + + List chlList = SqlSugarHelper.Db.Queryable().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; + } + } + } + } + //查询当前药师下所有的待确认的单子 + string currentDrawerUser = HomeWindowViewModel.Operator.UserBarcode; + OrderInfoList = SqlSugarHelper.Db.Queryable() + .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); + //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); + + } + } + 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> 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() + .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().Where(mr => mr.DrawerNo == cs.DrawerNo && mr.Type == 2) + //.OrderByDescending(mr => mr.OperationTime) + //.First(); + //string retUser = SqlSugarHelper.Db.Queryable().Where(cl => cl.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cl.DrawerNo == cs.DrawerNo) + //.Select(cl => cl.BelongUser).First(); + + RejectionReport rejectionReport = SqlSugarHelper.Db.Queryable().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() + .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() + .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().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().Publish(alertMsg); + } + if (!f.IsSuccess) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "处方核对失败!", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + Status = 0; + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "请勾选要核对的处方数据", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + + } + public void OnNavigatedTo(NavigationContext navigationContext) + { + RequestData(); + //_eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + } + + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + public void OnNavigatedFrom(NavigationContext navigationContext) + { + // 取消消息订阅 + //_eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + } +} diff --git a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs index 2afd8c2..49f6013 100644 --- a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs +++ b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs @@ -195,6 +195,13 @@ namespace DM_Weight.ViewModels PremissionName = "开药箱", PremissionPath = "OpenBoxNewWindow", }; + //开药箱核对名下单子 + PremissionDm openBoxWithOrder = new PremissionDm + { + Id = 14, + PremissionName = "开药箱", + PremissionPath = "CheckSelfOrderWindow", + }; //核对处方 PremissionDm checkOrder = new PremissionDm { @@ -206,7 +213,7 @@ namespace DM_Weight.ViewModels //核对处方 PremissionDm addition = new PremissionDm { - Id = 12, + Id = 13, PremissionName = "药箱补药", //PremissionPath = "CheckOrderWindow", PremissionPath = "AdditionWindow", @@ -262,6 +269,7 @@ namespace DM_Weight.ViewModels quyaoChild.Add(openBox); quyaoChild.Add(checkOrder); quyaoChild.Add(addition); + quyaoChild.Add(openBoxWithOrder); quyao.Children = quyaoChild; defaultAll.Add(quyao); #endregion diff --git a/DM_Weight/Views/AdditionWindow.xaml b/DM_Weight/Views/AdditionWindow.xaml index 8ebe5cf..954fcaa 100644 --- a/DM_Weight/Views/AdditionWindow.xaml +++ b/DM_Weight/Views/AdditionWindow.xaml @@ -20,6 +20,7 @@ + @@ -139,7 +140,7 @@ materialDesign:ExpanderAssist.HeaderBackground="PaleTurquoise" Collapsed="Expander_Collapsed"> - + @@ -161,6 +162,7 @@ + diff --git a/DM_Weight/Views/CheckSelfOrderWindow.xaml b/DM_Weight/Views/CheckSelfOrderWindow.xaml new file mode 100644 index 0000000..87e28d8 --- /dev/null +++ b/DM_Weight/Views/CheckSelfOrderWindow.xaml @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/CheckSelfOrderWindow.xaml.cs b/DM_Weight/Views/CheckSelfOrderWindow.xaml.cs new file mode 100644 index 0000000..d28ae69 --- /dev/null +++ b/DM_Weight/Views/CheckSelfOrderWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views +{ + /// + /// CheckSelfOrderWindow.xaml 的交互逻辑 + /// + public partial class CheckSelfOrderWindow : UserControl + { + public CheckSelfOrderWindow() + { + InitializeComponent(); + } + } +}