diff --git a/DM_Weight/App.config b/DM_Weight/App.config index 4e54c67..c7db2fb 100644 --- a/DM_Weight/App.config +++ b/DM_Weight/App.config @@ -37,7 +37,7 @@ - + diff --git a/DM_Weight/DM_Weight.csproj b/DM_Weight/DM_Weight.csproj index 7ff7ff6..4c2e17c 100644 --- a/DM_Weight/DM_Weight.csproj +++ b/DM_Weight/DM_Weight.csproj @@ -78,6 +78,7 @@ + diff --git a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs index ad587ec..03bfdeb 100644 --- a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs @@ -65,6 +65,8 @@ namespace DM_Weight.ViewModels { Status = 3; } + //保存库存 + SaveStock(); break; // 数量变化 case EventType.UPDATEQUANTITY: @@ -128,7 +130,7 @@ namespace DM_Weight.ViewModels if (HomeWindowViewModel.Operator.Role != null && HomeWindowViewModel.Operator.Role.RoleName != "管理员") { //查看当前用户是否有所在药品抽屉的权限;1-2层所有人能开,其他6层管理员才能开 - if (DrawerNo>3) + if (DrawerNo > 3) { AlertMsg alertMsg = new AlertMsg { @@ -178,198 +180,237 @@ namespace DM_Weight.ViewModels }, () => Status == 0).ObservesProperty(() => Status); } - private bool _isFinishClick = false; - - // 完成按钮 - public DelegateCommand TakeFinish + // private bool _isFinishClick = false; + //保存库存 + private void SaveStock() { - get => new DelegateCommand(() => + try { - if (!_isFinishClick) + List record = ChannelStocks.FindAll(it => it.AddQuantity != 0).ToList(); + if (record.Count > 0) { - _isFinishClick = true; - List record = ChannelStocks.FindAll(it => it.AddQuantity != 0).ToList(); - if (record.Count > 0) + string InvoiceId = "DRAWER_" + CurrentTimeMillis(); + var f = SqlSugarHelper.Db.UseTran(() => { - string InvoiceId = "DRAWER_" + CurrentTimeMillis(); - 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; - for (int i = 0; i < record.Count; i++) + + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() { - ChannelStock it = record[i]; - it.ManuNo = it.drugManuNo.ManuNo; - it.EffDate = it.drugManuNo.EffDate; - - - // 更新数据 库存信息 - 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(); - // 获取更新完库存后的药品库存 - 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, - Reviewer = HomeWindowViewModel.Reviewer?.Id, - OperationTime = DateTime.Now, - Quantity = it.AddQuantity, - Type = 1, - InvoiceId = InvoiceId - //,StockQuantity = nowChannels.Sum(it => it.Quantity) - }).ExecuteCommand(); - - - //保存账册 - SqlSugarHelper.Db.Insertable(new AccountBookG2() - { - DrugId = it.DrugId, - Type = 1, - Department = ConfigurationManager.AppSettings["department"].ToString(), - InvoiceNo = InvoiceId, - ManuNo = it.ManuNo, - EffDate = it.EffDate, - AddQuantity = it.AddQuantity, - UserId1 = HomeWindowViewModel.Operator?.Id, - UserId2 = HomeWindowViewModel.Reviewer?.Id, - MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), - CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - CreateTime = DateTime.Now - - }).ExecuteCommand(); - //修改凌晨生成的日结存数据 - AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() - .Where(ab => ab.MachineId.Equals(it.MachineId)) - .Where(ab => ab.Type == 3) - .Where(ab => ab.DrugId == it.DrugId) - .Where(ab => ab.ManuNo == it.ManuNo) - .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - if (accountBookG2Day != null) - { - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - } - else - { - //生成日结存时可能没有该库位的绑定信息,需要写入日结存 - int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() - { - DrugId = it.DrugId, - Type = 3, - ManuNo = it.ManuNo, - EffDate = it.EffDate, - YQuantity = 0, - ManuStock = it.AddQuantity, - TotalStock = it.AddQuantity, - UserId1 = HomeWindowViewModel.Operator?.Id, - UserId2 = HomeWindowViewModel.Reviewer?.Id, - MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), - CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - InvoiceNo = "日结存" - }).ExecuteCommand(); - if (iDayResult <= 0) - { - logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}"); - } - } - //修改凌晨生成的总结存数据 - AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() - .Where(ab => ab.MachineId.Equals(it.MachineId)) - .Where(ab => ab.Type == 4) - .Where(ab => ab.DrugId == it.DrugId) - .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - if (accountBookG2Total != null) - { - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.AddQuantity; - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); - } - else - { - //生成总结存时可能没有该库位的绑定信息,需要写入总结存 - int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() - { - DrugId = it.DrugId, - Type = 4, - YQuantity = 0, - ManuStock = it.AddQuantity, - TotalStock = it.AddQuantity, - UserId1 = HomeWindowViewModel.Operator?.Id, - UserId2 = HomeWindowViewModel.Reviewer?.Id, - MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), - CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - InvoiceNo = "总结存" - }).ExecuteCommand(); - if (iTotalResult <= 0) - { - logger.Info($"未写入总结存数据{it.DrugId}-{it.AddQuantity}"); - } - } - } - return true; - }); - if (f.Data) - { - RequestData(); - AlertMsg alertMsg = new AlertMsg - { - Message = "抽屉加药完成,库存已更新", - Type = MsgType.SUCCESS, - }; - _eventAggregator.GetEvent().Publish(alertMsg); + Quantity = it.Quantity + it.AddQuantity, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + Id = it.Id, + }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); + + logger.Info($"库存已更新{it.DrugId},{it.Quantity+it.AddQuantity}"); } - else - { - AlertMsg alertMsg = new AlertMsg - { - Message = "更新库存失败", - Type = MsgType.SUCCESS, - }; - _eventAggregator.GetEvent().Publish(alertMsg); - } - Status = 0; - _isFinishClick = false; - } - else - { - _isFinishClick = false; - AlertMsg alertMsg = new AlertMsg - { - Message = "没有填写加药数量", - Type = MsgType.ERROR - }; - _eventAggregator.GetEvent().Publish(alertMsg); - } - + }); + RequestData(); + Status = 0; } - - }); - } - - // 取消按钮 - public DelegateCommand CancleTake - { - get => new DelegateCommand(() => + } + catch (Exception ex) { - _portUtil.ResetData(); - Status = 0; - }); + logger.Info($"保存库存异常{ex.Message}"); + } } + //// 完成按钮 + //public DelegateCommand TakeFinish + //{ + // get => new DelegateCommand(() => + // { + // if (!_isFinishClick) + // { + // _isFinishClick = true; + // List record = ChannelStocks.FindAll(it => it.AddQuantity != 0).ToList(); + // if (record.Count > 0) + // { + // string InvoiceId = "DRAWER_" + CurrentTimeMillis(); + // 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; + + + // // 更新数据 库存信息 + // 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(); + // // 获取更新完库存后的药品库存 + // 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, + // Reviewer = HomeWindowViewModel.Reviewer?.Id, + // OperationTime = DateTime.Now, + // Quantity = it.AddQuantity, + // Type = 1, + // InvoiceId = InvoiceId + // //,StockQuantity = nowChannels.Sum(it => it.Quantity) + // }).ExecuteCommand(); + + + // //保存账册 + // SqlSugarHelper.Db.Insertable(new AccountBookG2() + // { + // DrugId = it.DrugId, + // Type = 1, + // Department = ConfigurationManager.AppSettings["department"].ToString(), + // InvoiceNo = InvoiceId, + // ManuNo = it.ManuNo, + // EffDate = it.EffDate, + // AddQuantity = it.AddQuantity, + // UserId1 = HomeWindowViewModel.Operator?.Id, + // UserId2 = HomeWindowViewModel.Reviewer?.Id, + // MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + // CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + // CreateTime = DateTime.Now + + // }).ExecuteCommand(); + // //修改凌晨生成的日结存数据 + // AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() + // .Where(ab => ab.MachineId.Equals(it.MachineId)) + // .Where(ab => ab.Type == 3) + // .Where(ab => ab.DrugId == it.DrugId) + // .Where(ab => ab.ManuNo == it.ManuNo) + // .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + // if (accountBookG2Day != null) + // { + // accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; + // SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + // } + // else + // { + // //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + // int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + // { + // DrugId = it.DrugId, + // Type = 3, + // ManuNo = it.ManuNo, + // EffDate = it.EffDate, + // YQuantity = 0, + // ManuStock = it.AddQuantity, + // TotalStock = it.AddQuantity, + // UserId1 = HomeWindowViewModel.Operator?.Id, + // UserId2 = HomeWindowViewModel.Reviewer?.Id, + // MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + // CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + // InvoiceNo = "日结存" + // }).ExecuteCommand(); + // if (iDayResult <= 0) + // { + // logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}"); + // } + // } + // //修改凌晨生成的总结存数据 + // AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() + // .Where(ab => ab.MachineId.Equals(it.MachineId)) + // .Where(ab => ab.Type == 4) + // .Where(ab => ab.DrugId == it.DrugId) + // .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + // if (accountBookG2Total != null) + // { + // accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.AddQuantity; + // SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + // } + // else + // { + // //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + // int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + // { + // DrugId = it.DrugId, + // Type = 4, + // YQuantity = 0, + // ManuStock = it.AddQuantity, + // TotalStock = it.AddQuantity, + // UserId1 = HomeWindowViewModel.Operator?.Id, + // UserId2 = HomeWindowViewModel.Reviewer?.Id, + // MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + // CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + // InvoiceNo = "总结存" + // }).ExecuteCommand(); + // if (iTotalResult <= 0) + // { + // logger.Info($"未写入总结存数据{it.DrugId}-{it.AddQuantity}"); + // } + // } + // } + // return true; + // }); + // if (f.Data) + // { + // RequestData(); + // AlertMsg alertMsg = new AlertMsg + // { + // Message = "抽屉加药完成,库存已更新", + // Type = MsgType.SUCCESS, + // }; + // _eventAggregator.GetEvent().Publish(alertMsg); + // } + // else + // { + // AlertMsg alertMsg = new AlertMsg + // { + // Message = "更新库存失败", + // Type = MsgType.SUCCESS, + // }; + // _eventAggregator.GetEvent().Publish(alertMsg); + // } + // Status = 0; + // _isFinishClick = false; + // } + // 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 long CurrentTimeMillis() { diff --git a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs index e97606e..07beddd 100644 --- a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs @@ -70,7 +70,9 @@ namespace DM_Weight.ViewModels if (Status == 2) { Status = 3; - } + } + //保存库存 + SaveStock(); break; // 数量变化 case EventType.UPDATEQUANTITY: @@ -178,200 +180,240 @@ namespace DM_Weight.ViewModels }); } - private bool _isFinishClick = false; - - // 完成按钮 - public DelegateCommand TakeFinish + //保存库存 + private void SaveStock() { - get => new DelegateCommand(() => + try { - if (!_isFinishClick) + List record = ChannelStocks.FindAll(it => it.TakeQuantity != 0).ToList(); + if (record.Count > 0) { - _isFinishClick = true; - List record = ChannelStocks.FindAll(it => it.TakeQuantity != 0).ToList(); - logger.Info("点击完成按钮,库位数据:" + JsonConvert.SerializeObject(record)); - if (record.Count > 0) + string InvoiceId = "DRAWER_" + CurrentTimeMillis(); + var f = SqlSugarHelper.Db.UseTran(() => { - string InvoiceId = "DRAWER_" + CurrentTimeMillis(); - var f = SqlSugarHelper.Db.UseTran(() => + + for (int i = 0; i < record.Count; i++) { + ChannelStock it = record[i]; + it.ManuNo = it.ManuNo; + it.EffDate = it.EffDate; - for (int i = 0; i < record.Count; i++) + + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() { - ChannelStock it = record[i]; + Quantity = it.Quantity - it.TakeQuantity, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + Id = it.Id, + }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); - - // 更新数据 库存信息 - SqlSugarHelper.Db.Updateable(new ChannelStock() - { - Quantity = it.Quantity - it.TakeQuantity, - ManuNo = it.ManuNo, - EffDate = it.EffDate, - Id = it.Id, - }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).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, - Reviewer = HomeWindowViewModel.Reviewer?.Id, - OperationTime = DateTime.Now, - Quantity = it.TakeQuantity, - Type = 2, - InvoiceId = InvoiceId - //,StockQuantity = nowChannels.Sum(it => it.Quantity) - }).ExecuteCommand(); - - - //保存账册 - SqlSugarHelper.Db.Insertable(new AccountBookG2() - { - DrugId = it.DrugId, - Type = 2, - Department = ConfigurationManager.AppSettings["department"].ToString(), - InvoiceNo = InvoiceId, - ManuNo = it.ManuNo, - EffDate = it.EffDate, - OutQuantity = it.TakeQuantity, - UserId1 = HomeWindowViewModel.Operator?.Id, - UserId2 = HomeWindowViewModel.Reviewer?.Id, - MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), - CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - CreateTime = DateTime.Now - - }).ExecuteCommand(); - //修改凌晨生成的日结存数据 - AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() - .Where(ab => ab.MachineId.Equals(it.MachineId)) - .Where(ab => ab.Type == 3) - .Where(ab => ab.DrugId == it.DrugId) - .Where(ab => ab.ManuNo == it.ManuNo) - .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - if (accountBookG2Day != null) - { - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - } - else - { - //生成日结存时可能没有该库位的绑定信息,需要写入日结存 - int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() - { - DrugId = it.DrugId, - Type = 3, - ManuNo = it.ManuNo, - EffDate = it.EffDate, - YQuantity = 0, - ManuStock = it.TakeQuantity, - TotalStock = it.TakeQuantity, - UserId1 = HomeWindowViewModel.Operator?.Id, - UserId2 = HomeWindowViewModel.Reviewer?.Id, - MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), - CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - InvoiceNo = "日结存" - }).ExecuteCommand(); - if (iDayResult <= 0) - { - logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}"); - } - } - //修改凌晨生成的总结存数据 - AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() - .Where(ab => ab.MachineId.Equals(it.MachineId)) - .Where(ab => ab.Type == 4) - .Where(ab => ab.DrugId == it.DrugId) - .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - if (accountBookG2Total != null) - { - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - it.TakeQuantity; - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); - } - else - { - //生成总结存时可能没有该库位的绑定信息,需要写入总结存 - int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() - { - DrugId = it.DrugId, - Type = 4, - YQuantity = 0, - ManuStock = it.TakeQuantity, - TotalStock = it.TakeQuantity, - UserId1 = HomeWindowViewModel.Operator?.Id, - UserId2 = HomeWindowViewModel.Reviewer?.Id, - MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), - CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - InvoiceNo = "总结存" - }).ExecuteCommand(); - if (iTotalResult <= 0) - { - logger.Info($"未写入总结存数据{it.DrugId}-{it.AddQuantity}"); - } - } - - - logger.Info($"抽屉取药保存->库位【{it.DrawerNo}-{it.ColNo}】取出药品【{it.DrugInfo.DrugName}】个数【{it.TakeQuantity}】,取药前库存【{it.Quantity}】"); - } - return true; - }); - if (f.Data) - { - RequestData(); - AlertMsg alertMsg = new AlertMsg - { - Message = "抽屉取药完成,库存已更新", - Type = MsgType.SUCCESS, - }; - _eventAggregator.GetEvent().Publish(alertMsg); + logger.Info($"库存已更新{it.DrugId},{it.Quantity - it.TakeQuantity}"); } - if (!f.IsSuccess) - { - AlertMsg alertMsg = new AlertMsg - { - Message = "抽屉取药完成,库存更新失败!", - Type = MsgType.ERROR, - }; - _eventAggregator.GetEvent().Publish(alertMsg); - } - Status = 0; - _isFinishClick = false; - } - else - { - _isFinishClick = false; - AlertMsg alertMsg = new AlertMsg - { - Message = "没有填写取药数量", - Type = MsgType.ERROR - }; - _eventAggregator.GetEvent().Publish(alertMsg); - } - + }); + RequestData(); + Status = 0; } - - }); - } - - // 取消按钮 - public DelegateCommand CancleTake - { - get => new DelegateCommand(() => + } + catch (Exception ex) { - _portUtil.ResetData(); - Status = 0; - }); + logger.Info($"保存库存异常{ex.Message}"); + } } + //private bool _isFinishClick = false; + + //// 完成按钮 + //public DelegateCommand TakeFinish + //{ + // get => new DelegateCommand(() => + // { + // if (!_isFinishClick) + // { + // _isFinishClick = true; + // List record = ChannelStocks.FindAll(it => it.TakeQuantity != 0).ToList(); + // logger.Info("点击完成按钮,库位数据:" + JsonConvert.SerializeObject(record)); + // if (record.Count > 0) + // { + // string InvoiceId = "DRAWER_" + CurrentTimeMillis(); + // var f = SqlSugarHelper.Db.UseTran(() => + // { + + // for (int i = 0; i < record.Count; i++) + // { + // ChannelStock it = record[i]; + + + // // 更新数据 库存信息 + // SqlSugarHelper.Db.Updateable(new ChannelStock() + // { + // Quantity = it.Quantity - it.TakeQuantity, + // ManuNo = it.ManuNo, + // EffDate = it.EffDate, + // Id = it.Id, + // }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).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, + // Reviewer = HomeWindowViewModel.Reviewer?.Id, + // OperationTime = DateTime.Now, + // Quantity = it.TakeQuantity, + // Type = 2, + // InvoiceId = InvoiceId + // //,StockQuantity = nowChannels.Sum(it => it.Quantity) + // }).ExecuteCommand(); + + + // //保存账册 + // SqlSugarHelper.Db.Insertable(new AccountBookG2() + // { + // DrugId = it.DrugId, + // Type = 2, + // Department = ConfigurationManager.AppSettings["department"].ToString(), + // InvoiceNo = InvoiceId, + // ManuNo = it.ManuNo, + // EffDate = it.EffDate, + // OutQuantity = it.TakeQuantity, + // UserId1 = HomeWindowViewModel.Operator?.Id, + // UserId2 = HomeWindowViewModel.Reviewer?.Id, + // MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + // CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + // CreateTime = DateTime.Now + + // }).ExecuteCommand(); + // //修改凌晨生成的日结存数据 + // AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() + // .Where(ab => ab.MachineId.Equals(it.MachineId)) + // .Where(ab => ab.Type == 3) + // .Where(ab => ab.DrugId == it.DrugId) + // .Where(ab => ab.ManuNo == it.ManuNo) + // .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + // if (accountBookG2Day != null) + // { + // accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; + // SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + // } + // else + // { + // //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + // int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + // { + // DrugId = it.DrugId, + // Type = 3, + // ManuNo = it.ManuNo, + // EffDate = it.EffDate, + // YQuantity = 0, + // ManuStock = it.TakeQuantity, + // TotalStock = it.TakeQuantity, + // UserId1 = HomeWindowViewModel.Operator?.Id, + // UserId2 = HomeWindowViewModel.Reviewer?.Id, + // MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + // CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + // InvoiceNo = "日结存" + // }).ExecuteCommand(); + // if (iDayResult <= 0) + // { + // logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}"); + // } + // } + // //修改凌晨生成的总结存数据 + // AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() + // .Where(ab => ab.MachineId.Equals(it.MachineId)) + // .Where(ab => ab.Type == 4) + // .Where(ab => ab.DrugId == it.DrugId) + // .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + // if (accountBookG2Total != null) + // { + // accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - it.TakeQuantity; + // SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + // } + // else + // { + // //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + // int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + // { + // DrugId = it.DrugId, + // Type = 4, + // YQuantity = 0, + // ManuStock = it.TakeQuantity, + // TotalStock = it.TakeQuantity, + // UserId1 = HomeWindowViewModel.Operator?.Id, + // UserId2 = HomeWindowViewModel.Reviewer?.Id, + // MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + // CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + // InvoiceNo = "总结存" + // }).ExecuteCommand(); + // if (iTotalResult <= 0) + // { + // logger.Info($"未写入总结存数据{it.DrugId}-{it.AddQuantity}"); + // } + // } + + + // logger.Info($"抽屉取药保存->库位【{it.DrawerNo}-{it.ColNo}】取出药品【{it.DrugInfo.DrugName}】个数【{it.TakeQuantity}】,取药前库存【{it.Quantity}】"); + // } + // return true; + // }); + // if (f.Data) + // { + // RequestData(); + // AlertMsg alertMsg = new AlertMsg + // { + // Message = "抽屉取药完成,库存已更新", + // Type = MsgType.SUCCESS, + // }; + // _eventAggregator.GetEvent().Publish(alertMsg); + // } + // if (!f.IsSuccess) + // { + // AlertMsg alertMsg = new AlertMsg + // { + // Message = "抽屉取药完成,库存更新失败!", + // Type = MsgType.ERROR, + // }; + // _eventAggregator.GetEvent().Publish(alertMsg); + // } + // Status = 0; + // _isFinishClick = false; + // } + // 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 long CurrentTimeMillis() { diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs index 48c8555..bc47171 100644 --- a/DM_Weight/ViewModels/HomeWindowViewModel.cs +++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs @@ -536,35 +536,85 @@ namespace DM_Weight.ViewModels SelectedChildMenu = premissions[0].Children[0]; _regionManager.RequestNavigate("ContentRegion", premissions[0].Children[0].PremissionPath); FindDrawerCount(); - int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0"); - int stopRecord = Convert.ToInt32(ConfigurationManager.AppSettings["stopRecord"] ?? "0"); if (autoExit > 0) { - System.Timers.Timer timer = new System.Timers.Timer(); - timer.Interval = 1000; - timer.Elapsed += (sender, e) => + //int interval = autoExit * 1000; + new PromiseUtil().taskAsyncLoop(1000, 0, async (options, next, stop) => { - // 串口无人操作 - if (!_portUtil.Operate) + try { - // 30秒内无人操作鼠标键盘 - if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit) + if (!_portUtil.Operate) { - logger.Info($"设备30秒内无人操作,用户【{Operator?.Nickname}】自动退出登录"); - //_chkFunction.HIKStopDVRRecord(); - Operator = null; - Reviewer = null; - Application.Current.Dispatcher.Invoke(() => + // 无人操作鼠标键盘 + if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit) { - _regionManager.RequestNavigate("MainRegion", "LoginWindow"); - timer.Stop(); - }); + logger.Info($"设备30秒内无人操作,用户【{Operator?.Nickname}】自动退出登录,_portUtil.Operate:{_portUtil.Operate},totalSecond:{(DateTime.Now - _portUtil.dateTime).TotalSeconds},lastInputTime:{CheckComputerFreeState.GetLastInputTime()},autoExit:{autoExit}"); + + Operator = null; + Reviewer = null; + //Application.Current.Dispatcher.Invoke(() => + //{ + stop(); + System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => + { + _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + })); + //}); + //timer.Dispose(); + } + else + { + if (Operator == null) + { + stop(); + } + else + { + next(); + } + } + } + else + { + _portUtil.dateTime = DateTime.Now; + next(); } } - }; - timer.Start(); + catch (Exception ex) + { + logger.Info($"自动退出异常:{ex.Message}"); + } + }); } + //int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0"); + //int stopRecord = Convert.ToInt32(ConfigurationManager.AppSettings["stopRecord"] ?? "0"); + //if (autoExit > 0) + //{ + // System.Timers.Timer timer = new System.Timers.Timer(); + // timer.Interval = 1000; + // timer.Elapsed += (sender, e) => + // { + // // 串口无人操作 + // if (!_portUtil.Operate) + // { + // // 30秒内无人操作鼠标键盘 + // if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit) + // { + // logger.Info($"设备30秒内无人操作,用户【{Operator?.Nickname}】自动退出登录,_portUtil.Operate:{_portUtil.Operate},totalSecond:{(DateTime.Now - _portUtil.dateTime).TotalSeconds},lastInputTime:{CheckComputerFreeState.GetLastInputTime()},autoExit:{autoExit}"); + // //_chkFunction.HIKStopDVRRecord(); + // Operator = null; + // Reviewer = null; + // Application.Current.Dispatcher.Invoke(() => + // { + // _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + // timer.Stop(); + // }); + // } + // } + // }; + // timer.Start(); + //} //#region 温度查询定时 //int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]); //if (interval > 0) diff --git a/DM_Weight/Views/DrawerAddDrugWindow.xaml b/DM_Weight/Views/DrawerAddDrugWindow.xaml index 410fee2..e9dc3aa 100644 --- a/DM_Weight/Views/DrawerAddDrugWindow.xaml +++ b/DM_Weight/Views/DrawerAddDrugWindow.xaml @@ -159,7 +159,7 @@ materialDesign:ButtonProgressAssist.IsIndeterminate="{Binding Status, Converter={StaticResource StatusConverter}, ConverterParameter=opearBtnLoading}" Style="{StaticResource MaterialDesignOutlinedLightButton}" Content="加药" /> -