diff --git a/DM_Weight/Converter/ColorCountConverter.cs b/DM_Weight/Converter/ColorCountConverter.cs new file mode 100644 index 0000000..e2b45da --- /dev/null +++ b/DM_Weight/Converter/ColorCountConverter.cs @@ -0,0 +1,41 @@ +using DM_Weight.Models; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; + +namespace DM_Weight.Converter +{ + internal class ColorCountConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var total = 0; + bool bInt = int.TryParse(value.ToString(), out var count); if (bInt) + { + if (count <= 0) + { + return "Red"; + } + else + { + return "black"; + } + } + else + { + return "black"; + } + + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/DM_Weight/Models/ChannelStock.cs b/DM_Weight/Models/ChannelStock.cs index 1c3f38e..f73b1e0 100644 --- a/DM_Weight/Models/ChannelStock.cs +++ b/DM_Weight/Models/ChannelStock.cs @@ -119,6 +119,12 @@ namespace DM_Weight.Models SetProperty(ref _addQuantity, value); } } + /// + /// 调拨入库数量 + /// + private int _invoiceQuantity; + [SugarColumn(IsIgnore =true)] + public int InvoiceQuantity { get=>_invoiceQuantity; set=>SetProperty(ref _invoiceQuantity, value); } private int _takeQuantity = 0; @@ -136,9 +142,25 @@ namespace DM_Weight.Models { throw new ArgumentException("取药数量不能小于0"); } + if(OrderQuantity>0&&value>OrderQuantity) + { + throw new ArgumentException("取药数量不能大于应取数量"); + } SetProperty(ref _takeQuantity, value); } } + + private int _orderQuantity = 0; + /// + /// 处方取药数量 + /// + [SugarColumn(IsIgnore =true)] + public int OrderQuantity + { + get => _orderQuantity; + set=>SetProperty(ref _orderQuantity, value); + } + //private string _tipMessage=string.Empty; //[SugarColumn(IsIgnore = true)] //public string TipMessage diff --git a/DM_Weight/Models/OrderDetail.cs b/DM_Weight/Models/OrderDetail.cs index 109654c..2b4540a 100644 --- a/DM_Weight/Models/OrderDetail.cs +++ b/DM_Weight/Models/OrderDetail.cs @@ -127,5 +127,10 @@ namespace DM_Weight.Models /// [SugarColumn(ColumnName = "use_dosage")] public string UseDosage { get; set; } + /// + /// 处方中该药品状态是否已全部取出0未取1已取(针对处方可取部分药) + /// + [SugarColumn(ColumnName = "dm_status")] + public int? DMStatus { get;set; } } } \ No newline at end of file diff --git a/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs b/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs index b7706fc..4b1ae46 100644 --- a/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs @@ -291,7 +291,7 @@ namespace DM_Weight.ViewModels if (SelectedInvoice != null) { //先查询有几种药 - string strSql = @"SELECT sum(Quantity) AS SumQuantity, COUNT(ID) AS CountNum,INVOICE_NO AS InvoiceNo,drug_id AS DrugId,QUANTITY AS quantity,drug_manu_no AS drugManuNo FROM IN_OUT_INVOICE WHERE INVOICE_NO=@INVOICE_NO GROUP BY INVOICE_NO,DRUG_ID"; + string strSql = @"SELECT sum(Quantity) AS SumQuantity, COUNT(ID) AS CountNum,INVOICE_NO AS InvoiceNo,drug_id AS DrugId,QUANTITY AS quantity,drug_manu_no AS drugManuNo FROM IN_OUT_INVOICE WHERE STATUS=0 AND INVOICE_NO=@INVOICE_NO GROUP BY INVOICE_NO,DRUG_ID"; var invoices = SqlSugarHelper.Db.SqlQueryable(strSql) .AddParameters(new @@ -354,6 +354,7 @@ namespace DM_Weight.ViewModels stock.ManuNo = invoicesManuNo[j].DrugManuNo; stock.EffDate = manuNoList[0].EffDate; stock.Chnguid = channelLst.Id; + stock.InvoiceQuantity = invoicesManuNo[j].quantity; stockList.Add(stock); } //stock.AddQuantity = invoicesManuNo[j].quantity; @@ -363,6 +364,7 @@ namespace DM_Weight.ViewModels { var ret = it.First(); ret.AddQuantity = invoicesManuNo[j].quantity; + ret.InvoiceQuantity = invoicesManuNo[j].quantity; return ret; }) .ToList(); @@ -390,7 +392,8 @@ namespace DM_Weight.ViewModels ChannelStocks.Clear(); foreach (ChannelList lst in ChannelLsts) { - ChannelStocks.AddRange(lst.channelStocks); + + ChannelStocks.AddRange(lst.channelStocks.Where(cs => cs.AddQuantity > 9)); } AddChannels = ChannelStocks.FindAll(it => it.AddQuantity != 0); @@ -414,17 +417,17 @@ namespace DM_Weight.ViewModels _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; - } + //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(); @@ -506,18 +509,48 @@ namespace DM_Weight.ViewModels if (!_isFinishClick) { _isFinishClick = true; - List record = ChannelStocks.ToList(); + List record = ChannelStocks;//.ToList(); string InvoiceId = SelectedInvoice.InvoiceNo; var f = SqlSugarHelper.Db.UseTran(() => { - SqlSugarHelper.Db.Updateable(new InOutInvoice() - { - Status = 1, - InvoiceNo = SelectedInvoice.InvoiceNo - }).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.InvoiceNo }).ExecuteCommand(); - for (int i = 0; i < record.Count; i++) { + //添加数量不能大于入库单上要加的数量 + if (record[i].AddQuantity > record[i].InvoiceQuantity) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "添加数量不能大于调拨单中药品数量!", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return false; + } + //添加数量等于入库单上要加的数量则更新入库单状态 + if (record[i].AddQuantity == record[i].InvoiceQuantity) + { + SqlSugarHelper.Db.Updateable(new InOutInvoice() + { + Status = 1, + InvoiceNo = SelectedInvoice.InvoiceNo, + DrugManuNo = record[i].ManuNo, + DrugId = record[i].DrugId + + }).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.InvoiceNo, it.DrugId, it.DrugManuNo }).ExecuteCommand(); + } + else + { + //添加数量小于入库单上要加的数量则更新入库单中的数量 + SqlSugarHelper.Db.Updateable(new InOutInvoice() + { + quantity= record[i].InvoiceQuantity- record[i].AddQuantity, + InvoiceNo = SelectedInvoice.InvoiceNo, + DrugManuNo = record[i].ManuNo, + DrugId = record[i].DrugId + + }).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.InvoiceNo, it.DrugId, it.DrugManuNo }).ExecuteCommand(); + + } ChannelStock it = record[i]; @@ -635,22 +668,22 @@ namespace DM_Weight.ViewModels { //if (singleChannels[i].BoardType == 5) //{ - List channelStockEffDate = SqlSugarHelper.Db.Queryable() - .Where(cs => cs.MachineId == singleChannels[i].MachineId) - .Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo) - .Where(cs => cs.ColNo == singleChannels[i].ColNo) - .Where(cs=>cs.Quantity>0) - .OrderBy(cs => cs.EffDate).ToList(); - int totalQuantity = channelStockEffDate.Sum(it => it.Quantity); + List channelStockEffDate = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId == singleChannels[i].MachineId) + .Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo) + .Where(cs => cs.ColNo == singleChannels[i].ColNo) + .Where(cs => cs.Quantity > 0) + .OrderBy(cs => cs.EffDate).ToList(); + int totalQuantity = channelStockEffDate.Sum(it => it.Quantity); - //将库位多批次的总库存数更新标签 - _portUtil.WriteQuantity(channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo, totalQuantity); - Thread.Sleep(200); - _portUtil.WriteChannelInfo(6, channelStockEffDate[0].EffDate == null ? "" : channelStockEffDate[0].EffDate, channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); - Thread.Sleep(200); - _portUtil.WriteChannelInfo(5, channelStockEffDate[0].ManuNo, channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); - Thread.Sleep(200); - _portUtil.ShowContent(channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); + //将库位多批次的总库存数更新标签 + _portUtil.WriteQuantity(channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo, totalQuantity); + Thread.Sleep(200); + _portUtil.WriteChannelInfo(6, channelStockEffDate[0].EffDate == null ? "" : channelStockEffDate[0].EffDate, channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); + Thread.Sleep(200); + _portUtil.WriteChannelInfo(5, channelStockEffDate[0].ManuNo, channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); + Thread.Sleep(200); + _portUtil.ShowContent(channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); //} } } @@ -664,6 +697,7 @@ namespace DM_Weight.ViewModels Type = MsgType.SUCCESS, }; _eventAggregator.GetEvent().Publish(alertMsg); + RequestData(); } if (!f.IsSuccess) { @@ -678,7 +712,6 @@ namespace DM_Weight.ViewModels _isFinishClick = false; } - RequestData(); }); } // 取消按钮 diff --git a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs index 358ec18..f6ba630 100644 --- a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs @@ -174,6 +174,7 @@ namespace DM_Weight.ViewModels orderDetails = SqlSugarHelper.Db.Queryable() .Includes(od => od.DrugInfo) .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (od, t) => od.DrugId == t.DrugId) + .Where(od=>od.DMStatus==0) .Where(od => od.OrderNo == OrderInfo.OrderNo) .ToList(); @@ -206,12 +207,14 @@ namespace DM_Weight.ViewModels ChannelStock stock = HasQChannels[j]; if (TakeQ > stock.Quantity) { + stock.OrderQuantity= orderDetail.Quantity; stock.TakeQuantity = stock.Quantity; channelStocks.Add(stock); TakeQ -= stock.Quantity; } else { + stock.OrderQuantity = orderDetail.Quantity; stock.TakeQuantity = TakeQ; channelStocks.Add(stock); TakeQ = 0; @@ -220,7 +223,16 @@ namespace DM_Weight.ViewModels } else { - msg.Add($"药品【{orderDetail.DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】"); + //msg.Add($"药品【{orderDetail.DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】"); + //数量不够就把全部数量取出 + for (int n = 0; n < HasQChannels.Count; n++) + { + ChannelStock stock = HasQChannels[n]; + stock.OrderQuantity = TakeQ; + stock.TakeQuantity = stock.Quantity; + channelStocks.Add(stock); + } + } } if (msg.Count > 0) @@ -332,17 +344,50 @@ namespace DM_Weight.ViewModels try { SqlSugarHelper.Db.BeginTran(); - logger.Info($"更新OrderInfo:{InvoiceId}"); - SqlSugarHelper.Db.Updateable(new OrderInfo() + //如果处方下全部药品都取完则更新orderInfo,order_detail中的dm_status + if (ChannelStocks.Sum(cs => cs.TakeQuantity) == ChannelStocks.Sum(cs => cs.OrderQuantity)) { - DmStatus = 1, - OrderNo = OrderInfo.OrderNo - }).UpdateColumns(it => new { it.DmStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand(); - + logger.Info($"更新OrderInfo:{InvoiceId}"); + SqlSugarHelper.Db.Updateable(new OrderInfo() + { + DmStatus = 1, + OrderNo = OrderInfo.OrderNo + }).UpdateColumns(it => new { it.DmStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable(new OrderDetail() + { + DMStatus = 1, + OrderNo = OrderInfo.OrderNo + }).UpdateColumns(it => new { it.DMStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand(); + } + logger.Info("进入record循环"); for (int i = 0; i < record.Count; i++) { + + ChannelStock it = record[i]; + //该药品下的所有取出数量 + int alTakeQuantity=record.Where(rd=>rd.DrugId==it.DrugId).Sum(rd=>rd.TakeQuantity); + //处方下某一个药品都取完则更新order_detail + if(it.OrderQuantity==it.TakeQuantity|| it.OrderQuantity == alTakeQuantity) + { + SqlSugarHelper.Db.Updateable(new OrderDetail() + { + DMStatus = 1, + OrderNo = OrderInfo.OrderNo, + DrugId= it.DrugId, + }).UpdateColumns(it => new { it.DMStatus }).WhereColumns(it => new { it.OrderNo,it.DrugId }).ExecuteCommand(); + } + else + { + //处方下某一个药品没有取完则更新order_detail中的取药数量(应取-已取) + SqlSugarHelper.Db.Updateable(new OrderDetail() + { + Quantity = it.OrderQuantity- alTakeQuantity, + OrderNo = OrderInfo.OrderNo, + DrugId = it.DrugId, + }).UpdateColumns(it => new { it.Quantity }).WhereColumns(it => new { it.OrderNo, it.DrugId }).ExecuteCommand(); + } logger.Info($"更新ChannelStock:{it.Id}"); // 更新数据 库存信息 diff --git a/DM_Weight/Views/Dialog/OrderTakeDialog.xaml b/DM_Weight/Views/Dialog/OrderTakeDialog.xaml index 651c5e2..4bc8eec 100644 --- a/DM_Weight/Views/Dialog/OrderTakeDialog.xaml +++ b/DM_Weight/Views/Dialog/OrderTakeDialog.xaml @@ -144,13 +144,6 @@ ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}" EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" /> - - + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/StockListWindow.xaml b/DM_Weight/Views/StockListWindow.xaml index 4004b4b..9ac0af2 100644 --- a/DM_Weight/Views/StockListWindow.xaml +++ b/DM_Weight/Views/StockListWindow.xaml @@ -22,6 +22,7 @@ --> + @@ -120,7 +121,9 @@ + +