抽屉取药、加药;自选取药、加药修改报表

This commit is contained in:
马巧 2025-08-29 13:57:32 +08:00
parent 013e282189
commit 220272e9ff
9 changed files with 211 additions and 146 deletions

View File

@ -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<AccountBookG2>()
.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<AccountBookG2>()
.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<AccountBookG2>()
.Where(ab => ab.MachineId.Equals(it.MachineId))

View File

@ -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<AccountBookG2>()
.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<AccountBookG2>()
.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<AccountBookG2>()
.Where(ab => ab.MachineId.Equals(it.MachineId))

View File

@ -259,10 +259,10 @@ namespace DM_Weight.ViewModels
}).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand();
// 获取更新完库存后的药品库存
List<ChannelStock> nowChannels = SqlSugarHelper.Db.Queryable<ChannelStock>()
.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<AccountBookG2>()
.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<AccountBookG2>()
.Where(ab => ab.MachineId.Equals(it.MachineId))

View File

@ -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);
}

View File

@ -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<AccountBookG2>()
.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<AccountBookG2>()
.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<AccountBookG2>()
.Where(ab => ab.MachineId.Equals(it.MachineId))

View File

@ -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<AccountBookG2>()
.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<AccountBookG2>()
.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<AccountBookG2>()
.Where(ab => ab.MachineId.Equals(ChannelStock.MachineId))

View File

@ -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<AccountBookG2>()
.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<AccountBookG2>()
.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<AccountBookG2>()
.Where(ab => ab.MachineId.Equals(it.MachineId))

View File

@ -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<AccountBookG2>()
.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<AccountBookG2>()
.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<AccountBookG2>()
.Where(ab => ab.MachineId.Equals(it.MachineId))

View File

@ -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);
}
}
}