diff --git a/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs b/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs index f0b215c..e3c4c29 100644 --- a/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs +++ b/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs @@ -673,21 +673,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/ApplyListWindowViewModel.cs b/DM_Weight/ViewModels/ApplyListWindowViewModel.cs index 8bb71d3..5003556 100644 --- a/DM_Weight/ViewModels/ApplyListWindowViewModel.cs +++ b/DM_Weight/ViewModels/ApplyListWindowViewModel.cs @@ -149,7 +149,8 @@ namespace DM_Weight.ViewModels .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cd) => cd.drugInfo.DrugName.Contains(SearchValue)) .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) + .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..4cbc1ef 100644 --- a/DM_Weight/ViewModels/DestoryEmptyDialogViewModel.cs +++ b/DM_Weight/ViewModels/DestoryEmptyDialogViewModel.cs @@ -195,6 +195,16 @@ 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..6cc03d1 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,67 @@ 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 +358,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..21919b2 100644 --- a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs @@ -233,20 +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}"); + } + } 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..7f768be 100644 --- a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs @@ -367,21 +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..b15d5f4 100644 --- a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs @@ -384,22 +384,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/ReturnDrugDialogViewModel.cs b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs index cbee016..264c0d5 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,20 +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}"); + } + } diff --git a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs index 463601f..17063ca 100644 --- a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs @@ -293,8 +293,35 @@ 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)) @@ -302,11 +329,32 @@ namespace DM_Weight.ViewModels .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/SelfTakeDialogViewModel.cs b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs index eb1474d..76bc928 100644 --- a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs @@ -270,8 +270,35 @@ 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)) @@ -279,11 +306,32 @@ namespace DM_Weight.ViewModels .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; });