diff --git a/DM_Weight/Models/OrderDetail.cs b/DM_Weight/Models/OrderDetail.cs
index 416f9fd..dc8ffff 100644
--- a/DM_Weight/Models/OrderDetail.cs
+++ b/DM_Weight/Models/OrderDetail.cs
@@ -19,8 +19,8 @@ namespace DM_Weight.Models
///
/// 默认值: NULL
///
- //[SugarColumn(ColumnName = "order_id")]
- //public int? OrderId { get; set; }
+ [SugarColumn(ColumnName = "order_id")]
+ public int? OrderId { get; set; }
///
///
///
diff --git a/DM_Weight/ViewModels/AddDrugControlViewModel.cs b/DM_Weight/ViewModels/AddDrugControlViewModel.cs
index 7e3db32..459f44e 100644
--- a/DM_Weight/ViewModels/AddDrugControlViewModel.cs
+++ b/DM_Weight/ViewModels/AddDrugControlViewModel.cs
@@ -426,11 +426,11 @@ namespace DM_Weight.ViewModels
Thread.Sleep(200);
_portUtil.ShowContent(it.DrawerNo, it.ColNo);
- Thread.Sleep(500);
+ Thread.Sleep(200);
//写库存数量
_portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity);
-
+ Thread.Sleep(200);
});
}
RequestData();
diff --git a/DM_Weight/ViewModels/BindingChannelNewDialogViewModel .cs b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel .cs
index 8d5a3ed..8639367 100644
--- a/DM_Weight/ViewModels/BindingChannelNewDialogViewModel .cs
+++ b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel .cs
@@ -577,6 +577,7 @@ namespace DM_Weight.ViewModels
_portUtil.ShowContent(item.DrawerNo, item.ColNo);
Thread.Sleep(200);
_portUtil.WriteQuantity(item.DrawerNo, item.ColNo, item.totalCount);
+ Thread.Sleep(200);
}
});
}
diff --git a/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs b/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs
index bbe0228..fa314ed 100644
--- a/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs
+++ b/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs
@@ -459,7 +459,7 @@ namespace DM_Weight.ViewModels
{
// 将库位多批次的总库存数更新标签
_portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.CheckQuantity);
-
+ Thread.Sleep(200);
});
}
diff --git a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs
index 38186d5..b812aa0 100644
--- a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs
+++ b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs
@@ -549,6 +549,7 @@ namespace DM_Weight.ViewModels
{
// 将库位多批次的总库存数更新标签
_portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.CheckQuantity);
+ Thread.Sleep(200);
});
}
diff --git a/DM_Weight/ViewModels/CheckStockWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockWindowViewModel.cs
index e4857fe..84cd5ab 100644
--- a/DM_Weight/ViewModels/CheckStockWindowViewModel.cs
+++ b/DM_Weight/ViewModels/CheckStockWindowViewModel.cs
@@ -15,6 +15,7 @@ using DM_Weight.Models;
using DM_Weight.msg;
using DM_Weight.Port;
using DM_Weight.util;
+using System.Threading;
namespace DM_Weight.ViewModels
{
@@ -257,6 +258,7 @@ namespace DM_Weight.ViewModels
singleChannels.ForEach(it =>
{
_portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.CheckQuantity);
+ Thread.Sleep(200);
});
}
diff --git a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs
index fe47c01..9c13df3 100644
--- a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs
+++ b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs
@@ -17,6 +17,7 @@ using DM_Weight.msg;
using DM_Weight.Port;
using DM_Weight.util;
using System.Collections.ObjectModel;
+using System.Threading;
namespace DM_Weight.ViewModels
{
@@ -332,6 +333,7 @@ namespace DM_Weight.ViewModels
singleChannels.ForEach(it =>
{
_portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity);
+ Thread.Sleep(200);
});
}
RequestData();
diff --git a/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs b/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs
index 7dc4f59..a155c44 100644
--- a/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs
+++ b/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs
@@ -415,7 +415,7 @@ namespace DM_Weight.ViewModels
{
//将库位多批次的总库存数更新标签
_portUtil.WriteQuantity(singleChannels[0].DrawerNo, singleChannels[0].ColNo, singleChannels.Sum(it => it.Quantity) + singleChannels.Sum(it => it.AddQuantity));
-
+ Thread.Sleep(200);
//singleChannels.ForEach(it =>
//{
// _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity);
diff --git a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs
index eed90fd..d44415f 100644
--- a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs
+++ b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs
@@ -413,7 +413,7 @@ namespace DM_Weight.ViewModels
{
//将库位多批次的总库存数更新标签
_portUtil.WriteQuantity(singleChannels[0].DrawerNo, singleChannels[0].ColNo, singleChannels.Sum(it => it.Quantity) - singleChannels.Sum(it => it.AddQuantity));
-
+ Thread.Sleep(200);
//singleChannels.ForEach(it =>
//{
// _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity);
diff --git a/DM_Weight/ViewModels/MultiOrderTakeDialogViewModel.cs b/DM_Weight/ViewModels/MultiOrderTakeDialogViewModel.cs
index 57d2bec..f0a5eb6 100644
--- a/DM_Weight/ViewModels/MultiOrderTakeDialogViewModel.cs
+++ b/DM_Weight/ViewModels/MultiOrderTakeDialogViewModel.cs
@@ -9,6 +9,7 @@ using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using SqlSugar;
+using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -382,89 +383,98 @@ namespace DM_Weight.ViewModels
// State = 1,
// Operator = HomeWindowViewModel.Operator?.Nickname,
//});
- //已取药数量
- int hasTake = 0;
for (int i = 0; i < record.Count; i++)
{
int ordinalNum = SqlSugarHelper.Db.Queryable()
.Where(mr => mr.OperationTime.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
.Max(mr => mr.OrdinalNum);
- int orderTakeQuantity = SqlSugarHelper.Db.Queryable()
+ //处方中该药品明细
+ OrderDetail orderDetail = SqlSugarHelper.Db.Queryable()
.Where(od => od.OrderNo == OrderInfo[j].OrderNo && od.DrugId == record[i].DrugId && od.DetailStatus == 0)
- .GroupBy(od => new { od.DrugId, od.SetManuNo }).Sum(od => od.Quantity);
- if (hasTake > 0)
+ .GroupBy(od => new { od.DrugId, od.OrderId, od.SetManuNo }).Select(od => new OrderDetail
+ {
+ OrderId = od.OrderId,
+ DrugId = od.DrugId,
+ Quantity = SqlFunc.AggregateSum(od.Quantity)
+ }).First();
+ if (orderDetail != null)
{
- orderTakeQuantity = orderTakeQuantity - hasTake;
- }
- //该处方没有这个药,跳出循环
- if (orderTakeQuantity <= 0 || record[i].Quantity <= 0)
- continue;
- if (!(record[i].Quantity == orderTakeQuantity))
- {
- if (record[i].Quantity > orderTakeQuantity)
- {
- //record[i].TakeQuantity = record[i].TakeQuantity - orderTakeQuantity;
- record[i].TakeQuantity = orderTakeQuantity;
- hasTake += orderTakeQuantity;
- record[i].Quantity = record[i].Quantity - orderTakeQuantity;
- }
- else if (record[i].Quantity < orderTakeQuantity)
- {
- hasTake += record[i].Quantity;
- record[i].TakeQuantity = record[i].Quantity;
- record[i].Quantity = 0;
- }
- }
- else
- {
- record[i].TakeQuantity = orderTakeQuantity;
- record[i].Quantity = record[i].Quantity - record[i].TakeQuantity;
- hasTake += record[i].TakeQuantity;
- }
- ChannelStock it = record[i];
- // 更新数据 库存信息
- SqlSugarHelper.Db.Updateable(new ChannelStock()
- {
- Quantity = record[i].Quantity,
- ManuNo = it.ManuNo,
- EffDate = it.EffDate,
- Id = it.Id,
- }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand();
- // 获取更新完库存后的药品库存
- List nowChannels = SqlSugarHelper.Db.Queryable()
- .Where(cs => cs.MachineId.Equals(it.MachineId))
- .Where(cs => cs.DrugId.Equals(it.DrugId))
- .Where(cs => cs.DrawerType == 1)
- .ToList();
+ //已取药数量
+ int hasTakeQuantity = SqlSugarHelper.Db.Queryable()
+ .Where(mr => mr.InvoiceId == InvoiceId && mr.DrugId == record[i].DrugId && mr.GetId == orderDetail.OrderId)
+ .Sum(mr => mr.Quantity);
+ //处方中该药品取药数量
+ int orderTakeQuantity = orderDetail.Quantity - hasTakeQuantity;
- // 保存数据 出库记录
- SqlSugarHelper.Db.Insertable(new MachineRecord()
- {
- MachineId = it.MachineId,
- DrawerNo = it.DrawerNo,
- ColNo = it.ColNo,
- DrugId = it.DrugId,
- 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,
- OperationTime = DateTime.Now,
- Quantity = record[i].TakeQuantity,
- Type = 2,
- InvoiceId = InvoiceId,
- OrdinalNum = ordinalNum + 1,
- StockQuantity = nowChannels.Sum(it => it.Quantity),
- ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity),
- SupplierDept = ConfigurationManager.AppSettings["receiveDept"].ToString(),
- ReceiveDept = OrderInfo[j].DeptName
- }).ExecuteCommand();
- if (0 == record[i].Quantity)
- {
- record[i].TakeQuantity = 0;
- }
- if (record[i].TakeQuantity == orderTakeQuantity)
- {
- break;
+ //当前药品库存
+ int stockQuantity = SqlSugarHelper.Db.Queryable()
+ .Where(cs => cs.MachineId == (record[i].MachineId)
+ && cs.DrugId == record[i].DrugId
+ && cs.ManuNo == record[i].ManuNo && cs.DrawerNo == record[i].DrawerNo
+ && cs.ColNo == record[i].ColNo).Select(cs => cs.Quantity).First();
+
+
+
+ //该处方没有这个药,跳出循环
+ if (stockQuantity <= 0)
+ continue;
+ if (!(stockQuantity == orderTakeQuantity))
+ {
+ if (stockQuantity > orderTakeQuantity)
+ {
+ //record[i].TakeQuantity = record[i].TakeQuantity - orderTakeQuantity;
+ record[i].TakeQuantity = orderTakeQuantity;
+ record[i].Quantity = stockQuantity - orderTakeQuantity;
+ }
+ else if (stockQuantity < orderTakeQuantity)
+ {
+ record[i].TakeQuantity = stockQuantity;
+ record[i].Quantity = 0;
+ }
+ }
+ else
+ {
+ record[i].TakeQuantity = orderTakeQuantity;
+ record[i].Quantity = stockQuantity - record[i].TakeQuantity;
+ }
+ ChannelStock it = record[i];
+ // 更新数据 库存信息
+ SqlSugarHelper.Db.Updateable(new ChannelStock()
+ {
+ Quantity = record[i].Quantity,
+ ManuNo = it.ManuNo,
+ EffDate = it.EffDate,
+ Id = it.Id,
+ }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand();
+ // 获取更新完库存后的药品库存
+ List nowChannels = SqlSugarHelper.Db.Queryable()
+ .Where(cs => cs.MachineId.Equals(it.MachineId))
+ .Where(cs => cs.DrugId.Equals(it.DrugId))
+ .Where(cs => cs.DrawerType == 1)
+ .ToList();
+
+ // 保存数据 出库记录
+ SqlSugarHelper.Db.Insertable(new MachineRecord()
+ {
+ MachineId = it.MachineId,
+ DrawerNo = it.DrawerNo,
+ ColNo = it.ColNo,
+ DrugId = it.DrugId,
+ 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,
+ OperationTime = DateTime.Now,
+ Quantity = record[i].TakeQuantity,
+ Type = 2,
+ InvoiceId = InvoiceId,
+ OrdinalNum = ordinalNum + 1,
+ StockQuantity = nowChannels.Sum(it => it.Quantity),
+ ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity),
+ SupplierDept = ConfigurationManager.AppSettings["receiveDept"].ToString(),
+ ReceiveDept = OrderInfo[j].DeptName,
+ GetId = orderDetail.OrderId
+ }).ExecuteCommand();
}
}
//更新处方状态
@@ -498,6 +508,7 @@ namespace DM_Weight.ViewModels
singleChannels.ForEach(it =>
{
_portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity);
+ Thread.Sleep(200);
});
}
AlertMsg alertMsg = new AlertMsg
diff --git a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs
index d8d43a9..d9c96df 100644
--- a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs
+++ b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs
@@ -440,6 +440,7 @@ namespace DM_Weight.ViewModels
.Sum(it => it.Quantity);
//将库位多批次的总库存数更新标签
_portUtil.WriteQuantity(singleChannels[i].DrawerNo, singleChannels[i].ColNo, totalQuantity);
+ Thread.Sleep(200);
}
}
}
diff --git a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs
index 71f0f81..426f5d8 100644
--- a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs
+++ b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs
@@ -460,6 +460,7 @@ namespace DM_Weight.ViewModels
.Sum(it => it.Quantity);
//将库位多批次的总库存数更新标签
_portUtil.WriteQuantity(singleChannels[i].DrawerNo, singleChannels[i].ColNo, totalQuantity);
+ Thread.Sleep(200);
}
}
}
diff --git a/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs
index e393973..dde2c90 100644
--- a/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs
+++ b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs
@@ -17,6 +17,7 @@ using DM_Weight.msg;
using DM_Weight.Port;
using DM_Weight.util;
using SqlSugar;
+using System.Threading;
namespace DM_Weight.ViewModels
{
@@ -334,6 +335,7 @@ namespace DM_Weight.ViewModels
.Sum(it => it.Quantity);
_portUtil.WriteQuantity(ChannelStock.DrawerNo, ChannelStock.ColNo, totalQuantity);
+ Thread.Sleep(200);
}
AlertMsg alertMsg = new AlertMsg
diff --git a/DM_Weight/ViewModels/ReturnEmptyDialogViewModel.cs b/DM_Weight/ViewModels/ReturnEmptyDialogViewModel.cs
index 37da7da..4aeb266 100644
--- a/DM_Weight/ViewModels/ReturnEmptyDialogViewModel.cs
+++ b/DM_Weight/ViewModels/ReturnEmptyDialogViewModel.cs
@@ -21,6 +21,7 @@ using DM_Weight.Views;
using SqlSugar;
using System.Threading.Channels;
using DM_Weight.Report;
+using System.Threading;
namespace DM_Weight.ViewModels
{
@@ -50,7 +51,7 @@ namespace DM_Weight.ViewModels
void DoMyPrismEvent(DeviceMsg msg)
{
-
+ logger.Info($"msg.WindowName【{msg.WindowName}】WindowName【{WindowName}】Status【{Status}】EventType【{msg.EventType}】");
if (msg.WindowName.Equals(WindowName))
{
@@ -413,6 +414,7 @@ namespace DM_Weight.ViewModels
if (ChannelStock.BoardType == 5)
{
_portUtil.WriteQuantity(ChannelStock.DrawerNo, ChannelStock.ColNo, ChannelStock.Quantity + ReturnQuantity);
+ Thread.Sleep(200);
}
AlertMsg alertMsg = new AlertMsg
diff --git a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs
index bedea56..d95373d 100644
--- a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs
+++ b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs
@@ -420,7 +420,8 @@ namespace DM_Weight.ViewModels
.Where(cs => cs.ColNo == singleChannels[i].ColNo)
.Sum(it => it.Quantity);
//将库位多批次的总库存数更新标签
- _portUtil.WriteQuantity(singleChannels[i].DrawerNo, singleChannels[i].ColNo, totalQuantity);
+ _portUtil.WriteQuantity(singleChannels[i].DrawerNo, singleChannels[i].ColNo, totalQuantity);
+ Thread.Sleep(200);
}
}
}
diff --git a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs
index d403a43..cc1ed03 100644
--- a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs
+++ b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs
@@ -382,6 +382,7 @@ namespace DM_Weight.ViewModels
.Sum(it => it.Quantity);
//将库位多批次的总库存数更新标签
_portUtil.WriteQuantity(singleChannels[i].DrawerNo, singleChannels[i].ColNo, totalQuantity);
+ Thread.Sleep(200);
}
}
}