From 25ec8fb290c53b764e99f1d888838d6f3ee15884 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Fri, 20 Sep 2024 11:26:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=B8=AA=E5=A4=84?= =?UTF-8?q?=E6=96=B9=E5=AF=B9=E5=BA=94=E5=A4=9A=E4=B8=AA=E8=8D=AF=E5=93=81?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheckOrderNewWindowViewModel.cs | 263 +++++++++--------- 1 file changed, 134 insertions(+), 129 deletions(-) diff --git a/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs index 5e7e533..aea5c09 100644 --- a/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs @@ -499,156 +499,161 @@ namespace DM_Weight.ViewModels //Expression> updateExp = it => it.ManuNo == oi._OrderDetail.SetManuNo && it.EffDate == oi._OrderDetail.SetEffDate; - 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) + for (int j = 0; j < oi.OrderDetailList.Count; j++) { - 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() + oi._OrderDetail = oi.OrderDetailList[j]; + 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+1).First(); + if (cs == null) { - 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(); + 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(); - #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 = new RejectionReport(); - rejectionReport.SendDate = SendMachineRecord.OperationTime; - rejectionReport.SendUser = SendMachineRecord.Operator.ToString(); - rejectionReport.ReceiveUser = retUser; - rejectionReport.RealNum = cs.BaseQuantity; + if (cs != null) + { - //还药信息 - rejectionReport.InfactNum = cs.BaseQuantity - oi._OrderDetail.Quantity; - rejectionReport.EmptyNum = oi._OrderDetail.Quantity; - rejectionReport.ReturnTime = DateTime.Now; - rejectionReport.ReturnUser = retUser; - rejectionReport.ReturnReceiveUser = SendMachineRecord.Operator.ToString(); - rejectionReport.DrugId = oi._OrderDetail.DrugId; - rejectionReport.DrugName = oi._OrderDetail.DrugInfo.DrugName; - rejectionReport.DrugSpec = oi._OrderDetail.DrugInfo.DrugSpec; + 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(); - rejectionReport.OperationTime = DateTime.Now; + #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 = new RejectionReport(); + rejectionReport.SendDate = SendMachineRecord.OperationTime; + rejectionReport.SendUser = SendMachineRecord.Operator.ToString(); + rejectionReport.ReceiveUser = retUser; + rejectionReport.RealNum = cs.BaseQuantity; - int iRejectionReport = SqlSugarHelper.Db.Insertable(rejectionReport).ExecuteCommand(); + //还药信息 + rejectionReport.InfactNum = cs.BaseQuantity - oi._OrderDetail.Quantity; + rejectionReport.EmptyNum = oi._OrderDetail.Quantity; + rejectionReport.ReturnTime = DateTime.Now; + rejectionReport.ReturnUser = retUser; + rejectionReport.ReturnReceiveUser = SendMachineRecord.Operator.ToString(); + rejectionReport.DrugId = oi._OrderDetail.DrugId; + rejectionReport.DrugName = oi._OrderDetail.DrugInfo.DrugName; + rejectionReport.DrugSpec = oi._OrderDetail.DrugInfo.DrugSpec; - #endregion + rejectionReport.OperationTime = DateTime.Now; - } - //保存账册 - 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 + int iRejectionReport = SqlSugarHelper.Db.Insertable(rejectionReport).ExecuteCommand(); - }).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() + #endregion + + } + //保存账册 + int iInsertResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() { DrugId = oi._OrderDetail.DrugId, - Type = 3, + Type = 2, + Department = oi.DeptName, + OrderNo = oi.OrderNo, ManuNo = cs.ManuNo, EffDate = cs.EffDate, - YQuantity = 0, - ManuStock = oi._OrderDetail.Quantity, - TotalStock = oi._OrderDetail.Quantity, + 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"), - InvoiceNo = "日结存" + CreateTime = DateTime.Now, + InvoiceNo = oi.OrderNo + }).ExecuteCommand(); - if (iDayResult <= 0) + //修改凌晨生成的日结存与总结存数据 + 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) { - logger.Info($"未写入日结存数据{oi._OrderDetail.DrugId}-{cs.ManuNo}-{cs.EffDate}-{cs.Quantity}"); + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - oi._OrderDetail.Quantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); } - } - //修改凌晨生成的日结存与总结存数据 - 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() + else { - 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}"); + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = oi._OrderDetail.DrugId, + Type = 3, + ManuNo = cs.ManuNo, + EffDate = cs.EffDate, + YQuantity = 0, + ManuStock = oi._OrderDetail.Quantity, + TotalStock = oi._OrderDetail.Quantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + InvoiceNo = "日结存" + }).ExecuteCommand(); + if (iDayResult <= 0) + { + logger.Info($"未写入日结存数据{oi._OrderDetail.DrugId}-{cs.ManuNo}-{cs.EffDate}-{cs.Quantity}"); + } } + //修改凌晨生成的日结存与总结存数据 + AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString())) + .Where(ab => ab.Type == 4) + .Where(ab => ab.DrugId == oi._OrderDetail.DrugId) + .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - oi._OrderDetail.Quantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = oi._OrderDetail.DrugId, + Type = 4, + YQuantity = 0, + ManuStock = oi._OrderDetail.Quantity, + TotalStock = oi._OrderDetail.Quantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + InvoiceNo = "总结存" + }).ExecuteCommand(); + if (iTotalResult <= 0) + { + logger.Info($"未写入总结存数据{oi._OrderDetail.DrugId}-{oi._OrderDetail.Quantity}"); + } + } + } } if (!string.IsNullOrEmpty(empChannelStock)) @@ -660,7 +665,7 @@ namespace DM_Weight.ViewModels }; _eventAggregator.GetEvent().Publish(alertMsg); logger.Info($"所选处方对应药品批次效期无库存{empChannelStock}"); - + return false; } return true; });