From db02d51934df041d24031a17b6ef18d7490ea670 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Mon, 18 Mar 2024 15:24:06 +0800 Subject: [PATCH] =?UTF-8?q?1)=E4=BF=AE=E6=94=B9=E8=B0=83=E6=8B=A8=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E6=97=B6=E5=8F=AF=E8=BE=93=E5=85=A5=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E6=95=B0=E9=87=8F=202=EF=BC=89=E4=BF=AE=E6=94=B9=E6=89=93?= =?UTF-8?q?=E5=BC=80=E6=8A=BD=E5=B1=89=E6=97=B6=E5=A4=8D=E5=88=B6list?= =?UTF-8?q?=E5=89=AF=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/Models/ChannelStock.cs | 2 + DM_Weight/Port/PortUtil.cs | 1 + .../ViewModels/AccountWindowViewModel.cs | 2 +- .../ViewModels/AddDrugControlViewModel.cs | 37 +++++++++- .../CheckStockNew2WindowViewModel.cs | 9 ++- .../CheckStockNewWindowViewModel.cs | 18 ++--- .../ViewModels/InvoiceInNewWindowViewModel.cs | 69 ++++++++++++++++--- .../ViewModels/OrderReturnDialogViewModel.cs | 10 ++- .../ViewModels/OrderTakeDialogViewModel.cs | 12 +++- .../ViewModels/SelfAddDialogViewModel.cs | 10 ++- .../ViewModels/SelfTakeDialogViewModel.cs | 9 ++- DM_Weight/Views/AddDrugControl.xaml | 22 ++++++ DM_Weight/Views/AddDrugControl.xaml.cs | 12 ++++ DM_Weight/Views/InvoiceInNewWindow.xaml | 8 +-- DM_Weight/msg/DelDrugManoEvent.cs | 14 ++++ 15 files changed, 197 insertions(+), 38 deletions(-) create mode 100644 DM_Weight/msg/DelDrugManoEvent.cs diff --git a/DM_Weight/Models/ChannelStock.cs b/DM_Weight/Models/ChannelStock.cs index 80c14c5..2a6a89b 100644 --- a/DM_Weight/Models/ChannelStock.cs +++ b/DM_Weight/Models/ChannelStock.cs @@ -73,6 +73,8 @@ namespace DM_Weight.Models [SugarColumn(ColumnName = "quantity")] public int Quantity { get; set; } + + /// /// /// 默认值: 1 diff --git a/DM_Weight/Port/PortUtil.cs b/DM_Weight/Port/PortUtil.cs index 9545e42..295f7a5 100644 --- a/DM_Weight/Port/PortUtil.cs +++ b/DM_Weight/Port/PortUtil.cs @@ -1110,6 +1110,7 @@ namespace DM_Weight.Port { try { + logger.Info($"TakeQuantity{drawerNo}-{colNo},操作数量{quantity},操作后数量{stock}"); canBusSerial.DiscardInBuffer(); //int channel = (drawerNo * 10 + colNo); diff --git a/DM_Weight/ViewModels/AccountWindowViewModel.cs b/DM_Weight/ViewModels/AccountWindowViewModel.cs index a70c5f7..f01f269 100644 --- a/DM_Weight/ViewModels/AccountWindowViewModel.cs +++ b/DM_Weight/ViewModels/AccountWindowViewModel.cs @@ -238,7 +238,7 @@ namespace DM_Weight.ViewModels try { string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; - //根据已生成的日结存记录 + //删除已生成的日结存记录 int deleteNum = SqlSugarHelper.Db.Deleteable() .Where(cs => cs.Type.Equals(5) && cs.OperationTime.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd") && cs.MachineId.Equals(machineId)).ExecuteCommand(); int inQuantity = 0; //当日入库量 diff --git a/DM_Weight/ViewModels/AddDrugControlViewModel.cs b/DM_Weight/ViewModels/AddDrugControlViewModel.cs index ee4cb7c..2bec9cc 100644 --- a/DM_Weight/ViewModels/AddDrugControlViewModel.cs +++ b/DM_Weight/ViewModels/AddDrugControlViewModel.cs @@ -3,6 +3,7 @@ using DM_Weight.msg; using DM_Weight.Port; using DM_Weight.util; using log4net; +using log4net.Repository.Hierarchy; using Prism.Commands; using Prism.Events; using Prism.Mvvm; @@ -170,6 +171,7 @@ namespace DM_Weight.ViewModels public bool Is17Drawer { get => _is17Drawer; set => SetProperty(ref _is17Drawer, value); } + public DelegateCommand UpdateDrawerNo { @@ -426,7 +428,7 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => true; + public bool KeepAlive => false; @@ -475,7 +477,34 @@ namespace DM_Weight.ViewModels channelLS.channelStocks = stockList; } } - + //删除药品下批次库存为0的批次 + private void DelManuNO(ChannelStock cstock) + { + if(cstock != null) + { + //删除ChannelStock表中该批次数据 + int isOk = SqlSugarHelper.Db.Deleteable().Where(cs => cs.DrugId == cstock.DrugId && cs.ManuNo == cs.ManuNo).ExecuteCommand(); + if(isOk>0 ) + { + logger.Info($"删除{cstock.DrawerNo}-{cstock.ColNo}抽屉中药品{cstock.DrugId}下的批次{cstock.ManuNo},"); + AlertMsg alertMsg = new AlertMsg + { + Message = "该药品批次已删除", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "该药品批次删除失败", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + } + } public long CurrentTimeMillis() { return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; @@ -506,7 +535,7 @@ namespace DM_Weight.ViewModels .Where(cl => cl.DrugId != null) .OrderBy(cl => cl.ColNo) .ToList(); - ChannelLsts = queryData.Select(cl => + ChannelLsts = queryData.AsParallel().Select(cl => { cl.channelStocks = cl.channelStocks.Select(cs => { @@ -525,6 +554,7 @@ namespace DM_Weight.ViewModels { _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); _eventAggregator.GetEvent().Subscribe(AddAction); + _eventAggregator.GetEvent().Subscribe(DelManuNO); FindDrawerCount(); RequestData(); } @@ -542,6 +572,7 @@ namespace DM_Weight.ViewModels // 取消消息订阅 _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); _eventAggregator.GetEvent().Unsubscribe(AddAction); + _eventAggregator.GetEvent().Unsubscribe(DelManuNO); } } } diff --git a/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs b/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs index d8731d1..23940db 100644 --- a/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs @@ -278,7 +278,14 @@ namespace DM_Weight.ViewModels channelStocks.ForEach(it => it.process = 1); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - List singleChannels = channelStocks.GroupBy(it => new + + List singleChannels = new List(); + for (int i = 0; i < channelStocks.Count; i++) + { + ChannelStock copy = TransExpV2.Trans(channelStocks[i]); + singleChannels.Add(copy); + } + singleChannels = singleChannels.GroupBy(it => new { it.DrawerNo, it.ColNo diff --git a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs index 4406add..f7997de 100644 --- a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs @@ -318,15 +318,15 @@ namespace DM_Weight.ViewModels //int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0,grouping.Key.IndexOf('-'))); int DrawerNo = grouping.Key; List Stocks = grouping.ToList(); - List copyStocks = new List(); - foreach (var item in Stocks) - { - copyStocks.Add(item); - } Stocks.ForEach(it => it.process = 1); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - - List singleChannels = Stocks.GroupBy(it => new + List singleChannels = new List(); + for (int i = 0; i < Stocks.Count; i++) + { + ChannelStock copy = TransExpV2.Trans(Stocks[i]); + singleChannels.Add(copy); + } + singleChannels = singleChannels.GroupBy(it => new { it.DrawerNo, it.ColNo @@ -334,7 +334,7 @@ namespace DM_Weight.ViewModels { var ret = it.First(); //ret.Quantity = it.Sum(itx => itx.Quantity); - ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + //ret.AddQuantity = it.Sum(itx => itx.AddQuantity); return ret; }).ToList().FindAll(it => it.BoardType != 1); @@ -360,7 +360,7 @@ namespace DM_Weight.ViewModels _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.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); _portUtil.DrawerNo = DrawerNo; _portUtil.Start(); } diff --git a/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs b/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs index 0a687df..f6fe068 100644 --- a/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs @@ -11,6 +11,7 @@ using Prism.Regions; using Prism.Services.Dialogs; using SqlSugar; using System; +using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Configuration; @@ -18,6 +19,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Windows.Documents; namespace DM_Weight.ViewModels { @@ -317,18 +319,18 @@ namespace DM_Weight.ViewModels //_eventAggregator.GetEvent().Publish(alertMsg); continue; } - ChannelStock stock = new ChannelStock(); + //ChannelStock stock = new ChannelStock(); //查询每种药有多少个批次 var invoicesManuNo = SqlSugarHelper.Db.Queryable() - .Where(iManuNo => iManuNo.InvoiceNo == invoices[i].InvoiceNo && iManuNo.DrugId == invoices[i].DrugId).ToList(); + .Where(iManuNo => iManuNo.InvoiceNo == invoices[i].InvoiceNo && iManuNo.DrugId == invoices[i].DrugId && iManuNo.Status == 0 && iManuNo.Type != 2 && iManuNo.CancelFlag == 0).ToList(); for (int j = 0; j < invoicesManuNo.Count; j++) { //查询是否有库存 List stockList = SqlSugarHelper.Db.Queryable() .Where(cs => cs.ManuNo == invoicesManuNo[j].DrugManuNo && cs.DrugId == invoicesManuNo[j].DrugId && cs.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM1")).ToList(); - stock = stockList.Count > 0 ? stockList[0] : new ChannelStock(); + //stock = stockList.Count > 0 ? stockList[0] : new ChannelStock(); List manuNoList = SqlSugarHelper.Db.Queryable().Where(dm => dm.ManuNo == invoicesManuNo[j].DrugManuNo && dm.DrugId == invoicesManuNo[j].DrugId).ToList(); - if (stock == null || stock.Id is null) + if (stockList == null || stockList.Count <= 0) { if (manuNoList == null || manuNoList.Count <= 0) { @@ -341,6 +343,7 @@ namespace DM_Weight.ViewModels _eventAggregator.GetEvent().Publish(alertMsg); continue; } + ChannelStock stock = new ChannelStock(); //没有库存写入一条数据 stock.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; stock.DrawerNo = channelLst.DrawerNo; @@ -351,13 +354,24 @@ namespace DM_Weight.ViewModels stock.ManuNo = invoicesManuNo[j].DrugManuNo; stock.EffDate = manuNoList[0].EffDate; stock.Chnguid = channelLst.Id; + stockList.Add(stock); } - stock.AddQuantity = invoicesManuNo[j].quantity; + //stock.AddQuantity = invoicesManuNo[j].quantity; + //stockList.ForEach(s => s.AddQuantity = invoicesManuNo[j].quantity); + stockList.GroupBy(x => x.ManuNo) + .Select(it => + { + var ret = it.First(); + ret.AddQuantity = invoicesManuNo[j].quantity; + return ret; + }) + .ToList(); + if (channelLst.channelStocks == null) { channelLst.channelStocks = new List(); } - channelLst.channelStocks.Add(stock); + channelLst.channelStocks.AddRange(stockList); } InOutInvoice copy = TransExpV2.Trans(invoices[i]); @@ -390,6 +404,27 @@ namespace DM_Weight.ViewModels { if (Status == 0) { + if (AddChannels == null || AddChannels.Count <= 0) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "请输入入库数量", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return; + } + int totalNum = AddChannels.Sum(add => add.AddQuantity); + if (totalNum != SelectedInvoice.Quantity) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "各批次添加数量要与调拨单药品总数一致!", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return; + } enumerator.MoveNext(); Status = 1; OpenOneByOne(); @@ -402,7 +437,13 @@ namespace DM_Weight.ViewModels List channelStocks = grouping.ToList(); channelStocks.ForEach(it => it.process = 1); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - List singleChannels = channelStocks.GroupBy(it => new + List singleChannels = new List(); + for (int i = 0; i < channelStocks.Count; i++) + { + ChannelStock copy = TransExpV2.Trans(channelStocks[i]); + singleChannels.Add(copy); + } + singleChannels = singleChannels.GroupBy(it => new { it.DrawerNo, it.ColNo @@ -422,7 +463,13 @@ namespace DM_Weight.ViewModels if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) { - List ChannelLst = channelStocks.Where(it => it.BoardType != 1) + List ChannelLst = new List(); + for (int i = 0; i < channelStocks.Count; i++) + { + ChannelStock copy = TransExpV2.Trans(channelStocks[i]); + singleChannels.Add(copy); + } + ChannelLst = ChannelLst.Where(it => it.BoardType != 1) .GroupBy(it => it.ColNo) .Select(it => { @@ -501,7 +548,7 @@ namespace DM_Weight.ViewModels } //查询现有库位中是否有库存为0的记录,如果有直接update ChannelStock recordHistory = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == it.DrawerNo && cs.ColNo == it.ColNo && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.Quantity <= 0).First(); - if (recordHistory!=null&& recordHistory.Id!=null) + if (recordHistory != null && recordHistory.Id != null) { SqlSugarHelper.Db.Updateable().SetColumns(item => new ChannelStock() { @@ -563,7 +610,7 @@ namespace DM_Weight.ViewModels { //根据ChannelLsts中的库位,删除该库位库存为0的记录 SqlSugarHelper.Db.Deleteable() - .Where(cs => cs.Quantity <= 0 && cs.DrawerNo == ChannelLsts[i].channelStocks[0].DrawerNo && cs.ColNo == ChannelLsts[i].channelStocks[0].ColNo).ExecuteCommand(); + .Where(cs => cs.Quantity <= 0 && cs.DrugId == ChannelLsts[i].DrugId && cs.MachineId == ChannelLsts[i].MachineId).ExecuteCommand(); } } return true; @@ -589,7 +636,7 @@ namespace DM_Weight.ViewModels if (singleChannels[i].BoardType == 5) { List channelStockEffDate = SqlSugarHelper.Db.Queryable() - .Where(cs => cs.MachineId==singleChannels[i].MachineId) + .Where(cs => cs.MachineId == singleChannels[i].MachineId) .Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo) .Where(cs => cs.ColNo == singleChannels[i].ColNo) .OrderBy(cs => cs.EffDate).ToList(); diff --git a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs index 6472456..79fc581 100644 --- a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs @@ -22,6 +22,7 @@ using DM_Weight.Port; using DM_Weight.select; using DM_Weight.util; using System.Threading; +using System.Collections; namespace DM_Weight.ViewModels { @@ -265,8 +266,13 @@ namespace DM_Weight.ViewModels channelStocks.ForEach(it => it.process = 1); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - - List singleChannels = channelStocks + List singleChannels = new List(); + for (int i = 0; i < channelStocks.Count; i++) + { + ChannelStock copy = TransExpV2.Trans(channelStocks[i]); + singleChannels.Add(copy); + } + singleChannels = singleChannels .GroupBy(it => new { it.DrawerNo, it.ColNo }) .Select(it => { diff --git a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs index 212041b..f1977ab 100644 --- a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs @@ -272,7 +272,14 @@ namespace DM_Weight.ViewModels _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); //List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); - List singleChannels = channelStocks + List singleChannels = new List(); + for (int i = 0; i < channelStocks.Count; i++) + { + ChannelStock copy = TransExpV2.Trans(channelStocks[i]); + singleChannels.Add(copy); + } + + singleChannels = singleChannels .GroupBy(it => new { it.DrawerNo, it.ColNo }) .Select(it => { @@ -289,8 +296,7 @@ namespace DM_Weight.ViewModels { try { - - _portUtil.TakeQuantity(DrawerNo, it.ColNo, it.TakeQuantity, it.Quantity - it.TakeQuantity); + _portUtil.TakeQuantity(DrawerNo, it.ColNo, it.Quantity, it.Quantity - it.TakeQuantity); } catch (Exception ex) { diff --git a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs index a8c6354..fe60ce0 100644 --- a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs @@ -20,6 +20,7 @@ using DM_Weight.Views; using System.Threading; using SqlSugar; using System.Configuration; +using System.Collections; namespace DM_Weight.ViewModels { @@ -192,8 +193,13 @@ namespace DM_Weight.ViewModels channelStocks.ForEach(it => it.process = 1); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - - List singleChannels = channelStocks + List singleChannels = new List(); + for (int i = 0; i < channelStocks.Count; i++) + { + ChannelStock copy = TransExpV2.Trans(channelStocks[i]); + singleChannels.Add(copy); + } + singleChannels = singleChannels .GroupBy(it => new { it.DrawerNo, it.ColNo }) diff --git a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs index 427d19e..2b7aaec 100644 --- a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs @@ -184,8 +184,13 @@ namespace DM_Weight.ViewModels channelStocks.ForEach(it => it.process = 1); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - - List singleChannels = channelStocks + List singleChannels = new List(); + for (int i = 0; i < channelStocks.Count; i++) + { + ChannelStock copy = TransExpV2.Trans(channelStocks[i]); + singleChannels.Add(copy); + } + singleChannels = singleChannels .GroupBy(it => new { it.DrawerNo, it.ColNo }) .Select(it => { diff --git a/DM_Weight/Views/AddDrugControl.xaml b/DM_Weight/Views/AddDrugControl.xaml index 50a0e68..0057a18 100644 --- a/DM_Weight/Views/AddDrugControl.xaml +++ b/DM_Weight/Views/AddDrugControl.xaml @@ -337,7 +337,29 @@ + + @@ -294,7 +294,7 @@ - --> + diff --git a/DM_Weight/msg/DelDrugManoEvent.cs b/DM_Weight/msg/DelDrugManoEvent.cs new file mode 100644 index 0000000..006244f --- /dev/null +++ b/DM_Weight/msg/DelDrugManoEvent.cs @@ -0,0 +1,14 @@ +using DM_Weight.Models; +using Prism.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.msg +{ + internal class DelDrugManoEvent:PubSubEvent + { + } +}