From 8fe17f7517ff8efb769966364219e8159a63e5e5 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Sat, 6 Jul 2024 10:25:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=8C=E6=99=A8=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=9A=84=E6=80=BB=E7=BB=93=E5=AD=98=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=88=99=E5=86=99=E5=85=A5=E4=B8=80=E6=9D=A1=E3=80=82?= =?UTF-8?q?=EF=BC=88=E5=87=8C=E6=99=A8=E7=94=9F=E6=88=90=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=97=B6=E6=B2=A1=E6=9C=89=E7=BB=91=E5=AE=9A=E5=BA=93=E4=BD=8D?= =?UTF-8?q?=E7=9A=84=E5=88=99=E4=B8=8D=E4=BC=9A=E7=94=9F=E6=88=90=EF=BC=8C?= =?UTF-8?q?=E5=BD=93=E5=A4=A9=E7=BB=91=E5=AE=9A=E5=BA=93=E4=BD=8D=E4=B8=94?= =?UTF-8?q?=E5=81=9A=E5=BA=93=E4=BD=8D=E6=93=8D=E4=BD=9C=E6=97=B6=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=89=8B=E5=8A=A8=E5=86=99=E5=85=A5=E4=B8=80=E6=9D=A1?= =?UTF-8?q?=E6=97=A5=E7=BB=93=E5=AD=98=E3=80=81=E6=80=BB=E7=BB=93=E5=AD=98?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/ApplyInStockWindowViewModel.cs | 65 +++++++++-- .../ViewModels/ApplyListWindowViewModel.cs | 1 + .../ViewModels/DestoryEmptyDialogViewModel.cs | 9 ++ .../DrawerAddDrugWindowViewModel.cs | 69 ++++++++++-- .../DrawerTakeDrugWindowViewModel.cs | 64 +++++++++-- .../ViewModels/InvoiceAddDialogViewModel.cs | 62 +++++++++-- .../ViewModels/InvoiceTakeDialogViewModel.cs | 72 +++++++++--- .../ViewModels/OrderReturnDialogViewModel.cs | 62 +++++++++-- .../ViewModels/OrderTakeDialogViewModel.cs | 102 ++++++++++++----- .../ViewModels/ReturnDrugDialogViewModel.cs | 104 +++++++++++++----- .../ViewModels/SelfAddDialogViewModel.cs | 72 ++++++++++-- .../ViewModels/SelfTakeDialogViewModel.cs | 62 +++++++++-- 12 files changed, 607 insertions(+), 137 deletions(-) diff --git a/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs b/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs index 261b93a..65e6475 100644 --- a/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs +++ b/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs @@ -330,7 +330,7 @@ namespace DM_Weight.ViewModels { if (SelectDrugPleaseClaim.GetQuantity == 1) { - if(SelectDrugPleaseClaim.DrugManuNo is null) + if (SelectDrugPleaseClaim.DrugManuNo is null) { AlertMsg alertMsg = new AlertMsg { @@ -359,7 +359,7 @@ namespace DM_Weight.ViewModels .OrderBy(cs => cs.DrawerNo) .OrderBy(cs => cs.ColNo) .First(); - if(q is null) + if (q is null) { AlertMsg alertMsg = new AlertMsg { @@ -655,7 +655,7 @@ namespace DM_Weight.ViewModels UserId2 = HomeWindowViewModel.Reviewer?.Id, MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - CreateTime = DateTime.Now, + //CreateTime = DateTime.Now, InvoiceNo = SelectDrugPleaseClaim.PleaseNo }).ExecuteCommand(); @@ -667,7 +667,33 @@ namespace DM_Weight.ViewModels .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() { + DrugId = Convert.ToInt32(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() @@ -675,12 +701,33 @@ namespace DM_Weight.ViewModels .Where(ab => ab.Type == 4) .Where(ab => ab.DrugId == Convert.ToInt32(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 = Convert.ToInt32(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}"); + } + } - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.AddQuantity; - - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); } return true; diff --git a/DM_Weight/ViewModels/ApplyListWindowViewModel.cs b/DM_Weight/ViewModels/ApplyListWindowViewModel.cs index f4a7455..0469b63 100644 --- a/DM_Weight/ViewModels/ApplyListWindowViewModel.cs +++ b/DM_Weight/ViewModels/ApplyListWindowViewModel.cs @@ -150,6 +150,7 @@ namespace DM_Weight.ViewModels .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cd) => cd.drugInfo.PyCode.Contains(SearchValue)) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cd) => cd.drugInfo.DrugBarcode.Contains(SearchValue)) .WhereIF((_DrugPleaseState!=null&& _DrugPleaseState.StateValue>=0),(cd,dp)=>dp.State==_DrugPleaseState.StateValue) + .GroupBy(cd=>cd.Applyid) .OrderByDescending(cd => cd.Createdate) .OrderByDescending(cd => cd.DrugId) .ToList(); diff --git a/DM_Weight/ViewModels/DestoryEmptyDialogViewModel.cs b/DM_Weight/ViewModels/DestoryEmptyDialogViewModel.cs index 399ac0e..42c43d8 100644 --- a/DM_Weight/ViewModels/DestoryEmptyDialogViewModel.cs +++ b/DM_Weight/ViewModels/DestoryEmptyDialogViewModel.cs @@ -195,6 +195,15 @@ namespace DM_Weight.ViewModels _eventAggregator.GetEvent().Publish(alertMsg); } } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "请选择要销毁的数据", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } }); } diff --git a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs index 04bd2ce..90263bd 100644 --- a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs @@ -198,7 +198,7 @@ namespace DM_Weight.ViewModels 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, + Reviewer = HomeWindowViewModel.Reviewer?.Id, OperationTime = DateTime.Now, Quantity = it.AddQuantity, Type = 1, @@ -231,21 +231,66 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == Convert.ToInt32(it.DrugId)) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; - + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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 == Convert.ToInt32(it.DrugId)) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.AddQuantity; - - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); - + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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; }); @@ -312,10 +357,10 @@ namespace DM_Weight.ViewModels .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; diff --git a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs index ae57516..50b9dee 100644 --- a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs @@ -233,22 +233,66 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == Convert.ToInt32(it.DrugId)) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; - + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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 == Convert.ToInt32(it.DrugId)) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - it.TakeQuantity; - - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); - - + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - it.TakeQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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}】"); diff --git a/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs b/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs index 2377880..37e6a99 100644 --- a/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs @@ -304,20 +304,66 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == Convert.ToInt32(it.DrugId)) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; - + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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 == Convert.ToInt32(it.DrugId)) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.AddQuantity; - - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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; }); diff --git a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs index 08cdf6d..cb0a1be 100644 --- a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs @@ -60,7 +60,7 @@ namespace DM_Weight.ViewModels // 抽屉打开 case EventType.DRAWEROPEN: - + if (Status == 1) { if (channelStocks[0].process == 1) @@ -144,7 +144,7 @@ namespace DM_Weight.ViewModels get => _channelStocks; set => SetProperty(ref _channelStocks, value); } - + private IEnumerable> enumerable; private IEnumerator> enumerator; @@ -172,7 +172,7 @@ namespace DM_Weight.ViewModels { invoices = SqlSugarHelper.Db.Queryable() .Includes(i => i.DrugInfo) - .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs =>cs.DrugId),(i,t) => i.DrugId == t.DrugId) + .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (i, t) => i.DrugId == t.DrugId) .Where(i => i.InvoiceNo == Invoice.InvoiceNo) .ToList(); @@ -219,7 +219,7 @@ namespace DM_Weight.ViewModels msg.Add($"药品【{invoice.DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】"); } } - if(msg.Count > 0) + if (msg.Count > 0) { RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); //MessageBox.Show(string.Join("\n", msg)); @@ -256,7 +256,7 @@ namespace DM_Weight.ViewModels Status = 1; OpenOneByOne(); } - + }); } @@ -367,20 +367,66 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == Convert.ToInt32(it.DrugId)) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; - + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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 == Convert.ToInt32(it.DrugId)) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - it.TakeQuantity; - - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - it.TakeQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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}"); + } + } } return true; diff --git a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs index c1c22ed..21e37f0 100644 --- a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs @@ -362,20 +362,66 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == Convert.ToInt32(it.DrugId)) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.ReturnQuantity; - + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.ReturnQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(it.DrugId), + Type = 3, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + YQuantity = 0, + ManuStock = it.ReturnQuantity, + TotalStock = it.ReturnQuantity, + 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 == Convert.ToInt32(it.DrugId)) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.ReturnQuantity; - - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.ReturnQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(it.DrugId), + Type = 4, + YQuantity = 0, + ManuStock = it.ReturnQuantity, + TotalStock = it.ReturnQuantity, + 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; }); diff --git a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs index 7ddc326..0b31572 100644 --- a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs @@ -66,7 +66,7 @@ namespace DM_Weight.ViewModels channelStocks.ForEach(it => it.process = 2); } } - + break; // 抽屉关闭 case EventType.DRAWERCLOSE: @@ -224,7 +224,7 @@ namespace DM_Weight.ViewModels DialogParameters dialogParameters = new DialogParameters(); dialogParameters.Add("msgInfo", msg); DialogServiceExtensions.ShowDialogHost(_dialogService, "ShowMessageDialog", dialogParameters, "RootDialog"); - + } else { @@ -361,44 +361,90 @@ namespace DM_Weight.ViewModels }).ExecuteCommand(); //保存账册 - int iInsertResult= SqlSugarHelper.Db.Insertable(new AccountBookG2() { + int iInsertResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { DrugId = Convert.ToInt32(it.DrugId), - Type= 2, - Department= OrderInfo.DeptName, - OrderNo=OrderInfo.OrderNo, - ManuNo=it.ManuNo, - EffDate=it.EffDate, - OutQuantity=it.TakeQuantity, + Type = 2, + Department = OrderInfo.DeptName, + OrderNo = OrderInfo.OrderNo, + 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"), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), CreateTime = DateTime.Now, - InvoiceNo=OrderInfo.OrderNo + InvoiceNo = OrderInfo.OrderNo }).ExecuteCommand(); //修改凌晨生成的日结存与总结存数据 - AccountBookG2 accountBookG2Day= SqlSugarHelper.Db.Queryable() - .Where(ab=>ab.MachineId.Equals(it.MachineId)) - .Where(ab=>ab.Type==3) - .Where(ab=>ab.DrugId==Convert.ToInt32(it.DrugId)) - .Where(ab=>ab.ManuNo==it.ManuNo) - .Where(ab=>ab.CreateDate==DateTime.Now.ToString("yyyy-MM-dd")).First(); - - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; - + AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(it.MachineId)) + .Where(ab => ab.Type == 3) + .Where(ab => ab.DrugId == Convert.ToInt32(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 = Convert.ToInt32(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==Convert.ToInt32(it.DrugId)) + .Where(ab => ab.DrugId == Convert.ToInt32(it.DrugId)) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - - accountBookG2Total.TotalStock= accountBookG2Total.TotalStock -it.TakeQuantity; - - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - it.TakeQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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}"); + } + } } return true; @@ -422,7 +468,7 @@ namespace DM_Weight.ViewModels }; _eventAggregator.GetEvent().Publish(alertMsg); } - if(!f.IsSuccess) + if (!f.IsSuccess) { AlertMsg alertMsg = new AlertMsg { diff --git a/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs index cbee016..de3da3e 100644 --- a/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs +++ b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs @@ -88,7 +88,7 @@ namespace DM_Weight.ViewModels { logger.Error(e); } - + break; // 打开失败 case EventType.OPENERROR: @@ -176,12 +176,12 @@ namespace DM_Weight.ViewModels List queryData = SqlSugarHelper.Db.Queryable() .Where(cs => cs.DrugId == MachineRecord.DrugId) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) - .WhereIF(MachineRecord.ManuNo != null,cs => cs.ManuNo == MachineRecord.ManuNo) + .WhereIF(MachineRecord.ManuNo != null, cs => cs.ManuNo == MachineRecord.ManuNo) .OrderBy(cs => cs.DrawerNo) .OrderBy(cs => cs.ColNo) .ToList(); ChannelStocks = queryData; - if(ChannelStocks.Count > 0) + if (ChannelStocks.Count > 0) { ChannelStock = ChannelStocks[0]; } @@ -202,7 +202,8 @@ namespace DM_Weight.ViewModels _portUtil.ColNos = new int[] { ChannelStock.ColNo }; _portUtil.DrawerNo = ChannelStock.DrawerNo; _portUtil.Start(); - } else + } + else { AlertMsg alertMsg = new AlertMsg { @@ -228,7 +229,7 @@ namespace DM_Weight.ViewModels string InvoiceId = "RETURN_" + CurrentTimeMillis(); var f = SqlSugarHelper.Db.UseTran(() => { - + // 更新数据 库存信息 SqlSugarHelper.Db.Updateable(new ChannelStock() { @@ -252,21 +253,21 @@ namespace DM_Weight.ViewModels // 保存数据 还药记录 SqlSugarHelper.Db.Insertable(new MachineRecord() - { - MachineId = ChannelStock.MachineId, - DrawerNo = ChannelStock.DrawerNo, - ColNo = ChannelStock.ColNo, - DrugId = ChannelStock.DrugId, - ManuNo = ChannelStock.ManuNo, - EffDate = !String.IsNullOrEmpty(ChannelStock.EffDate) ? DateTime.ParseExact(ChannelStock.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, - Operator = HomeWindowViewModel.Operator?.Id, - OperationTime = DateTime.Now, - Quantity = ReturnQuantity, - Type = 31, - InvoiceId = InvoiceId, - GetId = MachineRecord.Id - //,StockQuantity = nowChannels.Sum(it => it.Quantity) - }).ExecuteCommand(); + { + MachineId = ChannelStock.MachineId, + DrawerNo = ChannelStock.DrawerNo, + ColNo = ChannelStock.ColNo, + DrugId = ChannelStock.DrugId, + ManuNo = ChannelStock.ManuNo, + EffDate = !String.IsNullOrEmpty(ChannelStock.EffDate) ? DateTime.ParseExact(ChannelStock.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + OperationTime = DateTime.Now, + Quantity = ReturnQuantity, + Type = 31, + InvoiceId = InvoiceId, + GetId = MachineRecord.Id + //,StockQuantity = nowChannels.Sum(it => it.Quantity) + }).ExecuteCommand(); //保存账册 SqlSugarHelper.Db.Insertable(new AccountBookG2() @@ -292,21 +293,66 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == Convert.ToInt32(ChannelStock.DrugId)) .Where(ab => ab.ManuNo == ChannelStock.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + ChannelStock.ReturnQuantity; - + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + ChannelStock.ReturnQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(ChannelStock.DrugId), + Type = 3, + ManuNo = ChannelStock.ManuNo, + EffDate = ChannelStock.EffDate, + YQuantity = 0, + ManuStock = ChannelStock.ReturnQuantity, + TotalStock = ChannelStock.ReturnQuantity, + 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($"未写入日结存数据{ChannelStock.DrugId}-{ChannelStock.ManuNo}-{ChannelStock.EffDate}-{ChannelStock.AddQuantity}"); + } + } //修改凌晨生成的总结存数据 AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(ChannelStock.MachineId)) .Where(ab => ab.Type == 4) .Where(ab => ab.DrugId == Convert.ToInt32(ChannelStock.DrugId)) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + ChannelStock.ReturnQuantity; - - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); - + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + ChannelStock.ReturnQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(ChannelStock.DrugId), + Type = 4, + YQuantity = 0, + ManuStock = ChannelStock.ReturnQuantity, + TotalStock = ChannelStock.ReturnQuantity, + 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($"未写入总结存数据{ChannelStock.DrugId}-{ChannelStock.AddQuantity}"); + } + } return true; diff --git a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs index 463601f..7a4770a 100644 --- a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs @@ -125,7 +125,7 @@ namespace DM_Weight.ViewModels get => _status; set => SetProperty(ref _status, value); } - + private List _channelStocks; public List ChannelStocks @@ -133,7 +133,7 @@ namespace DM_Weight.ViewModels get => _channelStocks; set => SetProperty(ref _channelStocks, value); } - + private IEnumerable> enumerable; private IEnumerator> enumerator; @@ -192,7 +192,7 @@ namespace DM_Weight.ViewModels _portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray(); _portUtil.DrawerNo = DrawerNo; - if((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) { // 发送加药数量 singleChannels.ForEach(it => @@ -203,7 +203,7 @@ namespace DM_Weight.ViewModels if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 6) { - for(int i = 0; i < singleChannels.Count; i++) + for (int i = 0; i < singleChannels.Count; i++) { ChannelStock it = singleChannels[i]; _portUtil.ClearCount(it.DrawerNo, it.ColNo); @@ -226,7 +226,7 @@ namespace DM_Weight.ViewModels List record = ChannelStocks.ToList(); string InvoiceId = "SELF_" + CurrentTimeMillis(); var f = SqlSugarHelper.Db.UseTran(() => - { + { for (int i = 0; i < record.Count; i++) { ChannelStock it = record[i]; @@ -293,20 +293,68 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == Convert.ToInt32(it.DrugId)) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; - + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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 == Convert.ToInt32(it.DrugId)) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.AddQuantity; - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + it.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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}"); + } + } - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); } return true; @@ -322,7 +370,7 @@ namespace DM_Weight.ViewModels _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity); }); } - + AlertMsg alertMsg = new AlertMsg { diff --git a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs index eb1474d..dce4974 100644 --- a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs @@ -270,20 +270,66 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == Convert.ToInt32(it.DrugId)) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; - + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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 == Convert.ToInt32(it.DrugId)) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - it.TakeQuantity; - - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); - - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - it.TakeQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(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}"); + } + } } return true; });