1调拨入库同一调拨单可多次入

2库存管理页面添加库存为0时库存红色字体
3处方取药同一处方可多次取药
This commit is contained in:
maqiao 2024-03-29 18:21:28 +08:00
parent 2ef1c185e3
commit ff7716f63d
7 changed files with 233 additions and 54 deletions

View File

@ -0,0 +1,41 @@
using DM_Weight.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace DM_Weight.Converter
{
internal class ColorCountConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var total = 0;
bool bInt = int.TryParse(value.ToString(), out var count); if (bInt)
{
if (count <= 0)
{
return "Red";
}
else
{
return "black";
}
}
else
{
return "black";
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -119,6 +119,12 @@ namespace DM_Weight.Models
SetProperty(ref _addQuantity, value); SetProperty(ref _addQuantity, value);
} }
} }
/// <summary>
/// 调拨入库数量
/// </summary>
private int _invoiceQuantity;
[SugarColumn(IsIgnore =true)]
public int InvoiceQuantity { get=>_invoiceQuantity; set=>SetProperty(ref _invoiceQuantity, value); }
private int _takeQuantity = 0; private int _takeQuantity = 0;
@ -136,9 +142,25 @@ namespace DM_Weight.Models
{ {
throw new ArgumentException("取药数量不能小于0"); throw new ArgumentException("取药数量不能小于0");
} }
if(OrderQuantity>0&&value>OrderQuantity)
{
throw new ArgumentException("取药数量不能大于应取数量");
}
SetProperty(ref _takeQuantity, value); SetProperty(ref _takeQuantity, value);
} }
} }
private int _orderQuantity = 0;
/// <summary>
/// 处方取药数量
/// </summary>
[SugarColumn(IsIgnore =true)]
public int OrderQuantity
{
get => _orderQuantity;
set=>SetProperty(ref _orderQuantity, value);
}
//private string _tipMessage=string.Empty; //private string _tipMessage=string.Empty;
//[SugarColumn(IsIgnore = true)] //[SugarColumn(IsIgnore = true)]
//public string TipMessage //public string TipMessage

View File

@ -127,5 +127,10 @@ namespace DM_Weight.Models
///</summary> ///</summary>
[SugarColumn(ColumnName = "use_dosage")] [SugarColumn(ColumnName = "use_dosage")]
public string UseDosage { get; set; } public string UseDosage { get; set; }
/// <summary>
/// 处方中该药品状态是否已全部取出0未取1已取针对处方可取部分药
/// </summary>
[SugarColumn(ColumnName = "dm_status")]
public int? DMStatus { get;set; }
} }
} }

View File

@ -291,7 +291,7 @@ namespace DM_Weight.ViewModels
if (SelectedInvoice != null) if (SelectedInvoice != null)
{ {
//先查询有几种药 //先查询有几种药
string strSql = @"SELECT sum(Quantity) AS SumQuantity, COUNT(ID) AS CountNum,INVOICE_NO AS InvoiceNo,drug_id AS DrugId,QUANTITY AS quantity,drug_manu_no AS drugManuNo FROM IN_OUT_INVOICE WHERE INVOICE_NO=@INVOICE_NO GROUP BY INVOICE_NO,DRUG_ID"; string strSql = @"SELECT sum(Quantity) AS SumQuantity, COUNT(ID) AS CountNum,INVOICE_NO AS InvoiceNo,drug_id AS DrugId,QUANTITY AS quantity,drug_manu_no AS drugManuNo FROM IN_OUT_INVOICE WHERE STATUS=0 AND INVOICE_NO=@INVOICE_NO GROUP BY INVOICE_NO,DRUG_ID";
var invoices = SqlSugarHelper.Db.SqlQueryable<InOutInvoice>(strSql) var invoices = SqlSugarHelper.Db.SqlQueryable<InOutInvoice>(strSql)
.AddParameters(new .AddParameters(new
@ -354,6 +354,7 @@ namespace DM_Weight.ViewModels
stock.ManuNo = invoicesManuNo[j].DrugManuNo; stock.ManuNo = invoicesManuNo[j].DrugManuNo;
stock.EffDate = manuNoList[0].EffDate; stock.EffDate = manuNoList[0].EffDate;
stock.Chnguid = channelLst.Id; stock.Chnguid = channelLst.Id;
stock.InvoiceQuantity = invoicesManuNo[j].quantity;
stockList.Add(stock); stockList.Add(stock);
} }
//stock.AddQuantity = invoicesManuNo[j].quantity; //stock.AddQuantity = invoicesManuNo[j].quantity;
@ -363,6 +364,7 @@ namespace DM_Weight.ViewModels
{ {
var ret = it.First(); var ret = it.First();
ret.AddQuantity = invoicesManuNo[j].quantity; ret.AddQuantity = invoicesManuNo[j].quantity;
ret.InvoiceQuantity = invoicesManuNo[j].quantity;
return ret; return ret;
}) })
.ToList(); .ToList();
@ -390,7 +392,8 @@ namespace DM_Weight.ViewModels
ChannelStocks.Clear(); ChannelStocks.Clear();
foreach (ChannelList lst in ChannelLsts) foreach (ChannelList lst in ChannelLsts)
{ {
ChannelStocks.AddRange(lst.channelStocks);
ChannelStocks.AddRange(lst.channelStocks.Where(cs => cs.AddQuantity > 9));
} }
AddChannels = ChannelStocks.FindAll(it => it.AddQuantity != 0); AddChannels = ChannelStocks.FindAll(it => it.AddQuantity != 0);
@ -414,17 +417,17 @@ namespace DM_Weight.ViewModels
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg); _eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
return; return;
} }
int totalNum = AddChannels.Sum(add => add.AddQuantity); //int totalNum = AddChannels.Sum(add => add.AddQuantity);
if (totalNum != SelectedInvoice.Quantity) //if (totalNum != SelectedInvoice.Quantity)
{ //{
AlertMsg alertMsg = new AlertMsg // AlertMsg alertMsg = new AlertMsg
{ // {
Message = "各批次添加数量要与调拨单药品总数一致!", // Message = "各批次添加数量要与调拨单药品总数一致!",
Type = MsgType.ERROR, // Type = MsgType.ERROR,
}; // };
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg); // _eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
return; // return;
} //}
enumerator.MoveNext(); enumerator.MoveNext();
Status = 1; Status = 1;
OpenOneByOne(); OpenOneByOne();
@ -506,18 +509,48 @@ namespace DM_Weight.ViewModels
if (!_isFinishClick) if (!_isFinishClick)
{ {
_isFinishClick = true; _isFinishClick = true;
List<ChannelStock> record = ChannelStocks.ToList(); List<ChannelStock> record = ChannelStocks;//.ToList();
string InvoiceId = SelectedInvoice.InvoiceNo; string InvoiceId = SelectedInvoice.InvoiceNo;
var f = SqlSugarHelper.Db.UseTran(() => var f = SqlSugarHelper.Db.UseTran(() =>
{ {
SqlSugarHelper.Db.Updateable(new InOutInvoice()
{
Status = 1,
InvoiceNo = SelectedInvoice.InvoiceNo
}).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.InvoiceNo }).ExecuteCommand();
for (int i = 0; i < record.Count; i++) for (int i = 0; i < record.Count; i++)
{ {
//添加数量不能大于入库单上要加的数量
if (record[i].AddQuantity > record[i].InvoiceQuantity)
{
AlertMsg alertMsg = new AlertMsg
{
Message = "添加数量不能大于调拨单中药品数量!",
Type = MsgType.ERROR,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
return false;
}
//添加数量等于入库单上要加的数量则更新入库单状态
if (record[i].AddQuantity == record[i].InvoiceQuantity)
{
SqlSugarHelper.Db.Updateable(new InOutInvoice()
{
Status = 1,
InvoiceNo = SelectedInvoice.InvoiceNo,
DrugManuNo = record[i].ManuNo,
DrugId = record[i].DrugId
}).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.InvoiceNo, it.DrugId, it.DrugManuNo }).ExecuteCommand();
}
else
{
//添加数量小于入库单上要加的数量则更新入库单中的数量
SqlSugarHelper.Db.Updateable(new InOutInvoice()
{
quantity= record[i].InvoiceQuantity- record[i].AddQuantity,
InvoiceNo = SelectedInvoice.InvoiceNo,
DrugManuNo = record[i].ManuNo,
DrugId = record[i].DrugId
}).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.InvoiceNo, it.DrugId, it.DrugManuNo }).ExecuteCommand();
}
ChannelStock it = record[i]; ChannelStock it = record[i];
@ -635,22 +668,22 @@ namespace DM_Weight.ViewModels
{ {
//if (singleChannels[i].BoardType == 5) //if (singleChannels[i].BoardType == 5)
//{ //{
List<ChannelStock> channelStockEffDate = SqlSugarHelper.Db.Queryable<ChannelStock>() List<ChannelStock> channelStockEffDate = SqlSugarHelper.Db.Queryable<ChannelStock>()
.Where(cs => cs.MachineId == singleChannels[i].MachineId) .Where(cs => cs.MachineId == singleChannels[i].MachineId)
.Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo) .Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo)
.Where(cs => cs.ColNo == singleChannels[i].ColNo) .Where(cs => cs.ColNo == singleChannels[i].ColNo)
.Where(cs=>cs.Quantity>0) .Where(cs => cs.Quantity > 0)
.OrderBy(cs => cs.EffDate).ToList(); .OrderBy(cs => cs.EffDate).ToList();
int totalQuantity = channelStockEffDate.Sum(it => it.Quantity); int totalQuantity = channelStockEffDate.Sum(it => it.Quantity);
//将库位多批次的总库存数更新标签 //将库位多批次的总库存数更新标签
_portUtil.WriteQuantity(channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo, totalQuantity); _portUtil.WriteQuantity(channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo, totalQuantity);
Thread.Sleep(200); Thread.Sleep(200);
_portUtil.WriteChannelInfo(6, channelStockEffDate[0].EffDate == null ? "" : channelStockEffDate[0].EffDate, channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); _portUtil.WriteChannelInfo(6, channelStockEffDate[0].EffDate == null ? "" : channelStockEffDate[0].EffDate, channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo);
Thread.Sleep(200); Thread.Sleep(200);
_portUtil.WriteChannelInfo(5, channelStockEffDate[0].ManuNo, channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); _portUtil.WriteChannelInfo(5, channelStockEffDate[0].ManuNo, channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo);
Thread.Sleep(200); Thread.Sleep(200);
_portUtil.ShowContent(channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); _portUtil.ShowContent(channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo);
//} //}
} }
} }
@ -664,6 +697,7 @@ namespace DM_Weight.ViewModels
Type = MsgType.SUCCESS, Type = MsgType.SUCCESS,
}; };
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg); _eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
RequestData();
} }
if (!f.IsSuccess) if (!f.IsSuccess)
{ {
@ -678,7 +712,6 @@ namespace DM_Weight.ViewModels
_isFinishClick = false; _isFinishClick = false;
} }
RequestData();
}); });
} }
// 取消按钮 // 取消按钮

View File

@ -174,6 +174,7 @@ namespace DM_Weight.ViewModels
orderDetails = SqlSugarHelper.Db.Queryable<OrderDetail>() orderDetails = SqlSugarHelper.Db.Queryable<OrderDetail>()
.Includes<DrugInfo>(od => od.DrugInfo) .Includes<DrugInfo>(od => od.DrugInfo)
.InnerJoin(SqlSugarHelper.Db.Queryable<ChannelStock>().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (od, t) => od.DrugId == t.DrugId) .InnerJoin(SqlSugarHelper.Db.Queryable<ChannelStock>().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (od, t) => od.DrugId == t.DrugId)
.Where(od=>od.DMStatus==0)
.Where(od => od.OrderNo == OrderInfo.OrderNo) .Where(od => od.OrderNo == OrderInfo.OrderNo)
.ToList(); .ToList();
@ -206,12 +207,14 @@ namespace DM_Weight.ViewModels
ChannelStock stock = HasQChannels[j]; ChannelStock stock = HasQChannels[j];
if (TakeQ > stock.Quantity) if (TakeQ > stock.Quantity)
{ {
stock.OrderQuantity= orderDetail.Quantity;
stock.TakeQuantity = stock.Quantity; stock.TakeQuantity = stock.Quantity;
channelStocks.Add(stock); channelStocks.Add(stock);
TakeQ -= stock.Quantity; TakeQ -= stock.Quantity;
} }
else else
{ {
stock.OrderQuantity = orderDetail.Quantity;
stock.TakeQuantity = TakeQ; stock.TakeQuantity = TakeQ;
channelStocks.Add(stock); channelStocks.Add(stock);
TakeQ = 0; TakeQ = 0;
@ -220,7 +223,16 @@ namespace DM_Weight.ViewModels
} }
else else
{ {
msg.Add($"药品【{orderDetail.DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】"); //msg.Add($"药品【{orderDetail.DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】");
//数量不够就把全部数量取出
for (int n = 0; n < HasQChannels.Count; n++)
{
ChannelStock stock = HasQChannels[n];
stock.OrderQuantity = TakeQ;
stock.TakeQuantity = stock.Quantity;
channelStocks.Add(stock);
}
} }
} }
if (msg.Count > 0) if (msg.Count > 0)
@ -332,17 +344,50 @@ namespace DM_Weight.ViewModels
try try
{ {
SqlSugarHelper.Db.BeginTran(); SqlSugarHelper.Db.BeginTran();
logger.Info($"更新OrderInfo:{InvoiceId}"); //如果处方下全部药品都取完则更新orderInfo,order_detail中的dm_status
SqlSugarHelper.Db.Updateable(new OrderInfo() if (ChannelStocks.Sum(cs => cs.TakeQuantity) == ChannelStocks.Sum(cs => cs.OrderQuantity))
{ {
DmStatus = 1, logger.Info($"更新OrderInfo:{InvoiceId}");
OrderNo = OrderInfo.OrderNo SqlSugarHelper.Db.Updateable(new OrderInfo()
}).UpdateColumns(it => new { it.DmStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand(); {
DmStatus = 1,
OrderNo = OrderInfo.OrderNo
}).UpdateColumns(it => new { it.DmStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand();
SqlSugarHelper.Db.Updateable(new OrderDetail()
{
DMStatus = 1,
OrderNo = OrderInfo.OrderNo
}).UpdateColumns(it => new { it.DMStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand();
}
logger.Info("进入record循环"); logger.Info("进入record循环");
for (int i = 0; i < record.Count; i++) for (int i = 0; i < record.Count; i++)
{ {
ChannelStock it = record[i]; ChannelStock it = record[i];
//该药品下的所有取出数量
int alTakeQuantity=record.Where(rd=>rd.DrugId==it.DrugId).Sum(rd=>rd.TakeQuantity);
//处方下某一个药品都取完则更新order_detail
if(it.OrderQuantity==it.TakeQuantity|| it.OrderQuantity == alTakeQuantity)
{
SqlSugarHelper.Db.Updateable(new OrderDetail()
{
DMStatus = 1,
OrderNo = OrderInfo.OrderNo,
DrugId= it.DrugId,
}).UpdateColumns(it => new { it.DMStatus }).WhereColumns(it => new { it.OrderNo,it.DrugId }).ExecuteCommand();
}
else
{
//处方下某一个药品没有取完则更新order_detail中的取药数量应取-已取)
SqlSugarHelper.Db.Updateable(new OrderDetail()
{
Quantity = it.OrderQuantity- alTakeQuantity,
OrderNo = OrderInfo.OrderNo,
DrugId = it.DrugId,
}).UpdateColumns(it => new { it.Quantity }).WhereColumns(it => new { it.OrderNo, it.DrugId }).ExecuteCommand();
}
logger.Info($"更新ChannelStock:{it.Id}"); logger.Info($"更新ChannelStock:{it.Id}");
// 更新数据 库存信息 // 更新数据 库存信息

View File

@ -144,13 +144,6 @@
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}" ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
/> />
<DataGridTextColumn Width="100"
Header="数量"
IsReadOnly="True"
Binding="{Binding Quantity}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
/>
<DataGridTextColumn Width="130" <DataGridTextColumn Width="130"
Header="批次" Header="批次"
IsReadOnly="True" IsReadOnly="True"
@ -166,13 +159,36 @@
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
/> />
<DataGridTextColumn Width="100" <DataGridTextColumn Width="100"
Header="取出数量" Header="库存数量"
IsReadOnly="True" IsReadOnly="True"
Binding="{Binding TakeQuantity}" Binding="{Binding Quantity}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}" ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
/> />
</DataGrid.Columns> <DataGridTextColumn Width="100"
Header="应取数量"
IsReadOnly="True"
Binding="{Binding OrderQuantity}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
/>
<DataGridTemplateColumn Width="100"
Header="取出数量">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Width="100" Style="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
<TextBox.Text>
<Binding Path="TakeQuantity" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<ExceptionValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid> </DataGrid>
<Grid Grid.Row="3"> <Grid Grid.Row="3">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>

View File

@ -22,6 +22,7 @@
<convert:DrawerSelectConverter x:Key="DrawerSelectConverter" /> <convert:DrawerSelectConverter x:Key="DrawerSelectConverter" />
<convert:StatusConverter x:Key="StatusConverter" />--> <convert:StatusConverter x:Key="StatusConverter" />-->
<convert:TotalCountConverter x:Key="TotalCountConverter" /> <convert:TotalCountConverter x:Key="TotalCountConverter" />
<convert:ColorCountConverter x:Key="ColorCountConverter" />
</Grid.Resources> </Grid.Resources>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -120,7 +121,9 @@
<!--GroupStyle to group data--> <!--GroupStyle to group data-->
<!--<DataGrid.GroupStyle> <!--<DataGrid.GroupStyle>
<GroupStyle> <GroupStyle>
--><!--Group DataItems into DataGroup--><!-- -->
<!--Group DataItems into DataGroup-->
<!--
<GroupStyle.ContainerStyle> <GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}"> <Style TargetType="{x:Type GroupItem}">
<Setter Property="Template"> <Setter Property="Template">
@ -184,6 +187,20 @@
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>
<!--<DataGridTemplateColumn Header="库存" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding channelStocks}" materialDesign:ListBoxItemAssist.ShowSelection="False" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Quantity}" Foreground="{Binding Path=Quantity,Converter={StaticResource ColorCountConverter} }" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>-->
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<!--<ListView Grid.Row="1" <!--<ListView Grid.Row="1"