From de22a9a6c90af86457fcd9d8154f22dd82612049 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Tue, 14 Nov 2023 14:49:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A01=EF=BC=89=E5=A4=9A=E5=A4=84=E6=96=B9=E5=8F=96?= =?UTF-8?q?=E8=8D=AF2=EF=BC=89=E5=A4=9A=E6=89=B9=E6=AC=A1=E6=8A=BD?= =?UTF-8?q?=E5=B1=89=E5=8A=A0=E8=8D=AF=E3=80=82=E9=A1=B5=E9=9D=A2=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=80=BC=E6=98=BE=E7=A4=BA=E6=98=AF=E5=90=A6=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=A4=9A=E5=A4=84=E6=96=B9=E5=8F=96=E8=8D=AF=E5=8F=8A=E5=A4=9A?= =?UTF-8?q?=E6=89=B9=E6=AC=A1=E5=8A=A0=E8=8D=AF=E5=8F=8A=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/App.config | 6 + DM_Weight/App.xaml.cs | 4 + DM_Weight/Models/ChannelList.cs | 200 +++++++ DM_Weight/Models/ChannelStock.cs | 7 + .../ViewModels/AddDrugControlViewModel.cs | 533 ++++++++++++++++++ .../BindingChannelNewDialogViewModel.cs | 484 ++++++++++++++++ .../ViewModels/CheckStockWindowViewModel.cs | 12 +- .../DrawerAddDrugWindowViewModel.cs | 14 +- .../DrawerTakeDrugWindowViewModel.cs | 25 +- DM_Weight/ViewModels/HomeWindowViewModel.cs | 14 +- .../MultiOrderTakeDialogViewModel.cs | 6 +- .../ViewModels/RoleManagerWindowViewModel.cs | 56 +- .../ViewModels/StockListWindowViewModel.cs | 9 +- DM_Weight/Views/AddDrugControl.xaml | 395 +++++++++++++ DM_Weight/Views/AddDrugControl.xaml.cs | 41 ++ .../Views/Dialog/BindingChannelNewDialog.xaml | 230 ++++++++ .../Dialog/BindingChannelNewDialog.xaml.cs | 47 ++ DM_Weight/Views/DrawerAddDrugWindow.xaml | 13 +- DM_Weight/msg/AddDrugEvent.cs | 14 + 19 files changed, 2067 insertions(+), 43 deletions(-) create mode 100644 DM_Weight/Models/ChannelList.cs create mode 100644 DM_Weight/ViewModels/AddDrugControlViewModel.cs create mode 100644 DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs create mode 100644 DM_Weight/Views/AddDrugControl.xaml create mode 100644 DM_Weight/Views/AddDrugControl.xaml.cs create mode 100644 DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml create mode 100644 DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml.cs create mode 100644 DM_Weight/msg/AddDrugEvent.cs diff --git a/DM_Weight/App.config b/DM_Weight/App.config index 270baba..106848b 100644 --- a/DM_Weight/App.config +++ b/DM_Weight/App.config @@ -55,6 +55,12 @@ + + + + + \ No newline at end of file diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index f8fa7cb..28a848f 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -157,6 +157,8 @@ namespace DM_Weight // 自选加药模态框 containerRegistry.RegisterDialog(); containerRegistry.RegisterForNavigation(); + //多批次抽屉加药 + containerRegistry.RegisterForNavigation(); #endregion #region 还药 @@ -184,6 +186,8 @@ namespace DM_Weight // 库位绑定模态框 containerRegistry.RegisterDialog(); containerRegistry.RegisterForNavigation(); + //同一药品多批次库位绑定 + containerRegistry.RegisterForNavigation(); // 库存盘点页面 containerRegistry.RegisterForNavigation(); // 药品列表页面 diff --git a/DM_Weight/Models/ChannelList.cs b/DM_Weight/Models/ChannelList.cs new file mode 100644 index 0000000..81f1e4a --- /dev/null +++ b/DM_Weight/Models/ChannelList.cs @@ -0,0 +1,200 @@ +using Prism.Commands; +using Prism.Mvvm; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.Models +{ + [SugarTable("channel_list")] + public class ChannelList : BindableBase + { + /// + /// + /// + [SugarColumn(ColumnName = "chnguid", IsPrimaryKey = true)] + //[SugarColumn(ColumnName = "id", IsPrimaryKey = true)] + public string Id { get; set; } + + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "machine_id")] + public string MachineId { get; set; } + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "row_no")] + public int DrawerNo { get; set; } + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "col_no")] + public int ColNo { get; set; } + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "pos_no")] + public int PosNo { get; set; } + + + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "drug_id")] + public string DrugId { get; set; } + + ///// + ///// + ///// 默认值: NULL + ///// + //[SugarColumn(ColumnName = "manu_no")] + //public string ManuNo { get; set; } + ///// + ///// + ///// 默认值: NULL + ///// + //[SugarColumn(ColumnName = "eff_date")] + //public string EffDate { get; set; } + ///// + ///// + ///// 默认值: NULL + ///// + //[SugarColumn(ColumnName = "quantity")] + //public int Quantity { get; set; } + + /// + /// + /// 默认值: 1 + /// + [SugarColumn(ColumnName = "drawer_type")] + public int DrawerType { get; set; } + /// + /// + /// 默认值: 1 + /// + [SugarColumn(ColumnName = "board_type")] + public int BoardType { get; set; } + /// + /// + /// 默认值: 1 + /// + [SugarColumn(ColumnName = "state")] + public int? State { get; set; } + + [SugarColumn(IsIgnore = true)] + public bool IsSelected { get; set; } + + [SugarColumn(IsIgnore = true)] + public InOutInvoice Invoice { get; set; } + + [SugarColumn(IsIgnore = true)] + public string Location + { + get => DrawerNo + "-" + ColNo; + } + //private int _addQuantity = 0; + //[SugarColumn(IsIgnore = true)] + //public int AddQuantity + //{ + // get => _addQuantity; + // set + // { + // SetProperty(ref _addQuantity, value); + // } + //} + + //private int _takeQuantity = 0; + + //[SugarColumn(IsIgnore = true)] + //public int TakeQuantity + //{ + // get => _takeQuantity; + // set + // { + // if (value > Quantity) + // { + // throw new ArgumentException("取药数量不能大于库存"); + // } + // SetProperty(ref _takeQuantity, value); + // } + //} + //private int _returnQuantity = 0; + + //[SugarColumn(IsIgnore = true)] + //public int ReturnQuantity + //{ + // get => _returnQuantity; + // set + // { + // SetProperty(ref _returnQuantity, value); + // } + //} + + //private int _checkQuantity = 0; + + + //[SugarColumn(IsIgnore = true)] + //public int CheckQuantity + //{ + // get => _checkQuantity; + // set + // { + // if (value < 0) + // { + // throw new ArgumentException("盘点数量不能是负数"); + // } + // SetProperty(ref _checkQuantity, value); + // } + //} + + + //[SugarColumn(IsIgnore = true)] + //public int? CanReturnQuantity { get; set; } + + private DrugInfo? _DrugInfo; + [Navigate(NavigateType.ManyToOne, nameof(DrugId))] + public DrugInfo Drug { get => _DrugInfo; set => SetProperty(ref _DrugInfo, value); } + + //[SugarColumn(IsIgnore = true)] + //public int process { get; set; } = 0; + + + private DrugManuNo? _drugManuNo; + [SugarColumn(IsIgnore = true)] + public DrugManuNo? drugManuNo { get => _drugManuNo; set => SetProperty(ref _drugManuNo, value); } + + private List? _channelStocks; + [Navigate(NavigateType.OneToMany, nameof(ChannelStock.Chnguid))] + public List channelStocks { get => _channelStocks; set => SetProperty(ref _channelStocks, value); } + + //private DelegateCommand _addManunoCommand; + //[SugarColumn(IsIgnore = true)] + //public DelegateCommand AddManunoCommand + //{ + // get + // { + // if (_addManunoCommand == null) + // _addManunoCommand = new DelegateCommand(o => DoDelete(o)); + // return _addManunoCommand; + // } + //} + + //private void DoDelete(ChannelList parameter) + //{ + + //} + //药品规格 + private string _drugSpec; + [SugarColumn(ColumnName = "drug_manu_no")] + public string DrugSpec { get=> _drugSpec;set=>SetProperty(ref _drugSpec, value); } + } +} diff --git a/DM_Weight/Models/ChannelStock.cs b/DM_Weight/Models/ChannelStock.cs index 04da009..8bcd816 100644 --- a/DM_Weight/Models/ChannelStock.cs +++ b/DM_Weight/Models/ChannelStock.cs @@ -18,6 +18,9 @@ namespace DM_Weight.Models //[SugarColumn(ColumnName = "id", IsPrimaryKey = true)] public string Id { get; set; } + [SugarColumn(ColumnName = "chnguid")] + public string Chnguid { get; set; } + /// /// /// 默认值: NULL @@ -178,5 +181,9 @@ namespace DM_Weight.Models [SugarColumn(IsIgnore = true)] public DrugManuNo? drugManuNo { get; set; } + private ChannelList? _channelList; + [Navigate(NavigateType.ManyToOne, nameof(Chnguid))] + public ChannelList ChannelLst { get => _channelList; set => SetProperty(ref _channelList, value); } + } } \ No newline at end of file diff --git a/DM_Weight/ViewModels/AddDrugControlViewModel.cs b/DM_Weight/ViewModels/AddDrugControlViewModel.cs new file mode 100644 index 0000000..7a4d819 --- /dev/null +++ b/DM_Weight/ViewModels/AddDrugControlViewModel.cs @@ -0,0 +1,533 @@ +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 Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Configuration; +using System.Drawing.Printing; +using System.Linq; +using System.Reflection.PortableExecutable; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Documents; + +namespace DM_Weight.ViewModels +{ + public class AddDrugControlViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime + { + private readonly ILog logger = LogManager.GetLogger(typeof(DrawerAddDrugWindowViewModel)); + private List _drawerNoList = new List(); + public static AddDrugControlViewModel vm; + //凭证号 + //private string _pzh; + //public string PZH { get => _pzh; set { SetProperty(ref _pzh, value); } } + + private List? _channelLsts; + + public List? ChannelLsts + { + get => _channelLsts; + set => SetProperty(ref _channelLsts, value); + } + private List __channelStocks = new List(); + public List ChannelStocks + { + get => __channelStocks; + set => SetProperty(ref __channelStocks, value); + } + + private ChannelStock? _channelStock; + + public ChannelStock? CStock + { + get => _channelStock; + set => SetProperty(ref _channelStock, value); + } + + //private ChannelList? _channelList; + //public ChannelList? ChannelLst + //{ + // get => _channelList; + // set => SetProperty(ref _channelList, value); + //} + + private static readonly DateTime Jan1st1970 = new DateTime + (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + + private PortUtil _portUtil; + IEventAggregator _eventAggregator; + IDialogService _dialogService; + public AddDrugControlViewModel(IDialogService DialogService, PortUtil portUtil, IEventAggregator eventAggregator) + { + _dialogService = DialogService; + _portUtil = portUtil; + _eventAggregator = eventAggregator; + vm = this; + } + public DelegateCommand SelectionChangedCommand => new DelegateCommand(selectionAction); + + private async void selectionAction() + { + if (CStock != null) + { + // 此处延时1毫秒,等待页面渲染 + await Task.Delay(TimeSpan.FromMilliseconds(1)); + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("addManuno", CStock); + DialogServiceExtensions.ShowDialogHost(_dialogService, "AddManunoDialog", dialogParameters, DoDialogResult, "RootDialog"); + + } + + } + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + //if(dialogResult.Result == ButtonResult.OK) + //{ + CStock = null; + RequestData(); + //} + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } + void DoMyPrismEvent(DeviceMsg msg) + { + if (msg.WindowName == "DrawerAddDrugWindow") + { + switch (msg.EventType) + { + // 抽屉打开 + case EventType.DRAWEROPEN: + if (Status == 1) + { + Status = 2; + } + + break; + // 抽屉关闭 + case EventType.DRAWERCLOSE: + if (Status == 2) + { + Status = 3; + } + break; + // 数量变化 + case EventType.UPDATEQUANTITY: + if (Status == 2) + { + //ChannelStocks.ForEach(it => it.AddQuantity = msg.Quantitys[it.ColNo - 1]); + } + break; + // 打开失败 + case EventType.OPENERROR: + AlertMsg alertMsg = new AlertMsg + { + Message = msg.Message, + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Status = 0; + break; + } + } + + if (msg.WindowName == "AddDrugControl") + { + + } + + } + + private int _status; + + public int Status { get => _status; set => SetProperty(ref _status, value); } + + private int _drawerNo = 1; + + public int DrawerNo + { + get => _drawerNo; + set => SetProperty(ref _drawerNo, value); + } + + private bool _is8Drawer = true; + + public bool Is8Drawer { get => _is8Drawer; set => SetProperty(ref _is8Drawer, value); } + + private bool _is16Drawer = false; + + public bool Is16Drawer { get => _is16Drawer; set => SetProperty(ref _is16Drawer, value); } + + + private bool _is17Drawer = false; + + public bool Is17Drawer { get => _is17Drawer; set => SetProperty(ref _is17Drawer, value); } + + + public DelegateCommand UpdateDrawerNo + { + get => new DelegateCommand((DrawerNo) => + { + this.DrawerNo = Convert.ToInt32(DrawerNo); + RequestData(); + }, (DrawerNo) => Status == 0 + ); + } + public DelegateCommand OpenDrawer + + { + get => new DelegateCommand(() => + { + Status = 1; + _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + + try + { + //List singleChannels = ChannelStocks.FindAll(it => it.BoardType != 1); + List singleChannels = ChannelLsts.FindAll(it => it.BoardType != 1); + + _portUtil.WindowName = "DrawerAddDrugWindow"; + _portUtil.Operate = true; + _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; + _portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray(); + //_portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); + _portUtil.DrawerNo = DrawerNo; + _portUtil.Start(); + + } + catch (Exception ex) + { + logger.Info($"OpenDrawer异常:{ex.Message}"); + } + + + }, () => Status == 0).ObservesProperty(() => Status); + } + private bool _isFinishClick = false; + + // 完成按钮 + public DelegateCommand TakeFinish + { + get => new DelegateCommand(() => + { + if (!_isFinishClick) + { + _isFinishClick = true; + foreach (ChannelList lst in ChannelLsts) + { + ChannelStocks.AddRange(lst.channelStocks); + } + List record = ChannelStocks.FindAll(it => it.AddQuantity != 0).ToList(); + if (record.Count > 0) + { + string InvoiceId = "DRAWER_" + CurrentTimeMillis(); + //string InvoiceId = PZH; + //List repeatList = new List(); + List stockRepeats = new List(); + var f = SqlSugarHelper.Db.UseTran(() => + { + + for (int i = 0; i < record.Count; i++) + { + ChannelStock it = record[i]; + it.ManuNo = it.drugManuNo.ManuNo; + it.EffDate = it.drugManuNo.EffDate; + if (it.Id != null) + { + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = it.Quantity + it.AddQuantity, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + Id = it.Id, + }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); + } + else + { + //如果批号重复则不让添加 + List csCount = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == it.DrawerNo && cs.ManuNo == it.ManuNo && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).ToList(); + if (csCount.Count > 0) + { + //repeatList.Add(it.ManuNo); + stockRepeats.Add(it); + continue; + } + + // 更新数据 库存信息 + SqlSugarHelper.Db.Insertable(new ChannelStock() + { + Quantity = it.AddQuantity, + Chnguid = it.Chnguid, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + DrawerNo = it.DrawerNo, + ColNo = it.ColNo, + DrugId = it.DrugId, + DrawerType = it.DrawerType, + BoardType = it.BoardType, + Id = Guid.NewGuid().ToString(), + MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1" + }).ExecuteCommand(); + } + // 获取更新完库存后的药品库存 + List nowChannels = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId.Equals(it.MachineId)) + .Where(cs => cs.DrugId.Equals(it.DrugId)) + .Where(cs => cs.DrawerType == 1) + .ToList(); + + // 保存数据 入库记录 + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = it.MachineId, + DrawerNo = it.DrawerNo, + ColNo = it.ColNo, + DrugId = it.DrugId, + ManuNo = it.ManuNo, + EffDate = !String.IsNullOrEmpty(it.EffDate) ? DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + OperationTime = DateTime.Now, + Quantity = it.AddQuantity, + Type = 1, + InvoiceId = InvoiceId, + StockQuantity = nowChannels.Sum(it => it.Quantity) + }).ExecuteCommand(); + } + return true; + }); + ChannelStocks.Clear(); + //if (record.Count == repeatList.Count) + if (stockRepeats.Count == record.Count) + { + AlertMsg alertMsg = new AlertMsg + { + Message = $"该抽屉已存在此药品批次{string.Join(',', stockRepeats.Select(r=>r.ManuNo).ToArray())},请选择其他批次", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + else + { + //if (repeatList.Count > 0) + //{ + // AlertMsg alertMsg = new AlertMsg + // { + // Message = $"该抽屉已存在此药品批次{string.Join(',', repeatList)},请选择其他批次", + // Type = MsgType.ERROR + // }; + // _eventAggregator.GetEvent().Publish(alertMsg); + //} + if (f.Data) + { + + string msg = string.Empty; + MsgType type = MsgType.SUCCESS; + //if (repeatList.Count > 0) + if (stockRepeats.Count > 0) + { + msg = $"该抽屉下批次{string.Join(',', stockRepeats.Select(r => r.ManuNo).ToArray())}已存在,不可重复添加,其他批次加药完成,库存已更新"; + foreach(var stockRpt in stockRepeats) + { + //移除重复的信息,以免更新屏显库存时更新了重复数据 + record.Remove(stockRpt); + + } + type = MsgType.WARING; + } + else + { + msg = "抽屉加药完成,库存已更新"; + } + // 更新屏显库存 + List singleChannels = record.FindAll(it => it.BoardType != 1); + if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + { + singleChannels.ForEach(it => + { + _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity); + }); + } + RequestData(); + AlertMsg alertMsg = new AlertMsg + { + Message = msg, + Type = type, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "更新库存失败", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + } + Status = 0; + _isFinishClick = false; + + //PZH = string.Empty; + } + else + { + _isFinishClick = false; + AlertMsg alertMsg = new AlertMsg + { + Message = "没有填写加药数量", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + + } + + }); + } + + // 取消按钮 + public DelegateCommand CancleTake + { + get => new DelegateCommand(() => + { + _portUtil.ResetData(); + Status = 0; + }); + } + + + + //添加批次 + public void AddAction(ChannelList channelLS) + { + if (channelLS != null) + { + ChannelStock cls = new ChannelStock(); + DrugManuNo drugManu = new DrugManuNo(); + cls.DrugInfo = channelLS.Drug; + if (channelLS.channelStocks.Count > 0) + { + //drugManu = channelLS.channelStocks[0].DrugInfo.DrugManuNos[0]; + cls.drugManuNo = channelLS.channelStocks[0].drugManuNo; + } + else + { + //drugManu= cls.DrugInfo.DrugManuNos[0]; + if (cls.DrugInfo.DrugManuNos.Count > 0) + { + cls.drugManuNo = cls.DrugInfo.DrugManuNos[0]; + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "该药品下没有批次,请先添加批次", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return; + } + } + //cls.Id = ""; + cls.Chnguid = channelLS.Id; + cls.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; + cls.DrawerNo = channelLS.DrawerNo; + cls.BoardType = channelLS.BoardType; + cls.DrawerType = channelLS.DrawerType; + cls.ColNo = channelLS.ColNo; + cls.DrugId = channelLS.DrugId; + cls.AddQuantity = 0; + //string sqlStr = @"select drug_id,manu_no,manu_date,eff_date from drug_manu_no where drug_id=@drugId + // and manu_no not in(select manu_no from channel_stock where drug_id=@drugId) "; + //cls.DrugInfo.DrugManuNos=SqlSugarHelper.Db.SqlQueryable(sqlStr).AddParameters(new + //{ + // drugId = channelLS.DrugId + //}) + //.Select(it => new DrugManuNo()).ToList(); + List stockList = new List(); + stockList.AddRange(channelLS.channelStocks); + stockList.Add(cls); + channelLS.channelStocks = stockList; + } + } + + public long CurrentTimeMillis() + { + return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; + } + public bool KeepAlive => false; + + public void FindDrawerCount() + { + int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); + Is8Drawer = count < 9; + Is16Drawer = count >= 16; + Is17Drawer = count > 16; + } + + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 + public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) + { + continuationCallback(true); + } + public void RequestData() + { + List queryData = SqlSugarHelper.Db.Queryable() + .Includes(cl => cl.Drug, di => di.DrugManuNos) + .Includes(cl => cl.channelStocks, dr => dr.DrugInfo, d => d.DrugManuNos) + .Where(cl => cl.DrawerNo == DrawerNo) + .Where(cl => cl.DrawerType == 1) + .Where(cl => cl.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .Where(cl => cl.DrugId != null) + .OrderBy(cl => cl.ColNo) + .ToList(); + ChannelLsts = queryData.Select(cl => + { + cl.channelStocks = cl.channelStocks.Select(cs => + { + cs.drugManuNo = cl.Drug.DrugManuNos.Find(it => it.ManuNo.Equals(cs.ManuNo)); + return cs; + }).ToList(); + return cl; + }).ToList(); + //ChannelLsts = new ObservableCollection(queryData); + ChannelLsts.ForEach(cl => cl.channelStocks.ForEach(cs => cs.DrugInfo = cl.Drug)); + } + + //接收导航传过来的参数 现在是在此处初始化了表格数据 + public void OnNavigatedTo(NavigationContext navigationContext) + { + _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + _eventAggregator.GetEvent().Subscribe(AddAction); + FindDrawerCount(); + RequestData(); + } + + + //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + //这个方法用于拦截请求 + public void OnNavigatedFrom(NavigationContext navigationContext) + { + // 取消消息订阅 + _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + _eventAggregator.GetEvent().Unsubscribe(AddAction); + } + } +} diff --git a/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs new file mode 100644 index 0000000..98ede1d --- /dev/null +++ b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs @@ -0,0 +1,484 @@ +using MaterialDesignThemes.Wpf; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.util; +using log4net; +using System.Threading; +using System.Reflection.Metadata.Ecma335; + +namespace DM_Weight.ViewModels +{ + public class BindingChannelNewDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime + { + public static BindingChannelNewDialogViewModel vm; + public string Title => "库位绑定"; + + public event Action RequestClose; + + private int _drawerNo = 0; + + + private SolidColorBrush _colorBrush; + + public SolidColorBrush SnackbarBackground + { + get => _colorBrush; + set => SetProperty(ref _colorBrush, value); + } + + private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3)); + + public ISnackbarMessageQueue SnackbarMessageQueue + { + get => _snackbarMessageQueue; + set => SetProperty(ref _snackbarMessageQueue, value); + } + + IEventAggregator _eventAggregator; + PortUtil _portUtil; + //ScreenUtil _screenUtil; + + public BindingChannelNewDialogViewModel(IEventAggregator eventAggregator, PortUtil portUtil//, ScreenUtil screenUtil + ) + { + _eventAggregator = eventAggregator; + _portUtil = portUtil; + //_screenUtil = screenUtil; + vm = this; + } + + public int DrawerNo + { + get => _drawerNo; + set + { + SetProperty(ref _drawerNo, value); + GetChannelsByDrawerNo(); + } + } + + private DrugInfo? _drugInfo; + + public DrugInfo? DrugInfo + { + get => _drugInfo; + set + { + SetProperty(ref _drugInfo, value); + //if (_drugInfo != null) + //{ + // DrugManuNos = _drugInfo.DrugManuNos.OrderByDescending(dm => dm.ManuNo).ToList(); + //} + } + } + //拼音码对应药品实体 + //private DrugInfo? _durgInfo_for_py; + //public DrugInfo? DrugInfo_Py + //{ + // get => _durgInfo_for_py; + // set + // { + + // SetProperty(ref _durgInfo_for_py, value); + // if (_durgInfo_for_py != null) + // { + // DrugInfos = GetDrugByDrugPY(_durgInfo_for_py.PyCode); + // } + // else + // { + // DrugInfos = GetDrugByDrugPY(""); + // } + // } + //} + + //#region 根据药品拼音码查询药品名称 + //private List GetDrugByDrugPY(string pycode) + //{ + // List DrugList = null; + // if (!string.IsNullOrEmpty(pycode)) + // { + // DrugList = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).Where(di => di.PyCode.Contains(pycode)).OrderBy(di => di.DrugId).ToList(); + // } + // else + // { + // DrugList = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); + // } + // return DrugList; + //} + //private List? _drugInfos_py; + //public List? DrugInfos_PY + //{ + // get => _drugInfos_py; + // set => SetProperty(ref _drugInfos_py, value); + //} + //#endregion 根据药品拼音码查询药品名称 + + + private List? _drugInfos; + + public List? DrugInfos + { + get => _drugInfos; + set => SetProperty(ref _drugInfos, value); + } + + //private DrugManuNo? _drugManuNo; + + //public DrugManuNo? DrugManuNo + //{ + // get => _drugManuNo; + // set => SetProperty(ref _drugManuNo, value); + //} + //private List? _drugManuNos; + + //public List? DrugManuNos + //{ + // get => _drugManuNos; + // set => SetProperty(ref _drugManuNos, value); + //} + + + private List? _channels; + + public List? Channels + { + get => _channels; + set => SetProperty(ref _channels, value); + } + + private int _totalCount = 0; + public int TotalCount { get => _totalCount; set => SetProperty(ref _totalCount, value); } + + private int _pageNum = 1; + public int PageNum + { + get => _pageNum; + set + { + SetProperty(ref _pageNum, value); + GetChannelsByDrawerNo(); + } + } + + 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); + } + } + + + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + + private void GetAllDrugInfos() + { + var list = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); + DrugInfos = list; + //DrugInfos_PY = list; + } + + private void GetChannelsByDrawerNo() + { + Channels?.Clear(); + int totalCount = 0; + var list = SqlSugarHelper.Db.Queryable() + .Includes(cl => cl.Drug) + //.Includes(cs => cs.channelStock) + .WhereIF(DrawerNo > 0, cl => cl.DrawerNo == DrawerNo) + .Where(cl => cl.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .OrderBy(cl => cl.DrawerNo) + .OrderBy(cl => cl.ColNo) + .ToPageList(PageNum, PageSize, ref totalCount); + Channels = list; + TotalCount = totalCount; + } + public void OnDialogOpened(IDialogParameters parameters) + { + if (parameters.ContainsKey("DrawerNo")) + { + DrawerNo = parameters.GetValue("DrawerNo"); + } + GetAllDrugInfos(); + GetChannelsByDrawerNo(); + _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + } + public DelegateCommand Query + { + get => new DelegateCommand(() => + { + GetChannelsByDrawerNo(); + }); + } + + + public DelegateCommand BindingDrug + { + get => new DelegateCommand(async () => + { + + var SelectChannels = Channels.FindAll(item => item.IsSelected); + + if (SelectChannels.All(it => it.DrawerType != 1)) + { + if (SelectChannels.Count == 1) + { + if (DrugInfo != null) + { + int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrugId.Equals(DrugInfo.DrugId.ToString())).Where(cs => cs.DrawerType != 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).Count(); + if (count == 0) + { + var item = SelectChannels[0]; + + if (item.DrugId == null || !DrugInfo.DrugId.ToString().Equals(item.DrugId)) + { + item.PosNo = 0; + } + item.DrugId = DrugInfo.DrugId.ToString(); + item.DrugSpec= DrugInfo.DrugSpec.ToString(); + SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo,it.DrugSpec }).ExecuteCommand(); + GetChannelsByDrawerNo(); + + if (item.BoardType == 5) + { + _portUtil.WindowName = "BindingChannelDialog"; + // 向显示屏写入库位信息 + _portUtil.WriteChannelInfo(1, DrugInfo.DrugName, item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.WriteChannelInfo(2, DrugInfo.DrugSpec, item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.WriteChannelInfo(8, DrugInfo.Manufactory, item.DrawerNo, item.ColNo); + await Task.Delay(200); + //_portUtil.WriteChannelInfo(6, DrugManuNo.EffDate==null?"": DrugManuNo.EffDate, item.DrawerNo, item.ColNo); + //await Task.Delay(200); + //_portUtil.WriteChannelInfo(5, DrugManuNo.ManuNo, item.DrawerNo, item.ColNo); + //await Task.Delay(200); + _portUtil.ShowContent(item.DrawerNo, item.ColNo); + } + //_screenUtil.SetStockInfo(item, 1); + + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue($"药品【{DrugInfo.DrugName}】已经绑定了回收库位不可再次绑定"); + } + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("请选择库位需要绑定的药品信息"); + } + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("每种药品只能绑定一个回收库位"); + } + } + else + { + //if (DrugInfo != null && DrugManuNo != null) + //{ + + var c = SelectChannels.Count; + + if (c > 0) + { + for (int i = 0; i < SelectChannels.Count; i++) + { + var item = SelectChannels[i]; + var channelStock = SqlSugarHelper.Db.Queryable().Where(cs => cs.Chnguid == item.Id&&cs.Quantity>0).ToList(); + if(channelStock.Count>0) + { + //有库存,不能解绑 + + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue($"库位{item.DrawerNo}-{item.ColNo}中还存在药品,不能绑定其他药品"); + continue; + } + if (item.DrugId == null || !DrugInfo.DrugId.ToString().Equals(item.DrugId)) + { + item.PosNo = 0; + } + + item.DrugId = DrugInfo.DrugId.ToString(); + //item.ManuNo = DrugManuNo.ManuNo; + item.Drug = DrugInfo; + item.DrugSpec = DrugInfo.DrugSpec.ToString(); + //item.EffDate = String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate); + SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo,it.DrugSpec }).ExecuteCommand(); + + if (item.BoardType == 5) + { + _portUtil.WindowName = "BindingChannelDialog"; + // 向显示屏写入库位信息 + _portUtil.WriteChannelInfo(1, DrugInfo.DrugName, item.DrawerNo, item.ColNo); + //await Task.Delay(200); + Thread.Sleep(200); + _portUtil.WriteChannelInfo(2, DrugInfo.DrugSpec, item.DrawerNo, item.ColNo); + //await Task.Delay(200); + Thread.Sleep(200); + _portUtil.WriteChannelInfo(8, DrugInfo.Manufactory, item.DrawerNo, item.ColNo); + //await Task.Delay(200); + Thread.Sleep(200); + //_portUtil.WriteChannelInfo(6, DrugManuNo.ManuNo, item.DrawerNo, item.ColNo); + //await Task.Delay(200); + //Thread.Sleep(200); + //_portUtil.WriteChannelInfo(5, String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate), item.DrawerNo, item.ColNo); + ////await Task.Delay(200); + //Thread.Sleep(200); + _portUtil.ShowContent(item.DrawerNo, item.ColNo); + } + } + + + GetChannelsByDrawerNo(); + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("所选库位中无可绑定库位【库位还存在药品】"); + } + //} + //else + //{ + // SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + // SnackbarMessageQueue.Enqueue("请选择库位需要绑定的药品及批次信息"); + //} + } + }); + } + + public DelegateCommand RemoveBinding + { + get => new DelegateCommand(async () => + { + var SelectChannels = Channels.FindAll(item => item.IsSelected && item.DrugId != null); + var c = SelectChannels.Count; + if (c > 0) + { + + SelectChannels.ForEach(async item => + { + var channelStock = SqlSugarHelper.Db.Queryable().Where(cs => cs.Chnguid == item.Id && cs.Quantity > 0).ToList(); + if (channelStock.Count > 0) + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("所选库位中无可解绑药品【库位还存在药品】"); + //该药品下的批次还有库存则不能解绑 + return; + } + + item.DrugId = null; + //item.ManuNo = null; + //item.EffDate = null; + item.Drug = null; + item.DrugSpec = null; + SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId,it.DrugSpec }).ExecuteCommand(); + if (item.BoardType == 5) + { + // 清除显示屏库位信息 + _portUtil.ClearContent(item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.ShowContent(item.DrawerNo, item.ColNo); + } + + //_screenUtil.SetStockInfo(item, 1); + }); + GetChannelsByDrawerNo(); + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("所选库位中无可解绑药品"); + } + }); + } + + public DelegateCommand BtnCloseCommand + { + get => new DelegateCommand(() => + { + //DialogParameters parameters = new DialogParameters(); + //parameters.Add("",); + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + }); + } + + public bool KeepAlive => false; + string message = string.Empty; + private void DoMyPrismEvent(DeviceMsg msg) + { + if (msg.WindowName == "BindingChannelDialog") + { + switch (msg.EventType) + { + case EventType.OPENERROR: + AlertMsg alertMsg = new AlertMsg + { + Message = msg.Message, + Type = MsgType.ERROR, + }; + if (message != msg.Message) + { + message = msg.Message; + _eventAggregator.GetEvent().Publish(alertMsg); + } + break; + } + } + } + public void UpdateComboBoxItems(string text) + { + string str = @"SELECT d.drug_id,d.py_code,d.drug_barcode,d.drug_name,d.drug_brand_name,d.drug_spec,d.dosage,d.pack_unit, + d.manufactory,d.max_stock,CONCAT(drug_name,' ',drug_spec)as drug_name_spec FROM `drug_info` d"; + if (string.IsNullOrEmpty(text)) + { + DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); + return; + } + if (DrugInfos != null) + { + DrugInfos.Clear(); + } + DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).Where(di => di.DrugName.Contains(text) || di.PyCode.Contains(text)).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); + } + } +} diff --git a/DM_Weight/ViewModels/CheckStockWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockWindowViewModel.cs index 1cb7b69..43cbf47 100644 --- a/DM_Weight/ViewModels/CheckStockWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckStockWindowViewModel.cs @@ -263,8 +263,18 @@ namespace DM_Weight.ViewModels public void FindDrawerCount() { - int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) + int count = 0; + if (ConfigurationManager.AppSettings["MultiBatch"].ToString().Equals("1")) + { + count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); + } + else + { + count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); + + } Is8Drawer = count < 9; Is16Drawer = count >= 16; Is17Drawer = count > 16; diff --git a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs index e92901f..9cbde8f 100644 --- a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs @@ -159,7 +159,7 @@ namespace DM_Weight.ViewModels if (!_isFinishClick) { _isFinishClick = true; - List record = ChannelStocks.FindAll(it => it.AddQuantity != 0&&it.Quantity==0).ToList(); + List record = ChannelStocks.FindAll(it => it.AddQuantity != 0).ToList(); if (record.Count > 0) { string InvoiceId = "DRAWER_" + CurrentTimeMillis(); @@ -263,8 +263,18 @@ namespace DM_Weight.ViewModels public void FindDrawerCount() { - int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) + int count = 0; + if (ConfigurationManager.AppSettings["MultiBatch"].ToString().Equals("1")) + { + count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); + } + else + { + count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); + + } Is8Drawer = count < 9; Is16Drawer = count >= 16; Is17Drawer = count > 16; diff --git a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs index 127e62b..91de831 100644 --- a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs @@ -35,11 +35,11 @@ namespace DM_Weight.ViewModels get => _channelStocks; set => SetProperty(ref _channelStocks, value); } - + private static readonly DateTime Jan1st1970 = new DateTime (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - + private PortUtil _portUtil; IEventAggregator _eventAggregator; @@ -53,7 +53,7 @@ namespace DM_Weight.ViewModels void DoMyPrismEvent(DeviceMsg msg) { - if(msg.WindowName == "DrawerTakeDrugWindow") + if (msg.WindowName == "DrawerTakeDrugWindow") { switch (msg.EventType) { @@ -91,7 +91,7 @@ namespace DM_Weight.ViewModels break; } } - + } private int _status; @@ -127,7 +127,7 @@ namespace DM_Weight.ViewModels }, (DrawerNo) => Status == 0 ); } - + public DelegateCommand OpenDrawer { @@ -198,7 +198,7 @@ namespace DM_Weight.ViewModels ColNo = it.ColNo, DrugId = it.DrugId, ManuNo = it.ManuNo, - EffDate = !String.IsNullOrEmpty(it.EffDate) ?DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture):null, + EffDate = !String.IsNullOrEmpty(it.EffDate) ? DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, Operator = HomeWindowViewModel.Operator?.Id, Reviewer = HomeWindowViewModel.Reviewer?.Id, OperationTime = DateTime.Now, @@ -246,7 +246,7 @@ namespace DM_Weight.ViewModels } } - + }); } @@ -269,8 +269,17 @@ namespace DM_Weight.ViewModels public void FindDrawerCount() { - int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) + int count = 0; + if (ConfigurationManager.AppSettings["MultiBatch"].ToString().Equals("1")) + { + count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); + } + else + { + count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); + } Is8Drawer = count < 9; Is16Drawer = count >= 16; Is17Drawer = count > 16; diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs index 7094ba6..fad7459 100644 --- a/DM_Weight/ViewModels/HomeWindowViewModel.cs +++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs @@ -241,9 +241,17 @@ namespace DM_Weight.ViewModels public void FindDrawerCount() { - int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) + int count = 0; + if (ConfigurationManager.AppSettings["MultiBatch"].ToString().Equals("1")) + { + count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); - + } + else + { + count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); + } Is16Drawer = count == 16; } @@ -256,8 +264,6 @@ namespace DM_Weight.ViewModels //接收导航传过来的参数 public void OnNavigatedTo(NavigationContext navigationContext) { - - //取出user UserList = navigationContext.Parameters.GetValue("operator"); Operator = UserList; diff --git a/DM_Weight/ViewModels/MultiOrderTakeDialogViewModel.cs b/DM_Weight/ViewModels/MultiOrderTakeDialogViewModel.cs index 19dbc3c..f1aa9c4 100644 --- a/DM_Weight/ViewModels/MultiOrderTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/MultiOrderTakeDialogViewModel.cs @@ -181,7 +181,8 @@ namespace DM_Weight.ViewModels //.Where(od => od.OrderNo. OrderInfo.OrderNo) .ToList(); - + + List channelStocks = new List(); List msg = new List(); for (int i = 0; i < orderDetails.Count; i++) @@ -245,7 +246,8 @@ namespace DM_Weight.ViewModels } else { - msg.Add($"药品【{orderDetail.DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】"); + //msg.Add($"药品【{orderDetail.DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】"); + msg.Add($"药品【{HasQChannels[0].DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】"); } } if (msg.Count > 0) diff --git a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs index 1a8f843..a2c2472 100644 --- a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs +++ b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs @@ -34,7 +34,7 @@ namespace DM_Weight.ViewModels //{ // _allPremissions = Clone(defaultAll); //} - + public static ObservableCollection Clone(object List) { using (Stream objectStream = new MemoryStream()) @@ -89,7 +89,7 @@ namespace DM_Weight.ViewModels // { // AllPremissions.RemoveAt(index); // } - + // }); // RightPremissions = new ObservableCollection(Permissions); //} @@ -118,7 +118,7 @@ namespace DM_Weight.ViewModels { int i = p.Children.ToList().FindIndex(it4 => it4.Id == it3.Id); //if (i > 0 && AllPremissions.ElementAt(index).Children.Count > i) - if (p.Children[i] != null) + if (p.Children.Count > 0 && i >= 0 && p.Children[i] != null) { AllPremissions.ElementAt(index).Children.RemoveAt(i); } @@ -158,7 +158,8 @@ namespace DM_Weight.ViewModels static RoleManagerWindowViewModel() { #region 取药菜单 - PremissionDm quyao = new PremissionDm{ + PremissionDm quyao = new PremissionDm + { Id = 1, PremissionName = "取药", PremissionImage = "/Images/TbQyao.png", @@ -194,20 +195,22 @@ namespace DM_Weight.ViewModels PremissionName = "取药记录", PremissionPath = "TakeRecordWindow", }; - - PremissionDm mulityOrder = new PremissionDm + if (ConfigurationManager.AppSettings["returnDrugMode"].ToString().Equals("1")) { - Id = 16, - PremissionName = "多处方取药", - PremissionPath = "MultiOrderTakeDrugWindow", - }; + PremissionDm mulityOrder = new PremissionDm + { + Id = 16, + PremissionName = "多处方取药", + PremissionPath = "MultiOrderTakeDrugWindow", + }; + quyaoChild.Add(mulityOrder); + } quyaoChild.Add(quyao1); quyaoChild.Add(quyao2); quyaoChild.Add(quyao3); quyaoChild.Add(quyao4); quyaoChild.Add(quyao5); - quyaoChild.Add(mulityOrder); quyao.Children = quyaoChild; defaultAll.Add(quyao); #endregion @@ -243,6 +246,16 @@ namespace DM_Weight.ViewModels PremissionName = "加药记录", PremissionPath = "AddRecordWindow", }; + if (ConfigurationManager.AppSettings["MultiBatch"].ToString().Equals("1")) + { + PremissionDm jiayao5 = new PremissionDm + { + Id = 25, + PremissionName = "多批次抽屉加药", + PremissionPath = "AddDrugControl", + }; + jiayaoChild.Add(jiayao5); + } jiayaoChild.Add(jiayao1); jiayaoChild.Add(jiayao2); jiayaoChild.Add(jiayao3); @@ -282,7 +295,7 @@ namespace DM_Weight.ViewModels PremissionName = "归还记录", PremissionPath = "ReturnRecordWindow", }; - huanyaoChild.Add(Convert.ToInt32(ConfigurationManager.AppSettings["returnDrugMode"]) == 1? huanyao11:huanyao1); + huanyaoChild.Add(Convert.ToInt32(ConfigurationManager.AppSettings["returnDrugMode"]) == 1 ? huanyao11 : huanyao1); huanyaoChild.Add(huanyao2); huanyaoChild.Add(huanyao3); huanyao.Children = huanyaoChild; @@ -377,7 +390,7 @@ namespace DM_Weight.ViewModels set => SetProperty(ref _allPremissions, value); } - private PremissionDm? _leftPremission ; + private PremissionDm? _leftPremission; public PremissionDm? LeftPremission { get => _leftPremission; @@ -441,9 +454,10 @@ namespace DM_Weight.ViewModels if (v > item.Children.Count) { item.Children.Add(it); - } else + } + else { - item.Children.Insert(v-1, it); + item.Children.Insert(v - 1, it); } }); } @@ -458,7 +472,7 @@ namespace DM_Weight.ViewModels { RightPremissions.Insert(v - 1, LeftPremission); } - + } AllPremissions.RemoveAt(AllPremissions.ToList().FindIndex(it => it.Id == LeftPremission.Id)); @@ -473,7 +487,7 @@ namespace DM_Weight.ViewModels // 存在 if (index > -1) { - ObservableCollection a= RightPremissions.ElementAt(index).Children; + ObservableCollection a = RightPremissions.ElementAt(index).Children; int v = LeftPremission.Id % 10; if (v > a.Count) { @@ -506,7 +520,7 @@ namespace DM_Weight.ViewModels { RightPremissions.Insert(v - 1, item2); } - + item.Children.RemoveAt(item.Children.ToList().FindIndex(it => it.Id == LeftPremission.Id)); } @@ -527,7 +541,7 @@ namespace DM_Weight.ViewModels RightPremission = _selected; }); } - + public DelegateCommand ToLeft { @@ -663,7 +677,7 @@ namespace DM_Weight.ViewModels Role.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; Role.Permissions = RightPremissions.ToList(); List roleList = SqlSugarHelper.Db.Queryable().Where(r => r.RoleName == Role.RoleName).ToList(); - if(roleList.Count>0) + if (roleList.Count > 0) { SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); SnackbarMessageQueue.Enqueue("该角色已存在!"); @@ -704,7 +718,7 @@ namespace DM_Weight.ViewModels { RoleList = SqlSugarHelper.Db.Queryable() .Where(di => di.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) - .WhereIF(!String.IsNullOrEmpty(SearchValue), (di) => di.RoleName.Contains(SearchValue??"")) + .WhereIF(!String.IsNullOrEmpty(SearchValue), (di) => di.RoleName.Contains(SearchValue ?? "")) .Select(r => r) .ToList() ; diff --git a/DM_Weight/ViewModels/StockListWindowViewModel.cs b/DM_Weight/ViewModels/StockListWindowViewModel.cs index 18b26d3..8cbe56a 100644 --- a/DM_Weight/ViewModels/StockListWindowViewModel.cs +++ b/DM_Weight/ViewModels/StockListWindowViewModel.cs @@ -112,7 +112,14 @@ namespace DM_Weight.ViewModels get => new DelegateCommand(() => { DialogParameters dialogParameters = new DialogParameters(); - DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelDialog", dialogParameters, DoDialogResult, "RootDialog"); + if (ConfigurationManager.AppSettings["MultiBatch"].ToString().Equals("1")) + { + DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelNewDialog", dialogParameters, DoDialogResult, "RootDialog"); + } + else + { + DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelDialog", dialogParameters, DoDialogResult, "RootDialog"); + } }); } diff --git a/DM_Weight/Views/AddDrugControl.xaml b/DM_Weight/Views/AddDrugControl.xaml new file mode 100644 index 0000000..4f5afc9 --- /dev/null +++ b/DM_Weight/Views/AddDrugControl.xaml @@ -0,0 +1,395 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/AddDrugControl.xaml.cs b/DM_Weight/Views/AddDrugControl.xaml.cs new file mode 100644 index 0000000..075135a --- /dev/null +++ b/DM_Weight/Views/AddDrugControl.xaml.cs @@ -0,0 +1,41 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.ViewModels; +using Prism.Events; +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 +{ + /// + /// AddDrugControl.xaml 的交互逻辑 + /// + public partial class AddDrugControl : UserControl + { + IEventAggregator _eventAggregator; + public AddDrugControl(IEventAggregator eventAggregator) + { + InitializeComponent(); + _eventAggregator= eventAggregator; + } + private void Button_Click(object sender, RoutedEventArgs e) + { + Button btn = (Button)sender; + ChannelList cls = (ChannelList)btn.CommandParameter; + //vms.AddAction(cls); + _eventAggregator.GetEvent().Publish(cls); + } + } +} diff --git a/DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml b/DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml new file mode 100644 index 0000000..eb35eaa --- /dev/null +++ b/DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +