Compare commits

...

2 Commits

Author SHA1 Message Date
马巧 e79cdae0da 添加录屏功能,添加可多次加药,毒麻柜无药则显示无库存或未绑定,对应的药品先不补 2025-07-10 11:53:28 +08:00
马巧 a5d5a4aa40 盘点时删除药品中批次库存为0的记录channel_stock与channel_list.
移出药箱药品时修改查询及插入字段信息。
修改药品基数时更新channel_stock下所有药品的基数及需要加药数
2025-07-04 10:56:02 +08:00
13 changed files with 245 additions and 58 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

@ -74,6 +74,7 @@
<PackageReference Include="NModbus4.NetCore" Version="2.0.1" />
<PackageReference Include="Polly" Version="8.4.1" />
<PackageReference Include="Prism.Unity" Version="8.1.97" />
<PackageReference Include="ScreenRecorderLib" Version="6.5.1" />
<PackageReference Include="SharpPromise" Version="1.7.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.67" />
<PackageReference Include="SuperSimpleTcp" Version="3.0.10" />

View File

@ -116,11 +116,11 @@ namespace DM_Weight.ViewModels
channelList.channelStocks = new List<ChannelStock>();
}
channelList.channelStocks.AddRange(ChannelStocks.Where(cs => cs.DrawerNo == DrawerNoList[i]).ToList());
if (channelList != null)
{
channelList.State = 1;//统一将所有的状态设置为已取药待入库
channelLists.Add(channelList);
}
//if (channelList != null)
//{
// channelList.State = 1;//统一将所有的状态设置为已取药待入库
channelLists.Add(channelList);
//}
}
_ChannelLists = channelLists;
}
@ -149,7 +149,7 @@ namespace DM_Weight.ViewModels
selectedStock = _ChannelList.channelStocks.ToList();
if (selectedStock != null && selectedStock.Count > 0)
{
selectedStock.ForEach(cs => cs.ChannelLst.State = 2);
//selectedStock.ForEach(cs => cs.ChannelLst.State = 2);
int drawerNo = -1;
for (int i = 0; i < selectedStock.Count; i++)
@ -308,17 +308,22 @@ namespace DM_Weight.ViewModels
selectedStock.ForEach(cs =>
{
cs.Quantity = cs.Quantity + cs.AddToJJNum;
cs.NeedNum = 0;
//cs.NeedNum = 0;
cs.AddToJJNum = 0;
//cs.State = 0;
});
SqlSugarHelper.Db.Updateable(selectedStock).ExecuteCommand();
// 更新交接柜状态为 已取药未入库
SqlSugarHelper.Db.Updateable(new ChannelList()
{
State = 0
}).UpdateColumns(it => it.State).Where(it => it.DrawerNo == _ChannelList.DrawerNo).ExecuteCommand();
//SqlSugarHelper.Db.Updateable(new ChannelList()
//{
// State = 0
//}).UpdateColumns(it => it.State).Where(it => it.DrawerNo == _ChannelList.DrawerNo).ExecuteCommand();
for (int i = 0; i < selectedStock.Count; i++)
{
int iUpdateResult = SqlSugarHelper.Db.Updateable<ChannelStock>()
.SetColumns(cs => new ChannelStock() { State = 0 })
.Where(cs => cs.DrawerNo == selectedStock[i].DrawerNo && cs.DrugId == selectedStock[i].DrugId && cs.MachineId == selectedStock[i].MachineId)
.ExecuteCommand();
string InvoiceId = "AddJiaoJieFromDM_" + CurrentTimeMillis();
// 保存记录
SqlSugarHelper.Db.Insertable(new MachineRecord()
@ -392,7 +397,7 @@ namespace DM_Weight.ViewModels
{
if (channelStock != null)
{
if (channelStock.ChannelLst.State == 1)
if (channelStock.State == 1)
{
channelStock.ChannelLst.IsSelected = !channelStock.ChannelLst.IsSelected;
}

View File

@ -316,6 +316,7 @@ namespace DM_Weight.ViewModels
MachineId = "DM5",
AddToJJNum = 0,
NeedNum = baseQuantity,
State=0
//ManuNo=DrugManuNo.ManuNo
}).ExecuteCommand();
// 保存数据 入库记录
@ -455,7 +456,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 +467,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

@ -1074,7 +1074,7 @@ namespace DM_Weight.ViewModels
{
AlertMsg alertMsg = new AlertMsg
{
Message = $"处方{oi.OrderNo}药品批次{oi._OrderDetail.SetManuNo}无库存,无法确认",
Message = $"处方{oi.OrderNo}药品批次{oi._OrderDetail.SetManuNo}无库存,无法确认",
Type = MsgType.ERROR,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);

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,15 +181,16 @@ 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();
SqlSugarHelper.Db.Updateable(new ChannelList()
{
NeedNum = 0,
AddToJJNum = 0,
State = 0,
Id = it.Chnguid
}).UpdateColumns(cl => new { cl.State }).ExecuteCommand();
}).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate, it.NeedNum, it.AddToJJNum }).ExecuteCommand();
//SqlSugarHelper.Db.Updateable(new ChannelList()
//{
// State = 0,
// Id = it.Chnguid
//}).UpdateColumns(cl => new { cl.State }).ExecuteCommand();
// 保存数据 盘点记录
SqlSugarHelper.Db.Insertable(new MachineRecord()
@ -191,7 +206,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 +272,7 @@ namespace DM_Weight.ViewModels
{
if (_channelStock != null)
{
}
});
}

View File

@ -127,16 +127,16 @@ namespace DM_Weight.ViewModels
// _eventAggregator = eventAggregator;
//}
public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil, FingerprintUtil fingerprintUtil,SocketHelper socketHelper)
public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil, FingerprintUtil fingerprintUtil, SocketHelper socketHelper)
{
_fingerprintUtil = fingerprintUtil;
_portUtil = portUtil;
//_chkFunction= chcFunction;
_regionManager = regionManager;
_eventAggregator = eventAggregator;
_socketHelper= socketHelper;
_socketHelper = socketHelper;
FingerMsg = !_fingerprintUtil.bIsConnected;
NetMsg=!_socketHelper.ConnectedStatus;
NetMsg = !_socketHelper.ConnectedStatus;
_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
}
private DelegateCommand? _loginCommand;
@ -277,7 +277,7 @@ _exitCommand ??= new DelegateCommand(Exit);
keys.Add("operator", user);
//System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
//{
_regionManager.RequestNavigate("MainRegion", "HomeWindow", keys);
_regionManager.RequestNavigate("MainRegion", "HomeWindow", keys);
//}));
}
// 双人登录模式
@ -377,6 +377,8 @@ _exitCommand ??= new DelegateCommand(Exit);
void Exit()
{
//_chkFunction.HIKLoginOut();
//清录屏进程
_eventAggregator.GetEvent<PrintScreenEvent>().Publish(2);
_socketHelper.SocketDisConnect();
Process.GetCurrentProcess().Kill();
Environment.Exit(0);
@ -465,6 +467,8 @@ _exitCommand ??= new DelegateCommand(Exit);
{
//FingerMsg = !_fingerprintUtil.bIsConnected;
//_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
//结束录屏
_eventAggregator.GetEvent<PrintScreenEvent>().Publish(0);
}
@ -478,6 +482,10 @@ _exitCommand ??= new DelegateCommand(Exit);
public void OnNavigatedFrom(NavigationContext navigationContext)
{
_eventAggregator.GetEvent<FingerprintEvent>().Unsubscribe(LoginEvent);
#region
//登录进来后开始录屏
_eventAggregator.GetEvent<PrintScreenEvent>().Publish(1);
#endregion
}
//手动实现调用配置的逻辑 规避修改配置文件后不起作用的问题
public string ReadAppSetting(string key)

View File

@ -1,30 +1,40 @@
using MaterialDesignThemes.Wpf;
using DM_Weight.Finger;
using DM_Weight.HIKVISION;
using DM_Weight.Models;
using DM_Weight.msg;
using DM_Weight.Port;
using DM_Weight.util;
using DM_Weight.Views;
using log4net;
using log4net.Repository.Hierarchy;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using ScreenRecorderLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using DM_Weight.msg;
using DM_Weight.Port;
using DM_Weight.util;
using DM_Weight.Finger;
using DM_Weight.Views;
using Unity;
using DM_Weight.HIKVISION;
using log4net.Repository.Hierarchy;
using log4net;
using DM_Weight.Models;
using System.Windows;
using System.Windows.Media;
using Unity;
namespace DM_Weight.ViewModels
{
internal class MainWindowViewModel : BindableBase
{
#region
public Recorder _recorder;
private string _outputFolder;
private string _outputFilePath;
public static MainWindowViewModel vm;
#endregion
private string _title = "Prism App"; //标题
private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3));
@ -74,9 +84,11 @@ namespace DM_Weight.ViewModels
private PortUtil _portUtil;
public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil, SocketHelper socketHelper, PortUtil portUtil)
{
vm = this;
_portUtil = portUtil;
this.eventAggregator = eventAggregator;
this.eventAggregator.GetEvent<SnackbarEvent>().Subscribe(doMyPrismEvent2);
this.eventAggregator.GetEvent<PrintScreenEvent>().Subscribe(PrintScreen);
_fingerprintUtil = fingerprintUtil;
_regionManager = regionManager;
_container = container;
@ -146,6 +158,90 @@ namespace DM_Weight.ViewModels
SnackbarMessageQueue.Enqueue(msg.Message);
}));
}
#region
/// <summary>
/// 录屏事件
/// </summary>
/// <param name="type">0停止录屏1开始录屏2退出软件清进程</param>
void PrintScreen(int type)
{
if (type == 0)
{
StopPrintScreen();
//删除7天前的录屏文件
if (Directory.Exists(_outputFolder))
{
var files = Directory.GetFiles(_outputFolder);
foreach (var file in files)
{
var fileInfo = new FileInfo(file);
if (fileInfo.CreationTime < DateTime.Now.AddDays(-7))
{
try
{
fileInfo.Delete();
}
catch (Exception ex)
{
logger.Error($"删除录屏文件失败: {ex.Message}");
}
}
}
}
}
else if (type == 1)
{
StartPrintScreen();
}
else if (type == 2)
{
_recorder?.Dispose();
}
}
#endregion
void StopPrintScreen()
{
//退出登录结束录屏
_recorder?.Stop();
}
//录屏
void StartPrintScreen()
{
// 创建输出目录
_outputFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "Log", "ScreenRecordings");
if (!Directory.Exists(_outputFolder))
{
Directory.CreateDirectory(_outputFolder);
}
// 生成输出文件名
string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
_outputFilePath = Path.Combine(_outputFolder, $"{timestamp}.mp4");
// 设置录制选项
var options = new RecorderOptions();
// 创建录制器实例
_recorder = Recorder.CreateRecorder(options);
// 设置事件处理
_recorder.OnRecordingComplete += Recorder_OnRecordingComplete;
_recorder.OnRecordingFailed += Recorder_OnRecordingFailed;
// 开始录制
_recorder.Record(_outputFilePath);
}
//录制失败
private void Recorder_OnRecordingFailed(object sender, RecordingFailedEventArgs e)
{
logger.Info($"录制失败: {e.Error}");
}
//录制完成
private void Recorder_OnRecordingComplete(object sender, RecordingCompleteEventArgs e)
{
logger.Info($"录制完成: {e.FilePath}");
}
}
}

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

@ -240,9 +240,21 @@
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="100"
DisplayMemberBinding="{Binding State,Converter={StaticResource StockStatusConverter},ConverterParameter=TextState}"
Header="状态"/>
<GridViewColumn Width="130"
Header="状态">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding channelStocks}" materialDesign:ListBoxItemAssist.ShowSelection="False">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Width="130" Text="{Binding State,Converter={StaticResource StockStatusConverter},ConverterParameter=TextState}">
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>

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

View File

@ -1,4 +1,10 @@
using Prism.Events;
using DM_Weight.msg;
using DM_Weight.Port;
using DM_Weight.util;
using DM_Weight.ViewModels;
using log4net;
using log4net.Repository.Hierarchy;
using Prism.Events;
using Prism.Ioc;
using Prism.Regions;
using System;
@ -16,11 +22,6 @@ using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Unity;
using Unity.Lifetime;
using DM_Weight.msg;
using DM_Weight.util;
using log4net.Repository.Hierarchy;
using DM_Weight.Port;
using log4net;
namespace DM_Weight.Views
{
@ -31,10 +32,12 @@ namespace DM_Weight.Views
{
//IRegionManager _regionManager;
//IUnityContainer _container;
MainWindowViewModel vms;
private readonly ILog logger = LogManager.GetLogger(typeof(PortUtil));
public MainWindow()
{
InitializeComponent();
vms = MainWindowViewModel.vm;
//_regionManager = regionManager;
//_container = container;
//System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
@ -46,6 +49,10 @@ namespace DM_Weight.Views
//}));
}
protected override void OnClosed(EventArgs e)
{
vms._recorder?.Dispose();
base.OnClosed(e);
}
}
}

View File

@ -0,0 +1,13 @@
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.msg
{
internal class PrintScreenEvent : PubSubEvent<int>
{
}
}