From 27c9afd75f2e90e625d73ab02b0d1e8c8fa5e390 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Wed, 23 Apr 2025 14:14:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9B=98=E7=82=B9=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/App.xaml.cs | 4 + .../ViewModels/CheckStockWindowViewModel.cs | 248 ++++++++++++++++++ .../ViewModels/ConfirmDialogViewModel.cs | 66 +++++ .../ViewModels/RoleManagerWindowViewModel.cs | 7 + DM_Weight/Views/CheckStockWindow.xaml | 191 +++++--------- DM_Weight/Views/Dialog/ConfirmDialog.xaml | 48 ++++ DM_Weight/Views/Dialog/ConfirmDialog.xaml.cs | 28 ++ 7 files changed, 473 insertions(+), 119 deletions(-) create mode 100644 DM_Weight/ViewModels/CheckStockWindowViewModel.cs create mode 100644 DM_Weight/ViewModels/ConfirmDialogViewModel.cs create mode 100644 DM_Weight/Views/Dialog/ConfirmDialog.xaml create mode 100644 DM_Weight/Views/Dialog/ConfirmDialog.xaml.cs diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index 9c81398..c9a5bdd 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -289,6 +289,10 @@ namespace DM_Weight containerRegistry.RegisterForNavigation(); containerRegistry.RegisterDialog(); containerRegistry.RegisterForNavigation(); + //盘点 + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterDialog(); + containerRegistry.RegisterForNavigation(); #endregion // 设备记录页面 diff --git a/DM_Weight/ViewModels/CheckStockWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockWindowViewModel.cs new file mode 100644 index 0000000..841a11f --- /dev/null +++ b/DM_Weight/ViewModels/CheckStockWindowViewModel.cs @@ -0,0 +1,248 @@ +using Common.Logging; +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.util; +using log4net; +using MaterialDesignThemes.Wpf; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Reflection.Metadata.Ecma335; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace DM_Weight.ViewModels +{ + public class CheckStockWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime + { + private readonly log4net.ILog logger = log4net.LogManager.GetLogger(typeof(CheckStockWindowViewModel)); + private int _drawerNo = 0; + + public int DrawerNo + { + get => _drawerNo; + set => SetProperty(ref _drawerNo, value); + } + + private SolidColorBrush _colorBrush; + + public SolidColorBrush SnackbarBackground + { + get => _colorBrush; + set => SetProperty(ref _colorBrush, value); + } + + private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3)); + + public ISnackbarMessageQueue SnackbarMessageQueue + { + get => _snackbarMessageQueue; + set => SetProperty(ref _snackbarMessageQueue, value); + } + + private List _channelStocks = new(); + + public List ChannelStocks + { + get => _channelStocks; + set => SetProperty(ref _channelStocks, value); + } + private bool _isEnable = true; + public bool IsEnable { get => _isEnable; set => SetProperty(ref _isEnable, value); } + private int _status = 0; + public int Status { get => _status; set { SetProperty(ref _status, value); } } + + + private readonly IDialogService _dialogService; + + public bool KeepAlive => false; + IEventAggregator _eventAggregator; + public CheckStockWindowViewModel(IDialogService dialogService, IEventAggregator eventAggregator) + { + _dialogService = dialogService; + _eventAggregator = eventAggregator; + } + + private void RequestData() + { + List queryData = SqlSugarHelper.Db.Queryable() + .Includes(cs => cs.DrugInfo) + .Where(cs => cs.DrawerNo == DrawerNo + 1) + .Where(cs => cs.DrugId != null) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5")) + .OrderBy(cs => cs.DrugId) + .ToList(); + ChannelStocks = queryData.Select(it => { it.CheckQuantity = it.Quantity; return it; }).ToList(); + } + + public void OnNavigatedTo(NavigationContext navigationContext) + { + logger.Info("进入OnNavigatedTo"); + RequestData(); + logger.Info("结束RequestData"); + } + + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + public void OnNavigatedFrom(NavigationContext navigationContext) + { + // 取消消息订阅 + //_eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + + + public DelegateCommand UpdateDrawerNo + { + get => new DelegateCommand((DrawerNo) => + { + this.DrawerNo = Convert.ToInt32(DrawerNo); + RequestData(); + } + ); + } + private static readonly DateTime Jan1st1970 = new DateTime + (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + public long CurrentTimeMillis() + { + return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; + } + //保存修改的库存数 + public DelegateCommand SaveCommand + { + get => new DelegateCommand(() => + { + List record = ChannelStocks.FindAll(it => it.Quantity != it.CheckQuantity).ToList(); + if (record.Count > 0) + { + bool iFlag = true; + string InvoiceId = "CHECK_" + CurrentTimeMillis(); + var f = SqlSugarHelper.Db.UseTran(() => + { + + for (int i = 0; i < record.Count; i++) + { + iFlag = true; + ChannelStock it = record[i]; + if (it.AddToJJNum > 0 || it.NeedNum > 0) + { + //有待取药或待入库药品,弹出提示,确认后保存 + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("ConfirmInfo", $"所选药品{it.DrugInfo.DrugName}存在待取药或待入库数据是否确认保存?"); + DialogServiceExtensions.ShowDialogHost(_dialogService, "ConfirmDialog", dialogParameters, (IDialogResult dialogResult) => + { + if (dialogResult.Result == ButtonResult.OK) + { + iFlag = true; + } + else + { + iFlag = false; + } + }, "RootDialog"); + } + if (iFlag) + { + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = it.CheckQuantity, + 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() + { + State=0, + Id=it.Chnguid + }).UpdateColumns(cl => new { cl.State }).ExecuteCommand(); + + // 保存数据 盘点记录 + 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 = it.CheckQuantity - it.Quantity, + Type = 4, + InvoiceId = InvoiceId + //,StockQuantity = nowChannels.Sum(it => it.Quantity), + //CheckQuantity = it.CheckQuantity + }).ExecuteCommand(); + + + logger.Info($"库存盘点->药箱号【{it.DrawerNo}】药品【{it.DrugInfo.DrugName}】盘点前库存【{it.Quantity}】,更改后【{it.CheckQuantity}】"); + } + else + { + return false; + break; + } + } + return true; + }); + if (!iFlag) + { + return; + } + if (f.Data) + { + RequestData(); + AlertMsg alertMsg = new AlertMsg + { + Message = "操作完成", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + if (!f.IsSuccess) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "操作失败!", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + Status = 0; + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "盘点完成,库存无改变", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Status = 0; + } + }); + } + + //刷新 + public DelegateCommand Query + { + get => new DelegateCommand(RequestData); + } + } +} diff --git a/DM_Weight/ViewModels/ConfirmDialogViewModel.cs b/DM_Weight/ViewModels/ConfirmDialogViewModel.cs new file mode 100644 index 0000000..f1e2bfd --- /dev/null +++ b/DM_Weight/ViewModels/ConfirmDialogViewModel.cs @@ -0,0 +1,66 @@ +using DM_Weight.Models; +using Prism.Commands; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.ViewModels +{ + public class ConfirmDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime + { + private string _title = "保存确认"; + + public string Title + { + get => _title; + set => SetProperty(ref _title, value); + } + + private string _confirmInfo= "所选药品存在待取药或待入库数据是否确认保存?"; + public string ConfirmInfo + { + get => _confirmInfo; + set => SetProperty(ref _confirmInfo, value); + } + + public bool KeepAlive => false; + + public event Action RequestClose; + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + } + + public void OnDialogOpened(IDialogParameters parameters) + { + + ConfirmInfo = parameters.GetValue("ConfirmInfo"); + } + public DelegateCommand CancelCommand + { + get => new DelegateCommand(() => + { + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + }); + } + public DelegateCommand ConfirmCommand + { + get => new DelegateCommand(() => + { + //确认 + RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); + }); + } + } +} diff --git a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs index ff2cf9e..3ac2852 100644 --- a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs +++ b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs @@ -520,6 +520,12 @@ namespace DM_Weight.ViewModels PremissionName = "登录设置", PremissionPath = "SettingWindow", }; + PremissionDm sysset4 = new PremissionDm + { + Id = 58, + PremissionName = "盘点", + PremissionPath = "CheckStockWindow", + }; syssetChild.Add(sysset1); syssetChild.Add(sysset2); syssetChild.Add(syssetLogin); @@ -527,6 +533,7 @@ namespace DM_Weight.ViewModels syssetChild.Add(machineRecord); syssetChild.Add(wSDRecord); syssetChild.Add(sysset3); + syssetChild.Add(sysset4); sysset.Children = syssetChild; defaultAll.Add(sysset); #endregion diff --git a/DM_Weight/Views/CheckStockWindow.xaml b/DM_Weight/Views/CheckStockWindow.xaml index 93f8835..84d56a8 100644 --- a/DM_Weight/Views/CheckStockWindow.xaml +++ b/DM_Weight/Views/CheckStockWindow.xaml @@ -32,44 +32,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/Dialog/ConfirmDialog.xaml b/DM_Weight/Views/Dialog/ConfirmDialog.xaml new file mode 100644 index 0000000..70a6f90 --- /dev/null +++ b/DM_Weight/Views/Dialog/ConfirmDialog.xaml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + +