From 220272e9ff691aa3647e7d6baced2a9a4087742f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=B7=A7?= <625215135@qq.com> Date: Fri, 29 Aug 2025 13:57:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=B1=89=E5=8F=96=E8=8D=AF=E3=80=81?= =?UTF-8?q?=E5=8A=A0=E8=8D=AF=EF=BC=9B=E8=87=AA=E9=80=89=E5=8F=96=E8=8D=AF?= =?UTF-8?q?=E3=80=81=E5=8A=A0=E8=8D=AF=E4=BF=AE=E6=94=B9=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawerAddDrugWindowViewModel.cs | 44 +++++++++------- .../DrawerTakeDrugWindowViewModel.cs | 46 ++++++++++------- .../ViewModels/InvoiceAddDialogViewModel.cs | 49 +++++++++--------- .../ViewModels/InvoiceInWindowViewModel.cs | 1 + .../ViewModels/OrderReturnDialogViewModel.cs | 49 ++++++++++-------- .../ViewModels/ReturnDrugDialogViewModel.cs | 50 +++++++++++-------- .../ViewModels/SelfAddDialogViewModel.cs | 50 +++++++++++-------- .../ViewModels/SelfTakeDialogViewModel.cs | 48 ++++++++++-------- DM_Weight/util/CheckComputerFreeState.cs | 20 ++++++-- 9 files changed, 211 insertions(+), 146 deletions(-) diff --git a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs index 0b01279..9b68f36 100644 --- a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs @@ -239,24 +239,6 @@ namespace DM_Weight.ViewModels }).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, - TotalStock = nowChannels.Sum(itx => itx.Quantity), - ManuStock = nowChannels.Where(itx => itx.ManuNo == it.ManuNo && itx.EffDate == it.EffDate).Sum(itx => itx.Quantity), - }).ExecuteCommand(); //修改凌晨生成的日结存数据 AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) @@ -264,11 +246,13 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == it.DrugId) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + int manuStock = 0; if (accountBookG2Day != null) { accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.AddQuantity; SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + manuStock = accountBookG2Day.ManuStock; } else { @@ -295,6 +279,30 @@ namespace DM_Weight.ViewModels logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}"); } } + //查询上一条账册中的空瓶数 + AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString())) + .Where(ab => ab.Type == 1 || ab.Type == 2) + .Where(ab => ab.DrugId == it.DrugId) + .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First(); + //保存账册 + 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, + ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity), + TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 && accountBookEmpty.TotalStock > it.AddQuantity ? accountBookEmpty.TotalStock - it.AddQuantity : 0) : 0) //负数直接记0 + }).ExecuteCommand(); //修改凌晨生成的总结存数据 AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) diff --git a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs index bd5fc94..62c4048 100644 --- a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs @@ -237,25 +237,6 @@ namespace DM_Weight.ViewModels }).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, - TotalStock = nowChannels.Sum(itx => itx.Quantity), - ManuStock = nowChannels.Where(itx => itx.ManuNo == it.ManuNo && itx.EffDate == it.EffDate).Sum(itx => itx.Quantity) - - }).ExecuteCommand(); //修改凌晨生成的日结存数据 AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) @@ -263,11 +244,13 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == it.DrugId) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + int manuStock = 0; if (accountBookG2Day != null) { accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; accountBookG2Day.OutQuantity = accountBookG2Day.OutQuantity + accountBookG2Day.OutQuantity; SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + manuStock = accountBookG2Day.ManuStock; } else { @@ -294,6 +277,31 @@ namespace DM_Weight.ViewModels logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}"); } } + //查询上一条账册中的空瓶数 + AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString())) + .Where(ab => ab.Type == 1 || ab.Type == 2) + .Where(ab => ab.DrugId == it.DrugId) + .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First(); + //保存账册 + 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, + ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity), + TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 ? accountBookEmpty.TotalStock : 0) : 0) + it.TakeQuantity, + + }).ExecuteCommand(); //修改凌晨生成的总结存数据 AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) diff --git a/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs b/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs index f0c88d0..798ccc7 100644 --- a/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs @@ -259,10 +259,10 @@ namespace DM_Weight.ViewModels }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); // 获取更新完库存后的药品库存 List nowChannels = SqlSugarHelper.Db.Queryable() - .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"]) ||cs.MachineId.Equals(ConfigurationManager.AppSettings["jj_machineId"])) + .Where(cs => (cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"])&&cs.DrawerType == 1) || cs.MachineId.Equals(ConfigurationManager.AppSettings["jj_machineId"])) .Where(cs => cs.DrugId.Equals(it.DrugId)) .Where(cs=>cs.ManuNo.Equals(it.ManuNo)) - .Where(cs => cs.DrawerType == 1) + //.Where(cs => cs.DrawerType == 1) .ToList(); // 保存数据 出/入库记录 SqlSugarHelper.Db.Insertable(new MachineRecord() @@ -279,8 +279,9 @@ namespace DM_Weight.ViewModels Quantity = it.AddQuantity, Type = 1, InvoiceId = InvoiceId - , - ReturnQuantity1 = nowChannels.Sum(it => it.Quantity) + //, + //ReturnQuantity1 = nowChannels.Sum(it => it.Quantity) + ,GetId= nowChannels.Sum(it => it.Quantity) }).ExecuteCommand(); //查询上一条账册中的空瓶数 @@ -289,25 +290,6 @@ namespace DM_Weight.ViewModels .Where(ab => ab.Type == 1 || ab.Type == 2) .Where(ab => ab.DrugId == it.DrugId) .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First(); - //保存账册 - 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, - ManuStock= nowChannels.Sum(it => it.Quantity), - TotalStock= (accountBookEmpty!=null?(accountBookEmpty.TotalStock>0&& accountBookEmpty.TotalStock>it.AddQuantity ? accountBookEmpty.TotalStock - it.AddQuantity : 0):0) //负数直接记0 - - }).ExecuteCommand(); //修改凌晨生成的日结存数据 AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) @@ -315,11 +297,13 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == it.DrugId) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + int manuStock = 0; if (accountBookG2Day != null) { accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.AddQuantity; SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + manuStock= accountBookG2Day.ManuStock; } else { @@ -346,6 +330,25 @@ namespace DM_Weight.ViewModels logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}"); } } + //保存账册 + 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, + ManuStock= manuStock>0? manuStock: nowChannels.Sum(it => it.Quantity), + TotalStock= (accountBookEmpty!=null?(accountBookEmpty.TotalStock>0&& accountBookEmpty.TotalStock>it.AddQuantity ? accountBookEmpty.TotalStock - it.AddQuantity : 0):0) //负数直接记0 + + }).ExecuteCommand(); //修改凌晨生成的总结存数据 AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) diff --git a/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs b/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs index 7c53cd1..fe3d35b 100644 --- a/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs @@ -258,6 +258,7 @@ namespace DM_Weight.ViewModels invoice.quantity = invoice.Units == "盒" ? invoice.quantity * invoice.DrugInfo.ConvertRatio : invoice.quantity; item.AddQuantity = invoice.quantity; } + invoice.DrugInfo = invoice.DrugInfo == null ? item.DrugInfo : null; item.Invoice = invoice; i.Add(item); } diff --git a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs index afc7436..cfaea85 100644 --- a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs @@ -338,26 +338,6 @@ namespace DM_Weight.ViewModels //,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.ReturnQuantity, - UserId1 = HomeWindowViewModel.Operator?.Id, - UserId2 = HomeWindowViewModel.Reviewer?.Id, - MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), - CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - CreateTime = DateTime.Now, - TotalStock = nowChannels.Sum(itx => itx.Quantity), - ManuStock = nowChannels.Where(itx => itx.ManuNo == it.ManuNo && itx.EffDate == it.EffDate).Sum(itx => itx.Quantity) - - - }).ExecuteCommand(); //修改凌晨生成的日结存数据 AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) @@ -365,11 +345,13 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == it.DrugId) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + int manuStock = 0; if (accountBookG2Day != null) { accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.ReturnQuantity; accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.ReturnQuantity; SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + manuStock = accountBookG2Day.ManuStock; } else { @@ -396,6 +378,33 @@ namespace DM_Weight.ViewModels logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}"); } } + //查询上一条账册中的空瓶数 + AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString())) + .Where(ab => ab.Type == 1 || ab.Type == 2) + .Where(ab => ab.DrugId == it.DrugId) + .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First(); + //保存账册 + 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.ReturnQuantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + CreateTime = DateTime.Now, + TotalStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity),//nowChannels.Sum(itx => itx.Quantity), + ManuStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 && accountBookEmpty.TotalStock > it.ReturnQuantity ? accountBookEmpty.TotalStock - it.ReturnQuantity : 0) : 0) // + + + + }).ExecuteCommand(); //修改凌晨生成的总结存数据 AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) diff --git a/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs index d2f6e29..45c0db4 100644 --- a/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs +++ b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs @@ -269,27 +269,6 @@ namespace DM_Weight.ViewModels GetId = MachineRecord.Id //,StockQuantity = nowChannels.Sum(it => it.Quantity) }).ExecuteCommand(); - - //保存账册 - SqlSugarHelper.Db.Insertable(new AccountBookG2() - { - DrugId = ChannelStock.DrugId, - Type = 1, - Department = ConfigurationManager.AppSettings["department"].ToString(), - InvoiceNo = InvoiceId, - ManuNo = ChannelStock.ManuNo, - EffDate = ChannelStock.EffDate, - AddQuantity = ReturnQuantity, - UserId1 = HomeWindowViewModel.Operator?.Id, - UserId2 = HomeWindowViewModel.Reviewer?.Id, - MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), - CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - CreateTime = DateTime.Now, - TotalStock = nowChannels.Sum(itx => itx.Quantity), - ManuStock = nowChannels.Where(itx => itx.ManuNo == ChannelStock.ManuNo && itx.EffDate == ChannelStock.EffDate).Sum(itx => itx.Quantity) - - - }).ExecuteCommand(); //修改凌晨生成的日结存数据 AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(ChannelStock.MachineId)) @@ -297,11 +276,13 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == ChannelStock.DrugId) .Where(ab => ab.ManuNo == ChannelStock.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + int manuStock = 0; if (accountBookG2Day != null) { accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + ChannelStock.ReturnQuantity; accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + ChannelStock.ReturnQuantity; SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + manuStock = accountBookG2Day.ManuStock; } else { @@ -328,6 +309,33 @@ namespace DM_Weight.ViewModels logger.Info($"未写入日结存数据{ChannelStock.DrugId}-{ChannelStock.ManuNo}-{ChannelStock.EffDate}-{ChannelStock.AddQuantity}"); } } + //查询上一条账册中的空瓶数 + AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString())) + .Where(ab => ab.Type == 1 || ab.Type == 2) + .Where(ab => ab.DrugId == ChannelStock.DrugId) + .Where(ab => ab.ManuNo == ChannelStock.ManuNo).OrderByDescending(ab => ab.Id).First(); + //保存账册 + SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = ChannelStock.DrugId, + Type = 1, + Department = ConfigurationManager.AppSettings["department"].ToString(), + InvoiceNo = InvoiceId, + ManuNo = ChannelStock.ManuNo, + EffDate = ChannelStock.EffDate, + AddQuantity = ReturnQuantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + CreateTime = DateTime.Now, + + TotalStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity),//nowChannels.Sum(itx => itx.Quantity), + ManuStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 && accountBookEmpty.TotalStock > ChannelStock.ReturnQuantity ? accountBookEmpty.TotalStock - ChannelStock.ReturnQuantity : 0) : 0) // + + + }).ExecuteCommand(); //修改凌晨生成的总结存数据 AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(ChannelStock.MachineId)) diff --git a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs index fbfb013..3c9cc6f 100644 --- a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs @@ -267,27 +267,12 @@ namespace DM_Weight.ViewModels 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, - TotalStock = nowChannels.Sum(itx => itx.Quantity), - ManuStock = nowChannels.Where(itx => itx.ManuNo == it.ManuNo && itx.EffDate == it.EffDate).Sum(itx => itx.Quantity) - - }).ExecuteCommand(); + //查询上一条账册中的空瓶数 + AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString())) + .Where(ab => ab.Type == 1 || ab.Type == 2) + .Where(ab => ab.DrugId == it.DrugId) + .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First(); //修改凌晨生成的日结存数据 AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) @@ -295,11 +280,13 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == it.DrugId) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + int manuStock = 0; if (accountBookG2Day != null) { accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity; accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.AddQuantity; SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + manuStock = accountBookG2Day.ManuStock; } else { @@ -326,6 +313,27 @@ namespace DM_Weight.ViewModels logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}"); } } + + + //保存账册 + 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, + ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity), + TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 && accountBookEmpty.TotalStock > it.AddQuantity ? accountBookEmpty.TotalStock - it.AddQuantity : 0) : 0) //负数直接记0 + + }).ExecuteCommand(); //修改凌晨生成的总结存数据 AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) diff --git a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs index c13788a..c037f87 100644 --- a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs @@ -246,26 +246,6 @@ namespace DM_Weight.ViewModels - //保存账册 - 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, - TotalStock = nowChannels.Sum(itx => itx.Quantity), - ManuStock = nowChannels.Where(itx => itx.ManuNo == it.ManuNo && itx.EffDate == it.EffDate).Sum(itx => itx.Quantity) - - - }).ExecuteCommand(); //修改凌晨生成的日结存数据 AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) @@ -273,11 +253,13 @@ namespace DM_Weight.ViewModels .Where(ab => ab.DrugId == it.DrugId) .Where(ab => ab.ManuNo == it.ManuNo) .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + int manuStock = 0; if (accountBookG2Day != null) { accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity; - accountBookG2Day.OutQuantity = accountBookG2Day.OutQuantity - it.TakeQuantity; + accountBookG2Day.OutQuantity = accountBookG2Day.OutQuantity + it.TakeQuantity; SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + manuStock = accountBookG2Day.ManuStock; } else { @@ -304,6 +286,30 @@ namespace DM_Weight.ViewModels logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}"); } } + //查询上一条账册中的空瓶数 + AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString())) + .Where(ab => ab.Type == 1 || ab.Type == 2) + .Where(ab => ab.DrugId == it.DrugId) + .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First(); + //保存账册 + 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, + ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity), + TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 ? accountBookEmpty.TotalStock : 0) : 0) + it.TakeQuantity, + }).ExecuteCommand(); //修改凌晨生成的总结存数据 AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() .Where(ab => ab.MachineId.Equals(it.MachineId)) diff --git a/DM_Weight/util/CheckComputerFreeState.cs b/DM_Weight/util/CheckComputerFreeState.cs index 1c3f789..6ec9b0d 100644 --- a/DM_Weight/util/CheckComputerFreeState.cs +++ b/DM_Weight/util/CheckComputerFreeState.cs @@ -44,9 +44,23 @@ namespace DM_Weight.util } else { - var count = (Environment.TickCount & Int32.MaxValue) - (long)vLastInputInfo.dwTime; - var icount = count / 1000; - return icount; + //var count = (Environment.TickCount & Int32.MaxValue) - (long)vLastInputInfo.dwTime; + //var icount = count / 1000; + //return icount; + + // 使用 64 位 TickCount 避免回绕问题 + long currentTick = Environment.TickCount64; + long lastInputTick = vLastInputInfo.dwTime; + + // 处理可能的回绕(虽然使用 64 位后极不可能发生) + if (currentTick < lastInputTick) + { + // 发生了回绕,调整计算 + lastInputTick -= uint.MaxValue + 1L; + } + + long elapsedMilliseconds = currentTick - lastInputTick; + return Math.Max(0, elapsedMilliseconds / 1000); } } }