From 443bd5841440dcc4d3d14e8d87ca9a6f835b3f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=B7=A7?= <625215135@qq.com> Date: Sun, 28 Sep 2025 09:22:31 +0800 Subject: [PATCH] =?UTF-8?q?user=5Flist=E8=A1=A8=E6=B7=BB=E5=8A=A0Box=5FNum?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E3=80=82ALTER=20TABLE=20channel=5Flist=20MOD?= =?UTF-8?q?IFY=20COLUMN=20drawer=5Fstate=20INT=20DEFAULT=201;update=20chan?= =?UTF-8?q?nel=5Flist=20=20setdrawer=5Fstate=3D1=20where=20machine=5Fid=3D?= =?UTF-8?q?'DM5'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/App.xaml.cs | 6 + DM_Weight/Converter/TakeReturnConverter.cs | 50 + DM_Weight/Models/MachineRecord.cs | 6 +- DM_Weight/Models/UserList.cs | 5 +- DM_Weight/Report/GridReportUtil.cs | 2 +- .../CheckSelfOrderForAdminViewModel.cs | 1043 +++++++++++++++++ .../CheckSelfOrderWindowNewViewModel.cs | 132 +-- .../CheckSelfOrderWindowViewModel.cs | 568 +++------ .../ViewModels/CheckStockWindowViewModel.cs | 155 +++ DM_Weight/ViewModels/HomeWindowViewModel.cs | 2 +- .../ViewModels/RoleManagerWindowViewModel.cs | 21 +- .../SelectOperationTypeDialogViewModel.cs | 51 + DM_Weight/Views/CheckSelfOrderForAdmin.xaml | 232 ++++ .../Views/CheckSelfOrderForAdmin.xaml.cs | 28 + DM_Weight/Views/CheckSelfOrderWindow.xaml | 19 +- .../Dialog/SelectOperationTypeDialog.xaml | 40 + .../Dialog/SelectOperationTypeDialog.xaml.cs | 28 + DM_Weight/Views/MachineRecordWindow.xaml | 2 +- 18 files changed, 1872 insertions(+), 518 deletions(-) create mode 100644 DM_Weight/Converter/TakeReturnConverter.cs create mode 100644 DM_Weight/ViewModels/CheckSelfOrderForAdminViewModel.cs create mode 100644 DM_Weight/ViewModels/SelectOperationTypeDialogViewModel.cs create mode 100644 DM_Weight/Views/CheckSelfOrderForAdmin.xaml create mode 100644 DM_Weight/Views/CheckSelfOrderForAdmin.xaml.cs create mode 100644 DM_Weight/Views/Dialog/SelectOperationTypeDialog.xaml create mode 100644 DM_Weight/Views/Dialog/SelectOperationTypeDialog.xaml.cs diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index e9ffc04..38830e9 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -325,6 +325,12 @@ namespace DM_Weight containerRegistry.RegisterDialog(); containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterDialog(); + containerRegistry.RegisterForNavigation(); + + containerRegistry.RegisterForNavigation(); + + logger.Info("结束APP-RegisterTypes"); } diff --git a/DM_Weight/Converter/TakeReturnConverter.cs b/DM_Weight/Converter/TakeReturnConverter.cs new file mode 100644 index 0000000..915b881 --- /dev/null +++ b/DM_Weight/Converter/TakeReturnConverter.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace DM_Weight.Converter +{ + internal class TakeReturnConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + int status = int.Parse(value.ToString()); + //取药箱 + if (parameter.ToString().Equals("TakeBox")) + { + if (status == 0) + { + return Visibility.Visible; + } + else + { + return Visibility.Collapsed; + } + } + //还药箱 + if (parameter.ToString().Equals("ReturnBox")) + { + if (status == 1) + { + return Visibility.Visible; + } + else + { + return Visibility.Collapsed; + } + } + + return Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/DM_Weight/Models/MachineRecord.cs b/DM_Weight/Models/MachineRecord.cs index 250acde..e50a3a5 100644 --- a/DM_Weight/Models/MachineRecord.cs +++ b/DM_Weight/Models/MachineRecord.cs @@ -73,7 +73,7 @@ namespace DM_Weight.Models [SugarColumn(ColumnName = "eff_date")] public DateTime? EffDate { get; set; } /// - /// 出库入库类型(1入库2出库31还药32还空瓶,21药箱移出移入,69药箱替换,55绑定药品操作(绑定、解绑、修改基数)) + /// 出库入库类型(1入库2出库31还药32还空瓶,21药箱移出移入,69药箱替换,55绑定药品操作(绑定、解绑、修改基数)) 70取出药箱、71还回药箱 /// [SugarColumn(ColumnName = "type")] public int Type { get; set; } @@ -103,10 +103,10 @@ namespace DM_Weight.Models [SugarColumn(ColumnName = "department_id")] public string DepartmentId { get; set; } /// - /// 是否已经退药(0:没有1:还了部分2:完成) + /// 是否已经退药(0:没有1:还了部分2:完成) 取出药箱70还回药箱71 /// 默认值: 0 /// - [SugarColumn(ColumnName = "status", IsOnlyIgnoreInsert = true)] + [SugarColumn(ColumnName = "status")] public int Status { get; set; } /// /// 退药量 diff --git a/DM_Weight/Models/UserList.cs b/DM_Weight/Models/UserList.cs index 3c3d2a0..fd91bb4 100644 --- a/DM_Weight/Models/UserList.cs +++ b/DM_Weight/Models/UserList.cs @@ -73,5 +73,8 @@ namespace DM_Weight.Models { return "userList = [UserName:" + Nickname + ", UserId:" + UserName + "]"; } - } + //保存用户已取药箱的药箱号 + [SugarColumn(ColumnName = "Box_Num")] + public string BoxNumber { get; set; } + } } diff --git a/DM_Weight/Report/GridReportUtil.cs b/DM_Weight/Report/GridReportUtil.cs index dfd2be1..3be9b78 100644 --- a/DM_Weight/Report/GridReportUtil.cs +++ b/DM_Weight/Report/GridReportUtil.cs @@ -397,7 +397,7 @@ namespace DM_Weight.Report { SQL += " AND ab.drug_id='" + drug_id + "' "; } - SQL += " ORDER BY ab.type,ab.drug_id,ab.Manu_No,ab.id "; + SQL += " ORDER BY ab.create_time,ab.drug_id,ab.Manu_No,ab.id "; Report.DetailGrid.Recordset.QuerySQL = SQL; Report.PrintPreview(true); diff --git a/DM_Weight/ViewModels/CheckSelfOrderForAdminViewModel.cs b/DM_Weight/ViewModels/CheckSelfOrderForAdminViewModel.cs new file mode 100644 index 0000000..57c40a1 --- /dev/null +++ b/DM_Weight/ViewModels/CheckSelfOrderForAdminViewModel.cs @@ -0,0 +1,1043 @@ +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; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace DM_Weight.ViewModels +{ + public class CheckSelfOrderForAdminViewModel : 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 int _currentDrawerNo = -1; + + public int CurrentDrawerNo + { + get => _currentDrawerNo; + set => SetProperty(ref _currentDrawerNo, 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 iList = new List(); + /// + /// 查询条件 处方日期 + /// + 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 _surgicalResidualList = new List(); + public List SurgicalResidualList + { + get => _surgicalResidualList; + set => SetProperty(ref _surgicalResidualList, value); + } + + + private List? _totalDrugList = new List(); + public List? TotalDrugList + { + get => _totalDrugList; + set => SetProperty(ref _totalDrugList, value); + } + //选中行数据 + private SurgicalResidual _surgicalResidual; + public SurgicalResidual surgicalResidual + { + get => _surgicalResidual; + set => SetProperty(ref _surgicalResidual, 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; + } + } + IEventAggregator _eventAggregator; + //private PortUtil _portUtil; + + SocketHelper _socketHelper; + public CheckSelfOrderForAdminViewModel(IEventAggregator eventAggregator, SocketHelper socketHelper) + { + //_portUtil = portUtil; + _eventAggregator = eventAggregator; + _socketHelper = socketHelper; + } + 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 && 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() + // .Includes(oi => oi._OrderDetail, od => od.DrugInfo) + // .Includes(oi => oi._OrderDetail, od => od.surgicalResidual) + // .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) + // .Where(oi => oi._OrderDetail.SetManuNo != null&&oi._OrderDetail.SetManuNo!="null") + // .Where(oi=>oi._OrderDetail.Quantity>0) + // .Where(oi=>oi._OrderDetail.surgicalResidual.SendNo== DrawerNo.ToString()) + // .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._OrderDetail.DrugInfo = oi._OrderDetail.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).Select(OrderDetailList => OrderDetailList._OrderDetail).GroupBy(item => item.DrugInfo.DrugName).Select(group => new TotalDrug { DrugName = group.Key, TotalCount = group.Sum(item => item.Quantity) }).ToList(); + //} + //else + //{ + // TotalDrugList = null; + //} + + SurgicalResidualList = SqlSugarHelper.Db.Queryable() + .Includes(sr => sr.DrugInfo) + .WhereIF(OrderDate != null, sr => sr.CreateTime.ToString("yyyy-MM-dd") == OrderDate) + .Where(sr => sr.DmStatus == 0) + .OrderBy(sr => sr.OrderNo) + .ToPageList(PageNum, PageSize, ref totalCount); + if (SurgicalResidualList != null && SurgicalResidualList.Count > 0) + { + SurgicalResidualList.Where(sr=>sr.SendNo==DrawerNo.ToString()).ToList()?.ForEach(sr => sr.ItemIsChecked = true); + TotalDrugList = SurgicalResidualList.Where(sr => sr.ItemIsChecked) + // .Select(OrderDetailList => OrderDetailList._OrderDetail) + .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(); + } + } + /// + /// 选择药箱,打开药箱 + /// + public DelegateCommand UpdateDrawerNo + { + get => new DelegateCommand(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().Where(cl => cl.MachineId == "DM5" && cl.DrawerNo == Convert.ToInt32(strDrawerNo)).Select(cl => cl.DrawerType).First(); + //SelfEnable = true; + //int listSelfState = SqlSugarHelper.Db.Queryable().Where(cl => cl.MachineId == "DM5") + // .WhereIf(cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).Select(cl => cl.DrawerState).First(); + + //int listDrawerState = SqlSugarHelper.Db.Queryable().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); + CurrentDrawerNo += DrawerNo + 1; + 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().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().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(); + } + + Thread.Sleep(200); + int iException = 0; + new PromiseUtil().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().Publish(alertMsg); + logger.Info($"网口连接异常,正在重试{ex.Message}"); + next(); + } + }); + } + } + public DelegateCommand RowSelected + { + get => new DelegateCommand(() => + { + if (surgicalResidual != null) + { + SurgicalResidualList = SurgicalResidualList.Select(x => + { + if (x.OrderNo == surgicalResidual.OrderNo) + { + x.ItemIsChecked = !x.ItemIsChecked; + } + return x; + }).ToList(); + if (SurgicalResidualList != null && SurgicalResidualList.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 = SurgicalResidualList.Where(oi => oi.ItemIsChecked).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(() => + { + if (DrawerNo == -1) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "请先选择手术间", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return; + } + GetUseBox(); + CheckOrderAction(); + }); + } + + + void CheckOrderAction() + { + var confirmData = SurgicalResidualList.Where(oi => oi.ItemIsChecked == true).ToList(); + if (confirmData.Count > 0) + { + + var f = SqlSugarHelper.Db.UseTran(() => + { + for (int i = 0; i < confirmData.Count; i++) + { + //OrderInfo oi = confirmData[i]; + SurgicalResidual surgicalResidual = confirmData[i]; + //查询该药箱是否有该批次的药品,没有则无法确认(避免管理进行确认时确认不过去) + + int drawerNo = DrawerNo; + ChannelStock cs = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.DrugId == surgicalResidual.DrugId + && cs.ManuNo == surgicalResidual.ManuNo + && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5") + && cs.DrawerNo == drawerNo).First(); + if (cs == null) + { + AlertMsg alertMsg = new AlertMsg + { + Message = $"处方{surgicalResidual.OrderNo}因药品批次{surgicalResidual.ManuNo}无库存,无法确认", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return false; + } + + + + SqlSugarHelper.Db.Updateable(new SurgicalResidual() + { + DmStatus = 1, + OrderNo = surgicalResidual.OrderNo + }).UpdateColumns(it => it.DmStatus).WhereColumns(it => new { it.OrderNo }).ExecuteCommand(); + + SqlSugarHelper.Db.Insertable(new OrderFinish() + { + OrderNo = surgicalResidual.OrderNo, + PatientId = surgicalResidual.PatientId, + //Pharmacy = surgicalResidual.Pharmacy, + State = 1, + Operator = HomeWindowViewModel.Operator?.Nickname, + }).ExecuteCommand(); + } + return true; + }); + if (f.Data) + { + RequestData(); + AlertMsg alertMsg = new AlertMsg + { + Message = "所选单子已确认", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + RequestData(); + } + 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 DelegateCommand CancleTake + { + get => new DelegateCommand(() => + { + GetUseBox(); + }); + } + private void GetUseBox() + { + List chlList = SqlSugarHelper.Db.Queryable().Where(cl => cl.MachineId == "DM5").ToList();//.Select(cl => cl.BelongUser).First(); + chlList = chlList.GroupBy(cl => cl.DrawerNo).Select(cl => cl.FirstOrDefault()).ToList(); + 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"); + } + + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + public void OnNavigatedFrom(NavigationContext navigationContext) + { + // 取消消息订阅 + //_eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + + + /// + /// 点击取药箱按钮 + /// + public DelegateCommand TakeBoxCommand + { + get => new DelegateCommand(TakeBoxMethod); + } + public void TakeBoxMethod() + { + + } + /// + /// 点击还药箱按钮 + /// + public DelegateCommand ReturnBoxCommand + { + get => new DelegateCommand(ReturnBoxMethod); + } + public void ReturnBoxMethod() + { + + } + } +} diff --git a/DM_Weight/ViewModels/CheckSelfOrderWindowNewViewModel.cs b/DM_Weight/ViewModels/CheckSelfOrderWindowNewViewModel.cs index a86ce32..ef52eca 100644 --- a/DM_Weight/ViewModels/CheckSelfOrderWindowNewViewModel.cs +++ b/DM_Weight/ViewModels/CheckSelfOrderWindowNewViewModel.cs @@ -9,10 +9,12 @@ using Prism.Events; using Prism.Mvvm; using Prism.Regions; using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Linq; +using System.Reflection.Emit; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -589,12 +591,13 @@ namespace DM_Weight.ViewModels SurgicalResidualList = SqlSugarHelper.Db.Queryable() .Includes(sr => sr.DrugInfo) .WhereIF(OrderDate != null, sr => sr.CreateTime.ToString("yyyy-MM-dd") == OrderDate) - .Where(sr => sr.SendNo == DrawerNo.ToString() && sr.DmStatus == 0 && sr.DoctorCode == currentDrawerUser) + //.Where(sr => sr.SendNo == DrawerNo.ToString() && sr.DmStatus == 0 && sr.DoctorCode == currentDrawerUser) + .Where(sr => sr.DmStatus == 0 && sr.DoctorCode == currentDrawerUser) .OrderBy(sr => sr.OrderNo) .ToPageList(PageNum, PageSize, ref totalCount); if (SurgicalResidualList != null && SurgicalResidualList.Count > 0) { - SurgicalResidualList.ForEach(sr => sr.ItemIsChecked = true); + SurgicalResidualList.Where(sr => sr.SendNo == DrawerNo.ToString()).ToList()?.ForEach(sr => sr.ItemIsChecked = true); TotalDrugList = SurgicalResidualList.Where(sr => sr.ItemIsChecked) // .Select(OrderDetailList => OrderDetailList._OrderDetail) .GroupBy(item => item.DrugInfo.DrugName) @@ -717,7 +720,7 @@ namespace DM_Weight.ViewModels machineRecord.Operator = HomeWindowViewModel.Operator?.Id; machineRecord.OperationTime = DateTime.Now; machineRecord.Type = 55; - machineRecord.InvoiceId = $"麻醉师核对单,打开{DrawerNo}号手术间"; + machineRecord.InvoiceId = $"麻醉师,打开{DrawerNo}号手术间"; if (DrawerNo > 0) @@ -767,26 +770,7 @@ namespace DM_Weight.ViewModels 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().taskAsyncLoop(500, 0, async (options, next, stop) => @@ -844,84 +828,7 @@ namespace DM_Weight.ViewModels } }); } - //if (DrawerType == 1) //公共药箱 - //{ - // if (listDrawerState == 0) - // { - // SelfContent = "还公共药箱"; - // } - // else - // { - // SelfContent = "取公共药箱"; - // } - - //} - //else - //{ - // if (listDrawerState == 0) - // { - // SelfContent = "还名下药箱"; - // } - // else - // { - // SelfContent = "取名下药箱"; - // } - - //} - } - //public DelegateCommand OpenBoxDelegate - //{ - // get => new DelegateCommand((DrawerType) => - // { - // SearchBox(); - // } - // ); - //} - //private void SearchBox() - //{ - - // SetAllBtnEnableFalse(); - // iList = SqlSugarHelper.Db.Queryable().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(() => @@ -1070,6 +977,7 @@ namespace DM_Weight.ViewModels private void GetUseBox() { List chlList = SqlSugarHelper.Db.Queryable().Where(cl => cl.MachineId == "DM5").ToList();//.Select(cl => cl.BelongUser).First(); + chlList = chlList.GroupBy(cl => cl.DrawerNo).Select(cl => cl.FirstOrDefault()).ToList(); if (chlList != null && chlList.Count > 0) { for (int i = 0; i < chlList.Count; i++) @@ -1113,5 +1021,29 @@ namespace DM_Weight.ViewModels // 取消消息订阅 //_eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); } + + + /// + /// 点击取药箱按钮 + /// + public DelegateCommand TakeBoxCommand + { + get => new DelegateCommand(TakeBoxMethod); + } + public void TakeBoxMethod() + { + + } + /// + /// 点击还药箱按钮 + /// + public DelegateCommand ReturnBoxCommand + { + get => new DelegateCommand(ReturnBoxMethod); + } + public void ReturnBoxMethod() + { + + } } } diff --git a/DM_Weight/ViewModels/CheckSelfOrderWindowViewModel.cs b/DM_Weight/ViewModels/CheckSelfOrderWindowViewModel.cs index 5fe790c..3213566 100644 --- a/DM_Weight/ViewModels/CheckSelfOrderWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckSelfOrderWindowViewModel.cs @@ -8,6 +8,7 @@ using Prism.Commands; using Prism.Events; using Prism.Mvvm; using Prism.Regions; +using Prism.Services.Dialogs; using System; using System.Collections; using System.Collections.Generic; @@ -32,6 +33,14 @@ namespace DM_Weight.ViewModels get => _drawerType; set => SetProperty(ref _drawerType, value); } + //1取药箱;0还药箱 + private int _operationType = -1; + + public int OperationType + { + get => _operationType; + set => SetProperty(ref _operationType, value); + } public bool KeepAlive => false; private int _pageNum = 1; @@ -543,12 +552,14 @@ namespace DM_Weight.ViewModels IEventAggregator _eventAggregator; //private PortUtil _portUtil; + IDialogService _dialogService; SocketHelper _socketHelper; - public CheckSelfOrderWindowViewModel(IEventAggregator eventAggregator, SocketHelper socketHelper) + public CheckSelfOrderWindowViewModel(IEventAggregator eventAggregator, SocketHelper socketHelper, IDialogService dialogService) { //_portUtil = portUtil; _eventAggregator = eventAggregator; _socketHelper = socketHelper; + _dialogService = dialogService; } private string? _searchValue; @@ -586,9 +597,9 @@ namespace DM_Weight.ViewModels .Where(oi => oi.HisDispFlag == 0) .Where(oi => oi.CancelFlag == 0) .Where(oi => oi.DoctorCode == currentDrawerUser) - .Where(oi => oi._OrderDetail.SetManuNo != null&&oi._OrderDetail.SetManuNo!="null") - .Where(oi=>oi._OrderDetail.Quantity>0) - .Where(oi=>oi._OrderDetail.surgicalResidual.SendNo== DrawerNo.ToString()) + .Where(oi => oi._OrderDetail.SetManuNo != null && oi._OrderDetail.SetManuNo != "null") + .Where(oi => oi._OrderDetail.Quantity > 0) + //.Where(oi => oi._OrderDetail.surgicalResidual.SendNo == DrawerNo.ToString()) .OrderBy(oi => oi.OrderId) .ToPageList(PageNum, PageSize, ref totalCount); @@ -609,8 +620,8 @@ namespace DM_Weight.ViewModels if (OrderInfoList != null && OrderInfoList.Count() > 0) { - OrderInfoList.ForEach(oi => oi.ItemIsChecked = true); OrderInfoList.ForEach(oi => oi._OrderDetail.DrugInfo = oi._OrderDetail.DrugInfo ?? new DrugInfo()); + OrderInfoList.Where(oi=>oi._OrderDetail.surgicalResidual?.SendNo==DrawerNo.ToString()).ToList()?.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).Select(OrderDetailList => OrderDetailList._OrderDetail).GroupBy(item => item.DrugInfo.DrugName).Select(group => new TotalDrug { DrugName = group.Key, TotalCount = group.Sum(item => item.Quantity) }).ToList(); } @@ -784,12 +795,11 @@ namespace DM_Weight.ViewModels machineRecord.Operator = HomeWindowViewModel.Operator?.Id; machineRecord.OperationTime = DateTime.Now; machineRecord.Type = 55; - machineRecord.InvoiceId = $"麻醉师核对单,打开{DrawerNo}号手术间"; + machineRecord.InvoiceId = $"麻醉师,打开{DrawerNo}号手术间"; if (DrawerNo > 0) { - RequestData(); Status = 1; _socketHelper.speechSynthesizer.SpeakAsyncCancelAll(); _socketHelper.speechSynthesizer.Resume(); @@ -815,45 +825,72 @@ namespace DM_Weight.ViewModels 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().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 () => + //ChannelList channelList = SqlSugarHelper.Db.Queryable().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"))) //{ - // 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("药箱已打开,请及时关闭"); - // } - // } - //}); + //channelList.DrawerState = 0; + //channelList.EffDate = DateTime.Now.ToString(); + //SqlSugarHelper.Db.Updateable(channelList).UpdateColumns(it => new { it.EffDate,it.DrawerState }).ExecuteCommand(); + // SqlSugarHelper.Db.Updateable().SetColumns(it=>it.EffDate== DateTime.Now.ToString()).SetColumns(it => it.DrawerState == 0) + // .Where(it => it.MachineId == "DM5" && it.DrawerNo == DrawerNo).ExecuteCommand(); + //} + if (OperationType == 1) + { + //取药箱,将当前药箱号记录到当前登录人身上 + if (!string.IsNullOrEmpty(HomeWindowViewModel.Operator.BoxNumber)) + { + HomeWindowViewModel.Operator.BoxNumber += $",{DrawerNo.ToString()}"; + SqlSugarHelper.Db.Updateable(HomeWindowViewModel.Operator).UpdateColumns(it => new { it.BoxNumber }).ExecuteCommand(); + } + else + { + HomeWindowViewModel.Operator.BoxNumber = $",{DrawerNo.ToString()}"; + SqlSugarHelper.Db.Updateable(HomeWindowViewModel.Operator).UpdateColumns(it => new { it.BoxNumber }).ExecuteCommand(); + } + SqlSugarHelper.Db.Updateable().SetColumns(it => it.EffDate == DateTime.Now.ToString()).SetColumns(it => it.DrawerState == 0) + .Where(it => it.MachineId == "DM5" && it.DrawerNo == DrawerNo).ExecuteCommand(); + //记录取药箱信息 + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + DrawerNo = DrawerNo, + Operator = HomeWindowViewModel.Operator?.Id, + Reviewer = HomeWindowViewModel.Reviewer?.Id, + OperationTime = DateTime.Now, + Type = 70, + Status= 70, + InvoiceId = $"{DateTime.Now} 取出药箱" + }).ExecuteCommand(); + } + else if (OperationType == 0) + { + RequestData(); + //还药箱,将当前药箱号从当前登录人身上删除 + if (HomeWindowViewModel.Operator.BoxNumber == $",{DrawerNo.ToString()}") + { + HomeWindowViewModel.Operator.BoxNumber = string.Empty; + } + else + { + HomeWindowViewModel.Operator.BoxNumber = HomeWindowViewModel.Operator.BoxNumber.Replace($",{DrawerNo.ToString()},", ","); + } + SqlSugarHelper.Db.Updateable(HomeWindowViewModel.Operator).UpdateColumns(it => new { it.BoxNumber }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable().SetColumns(it => it.EffDate ==null).SetColumns(it => it.DrawerState == 1) + .Where(it => it.MachineId == "DM5" && it.DrawerNo == DrawerNo).ExecuteCommand(); + //记录还药箱时间 + MachineRecord returnRecord = SqlSugarHelper.Db.Queryable().Where(mc => mc.MachineId == "DM5" && mc.DrawerNo == DrawerNo&&mc.Type==70&&mc.Operator==HomeWindowViewModel.Operator.Id).First(); + if(returnRecord!=null) + { + returnRecord.EffDate = DateTime.Now; + returnRecord.Status = 71; + returnRecord.Type = 71; + returnRecord.InvoiceId += $";{DateTime.Now} 还回药箱"; + + SqlSugarHelper.Db.Updateable(returnRecord).UpdateColumns(it => new { it.EffDate,it.Status,it.Type,it.InvoiceId }).ExecuteCommand(); + } + + } Thread.Sleep(200); int iException = 0; new PromiseUtil().taskAsyncLoop(500, 0, async (options, next, stop) => @@ -911,84 +948,7 @@ namespace DM_Weight.ViewModels } }); } - //if (DrawerType == 1) //公共药箱 - //{ - // if (listDrawerState == 0) - // { - // SelfContent = "还公共药箱"; - // } - // else - // { - // SelfContent = "取公共药箱"; - // } - - //} - //else - //{ - // if (listDrawerState == 0) - // { - // SelfContent = "还名下药箱"; - // } - // else - // { - // SelfContent = "取名下药箱"; - // } - - //} - } - //public DelegateCommand OpenBoxDelegate - //{ - // get => new DelegateCommand((DrawerType) => - // { - // SearchBox(); - // } - // ); - //} - //private void SearchBox() - //{ - - // SetAllBtnEnableFalse(); - // iList = SqlSugarHelper.Db.Queryable().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(() => @@ -1026,7 +986,7 @@ namespace DM_Weight.ViewModels { get => new DelegateCommand(() => { - if(DrawerNo==-1) + if (DrawerNo == -1) { AlertMsg alertMsg = new AlertMsg { @@ -1060,27 +1020,27 @@ namespace DM_Weight.ViewModels if (oi.DmStatus == 0) { //查询该药箱是否有该批次的药品,没有则无法确认(避免管理进行确认时确认不过去) - if(oi._OrderDetail != null) + if (oi._OrderDetail != null) { //for (int j = 0; j < oi.OrderDetailList.Count; j++) //{ // oi._OrderDetail = oi.OrderDetailList[j]; - int drawerNo = DrawerNo; - ChannelStock cs = SqlSugarHelper.Db.Queryable() - .Where(cs => cs.DrugId == oi._OrderDetail.DrugId - && cs.ManuNo == oi._OrderDetail.SetManuNo - && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5") - && cs.DrawerNo == drawerNo).First(); - if (cs == null) + int drawerNo = DrawerNo; + ChannelStock cs = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.DrugId == oi._OrderDetail.DrugId + && cs.ManuNo == oi._OrderDetail.SetManuNo + && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5") + && cs.DrawerNo == drawerNo).First(); + if (cs == null) + { + AlertMsg alertMsg = new AlertMsg { - AlertMsg alertMsg = new AlertMsg - { - Message = $"处方{oi.OrderNo}因药品批次{oi._OrderDetail.SetManuNo}无库存,无法确认", - Type = MsgType.ERROR, - }; - _eventAggregator.GetEvent().Publish(alertMsg); - return false; - } + Message = $"处方{oi.OrderNo}因药品批次{oi._OrderDetail.SetManuNo}无库存,无法确认", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return false; + } //} } @@ -1103,171 +1063,6 @@ namespace DM_Weight.ViewModels }).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() - // .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}"); - // } - // } - - //} - - #endregion - } //if (!string.IsNullOrEmpty(empChannelStock)) //{ @@ -1328,6 +1123,7 @@ namespace DM_Weight.ViewModels private void GetUseBox() { List chlList = SqlSugarHelper.Db.Queryable().Where(cl => cl.MachineId == "DM5").ToList();//.Select(cl => cl.BelongUser).First(); + chlList = chlList.GroupBy(cl => cl.DrawerNo).Select(cl => cl.FirstOrDefault()).ToList(); if (chlList != null && chlList.Count > 0) { for (int i = 0; i < chlList.Count; i++) @@ -1341,7 +1137,32 @@ namespace DM_Weight.ViewModels //DrawerType== 1为公共药箱 if (chl.DrawerType == 1) { - SetBtnEnable(chl.DrawerNo, true); + if (OperationType == 1) + { + //取药箱,在库则可取,不在则不可取 + if (chl.DrawerState == 1) + { + SetBtnEnable(chl.DrawerNo, true); + } + else + { + SetBtnEnable(chl.DrawerNo, false); + } + } + else + { + //还药箱,只能还自己取过的药箱 + //查询用户取过哪些药箱 + string[] BoxNumber = HomeWindowViewModel.Operator.BoxNumber.Split(','); + if (BoxNumber != null && BoxNumber.Contains(chl.DrawerNo.ToString())) + { + SetBtnEnable(chl.DrawerNo, true); + } + else + { + SetBtnEnable(chl.DrawerNo, false); + } + } } if (!string.IsNullOrEmpty(chl.BelongUser) && chl.BelongUser == HomeWindowViewModel.Operator.UserBarcode) { @@ -1354,98 +1175,39 @@ namespace DM_Weight.ViewModels } } } + public void OnNavigatedTo(NavigationContext navigationContext) { logger.Info("进入OnNavigatedTo"); - RequestData(); + OpenOrderDialog(); + //RequestData(); logger.Info("结束RequestData"); - //if(ModbusHelper.BoxOperate) - //{ - // Task.Factory.StartNew(() => { ModbusHelper.SpeakAsync("请关闭药箱后再打开"); }); - // return; - //} - ////查询当前药师的第一个药箱号并打开该药箱 - //int drawerNo = SqlSugarHelper.Db.Queryable().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().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 async Task OpenOrderDialog() + { + // 此处延时1毫秒,等待页面渲染 + await Task.Delay(TimeSpan.FromMilliseconds(1)); + DialogServiceExtensions.ShowDialogHost(_dialogService, "SelectOperationTypeDialog", null, DoDialogResult, "RootDialog"); + } + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + if (dialogResult.Result == ButtonResult.OK) + { + //取药箱,只能取在库存的药箱 + OperationType = 1; + GetUseBox(); + } + else + { + //还药箱,只能点自己取过的药箱 + OperationType = 0; + RequestData(); + } + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; @@ -1456,5 +1218,31 @@ namespace DM_Weight.ViewModels // 取消消息订阅 //_eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); } + /// + /// 点击取药箱按钮 + /// + public DelegateCommand TakeBoxCommand + { + get => new DelegateCommand(TakeBoxMethod); + } + public void TakeBoxMethod() + { + OperationType = 1; + GetUseBox(); + } + /// + /// 点击还药箱按钮 + /// + public DelegateCommand ReturnBoxCommand + { + get => new DelegateCommand(ReturnBoxMethod); + } + public void ReturnBoxMethod() + { + + OperationType = 0; + GetUseBox(); + RequestData(); + } } } diff --git a/DM_Weight/ViewModels/CheckStockWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockWindowViewModel.cs index 01ed36b..f4ce4ad 100644 --- a/DM_Weight/ViewModels/CheckStockWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckStockWindowViewModel.cs @@ -192,6 +192,161 @@ namespace DM_Weight.ViewModels // Id = it.Chnguid //}).UpdateColumns(cl => new { cl.State }).ExecuteCommand(); + //盘点改库存记录账册,多了则记录入库、少了记录出库 + if(it.CheckQuantity!=it.Quantity) + { + + //查询上一条账册中的空瓶数 + AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString())) + .Where(ab => ab.Type == 1 || ab.Type == 2) + .Where(ab => ab.DrugId == it.DrugId) + .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First(); + //修改凌晨生成的日结存与总结存数据 + AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString())) + .Where(ab => ab.Type == 3) + .Where(ab => ab.DrugId == it.DrugId) + .Where(ab => ab.ManuNo == it.ManuNo) + .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + // 获取更新完库存后的药品库存 + List nowChannels = SqlSugarHelper.Db.Queryable() + .Where(cs => (cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"]) && cs.DrawerType == 1) || cs.MachineId.Equals(ConfigurationManager.AppSettings["jj_machineId"])) + .Where(cs => cs.DrugId.Equals(it.DrugId)) + .Where(cs => cs.ManuNo.Equals(it.ManuNo)) + //.Where(cs => cs.DrawerType == 1) + .ToList(); + + int manuStock = 0; + if (it.CheckQuantity-it.Quantity>0) + { + //盘多了,记录入库 + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + (it.CheckQuantity - it.Quantity); + accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + (it.CheckQuantity - it.Quantity); + //负数直接记0 + accountBookG2Day.TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 && accountBookEmpty.TotalStock > (it.CheckQuantity - it.Quantity) ? accountBookEmpty.TotalStock - (it.CheckQuantity - it.Quantity) : 0) : 0); + + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + manuStock = accountBookG2Day.ManuStock; + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = it.DrugId, + Type = 3, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + YQuantity = 0, + ManuStock = (it.CheckQuantity - it.Quantity), + TotalStock = (it.CheckQuantity - it.Quantity), + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + CreateTime = DateTime.Now, + InvoiceNo = "日结存", + AddQuantity = (it.CheckQuantity - it.Quantity) + }).ExecuteCommand(); + if (iDayResult <= 0) + { + logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.CheckQuantity - it.Quantity}"); + } + } + //保存账册 + SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = it.DrugId, + Type = 1, + Department = ConfigurationManager.AppSettings["department"].ToString(), + InvoiceNo = InvoiceId, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + AddQuantity = it.CheckQuantity - it.Quantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + CreateTime = DateTime.Now, + ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity), + TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 && accountBookEmpty.TotalStock > (it.CheckQuantity - it.Quantity) ? accountBookEmpty.TotalStock - (it.CheckQuantity - it.Quantity) : 0) : 0) //负数直接记0 + + }).ExecuteCommand(); + } + else + { + //盘少了,记录出库 + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - (it.Quantity-it.CheckQuantity); + accountBookG2Day.OutQuantity = accountBookG2Day.OutQuantity + (it.Quantity - it.CheckQuantity); + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + //accountBookG2Day.UseDose = (Convert.ToInt32(accountBookG2Day.UseDose) + Convert.ToInt32(oi._OrderDetail.surgicalResidual.UseDose)).ToString();//盘点减的库存没有使用剂量 + //accountBookG2Day.ResidualDose = (Convert.ToInt32(accountBookG2Day.ResidualDose) + Convert.ToInt32(oi._OrderDetail.surgicalResidual.ResidualDose)).ToString();//盘点减的库存没有剩余剂量 + accountBookG2Day.TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 ? accountBookEmpty.TotalStock : 0) : 0) + (it.Quantity - it.CheckQuantity); + manuStock = accountBookG2Day.ManuStock; + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId =it.DrugId, + Type = 3, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + YQuantity = 0, + ManuStock = nowChannels.Sum(it => it.Quantity), //oi._OrderDetail.Quantity, + TotalStock = it.Quantity - it.CheckQuantity, + 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 = "日结存", + OutQuantity = (it.Quantity - it.CheckQuantity), + //UseDose = oi._OrderDetail.surgicalResidual.UseDose, + //ResidualDose = oi._OrderDetail.surgicalResidual.ResidualDose + }).ExecuteCommand(); + if (iDayResult <= 0) + { + logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.Quantity-it.CheckQuantity}"); + } + } + //查询上一条账册中的空瓶数 + //AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable() + //.Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString())) + //.Where(ab => ab.Type == 1 || ab.Type == 2) + //.Where(ab => ab.DrugId == oi._OrderDetail.DrugId) + //.Where(ab => ab.ManuNo == cs.ManuNo).OrderByDescending(ab => ab.Id).First(); + //保存账册 + int iInsertResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = it.DrugId, + Type = 2, + //Department = oi.DeptName, + OrderNo = $"checkStock_{it.DrawerNo}_{it.ColNo}_{it.Quantity}_{it.CheckQuantity}_{DateTime.Now}", + ManuNo = it.ManuNo, + EffDate = it.EffDate, + OutQuantity = it.Quantity-it.CheckQuantity, + 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 = $"checkStock_{it.DrawerNo}_{it.ColNo}_{it.Quantity}_{it.CheckQuantity}_{DateTime.Now}", + ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity), + TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 ? accountBookEmpty.TotalStock : 0) : 0) + (it.Quantity - it.CheckQuantity), + //ShoushuJian = drawerNo.ToString() + }).ExecuteCommand(); + //修改凌晨生成的日结存与总结存数据 + + } + } + // 保存数据 盘点记录 SqlSugarHelper.Db.Insertable(new MachineRecord() { diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs index e55a585..4be088a 100644 --- a/DM_Weight/ViewModels/HomeWindowViewModel.cs +++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs @@ -589,7 +589,7 @@ namespace DM_Weight.ViewModels PremissionDmList = premissions; SelectedMenu = premissions[0]; SelectedChildMenu = premissions[0].Children[0]; - _regionManager.RequestNavigate("ContentRegion", premissions[0].Children[0].PremissionPath); + //_regionManager.RequestNavigate("ContentRegion", premissions[0].Children[0].PremissionPath); //FindDrawerCount(); int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0"); if (autoExit > 0) diff --git a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs index ad75605..7c21174 100644 --- a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs +++ b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs @@ -220,18 +220,14 @@ namespace DM_Weight.ViewModels PremissionPath = "AdditionWindow", }; - //PremissionDm quyao1 = new PremissionDm - //{ - // Id = 11, - // PremissionName = "交接柜补药", - // PremissionPath = "AddToJiaoJieWindow", - //}; - //PremissionDm quyao2 = new PremissionDm - //{ - // Id = 12, - // PremissionName = "调拨出库", - // PremissionPath = "InvoiceOutWindow", - //}; + //管理做麻醉师核对处方的操作 + PremissionDm adminCheck = new PremissionDm + { + Id = 13, + PremissionName = "管理员操作手术间", + //PremissionPath = "CheckOrderWindow", + PremissionPath = "CheckSelfOrderForAdminViewModel", + }; PremissionDm quyao3 = new PremissionDm { Id = 13, @@ -270,6 +266,7 @@ namespace DM_Weight.ViewModels //quyaoChild.Add(openBox); quyaoChild.Add(checkOrder); quyaoChild.Add(addition); + quyaoChild.Add(adminCheck); quyaoChild.Add(openBoxWithOrder); quyao.Children = quyaoChild; defaultAll.Add(quyao); diff --git a/DM_Weight/ViewModels/SelectOperationTypeDialogViewModel.cs b/DM_Weight/ViewModels/SelectOperationTypeDialogViewModel.cs new file mode 100644 index 0000000..38eeb40 --- /dev/null +++ b/DM_Weight/ViewModels/SelectOperationTypeDialogViewModel.cs @@ -0,0 +1,51 @@ +using Prism.Commands; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.ViewModels +{ + public class SelectOperationTypeDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime + { + public string Title => "请选择操作类型"; + + public bool KeepAlive =>false; + + public event Action RequestClose; + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + + } + + public void OnDialogOpened(IDialogParameters parameters) + { + } + public DelegateCommand CancelCommand + { + get => new DelegateCommand(() => + { + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + }); + } + public DelegateCommand ConfirmCommand + { + get => new DelegateCommand(() => + { + //确认 + RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); + }); + } + } +} diff --git a/DM_Weight/Views/CheckSelfOrderForAdmin.xaml b/DM_Weight/Views/CheckSelfOrderForAdmin.xaml new file mode 100644 index 0000000..01289be --- /dev/null +++ b/DM_Weight/Views/CheckSelfOrderForAdmin.xaml @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/CheckSelfOrderForAdmin.xaml.cs b/DM_Weight/Views/CheckSelfOrderForAdmin.xaml.cs new file mode 100644 index 0000000..ed64ab0 --- /dev/null +++ b/DM_Weight/Views/CheckSelfOrderForAdmin.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 +{ + /// + /// CheckSelfOrderForAdmin.xaml 的交互逻辑 + /// + public partial class CheckSelfOrderForAdmin : UserControl + { + public CheckSelfOrderForAdmin() + { + InitializeComponent(); + } + } +} diff --git a/DM_Weight/Views/CheckSelfOrderWindow.xaml b/DM_Weight/Views/CheckSelfOrderWindow.xaml index 80b13d6..c2a08d5 100644 --- a/DM_Weight/Views/CheckSelfOrderWindow.xaml +++ b/DM_Weight/Views/CheckSelfOrderWindow.xaml @@ -15,7 +15,7 @@ - +