盘点时删除药品中批次库存为0的记录channel_stock与channel_list.

移出药箱药品时修改查询及插入字段信息。
修改药品基数时更新channel_stock下所有药品的基数及需要加药数
This commit is contained in:
马巧 2025-07-04 10:56:02 +08:00
parent 701f6c88e6
commit a5d5a4aa40
5 changed files with 57 additions and 14 deletions

View File

@ -3,7 +3,7 @@
<connectionStrings>
<!-- 数据库连接字符串 -->
<!--<add name="database" connectionString="server=127.0.0.1;database=wpf_dm_program;userid=root;password=qq1223" />-->
<add name="database" connectionString="server=127.0.0.1;port=3306;database=xiangtan_mazuike_xx;userid=root;password=root" />
<add name="database" connectionString="server=192.168.50.84;port=3306;database=xiangtanTest;userid=root;password=root" />
</connectionStrings>
<!--<runtime>
--><!--配置之后Appdomain.CurrentDomain.UnhandledException 事件的 IsTerminating 就变成了 false 啦!也就是说,程序并不会因为这次的异常而崩溃退出。--><!--

View File

@ -455,7 +455,7 @@ namespace DM_Weight.ViewModels
if (baseQty > _ChannelList.BaseQuantity)
{
//基数变大,需要补药
_ChannelList.channelStocks[0].NeedNum = baseQty - _ChannelList.BaseQuantity;
_ChannelList.channelStocks[0].NeedNum = _ChannelList.channelStocks[0].NeedNum+ baseQty - _ChannelList.BaseQuantity;
}
else
{
@ -466,8 +466,11 @@ namespace DM_Weight.ViewModels
//_ChannelList.channelStocks[0].BaseQuantity = baseQty;
//int iUpdate = SqlSugarHelper.Db.Updateable<ChannelStock>(_ChannelList.channelStocks[0]).ExecuteCommand();
_ChannelList.channelStocks.ForEach(cs => cs.BaseQuantity = baseQty);
int iBaseUpdate = SqlSugarHelper.Db.Updateable(_ChannelList.channelStocks).UpdateColumns(cs => new { cs.BaseQuantity, cs.NeedNum }).ExecuteCommand();
int iBaseUpdate = SqlSugarHelper.Db.Updateable<ChannelStock>().SetColumns(cs => new ChannelStock(){ BaseQuantity= _ChannelList.channelStocks[0].BaseQuantity }).Where(cs=>cs.Chnguid==_ChannelList.Id).ExecuteCommand();
if (iBaseUpdate > 0)
{
iBaseUpdate = SqlSugarHelper.Db.Updateable(_ChannelList.channelStocks[0]).UpdateColumns(cs => new { cs.NeedNum }).ExecuteCommand();
}
//更新ChannelList表中的BaseQuantity
int iUpdateChannelList = SqlSugarHelper.Db.Updateable<ChannelList>()
.SetColumns(it => new ChannelList() { BaseQuantity = baseQty })

View File

@ -93,6 +93,20 @@ namespace DM_Weight.ViewModels
public void OnNavigatedTo(NavigationContext navigationContext)
{
logger.Info("进入OnNavigatedTo");
//删除药品有批次但是库存为0的药品
List<ChannelStock> csList = SqlSugarHelper.Db.Queryable<ChannelStock>().Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cs.Quantity <= 0 && !string.IsNullOrEmpty(cs.ManuNo)).ToList();
if (csList != null && csList.Count > 0)
{
SqlSugarHelper.Db.Deleteable<ChannelStock>().Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cs.Quantity <= 0 && !string.IsNullOrEmpty(cs.ManuNo)).ExecuteCommand();
for (int i = 0; i < csList.Count; i++)
{
//如果channel_stock下无数据则channel_list同步删除
int iListCount= SqlSugarHelper.Db.Queryable<ChannelStock>().Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cs.DrawerNo==csList[i].DrawerNo&& cs.DrugId == csList[i].DrugId).Count();
if (iListCount <=0)
SqlSugarHelper.Db.Deleteable<ChannelList>().Where(cl => cl.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cl.Id == csList[i].Chnguid).ExecuteCommand();
}
}
RequestData();
logger.Info("结束RequestData");
}
@ -167,9 +181,9 @@ namespace DM_Weight.ViewModels
ManuNo = it.ManuNo,
EffDate = it.EffDate,
Id = it.Id,
NeedNum=0,
AddToJJNum=0
}).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate,it.NeedNum,it.AddToJJNum }).ExecuteCommand();
NeedNum = 0,
AddToJJNum = 0
}).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate, it.NeedNum, it.AddToJJNum }).ExecuteCommand();
SqlSugarHelper.Db.Updateable(new ChannelList()
{
@ -191,7 +205,7 @@ namespace DM_Weight.ViewModels
OperationTime = DateTime.Now,
Quantity = it.CheckQuantity - it.Quantity,
Type = 4,
InvoiceId = InvoiceId
InvoiceId = $"{it.DrawerNo}{it.DrugInfo.DrugName}盘前库存{it.Quantity},后{it.CheckQuantity}" // InvoiceId
//,StockQuantity = nowChannels.Sum(it => it.Quantity),
//CheckQuantity = it.CheckQuantity
}).ExecuteCommand();
@ -257,7 +271,7 @@ namespace DM_Weight.ViewModels
{
if (_channelStock != null)
{
}
});
}

View File

@ -317,7 +317,7 @@ namespace DM_Weight.ViewModels
string csId = Guid.NewGuid().ToString();
//查询要移动的药箱是否有该批次
ChannelStock removeChannelStock = RemoveChannelStockList.Where(it => it.ManuNo == _ChannelStock.ManuNo).First();
ChannelStock removeChannelStock = RemoveChannelStockList.Where(it => it.ManuNo == _ChannelStock.ManuNo).FirstOrDefault();
//有该药品且有该批次
if (removeChannelStock != null)
{
@ -328,7 +328,7 @@ namespace DM_Weight.ViewModels
else
{
//有该药品但没有该批次
SqlSugarHelper.Db.Insertable(new ChannelStock()
int iInsertResult= SqlSugarHelper.Db.Insertable(new ChannelStock()
{
MachineId = _ChannelStock.MachineId,
DrawerNo = Convert.ToInt32(SelectedItem.Code),
@ -338,13 +338,29 @@ namespace DM_Weight.ViewModels
EffDate=_ChannelStock.EffDate,
Quantity = RemoveQuantity,
DrawerType = 1,
Chnguid = _ChannelStock.Chnguid,
Chnguid = RemoveChannelStockList[0].Chnguid,
CheckQuantity= RemoveChannelStockList[0].CheckQuantity,
Id = csId,
}).ExecuteCommand();
if (iInsertResult > 0)
{
//删除没有批次的数据
SqlSugarHelper.Db.Deleteable<ChannelStock>(RemoveChannelStockList.Where(cs => cs.ManuNo == null)).ExecuteCommand();
}
else
{
AlertMsg alertMsg = new AlertMsg
{
Message = "移入失败",
Type = MsgType.ERROR,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
return false;
}
}
// 保存数据 药品移出记录
SqlSugarHelper.Db.Insertable(new MachineRecord()
int iInsertRecord= SqlSugarHelper.Db.Insertable(new MachineRecord()
{
MachineId = _ChannelStock.MachineId,
DrawerNo = _ChannelStock.DrawerNo,
@ -359,6 +375,16 @@ namespace DM_Weight.ViewModels
InvoiceId = _ChannelStock.Id,
DepartmentId = csId //要移入的药箱的channelStock的id
}).ExecuteCommand();
if(iInsertRecord<=0)
{
AlertMsg alertMsg = new AlertMsg
{
Message = "添加记录失败",
Type = MsgType.ERROR,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
return false;
}
}
else
{

View File

@ -142,7 +142,7 @@
<Grid Grid.Column="1" Margin="6">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="550" />
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Grid.ColumnSpan="2">
<ComboBox