From 3df79378b772b7463a4678ed0321e2e480b75d11 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Sun, 4 Feb 2024 13:35:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=8D=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E3=80=81=E6=96=B0=E5=A2=9E=E5=A4=9A=E6=89=B9?= =?UTF-8?q?=E6=AC=A1=E5=85=A5=E5=BA=93=E3=80=81=E4=BF=AE=E6=94=B9=E8=B0=83?= =?UTF-8?q?=E6=8B=A8=E5=85=A5=E5=BA=93=E3=80=81=E6=B7=BB=E5=8A=A0=E8=B4=A6?= =?UTF-8?q?=E5=86=8C=E9=A1=B5=E9=9D=A2=E3=80=81=E4=BF=AE=E6=94=B9=E7=9B=98?= =?UTF-8?q?=E7=82=B9=E9=A1=B5=E9=9D=A2=E3=80=81=E6=B7=BB=E5=8A=A0=E7=9B=98?= =?UTF-8?q?=E7=82=B9=E8=AE=B0=E5=BD=95=E9=A1=B5=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/App.config | 20 +- DM_Weight/App.xaml | 2 +- DM_Weight/App.xaml.cs | 67 +- DM_Weight/Converter/GroupSumConverter.cs | 10 +- DM_Weight/Converter/TotalCountConverter.cs | 33 + DM_Weight/DM_Weight.csproj | 13 + DM_Weight/Finger/FingerprintUtil.cs | 34 +- DM_Weight/Models/AccountModel.cs | 87 ++ DM_Weight/Models/AccountType.cs | 23 + DM_Weight/Models/ChannelList.cs | 184 +++++ DM_Weight/Models/ChannelStock.cs | 7 + DM_Weight/Models/ChannelStockCount.cs | 25 + DM_Weight/Models/CheckRecordStock.cs | 94 +++ DM_Weight/Models/Class1.cs | 77 ++ DM_Weight/Models/InOutInvoice.cs | 6 + DM_Weight/Models/MachineRecord.cs | 10 + DM_Weight/Port/PortUtil.cs | 136 +++- DM_Weight/Report/GridReportUtil.cs | 74 +- DM_Weight/ReportTemp/account_book_temp.grf | 23 +- DM_Weight/ReportTemp/machine_log_add.grf | 1 - DM_Weight/ReportTemp/machine_log_check.grf | 25 +- .../ReportTemp/machine_log_check_new.grf | 313 ++++++++ .../ReportTemp/machine_log_check_new2.grf | 278 +++++++ DM_Weight/ReportTemp/machine_log_return.grf | 1 - DM_Weight/ReportTemp/machine_log_take.grf | 1 - DM_Weight/ReportTemp/stock_template.grf | 1 - DM_Weight/Services/ChannelStockService.cs | 37 + DM_Weight/Services/MachineRecordService.cs | 79 ++ DM_Weight/Services/UserService.cs | 54 ++ .../ViewModels/AccountWindowViewModel.cs | 414 ++++++++++ .../ViewModels/AddDrugControlViewModel.cs | 545 +++++++++++++ .../BindingChannelDialogViewModel.cs | 47 +- .../BindingChannelNewDialogViewModel.cs | 544 +++++++++++++ .../ViewModels/ChangeShiftsDialogViewModel.cs | 38 +- .../ChangeShiftsListWindowViewModel.cs | 10 +- .../ChangeShiftsRecordWindowViewModel.cs | 4 +- .../ViewModels/ChangeShiftsWindowViewModel.cs | 26 +- .../CheckRecordDetailDialogViewModel.cs | 198 +++++ .../CheckRecordNewWindowViewModel.cs | 211 +++++ .../CheckStockNew2WindowViewModel.cs | 604 ++++++++++++++ .../CheckStockNewWindowViewModel.cs | 647 +++++++++++++++ .../ViewModels/CheckStockWindowViewModel.cs | 21 +- .../DrawerAddDrugWindowViewModel.cs | 68 +- .../DrawerTakeDrugWindowViewModel.cs | 72 +- .../ViewModels/DrugListWindowViewModel.cs | 114 ++- .../ViewModels/EditUserDialogViewModel.cs | 16 +- .../ViewModels/FingerprintDialogViewModel.cs | 2 +- DM_Weight/ViewModels/HomeWindowViewModel.cs | 310 +++++-- .../ViewModels/InvoiceAddDialogViewModel.cs | 122 ++- .../InvoiceInNewWindow2ViewModel.cs | 626 +++++++++++++++ .../ViewModels/InvoiceInNewWindowViewModel.cs | 754 ++++++++++++++++++ .../ViewModels/InvoiceInWindowViewModel.cs | 36 +- .../ViewModels/InvoiceOutWindowViewModel.cs | 11 +- .../ViewModels/InvoiceTakeDialogViewModel.cs | 49 +- DM_Weight/ViewModels/LoginWindowViewModel.cs | 141 ++-- .../MachineRecordWindowViewModel.cs | 77 +- DM_Weight/ViewModels/MainWindowViewModel.cs | 26 +- DM_Weight/ViewModels/MaskDialogViewModel.cs | 33 + .../ViewModels/OrderReturnDialogViewModel.cs | 71 +- .../ViewModels/OrderTakeDialogViewModel.cs | 94 ++- .../OrderTakeDrugWindowViewModel.cs | 47 +- .../ViewModels/ReturnDrugDialogViewModel.cs | 27 +- .../ViewModels/ReturnDrugWindow2ViewModel.cs | 12 +- .../ViewModels/ReturnDrugWindowViewModel.cs | 10 +- .../ViewModels/ReturnEmptyDialogViewModel.cs | 18 +- .../ViewModels/ReturnEmptyWindowViewModel.cs | 9 +- .../ViewModels/RoleManagerWindowViewModel.cs | 61 +- .../ViewModels/SelfAddDialogViewModel.cs | 86 +- .../SelfAddWindowViewModel - 复制.cs | 211 +++++ .../ViewModels/SelfAddWindowViewModel.cs | 86 +- .../ViewModels/SelfTakeDialogViewModel.cs | 69 +- .../ViewModels/SelfTakeDrugWindowViewModel.cs | 74 +- .../ViewModels/SettingWindowViewModel.cs | 4 +- .../StockListAccountDialogViewModel.cs | 136 ++++ .../ViewModels/StockListWindowViewModel.cs | 148 +++- DM_Weight/ViewModels/TestCheckBoxViewModel.cs | 22 - .../ViewModels/UserManagerWindowViewModel.cs | 9 +- DM_Weight/Views/AccountWindow.xaml | 257 ++++++ DM_Weight/Views/AccountWindow.xaml.cs | 53 ++ DM_Weight/Views/AddDrugControl.xaml | 395 +++++++++ DM_Weight/Views/AddDrugControl.xaml.cs | 41 + DM_Weight/Views/CheckRecordNewWindow.xaml | 203 +++++ DM_Weight/Views/CheckRecordNewWindow.xaml.cs | 28 + DM_Weight/Views/CheckStockNew2Window.xaml | 195 +++++ DM_Weight/Views/CheckStockNew2Window.xaml.cs | 60 ++ DM_Weight/Views/CheckStockNewWindow.xaml | 220 +++++ DM_Weight/Views/CheckStockNewWindow.xaml.cs | 60 ++ .../Views/Dialog/BindingChannelNewDialog.xaml | 237 ++++++ .../Dialog/BindingChannelNewDialog.xaml.cs | 48 ++ .../Views/Dialog/CheckRecordDetailDialog.xaml | 122 +++ .../Dialog/CheckRecordDetailDialog.xaml.cs | 28 + DM_Weight/Views/Dialog/MaskDialog.xaml | 12 + DM_Weight/Views/Dialog/MaskDialog.xaml.cs | 28 + .../Views/Dialog/StockListAccountDialog.xaml | 59 ++ .../Dialog/StockListAccountDialog.xaml.cs | 28 + DM_Weight/Views/DrawerAddDrugWindow.xaml | 13 +- DM_Weight/Views/HomeWindow.xaml | 37 +- DM_Weight/Views/InvoiceInNewWindow.xaml | 309 +++++++ DM_Weight/Views/InvoiceInNewWindow.xaml.cs | 40 + DM_Weight/Views/LoginWindow.xaml | 4 +- DM_Weight/Views/MachineRecordWindow.xaml | 16 +- DM_Weight/Views/OrderTakeDrugWindow.xaml | 40 +- DM_Weight/Views/SelfAddWindow - 复制.xaml | 238 ++++++ DM_Weight/Views/SelfAddWindow - 复制.xaml.cs | 28 + DM_Weight/Views/SelfAddWindow.xaml | 116 +-- DM_Weight/Views/SelfTakeDrugWindow.xaml | 111 +-- DM_Weight/Views/StockListWindow.xaml | 108 ++- DM_Weight/Views/StockListWindow.xaml.cs | 36 +- DM_Weight/msg/AddDrugEvent.cs | 14 + 109 files changed, 11038 insertions(+), 821 deletions(-) create mode 100644 DM_Weight/Converter/TotalCountConverter.cs create mode 100644 DM_Weight/Models/AccountModel.cs create mode 100644 DM_Weight/Models/AccountType.cs create mode 100644 DM_Weight/Models/ChannelList.cs create mode 100644 DM_Weight/Models/ChannelStockCount.cs create mode 100644 DM_Weight/Models/CheckRecordStock.cs create mode 100644 DM_Weight/Models/Class1.cs create mode 100644 DM_Weight/ReportTemp/machine_log_check_new.grf create mode 100644 DM_Weight/ReportTemp/machine_log_check_new2.grf create mode 100644 DM_Weight/Services/ChannelStockService.cs create mode 100644 DM_Weight/Services/MachineRecordService.cs create mode 100644 DM_Weight/Services/UserService.cs create mode 100644 DM_Weight/ViewModels/AccountWindowViewModel.cs create mode 100644 DM_Weight/ViewModels/AddDrugControlViewModel.cs create mode 100644 DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs create mode 100644 DM_Weight/ViewModels/CheckRecordDetailDialogViewModel.cs create mode 100644 DM_Weight/ViewModels/CheckRecordNewWindowViewModel.cs create mode 100644 DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs create mode 100644 DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs create mode 100644 DM_Weight/ViewModels/InvoiceInNewWindow2ViewModel.cs create mode 100644 DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs create mode 100644 DM_Weight/ViewModels/MaskDialogViewModel.cs create mode 100644 DM_Weight/ViewModels/SelfAddWindowViewModel - 复制.cs create mode 100644 DM_Weight/ViewModels/StockListAccountDialogViewModel.cs delete mode 100644 DM_Weight/ViewModels/TestCheckBoxViewModel.cs create mode 100644 DM_Weight/Views/AccountWindow.xaml create mode 100644 DM_Weight/Views/AccountWindow.xaml.cs create mode 100644 DM_Weight/Views/AddDrugControl.xaml create mode 100644 DM_Weight/Views/AddDrugControl.xaml.cs create mode 100644 DM_Weight/Views/CheckRecordNewWindow.xaml create mode 100644 DM_Weight/Views/CheckRecordNewWindow.xaml.cs create mode 100644 DM_Weight/Views/CheckStockNew2Window.xaml create mode 100644 DM_Weight/Views/CheckStockNew2Window.xaml.cs create mode 100644 DM_Weight/Views/CheckStockNewWindow.xaml create mode 100644 DM_Weight/Views/CheckStockNewWindow.xaml.cs create mode 100644 DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml create mode 100644 DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml.cs create mode 100644 DM_Weight/Views/Dialog/CheckRecordDetailDialog.xaml create mode 100644 DM_Weight/Views/Dialog/CheckRecordDetailDialog.xaml.cs create mode 100644 DM_Weight/Views/Dialog/MaskDialog.xaml create mode 100644 DM_Weight/Views/Dialog/MaskDialog.xaml.cs create mode 100644 DM_Weight/Views/Dialog/StockListAccountDialog.xaml create mode 100644 DM_Weight/Views/Dialog/StockListAccountDialog.xaml.cs create mode 100644 DM_Weight/Views/InvoiceInNewWindow.xaml create mode 100644 DM_Weight/Views/InvoiceInNewWindow.xaml.cs create mode 100644 DM_Weight/Views/SelfAddWindow - 复制.xaml create mode 100644 DM_Weight/Views/SelfAddWindow - 复制.xaml.cs create mode 100644 DM_Weight/msg/AddDrugEvent.cs diff --git a/DM_Weight/App.config b/DM_Weight/App.config index 641ab62..f36dcbe 100644 --- a/DM_Weight/App.config +++ b/DM_Weight/App.config @@ -3,7 +3,7 @@ - + + + + + - + @@ -24,7 +28,7 @@ - + @@ -36,11 +40,11 @@ - + - + - + - + - + diff --git a/DM_Weight/App.xaml b/DM_Weight/App.xaml index ef8d445..704fc50 100644 --- a/DM_Weight/App.xaml +++ b/DM_Weight/App.xaml @@ -6,7 +6,7 @@ d1p1:Ignorable="d" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:local="clr-namespace:DM_Weight" - xmlns:prism="http://prismlibrary.com/"> + xmlns:prism="http://prismlibrary.com/" Startup="PrismApplication_Startup"> diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index 3327878..3015529 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -26,6 +26,9 @@ using System.Timers; using DM_Weight.Models; using SqlSugar; using Microsoft.Extensions.DependencyInjection; +using DM_Weight.Services; +using System.Diagnostics; +using System.Runtime.InteropServices; namespace DM_Weight { @@ -114,7 +117,7 @@ namespace DM_Weight // 串口工具 containerRegistry.RegisterSingleton(); // 指纹机工具 - //containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); // 组态屏工具 containerRegistry.RegisterSingleton(); @@ -164,6 +167,8 @@ namespace DM_Weight containerRegistry.RegisterForNavigation(); // 调拨加药页面 containerRegistry.RegisterForNavigation(); + // 调拨加药页面 + containerRegistry.RegisterForNavigation(); // 调拨取药模态框 containerRegistry.RegisterDialog(); @@ -173,6 +178,8 @@ namespace DM_Weight // 自选加药模态框 containerRegistry.RegisterDialog(); containerRegistry.RegisterForNavigation(); + //多批次抽屉加药 + containerRegistry.RegisterForNavigation(); #endregion #region 还药 @@ -200,11 +207,24 @@ namespace DM_Weight // 库位绑定模态框 containerRegistry.RegisterDialog(); containerRegistry.RegisterForNavigation(); + + // 库位绑定模态框 + containerRegistry.RegisterDialog(); + containerRegistry.RegisterForNavigation(); // 库存盘点页面 containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterDialog(); + containerRegistry.RegisterForNavigation(); + // 库存盘点页面--新(类似库存列表页面) + containerRegistry.RegisterForNavigation(); + // 库存盘点页面--新(类似库存列表页面) + containerRegistry.RegisterForNavigation(); + // 库存盘点页面--新(类似库存列表页面) + containerRegistry.RegisterForNavigation(); // 药品列表页面 containerRegistry.RegisterForNavigation(); - + //库存列表导出账册弹窗 + containerRegistry.RegisterForNavigation(); #endregion #region 系统设置 @@ -239,9 +259,48 @@ namespace DM_Weight containerRegistry.RegisterSingleton(() => SqlSugarHelperNew.GetInstance()); - containerRegistry.RegisterForNavigation(); - + //账册页面 + containerRegistry.RegisterForNavigation(); + //账册服务类 + containerRegistry.Register(); } + + private void PrismApplication_Startup(object sender, StartupEventArgs e) + { + //获取欲启动程序名 + string processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; + //检查程序是否已经启动,已经启动则显示提示退出程序 + if (System.Diagnostics.Process.GetProcessesByName(processName).Length > 1) + { + //系统在运行 + RaiseOtherProcess(); + Application.Current.Shutdown(); + return; + } + } + private static void RaiseOtherProcess() + { + Process proc = Process.GetCurrentProcess(); + foreach (Process otherProc in Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName)) + { + if (proc.Id != otherProc.Id) + { + IntPtr hWnd = otherProc.MainWindowHandle; + if (IsIconic(hWnd)) + { + ShowWindowAsync(hWnd, 9); + } + SetForegroundWindow(hWnd); + break; + } + } + } + [DllImport("user32.dll")] + private static extern bool SetForegroundWindow(IntPtr hWnd); + [DllImport("user32.dll")] + private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); + [DllImport("user32.dll")] + private static extern bool IsIconic(IntPtr hWnd); //protected IServiceProvider ConfigureServices(IServiceCollection services) //{ // // 创建 SqlSugar 实例 diff --git a/DM_Weight/Converter/GroupSumConverter.cs b/DM_Weight/Converter/GroupSumConverter.cs index 3907e37..9917c8b 100644 --- a/DM_Weight/Converter/GroupSumConverter.cs +++ b/DM_Weight/Converter/GroupSumConverter.cs @@ -23,7 +23,15 @@ namespace DM_Weight.Converter foreach (var item in items) { var de = item as ChannelStock; - total += de.Quantity; + try + { + total += de.Quantity; + } + catch (Exception) + { + var de2 = item as CheckRecordStock; + total = de2.quantity; + } } } return "总库存:" + total; diff --git a/DM_Weight/Converter/TotalCountConverter.cs b/DM_Weight/Converter/TotalCountConverter.cs new file mode 100644 index 0000000..0c996e7 --- /dev/null +++ b/DM_Weight/Converter/TotalCountConverter.cs @@ -0,0 +1,33 @@ +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; + +namespace DM_Weight.Converter +{ + public class TotalCountConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var total = 0; + if (value is List items) + { + foreach (var item in items) + { + var de = item as ChannelStock; + total += de.Quantity; + } + } + return total; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/DM_Weight/DM_Weight.csproj b/DM_Weight/DM_Weight.csproj index 588c057..962e012 100644 --- a/DM_Weight/DM_Weight.csproj +++ b/DM_Weight/DM_Weight.csproj @@ -70,6 +70,7 @@ + @@ -87,6 +88,12 @@ + + + Code + + + Never @@ -106,6 +113,12 @@ Always + + Always + + + Always + Always diff --git a/DM_Weight/Finger/FingerprintUtil.cs b/DM_Weight/Finger/FingerprintUtil.cs index 27cf4eb..6388b71 100644 --- a/DM_Weight/Finger/FingerprintUtil.cs +++ b/DM_Weight/Finger/FingerprintUtil.cs @@ -20,22 +20,22 @@ namespace DM_Weight.Finger { private readonly ILog logger = LogManager.GetLogger(typeof(FingerprintUtil)); - public zkemkeeper.CZKEMClass axCZKEM1; //= new zkemkeeper.CZKEMClass(); + public zkemkeeper.CZKEMClass axCZKEM1;// = new zkemkeeper.CZKEMClass(); public bool bIsConnected = false; - private string fingerIp = ConfigurationManager.AppSettings["fingerIp"]?.ToString()??""; + private string fingerIp = ConfigurationManager.AppSettings["fingerIp"]?.ToString() ?? ""; private int fingerPort = 4370; - private int machineNumber = Convert.ToInt32(ConfigurationManager.AppSettings["machineNumber"]?.ToString()??"0"); - private int machineType = Convert.ToInt32(ConfigurationManager.AppSettings["machineType"]?.ToString()??"0"); + private int machineNumber = Convert.ToInt32(ConfigurationManager.AppSettings["machineNumber"]?.ToString() ?? "0"); + private int machineType = Convert.ToInt32(ConfigurationManager.AppSettings["machineType"]?.ToString() ?? "0"); private readonly IEventAggregator _eventAggregator; public FingerprintUtil(IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; logger.Info($"进入构造器,开始连接指纹机"); - Task.Run(() => - { + // Task.Factory.StartNew(() => + //{ ConnectionMain(); - }); + //}); } public void ConnectionMain() @@ -47,7 +47,7 @@ namespace DM_Weight.Finger logger.Info($"连接指纹机,IP:{fingerIp},端口:{fingerPort},机器号:{machineNumber},连接结果:{bIsConnected}"); if (bIsConnected) { - if (axCZKEM1.RegEvent(machineNumber, 65535)) + if (axCZKEM1.RegEvent(machineNumber, 9)) { this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx); //this.axCZKEM1.OnEnrollFinger += new zkemkeeper._IZKEMEvents_OnEnrollFingerEventHandler(axCZKEM1_OnEnrollFinger); @@ -62,7 +62,7 @@ namespace DM_Weight.Finger Result = bIsConnected, }); } - catch(Exception ex) + catch (Exception ex) { logger.Info($"连接指纹机异常{ex.Message.ToString()}"); } @@ -90,10 +90,10 @@ namespace DM_Weight.Finger Id = iEnrollNumber, FingerIndex = iFingerIndex }; - + axCZKEM1.StartIdentify(); axCZKEM1.RefreshData(1); - + logger.Info($"触发用户登记指纹事件,用户id:{iEnrollNumber}指纹索引:{iFingerIndex}登记结果:{(iActionResult == 0)}"); message.Result = (iActionResult == 0); _eventAggregator.GetEvent().Publish(message); @@ -161,8 +161,16 @@ namespace DM_Weight.Finger bool result = false; // 取消其他操作 bool res2 = axCZKEM1.CancelOperation(); - // 删除源指纹 - bool res = axCZKEM1.DelUserTmp(machineNumber, Id, FingerIndex); + if (machineType == 1) + { + // 删除源指纹 + bool res = axCZKEM1.DelUserTmp(machineNumber, Id, FingerIndex); + } + else + { + // 删除源指纹 + bool res = axCZKEM1.SSR_DelUserTmp(machineNumber, Id.ToString(), FingerIndex); + } // 添加新指纹 result = axCZKEM1.StartEnrollEx(Id.ToString(), FingerIndex, 3); return result; diff --git a/DM_Weight/Models/AccountModel.cs b/DM_Weight/Models/AccountModel.cs new file mode 100644 index 0000000..ff8fab5 --- /dev/null +++ b/DM_Weight/Models/AccountModel.cs @@ -0,0 +1,87 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.Models +{ + /// + /// 账册 + /// + public class AccountModel + { + /// + /// 总结存 + /// + public int StockQuantity { get; set; } + /// + /// 借入数量 + /// + public int InQuantity { get; set; } + /// + /// 发出数量 + /// + public int OutQuantity { get; set; } + /// + /// 日期 + /// + public string OperationTime { get; set; } + /// + /// 凭证号 + /// + public string InvoiceId { get;set; } + /// + /// 药品名称 + /// + public string DrugName { get; set; } + /// + /// 药品ID + /// + public string DrugId { get; set; } + /// + /// 单位 + /// + public string PackUnit { get; set; } + /// + /// 剂型 + /// + public string Dosage { get; set; } + /// + /// 厂家 + /// + public string Manufactory { get; set; } + /// + /// 批次 + /// + public string ManuNo { get;set; } + /// + /// 效期 + /// + public string EffDate { get; set; } + /// + /// 操作人 + /// + public string OperatorName { get;set; } + /// + /// 复核人 + /// + public string ReviewerName { get; set; } + /// + /// 规格 + /// + public string DrugSpec { get; set; } + + public DrugInfo DrugInfo { get; set; } + + /// + /// 供应单位 + /// + public string SupplierDept { get; set; } + /// + /// 领用部门 + /// + public string ReceiveDept { get; set; } + } +} diff --git a/DM_Weight/Models/AccountType.cs b/DM_Weight/Models/AccountType.cs new file mode 100644 index 0000000..54509cf --- /dev/null +++ b/DM_Weight/Models/AccountType.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.Models +{ + /// + /// 账册类型 + /// + public class AccountType + { + /// + /// 账册类型名称 + /// + public string AccountTypeName { get; set; } + /// + /// 账册类型值 + /// + public int AccountTypeValue { get; set; } + } +} diff --git a/DM_Weight/Models/ChannelList.cs b/DM_Weight/Models/ChannelList.cs new file mode 100644 index 0000000..8124e4f --- /dev/null +++ b/DM_Weight/Models/ChannelList.cs @@ -0,0 +1,184 @@ +using Prism.Commands; +using Prism.Mvvm; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.Models +{ + [SugarTable("channel_list")] + public class ChannelList : BindableBase + { + /// + /// + /// + [SugarColumn(ColumnName = "chnguid", IsPrimaryKey = true)] + //[SugarColumn(ColumnName = "id", IsPrimaryKey = true)] + public string Id { get; set; } + + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "machine_id")] + public string MachineId { get; set; } + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "row_no")] + public int DrawerNo { get; set; } + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "col_no")] + public int ColNo { get; set; } + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "pos_no")] + public int PosNo { get; set; } + + + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "drug_id")] + public string DrugId { get; set; } + + ///// + ///// + ///// 默认值: NULL + ///// + //[SugarColumn(ColumnName = "manu_no")] + //public string ManuNo { get; set; } + ///// + ///// + ///// 默认值: NULL + ///// + //[SugarColumn(ColumnName = "eff_date")] + //public string EffDate { get; set; } + ///// + ///// + ///// 默认值: NULL + ///// + //[SugarColumn(ColumnName = "quantity")] + //public int Quantity { get; set; } + + /// + /// + /// 默认值: 1 + /// + [SugarColumn(ColumnName = "drawer_type")] + public int DrawerType { get; set; } + /// + /// + /// 默认值: 1 + /// + [SugarColumn(ColumnName = "board_type")] + public int BoardType { get; set; } + /// + /// + /// 默认值: 1 + /// + [SugarColumn(ColumnName = "state")] + public int? State { get; set; } + + [SugarColumn(IsIgnore = true)] + public bool IsSelected { get; set; } + + [SugarColumn(IsIgnore = true)] + public InOutInvoice Invoice { get; set; } + + [SugarColumn(IsIgnore = true)] + public string Location + { + get => DrawerNo + "-" + ColNo; + } + //private int _addQuantity = 0; + //[SugarColumn(IsIgnore = true)] + //public int AddQuantity + //{ + // get => _addQuantity; + // set + // { + // SetProperty(ref _addQuantity, value); + // } + //} + + //private int _takeQuantity = 0; + + //[SugarColumn(IsIgnore = true)] + //public int TakeQuantity + //{ + // get => _takeQuantity; + // set + // { + // if (value > Quantity) + // { + // throw new ArgumentException("取药数量不能大于库存"); + // } + // SetProperty(ref _takeQuantity, value); + // } + //} + //private int _returnQuantity = 0; + + //[SugarColumn(IsIgnore = true)] + //public int ReturnQuantity + //{ + // get => _returnQuantity; + // set + // { + // SetProperty(ref _returnQuantity, value); + // } + //} + + //private int _checkQuantity = 0; + + + //[SugarColumn(IsIgnore = true)] + //public int CheckQuantity + //{ + // get => _checkQuantity; + // set + // { + // if (value < 0) + // { + // throw new ArgumentException("盘点数量不能是负数"); + // } + // SetProperty(ref _checkQuantity, value); + // } + //} + + + //[SugarColumn(IsIgnore = true)] + //public int? CanReturnQuantity { get; set; } + + private DrugInfo? _DrugInfo; + [Navigate(NavigateType.ManyToOne, nameof(DrugId))] + public DrugInfo Drug { get => _DrugInfo; set => SetProperty(ref _DrugInfo, value); } + + //[SugarColumn(IsIgnore = true)] + //public int process { get; set; } = 0; + + + private DrugManuNo? _drugManuNo; + [SugarColumn(IsIgnore = true)] + public DrugManuNo? drugManuNo { get => _drugManuNo; set => SetProperty(ref _drugManuNo, value); } + + private List? _channelStocks; + [Navigate(NavigateType.OneToMany, nameof(ChannelStock.Chnguid))] + public List channelStocks { get => _channelStocks; set => SetProperty(ref _channelStocks, value); } + + public int _totalCount; + [SugarColumn(IsIgnore = true)] + public int totalCount { get => _totalCount;set=> SetProperty(ref _totalCount, value); } + + } +} diff --git a/DM_Weight/Models/ChannelStock.cs b/DM_Weight/Models/ChannelStock.cs index 9046e1c..80c14c5 100644 --- a/DM_Weight/Models/ChannelStock.cs +++ b/DM_Weight/Models/ChannelStock.cs @@ -19,6 +19,8 @@ namespace DM_Weight.Models //[SugarColumn(ColumnName = "id", IsPrimaryKey = true)] public string Id { get; set; } + [SugarColumn(ColumnName = "chnguid")] + public string Chnguid { get; set; } /// /// /// 默认值: NULL @@ -185,5 +187,10 @@ namespace DM_Weight.Models //private string _manuNoEffDate; //[SugarColumn(IsIgnore = true)] //public string ManuNoEffDate { get => _manuNoEffDate; set => SetProperty(ref _manuNoEffDate, value); } + + + private ChannelList? _channelList; + [Navigate(NavigateType.ManyToOne, nameof(Chnguid))] + public ChannelList ChannelLst { get => _channelList; set => SetProperty(ref _channelList, value); } } } \ No newline at end of file diff --git a/DM_Weight/Models/ChannelStockCount.cs b/DM_Weight/Models/ChannelStockCount.cs new file mode 100644 index 0000000..97e41ab --- /dev/null +++ b/DM_Weight/Models/ChannelStockCount.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.Models +{ + public class ChannelStockCount + { + public int DrawerNo { get; set; } + public int ColNo { get; set; } + public string DrugId { get; set; } + public string ManuNo { get;set; } + public int Quantity { get;set; } + public string EffDate { get; set; } + public string DrugName { get; set; } + public string DrugSpec { get; set; } + public string Dosage { get;set; } + public string ManuFactory { get;set; } + public string SmallUnit { get;set; } + public string PackUnit { get; set; } + public string MachineId { get; set; } + } +} diff --git a/DM_Weight/Models/CheckRecordStock.cs b/DM_Weight/Models/CheckRecordStock.cs new file mode 100644 index 0000000..4054257 --- /dev/null +++ b/DM_Weight/Models/CheckRecordStock.cs @@ -0,0 +1,94 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.Models +{ + /// + /// 盘点后药品库存数 + /// + [SugarTable("check_stock")] + public class CheckRecordStock + { + [SugarColumn(ColumnName = "id", IsPrimaryKey = true)] + public int ID { get; set; } + /// + /// 抽屉号 + /// + [SugarColumn(ColumnName = "row_no")] + public int rowNo { get; set; } + /// + /// 列号 + /// + [SugarColumn(ColumnName = "col_no")] + public int colNo { get; set; } + /// + /// 数量 + /// + [SugarColumn(ColumnName = "quantity")] + public int quantity { get; set; } + /// + /// 批次 + /// + [SugarColumn(ColumnName = "manu_no")] + public string manuNo { get; set; } + /// + /// 效期 + /// + [SugarColumn(ColumnName = "eff_date")] + public string effDate { get; set; } + /// + /// 药品名称 + /// + [SugarColumn(ColumnName = "drug_name")] + public string drugName { get; set; } + /// + /// 规格 + /// + [SugarColumn(ColumnName = "drug_spec")] + public string drugSpec { get; set; } + // + [SugarColumn(ColumnName = "pack_unit")] + public string packUnit { get; set; } + /// + /// 厂商 + /// + [SugarColumn(ColumnName = "manufactory")] + public string manufactory { get; set; } + [SugarColumn(ColumnName = "max_stock")] + public int maxStock { get; set; } + [SugarColumn(ColumnName = "drug_id")] + public string drugId { get; set; } + [SugarColumn(ColumnName = "machine_id")] + public string MachineId { get; set; } + /// + /// 批次总库存 + /// + [SugarColumn(ColumnName = "manuQuantity")] + public int ManuQuantity { get; set; } + /// + /// 操作时间 + /// + [SugarColumn(ColumnName = "optdate")] + public string optdate { get; set; } + /// + /// 操作人 + /// + [SugarColumn(ColumnName = "operator")] + public string operatorUser { get; set; } + /// + /// 审核人 + /// + [SugarColumn(ColumnName = "reviewer")] + public string reviewerUser { get; set; } + + [SugarColumn(IsIgnore =true)] + public List manuNoDetails { get;set; } + + [Navigate(NavigateType.ManyToOne, nameof(drugId))] + public DrugInfo DrugInfo { get; set; } + } +} diff --git a/DM_Weight/Models/Class1.cs b/DM_Weight/Models/Class1.cs new file mode 100644 index 0000000..e03f93d --- /dev/null +++ b/DM_Weight/Models/Class1.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.Models +{ + internal class Class1 + { + } + /// /// 行政区表 + /// /// + public class DistrictModel + { /// /// 主键 /// + private int id; /// /// 代码 /// + private int code; /// /// 名称 /// + private string name; + public int Id { get { return id; } set { id = value; } } + /// /// 代码 /// + public int Code { get { return code; } set { code = value; } } + /// /// 名称 /// + public string Name { get { return name; } set { name = value; } } + } + /// /// 表 /// + public class MapSpotModel + { + private int id; //名称 + + private string name; //代码 + private int code; //个数 + private int allNumber; //面积 + private double allArea; + + + private int hCTureNumber; + + private double hCTrueArea; + + /// + /// 通过个数 + /// + private int hCTruePassNumber; //不通过个数 + private int hCTrueNoPassNumber; //通过率 + private string hCTruePassingRate; //个数 + private int jLTureNumber; //面积 + private double jLTrueArea; //通过个数 + private int jLTruePassNumber; //不通过个数 + private int jLTrueNoPassNumber; //通过率 + private string jLTruePassingRate; + private DistrictModel districtModels; + public int Id { get { return id; } set { id = value; } } + /// /// 名称 /// + public string Name { get { return name; } set { name = value; } } /// /// 代码 /// + public int Code { get { return code; } set { code = value; } } /// /// 个数 /// + public int AllNumber { get { return allNumber; } set { allNumber = value; } } /// /// 面积 /// + public double AllArea { get { return allArea; } set { allArea = value; } } /// /// 个数 /// + public int HCTureNumber { get { return hCTureNumber; } set { hCTureNumber = value; } } /// /// 面积 /// + public double HCTrueArea { get { return hCTrueArea; } set { hCTrueArea = value; } } + /// /// 通过个数 /// + public int HCTruePassNumber { get { return hCTruePassNumber; } set { hCTruePassNumber = value; } } + /// /// /// 不通过个数 /// + public int HCTrueNoPassNumber { get { return hCTrueNoPassNumber; } set { hCTrueNoPassNumber = value; } } + /// /// /// 通过率 /// + public string HCTruePassingRate { get { return hCTruePassingRate; } set { hCTruePassingRate = value; } } /// /// 个数 /// + public int JLTureNumber { get { return jLTureNumber; } set { jLTureNumber = value; } } + /// /// 面积 /// + public double JLTrueArea { get { return jLTrueArea; } set { jLTrueArea = value; } } + /// /// /// 通过个数 /// + public int JLTruePassNumber { get { return jLTruePassNumber; } set { jLTruePassNumber = value; } } + /// /// /// 不通过个数 /// + public int JLTrueNoPassNumber { get { return jLTrueNoPassNumber; } set { jLTrueNoPassNumber = value; } } + /// /// /// 监理单位已审核图斑-通过率 /// + public string JLTruePassingRate { get { return jLTruePassingRate; } set { jLTruePassingRate = value; } } + public DistrictModel DistrictModels { get { return districtModels; } set { districtModels = value; } } + } +} diff --git a/DM_Weight/Models/InOutInvoice.cs b/DM_Weight/Models/InOutInvoice.cs index 0680abd..ca8fa2c 100644 --- a/DM_Weight/Models/InOutInvoice.cs +++ b/DM_Weight/Models/InOutInvoice.cs @@ -145,5 +145,11 @@ namespace DM_Weight.Models [SugarColumn(ColumnName = "cancel_flag")] public int CancelFlag { get; set; } + [SugarColumn(IsIgnore =true)] + public int CountNum { get; set; } + + [SugarColumn(IsIgnore =true)] + public int SumQuantity { get; set; } + } } diff --git a/DM_Weight/Models/MachineRecord.cs b/DM_Weight/Models/MachineRecord.cs index 01f58b2..f9cb957 100644 --- a/DM_Weight/Models/MachineRecord.cs +++ b/DM_Weight/Models/MachineRecord.cs @@ -143,5 +143,15 @@ namespace DM_Weight.Models /// [SugarColumn(ColumnName = "manunoQuantity")] public int? ManunoQuantity { get; set; } + /// + /// 供应单位 + /// + [SugarColumn(ColumnName = "supplierDept")] + public string SupplierDept { get; set; } + /// + /// 领用部门 + /// + [SugarColumn(ColumnName = "receiveDept")] + public string ReceiveDept { get; set; } } } diff --git a/DM_Weight/Port/PortUtil.cs b/DM_Weight/Port/PortUtil.cs index f9fe969..8ce57bf 100644 --- a/DM_Weight/Port/PortUtil.cs +++ b/DM_Weight/Port/PortUtil.cs @@ -63,9 +63,9 @@ namespace DM_Weight.Port // 取药操作的窗口名【处方取药、抽屉取药、自选取药、调拨出库】 private string[] TakeNames = new string[] { "DrawerTakeDrugWindow", "OrderTakeDrugWindow", "SelfTakeDrugWindow", "InvoiceTakeDrugWindow" }; // 加药操作的窗口名【自选加药、抽屉加药、还药】 - private string[] AddNames = new string[] { "SelfAddWindow", "ReturnDrugWindow", "ReturnDrug1Window", "DrawerAddDrugWindow" }; + private string[] AddNames = new string[] { "SelfAddWindow", "ReturnDrugWindow", "ReturnDrug1Window", "DrawerAddDrugWindow", "AddDrugControl" }; // 盘点操作的窗口名【盘点】 - private string[] CheckNames = new string[] { "CheckStockWindow" }; + private string[] CheckNames = new string[] { "CheckStockWindow", "CheckStockNewWindow" }; // 归还空瓶操作的窗口名【盘点】 private string[] ReturnEmptyNames = new string[] { "ReturnEmptyWindow" }; @@ -85,7 +85,7 @@ namespace DM_Weight.Port public DateTime dateTime { get; set; } = DateTime.Now; - public async void ResetData() + public async Task ResetData() { logger.Info($"重新设置串口数据状态【{statue}】,抽屉【{DrawerNo}】"); if (!"HomeWindow".Equals(WindowName) && statue == 1) @@ -112,7 +112,7 @@ namespace DM_Weight.Port } if (BoardType == 5) { - await WriteQuantityArray(); + //await WriteQuantityArray(); } } Operate = false; @@ -139,9 +139,10 @@ namespace DM_Weight.Port if (BoardType == 4) { byte[] result = await OpenStorage(); + logger.Info($"储物箱使能返回:" + Convert.ToHexString(result)); int[] r = result.Select(it => Convert.ToInt32(it)).ToArray(); - logger.Info($"储物箱使能返回:" + string.Join("", r)); + logger.Info($"储物箱使能返回:{Convert.ToHexString(result)}"); if (r[4] != 0) { logger.Info($"储物箱使能成功"); @@ -151,6 +152,7 @@ namespace DM_Weight.Port else { string _WindowName = WindowName; + logger.Info($"储物箱使能失败r:" + string.Join("", r)); // 重新初始化数据 ResetData(); // 指令发送错误,未打开 @@ -161,7 +163,6 @@ namespace DM_Weight.Port WindowName = _WindowName, Message = "储物箱使能失败" }); - logger.Info($"储物箱使能失败r:" + string.Join("", r)); } } else @@ -190,6 +191,7 @@ namespace DM_Weight.Port else { string _WindowName = WindowName; + logger.Info($"回收箱打开失败"); // 重新初始化数据 ResetData(); // 返回消息开启失败 @@ -200,7 +202,6 @@ namespace DM_Weight.Port WindowName = _WindowName, Message = "回收箱打开失败" }); - logger.Info($"回收箱打开失败"); } } } @@ -300,6 +301,7 @@ namespace DM_Weight.Port { string _WindowName = WindowName; statue = 1; + logger.Info(ex.Message); // 重新初始化数据 ResetData(); // 返回消息 抽屉打开失败 @@ -309,7 +311,6 @@ namespace DM_Weight.Port WindowName = _WindowName, Message = $"操作异常{ex.Message}" }); - logger.Info(ex.Message); } } @@ -439,15 +440,16 @@ namespace DM_Weight.Port await BoxLockLightOff2(); } string _WindowName = WindowName; + logger.Info($"抽屉【{DrawerNo}】已关闭"); + // 重新初始化数据 - ResetData(); + await ResetData(); // 返回消息 抽屉已经关闭 _eventAggregator.GetEvent().Publish(new util.DeviceMsg() { EventType = util.EventType.DRAWERCLOSE, WindowName = _WindowName, }); - logger.Info($"抽屉【{DrawerNo}】已关闭"); } } @@ -456,6 +458,7 @@ namespace DM_Weight.Port { string _WindowName = WindowName; + logger.Info($"GetDrawerStatus异常:{ex.Message}"); // 重新初始化数据 ResetData(); _eventAggregator.GetEvent().Publish(new util.DeviceMsg() @@ -464,7 +467,6 @@ namespace DM_Weight.Port WindowName = _WindowName, Message = $"GetDrawerStatus异常:{ex.Message}" }); - logger.Info($"GetDrawerStatus异常:{ex.Message}"); } } @@ -552,9 +554,9 @@ namespace DM_Weight.Port statue = 2; string _WindowName = WindowName; + logger.Info($"储物箱关闭"); // 重新初始化数据 ResetData(); - logger.Info($"储物箱关闭"); _eventAggregator.GetEvent().Publish(new util.DeviceMsg() { EventType = util.EventType.DRAWERCLOSE, @@ -587,6 +589,8 @@ namespace DM_Weight.Port catch (Exception ex) { logger.Info($"GetBackDoorState异常{ex.Message}"); + // 重新初始化数据 + ResetData(); } } @@ -665,7 +669,44 @@ namespace DM_Weight.Port } if (_length != length) { - throw new TimeoutException($"串口【{serialPort.PortName}】交互超时"); + if(_length!=0) + { + byte[] _buffer = new byte[_length]; + serialPort.Read(_buffer, 0, _length); + logger.Info($"交互超时回复:{Convert.ToHexString(buffer)}"); + } + throw new TimeoutException($"串口【{serialPort.PortName}】交互超时"); + } + serialPort.Read(buffer, 0, length); + //} + //catch (Exception ex) + //{ + // logger.Error($"GetBufferByPort:{ex.Message}"); + //} + return buffer; + } + private byte[] GetBufferByPort(SerialPort serialPort, int length, int timeout,string operation) + { + byte[] buffer = new byte[length]; + //try + //{ + int _length = 0; + DateTime start = DateTime.Now; + DateTime end = DateTime.Now; + while (_length != length && end.Subtract(start).TotalMilliseconds < timeout) + { + _length = serialPort.BytesToRead; + end = DateTime.Now; + } + if (_length != length) + { + if (_length != 0) + { + byte[] _buffer = new byte[_length]; + serialPort.Read(_buffer, 0, _length); + logger.Info($"交互超时回复:{Convert.ToHexString(buffer)},{operation}"); + } + throw new TimeoutException($"串口【{serialPort.PortName}】交互超时,操作为{operation}"); } serialPort.Read(buffer, 0, length); //} @@ -681,6 +722,11 @@ namespace DM_Weight.Port return Task.Run(() => GetBufferByPort(serialPort, length, 3000)); } + private Task GetBufferByPort(SerialPort serialPort, int length,string operation) + { + + return Task.Run(() => GetBufferByPort(serialPort, length, 3000,operation)); + } public static SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); public void SpeakAsync(string textinfo) @@ -764,9 +810,9 @@ namespace DM_Weight.Port canBusSerial.DiscardInBuffer(); byte[] buffer = new byte[] { 0xaa, (byte)(_doorAddr), 0x01, (byte)_storageBoxAddr, 0x00, 0x00, 0x00, 0xee }; canBusSerial.Write(buffer, 0, 8); - logger.Info($"OpenStorage:{string.Join("", buffer)}"); + logger.Info($"OpenStorage:{Convert.ToHexString(buffer)}"); - return await GetBufferByPort(canBusSerial, 8); + return await GetBufferByPort(canBusSerial, 8,"开储物箱"); } // 关闭电控门储物箱(有灯失能) public void CloseStorage() @@ -806,9 +852,9 @@ namespace DM_Weight.Port Array.Reverse(schar); int[] iArray = Array.ConvertAll(schar, c => (int)Char.GetNumericValue(c)); int[] addArray = new int[8 - iArray.Length]; - if(iArray.Length<8) + if (iArray.Length < 8) { - for (int i = 0; i < 8- iArray.Length; i++) + for (int i = 0; i < 8 - iArray.Length; i++) { addArray[i] = 0; } @@ -837,7 +883,7 @@ namespace DM_Weight.Port byte[] buffer = new byte[] { 0xaa, (byte)(0xf0 + DrawerNo), 0x01, 0x00, 0x00, 0x00, 0x00, 0xee }; - logger.Info($"单支板发送库位数量查询【{string.Join(",", buffer)}】"); + logger.Info($"单支板发送库位数量查询【{Convert.ToHexString(buffer)}】"); canBusSerial.Write(buffer, 0, 8); return await GetBufferByPort(canBusSerial, 13); @@ -969,6 +1015,7 @@ namespace DM_Weight.Port { try { + logger.Info($"写标签数据:{type}-{content}-{drawerNo}-{colNo}"); canBusSerial.DiscardInBuffer(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); byte[] contentBuf = Encoding.GetEncoding("gb2312").GetBytes(trim(content)); @@ -1071,6 +1118,39 @@ namespace DM_Weight.Port } // 写入数量 public void WriteQuantity(int drawerNo, int colNo, int quantity) + { + try + { + logger.Info($"写入数量:{drawerNo}-{colNo}-{quantity}"); + canBusSerial.DiscardInBuffer(); + int channel = ((drawerNo > 8 ? (drawerNo - 8) * 2 : (drawerNo * 2 - 1)) - 1) * this.labelCount + 10 + colNo; + byte[] buffer = new byte[] { 0xaa, (byte)channel, 0x21, 0, 0, 0, 0, 0xee }; + buffer[5] = (byte)(quantity >> 8); + buffer[6] = (byte)(quantity & 0xff); + logger.Info($"写入数量buffer:{Convert.ToHexString(buffer)}"); + canBusSerial.Write(buffer, 0, 8); + Task task = GetBufferByPort(canBusSerial, 8); + if (task.Status == TaskStatus.Created) + { + task.Start(); + + } + byte[] bytes = task.Result; + logger.Info($"写入数量返回:" + Convert.ToHexString(bytes)); + } + catch (Exception ex) + { + _eventAggregator.GetEvent().Publish(new util.DeviceMsg() + { + EventType = util.EventType.OPENERROR, + WindowName = WindowName, + Message = $"操作发生异常{ex.InnerException}" + }); + logger.Info($"操作发生异常:ex:{ex.InnerException}"); + } + } + // 写入数量 + public async void WriteQuantityAsync(int drawerNo, int colNo, int quantity) { try { @@ -1080,6 +1160,8 @@ namespace DM_Weight.Port buffer[5] = (byte)(quantity >> 8); buffer[6] = (byte)(quantity & 0xff); canBusSerial.Write(buffer, 0, 8); + byte[] bufferReturn=await GetBufferByPort(canBusSerial, 8); + logger.Info($"写入数量返回:" + Convert.ToHexString(bufferReturn)); } catch (Exception ex) { @@ -1114,7 +1196,7 @@ namespace DM_Weight.Port byte[] buffer = new byte[] { 0xAA, 0x9A, 0x04, 0x00, 0x00, 0x00, 0x00, 0xEE }; canBusSerial.Write(buffer, 0, 8); - return await GetBufferByPort(canBusSerial, 8); + return await GetBufferByPort(canBusSerial, 8, "打开回收箱"); } catch (Exception ex) { @@ -1188,14 +1270,14 @@ namespace DM_Weight.Port canBusSerial.DiscardInBuffer(); var channel = Convert.ToInt32((DrawerNo * 10 + 1).ToString(), 16); byte[] buffer = new byte[] { 0xaa, (byte)(channel), 0x28, 0x00, 0x00, 0x00, 0x00, 0xee }; - logger.Info($"称重发送库位数量查询1【{string.Join(",", buffer)}】"); + logger.Info($"称重发送库位数量查询1【{Convert.ToHexString(buffer)}】"); canBusSerial.Write(buffer, 0, 8); byte[] result1 = await GetBufferByPort(canBusSerial, 8); var channel2 = Convert.ToInt32((DrawerNo * 10 + 2).ToString(), 16); byte[] buffer2 = new byte[] { 0xaa, (byte)(channel2), 0x28, 0x00, 0x00, 0x00, 0x00, 0xee }; - logger.Info($"称重发送库位数量查询2【{string.Join(",", buffer2)}】"); + logger.Info($"称重发送库位数量查询2【{Convert.ToHexString(buffer2)}】"); canBusSerial.Write(buffer2, 0, 8); byte[] result2 = await GetBufferByPort(canBusSerial, 8); @@ -1221,10 +1303,10 @@ namespace DM_Weight.Port var channel = Convert.ToInt32((DrawerNo * 10 + index).ToString(), 16); byte[] buffer = new byte[] { 0xaa, (byte)(channel), 0x27, (byte)lock1, 0x00, 0x00, 0x00, 0xee }; - logger.Info($"称重发送库位数量查询1【{string.Join(",", buffer)}】"); + logger.Info($"称重发送库位数量查询1【{Convert.ToHexString(buffer)}】"); canBusSerial.Write(buffer, 0, 8); byte[] result = await GetBufferByPort(canBusSerial, 8); - logger.Info($"称重发送库位数量查询1返回结果【{string.Join(",", result)}】"); + logger.Info($"称重发送库位数量查询1返回结果【{Convert.ToHexString(result)}】"); byte[] hl = result.Skip(3).Take(2).ToArray(); int quantity = BitConverter.ToInt16(hl.Reverse().ToArray(), 0); res[ColNos[i] - 1] = quantity; @@ -1243,7 +1325,7 @@ namespace DM_Weight.Port var lock1 = ColNos[i] % 3 == 0 ? 3 : ColNos[i] % 3; var channel = Convert.ToInt32((DrawerNo * 10 + index).ToString(), 16); byte[] buffer = new byte[] { 0xaa, (byte)(channel), 0x03, (byte)lock1, 0x00, 0x00, 0x00, 0xee }; - logger.Info($"称重发送药盒使能【{string.Join(",", buffer)}】"); + logger.Info($"称重发送药盒使能【{Convert.ToHexString(buffer)}】"); canBusSerial.Write(buffer, 0, 8); await Task.Delay(TimeSpan.FromMilliseconds(500)); } @@ -1258,7 +1340,7 @@ namespace DM_Weight.Port var lock1 = ColNos[i] % 3 == 0 ? 3 : ColNos[i] % 3; var channel = Convert.ToInt32((DrawerNo * 10 + index).ToString(), 16); byte[] buffer = new byte[] { 0xaa, (byte)(channel), 0x04, (byte)lock1, 0x00, 0x00, 0x00, 0xee }; - logger.Info($"称重发送药盒失能【{string.Join(",", buffer)}】"); + logger.Info($"称重发送药盒失能【{Convert.ToHexString(buffer)}】"); canBusSerial.Write(buffer, 0, 8); await Task.Delay(TimeSpan.FromMilliseconds(50)); } @@ -1274,7 +1356,7 @@ namespace DM_Weight.Port var channel = Convert.ToInt32((DrawerNo * 10 + index).ToString(), 16); byte[] buffer = new byte[] { 0xaa, (byte)(channel), 0x25, (byte)lock1, 0x00, 0x00, 0x00, 0xee }; - logger.Info($"称重发送清空计数【{string.Join(",", buffer)}】"); + logger.Info($"称重发送清空计数【{Convert.ToHexString(buffer)}】"); canBusSerial.Write(buffer, 0, 8); } catch (Exception ex) @@ -1305,7 +1387,7 @@ namespace DM_Weight.Port buffer[5] = (byte)(Quantity & 0xff); - logger.Info($"称重发送数量【{string.Join(",", buffer)}】"); + logger.Info($"称重发送数量【{Convert.ToHexString(buffer)}】"); canBusSerial.Write(buffer, 0, 8); } catch (Exception ex) diff --git a/DM_Weight/Report/GridReportUtil.cs b/DM_Weight/Report/GridReportUtil.cs index e4b3aad..ed7148b 100644 --- a/DM_Weight/Report/GridReportUtil.cs +++ b/DM_Weight/Report/GridReportUtil.cs @@ -53,7 +53,32 @@ namespace DM_Weight.Report Report.DetailGrid.Recordset.QuerySQL = SQL; Report.PrintPreview(true); } - public static void PrintReportAccountBook(DateTime? startDate, DateTime? endDate,string drug_id) + /// + /// 导出盘点后库存信息 + /// + /// + /// + public static void PrintReportStockNew(DateTime? startDate, DateTime? endDate) + { + DateTime? p_startDate = startDate ?? Convert.ToDateTime("2010-1-1"); + DateTime? p_endDate = endDate ?? DateTime.Now.AddDays(1); + // 定义Grid++Report报表主对象 + GridppReport Report = new GridppReport(); + //Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(() => + //{ + // Report.ParameterByName("machine_id").Value = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + //}); + string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + string SQL = $@"SELECT cl.`row_no` AS drawerNo,cl.`col_no` AS colNo,cl.`quantity` AS quantity,cl.`manu_no` AS manuNo,cl.`eff_date` AS effDate, + `drug_name` AS drugName,`drug_spec` AS drugSpec,`pack_unit` AS packUnit,`manufactory` AS manuFactory,`max_stock` AS baseQuantity, + cl.`drug_id` AS drugId,cl.manuquantity, cl.`optdate` FROM check_stock cl WHERE cl.`machine_id` = '{machine_id}' AND cl.`optdate` > '{p_startDate}' AND cl.`optdate` < '{p_endDate}' ORDER BY cl.`optdate` desc, cl.`drug_id`"; + // 加载模板文件 + Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//" + "machine_log_check_new2.grf"); + Report.DetailGrid.Recordset.ConnectionString = gridConnectionString; + Report.DetailGrid.Recordset.QuerySQL = SQL; + Report.PrintPreview(true); + } + public static void PrintReportAccountBook(DateTime? startDate, DateTime? endDate,int type,string drug_id) { DateTime? p_startDate = startDate ?? Convert.ToDateTime("2010-1-1"); DateTime? p_endDate = endDate ?? DateTime.Now.AddDays(1); @@ -71,19 +96,36 @@ namespace DM_Weight.Report Report.ParameterByName("endDate").Value = endDate ?? DateTime.Now.AddDays(1); }); //Report.DetailGrid.Recordset.QuerySQL = SQL; - SQL = $@"SELECT mr.`stock_quantity` AS `stockQuantity`, IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, 0)) + SQL = $@"SELECT TYPE, stockQuantity,inQuantity,outQuantity,operationTime,invoiceId,drugName,drugId,drugSpec,packUnit,dosage,manufactory,manuNo,effDate, + operatorName,reviewerName,supplierDept,receiveDept,bigUnit FROM + (SELECT mr.type, mr.`stock_quantity` AS `stockQuantity`, IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, 0)) AS `inQuantity`, IF(mr.`type` = 2, mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` < 0, (0 - mr.`quantity`), 0)) AS `outQuantity`, mr.`operation_time` AS `operationTime`,IF(mr.`type`=1,mr.`invoice_id`,NULL) AS `invoiceId`, di.`drug_name` AS `drugName`, di.`drug_id` AS `drugId`, - di.`drug_spec` AS `drugSpec`, di.`pack_unit` AS `packUnit`, di.`dosage` AS `dosage`, di.`manufactory` AS `manufactory`, - mr.`manu_no` AS `manuNo`, mr.`eff_date` AS `effDate`, u1.`user_name` AS `operatorName`, u2.`user_name` AS `reviewerName` FROM + di.`drug_spec` AS `drugSpec`, di.`pack_unit` AS `packUnit`,di.big_unit as bigUnit, di.`dosage` AS `dosage`, di.`manufactory` AS `manufactory`, + mr.`manu_no` AS `manuNo`, mr.`eff_date` AS `effDate`, u1.`user_name` AS `operatorName`, u2.`user_name` AS `reviewerName`,mr.supplierDept,mr.receiveDept FROM dm_machine_record mr LEFT JOIN drug_info di ON mr.`drug_id` = di.`drug_id` LEFT JOIN user_list u1 ON mr.`operator` = u1.`id` LEFT JOIN user_list u2 ON mr.`reviewer` = u2.`id` WHERE mr.`machine_id` = '{p_machine_id}' AND mr.`operation_time` > '{p_startDate}' - AND mr.`operation_time` < '{p_endDate}' "; + AND mr.`operation_time` < '{p_endDate}' and IF(mr.`type` = 4 AND mr.`quantity` = 0, 99999, mr.`quantity`) <>99999 "; if(!string.IsNullOrEmpty(drug_id)) { SQL+= " AND mr.drug_id='"+ drug_id+"' "; } - SQL+="ORDER BY mr.`drug_id`, mr.`operation_time`, mr.`id`"; + SQL+= " ORDER BY mr.`drug_id`, mr.`operation_time`, mr.`id`) AS T"; + if (type > 0) + { + if (type == 1) + { + SQL += " WHERE inQuantity>0 "; + } + if (type == 2) + { + SQL += " WHERE outQuantity>0 "; + } + if (type == 5) + { + SQL += " WHERE type=5 "; + } + } Report.DetailGrid.Recordset.QuerySQL = SQL; Report.PrintPreview(true); } @@ -203,5 +245,25 @@ namespace DM_Weight.Report Report.DetailGrid.Recordset.QuerySQL = SQL; Report.PrintPreview(true); } + + /// + /// 盘点页面导出记录,按选中行进行导出 + /// + /// + /// + /// + public static void PrintReportMechineRecordForSelect(List data) + { + // 定义Grid++Report报表主对象 + GridppReport Report = new GridppReport(); + // 加载模板文件 + Report.LoadFromFile(new FileInfo(AppDomain.CurrentDomain.BaseDirectory) + "ReportTemp//machine_log_check.grf"); + Dictionary> records = new Dictionary>(); + records.Add("table", data); + string str= JsonConvert.SerializeObject(records); + Report.LoadDataFromXML(str); + // 加载数据 + Report.PrintPreview(true); + } } } diff --git a/DM_Weight/ReportTemp/account_book_temp.grf b/DM_Weight/ReportTemp/account_book_temp.grf index 50a66eb..d509b10 100644 --- a/DM_Weight/ReportTemp/account_book_temp.grf +++ b/DM_Weight/ReportTemp/account_book_temp.grf @@ -15,7 +15,6 @@ }, "DetailGrid":{ "CenterView":true, - "AppendBlankRow":true, "Recordset":{ "Field":[ { @@ -75,7 +74,7 @@ }, { "Name":"单位", - "DBFieldName":"packUnit" + "DBFieldName":"bigUnit" }, { "Name":"剂型", @@ -105,6 +104,14 @@ { "Name":"凭证号", "DBFieldName":"invoiceId" + }, + { + "Name":"供应单位", + "DBFieldName":"supplierDept" + }, + { + "Name":"领用部门", + "DBFieldName":"receiveDept" } ] }, @@ -222,11 +229,11 @@ "FreeCell":true, "Control":[ { - "Type":"StaticBox", - "Name":"StaticBox6", + "Type":"FieldBox", + "Name":"FieldBox14", "Dock":"Fill", "TextAlign":"MiddleCenter", - "Text":"药库" + "DataField":"供应单位" } ] }, @@ -235,11 +242,11 @@ "FreeCell":true, "Control":[ { - "Type":"StaticBox", - "Name":"StaticBox7", + "Type":"FieldBox", + "Name":"FieldBox15", "Dock":"Fill", "TextAlign":"MiddleCenter", - "Text":"门诊药房11" + "DataField":"领用部门" } ] } diff --git a/DM_Weight/ReportTemp/machine_log_add.grf b/DM_Weight/ReportTemp/machine_log_add.grf index bf9031e..4542aee 100644 --- a/DM_Weight/ReportTemp/machine_log_add.grf +++ b/DM_Weight/ReportTemp/machine_log_add.grf @@ -13,7 +13,6 @@ }, "DetailGrid":{ "CenterView":true, - "AppendBlankRow":true, "Recordset":{ "QuerySQL":"SELECT \r\n dmr.`drawer_no` AS drawerNo,\r\n dmr.`col_no` AS colNo,\r\n dmr.`type` AS `type`,\r\n dmr.`quantity` AS quantity,\r\n dmr.`manu_no` AS manuNo,\r\n dmr.`eff_date` AS effDate,\r\n dmr.`operation_time` AS operationTime,\r\n di.`drug_name` AS drugName,\r\n di.`drug_spec` AS drugSpec,\r\n di.`pack_unit` AS packUnit,\r\n di.`manufactory` AS manuFactory,\r\n di.`max_stock` AS baseQuantity,\r\n dmr.`drug_id` AS drugId,\r\n ul.`user_name` AS nickname\r\nFROM\r\n dm_machine_record dmr\r\nLEFT JOIN drug_info di ON di.`drug_id` = dmr.`drug_id`\r\nLEFT JOIN user_list ul ON ul.`id` = dmr.`Operator`\r\nWHERE dmr.`type` = 1 \r\n AND dmr.`machine_id` = :machine_id\r\n AND dmr.`operation_time` > :startDate\r\n AND dmr.`operation_time` < :endDate", "Field":[ diff --git a/DM_Weight/ReportTemp/machine_log_check.grf b/DM_Weight/ReportTemp/machine_log_check.grf index 8521095..f909608 100644 --- a/DM_Weight/ReportTemp/machine_log_check.grf +++ b/DM_Weight/ReportTemp/machine_log_check.grf @@ -13,7 +13,6 @@ }, "DetailGrid":{ "CenterView":true, - "AppendBlankRow":true, "Recordset":{ "QuerySQL":"SELECT \r\n dmr.`drawer_no` AS drawerNo,\r\n dmr.`col_no` AS colNo,\r\n dmr.`type` AS `type`,\r\n dmr.`quantity` AS quantity,\r\n dmr.`manu_no` AS manuNo,\r\n dmr.`eff_date` AS effDate,\r\n dmr.`operation_time` AS operationTime,\r\n di.`drug_name` AS drugName,\r\n di.`drug_spec` AS drugSpec,\r\n di.`pack_unit` AS packUnit,\r\n di.`manufactory` AS manuFactory,\r\n di.`max_stock` AS baseQuantity,\r\n dmr.`drug_id` AS drugId,\r\n ul.`user_name` AS nickname\r\nFROM\r\n dm_machine_record dmr\r\nLEFT JOIN drug_info di ON di.`drug_id` = dmr.`drug_id`\r\nLEFT JOIN user_list ul ON ul.`id` = dmr.`Operator`\r\nWHERE dmr.`type` = 4 \r\n AND dmr.`machine_id` = :machine_id\r\n AND dmr.`operation_time` > :startDate\r\n AND dmr.`operation_time` < :endDate", "Field":[ @@ -60,6 +59,10 @@ "Name":"type2", "Type":"Integer", "DBFieldName":"type" + }, + { + "Name":"规格", + "DBFieldName":"drugSpec" } ] }, @@ -80,6 +83,10 @@ "Name":"药品名称", "Width":4.63021 }, + { + "Name":"规格", + "Width":1.69333 + }, { "Name":"数量", "Width":1.98438 @@ -119,6 +126,10 @@ "TextAlign":"MiddleCenter", "DataField":"药品名称" }, + { + "Column":"规格", + "DataField":"规格" + }, { "Column":"数量", "TextAlign":"MiddleCenter", @@ -210,6 +221,18 @@ "TextAlign":"MiddleCenter", "Text":"药品名称" }, + { + "GroupTitle":false, + "Column":"规格", + "Font":{ + "Name":"宋体", + "Size":120000, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"规格" + }, { "GroupTitle":false, "Column":"数量", diff --git a/DM_Weight/ReportTemp/machine_log_check_new.grf b/DM_Weight/ReportTemp/machine_log_check_new.grf new file mode 100644 index 0000000..c666ba5 --- /dev/null +++ b/DM_Weight/ReportTemp/machine_log_check_new.grf @@ -0,0 +1,313 @@ +{ + "Version":"6.3.0.1", + "Font":{ + "Name":"宋体", + "Size":105000, + "Weight":400, + "Charset":134 + }, + "Printer":{ + "Oriention":"Landscape" + }, + "DetailGrid":{ + "CenterView":true, + "PrintAdaptMethod":"ResizeToFit", + "Recordset":{ + "QuerySQL":"SELECT \r\n cl.`row_no` AS drawerNo,\r\n cl.`col_no` AS colNo,\r\n cl.`quantity` AS quantity,\r\n cl.`manu_no` AS manuNo,\r\n cl.`eff_date` AS effDate,\r\n di.`drug_name` AS drugName,\r\n di.`drug_spec` AS drugSpec,\r\n di.`pack_unit` AS packUnit,\r\n di.`manufactory` AS manuFactory,\r\n di.`max_stock` AS baseQuantity,\r\n cl.`drug_id` AS drugId\r\nFROM\r\n channel_stock cl\r\nINNER JOIN drug_info di ON di.`drug_id` = cl.`drug_id`\r\nWHERE cl.`machine_id` = :machine_id\r\n AND cl.`drawer_type` = 1\r\n ORDER BY cl.`drug_id`", + "Field":[ + { + "Name":"drugName" + }, + { + "Name":"drugSpec" + }, + { + "Name":"manuFactory" + }, + { + "Name":"quantityCount", + "Type":"Integer" + }, + { + "Name":"manuNo" + }, + { + "Name":"effDate" + }, + { + "Name":"quantity", + "Type":"Integer", + "Format":"0" + }, + { + "Name":"drawerNo" + }, + { + "Name":"drugId" + }, + { + "Name":"baseQuantity", + "Type":"Integer" + }, + { + "Name":"manuquantity", + "Type":"Integer" + }, + { + "Name":"optDate", + "DBFieldName":"optdate" + } + ] + }, + "Column":[ + { + "Name":"optDate", + "Width":4.20688 + }, + { + "Name":"drugName", + "Width":4.57729 + }, + { + "Name":"drugSpec" + }, + { + "Name":"manuFactory", + "Width":4.60375 + }, + { + "Name":"quantityCount", + "Width":2.19604 + }, + { + "Name":"manuNo" + }, + { + "Name":"effDate", + "Width":2.61938 + }, + { + "Name":"quantity", + "Width":1.42875 + } + ], + "ColumnContent":{ + "Height":0.79375, + "ColumnContentCell":[ + { + "Column":"optDate", + "DataField":"optDate" + }, + { + "Column":"drugName", + "TextAlign":"MiddleCenter", + "DataField":"drugName" + }, + { + "Column":"drugSpec", + "TextAlign":"MiddleCenter", + "DataField":"drugSpec" + }, + { + "Column":"manuFactory", + "TextAlign":"MiddleCenter", + "DataField":"manuFactory" + }, + { + "Column":"quantityCount", + "FreeCell":true, + "Control":[ + { + "Type":"MemoBox", + "Name":"MemoBox1", + "Dock":"Fill", + "Text":"[#Sum(manuquantity)#]" + } + ] + }, + { + "Column":"manuNo", + "TextAlign":"MiddleCenter", + "DataField":"manuNo" + }, + { + "Column":"effDate", + "TextAlign":"MiddleCenter", + "DataField":"effDate" + }, + { + "Column":"quantity", + "TextAlign":"MiddleCenter", + "DataField":"manuquantity" + } + ] + }, + "ColumnTitle":{ + "Height":1.19063, + "RepeatStyle":"OnPage", + "ColumnTitleCell":[ + { + "GroupTitle":false, + "Column":"optDate", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"盘点日期" + }, + { + "GroupTitle":false, + "Column":"drugName", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"药品名称" + }, + { + "GroupTitle":false, + "Column":"drugSpec", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"规格" + }, + { + "GroupTitle":false, + "Column":"manuFactory", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"厂家" + }, + { + "GroupTitle":false, + "Column":"quantityCount", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"总库存" + }, + { + "GroupTitle":false, + "Column":"manuNo", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"批次" + }, + { + "GroupTitle":false, + "Column":"effDate", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"效期" + }, + { + "GroupTitle":false, + "Column":"quantity", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"数量" + } + ] + }, + "Group":[ + { + "Name":"Group2", + "ByFields":"optDate", + "GroupHeader":{ + "Height":0.635, + "OccupyColumn":true, + "OccupiedColumns":"optDate", + "VAlign":"Middle" + }, + "GroupFooter":{ + "Visible":false, + "Height":0 + } + }, + { + "Name":"drugId", + "ByFields":"drugId", + "GroupHeader":{ + "Visible":false, + "Height":0.79375, + "RepeatOnPage":true, + "OccupyColumn":true, + "IncludeFooter":true, + "OccupiedColumns":"drugName;drugSpec;manuFactory;quantityCount", + "VAlign":"Middle" + }, + "GroupFooter":{ + "Visible":false, + "Height":0 + } + } + ] + }, + "Parameter":[ + { + "Name":"machine_id", + "Value":"DM1" + } + ], + "ReportHeader":[ + { + "Name":"ReportHeader1", + "Height":2.40771, + "Control":[ + { + "Type":"StaticBox", + "Name":"StaticBox1", + "Center":"Horizontal", + "Left":8.22854, + "Top":0.608542, + "Width":9.18104, + "Height":1.21708, + "Font":{ + "Name":"宋体", + "Size":217500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"毒麻药品盘点后库存信息" + } + ], + "RepeatOnPage":true + } + ] +} \ No newline at end of file diff --git a/DM_Weight/ReportTemp/machine_log_check_new2.grf b/DM_Weight/ReportTemp/machine_log_check_new2.grf new file mode 100644 index 0000000..4de9e86 --- /dev/null +++ b/DM_Weight/ReportTemp/machine_log_check_new2.grf @@ -0,0 +1,278 @@ +{ + "Version":"6.3.0.1", + "Font":{ + "Name":"宋体", + "Size":105000, + "Weight":400, + "Charset":134 + }, + "Printer":{ + "LeftMargin":1, + "TopMargin":1, + "RightMargin":1, + "BottomMargin":1 + }, + "DetailGrid":{ + "Recordset":{ + "Field":[ + { + "Name":"盘点日期", + "DBFieldName":"optDate" + }, + { + "Name":"药品名称", + "DBFieldName":"drugName" + }, + { + "Name":"drugId" + }, + { + "Name":"规格", + "DBFieldName":"drugSpec" + }, + { + "Name":"厂家", + "DBFieldName":"manuFactory" + }, + { + "Name":"总库存", + "DBFieldName":"quantity" + }, + { + "Name":"批次", + "DBFieldName":"manuNo" + }, + { + "Name":"效期", + "DBFieldName":"effDate" + }, + { + "Name":"数量", + "DBFieldName":"manuquantity" + } + ] + }, + "Column":[ + { + "Name":"盘点日期", + "Width":2.56646 + }, + { + "Name":"药品名称", + "Width":2.80458 + }, + { + "Name":"规格", + "Width":2.01083 + }, + { + "Name":"厂家", + "Width":2.98979 + }, + { + "Name":"总库存", + "Width":1.69333 + }, + { + "Name":"批次", + "Width":2.06375 + }, + { + "Name":"效期", + "Width":2.19604 + }, + { + "Name":"数量", + "Width":1.69333 + } + ], + "ColumnContent":{ + "Height":0.79375, + "ColumnContentCell":[ + { + "Column":"盘点日期", + "DataField":"盘点日期" + }, + { + "Column":"药品名称", + "DataField":"药品名称" + }, + { + "Column":"规格", + "DataField":"规格" + }, + { + "Column":"厂家", + "DataField":"厂家" + }, + { + "Column":"总库存", + "DataField":"总库存" + }, + { + "Column":"批次", + "DataField":"批次" + }, + { + "Column":"效期", + "DataField":"效期" + }, + { + "Column":"数量", + "DataField":"数量" + } + ] + }, + "ColumnTitle":{ + "Height":1.19063, + "RepeatStyle":"OnPage", + "ColumnTitleCell":[ + { + "GroupTitle":false, + "Column":"盘点日期", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"盘点日期" + }, + { + "GroupTitle":false, + "Column":"药品名称", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"药品名称" + }, + { + "GroupTitle":false, + "Column":"规格", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"规格" + }, + { + "GroupTitle":false, + "Column":"厂家", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"厂家" + }, + { + "GroupTitle":false, + "Column":"总库存", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"总库存" + }, + { + "GroupTitle":false, + "Column":"批次", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"批次" + }, + { + "GroupTitle":false, + "Column":"效期", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"效期" + }, + { + "GroupTitle":false, + "Column":"数量", + "Font":{ + "Name":"宋体", + "Size":142500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"数量" + } + ] + }, + "Group":[ + { + "Name":"Group1", + "ByFields":"盘点日期", + "GroupHeader":{ + "Height":0.635, + "OccupyColumn":true, + "OccupiedColumns":"盘点日期", + "VAlign":"Middle" + }, + "GroupFooter":{ + "Height":0 + } + }, + { + "Name":"Group2", + "ByFields":"drugId", + "GroupHeader":{ + "Height":0.635, + "OccupyColumn":true, + "OccupiedColumns":"药品名称;厂家;规格;总库存", + "VAlign":"Middle" + }, + "GroupFooter":{ + "Height":0 + } + } + ] + }, + "ReportHeader":[ + { + "Name":"ReportHeader1", + "Height":1.32292, + "Control":[ + { + "Type":"MemoBox", + "Name":"MemoBox1", + "Dock":"Fill", + "Font":{ + "Name":"宋体", + "Size":157500, + "Bold":true, + "Charset":134 + }, + "TextAlign":"MiddleCenter", + "Text":"毒麻药品盘点后库存信息" + } + ] + } + ] +} \ No newline at end of file diff --git a/DM_Weight/ReportTemp/machine_log_return.grf b/DM_Weight/ReportTemp/machine_log_return.grf index 493f661..f02bef4 100644 --- a/DM_Weight/ReportTemp/machine_log_return.grf +++ b/DM_Weight/ReportTemp/machine_log_return.grf @@ -13,7 +13,6 @@ }, "DetailGrid":{ "CenterView":true, - "AppendBlankRow":true, "Recordset":{ "QuerySQL":"SELECT \r\n dmr.`drawer_no` AS drawerNo,\r\n dmr.`col_no` AS colNo,\r\n dmr.`type` AS `type`,\r\n CONCAT(dmr.`quantity`,IF(dmr.`type`=32,\"(空瓶)\",\"\")) AS quantity,\r\n dmr.`manu_no` AS manuNo,\r\n dmr.`eff_date` AS effDate,\r\n dmr.`operation_time` AS operationTime,\r\n di.`drug_name` AS drugName,\r\n di.`drug_spec` AS drugSpec,\r\n di.`pack_unit` AS packUnit,\r\n di.`manufactory` AS manuFactory,\r\n di.`max_stock` AS baseQuantity,\r\n dmr.`drug_id` AS drugId,\r\n ul.`user_name` AS nickname\r\nFROM\r\n dm_machine_record dmr\r\nLEFT JOIN drug_info di ON di.`drug_id` = dmr.`drug_id`\r\nLEFT JOIN user_list ul ON ul.`id` = dmr.`Operator`\r\nWHERE dmr.`type` in (31, 32)\r\n AND dmr.`machine_id` = :machine_id\r\n AND dmr.`operation_time` > :startDate\r\n AND dmr.`operation_time` < :endDate", "Field":[ diff --git a/DM_Weight/ReportTemp/machine_log_take.grf b/DM_Weight/ReportTemp/machine_log_take.grf index 32fe037..d0d31a4 100644 --- a/DM_Weight/ReportTemp/machine_log_take.grf +++ b/DM_Weight/ReportTemp/machine_log_take.grf @@ -13,7 +13,6 @@ }, "DetailGrid":{ "CenterView":true, - "AppendBlankRow":true, "Recordset":{ "QuerySQL":"SELECT \r\n dmr.`drawer_no` AS drawerNo,\r\n dmr.`col_no` AS colNo,\r\n dmr.`type` AS `type`,\r\n dmr.`quantity` AS quantity,\r\n dmr.`manu_no` AS manuNo,\r\n dmr.`eff_date` AS effDate,\r\n dmr.`operation_time` AS operationTime,\r\n di.`drug_name` AS drugName,\r\n di.`drug_spec` AS drugSpec,\r\n di.`pack_unit` AS packUnit,\r\n di.`manufactory` AS manuFactory,\r\n di.`max_stock` AS baseQuantity,\r\n dmr.`drug_id` AS drugId,\r\n ul.`user_name` AS nickname\r\nFROM\r\n dm_machine_record dmr\r\nLEFT JOIN drug_info di ON di.`drug_id` = dmr.`drug_id`\r\nLEFT JOIN user_list ul ON ul.`id` = dmr.`Operator`\r\nWHERE dmr.`type` = 2 \r\n AND dmr.`machine_id` = :machine_id\r\n AND dmr.`operation_time` > :startDate\r\n AND dmr.`operation_time` < :endDate", "Field":[ diff --git a/DM_Weight/ReportTemp/stock_template.grf b/DM_Weight/ReportTemp/stock_template.grf index 6a2d5fb..2b53449 100644 --- a/DM_Weight/ReportTemp/stock_template.grf +++ b/DM_Weight/ReportTemp/stock_template.grf @@ -12,7 +12,6 @@ "DetailGrid":{ "CenterView":true, "PrintAdaptMethod":"ResizeToFit", - "AppendBlankRow":true, "Recordset":{ "QuerySQL":"SELECT \r\n cl.`row_no` AS drawerNo,\r\n cl.`col_no` AS colNo,\r\n cl.`quantity` AS quantity,\r\n cl.`manu_no` AS manuNo,\r\n cl.`eff_date` AS effDate,\r\n di.`drug_name` AS drugName,\r\n di.`drug_spec` AS drugSpec,\r\n di.`pack_unit` AS packUnit,\r\n di.`manufactory` AS manuFactory,\r\n di.`max_stock` AS baseQuantity,\r\n cl.`drug_id` AS drugId\r\nFROM\r\n channel_stock cl\r\nINNER JOIN drug_info di ON di.`drug_id` = cl.`drug_id`\r\nWHERE cl.`machine_id` = :machine_id\r\n AND cl.`drawer_type` = 1\r\n ORDER BY cl.`drug_id`", "Field":[ diff --git a/DM_Weight/Services/ChannelStockService.cs b/DM_Weight/Services/ChannelStockService.cs new file mode 100644 index 0000000..a871464 --- /dev/null +++ b/DM_Weight/Services/ChannelStockService.cs @@ -0,0 +1,37 @@ +using DM_Weight.Models; +using DM_Weight.util; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.Services +{ + public class ChannelStockService + { + ////private SqlSugarScope SqlSugarHelper.Db; + //public ChannelStockService(SqlSugarScope sqlSugarScope) + //{ + // //this.SqlSugarHelper.Db = sqlSugarScope; + //} + public List GetAll() + { + string p_machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + string SQL = $@"SELECT CS.drug_id as DrugId,CS.manu_no as ManuNo,sum(quantity) as Quantity,CS.eff_date as EffDate,DI.drug_name as DrugName, + DI.drug_spec as DrugSpec,DI.dosage as Dosage,DI.manufactory as ManuFactory,DI.small_unit as SmallUnit,DI.pack_unit as PackUnit, + CS.machine_id as MachineId FROM channel_stock CS + INNER JOIN drug_info DI ON CS.drug_id=DI.drug_id where CS.machine_id='{p_machine_id}' AND quantity>0 GROUP BY CS.drug_id,CS.manu_no "; + + List accountList = SqlSugarHelper.Db.SqlQueryable(SQL).ToList(); + //List accountList = SqlSugarHelper.Db.Queryable().Includes(cs=>cs.DrugInfo) + // .GroupBy(cs=>new { cs.DrugId, cs.ManuNo }) + // .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"]??"DM1")) + // .Where(cs=>cs.Quantity>0) + // .ToList(); + return accountList; + } + } +} diff --git a/DM_Weight/Services/MachineRecordService.cs b/DM_Weight/Services/MachineRecordService.cs new file mode 100644 index 0000000..2809a39 --- /dev/null +++ b/DM_Weight/Services/MachineRecordService.cs @@ -0,0 +1,79 @@ +using DM_Weight.Models; +using DM_Weight.util; +using DM_Weight.Views.Dialog; +using gregn6Lib; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.Services +{ + /// + /// 账册服务类 + /// + public class MachineRecordService + { + ////private SqlSugarScope SqlSugarHelper.Db; + public MachineRecordService() + { + ////this.SqlSugarHelper.Db = sqlSugarScope; + } + public List ReportAccountBook(DateTime? startDate, DateTime? endDate,int type, string drug_id="") + { + DateTime? p_startDate = startDate ?? Convert.ToDateTime("2010-1-1"); + DateTime? p_endDate = endDate ?? DateTime.Now.AddDays(1); + string p_machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + string SQL = $@"SELECT TYPE, stockQuantity,inQuantity,outQuantity,operationTime,invoiceId,drugName,drugId,drugSpec,packUnit,dosage,manufactory,manuNo,effDate, + operatorName,reviewerName,supplierDept,receiveDept FROM + (SELECT mr.type,mr.`stock_quantity` AS `stockQuantity`, IF(mr.`type` IN (1, 31), mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` > 0, mr.`quantity`, 0)) + AS `inQuantity`, IF(mr.`type` = 2, mr.`quantity`, IF(mr.`type` = 4 AND mr.`quantity` < 0, (0 - mr.`quantity`), 0)) AS `outQuantity`, + DATE_FORMAT(mr.`operation_time`,'%m/%d') AS `operationTime`,IF(mr.`type`=1,mr.`invoice_id`,NULL) AS `invoiceId`, di.`drug_name` AS `drugName`, di.`drug_id` AS `drugId`, + di.`drug_spec` AS `drugSpec`, di.`pack_unit` AS `packUnit`, di.`dosage` AS `dosage`, di.`manufactory` AS `manufactory`, + mr.`manu_no` AS `manuNo`, DATE_FORMAT(mr.`eff_date`,'%y/%m/%d') AS `effDate`, u1.`user_name` AS `operatorName`, u2.`user_name` AS `reviewerName`,mr.supplierDept,mr.receiveDept FROM + dm_machine_record mr LEFT JOIN drug_info di ON mr.`drug_id` = di.`drug_id` LEFT JOIN user_list u1 ON mr.`operator` = u1.`id` + LEFT JOIN user_list u2 ON mr.`reviewer` = u2.`id` WHERE mr.`machine_id` = '{p_machine_id}' AND mr.`operation_time` > '{p_startDate}' + AND mr.`operation_time` < '{p_endDate}' and IF(mr.`type` = 4 AND mr.`quantity` = 0, 99999, mr.`quantity`) <>99999 "; + if (!string.IsNullOrEmpty(drug_id)) + { + SQL += " AND mr.drug_id='" + drug_id + "' "; + } + SQL += " ORDER BY mr.`drug_id`, mr.`operation_time`, mr.`id`) AS T"; + if(type>0) + { + if(type==1) + { + SQL += " WHERE inQuantity>0 "; + } + if(type==2) + { + SQL += " WHERE outQuantity>0 "; + } + if(type==5) + { + SQL += " WHERE type=5 "; + } + } + + + //ChannelStocks = q.Select(it => { it.CheckQuantity = it.Quantity; return it; }).ToList(); + + List accountList = SqlSugarHelper.Db.SqlQueryable(SQL) + .AddParameters(new + { + machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1" + }) + //.Select(it => new { o = new AccountModel(), i = new DrugInfo() }) + //.Select(it=>new AccountModel()) + //.Select("*") //让上面一行不生成sql + .ToList(); + + //List accountList=new List(); + return accountList; + } + } +} diff --git a/DM_Weight/Services/UserService.cs b/DM_Weight/Services/UserService.cs new file mode 100644 index 0000000..4d457a4 --- /dev/null +++ b/DM_Weight/Services/UserService.cs @@ -0,0 +1,54 @@ +using DM_Weight.Models; +using MySqlConnector; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.Services +{ + public class UserService + { + //public static string connStr = ConfigurationManager.AppSettings["database"].ToString(); + public static string connStr = ConfigurationManager.ConnectionStrings["database"].ToString(); + public UserList CheckUserByFingerPrinter(int fingerPrinterId) + { + UserList? user = null; + + using (MySqlConnection con = new MySqlConnection(connStr)) + { + con.Open(); + string sql = @"select ul.id as id,ul.User_name as userName,r.id,r.role_name,r.permissions,r.machine_id from user_list ul + INNER JOIN role r on ul.machine_role_id=r.id where ul.Id=@ID and ul.machine_id=@machine_id and r.machine_id=@machine_id;"; + MySqlCommand cmd = new MySqlCommand(sql, con); + cmd.Parameters.Clear(); + MySqlParameter[] mySqlParameter = new MySqlParameter[] {new MySqlParameter("ID", fingerPrinterId),new MySqlParameter("machine_id", (ConfigurationManager.AppSettings["machineId"] ?? "DM1")) }; + cmd.Parameters.AddRange(mySqlParameter); + //执行语句 + MySqlDataReader reader = cmd.ExecuteReader(); + while (reader.Read()) + { + user = new UserList(); + user.Id = reader.GetInt32("id"); + user.UserName = reader["userName"] is DBNull ? "" : reader.GetString("userName"); + //user.UserName = reader["id"] is DBNull ? "" : reader.GetString("id"); + user.Nickname= reader["userName"] is DBNull ? "" : reader.GetString("userName"); + user.MachineId = reader["machine_id"] is DBNull ? "" : reader.GetString("machine_id"); + RoleDm role= new RoleDm(); + role.Id= reader.GetInt32("id"); + //role.Permissions = reader["permissions"] is DBNull ? "" : reader.GetString("permissions"); + role.RoleName = reader["role_name"] is DBNull ? "" : reader.GetString("role_name"); + role.Permissions = JsonConvert.DeserializeObject>(reader["permissions"] is DBNull ? "" : reader.GetString("permissions")); // JsonConvert.SerializeObject(reader.GetString("permissions")).ToList(); + user.Role = role; + } + reader.Close(); + + return user; + } + + } + } +} diff --git a/DM_Weight/ViewModels/AccountWindowViewModel.cs b/DM_Weight/ViewModels/AccountWindowViewModel.cs new file mode 100644 index 0000000..848db2f --- /dev/null +++ b/DM_Weight/ViewModels/AccountWindowViewModel.cs @@ -0,0 +1,414 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Report; +using DM_Weight.Services; +using DM_Weight.util; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Configuration; +using System.Drawing.Printing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace DM_Weight.ViewModels +{ + public class AccountWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime + { + public static AccountWindowViewModel vm; + //private int _pageNum = 1; + //public int PageNum + //{ + // get => _pageNum; + // set + // { + // SetProperty(ref _pageNum, value); + // RequestData(); + // } + //} + + //private int _pageCount = 1; + //public int PageCount + //{ + // get => _pageCount; + // set + // { + // SetProperty(ref _pageCount, value); + // } + //} + + //private int _pageSize = 8; + //public int PageSize + //{ + // get => _pageSize; + // set + // { + // SetProperty(ref _pageSize, value); + // } + //} + + //private int _totalCount = 0; + //public int TotalCount + //{ + // get => _totalCount; + // set + // { + // SetProperty(ref _totalCount, value); + // } + //} + private DateTime? _startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); + + private DateTime? nowDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); + + public DateTime? StartDate + { + get => _startDate; + set + { + if (value != null) + { + SetProperty(ref _startDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0)); + } + else + { + SetProperty(ref _startDate, value); + } + RequestData(); + } + } + + private DateTime? _endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); + + public DateTime? EndDate + { + get => _endDate; + set + { + if (value != null) + { + TimeSpan ershisi = new TimeSpan(23, 59, 59); + SetProperty(ref _endDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0, 23, 59, 59)); + } + else + { + SetProperty(ref _endDate, value); + } + + RequestData(); + } + } + private static readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + /// + /// 账册 + /// + private List _accountList = new(); + + public List AccountList + { + get => _accountList; + set => SetProperty(ref _accountList, value); + } + /// + /// 药品 + /// + private List? _drugInfos; + + public List? DrugInfos + { + get => _drugInfos; + set => SetProperty(ref _drugInfos, value); + } + private DrugInfo? _drugInfo; + + public DrugInfo? DrugInfo + { + get => _drugInfo; + set + { + SetProperty(ref _drugInfo, value); + //if (_drugInfo != null) + //{ + //DrugManuNos = _drugInfo.DrugManuNos.OrderByDescending(dm => dm.ManuNo).ToList(); + //} + RequestData(); + } + } + /// + /// 账册类型1入2出3总结存 + /// + private List _accountTypeList = new List() { + new AccountType + { + AccountTypeName="借入", + AccountTypeValue=1 + }, + new AccountType + { + AccountTypeName="发出", + AccountTypeValue=2 + }, + new AccountType + { + AccountTypeName="日结存", + AccountTypeValue=5 + } + }; + public List? AccountTypeList + { + get => _accountTypeList; + set + { + SetProperty(ref _accountTypeList, value); + RequestData(); + } + } + private AccountType? _accountType; + public AccountType AccountType + { + get => _accountType; + set + { + SetProperty(ref _accountType, value); + RequestData(); + } + } + + MachineRecordService _machineRecordService; + ChannelStockService _channelStockService; + IEventAggregator _eventAggregator; + ////private SqlSugarScope SqlSugarHelper.Db; + public AccountWindowViewModel(MachineRecordService machineRecord, ChannelStockService channelStockService, IEventAggregator eventAggregator) + { + _machineRecordService = machineRecord; + _channelStockService = channelStockService; + ////this.SqlSugarHelper.Db = sqlSugarScope; + _eventAggregator = eventAggregator; + vm = this; + } + void RequestData() + { + int totalCount = 0; + AccountList = _machineRecordService.ReportAccountBook(StartDate, EndDate, AccountType == null ? 0 : AccountType.AccountTypeValue, DrugInfo == null ? "" : DrugInfo.DrugId ?? ""); + //for (int i = 0; i < accountList.Count; i++) + //{ + // if (accountList[i].DrugInfo is null) + // { + // DrugInfo drug= new DrugInfo(); + // drug.DrugId = accountList[i].DrugId; + // drug.DrugName = accountList[i].DrugName; + // drug.DrugSpec = accountList[i].DrugSpec; + // drug.Dosage= accountList[i].Dosage; + // drug.PackUnit= accountList[i].PackUnit; + // drug.Manufactory= accountList[i].Manufactory; + // accountList[i].DrugInfo= drug; + // } + //} + //ICollectionView vw = CollectionViewSource.GetDefaultView(accountList); + //vw.GroupDescriptions.Add(new PropertyGroupDescription("DrugInfo")); + + } + private void GetAllDrugInfos() + { + var list = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); + DrugInfos = list; + DrugInfo = list[0]; + } + + /// + /// 生成日结存 + /// + public DelegateCommand DayAccountBook + { + get => new DelegateCommand(() => + { + DayAccountAction(); + RequestData(); + }); + } + //生成一条当日没有记录的账册记录 + private void DayAccountAction() + { + try + { + + //查询账册中所有记录,与库存中的记录做比校,如果账册中没有,则添加一条 + List accountList = _machineRecordService.ReportAccountBook(nowDate, null, 0); + //库存中的记录 + List channelStockList = _channelStockService.GetAll(); + //List channelStockInsert = new List(); + if (accountList != null && accountList.Count() > 0) + { + //账册中有记录则与库存记录对比 + + for (int i = 0; i < channelStockList.Count; i++) + { + int Count = accountList.Where(cs => cs.DrugId == channelStockList[i].DrugId && cs.ManuNo == channelStockList[i].ManuNo).Count(); + if (Count <= 0) + { + //没有直接插入 + // 保存数据 出/入库记录 + string InvoiceId = "Account_" + CurrentTimeMillis(); + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = channelStockList[i].MachineId, + DrawerNo = 0,//channelStockList[i].DrawerNo, + ColNo = 0,// channelStockList[i].ColNo,FV + DrugId = channelStockList[i].DrugId, + ManuNo = channelStockList[i].ManuNo, + EffDate = !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + Reviewer = HomeWindowViewModel.Reviewer?.Id, + OperationTime = DateTime.Now, + Quantity = 0, + Type = 5, + InvoiceId = string.Empty,//InvoiceId, + StockQuantity = channelStockList[i].Quantity, + ManunoQuantity = 0, + SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() + }).ExecuteCommand(); + + } + } + } + else + { + for (int i = 0; i < channelStockList.Count; i++) + { + //账册中没有记录则把库存中的所有数据都要生成一条账册记录 + // 保存数据 出/入库记录 + string InvoiceId = "Account_" + CurrentTimeMillis(); + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = channelStockList[i].MachineId, + DrawerNo = 0,//channelStockList[i].DrawerNo, + ColNo = 0,//channelStockList[i].ColNo, + DrugId = channelStockList[i].DrugId, + ManuNo = channelStockList[i].ManuNo, + EffDate = !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + Reviewer = HomeWindowViewModel.Reviewer?.Id, + OperationTime = DateTime.Now, + Quantity = 0, + Type = 5, + InvoiceId = string.Empty,//InvoiceId, + StockQuantity = channelStockList[i].Quantity, + ManunoQuantity = 0, + SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() + }).ExecuteCommand(); + } + } + AlertMsg alertMsg = new AlertMsg + { + Message = "日结存已生成完成", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + catch (Exception ex) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "生成日结存失败", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + RequestData(); + } + public long CurrentTimeMillis() + { + return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; + } + //public void InsertDayAccount() + //{ + // // 保存数据 出/入库记录 + // 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.AddQuantity, + // Type = 1, + // InvoiceId = InvoiceId, + // StockQuantity = nowChannels.Sum(it => it.Quantity), + // ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity), + // SupplierDept = Invoice.PharmacyName1 ?? ConfigurationManager.AppSettings["supplierDept"].ToString(), + // ReceiveDept = Invoice.PharmacyName2 ?? ConfigurationManager.AppSettings["receiveDept"].ToString() + // }).ExecuteCommand(); + //} + /// + /// 导出账册 + /// + public DelegateCommand DownloadAccountBook + { + get => new DelegateCommand(() => + { + GridReportUtil.PrintReportAccountBook(StartDate, EndDate, AccountType == null ? 0 : AccountType.AccountTypeValue, DrugInfo == null ? "" : DrugInfo.DrugId); + + }); + } + /// + /// 刷新 + /// + public DelegateCommand Query + { + get => new DelegateCommand(() => + { + RequestData(); + }); + } + + public bool KeepAlive => true; + + public void UpdateComboBoxItems(string text) + { + string str = @"SELECT d.drug_id,d.py_code,d.drug_barcode,d.drug_name,d.drug_brand_name,d.drug_spec,d.dosage,d.pack_unit, + d.manufactory,d.max_stock FROM `drug_info` d"; + if (string.IsNullOrEmpty(text)) + { + DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); + return; + } + if (DrugInfos != null) + { + DrugInfos.Clear(); + } + + DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).Where(di => di.DrugName.Contains(text) || di.PyCode.Contains(text) || di.DrugId.Contains(text)).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); + + } + + public void OnNavigatedTo(NavigationContext navigationContext) + { + //药品信息 + GetAllDrugInfos(); + //查询表格数据 + RequestData(); + } + + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + public void OnNavigatedFrom(NavigationContext navigationContext) + { + } + + } +} diff --git a/DM_Weight/ViewModels/AddDrugControlViewModel.cs b/DM_Weight/ViewModels/AddDrugControlViewModel.cs new file mode 100644 index 0000000..d6a90ed --- /dev/null +++ b/DM_Weight/ViewModels/AddDrugControlViewModel.cs @@ -0,0 +1,545 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.util; +using log4net; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Configuration; +using System.Drawing.Printing; +using System.Linq; +using System.Reflection.PortableExecutable; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Documents; + +namespace DM_Weight.ViewModels +{ + public class AddDrugControlViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime + { + private readonly ILog logger = LogManager.GetLogger(typeof(AddDrugControlViewModel)); + private List _drawerNoList = new List(); + public static AddDrugControlViewModel vm; + //凭证号 + private string _pzh; + public string PZH { get => _pzh; set { SetProperty(ref _pzh, value); } } + + private List? _channelLsts; + + public List? ChannelLsts + { + get => _channelLsts; + set => SetProperty(ref _channelLsts, value); + } + private List __channelStocks = new List(); + public List ChannelStocks + { + get => __channelStocks; + set => SetProperty(ref __channelStocks, value); + } + + private ChannelStock? _channelStock; + + public ChannelStock? CStock + { + get => _channelStock; + set => SetProperty(ref _channelStock, value); + } + + //private ChannelList? _channelList; + //public ChannelList? ChannelLst + //{ + // get => _channelList; + // set => SetProperty(ref _channelList, value); + //} + + private static readonly DateTime Jan1st1970 = new DateTime + (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + + private PortUtil _portUtil; + IEventAggregator _eventAggregator; + IDialogService _dialogService; + ////private SqlSugarScope SqlSugarHelper.Db; + public AddDrugControlViewModel(IDialogService DialogService, PortUtil portUtil, IEventAggregator eventAggregator) + { + _dialogService = DialogService; + _portUtil = portUtil; + _eventAggregator = eventAggregator; + ////this.SqlSugarHelper.Db = sqlSugarScope; + vm = this; + } + public DelegateCommand SelectionChangedCommand => new DelegateCommand(selectionAction); + + private async void selectionAction() + { + if (CStock != null) + { + // 此处延时1毫秒,等待页面渲染 + await Task.Delay(TimeSpan.FromMilliseconds(1)); + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("addManuno", CStock); + DialogServiceExtensions.ShowDialogHost(_dialogService, "AddManunoDialog", dialogParameters, DoDialogResult, "RootDialog"); + + } + + } + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + //if(dialogResult.Result == ButtonResult.OK) + //{ + CStock = null; + RequestData(); + //} + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } + void DoMyPrismEvent(DeviceMsg msg) + { + if (msg.WindowName == "AddDrugControl") + { + switch (msg.EventType) + { + // 抽屉打开 + case EventType.DRAWEROPEN: + if (Status == 1) + { + Status = 2; + } + + break; + // 抽屉关闭 + case EventType.DRAWERCLOSE: + if (Status == 2) + { + Status = 3; + } + break; + // 数量变化 + case EventType.UPDATEQUANTITY: + if (Status == 2) + { + //ChannelStocks.ForEach(it => it.AddQuantity = msg.Quantitys[it.ColNo - 1]); + } + break; + // 打开失败 + case EventType.OPENERROR: + AlertMsg alertMsg = new AlertMsg + { + Message = msg.Message, + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Status = 0; + break; + } + } + + } + + private int _status; + + public int Status { get => _status; set => SetProperty(ref _status, value); } + + private int _drawerNo = 1; + + public int DrawerNo + { + get => _drawerNo; + set => SetProperty(ref _drawerNo, value); + } + + private bool _is8Drawer = true; + + public bool Is8Drawer { get => _is8Drawer; set => SetProperty(ref _is8Drawer, value); } + + private bool _is16Drawer = false; + + public bool Is16Drawer { get => _is16Drawer; set => SetProperty(ref _is16Drawer, value); } + + + private bool _is17Drawer = false; + + public bool Is17Drawer { get => _is17Drawer; set => SetProperty(ref _is17Drawer, value); } + + + public DelegateCommand UpdateDrawerNo + { + get => new DelegateCommand((DrawerNo) => + { + this.DrawerNo = Convert.ToInt32(DrawerNo); + RequestData(); + }, (DrawerNo) => Status == 0 + ); + } + public DelegateCommand OpenDrawer + + { + get => new DelegateCommand(() => + { + Status = 1; + _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + + try + { + //List singleChannels = ChannelStocks.FindAll(it => it.BoardType != 1); + List singleChannels = ChannelLsts.FindAll(it => it.BoardType != 1); + + _portUtil.WindowName = "AddDrugControl"; + _portUtil.Operate = true; + _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; + _portUtil.ColNos = new int[] { };// singleChannels.Select(it => it.ColNo).ToArray(); + //_portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); + _portUtil.DrawerNo = DrawerNo; + _portUtil.Start(); + + } + catch (Exception ex) + { + logger.Info($"OpenDrawer异常:{ex.Message}"); + } + + + }, () => Status == 0).ObservesProperty(() => Status); + } + private bool _isFinishClick = false; + + // 完成按钮 + public DelegateCommand TakeFinish + { + get => new DelegateCommand(() => + { + if (!_isFinishClick) + { + _isFinishClick = true; + foreach (ChannelList lst in ChannelLsts) + { + ChannelStocks.AddRange(lst.channelStocks); + } + List record = ChannelStocks.FindAll(it => it.AddQuantity != 0).ToList(); + if (record.Count > 0) + { + //string InvoiceId = "DRAWER_" + CurrentTimeMillis(); + string InvoiceId = PZH; + //List repeatList = new List(); + List stockRepeats = new List(); + var f = SqlSugarHelper.Db.UseTran(() => + { + + for (int i = 0; i < record.Count; i++) + { + ChannelStock it = record[i]; + it.ManuNo = it.drugManuNo.ManuNo; + it.EffDate = it.drugManuNo.EffDate; + if (it.Id != null) + { + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = it.Quantity + it.AddQuantity, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + Id = it.Id, + }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); + } + else + { + //如果批号重复则不让添加 + List csCount = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == it.DrawerNo && cs.ManuNo == it.ManuNo && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).ToList(); + if (csCount.Count > 0) + { + //repeatList.Add(it.ManuNo); + stockRepeats.Add(it); + continue; + } + + // 更新数据 库存信息 + SqlSugarHelper.Db.Insertable(new ChannelStock() + { + Quantity = it.AddQuantity, + Chnguid = it.Chnguid, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + DrawerNo = it.DrawerNo, + ColNo = it.ColNo, + DrugId = it.DrugId, + DrawerType = it.DrawerType, + BoardType = it.BoardType, + Id = Guid.NewGuid().ToString(), + MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1" + }).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 = it.AddQuantity, + Type = 1, + InvoiceId = InvoiceId, + StockQuantity = nowChannels.Sum(it => it.Quantity), + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + }).ExecuteCommand(); + } + return true; + }); + //ChannelStocks.Clear(); + if (stockRepeats.Count == record.Count) + { + AlertMsg alertMsg = new AlertMsg + { + Message = $"该抽屉已存在此药品批次{string.Join(',', stockRepeats.Select(r=>r.ManuNo).ToArray())},请选择其他批次", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + else + { + if (f.Data) + { + + string msg = string.Empty; + MsgType type = MsgType.SUCCESS; + if (stockRepeats.Count > 0) + { + msg = $"该抽屉下批次{string.Join(',', stockRepeats.Select(r => r.ManuNo).ToArray())}已存在,不可重复添加,其他批次加药完成,库存已更新"; + foreach(var stockRpt in stockRepeats) + { + //移除重复的信息,以免更新屏显库存时更新了重复数据 + record.Remove(stockRpt); + + } + type = MsgType.WARING; + } + else + { + msg = "抽屉加药完成,库存已更新"; + } + // 更新屏显库存 + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = ChannelStocks.Where(it => it.BoardType != 1) + .GroupBy(it => it.ColNo) + .Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(itx => itx.Quantity); + ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + ret.EffDate = it.Min(it => it.EffDate); + ret.ManuNo = it.OrderBy(it=>it.ManuNo).Select(it=>it.ManuNo).First().ToString(); + return ret; + }) + .OrderBy(it=>it.EffDate) + .ToList(); + singleChannels = singleChannels.Where(it => it.AddQuantity > 0).ToList(); + if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + { + //将库位多批次的总库存数更新标签 + //_portUtil.WriteQuantity(singleChannels[0].DrawerNo, singleChannels[0].ColNo, singleChannels.Sum(it => it.Quantity) + singleChannels.Sum(it => it.AddQuantity)); + + singleChannels.ForEach(it => + { + + _portUtil.WriteChannelInfo(6, it.EffDate == null ? "" : it.EffDate, it.DrawerNo, it.ColNo); + Thread.Sleep(200); + _portUtil.WriteChannelInfo(5, it.ManuNo, it.DrawerNo, it.ColNo); + Thread.Sleep(200); + _portUtil.ShowContent(it.DrawerNo, it.ColNo); + + Thread.Sleep(500); + + //写库存数量 + _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity); + + }); + } + RequestData(); + AlertMsg alertMsg = new AlertMsg + { + Message = msg, + Type = type, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "更新库存失败", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + } + Status = 0; + _isFinishClick = false; + + PZH = string.Empty; + + ChannelStocks.Clear(); + } + else + { + _isFinishClick = false; + AlertMsg alertMsg = new AlertMsg + { + Message = "没有填写加药数量", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + + } + + }); + } + + // 取消按钮 + public DelegateCommand CancleTake + { + get => new DelegateCommand(() => + { + _portUtil.ResetData(); + Status = 0; + }); + } + + public bool KeepAlive => true; + + + + //添加批次 + public void AddAction(ChannelList channelLS) + { + if (channelLS != null) + { + ChannelStock cls = new ChannelStock(); + DrugManuNo drugManu = new DrugManuNo(); + cls.DrugInfo = channelLS.Drug; + if (channelLS.channelStocks.Count > 0) + { + cls.drugManuNo = channelLS.channelStocks[0].drugManuNo; + } + else + { + //drugManu= cls.DrugInfo.DrugManuNos[0]; + if (cls.DrugInfo.DrugManuNos.Count > 0) + { + cls.drugManuNo = cls.DrugInfo.DrugManuNos[0]; + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "该药品下没有批次,请先添加批次", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return; + } + } + //cls.Id = ""; + cls.Chnguid = channelLS.Id; + cls.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; + cls.DrawerNo = channelLS.DrawerNo; + cls.BoardType = channelLS.BoardType; + cls.DrawerType = channelLS.DrawerType; + cls.ColNo = channelLS.ColNo; + cls.DrugId = channelLS.DrugId; + cls.AddQuantity = 0; + List stockList = new List(); + stockList.AddRange(channelLS.channelStocks); + stockList.Add(cls); + channelLS.channelStocks = stockList; + } + } + + public long CurrentTimeMillis() + { + return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; + } + + public void FindDrawerCount() + { + int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); + Is8Drawer = count < 9; + Is16Drawer = count >= 16; + Is17Drawer = count > 16; + } + + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 + public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) + { + continuationCallback(true); + } + public void RequestData() + { + List queryData = SqlSugarHelper.Db.Queryable() + .Includes(cl => cl.Drug, di => di.DrugManuNos) + .Includes(cl => cl.channelStocks, dr => dr.DrugInfo, d => d.DrugManuNos) + .Where(cl => cl.DrawerNo == DrawerNo) + .Where(cl => cl.DrawerType == 1) + .Where(cl => cl.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .Where(cl => cl.DrugId != null) + .OrderBy(cl => cl.ColNo) + .ToList(); + ChannelLsts = queryData.Select(cl => + { + cl.channelStocks = cl.channelStocks.Select(cs => + { + cs.drugManuNo = cl.Drug.DrugManuNos.Find(it => it.ManuNo.Equals(cs.ManuNo)); + return cs; + }).ToList(); + return cl; + }).ToList(); + //ChannelLsts = new ObservableCollection(queryData); + ChannelLsts.ForEach(cl => cl.channelStocks.ForEach(cs => cs.DrugInfo = cl.Drug)); + } + + //接收导航传过来的参数 现在是在此处初始化了表格数据 + public void OnNavigatedTo(NavigationContext navigationContext) + { + _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + _eventAggregator.GetEvent().Subscribe(AddAction); + FindDrawerCount(); + RequestData(); + } + + + //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + //这个方法用于拦截请求 + public void OnNavigatedFrom(NavigationContext navigationContext) + { + // 取消消息订阅 + _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + _eventAggregator.GetEvent().Unsubscribe(AddAction); + } + } +} diff --git a/DM_Weight/ViewModels/BindingChannelDialogViewModel.cs b/DM_Weight/ViewModels/BindingChannelDialogViewModel.cs index 1acbb96..ef6f52a 100644 --- a/DM_Weight/ViewModels/BindingChannelDialogViewModel.cs +++ b/DM_Weight/ViewModels/BindingChannelDialogViewModel.cs @@ -21,7 +21,7 @@ using System.Threading; namespace DM_Weight.ViewModels { - public class BindingChannelDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime + public class BindingChannelDialogViewModel : BindableBase, IDialogAware { public string Title => "库位绑定"; @@ -50,14 +50,14 @@ namespace DM_Weight.ViewModels IEventAggregator _eventAggregator; PortUtil _portUtil; //ScreenUtil _screenUtil; - private SqlSugarScope _sqlSugarScope1; - public BindingChannelDialogViewModel(IEventAggregator eventAggregator, PortUtil portUtil, SqlSugarScope sqlSugarScope//, ScreenUtil screenUtil + ////private SqlSugarScope SqlSugarHelper.Db; + public BindingChannelDialogViewModel(IEventAggregator eventAggregator, PortUtil portUtil//, ScreenUtil screenUtil ) { _eventAggregator = eventAggregator; _portUtil = portUtil; //_screenUtil = screenUtil; - this._sqlSugarScope1 = sqlSugarScope; + ////this.SqlSugarHelper.Db = sqlSugarScope; } public int DrawerNo @@ -110,13 +110,13 @@ namespace DM_Weight.ViewModels List DrugList = null; if (!string.IsNullOrEmpty(pycode)) { - //DrugList = _sqlSugarScope1.Queryable().Includes(di => di.DrugManuNos).Where(di => di.PyCode.Contains(pycode)).OrderBy(di => di.DrugId).ToList(); - DrugList = _sqlSugarScope1.Queryable().Includes(di => di.DrugManuNos).Where(di => di.PyCode.Contains(pycode)).OrderBy(di => di.DrugId).ToList(); + //DrugList = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).Where(di => di.PyCode.Contains(pycode)).OrderBy(di => di.DrugId).ToList(); + DrugList = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).Where(di => di.PyCode.Contains(pycode)).OrderBy(di => di.DrugId).ToList(); } else { - //DrugList = _sqlSugarScope1.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); - DrugList = _sqlSugarScope1.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); + //DrugList = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); + DrugList = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); } return DrugList; } @@ -209,8 +209,8 @@ namespace DM_Weight.ViewModels private void GetAllDrugInfos() { - //var list = _sqlSugarScope1.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); - var list = _sqlSugarScope1.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); + //var list = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); + var list = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); DrugInfos = list; DrugInfos_PY = list; } @@ -219,14 +219,14 @@ namespace DM_Weight.ViewModels { Channels?.Clear(); int totalCount = 0; - //var list = _sqlSugarScope1.Queryable() + //var list = SqlSugarHelper.Db.Queryable() // .Includes(cs => cs.DrugInfo) // .WhereIF(DrawerNo > 0, cs => cs.DrawerNo == DrawerNo) // .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) // .OrderBy(cs => cs.DrawerNo) // .OrderBy(cs => cs.ColNo) // .ToPageList(PageNum, PageSize, ref totalCount); - var list = _sqlSugarScope1.Queryable() + var list = SqlSugarHelper.Db.Queryable() .Includes(cs => cs.DrugInfo) .WhereIF(DrawerNo > 0, cs => cs.DrawerNo == DrawerNo) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) @@ -268,7 +268,7 @@ namespace DM_Weight.ViewModels { if (DrugInfo != null) { - int count = _sqlSugarScope1.Queryable().Where(cs => cs.DrugId.Equals(DrugInfo.DrugId.ToString())).Where(cs => cs.DrawerType != 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).Count(); + int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrugId.Equals(DrugInfo.DrugId.ToString())).Where(cs => cs.DrawerType != 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).Count(); if (count == 0) { var item = SelectChannels[0]; @@ -278,8 +278,8 @@ namespace DM_Weight.ViewModels item.PosNo = 0; } item.DrugId = DrugInfo.DrugId.ToString(); - //_sqlSugarScope1.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo }).ExecuteCommand(); - _sqlSugarScope1.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo }).ExecuteCommand(); + //SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo }).ExecuteCommand(); GetChannelsByDrawerNo(); if (item.BoardType == 5) @@ -339,7 +339,7 @@ namespace DM_Weight.ViewModels // item.ManuNo = DrugManuNo.ManuNo; // item.DrugInfo = DrugInfo; // item.EffDate = String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate); - // _sqlSugarScope1.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); + // SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); // if (item.BoardType == 5) // { @@ -369,7 +369,7 @@ namespace DM_Weight.ViewModels // item.ManuNo = DrugManuNo.ManuNo; // item.DrugInfo = DrugInfo; // item.EffDate = String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate); - // _sqlSugarScope1.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); + // SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); // if (item.BoardType == 5) // { @@ -402,8 +402,8 @@ namespace DM_Weight.ViewModels item.ManuNo = DrugManuNo.ManuNo; item.DrugInfo = DrugInfo; item.EffDate = String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate); - //_sqlSugarScope1.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); - _sqlSugarScope1.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); + //SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); if (item.BoardType == 5) { @@ -460,8 +460,8 @@ namespace DM_Weight.ViewModels item.ManuNo = null; item.EffDate = null; item.DrugInfo = null; - //_sqlSugarScope1.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate }).ExecuteCommand(); - _sqlSugarScope1.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate }).ExecuteCommand(); + //SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate }).ExecuteCommand(); if (item.BoardType == 5) { // 清除显示屏库位信息 @@ -499,8 +499,8 @@ namespace DM_Weight.ViewModels item.ManuNo = null; item.EffDate = null; item.DrugInfo = null; - //_sqlSugarScope1.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate }).ExecuteCommand(); - _sqlSugarScope1.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate }).ExecuteCommand(); + //SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.ManuNo, it.EffDate }).ExecuteCommand(); if (item.BoardType == 5) { // 清除显示屏库位信息 @@ -532,7 +532,6 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => false; string message = string.Empty; private void DoMyPrismEvent(DeviceMsg msg) { diff --git a/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs new file mode 100644 index 0000000..9303581 --- /dev/null +++ b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs @@ -0,0 +1,544 @@ +using MaterialDesignThemes.Wpf; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.util; +using log4net; +using System.Threading; +using System.Reflection.Metadata.Ecma335; + +namespace DM_Weight.ViewModels +{ + public class BindingChannelNewDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime + { + + public string Title => "库位绑定"; + + public event Action RequestClose; + + private int _drawerNo = 0; + + + 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); + } + + IEventAggregator _eventAggregator; + PortUtil _portUtil; + //ScreenUtil _screenUtil; + ////private SqlSugarScope SqlSugarHelper.Db; + public static BindingChannelNewDialogViewModel vm; + public BindingChannelNewDialogViewModel(IEventAggregator eventAggregator, PortUtil portUtil//, ScreenUtil screenUtil + ) + { + _eventAggregator = eventAggregator; + _portUtil = portUtil; + //_screenUtil = screenUtil; + ////this.SqlSugarHelper.Db = sqlSugarScope; + vm = this; + } + + public int DrawerNo + { + get => _drawerNo; + set + { + SetProperty(ref _drawerNo, value); + GetChannelsByDrawerNo(); + } + } + + private DrugInfo? _drugInfo; + + public DrugInfo? DrugInfo + { + get => _drugInfo; + set + { + SetProperty(ref _drugInfo, value); + //if (_drugInfo != null) + //{ + // DrugManuNos = _drugInfo.DrugManuNos.OrderByDescending(dm => dm.ManuNo).ToList(); + //} + } + } + private List? _drugInfos; + public List? DrugInfos + { + get => _drugInfos; + set => SetProperty(ref _drugInfos, value); + } + ////拼音码对应药品实体 + //private DrugInfo? _durgInfo_for_py; + //public DrugInfo? DrugInfo_Py + //{ + // get => _durgInfo_for_py; + // set + // { + + // SetProperty(ref _durgInfo_for_py, value); + // if (_durgInfo_for_py != null) + // { + // DrugInfos = GetDrugByDrugPY(_durgInfo_for_py.PyCode); + // } + // else + // { + // DrugInfos = GetDrugByDrugPY(""); + // } + // } + //} + + //#region 根据药品拼音码查询药品名称 + //private List GetDrugByDrugPY(string pycode) + //{ + // List DrugList = null; + // if (!string.IsNullOrEmpty(pycode)) + // { + // DrugList = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).Where(di => di.PyCode.Contains(pycode)).OrderBy(di => di.DrugId).ToList(); + // } + // else + // { + // DrugList = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); + // } + // return DrugList; + //} + //private List? _drugInfos_py; + //public List? DrugInfos_PY + //{ + // get => _drugInfos_py; + // set => SetProperty(ref _drugInfos_py, value); + //} + //#endregion 根据药品拼音码查询药品名称 + + + public void UpdateComboBoxItems(string text) + { + string str = @"SELECT d.drug_id,d.py_code,d.drug_barcode,d.drug_name,d.drug_brand_name,d.drug_spec,d.dosage,d.pack_unit, + d.manufactory,d.max_stock,CONCAT(drug_name,' ',drug_spec)as drug_name_spec FROM `drug_info` d"; + if (string.IsNullOrEmpty(text)) + { + DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); + return; + } + if (DrugInfos != null) + { + DrugInfos.Clear(); + } + + DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).Where(di => di.DrugName.Contains(text) || di.PyCode.Contains(text) || di.DrugId.Contains(text)).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); + + } + //private List? _drugInfos; + + //public List? DrugInfos + //{ + // get => _drugInfos; + // set => SetProperty(ref _drugInfos, value); + //} + + //private DrugManuNo? _drugManuNo; + + //public DrugManuNo? DrugManuNo + //{ + // get => _drugManuNo; + // set => SetProperty(ref _drugManuNo, value); + //} + //private List? _drugManuNos; + + //public List? DrugManuNos + //{ + // get => _drugManuNos; + // set => SetProperty(ref _drugManuNos, value); + //} + + + private List? _channels; + + public List? Channels + { + get => _channels; + set => SetProperty(ref _channels, value); + } + + private int _totalCount = 0; + public int TotalCount { get => _totalCount; set => SetProperty(ref _totalCount, value); } + + private int _pageNum = 1; + public int PageNum + { + get => _pageNum; + set + { + SetProperty(ref _pageNum, value); + GetChannelsByDrawerNo(); + } + } + + private int _pageCount = 1; + public int PageCount + { + get => _pageCount; + set + { + SetProperty(ref _pageCount, value); + } + } + + private int _pageSize = 8; + public int PageSize + { + get => _pageSize; + set + { + SetProperty(ref _pageSize, value); + } + } + + + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + + private void GetAllDrugInfos() + { + //var list = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); + //DrugInfos = list; + //DrugInfos_PY = list; + string str = "SELECT d.drug_id,d.py_code,d.drug_barcode,d.drug_name,d.drug_brand_name,d.drug_spec,d.dosage,d.pack_unit,d.manufactory,d.max_stock,CONCAT(drug_name,' ',drug_spec)as drug_name_spec FROM `drug_info` d"; + DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); + + } + + private void GetChannelsByDrawerNo() + { + Channels?.Clear(); + int totalCount = 0; + var list = SqlSugarHelper.Db.Queryable() + .Includes(cl => cl.Drug) + .Includes(cs => cs.channelStocks) + .WhereIF(DrawerNo > 0, cl => cl.DrawerNo == DrawerNo) + .Where(cl => cl.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .OrderBy(cl => cl.DrawerNo) + .OrderBy(cl => cl.ColNo) + .ToPageList(PageNum, PageSize, ref totalCount); + if(list!=null&&list.Count>0) + { + for (int i = 0; i < list.Count; i++) + { + if(list[i].channelStocks!=null&& list[i].channelStocks.Count>0) + { + for (int j = 0; j < list[i].channelStocks.Count; j++) + { + list[i].totalCount += list[i].channelStocks[j].Quantity; + } + } + } + } + Channels = list; + TotalCount = totalCount; + } + public void OnDialogOpened(IDialogParameters parameters) + { + if (parameters.ContainsKey("DrawerNo")) + { + DrawerNo = parameters.GetValue("DrawerNo"); + } + GetAllDrugInfos(); + GetChannelsByDrawerNo(); + _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + } + public DelegateCommand Query + { + get => new DelegateCommand(() => + { + GetChannelsByDrawerNo(); + }); + } + + + public DelegateCommand BindingDrug + { + get => new DelegateCommand(async () => + { + + var SelectChannels = Channels.FindAll(item => item.IsSelected); + + if (SelectChannels.All(it => it.DrawerType != 1)) + { + if (SelectChannels.Count == 1) + { + if (DrugInfo != null) + { + int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrugId.Equals(DrugInfo.DrugId.ToString())).Where(cs => cs.DrawerType != 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).Count(); + if (count == 0) + { + var item = SelectChannels[0]; + + if (item.DrugId == null || !DrugInfo.DrugId.ToString().Equals(item.DrugId)) + { + item.PosNo = 0; + } + item.DrugId = DrugInfo.DrugId.ToString(); + SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo }).ExecuteCommand(); + GetChannelsByDrawerNo(); + + if (item.BoardType == 5) + { + _portUtil.WindowName = "BindingChannelDialog"; + // 向显示屏写入库位信息 + _portUtil.WriteChannelInfo(1, DrugInfo.DrugName, item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.WriteChannelInfo(2, DrugInfo.DrugSpec, item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.WriteChannelInfo(8, DrugInfo.Manufactory.Length>10? DrugInfo.Manufactory.Substring(0, 10): DrugInfo.Manufactory, item.DrawerNo, item.ColNo); + await Task.Delay(200); + //_portUtil.WriteChannelInfo(6, DrugManuNo.EffDate==null?"": DrugManuNo.EffDate, item.DrawerNo, item.ColNo); + //await Task.Delay(200); + //_portUtil.WriteChannelInfo(5, DrugManuNo.ManuNo, item.DrawerNo, item.ColNo); + //await Task.Delay(200); + _portUtil.ShowContent(item.DrawerNo, item.ColNo); + } + //_screenUtil.SetStockInfo(item, 1); + + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue($"药品【{DrugInfo.DrugName}】已经绑定了回收库位不可再次绑定"); + } + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("请选择库位需要绑定的药品信息"); + } + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("每种药品只能绑定一个回收库位"); + } + } + else + { + //if (DrugInfo != null && DrugManuNo != null) + //{ + + var c = SelectChannels.Count; + + if (c > 0) + { + if(c>1) + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("同一药品不可绑多个库位"); + return; + } + //else + //{ + // int count = SqlSugarHelper.Db.Queryable() + // .Where(cs => cs.DrugId.Equals(DrugInfo.DrugId.ToString())) + // .Where(cs => cs.DrawerType == 1) + // .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + // .Where(cs=>cs.DrawerNo=) + // .Count(); + + // if (count > 0) + // { + // SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + // SnackbarMessageQueue.Enqueue("该药品已绑定库位,不可绑定多个库位"); + // return; + // } + //} + + for (int i = 0; i < SelectChannels.Count; i++) + { + var item = SelectChannels[i]; + int count = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.DrugId.Equals(DrugInfo.DrugId.ToString())) + .Where(cs => cs.DrawerType == 1) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .Where(cs => cs.DrawerNo == item.DrawerNo) + .Count(); + + if (count > 0) + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("该药品已绑定库位,不可绑定多个库位"); + return; + } + var channelStock = SqlSugarHelper.Db.Queryable().Where(cs => cs.Chnguid == item.Id&&cs.Quantity>0).ToList(); + if(channelStock.Count>0) + { + //有库存,不能解绑 + + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue($"库位{item.DrawerNo}-{item.ColNo}中还存在药品,不能绑定其他药品"); + continue; + } + if (item.DrugId == null || !DrugInfo.DrugId.ToString().Equals(item.DrugId)) + { + item.PosNo = 0; + } + + item.DrugId = DrugInfo.DrugId.ToString(); + //item.ManuNo = DrugManuNo.ManuNo; + item.Drug = DrugInfo; + //item.EffDate = String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate); + SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo }).ExecuteCommand(); + + if (item.BoardType == 5) + { + _portUtil.WindowName = "BindingChannelDialog"; + // 向显示屏写入库位信息 + _portUtil.WriteChannelInfo(1, DrugInfo.DrugName, item.DrawerNo, item.ColNo); + await Task.Delay(200); + //Thread.Sleep(200); + _portUtil.WriteChannelInfo(2, DrugInfo.DrugSpec, item.DrawerNo, item.ColNo); + await Task.Delay(200); + //Thread.Sleep(200); + _portUtil.WriteChannelInfo(8, DrugInfo.Manufactory.Length > 10 ? DrugInfo.Manufactory.Substring(0, 10) : DrugInfo.Manufactory, item.DrawerNo, item.ColNo); + await Task.Delay(200); + //Thread.Sleep(200); + //_portUtil.WriteChannelInfo(6, DrugManuNo.ManuNo, item.DrawerNo, item.ColNo); + //await Task.Delay(200); + //Thread.Sleep(200); + //_portUtil.WriteChannelInfo(5, String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate), item.DrawerNo, item.ColNo); + ////await Task.Delay(200); + //Thread.Sleep(200); + _portUtil.ShowContent(item.DrawerNo, item.ColNo); + } + } + + + GetChannelsByDrawerNo(); + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("所选库位中无可绑定库位【库位还存在药品】"); + } + //} + //else + //{ + // SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + // SnackbarMessageQueue.Enqueue("请选择库位需要绑定的药品及批次信息"); + //} + } + }); + } + + public DelegateCommand RemoveBinding + { + get => new DelegateCommand(async () => + { + var SelectChannels = Channels.FindAll(item => item.IsSelected && item.DrugId != null); + var c = SelectChannels.Count; + if (c > 0) + { + + SelectChannels.ForEach(async item => + { + var channelStock = SqlSugarHelper.Db.Queryable().Where(cs => cs.Chnguid == item.Id && cs.Quantity > 0).ToList(); + if (channelStock.Count > 0) + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("所选库位中无可解绑药品【库位还存在药品】"); + //该药品下的批次还有库存则不能解绑 + return; + } + + item.DrugId = null; + //item.ManuNo = null; + //item.EffDate = null; + item.Drug = null; + SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable().SetColumns(it =>new ChannelStock { DrugId = null, ManuNo = null, EffDate = null} ).Where(it=>it.Chnguid==item.Id).ExecuteCommand(); + if (item.BoardType == 5) + { + // 清除显示屏库位信息 + _portUtil.ClearContent(item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.ShowContent(item.DrawerNo, item.ColNo); + } + + //_screenUtil.SetStockInfo(item, 1); + }); + GetChannelsByDrawerNo(); + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("所选库位中无可解绑药品"); + } + }); + } + + public DelegateCommand BtnCloseCommand + { + get => new DelegateCommand(() => + { + //DialogParameters parameters = new DialogParameters(); + //parameters.Add("",); + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + }); + } + + public bool KeepAlive => true; + string message = string.Empty; + private void DoMyPrismEvent(DeviceMsg msg) + { + if (msg.WindowName == "BindingChannelDialog") + { + switch (msg.EventType) + { + case EventType.OPENERROR: + AlertMsg alertMsg = new AlertMsg + { + Message = msg.Message, + Type = MsgType.ERROR, + }; + if (message != msg.Message) + { + message = msg.Message; + _eventAggregator.GetEvent().Publish(alertMsg); + } + break; + } + } + } + } +} diff --git a/DM_Weight/ViewModels/ChangeShiftsDialogViewModel.cs b/DM_Weight/ViewModels/ChangeShiftsDialogViewModel.cs index 3a5804b..037030e 100644 --- a/DM_Weight/ViewModels/ChangeShiftsDialogViewModel.cs +++ b/DM_Weight/ViewModels/ChangeShiftsDialogViewModel.cs @@ -29,7 +29,7 @@ namespace DM_Weight.ViewModels { public string Title => "交接班"; - public bool KeepAlive => false; + public bool KeepAlive => true; //交班人 发药人 public UserList Operator { get; set; } private bool _operatorLogin = false; @@ -164,10 +164,10 @@ namespace DM_Weight.ViewModels //{ DateTime dt = DateTime.Now; //保存交接班信息(查询当前值班人的最后一条交接班信息(如有则修改状态,没有则插入一条)并写入一条接班人信息) - //var f = _sqlSugarScope1.UseTran(() => - var f = _sqlSugarScope1.UseTran(() => + //var f = SqlSugarHelper.Db.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { - List listHkcChangeShifts = _sqlSugarScope1.Queryable() + List listHkcChangeShifts = SqlSugarHelper.Db.Queryable() .Where(cs => cs.State == "0") .WhereIF(Operator != null && !string.IsNullOrEmpty(Operator.UserName), cs => cs.FromOperator == Operator.UserName) .WhereIF(Reviewer != null && !string.IsNullOrEmpty(Reviewer.UserName), cs => cs.FromRviewer == Reviewer.UserName) @@ -177,7 +177,7 @@ namespace DM_Weight.ViewModels if (listHkcChangeShifts != null && listHkcChangeShifts.Count > 0) { //存在则修改,不存在则插入一条 - _sqlSugarScope1.Updateable(new HkcChangeShifts() + SqlSugarHelper.Db.Updateable(new HkcChangeShifts() { Id = listHkcChangeShifts[0].Id, ToOperator = JieOperator == null ? "" : JieOperator.UserName, @@ -188,7 +188,7 @@ namespace DM_Weight.ViewModels } else { - _sqlSugarScope1.Insertable(new HkcChangeShifts() + SqlSugarHelper.Db.Insertable(new HkcChangeShifts() { FromOperator = Operator == null ? "" : Operator.UserName, FromRviewer = Reviewer == null ? "" : Reviewer.UserName, @@ -201,7 +201,7 @@ namespace DM_Weight.ViewModels }).ExecuteCommand(); } - _sqlSugarScope1.Insertable(new HkcChangeShifts() + SqlSugarHelper.Db.Insertable(new HkcChangeShifts() { FromOperator = JieOperator == null ? "" : JieOperator.UserName, FromRviewer = JieReviewer == null ? "" : JieReviewer.UserName, @@ -225,7 +225,7 @@ namespace DM_Weight.ViewModels ORDER BY d2.operation_time DESC,d2.id DESC LIMIT 1) AS beforeNum from (SELECT drug_id,manu_no, SUM(IF(d1.`type` = 1, d1.quantity, 0)) AS getNum,SUM(IF(d1.`type` = 2, d1.quantity, 0)) AS useNum FROM dm_machine_record d1 WHERE d1.`type` IN (1, 2) AND d1.`operation_time` >= @startDate and d1.`operation_time` <=@endDate and d1.machine_id=@machineId GROUP BY d1.Drug_ID ,d1.manu_no) d LEFT JOIN drug_info drug on d.drug_id=drug.drug_id left JOIN channel_stock c on c.drug_id=d.drug_id and c.manu_no=d.manu_no AND c.machine_id=@machineId GROUP BY d.Drug_ID ,d.manu_no "; - List shiftsReports = _sqlSugarScope1.SqlQueryable(strSql) + List shiftsReports = SqlSugarHelper.Db.SqlQueryable(strSql) .AddParameters(new { machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1", @@ -240,7 +240,7 @@ namespace DM_Weight.ViewModels for (int i = 0; i < shiftsReports.Count; i++) { - _sqlSugarScope1.Insertable(new ShiftsReport() + SqlSugarHelper.Db.Insertable(new ShiftsReport() { OptDate = dt, DrugName = shiftsReports[i].DrugName, @@ -312,7 +312,7 @@ namespace DM_Weight.ViewModels LoginBtnEnable = false; if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) { - UserList userList = _sqlSugarScope1.Queryable() + UserList userList = SqlSugarHelper.Db.Queryable() .Includes(u => u.Role) .InnerJoin((u, r) => u.RoleId == r.Id) .First(u => u.UserName == username && ConfigurationManager.AppSettings["machineId"].ToString().Equals(u.MachineId)); @@ -508,7 +508,7 @@ namespace DM_Weight.ViewModels { if (msg.Message.Equals("LOGIN")) { - UserList userList = _sqlSugarScope1.Queryable() + UserList userList = SqlSugarHelper.Db.Queryable() .Includes(u => u.Role) .First(u => u.Id == msg.Id); @@ -609,11 +609,11 @@ namespace DM_Weight.ViewModels } IEventAggregator _eventAggregator; - private SqlSugarScope _sqlSugarScope1; - public ChangeShiftsDialogViewModel(IEventAggregator eventAggregator,SqlSugarScope sqlSugarScope) + ////private SqlSugarScope SqlSugarHelper.Db; + public ChangeShiftsDialogViewModel(IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + ////this.SqlSugarHelper.Db = sqlSugarScope; } public bool CanCloseDialog() @@ -631,8 +631,8 @@ namespace DM_Weight.ViewModels HkcChangeShifts changeOperator = GetOperator(); if (changeOperator != null) { - Operator = _sqlSugarScope1.Queryable().Where(u => u.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).Single(u => u.UserName == changeOperator.FromOperator); - Reviewer = _sqlSugarScope1.Queryable().Where(u => u.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).Single(u => u.UserName == changeOperator.FromRviewer); + Operator = SqlSugarHelper.Db.Queryable().Where(u => u.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).Single(u => u.UserName == changeOperator.FromOperator); + Reviewer = SqlSugarHelper.Db.Queryable().Where(u => u.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).Single(u => u.UserName == changeOperator.FromRviewer); } FingerMsg = false;// !_fingerprintUtil.bIsConnected; @@ -642,11 +642,11 @@ namespace DM_Weight.ViewModels private HkcChangeShifts GetOperator() { //查询发药人及审核人 - HkcChangeShifts changeOperator = _sqlSugarScope1.Queryable().Single(change => change.State == "0"); + HkcChangeShifts changeOperator = SqlSugarHelper.Db.Queryable().Single(change => change.State == "0"); //if (changeOperator != null) //{ - // Operator = _sqlSugarScope1.Queryable().Single(u => u.UserName == changeOperator.FromOperator); - // Reviewer = _sqlSugarScope1.Queryable().Single(u => u.UserName == changeOperator.ToOperator); + // Operator = SqlSugarHelper.Db.Queryable().Single(u => u.UserName == changeOperator.FromOperator); + // Reviewer = SqlSugarHelper.Db.Queryable().Single(u => u.UserName == changeOperator.ToOperator); //} return changeOperator; } diff --git a/DM_Weight/ViewModels/ChangeShiftsListWindowViewModel.cs b/DM_Weight/ViewModels/ChangeShiftsListWindowViewModel.cs index 6bfaee8..556d35d 100644 --- a/DM_Weight/ViewModels/ChangeShiftsListWindowViewModel.cs +++ b/DM_Weight/ViewModels/ChangeShiftsListWindowViewModel.cs @@ -104,7 +104,7 @@ namespace DM_Weight.ViewModels set { SetProperty(ref hkcChangeShifts, value); } } - public bool KeepAlive => false; + public bool KeepAlive => true; IDialogService _dialogService; //交接班 @@ -124,11 +124,11 @@ namespace DM_Weight.ViewModels { GridReportUtil.PrintChangeShiftsReport(StartDate, EndDate); } - private SqlSugarScope _sqlSugarScope1; - public ChangeShiftsListWindowViewModel(IDialogService dialogService,SqlSugarScope sqlSugarScope) + ////private SqlSugarScope SqlSugarHelper.Db; + public ChangeShiftsListWindowViewModel(IDialogService dialogService) { _dialogService = dialogService; - this._sqlSugarScope1 = sqlSugarScope; + ////this.SqlSugarHelper.Db = sqlSugarScope; } void RequestData() { @@ -147,7 +147,7 @@ namespace DM_Weight.ViewModels sqlStr += " and c.optdate<=@endOptDate "; } sqlStr+=" group by c.id"; - HkcChangeShifts = _sqlSugarScope1.SqlQueryable(sqlStr) + HkcChangeShifts = SqlSugarHelper.Db.SqlQueryable(sqlStr) .AddParameters(new { machineId = machineId, diff --git a/DM_Weight/ViewModels/ChangeShiftsRecordWindowViewModel.cs b/DM_Weight/ViewModels/ChangeShiftsRecordWindowViewModel.cs index 07a1aed..93b0c49 100644 --- a/DM_Weight/ViewModels/ChangeShiftsRecordWindowViewModel.cs +++ b/DM_Weight/ViewModels/ChangeShiftsRecordWindowViewModel.cs @@ -102,7 +102,7 @@ namespace DM_Weight.ViewModels set { SetProperty(ref machineRecords, value); } } - public bool KeepAlive => false; + public bool KeepAlive => true; IDialogService _dialogService; //交接班 @@ -124,7 +124,7 @@ namespace DM_Weight.ViewModels { int totalCount = 0; string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; - //MachineRecords = _sqlSugarScope1.Queryable() + //MachineRecords = SqlSugarHelper.Db.Queryable() // .Includes(mr => mr.DrugInfo) // .Includes(mr => mr.User) // .Where(mr => mr.MachineId == machineId) diff --git a/DM_Weight/ViewModels/ChangeShiftsWindowViewModel.cs b/DM_Weight/ViewModels/ChangeShiftsWindowViewModel.cs index 278c59f..bc258f3 100644 --- a/DM_Weight/ViewModels/ChangeShiftsWindowViewModel.cs +++ b/DM_Weight/ViewModels/ChangeShiftsWindowViewModel.cs @@ -79,7 +79,7 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IRegionManager _regionManager; IEventAggregator _eventAggregator; - public bool KeepAlive => false; + public bool KeepAlive => true; private bool _fingerMsg; @@ -88,13 +88,13 @@ namespace DM_Weight.ViewModels get => _fingerMsg; set => SetProperty(ref _fingerMsg, value); } - private SqlSugarScope _sqlSugarScope1; - public ChangeShiftsWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil,SqlSugarScope sqlSugarScope) + ////private SqlSugarScope SqlSugarHelper.Db; + public ChangeShiftsWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil) { _portUtil = portUtil; _regionManager = regionManager; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + ////this.SqlSugarHelper.Db = sqlSugarScope; } #region 交班确认按钮 @@ -188,22 +188,22 @@ namespace DM_Weight.ViewModels if ((JiaoBanFYRFlag || JiaoBanSHRFlag) && (JieBanFYRFlag || JieBanSHRFlag)) { //保存交接班信息(查询当前值班人的最后一条交接班信息(如有则修改状态,没有则插入一条)并写入一条接班人信息) - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { - List listHkcChangeShifts = _sqlSugarScope1.Queryable() + List listHkcChangeShifts = SqlSugarHelper.Db.Queryable() .Where(cs => cs.State == "0") .WhereIF(App.CurrentFaUserList != null && !string.IsNullOrEmpty(App.CurrentFaUserList.UserName), cs => cs.FromOperator == App.CurrentFaUserList.UserName) .WhereIF(App.CurrentShenUserList != null && !string.IsNullOrEmpty(App.CurrentShenUserList.UserName), cs => cs.FromRviewer == App.CurrentShenUserList.UserName) .OrderByDescending(cs => cs.OptState) .ToList(); - //List listMachineRecord=_sqlSugarScope1.Queryable() + //List listMachineRecord=SqlSugarHelper.Db.Queryable() //.Where(m=>) if (listHkcChangeShifts != null && listHkcChangeShifts.Count > 0) { //存在则修改,不存在则插入一条 - _sqlSugarScope1.Updateable(new HkcChangeShifts() + SqlSugarHelper.Db.Updateable(new HkcChangeShifts() { Id = listHkcChangeShifts[0].Id, ToOperator = Operator == null ? "" : Operator.UserName, @@ -215,7 +215,7 @@ namespace DM_Weight.ViewModels } else { - _sqlSugarScope1.Insertable(new HkcChangeShifts() + SqlSugarHelper.Db.Insertable(new HkcChangeShifts() { FromOperator = App.CurrentFaUserList.UserName, FromRviewer = App.CurrentShenUserList.UserName, @@ -227,7 +227,7 @@ namespace DM_Weight.ViewModels }).ExecuteCommand(); } - _sqlSugarScope1.Insertable(new HkcChangeShifts() + SqlSugarHelper.Db.Insertable(new HkcChangeShifts() { FromOperator = App.CurrentFaUserList.UserName, FromRviewer = App.CurrentShenUserList.UserName, @@ -266,7 +266,7 @@ namespace DM_Weight.ViewModels if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(passWord)) { { - UserList userList = _sqlSugarScope1.Queryable() + UserList userList = SqlSugarHelper.Db.Queryable() .Includes(u => u.Role) .InnerJoin((u, r) => u.RoleId == r.Id) .First(u => u.UserName == userName && ConfigurationManager.AppSettings["machineId"].ToString().Equals(u.MachineId)); @@ -350,7 +350,7 @@ namespace DM_Weight.ViewModels if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(passWord)) { { - UserList userList = _sqlSugarScope1.Queryable() + UserList userList = SqlSugarHelper.Db.Queryable() .Includes(u => u.Role) .InnerJoin((u, r) => u.RoleId == r.Id) .First(u => u.UserName == userName && ConfigurationManager.AppSettings["machineId"].ToString().Equals(u.MachineId)); @@ -419,7 +419,7 @@ namespace DM_Weight.ViewModels { if (msg.Message.Equals("LOGIN")) { - UserList userList = _sqlSugarScope1.Queryable() + UserList userList = SqlSugarHelper.Db.Queryable() .Includes(u => u.Role) .First(u => u.Id == msg.Id); diff --git a/DM_Weight/ViewModels/CheckRecordDetailDialogViewModel.cs b/DM_Weight/ViewModels/CheckRecordDetailDialogViewModel.cs new file mode 100644 index 0000000..f2add79 --- /dev/null +++ b/DM_Weight/ViewModels/CheckRecordDetailDialogViewModel.cs @@ -0,0 +1,198 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.Report; +using DM_Weight.util; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace DM_Weight.ViewModels +{ + public class CheckRecordDetailDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime + { + public string Title => "盘点记录明细"; + private int _pageNum = 1; + public int PageNum + { + get => _pageNum; + set + { + SetProperty(ref _pageNum, value); + RequestData(); + } + } + + private int _pageCount = 1; + public int PageCount + { + get => _pageCount; + set + { + SetProperty(ref _pageCount, value); + } + } + + private int _pageSize = 8; + public int PageSize + { + get => _pageSize; + set + { + SetProperty(ref _pageSize, value); + } + } + + private int _totalCount = 0; + public int TotalCount + { + get => _totalCount; + set + { + SetProperty(ref _totalCount, value); + } + } + private DateTime? _startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); + + public DateTime? StartDate + { + get => _startDate; + set + { + if (value != null) + { + SetProperty(ref _startDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0)); + } + else + { + SetProperty(ref _startDate, value); + } + RequestData(); + } + } + + private DateTime? _endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); + + public DateTime? EndDate + { + get => _endDate; + set + { + if (value != null) + { + TimeSpan ershisi = new TimeSpan(23, 59, 59); + SetProperty(ref _endDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0, 23, 59, 59)); + } + else + { + SetProperty(ref _endDate, value); + } + + RequestData(); + } + } + + private string _optDate; + public string OptDate + { + get => _optDate; + set + { + SetProperty(ref _optDate, value); + } + } + + private ObservableCollection _obsCheckRecordStock = new ObservableCollection(); + public ObservableCollection obsCheckRecordStock + { + get => _obsCheckRecordStock; + set => SetProperty(ref _obsCheckRecordStock, value); + } + private CheckRecordStock _checkRecordStock = new CheckRecordStock(); + public CheckRecordStock checkRecordStock + { + get => _checkRecordStock; + set => SetProperty(ref _checkRecordStock, value); + } + + private List? _channelStocks = new(); + + public List? ChannelStocks + { + get => _channelStocks; + set => SetProperty(ref _channelStocks, value); + } + ////private SqlSugarScope SqlSugarHelper.Db; + private PortUtil _portUtil; + IEventAggregator _eventAggregator; + + public event Action RequestClose; + + public CheckRecordDetailDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService dialogService) + { + ////this.SqlSugarHelper.Db = sqlSugarScope; + _portUtil = portUtil; + _eventAggregator = eventAggregator; + } + public void RequestData() + { + + ChannelStocks.Clear(); + obsCheckRecordStock.Clear(); + //string strSql = "SELECT optDate AS optdate,U.User_name AS operatorUser,R.User_name AS reviewerUser,Drug_ID AS drugId,Drug_name AS drugName FROM check_stock C LEFT JOIN user_list U ON C.operator=U.ID LEFT JOIN user_list R ON C.reviewer=R.ID WHERE 1=1"; + //if (StartDate != null) + //{ + // strSql += " AND C.optDate=@OPTSTARTDATE "; + //} + //strSql += " GROUP BY C.optdate,Drug_id ORDER BY C.OPTDATE DESC"; + List checkList = SqlSugarHelper.Db.Queryable() + .Includes(cs => cs.DrugInfo) + .Where(cs => cs.optdate == OptDate).OrderByDescending(cs => cs.optdate).ToList(); + ICollectionView vw = CollectionViewSource.GetDefaultView(checkList); + vw.GroupDescriptions.Add(new PropertyGroupDescription("DrugInfo")); + obsCheckRecordStock = new ObservableCollection(checkList); + + ChannelStocks = checkList; + + } + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + + } + + public void OnDialogOpened(IDialogParameters parameters) + { + if (parameters.ContainsKey("OptDate")) + { + OptDate = parameters.GetValue("OptDate"); + } + RequestData(); + } + public DelegateCommand BtnCloseCommand { + get => new DelegateCommand(() => + { + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + }); + } + + public bool KeepAlive => true; + } +} diff --git a/DM_Weight/ViewModels/CheckRecordNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckRecordNewWindowViewModel.cs new file mode 100644 index 0000000..39d60fc --- /dev/null +++ b/DM_Weight/ViewModels/CheckRecordNewWindowViewModel.cs @@ -0,0 +1,211 @@ +using DM_Weight.Models; +using DM_Weight.Port; +using DM_Weight.Report; +using DM_Weight.util; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace DM_Weight.ViewModels +{ + public class CheckRecordNewWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime + { + private int _pageNum = 1; + public int PageNum + { + get => _pageNum; + set + { + SetProperty(ref _pageNum, value); + RequestData(); + } + } + + private int _pageCount = 1; + public int PageCount + { + get => _pageCount; + set + { + SetProperty(ref _pageCount, value); + } + } + + private int _pageSize = 8; + public int PageSize + { + get => _pageSize; + set + { + SetProperty(ref _pageSize, value); + } + } + + private int _totalCount = 0; + public int TotalCount + { + get => _totalCount; + set + { + SetProperty(ref _totalCount, value); + } + } + private DateTime? _startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); + + public DateTime? StartDate + { + get => _startDate; + set + { + if (value != null) + { + SetProperty(ref _startDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0)); + } + else + { + SetProperty(ref _startDate, value); + } + RequestData(); + } + } + + private DateTime? _endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); + + public DateTime? EndDate + { + get => _endDate; + set + { + if (value != null) + { + TimeSpan ershisi = new TimeSpan(23, 59, 59); + SetProperty(ref _endDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0, 23, 59, 59)); + } + else + { + SetProperty(ref _endDate, value); + } + + RequestData(); + } + } + public event Action RequestClose; + private ObservableCollection _obsCheckRecordStock = new ObservableCollection(); + public ObservableCollection obsCheckRecordStock + { + get => _obsCheckRecordStock; + set=>SetProperty(ref _obsCheckRecordStock, value); + } + private CheckRecordStock _checkRecordStock=new CheckRecordStock(); + public CheckRecordStock checkRecordStock + { + get => _checkRecordStock; + set=>SetProperty(ref _checkRecordStock, value); + } + + + ////private SqlSugarScope SqlSugarHelper.Db; + private PortUtil _portUtil; + IEventAggregator _eventAggregator; + IDialogService _dialogService; + public CheckRecordNewWindowViewModel(IDialogService DialogService, PortUtil portUtil, IEventAggregator eventAggregator, IDialogService dialogService) + { + _dialogService = DialogService; + ////this.SqlSugarHelper.Db = sqlSugarScope; + _portUtil = portUtil; + _eventAggregator = eventAggregator; + } + public DelegateCommand DownLoadCommond + { + get => new DelegateCommand(() => + { + GridReportUtil.PrintReportStockNew(StartDate, EndDate); + }); + } + public DelegateCommand Query + { + get => new DelegateCommand(() => + { + RequestData(); + }); + } + public void RequestData() + { + int totalCount = 0; + string strSql = @"SELECT optDate AS optdate,U.User_name AS operatorUser,R.User_name AS reviewerUser,Drug_spec AS drugSpec,Manufactory AS manufactory,Quantity FROM check_stock C + LEFT JOIN user_list U ON C.operator=U.ID LEFT JOIN user_list R ON C.reviewer=R.ID WHERE 1=1"; + if(StartDate!=null) + { + strSql += " AND C.optDate>@OPTSTARTDATE "; + } + if(EndDate!=null) + { + strSql += " AND C.optDate<@OPTENDDATE "; + } + strSql += " GROUP BY C.optdate ORDER BY C.OPTDATE DESC"; + List checkList = SqlSugarHelper.Db.SqlQueryable(strSql) + .AddParameters(new + { + OPTSTARTDATE = StartDate, + OPTENDDATE = EndDate + }).ToPageList(PageNum, PageSize, ref totalCount); + //SqlSugarHelper.Db.ThenMapper(checkList, item => + //{ + // //item.drugDetails = SqlSugarHelper.Db.Queryable().SetContext(x => x.optdate, () => item.optdate, item).ToList(); + // item.manuNoDetails = SqlSugarHelper.Db.Queryable().SetContext(x => x.optdate, () => item.optdate, item).ToList(); + //}); + obsCheckRecordStock = new ObservableCollection(checkList); + + } + + public DelegateCommand RowSelected + { + get => new DelegateCommand(async () => + { + if (checkRecordStock != null && checkRecordStock.optdate!=null) + { + // 此处延时1毫秒,等待页面渲染 + await Task.Delay(TimeSpan.FromMilliseconds(1)); + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("OptDate", checkRecordStock.optdate); + DialogServiceExtensions.ShowDialogHost(_dialogService, "CheckRecordDetailDialog", dialogParameters, DoDialogResult, "RootDialog"); + + } + }); + } + + public bool KeepAlive => true; + + private void DoDialogResult(IDialogResult dialogResult) + { + checkRecordStock = null; + RequestData(); + } + + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + public void OnNavigatedFrom(NavigationContext navigationContext) + { + + } + + public void OnNavigatedTo(NavigationContext navigationContext) + { + RequestData(); + } + } +} diff --git a/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs b/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs new file mode 100644 index 0000000..d8731d1 --- /dev/null +++ b/DM_Weight/ViewModels/CheckStockNew2WindowViewModel.cs @@ -0,0 +1,604 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.Report; +using DM_Weight.select; +using DM_Weight.util; +using log4net; +using log4net.Repository.Hierarchy; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace DM_Weight.ViewModels +{ + public class CheckStockNew2WindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime + { + //public static CheckStockNewWindowViewModel vm; + private readonly ILog logger = LogManager.GetLogger(typeof(CheckStockWindowViewModel)); + public string drugId; + //public string Stock; + private static readonly DateTime Jan1st1970 = new DateTime + (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + public static List StaticSelects = new() + { + new OrderTakeSelect + { + Code = "DrugName", + Name = "药品名称" + }, + new OrderTakeSelect + { + Code = "PyCode", + Name = "拼音码" + }, + new OrderTakeSelect + { + Code = "DrugBarcode", + Name = "药品条码" + }, + new OrderTakeSelect + { + Code = "DrugId", + Name = "药品编码" + } + }; + + private List _selects = StaticSelects; + + public List Selects + { + get { return _selects; } + set + { + SetProperty(ref _selects, value); + } + } + + private OrderTakeSelect _selectedItem = StaticSelects[0]; + /// + /// 查询条件 查询字段 + /// + public OrderTakeSelect SelectedItem + { + get { return _selectedItem; } + set + { + SetProperty(ref _selectedItem, value); + RequestData(); + } + } + + private string? _searchValue; + + /// + /// 查询条件 查询字段值 + /// + public string? SearchValue + { + get { return _searchValue; } + set + { + SetProperty(ref _searchValue, value); + RequestData(); + } + } + IDialogService _dialogService; + IEventAggregator _eventAggregator; + ////private SqlSugarScope SqlSugarHelper.Db; + private PortUtil _portUtil; + private int _status; + + public int Status { get => _status; set => SetProperty(ref _status, value); } + + private int _drawerNo = 1; + + public int DrawerNo + { + get => _drawerNo; + set => SetProperty(ref _drawerNo, value); + } + + public long CurrentTimeMillis() + { + return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; + } + + public CheckStockNew2WindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService dialogService) + { + _dialogService = dialogService; + ////this.SqlSugarHelper.Db = sqlSugarScope; + _portUtil = portUtil; + _portUtil = portUtil; + _eventAggregator = eventAggregator; + //vm= this; + } + void DoMyPrismEvent(DeviceMsg msg) + { + + if (msg.WindowName == "CheckStockNewWindow") + { + IGrouping grouping = enumerator.Current; + int DrawerNo = grouping.Key; + List channelStocks = grouping.ToList(); + + switch (msg.EventType) + { + // 抽屉打开 + case EventType.DRAWEROPEN: + + + if (Status == 1) + { + if (channelStocks[0].process == 1) + { + channelStocks.ForEach(it => it.process = 2); + } + //Status = 2; + } + + break; + // 抽屉关闭 + case EventType.DRAWERCLOSE: + if (Status == 1) + { + if (channelStocks[0].process == 2) + { + channelStocks.ForEach(it => it.process = 3); + } + IGrouping groupingBefore = enumerator.Current; + int DrawerNoBefore = groupingBefore.Key; + if (enumerator.MoveNext()) + { + IGrouping groupingAfter = enumerator.Current; + int DrawerNoAfter = groupingAfter.Key; + //if (DrawerNoBefore < 9 && DrawerNoAfter > 8) + //{ + // Thread.Sleep(50); + //} + + logger.Info($"抽屉号DrawerNoBefore【{DrawerNoBefore}】抽屉号DrawerNoAfter【{DrawerNoAfter}】"); + if (DrawerNoAfter == 17) + { + if (DrawerNoBefore == 17) + { + Thread.Sleep(1000); + } + else + { + Thread.Sleep(500); + } + } + else + { + Thread.Sleep(80); + } + logger.Info($"抽屉号DrawerNoBefore【{DrawerNoBefore}】抽屉号DrawerNoAfter【{DrawerNoAfter}】"); + OpenOneByOne(); + } + // 已经全部取出 + else + { + Status = 3; + } + } + break; + // 数量变化 + case EventType.UPDATEQUANTITY: + if (Status == 1) + { + logger.Info($"抽屉【{DrawerNo}】库位药品数量【{msg.Quantitys}】"); + } + break; + // 打开失败 + case EventType.OPENERROR: + AlertMsg alertMsg = new AlertMsg + { + Message = msg.Message, + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Status = 0; + break; + } + } + + } + private ChannelStock? _selectedChannel; + + public ChannelStock? SelectedChannel + { + get => _selectedChannel; + set => SetProperty(ref _selectedChannel, value); + } + + private List? _channelStocks = new(); + + public List? ChannelStocks + { + get => _channelStocks; + set => SetProperty(ref _channelStocks, value); + } + + private IEnumerable> enumerable; + private IEnumerator> enumerator; + + public DelegateCommand BindingChannelDialog + { + get => new DelegateCommand(() => + { + DialogParameters dialogParameters = new DialogParameters(); + DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelDialog", dialogParameters, DoDialogResult, "RootDialog"); + }); + } + + + public DelegateCommand QueryCommand + { + get => new DelegateCommand(() => + { + RequestData(); + }); + } + /// + /// 盘点 + /// + public DelegateCommand OpenDrawer + { + get => new DelegateCommand(() => + { + if (Status == 0) + { + enumerable = ChannelStocks.GroupBy(cs => cs.DrawerNo, cs => cs); + //enumerable = ChannelStocks.GroupBy(cs => cs.Location, cs => cs); + enumerator = enumerable.GetEnumerator(); + enumerator.MoveNext(); + Status = 1; + OpenOneByOne(); + } + }); + } + private void OpenOneByOne() + { + IGrouping grouping = enumerator.Current; + int DrawerNo =grouping.Key; + List channelStocks = grouping.ToList(); + channelStocks.ForEach(it => it.process = 1); + _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + + List singleChannels = channelStocks.GroupBy(it => new + { + it.DrawerNo, + it.ColNo + }).Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(itx => itx.Quantity); + ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList().FindAll(it => it.BoardType != 1); + + // 发送取药数量 + //singleChannels.ForEach(it => + //{ + // try + // { + + // _portUtil.TakeQuantity(DrawerNo, it.ColNo, it.TakeQuantity, it.Quantity - it.TakeQuantity); + // } + // catch (Exception ex) + // { + // AlertMsg alertMsg = new AlertMsg + // { + // Message = $"打开抽屉异常{ex.Message}", + // Type = MsgType.ERROR, + // }; + // _eventAggregator.GetEvent().Publish(alertMsg); + // } + //}); + _portUtil.WindowName = "CheckStockNewWindow"; + _portUtil.Operate = true; + _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; + _portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray(); + _portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); + _portUtil.DrawerNo = DrawerNo; + _portUtil.Start(); + } + + private bool _isFinishClick = false; + + // 完成按钮 + public DelegateCommand TakeFinish + { + get => new DelegateCommand(() => + { + _isFinishClick = true; + //List record = ChannelStocks.FindAll(it => it.Quantity != it.CheckQuantity).ToList(); + List record = ChannelStocks; + if (record.Count > 0) + { + string InvoiceId = "CHECK_" + CurrentTimeMillis(); + var f = SqlSugarHelper.Db.UseTran(() => + { + + for (int i = 0; i < record.Count; i++) + { + ChannelStock it = record[i]; + + + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = it.CheckQuantity, + 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 = it.CheckQuantity - it.Quantity, + Type = 4, + InvoiceId = InvoiceId, + StockQuantity = nowChannels.Sum(it => it.Quantity), + CheckQuantity = it.CheckQuantity, + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + }).ExecuteCommand(); + + + logger.Info($"库存盘点->库位【{it.DrawerNo}-{it.ColNo}】药品【{it.DrugInfo.DrugName}】盘点前库存【{it.Quantity}】,更改后【{it.CheckQuantity}】"); + } + + + string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + string strSql = $@"SELECT cl.`row_no` AS rowNo,cl.`col_no` AS colNo,cl.`quantity` AS quantity,cl.`manu_no` AS manuNo,cl.`eff_date` AS effDate, + di.`drug_name` AS drugName,di.`drug_spec` AS drugSpec,di.`pack_unit` AS packUnit,di.`manufactory` AS manufactory,di.`max_stock` maxStock, + cl.`drug_id` AS drugId,cl.`machine_id` AS MachineId FROM channel_stock cl INNER JOIN drug_info di ON di.`drug_id` = cl.`drug_id` WHERE cl.`machine_id` = '{machine_id}' AND cl.`drawer_type` = 1 ORDER BY cl.`drug_id`"; + List checkRecordStockList = SqlSugarHelper.Db.SqlQueryable(strSql) + .AddParameters(new + { + machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1" + }) + .Select(it => new CheckRecordStock()) + .ToList(); + List insertList = new List(); + + if (checkRecordStockList != null && checkRecordStockList.Count > 0) + { + for (int i = 0; i < checkRecordStockList.Count; i++) + { + if (!(insertList.Where(it => it.drugId == checkRecordStockList[i].drugId && it.manuNo == checkRecordStockList[i].manuNo).Count() > 0)) + { + insertList.Add(checkRecordStockList[i]); + } + } + for (int j = 0; j < insertList.Count; j++) + { + + + CheckRecordStock cStock = insertList[j]; + // 保存数据 盘点后药品总库存及批次库存数 + SqlSugarHelper.Db.Insertable(new CheckRecordStock() + { + rowNo = cStock.rowNo, + colNo = cStock.colNo, + ManuQuantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId && it.manuNo == cStock.manuNo).Sum(it => it.quantity), + manuNo = cStock.manuNo, + effDate = cStock.effDate, + drugName = cStock.drugName, + manufactory = cStock.manufactory, + drugSpec = cStock.drugSpec, + packUnit = cStock.packUnit, + maxStock = cStock.maxStock, + drugId = cStock.drugId, + MachineId = cStock.MachineId, + quantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId).Sum(it => it.quantity), + optdate = DateTime.Now.ToString(), + operatorUser = HomeWindowViewModel.Operator?.Id.ToString(), + reviewerUser = HomeWindowViewModel.Reviewer?.Id.ToString() + }).ExecuteCommand(); + } + } + + + return true; + }); + if (f.Data) + { + // 更新屏显库存 + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = record.FindAll(it => it.BoardType != 1) + .GroupBy(it => new + { + it.DrawerNo, + it.ColNo + }).Select(it => + { + var ret = it.First(); + ret.CheckQuantity = it.Sum(itx => itx.CheckQuantity); + //ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList(); + if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + { + singleChannels.ForEach(it => + { + // 将库位多批次的总库存数更新标签 + _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.CheckQuantity); + + }); + } + + 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; + _isFinishClick = false; + } + else + { + _isFinishClick = false; + AlertMsg alertMsg = new AlertMsg + { + Message = "盘点完成,库存无改变", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Status = 0; + _isFinishClick = false; + } + + + }, () => Status == 3 && !_isFinishClick).ObservesProperty(() => Status); + } + + // 取消按钮 + public DelegateCommand CancleTake + { + get => new DelegateCommand(() => + { + _portUtil.ResetData(); + Status = 0; + }); + } + + public bool KeepAlive => true; + + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + //if (dialogResult.Result == ButtonResult.OK) + //{ + RequestData(); + //} + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } + ///// + ///// 导出账册 + ///// + //public DelegateCommand DownloadAccountBook + //{ + // get => new DelegateCommand(() => + // { + // if (!string.IsNullOrEmpty(Stock)) + // { + // //根据库位信息查询出药品id + // string[] strStock = Stock.Split('-'); + // if (strStock.Length >= 2) + // { + // //DrugId = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == Convert.ToInt32(strStock[0]) && cs.ColNo == Convert.ToInt32(strStock[1])).Select(cs => cs.DrugId).ToString(); + // var list = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == Convert.ToInt32(strStock[0]) && cs.ColNo == Convert.ToInt32(strStock[1]) && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).ToList(); + // if (list != null && list.Count > 0) + // { + // drugId = list[0].DrugId; + // } + // } + // } + // GridReportUtil.PrintReportAccountBook(StartDate, EndDate, drugId ?? ""); + // }); + //} + //public DelegateCommand DownLoadCommond + //{ + // get => new DelegateCommand(() => + // { + // GridReportUtil.PrintReportStockNew(StartDate, EndDate); + // }); + //} + + + + + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 + public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) + { + continuationCallback(true); + } + + + public void RequestData() + { + ChannelStocks.Clear(); + + List q = SqlSugarHelper.Db.Queryable() + .Includes(cs => cs.DrugInfo) + .InnerJoin((cs, cl) => cs.Chnguid == cl.Id && cs.DrugId == cl.DrugId) + .Where(cs => cs.DrawerType == 1) + .Where(cs => cs.DrugId != null) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + + .WhereIF(!String.IsNullOrEmpty(SearchValue), cs => cs.DrugInfo.DrugName == SearchValue) + .OrderBy(cs => cs.DrawerNo) + .OrderBy(cs => cs.ColNo) + //.OrderBy(cs => cs.DrugId) + .ToList(); + ChannelStocks = q.Select(it => { it.CheckQuantity = it.Quantity; return it; }).ToList(); + ChannelStocks = q; + + } + + //接收导航传过来的参数 现在是在此处初始化了表格数据 + public void OnNavigatedTo(NavigationContext navigationContext) + { + _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + Task.Factory.StartNew(() => { RequestData(); }); + //RequestData(); + } + + + //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + //这个方法用于拦截请求 + public void OnNavigatedFrom(NavigationContext navigationContext) + { + // 取消消息订阅 + _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + } +} diff --git a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs new file mode 100644 index 0000000..6cd723f --- /dev/null +++ b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs @@ -0,0 +1,647 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.Report; +using DM_Weight.select; +using DM_Weight.util; +using log4net; +using log4net.Repository.Hierarchy; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace DM_Weight.ViewModels +{ + public class CheckStockNewWindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime + { + //public static CheckStockNewWindowViewModel vm; + private readonly ILog logger = LogManager.GetLogger(typeof(CheckStockWindowViewModel)); + public string drugId; + //public string Stock; + private static readonly DateTime Jan1st1970 = new DateTime + (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + public static List StaticSelects = new() + { + new OrderTakeSelect + { + Code = "DrugName", + Name = "药品名称" + }, + new OrderTakeSelect + { + Code = "PyCode", + Name = "拼音码" + }, + new OrderTakeSelect + { + Code = "DrugBarcode", + Name = "药品条码" + }, + new OrderTakeSelect + { + Code = "DrugId", + Name = "药品编码" + } + }; + + private List _selects = StaticSelects; + + public List Selects + { + get { return _selects; } + set + { + SetProperty(ref _selects, value); + } + } + + private OrderTakeSelect _selectedItem = StaticSelects[0]; + /// + /// 查询条件 查询字段 + /// + public OrderTakeSelect SelectedItem + { + get { return _selectedItem; } + set + { + SetProperty(ref _selectedItem, value); + RequestData(); + } + } + + private string? _searchValue; + + /// + /// 查询条件 查询字段值 + /// + public string? SearchValue + { + get { return _searchValue; } + set + { + SetProperty(ref _searchValue, value); + RequestData(); + } + } + //private DateTime? _startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); + + //public DateTime? StartDate + //{ + // get => _startDate; + // set + // { + // if (value != null) + // { + // SetProperty(ref _startDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0)); + // } + // else + // { + // SetProperty(ref _startDate, value); + // } + // RequestData(); + // } + //} + + //private DateTime? _endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); + + //public DateTime? EndDate + //{ + // get => _endDate; + // set + // { + // if (value != null) + // { + // TimeSpan ershisi = new TimeSpan(23, 59, 59); + // SetProperty(ref _endDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0, 23, 59, 59)); + // } + // else + // { + // SetProperty(ref _endDate, value); + // } + + // RequestData(); + // } + //} + + IDialogService _dialogService; + IEventAggregator _eventAggregator; + ////private SqlSugarScope SqlSugarHelper.Db; + private PortUtil _portUtil; + private int _status; + + public int Status { get => _status; set => SetProperty(ref _status, value); } + + private int _drawerNo = 1; + + public int DrawerNo + { + get => _drawerNo; + set => SetProperty(ref _drawerNo, value); + } + + public long CurrentTimeMillis() + { + return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; + } + + public CheckStockNewWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService dialogService) + { + _dialogService = dialogService; + ////this.SqlSugarHelper.Db = sqlSugarScope; + _portUtil = portUtil; + _portUtil = portUtil; + _eventAggregator = eventAggregator; + //vm= this; + } + void DoMyPrismEvent(DeviceMsg msg) + { + + if (msg.WindowName == "CheckStockNewWindow") + { + IGrouping grouping = enumerator.Current; + int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0, grouping.Key.IndexOf('-'))); + List channelStocks = grouping.ToList(); + + switch (msg.EventType) + { + // 抽屉打开 + case EventType.DRAWEROPEN: + + + if (Status == 1) + { + if (channelStocks[0].process == 1) + { + channelStocks.ForEach(it => it.process = 2); + } + //Status = 2; + } + + break; + // 抽屉关闭 + case EventType.DRAWERCLOSE: + if (Status == 1) + { + if (channelStocks[0].process == 2) + { + channelStocks.ForEach(it => it.process = 3); + } + IGrouping groupingBefore = enumerator.Current; + int DrawerNoBefore = Convert.ToInt32(groupingBefore.Key.Substring(0, groupingBefore.Key.IndexOf('-'))); + if (enumerator.MoveNext()) + { + IGrouping groupingAfter = enumerator.Current; + int DrawerNoAfter = Convert.ToInt32(groupingAfter.Key.Substring(0, groupingAfter.Key.IndexOf('-'))); + //if (DrawerNoBefore < 9 && DrawerNoAfter > 8) + //{ + // Thread.Sleep(50); + //} + + logger.Info($"抽屉号DrawerNoBefore【{DrawerNoBefore}】抽屉号DrawerNoAfter【{DrawerNoAfter}】"); + if (DrawerNoAfter == 17) + { + if (DrawerNoBefore == 17) + { + Thread.Sleep(1000); + } + else + { + Thread.Sleep(500); + } + } + else + { + Thread.Sleep(80); + } + logger.Info($"抽屉号DrawerNoBefore【{DrawerNoBefore}】抽屉号DrawerNoAfter【{DrawerNoAfter}】"); + OpenOneByOne(); + } + // 已经全部取出 + else + { + Status = 3; + } + } + break; + // 数量变化 + case EventType.UPDATEQUANTITY: + if (Status == 1) + { + logger.Info($"抽屉【{DrawerNo}】库位药品数量【{msg.Quantitys}】"); + } + break; + // 打开失败 + case EventType.OPENERROR: + AlertMsg alertMsg = new AlertMsg + { + Message = msg.Message, + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Status = 0; + break; + } + } + + } + private ChannelStock? _selectedChannel; + + public ChannelStock? SelectedChannel + { + get => _selectedChannel; + set => SetProperty(ref _selectedChannel, value); + } + + private List? _channelStocks = new(); + + public List? ChannelStocks + { + get => _channelStocks; + set => SetProperty(ref _channelStocks, value); + } + + private IEnumerable> enumerable; + private IEnumerator> enumerator; + + public DelegateCommand BindingChannelDialog + { + get => new DelegateCommand(() => + { + DialogParameters dialogParameters = new DialogParameters(); + DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelDialog", dialogParameters, DoDialogResult, "RootDialog"); + }); + } + + + public DelegateCommand QueryCommand + { + get => new DelegateCommand(() => + { + RequestData(); + }); + } + /// + /// 盘点 + /// + public DelegateCommand OpenDrawer + { + get => new DelegateCommand(() => + { + if (Status == 0) + { + //enumerable = ChannelStocks.GroupBy(cs => cs.DrawerNo, cs => cs); + enumerable = ChannelStocks.GroupBy(cs => cs.Location, cs => cs); + enumerator = enumerable.GetEnumerator(); + enumerator.MoveNext(); + Status = 1; + OpenOneByOne(); + } + }); + } + private void OpenOneByOne() + { + IGrouping grouping = enumerator.Current; + int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0,grouping.Key.IndexOf('-'))); + List channelStocks = grouping.ToList(); + channelStocks.ForEach(it => it.process = 1); + _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + + List singleChannels = channelStocks.GroupBy(it => new + { + it.DrawerNo, + it.ColNo + }).Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(itx => itx.Quantity); + ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList().FindAll(it => it.BoardType != 1); + + // 发送取药数量 + //singleChannels.ForEach(it => + //{ + // try + // { + + // _portUtil.TakeQuantity(DrawerNo, it.ColNo, it.TakeQuantity, it.Quantity - it.TakeQuantity); + // } + // catch (Exception ex) + // { + // AlertMsg alertMsg = new AlertMsg + // { + // Message = $"打开抽屉异常{ex.Message}", + // Type = MsgType.ERROR, + // }; + // _eventAggregator.GetEvent().Publish(alertMsg); + // } + //}); + _portUtil.WindowName = "CheckStockNewWindow"; + _portUtil.Operate = true; + _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; + _portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray(); + _portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); + _portUtil.DrawerNo = DrawerNo; + _portUtil.Start(); + } + + private bool _isFinishClick = false; + + // 完成按钮 + public DelegateCommand TakeFinish + { + get => new DelegateCommand(() => + { + _isFinishClick = true; + //List record = ChannelStocks.FindAll(it => it.Quantity != it.CheckQuantity).ToList(); + List record = ChannelStocks; + if (record.Count > 0) + { + string InvoiceId = "CHECK_" + CurrentTimeMillis(); + var f = SqlSugarHelper.Db.UseTran(() => + { + + for (int i = 0; i < record.Count; i++) + { + ChannelStock it = record[i]; + + + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = it.CheckQuantity, + 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 = it.CheckQuantity - it.Quantity, + Type = 4, + InvoiceId = InvoiceId, + StockQuantity = nowChannels.Sum(it => it.Quantity), + CheckQuantity = it.CheckQuantity, + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + }).ExecuteCommand(); + + + logger.Info($"库存盘点->库位【{it.DrawerNo}-{it.ColNo}】药品【{it.DrugInfo.DrugName}】盘点前库存【{it.Quantity}】,更改后【{it.CheckQuantity}】"); + } + + + string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + string strSql = $@"SELECT cl.`row_no` AS rowNo,cl.`col_no` AS colNo,cl.`quantity` AS quantity,cl.`manu_no` AS manuNo,cl.`eff_date` AS effDate, + di.`drug_name` AS drugName,di.`drug_spec` AS drugSpec,di.`pack_unit` AS packUnit,di.`manufactory` AS manufactory,di.`max_stock` maxStock, + cl.`drug_id` AS drugId,cl.`machine_id` AS MachineId FROM channel_stock cl INNER JOIN drug_info di ON di.`drug_id` = cl.`drug_id` WHERE cl.`machine_id` = '{machine_id}' AND cl.`drawer_type` = 1 ORDER BY cl.`drug_id`"; + List checkRecordStockList = SqlSugarHelper.Db.SqlQueryable(strSql) + .AddParameters(new + { + machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1" + }) + .Select(it => new CheckRecordStock()) + .ToList(); + List insertList = new List(); + + if (checkRecordStockList != null && checkRecordStockList.Count > 0) + { + for (int i = 0; i < checkRecordStockList.Count; i++) + { + if (!(insertList.Where(it => it.drugId == checkRecordStockList[i].drugId && it.manuNo == checkRecordStockList[i].manuNo).Count() > 0)) + { + insertList.Add(checkRecordStockList[i]); + } + } + for (int j = 0; j < insertList.Count; j++) + { + + + CheckRecordStock cStock = insertList[j]; + // 保存数据 盘点后药品总库存及批次库存数 + SqlSugarHelper.Db.Insertable(new CheckRecordStock() + { + rowNo = cStock.rowNo, + colNo = cStock.colNo, + ManuQuantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId && it.manuNo == cStock.manuNo).Sum(it => it.quantity), + manuNo = cStock.manuNo, + effDate = cStock.effDate, + drugName = cStock.drugName, + manufactory = cStock.manufactory, + drugSpec = cStock.drugSpec, + packUnit = cStock.packUnit, + maxStock = cStock.maxStock, + drugId = cStock.drugId, + MachineId = cStock.MachineId, + quantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId).Sum(it => it.quantity), + optdate = DateTime.Now.ToString(), + operatorUser = HomeWindowViewModel.Operator?.Id.ToString(), + reviewerUser = HomeWindowViewModel.Reviewer?.Id.ToString() + }).ExecuteCommand(); + } + } + + + return true; + }); + if (f.Data) + { + // 更新屏显库存 + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = record.FindAll(it => it.BoardType != 1) + .GroupBy(it => new + { + it.DrawerNo, + it.ColNo + }).Select(it => + { + var ret = it.First(); + ret.CheckQuantity = it.Sum(itx => itx.CheckQuantity); + //ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList(); + if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + { + singleChannels.ForEach(it => + { + // 将库位多批次的总库存数更新标签 + _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.CheckQuantity); + + }); + } + + 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; + _isFinishClick = false; + } + else + { + _isFinishClick = false; + AlertMsg alertMsg = new AlertMsg + { + Message = "盘点完成,库存无改变", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Status = 0; + _isFinishClick = false; + } + + + }, () => Status == 3 && !_isFinishClick).ObservesProperty(() => Status); + } + + // 取消按钮 + public DelegateCommand CancleTake + { + get => new DelegateCommand(() => + { + _portUtil.ResetData(); + Status = 0; + }); + } + + public bool KeepAlive => true; + + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + //if (dialogResult.Result == ButtonResult.OK) + //{ + RequestData(); + //} + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } + ///// + ///// 导出账册 + ///// + //public DelegateCommand DownloadAccountBook + //{ + // get => new DelegateCommand(() => + // { + // if (!string.IsNullOrEmpty(Stock)) + // { + // //根据库位信息查询出药品id + // string[] strStock = Stock.Split('-'); + // if (strStock.Length >= 2) + // { + // //DrugId = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == Convert.ToInt32(strStock[0]) && cs.ColNo == Convert.ToInt32(strStock[1])).Select(cs => cs.DrugId).ToString(); + // var list = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == Convert.ToInt32(strStock[0]) && cs.ColNo == Convert.ToInt32(strStock[1]) && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).ToList(); + // if (list != null && list.Count > 0) + // { + // drugId = list[0].DrugId; + // } + // } + // } + // GridReportUtil.PrintReportAccountBook(StartDate, EndDate, drugId ?? ""); + // }); + //} + //public DelegateCommand DownLoadCommond + //{ + // get => new DelegateCommand(() => + // { + // GridReportUtil.PrintReportStockNew(StartDate, EndDate); + // }); + //} + + + + + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 + public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) + { + continuationCallback(true); + } + + + public void RequestData() + { + ChannelStocks.Clear(); + + ChannelStocks.Clear(); + + List q = SqlSugarHelper.Db.Queryable() + .Includes(cs => cs.DrugInfo) + .InnerJoin((cs, cl) => cs.Chnguid == cl.Id && cs.DrugId == cl.DrugId) + .Where(cs => cs.DrawerType == 1) + .Where(cs => cs.DrugId != null) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + + .WhereIF(!String.IsNullOrEmpty(SearchValue), cs => cs.DrugInfo.DrugName == SearchValue) + .OrderBy(cs => cs.DrawerNo) + .OrderBy(cs => cs.ColNo) + //.OrderBy(cs => cs.DrugId) + .ToList(); + ChannelStocks = q.Select(it => { it.CheckQuantity = it.Quantity; return it; }).ToList(); + ChannelStocks = q; + + + } + + //接收导航传过来的参数 现在是在此处初始化了表格数据 + public void OnNavigatedTo(NavigationContext navigationContext) + { + _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + Task.Factory.StartNew(() => { RequestData(); }); + //RequestData(); + } + + + //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + //这个方法用于拦截请求 + public void OnNavigatedFrom(NavigationContext navigationContext) + { + // 取消消息订阅 + _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + } +} diff --git a/DM_Weight/ViewModels/CheckStockWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockWindowViewModel.cs index 6785a43..6802621 100644 --- a/DM_Weight/ViewModels/CheckStockWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckStockWindowViewModel.cs @@ -33,12 +33,12 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IEventAggregator _eventAggregator; - private SqlSugarScope _sqlSugarScope1; - public CheckStockWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator,SqlSugarScope sqlSugarScope) + ////private SqlSugarScope SqlSugarHelper.Db; + public CheckStockWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator) { _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1= sqlSugarScope; + //this.SqlSugarHelper.Db= sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) @@ -151,7 +151,7 @@ namespace DM_Weight.ViewModels if (record.Count > 0) { string InvoiceId = "CHECK_" + CurrentTimeMillis(); - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { for (int i = 0; i < record.Count; i++) @@ -160,7 +160,7 @@ namespace DM_Weight.ViewModels // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + SqlSugarHelper.Db.Updateable(new ChannelStock() { Quantity = it.CheckQuantity, ManuNo = it.ManuNo, @@ -168,14 +168,14 @@ namespace DM_Weight.ViewModels Id = it.Id, }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + 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(); // 保存数据 盘点记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = it.MachineId, DrawerNo = it.DrawerNo, @@ -258,16 +258,17 @@ namespace DM_Weight.ViewModels }); } + public bool KeepAlive => true; + public long CurrentTimeMillis() { return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; } - public bool KeepAlive => false; public void FindDrawerCount() { - int count = _sqlSugarScope1.Queryable().Where(cs => cs.DrawerType != 3) + int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); Is8Drawer = count < 9; Is16Drawer = count >= 16; @@ -284,7 +285,7 @@ namespace DM_Weight.ViewModels public void RequestData() { - List queryData = _sqlSugarScope1.Queryable() + List queryData = SqlSugarHelper.Db.Queryable() .Includes(cs => cs.DrugInfo) .Where(cs => cs.DrawerNo == DrawerNo) .Where(cs => cs.DrugId != null) diff --git a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs index 84e9242..24789af 100644 --- a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs @@ -49,16 +49,17 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IEventAggregator _eventAggregator; - private SqlSugarScope _sqlSugarScope1; - public DrawerAddDrugWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator,SqlSugarScope sqlSugarScope) + ////private SqlSugarScope SqlSugarHelper.Db; + public DrawerAddDrugWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator) { _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1= sqlSugarScope; + //this.SqlSugarHelper.Db= sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) { + logger.Info("抽屉加药页面_DoMyPrismEvent"); if (msg.WindowName == "DrawerAddDrugWindow") { switch (msg.EventType) @@ -142,13 +143,26 @@ namespace DM_Weight.ViewModels try { + //var groupQuery = (from t in ChannelStocks + // group t by new { t.ColNo, t.BoardType } + // into grp + // select new { grp.Key.ColNo, grp.Key.BoardType, quantity = grp.Sum(t => t.Quantity) }).ToList(); + // singleChannelsFor = singleChannelsFor.GroupBy(it => it.ColNo) + // .Select(it => new + // { + // Quantity = it.Sum(itx => itx.Quantity), + // AddQuantity = it.Sum(itx => itx.AddQuantity) + + //}) + // .ToList() + // .FindAll(it => it.BoardType != 1); + List singleChannels = ChannelStocks.FindAll(it => it.BoardType != 1); _portUtil.WindowName = "DrawerAddDrugWindow"; _portUtil.Operate = true; _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; - _portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray(); - _portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); + _portUtil.ColNos = new int[] { };// singleChannels.Select(it => it.ColNo).ToArray(); _portUtil.DrawerNo = DrawerNo; _portUtil.Start(); @@ -177,7 +191,7 @@ namespace DM_Weight.ViewModels { //string InvoiceId = "DRAWER_" + CurrentTimeMillis(); string InvoiceId = PZH; - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { for (int i = 0; i < record.Count; i++) @@ -187,7 +201,7 @@ namespace DM_Weight.ViewModels it.EffDate = it.drugManuNo.EffDate; // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + SqlSugarHelper.Db.Updateable(new ChannelStock() { Quantity = it.Quantity + it.AddQuantity, ManuNo = it.ManuNo, @@ -195,14 +209,14 @@ namespace DM_Weight.ViewModels Id = it.Id, }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + 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(); // 保存数据 入库记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = it.MachineId, DrawerNo = it.DrawerNo, @@ -211,13 +225,15 @@ namespace DM_Weight.ViewModels 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, + Reviewer = HomeWindowViewModel.Reviewer?.Id, OperationTime = DateTime.Now, Quantity = it.AddQuantity, Type = 1, InvoiceId = InvoiceId, StockQuantity = nowChannels.Sum(it => it.Quantity), - ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity), + SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() }).ExecuteCommand(); } return true; @@ -225,12 +241,22 @@ namespace DM_Weight.ViewModels if (f.Data) { // 更新屏显库存 - List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = ChannelStocks.Where(it => it.BoardType != 1) + .GroupBy(it => it.ColNo) + .Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(it => it.Quantity); + ret.AddQuantity = it.Sum(it => it.AddQuantity); + return ret; + }).ToList(); + singleChannels = singleChannels.Where(it => it.AddQuantity > 0).ToList(); if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) { + //将库位多批次的总库存数更新标签 singleChannels.ForEach(it => { - _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity+it.AddQuantity); + _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity); }); } RequestData(); @@ -288,15 +314,16 @@ namespace DM_Weight.ViewModels }); } + public bool KeepAlive => true; + public long CurrentTimeMillis() { return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; } - public bool KeepAlive => false; public void FindDrawerCount() { - int count = _sqlSugarScope1.Queryable().Where(cs => cs.DrawerType != 3) + int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); Is8Drawer = count < 9; Is16Drawer = count >= 16; @@ -314,8 +341,13 @@ namespace DM_Weight.ViewModels public void RequestData() { - List queryData = _sqlSugarScope1.Queryable() - .Includes(cs => cs.DrugInfo,di=>di.DrugManuNos) + if (ChannelStocks != null) + { + ChannelStocks.Clear(); + } + List queryData = SqlSugarHelper.Db.Queryable() + .Includes(cs => cs.DrugInfo, di => di.DrugManuNos) + .InnerJoin((cs, cl) => cs.Chnguid==cl.Id &&cs.DrugId==cl.DrugId) .Where(cs => cs.DrawerNo == DrawerNo) .Where(cs => cs.DrawerType == 1) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) @@ -328,7 +360,7 @@ namespace DM_Weight.ViewModels return cs; }).ToList(); - //obChannelStock = new ObservableCollection(ChannelStocks); + //obChannelStock = new ObservableCollection(ChannelStocks); } //接收导航传过来的参数 现在是在此处初始化了表格数据 diff --git a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs index 409667e..3a99f38 100644 --- a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs @@ -44,17 +44,18 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IEventAggregator _eventAggregator; - private SqlSugarScope _sqlSugarScope1; - public DrawerTakeDrugWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator,SqlSugarScope sqlSugarScope) + ////private SqlSugarScope SqlSugarHelper.Db; + public DrawerTakeDrugWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator) { _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1= sqlSugarScope; + //this.SqlSugarHelper.Db= sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) { - if(msg.WindowName == "DrawerTakeDrugWindow") + logger.Info($"抽屉取药页面_DoMyPrismEvent:{msg.WindowName}"); + if (msg.WindowName == "DrawerTakeDrugWindow") { switch (msg.EventType) { @@ -139,16 +140,18 @@ namespace DM_Weight.ViewModels Status = 1; _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - + //var groupQuery = (from t in ChannelStocks + // group t by new { t.ColNo, t.BoardType } + // into grp + // select new { grp.Key.ColNo, grp.Key.BoardType, quantity = grp.Sum(t => t.Quantity) }).ToList(); + List singleChannels = ChannelStocks.FindAll(it => it.BoardType != 1); _portUtil.WindowName = "DrawerTakeDrugWindow"; _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; - _portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray(); - _portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); + _portUtil.ColNos = new int[] { };// groupQuery.Select(it => it.ColNo).ToArray(); _portUtil.DrawerNo = DrawerNo; - Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, () => _portUtil.Start()) - ; + Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, () => _portUtil.Start()); } }); @@ -168,8 +171,9 @@ namespace DM_Weight.ViewModels logger.Info("点击完成按钮,库位数据:" + JsonConvert.SerializeObject(record)); if (record.Count > 0) { + logger.Info("record.Count>0"); string InvoiceId = "DRAWER_" + CurrentTimeMillis(); - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { for (int i = 0; i < record.Count; i++) @@ -178,22 +182,24 @@ namespace DM_Weight.ViewModels // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + SqlSugarHelper.Db.Updateable(new ChannelStock() { Quantity = it.Quantity - it.TakeQuantity, ManuNo = it.ManuNo, EffDate = it.EffDate, Id = it.Id, }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); + + logger.Info("Updateable_ChannelStock完成"); // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + 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(); - + logger.Info("Queryable_ChannelStock完成"); // 保存数据 出库记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = it.MachineId, DrawerNo = it.DrawerNo, @@ -208,28 +214,46 @@ namespace DM_Weight.ViewModels Type = 2, InvoiceId = InvoiceId, StockQuantity = nowChannels.Sum(it => it.Quantity), - ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity), + SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() }).ExecuteCommand(); + logger.Info("Insert_MachineRecord完成"); logger.Info($"抽屉取药保存->库位【{it.DrawerNo}-{it.ColNo}】取出药品【{it.DrugInfo.DrugName}】个数【{it.TakeQuantity}】,取药前库存【{it.Quantity}】"); } return true; }); - if (f.Data) + if (f.Data) { + logger.Info("更新屏显库存singleChannels"); // 更新屏显库存 - List singleChannels = record.FindAll(it => it.BoardType != 1); + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = ChannelStocks.Where(it => it.BoardType != 1) + .GroupBy(it => it.ColNo) + .Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(itx => itx.Quantity); + ret.TakeQuantity = it.Sum(itx => itx.TakeQuantity); + return ret; + }).ToList(); + singleChannels = singleChannels.Where(it => it.TakeQuantity > 0).ToList(); if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) { + //将库位多批次的总库存数更新标签 + //_portUtil.WriteQuantity(singleChannels[0].DrawerNo, singleChannels[0].ColNo, singleChannels.Sum(it => it.Quantity) - singleChannels.Sum(it => it.TakeQuantity)); + singleChannels.ForEach(it => { - _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity); + _portUtil.WriteQuantityAsync(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity); }); } + logger.Info("更新屏显库存singleChannels_完成"); RequestData(); AlertMsg alertMsg = new AlertMsg { - Message = "抽屉取药完成,库存已更新", + Message = $"抽屉取药完成,库存已更新", Type = MsgType.SUCCESS, }; _eventAggregator.GetEvent().Publish(alertMsg); @@ -238,7 +262,7 @@ namespace DM_Weight.ViewModels { AlertMsg alertMsg = new AlertMsg { - Message = "抽屉取药完成,库存更新失败!", + Message = $"抽屉取药完成,库存更新失败!{f.ErrorMessage}", Type = MsgType.ERROR, }; _eventAggregator.GetEvent().Publish(alertMsg); @@ -272,16 +296,16 @@ namespace DM_Weight.ViewModels }); } + public bool KeepAlive => true; + public long CurrentTimeMillis() { return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; } - public bool KeepAlive => false; - public void FindDrawerCount() { - int count = _sqlSugarScope1.Queryable().Where(cs => cs.DrawerType != 3) + int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); Is8Drawer = count < 9; Is16Drawer = count >= 16; @@ -298,7 +322,7 @@ namespace DM_Weight.ViewModels public void RequestData() { - List queryData = _sqlSugarScope1.Queryable() + List queryData = SqlSugarHelper.Db.Queryable() .Includes(cs => cs.DrugInfo) .Where(cs => cs.DrawerNo == DrawerNo) .Where(cs => cs.DrugId != null) diff --git a/DM_Weight/ViewModels/DrugListWindowViewModel.cs b/DM_Weight/ViewModels/DrugListWindowViewModel.cs index 34f7579..1b6e3fc 100644 --- a/DM_Weight/ViewModels/DrugListWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrugListWindowViewModel.cs @@ -13,6 +13,8 @@ using DM_Weight.util; using log4net.Repository.Hierarchy; using log4net; using SqlSugar; +using DM_Weight.msg; +using Prism.Events; namespace DM_Weight.ViewModels { @@ -165,11 +167,12 @@ namespace DM_Weight.ViewModels set { SetProperty(ref _selectedManuno, value ?? new()); } } - public bool KeepAlive => false; - private SqlSugarScope _sqlSugarScope1; - public DrugListWindowViewModel(SqlSugarScope sqlSugarScope) + //private SqlSugarScope SqlSugarHelper.Db; + + IEventAggregator _eventAggregator; + public DrugListWindowViewModel(IEventAggregator eventAggregator) { - this._sqlSugarScope1 = sqlSugarScope; + _eventAggregator = eventAggregator; } public DelegateCommand Query @@ -188,7 +191,7 @@ namespace DM_Weight.ViewModels { //SelectedDrug.DrugId = 0; - _sqlSugarScope1.Insertable(SelectedDrug).ExecuteCommand(); + SqlSugarHelper.Db.Insertable(SelectedDrug).ExecuteCommand(); RequestData(); } catch (Exception ex) @@ -204,7 +207,7 @@ namespace DM_Weight.ViewModels { get => new DelegateCommand(() => { - _sqlSugarScope1.Updateable(SelectedDrug).UpdateColumns(d => new { d.DrugName, d.Manufactory, d.PyCode, d.PackUnit, d.MaxStock, d.DrugSpec }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable(SelectedDrug).UpdateColumns(d => new { d.DrugName, d.Manufactory, d.PyCode, d.PackUnit, d.MaxStock, d.DrugSpec }).ExecuteCommand(); RequestData(); }, () => SelectedDrug.DrugId !=null).ObservesProperty(() => SelectedDrug); } @@ -213,13 +216,55 @@ namespace DM_Weight.ViewModels { get => new DelegateCommand(() => { - if (!string.IsNullOrEmpty(SelectedManuno.EffDate) && !string.IsNullOrEmpty(SelectedManuno.ManuNo)) + try { - SelectedManuno.Id = Guid.NewGuid().ToString(); - SelectedManuno.DrugId = SelectedDrug.DrugId.ToString(); - SelectedManuno.EffDate = DateTime.Parse(SelectedManuno.EffDate).ToString("yyyy-MM-dd"); - _sqlSugarScope1.Insertable(SelectedManuno).ExecuteCommand(); - GetManuNos(); + + if (!string.IsNullOrEmpty(SelectedManuno.EffDate) && !string.IsNullOrEmpty(SelectedManuno.ManuNo)) + { + string dt = DateTime.Parse(SelectedManuno.EffDate).ToString("yyyy-MM-dd"); + int repeatCount = SqlSugarHelper.Db.Queryable().Where(dm => dm.DrugId == SelectedDrug.DrugId && dm.EffDate == dt && dm.ManuNo == SelectedManuno.ManuNo).Count(); + if (repeatCount > 0) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "批次重复,请勿重复添加!", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + else + { + SelectedManuno.Id = Guid.NewGuid().ToString(); + SelectedManuno.DrugId = SelectedDrug.DrugId.ToString(); + SelectedManuno.EffDate = DateTime.Parse(SelectedManuno.EffDate).ToString("yyyy-MM-dd"); + SqlSugarHelper.Db.Insertable(SelectedManuno).ExecuteCommand(); GetManuNos(); + AlertMsg alertMsg = new AlertMsg + { + Message = "保存成功!", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "请输入批次及效期!", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + } + catch (Exception ex) + { + AlertMsg alertMsg = new AlertMsg + { + Message = $"添加失败{ex.Message}", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); } }, () => SelectedDrug.DrugId !=null).ObservesProperty(() => SelectedDrug); @@ -229,12 +274,47 @@ namespace DM_Weight.ViewModels { get => new DelegateCommand(() => { - SelectedManuno.EffDate = DateTime.Parse(SelectedManuno.EffDate).ToString("yyyy-MM-dd"); - _sqlSugarScope1.Updateable(SelectedManuno).UpdateColumns(m => new { m.ManuNo, m.EffDate }).ExecuteCommand(); - GetManuNos(); + try + { + string dt = DateTime.Parse(SelectedManuno.EffDate).ToString("yyyy-MM-dd"); + int repeatCount = SqlSugarHelper.Db.Queryable().Where(dm => dm.DrugId == SelectedDrug.DrugId && dm.EffDate == dt && dm.ManuNo == SelectedManuno.ManuNo).Count(); + if (repeatCount > 0) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "批次重复,请勿重复添加!", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + else + { + SelectedManuno.EffDate = DateTime.Parse(SelectedManuno.EffDate).ToString("yyyy-MM-dd"); + SqlSugarHelper.Db.Updateable(SelectedManuno).UpdateColumns(m => new { m.ManuNo, m.EffDate }).ExecuteCommand(); + GetManuNos(); + AlertMsg alertMsg = new AlertMsg + { + Message = "修改成功!", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + } + catch (Exception ex) + { + + AlertMsg alertMsg = new AlertMsg + { + Message = "修改失败!", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } }, () => !string.IsNullOrEmpty(SelectedManuno.DrugId)).ObservesProperty(() => SelectedManuno); } + public bool KeepAlive => true; + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) @@ -252,7 +332,7 @@ namespace DM_Weight.ViewModels void GetManuNos() { - Manunos = _sqlSugarScope1.Queryable() + Manunos = SqlSugarHelper.Db.Queryable() .WhereIF(SelectedDrug != null, (di) => di.DrugId.Equals(SelectedDrug.DrugId)) .Select(di => di) .ToList(); @@ -261,7 +341,7 @@ namespace DM_Weight.ViewModels void RequestData() { int totalCount = 0; - DrugInfos = _sqlSugarScope1.Queryable() + DrugInfos = SqlSugarHelper.Db.Queryable() .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (di) => di.DrugId.ToString().Contains(SearchValue)) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (di) => di.DrugName.Contains(SearchValue)) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (di) => di.PyCode.Contains(SearchValue)) diff --git a/DM_Weight/ViewModels/EditUserDialogViewModel.cs b/DM_Weight/ViewModels/EditUserDialogViewModel.cs index 4b678d5..3ab98a3 100644 --- a/DM_Weight/ViewModels/EditUserDialogViewModel.cs +++ b/DM_Weight/ViewModels/EditUserDialogViewModel.cs @@ -23,12 +23,12 @@ namespace DM_Weight.ViewModels private readonly FingerprintUtil _fingerprintUtil; IEventAggregator _eventAggregator; - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public EditUserDialogViewModel(FingerprintUtil fingerprintUtil, IEventAggregator eventAggregator,SqlSugarScope sqlSugarScope) { _fingerprintUtil = fingerprintUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } private UserList _userList = new UserList(); @@ -80,7 +80,7 @@ namespace DM_Weight.ViewModels - public bool KeepAlive => false; + public bool KeepAlive => true; private string _title = "编辑用户"; @@ -105,7 +105,7 @@ namespace DM_Weight.ViewModels { // 旧密码输入正确 UserList.PassWord = MD5.GetMD5Hash(NewPass); - _sqlSugarScope1.Updateable(UserList).UpdateColumns(u => new { u.PassWord }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable(UserList).UpdateColumns(u => new { u.PassWord }).ExecuteCommand(); // 关闭当前窗口 RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); } @@ -123,13 +123,13 @@ namespace DM_Weight.ViewModels // 没有写密码 if (string.IsNullOrEmpty(NewPass)) { - _sqlSugarScope1.Updateable(UserList).UpdateColumns(u => new { u.Nickname, u.UserName, u.UserBarcode, u.RoleId }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable(UserList).UpdateColumns(u => new { u.Nickname, u.UserName, u.UserBarcode, u.RoleId }).ExecuteCommand(); } // 更改了密码 else { UserList.PassWord = MD5.GetMD5Hash(NewPass); - _sqlSugarScope1.Updateable(UserList).UpdateColumns(u => new { u.Nickname, u.UserName, u.PassWord, u.UserBarcode, u.RoleId }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable(UserList).UpdateColumns(u => new { u.Nickname, u.UserName, u.PassWord, u.UserBarcode, u.RoleId }).ExecuteCommand(); } } else @@ -137,7 +137,7 @@ namespace DM_Weight.ViewModels UserList.PassWord = MD5.GetMD5Hash(NewPass); UserList.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; // 插入 - _sqlSugarScope1.Insertable(UserList).InsertColumns(u => new { u.Id, u.Nickname, u.UserName, u.PassWord, u.UserBarcode, u.RoleId, u.MachineId }).ExecuteCommand(); + SqlSugarHelper.Db.Insertable(UserList).InsertColumns(u => new { u.Id, u.Nickname, u.UserName, u.PassWord, u.UserBarcode, u.RoleId, u.MachineId }).ExecuteCommand(); } RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); } @@ -157,7 +157,7 @@ namespace DM_Weight.ViewModels void GetAllRole() { - Roles = _sqlSugarScope1.Queryable().Where(r => r.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM1")).OrderBy(r => r.Id).ToList(); + Roles = SqlSugarHelper.Db.Queryable().Where(r => r.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM1")).OrderBy(r => r.Id).ToList(); RaisePropertyChanged("Roles"); } diff --git a/DM_Weight/ViewModels/FingerprintDialogViewModel.cs b/DM_Weight/ViewModels/FingerprintDialogViewModel.cs index 503f28d..5408d5e 100644 --- a/DM_Weight/ViewModels/FingerprintDialogViewModel.cs +++ b/DM_Weight/ViewModels/FingerprintDialogViewModel.cs @@ -63,7 +63,7 @@ namespace DM_Weight.ViewModels set => SetProperty(ref _fingerIndex, value); } - public bool KeepAlive => false; + public bool KeepAlive => true; private int _status = 0; diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs index a50443e..7786bed 100644 --- a/DM_Weight/ViewModels/HomeWindowViewModel.cs +++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs @@ -52,65 +52,122 @@ namespace DM_Weight.ViewModels get { return _selectedChildMenu; } set { - if (!_portUtil.Operate) - { - if (value != null) - { - if (value.PremissionPath.Equals("TakeRecordWindow")) - { - //定义传参变量 - NavigationParameters keys = new NavigationParameters(); + //if (!_portUtil.Operate) + //{ + //if (value != null) + //{ + // if (value.PremissionPath.Equals("TakeRecordWindow")) + // { + // //定义传参变量 + // NavigationParameters keys = new NavigationParameters(); - //添加参数,键值对格式 - keys.Add("Type", 2); - _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); - } - else if (value.PremissionPath.Equals("AddRecordWindow")) - { - //定义传参变量 - NavigationParameters keys = new NavigationParameters(); + // //添加参数,键值对格式 + // keys.Add("Type", 2); + // _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); + // } + // else if (value.PremissionPath.Equals("AddRecordWindow")) + // { + // //定义传参变量 + // NavigationParameters keys = new NavigationParameters(); - //添加参数,键值对格式 - keys.Add("Type", 1); - _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); - } - else if (value.PremissionPath.Equals("ReturnRecordWindow")) - { - //定义传参变量 - NavigationParameters keys = new NavigationParameters(); + // //添加参数,键值对格式 + // keys.Add("Type", 1); + // _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); + // } + // else if (value.PremissionPath.Equals("ReturnRecordWindow")) + // { + // //定义传参变量 + // NavigationParameters keys = new NavigationParameters(); - //添加参数,键值对格式 - keys.Add("Type", 3); - _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); - } - else if (value.PremissionPath.Equals("RetrunEmptyRecordWindow")) - { - //定义传参变量 - NavigationParameters keys = new NavigationParameters(); + // //添加参数,键值对格式 + // keys.Add("Type", 3); + // _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); + // } + // else if (value.PremissionPath.Equals("RetrunEmptyRecordWindow")) + // { + // //定义传参变量 + // NavigationParameters keys = new NavigationParameters(); - //添加参数,键值对格式 - keys.Add("Type", 3); - _regionManager.RequestNavigate("ContentRegion", value.PremissionPath, keys); - } - else if (value.PremissionPath.Equals("CheckRecordWindow")) - { - //定义传参变量 - NavigationParameters keys = new NavigationParameters(); + // //添加参数,键值对格式 + // keys.Add("Type", 3); + // _regionManager.RequestNavigate("ContentRegion", value.PremissionPath, keys); + // } + // else if (value.PremissionPath.Equals("CheckRecordWindow")) + // { + // //定义传参变量 + // NavigationParameters keys = new NavigationParameters(); - //添加参数,键值对格式 - keys.Add("Type", 4); - _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); - } - else - { - _regionManager.RequestNavigate("ContentRegion", value.PremissionPath); - } - } + // //添加参数,键值对格式 + // keys.Add("Type", 4); + // _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); + // } + // else + // { + // _regionManager.RequestNavigate("ContentRegion", value.PremissionPath); + // } + //} SetProperty(ref _selectedChildMenu, value); + //} + } + } + private void SelectChildNavigate(PremissionDm SelectedChildMenu) + { + if (!_portUtil.Operate) + { + if (SelectedChildMenu != null) + { + if (SelectedChildMenu.PremissionPath.Equals("TakeRecordWindow")) + { + //定义传参变量 + NavigationParameters keys = new NavigationParameters(); + + //添加参数,键值对格式 + keys.Add("Type", 2); + _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); + } + else if (SelectedChildMenu.PremissionPath.Equals("AddRecordWindow")) + { + //定义传参变量 + NavigationParameters keys = new NavigationParameters(); + + //添加参数,键值对格式 + keys.Add("Type", 1); + _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); + } + else if (SelectedChildMenu.PremissionPath.Equals("ReturnRecordWindow")) + { + //定义传参变量 + NavigationParameters keys = new NavigationParameters(); + + //添加参数,键值对格式 + keys.Add("Type", 3); + _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); + } + else if (SelectedChildMenu.PremissionPath.Equals("RetrunEmptyRecordWindow")) + { + //定义传参变量 + NavigationParameters keys = new NavigationParameters(); + + //添加参数,键值对格式 + keys.Add("Type", 3); + _regionManager.RequestNavigate("ContentRegion", SelectedChildMenu.PremissionPath, keys); + } + else if (SelectedChildMenu.PremissionPath.Equals("CheckRecordWindow")) + { + //定义传参变量 + NavigationParameters keys = new NavigationParameters(); + + //添加参数,键值对格式 + keys.Add("Type", 4); + _regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys); + } + else + { + _regionManager.RequestNavigate("ContentRegion", SelectedChildMenu.PremissionPath); + } } } } - public PremissionDm? SelectedMenu { get { return _selectedMenu; } @@ -134,15 +191,17 @@ namespace DM_Weight.ViewModels } } - private DelegateCommand _selectionCommon; - public DelegateCommand SelectionCommon + #region 父菜单点击 + private DelegateCommand _selectionCommon; + public DelegateCommand SelectionCommon { - get => _selectionCommon ?? (_selectionCommon = new DelegateCommand(SelectionMethod)); + get => _selectionCommon ?? (_selectionCommon = new DelegateCommand(SelectionMethod)); } - private void SelectionMethod(ListBox viewName) + private void SelectionMethod() { - SelectedMenu = viewName.SelectedItem as PremissionDm; - if (SelectedMenu.PremissionName == "退出") + logger.Info("开始进入父菜单"); + //SelectedMenu = viewName.SelectedItem as PremissionDm; + if (SelectedMenu!=null&&SelectedMenu.PremissionName == "退出") { logger.Info($"用户【{Operator?.Nickname}】退出登录"); Operator = null; @@ -152,9 +211,27 @@ namespace DM_Weight.ViewModels else { //SelectedMenu.Children = SelectedMenu.Children; - SelectedChildMenu = SelectedMenu.Children[0]; + //SelectedChildMenu = SelectedMenu.Children[0]; + if (!_portUtil.Operate) + { + _regionManager.RequestNavigate("ContentRegion", SelectedMenu.Children[0].PremissionPath); + } } + + logger.Info("结束父菜单"); + } + #endregion + #region 子菜单点击 + private DelegateCommand _selectionChildCommon; + public DelegateCommand SelectionChildCommon + { + get => _selectionChildCommon ?? (_selectionChildCommon = new DelegateCommand(SelectionChildMethod)); } + private void SelectionChildMethod() + { + SelectChildNavigate(SelectedChildMenu); + } + #endregion public List PremissionDmList { get { return _premissionDmList; } set { SetProperty(ref _premissionDmList, value); } } @@ -169,9 +246,8 @@ namespace DM_Weight.ViewModels private bool _is16Drawer; public bool Is16Drawer { get => _is16Drawer; set => SetProperty(ref _is16Drawer, value); } - public bool KeepAlive => false; private PortUtil _portUtil; - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; IEventAggregator _eventAggregator; public HomeWindowViewModel(IRegionManager iRegionManager, PortUtil portUtil, IDialogService dialogService, IUnityContainer container, SqlSugarScope sqlSugarScope, IEventAggregator eventAggregator) { @@ -179,7 +255,7 @@ namespace DM_Weight.ViewModels _regionManager = iRegionManager; _dialogService = dialogService; _container = container; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; this._eventAggregator = eventAggregator; } @@ -237,6 +313,9 @@ namespace DM_Weight.ViewModels get => new DelegateCommand(ShiftsAction); } + + public bool KeepAlive => false; + private void ShiftsAction() { _regionManager.RequestNavigate("ContentRegion", "ChangeShiftsWindow"); @@ -244,7 +323,7 @@ namespace DM_Weight.ViewModels public void FindDrawerCount() { - int count = _sqlSugarScope1.Queryable().Where(cs => cs.DrawerType != 3) + int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType != 3) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); Is16Drawer = count == 16; @@ -289,11 +368,12 @@ namespace DM_Weight.ViewModels _eventAggregator.GetEvent().Publish(alertMsg); return; } - //_sqlSugarScope1.SqlQueryable(sql) + //SqlSugarHelper.Db.SqlQueryable(sql) //.ToTree(pd => pd.Children, pd => pd.ParentId, 0); PremissionDmList = premissions; SelectedMenu = premissions[0]; SelectedChildMenu = premissions[0].Children[0]; + _regionManager.RequestNavigate("ContentRegion", premissions[0].Children[0].PremissionPath); FindDrawerCount(); int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0"); @@ -334,5 +414,111 @@ namespace DM_Weight.ViewModels public void OnNavigatedFrom(NavigationContext navigationContext) { } + //取药 + private DelegateCommand _takeCommand; + public DelegateCommand TakeCommand + { + get => new DelegateCommand(() => + { + TakeMethod(); + }); + } + + //=>_takeCommand??= new DelegateCommand(TakeMethod); + private void TakeMethod() + { + SelectedMenu = PremissionDmList[0]; + if (SelectedMenu.PremissionName == "退出") + { + logger.Info($"用户【{Operator?.Nickname}】退出登录"); + Operator = null; + Reviewer = null; + _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + } + else + { + //SelectedMenu.Children = SelectedMenu.Children; + SelectedChildMenu = SelectedMenu.Children[0]; + } + } + + //加药 + private DelegateCommand _addCommand; + public DelegateCommand AddCommand => _addCommand ??= new DelegateCommand(AddMethod); + private void AddMethod() + { + SelectedMenu = PremissionDmList[1]; + if (SelectedMenu.PremissionName == "退出") + { + logger.Info($"用户【{Operator?.Nickname}】退出登录"); + Operator = null; + Reviewer = null; + _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + } + else + { + //SelectedMenu.Children = SelectedMenu.Children; + SelectedChildMenu = SelectedMenu.Children[0]; + } + } + + + //还药 + private DelegateCommand _returnCommand; + public DelegateCommand ReturnCommand => _returnCommand ??= new DelegateCommand(ReturnMethod); + private void ReturnMethod() + { + SelectedMenu = PremissionDmList[2]; + if (SelectedMenu.PremissionName == "退出") + { + logger.Info($"用户【{Operator?.Nickname}】退出登录"); + Operator = null; + Reviewer = null; + _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + } + else + { + //SelectedMenu.Children = SelectedMenu.Children; + SelectedChildMenu = SelectedMenu.Children[0]; + } + } + + private DelegateCommand _stockCommand; + public DelegateCommand StockCommand => _stockCommand ??= new DelegateCommand(StockMethod); + private void StockMethod() + { + SelectedMenu = PremissionDmList[3]; + if (SelectedMenu.PremissionName == "退出") + { + logger.Info($"用户【{Operator?.Nickname}】退出登录"); + Operator = null; + Reviewer = null; + _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + } + else + { + //SelectedMenu.Children = SelectedMenu.Children; + SelectedChildMenu = SelectedMenu.Children[0]; + } + } + + private DelegateCommand _settingCommand; + public DelegateCommand SettingCommand => _settingCommand ??= new DelegateCommand(SettingMethod); + private void SettingMethod() + { + SelectedMenu = PremissionDmList[4]; + if (SelectedMenu.PremissionName == "退出") + { + logger.Info($"用户【{Operator?.Nickname}】退出登录"); + Operator = null; + Reviewer = null; + _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + } + else + { + //SelectedMenu.Children = SelectedMenu.Children; + SelectedChildMenu = SelectedMenu.Children[0]; + } + } } } diff --git a/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs b/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs index d1e54e0..6fe2b95 100644 --- a/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs @@ -12,6 +12,7 @@ using Prism.Services.Dialogs; using SqlSugar; using System; using System.Collections.Generic; +using System.Configuration; using System.Linq; using System.Text; using System.Threading; @@ -34,12 +35,12 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IEventAggregator _eventAggregator; - private SqlSugarScope _sqlSugarScope1; - public InvoiceAddDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, SqlSugarScope sqlSugarScope) + ////private SqlSugarScope SqlSugarHelper.Db; + public InvoiceAddDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator) { _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + ////this.SqlSugarHelper.Db = sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) @@ -201,6 +202,16 @@ namespace DM_Weight.ViewModels if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) { + List ChannelLst = channelStocks.Where(it => it.BoardType != 1) + .GroupBy(it => it.ColNo) + .Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(itx => itx.Quantity); + ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList(); + // 发送加药数量 singleChannels.ForEach(it => { @@ -232,9 +243,9 @@ namespace DM_Weight.ViewModels _isFinishClick = true; List record = ChannelStocks.ToList(); string InvoiceId = Invoice.InvoiceNo; - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { - _sqlSugarScope1.Updateable(new InOutInvoice() + SqlSugarHelper.Db.Updateable(new InOutInvoice() { Status = 1, InvoiceNo = Invoice.InvoiceNo @@ -242,29 +253,82 @@ namespace DM_Weight.ViewModels for (int i = 0; i < record.Count; i++) { + + ChannelStock it = record[i]; if (it.BoardType == 6 && it.PosNo == 0) { _portUtil.SetNumCount(it.DrawerNo, it.ColNo, it.AddQuantity); } - // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + if (it.Id != null) { - Quantity = it.Quantity + it.AddQuantity, - PosNo = 1, - ManuNo = it.ManuNo, - EffDate = it.EffDate, - Id = it.Id, - }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = it.Quantity + it.AddQuantity, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + Id = it.Id, + }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); + } + else + { + //如果批号重复则不让添加 + List csCount = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == it.DrawerNo && cs.ColNo==it.ColNo&&cs.ManuNo == it.ManuNo && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")&&cs.Quantity>0).ToList(); + if (csCount.Count > 0) + { + //repeatList.Add(it.ManuNo); + //stockRepeats.Add(it); + continue; + } + //查询现有库位中是否有库存为0的记录,如果有直接update + List recordList = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == it.DrawerNo && cs.ColNo == it.ColNo && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.Quantity <= 0).ToList(); + if (recordList.Count > 0) + { + // 更新数据 库存信息 + //SqlSugarHelper.Db.Updateable(new ChannelStock() + //{ + // Quantity = recordList[0].Quantity + it.AddQuantity, + // ManuNo = recordList[0].ManuNo, + // EffDate = recordList[0].EffDate, + // Id = recordList[0].Id, + //}).UpdateColumns(it => new { recordList[0].Quantity, recordList[0].ManuNo, recordList[0].EffDate }).ExecuteCommand(); + SqlSugarHelper.Db.Updateable() .SetColumns(item=>new ChannelStock() + { + Quantity = recordList[0].Quantity + it.AddQuantity, + ManuNo = recordList[0].ManuNo, + EffDate = recordList[0].EffDate, + Id = recordList[0].Id, + }).Where(item => item.Id == item.Id).ExecuteCommand(); + } + else + { + // 更新数据 库存信息 + SqlSugarHelper.Db.Insertable(new ChannelStock() + { + Quantity = it.AddQuantity, + Chnguid = it.Chnguid, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + DrawerNo = it.DrawerNo, + ColNo = it.ColNo, + DrugId = it.DrugId, + DrawerType = it.DrawerType, + BoardType = it.BoardType, + Id = Guid.NewGuid().ToString(), + MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1" + }).ExecuteCommand(); + } + } // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + 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(); // 保存数据 出/入库记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = it.MachineId, DrawerNo = it.DrawerNo, @@ -279,7 +343,9 @@ namespace DM_Weight.ViewModels Type = 1, InvoiceId = InvoiceId, StockQuantity = nowChannels.Sum(it => it.Quantity), - ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity), + SupplierDept = Invoice.PharmacyName1?? ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = Invoice.PharmacyName2 ?? ConfigurationManager.AppSettings["receiveDept"].ToString() }).ExecuteCommand(); } return true; @@ -287,13 +353,25 @@ namespace DM_Weight.ViewModels if (f.Data) { // 更新屏显库存 - List singleChannels = record.FindAll(it => it.BoardType != 1); + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = record.Where(it => it.BoardType != 1) + .GroupBy(it => it.ColNo) + .Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(itx => itx.Quantity); + ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList(); if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) { - singleChannels.ForEach(it => - { - _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity); - }); + //将库位多批次的总库存数更新标签 + _portUtil.WriteQuantity(singleChannels[0].DrawerNo, singleChannels[0].ColNo, singleChannels.Sum(it => it.Quantity) + singleChannels.Sum(it => it.AddQuantity)); + + //singleChannels.ForEach(it => + //{ + // _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity); + //}); } @@ -354,6 +432,6 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => false; + public bool KeepAlive => true; } } diff --git a/DM_Weight/ViewModels/InvoiceInNewWindow2ViewModel.cs b/DM_Weight/ViewModels/InvoiceInNewWindow2ViewModel.cs new file mode 100644 index 0000000..897861e --- /dev/null +++ b/DM_Weight/ViewModels/InvoiceInNewWindow2ViewModel.cs @@ -0,0 +1,626 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.select; +using DM_Weight.util; +using log4net; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Channels; +using System.Threading.Tasks; +using System.Windows.Data; +using Unity; + +namespace DM_Weight.ViewModels +{ + public class InvoiceInNewWindow2ViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime + { + private readonly ILog logger = LogManager.GetLogger(typeof(InvoiceInWindowViewModel)); + private int _pageNum = 1; + public int PageNum + { + get => _pageNum; + set + { + SetProperty(ref _pageNum, value); + RequestData(); + } + } + + private int _pageCount = 1; + public int PageCount + { + get => _pageCount; + set + { + SetProperty(ref _pageCount, value); + } + } + + private int _pageSize = 8; + public int PageSize + { + get => _pageSize; + set + { + SetProperty(ref _pageSize, value); + } + } + + private int _totalCount = 0; + public int TotalCount + { + get => _totalCount; + set + { + SetProperty(ref _totalCount, value); + } + } + private int _status = 0; + + public int Status { get => _status; set => SetProperty(ref _status, value); } + + IDialogService _dialogService; + + + IEventAggregator _eventAggregator; + + private DelegateCommand _rowSelected; + + public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(GetChannelByInvoice); + //private SqlSugarScope SqlSugarHelper.Db; + private PortUtil _portUtil; + public InvoiceInNewWindow2ViewModel(PortUtil portUtil, IDialogService DialogService, IEventAggregator eventAggregator, SqlSugarScope sqlSugarScope) + { + _portUtil = portUtil; + _dialogService = DialogService; + _eventAggregator = eventAggregator; + //this.SqlSugarHelper.Db = sqlSugarScope; + } + + public static List StaticOrderTakeSelects = new() + { + new OrderTakeSelect + { + Code = "invoiceNo", + Name = "凭证单号" + } + }; + + private List _orderTakeSelects = StaticOrderTakeSelects; + + public List OrderTakeSelects + { + get { return _orderTakeSelects; } + set + { + SetProperty(ref _orderTakeSelects, value); + } + } + + private OrderTakeSelect _selectedItem = StaticOrderTakeSelects[0]; + /// + /// 查询条件 查询字段 + /// + public OrderTakeSelect SelectedItem + { + get { return _selectedItem; } + set + { + SetProperty(ref _selectedItem, value); + RequestData(); + } + } + + private Invoice? _selectedInvoice; + + public Invoice? SelectedInvoice + { + get { return _selectedInvoice; } + set + { + SetProperty(ref _selectedInvoice, value); + + //OpenOrderDialog(); + } + } + + + private string _orderDate = DateTime.Now.ToString("yyyy-MM-dd"); + /// + /// 查询条件 处方日期 + /// + public string OrderDate + { + get { return _orderDate; } + set + { + if (!String.IsNullOrEmpty(value)) + { + SetProperty(ref _orderDate, DateTime.Parse(value).ToString("yyyy-MM-dd")); + } + else + { + SetProperty(ref _orderDate, value); + } + + RequestData(); + } + } + + private string? _searchValue; + + /// + /// 查询条件 查询字段值 + /// + public string? SearchValue + { + get { return _searchValue; } + set + { + SetProperty(ref _searchValue, value); + RequestData(); + } + } + + private List _invoices = new(); + + public List Invoices { get { return _invoices; } set { SetProperty(ref _invoices, value); } } + + + private List _inOutInvoices = new(); + + public List InOutInvoices { get { return _inOutInvoices; } set { SetProperty(ref _inOutInvoices, value); } } + + public bool KeepAlive => true; + + private ObservableCollection? _channelLsts = new(); + + public ObservableCollection? ChannelLsts + { + get => _channelLsts; + set => SetProperty(ref _channelLsts, value); + } + private List _channelStocks = new List(); + public List ChannelStocks + { + get => _channelStocks; + set => SetProperty(ref _channelStocks, value); + } + private IEnumerable> enumerable; + private IEnumerator> enumerator; + private string WindowName = "InvoiceAddWindow"; + //private List _channelStocks = new(); + + //public List ChannelStocks { get { return _channelStocks; } set { SetProperty(ref _channelStocks, value); } } + + + + private List _addChannels = new(); + + public List AddChannels { get { return _addChannels; } set { SetProperty(ref _addChannels, value); } } + //左侧点击事件 + public void GetChannelByInvoice() + { + //ChannelStocks.Clear(); + ChannelLsts.Clear(); + InOutInvoices.Clear(); + List iChannelStock = new List(); + 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"; + + var invoices = SqlSugarHelper.Db.SqlQueryable(strSql) + .AddParameters(new + { + INVOICE_NO = SelectedInvoice.InvoiceNo + }) + .Select(it => new InOutInvoice()) + .Select("*").ToList(); + + //if(iList!=null&&iList.Count>0) + //{ + // for (int i = 0; i < iList.Count; i++) + // { + // if (iList[i].Count>1) + // { + // for (int j = 0; j < iList[i].Count; j++) + // { + + // } + // } + // } + //} + + + //var invoices = SqlSugarHelper.Db.Queryable() + // .Includes(i => i.DrugInfo) + // .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (i, t) => i.DrugId == t.DrugId) + // .Where(i => i.InvoiceNo == SelectedInvoice.InvoiceNo) + // .ToList(); + + for (int i = 0; i < invoices.Count; i++) + { + List queryData = SqlSugarHelper.Db.Queryable() + .Includes(cl => cl.Drug, di => di.DrugManuNos) + .Includes(cl => cl.channelStocks, dr => dr.DrugInfo, d => d.DrugManuNos) + .Where(cl => cl.DrugId == invoices[i].DrugId) + .Where(cl => cl.DrawerType == 1) + .Where(cl => cl.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + //.Where(cl => cl.DrugId != null) + //.WhereIF(!string.IsNullOrEmpty(invoices[i].DrugManuNo), cl => cl.drugManuNo.Equals(invoices[i].DrugManuNo)) + .OrderBy(cl => cl.ColNo) + .ToList(); + List channelLst = queryData.Select(cl => + { + cl.channelStocks = cl.channelStocks.Select(cs => + { + cs.drugManuNo = cl.Drug.DrugManuNos.Find(it => it.ManuNo.Equals(cs.ManuNo)); + return cs; + }).ToList(); + return cl; + }).OrderBy(cl => cl.ColNo).ToList(); + channelLst.ForEach(cl => cl.channelStocks.ForEach(cs => cs.DrugInfo = cl.Drug)); + if (channelLst.Count > 0) + { + if (channelLst[0].channelStocks.Count > 0) + { + //for (int j = 0; j < channelLst[0].channelStocks.Count; j++) + { + var invoicesManuNo = SqlSugarHelper.Db.Queryable() + .Where(iManuNo => iManuNo.InvoiceNo == invoices[i].InvoiceNo && iManuNo.DrugId == invoices[i].DrugId).ToList(); + for (int k = 0; k < invoicesManuNo.Count; k++) + { + + List stockLst = channelLst[0].channelStocks.Where(cs => cs.ManuNo == invoicesManuNo[k].DrugManuNo).ToList(); + if (stockLst != null && stockLst.Count > 0) + { + channelLst[0].channelStocks.Where(cs => cs.ManuNo == invoicesManuNo[k].DrugManuNo).ToList()[0].AddQuantity = invoicesManuNo[k].quantity; //.AddQuantity = invoicesManuNo[k].quantity; + + } + else + { + ChannelStock cls = new ChannelStock(); + DrugManuNo drugManu = new DrugManuNo(); + cls.DrugInfo = channelLst[0].Drug; + List drugManuNoList = channelLst[0].Drug.DrugManuNos;// SqlSugarHelper.Db.Queryable().Where(dmn=>dmn.DrugId== invoicesManuNo[k].DrugId).ToList(); + //if (channelLst[0].channelStocks.Count > 0) + //{ + // //channelLst[0].channelStocks[0].AddQuantity = invoices[i].quantity; + // cls.drugManuNo = channelLst[0].channelStocks[0].drugManuNo; + //} + //else + { + //drugManu = cls.DrugInfo.DrugManuNos[0]; + if (drugManuNoList != null&& drugManuNoList.Count>0) + { + cls.DrugInfo.DrugManuNos = drugManuNoList; + cls.drugManuNo = drugManuNoList.Where(dmn => dmn.ManuNo == invoicesManuNo[k].DrugManuNo).First(); + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "该药品下没有批次,请先添加批次", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return; + } + } + cls.Chnguid = null; + cls.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; + cls.DrawerNo = channelLst[0].DrawerNo; + cls.BoardType = channelLst[0].BoardType; + cls.DrawerType = channelLst[0].DrawerType; + cls.ColNo = channelLst[0].ColNo; + cls.DrugId = channelLst[0].DrugId; + cls.AddQuantity = invoicesManuNo[k].quantity; + cls.ManuNo = invoicesManuNo[k].DrugManuNo; + channelLst[0].channelStocks.Add(cls); + } + } + + } + } + else + { + List CSList = new List(); + if (!string.IsNullOrEmpty(invoices[i].DrugManuNo)) + { + //List stockLst = channelLst[i].channelStocks.Where(cs => cs.ManuNo == invoices[i].DrugManuNo).ToList(); + //if (stockLst != null && stockLst.Count > 0) + //{ + // channelLst[i].channelStocks[i].AddQuantity = invoices[i].quantity; + //} + //else + { + ChannelStock cls = new ChannelStock(); + DrugManuNo drugManu = new DrugManuNo(); + cls.DrugInfo = channelLst[0].Drug; + if (channelLst[0].channelStocks.Count > 0) + { + channelLst[0].channelStocks[0].AddQuantity = invoices[i].quantity; + cls.drugManuNo = channelLst[0].channelStocks[0].drugManuNo; + } + else + { + //drugManu= cls.DrugInfo.DrugManuNos[0]; + if (cls.DrugInfo.DrugManuNos.Count > 0) + { + //cls.drugManuNo = cls.DrugInfo.DrugManuNos[0]; + cls.drugManuNo = cls.DrugInfo.DrugManuNos.Where(dm => dm.ManuNo == invoices[i].DrugManuNo).First(); + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "该药品下没有批次,请先添加批次", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return; + } + } + cls.Chnguid = channelLst[0].Id; + cls.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; + cls.DrawerNo = channelLst[0].DrawerNo; + cls.BoardType = channelLst[0].BoardType; + cls.DrawerType = channelLst[0].DrawerType; + cls.ColNo = channelLst[0].ColNo; + cls.DrugId = channelLst[0].DrugId; + cls.AddQuantity = invoices[i].quantity; + List stockList = new List(); + stockList.AddRange(channelLst[0].channelStocks); + stockList.Add(cls); + channelLst[0].channelStocks = stockList; + } + } + } + } + else + { + //药品未绑定库位,需要先绑药 + AlertMsg alertMsg = new AlertMsg + { + Message = "药品未绑定库位,请先绑定库位", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + InOutInvoice copy = TransExpV2.Trans(invoices[i]); + InOutInvoices.Add(copy); + ChannelLsts.AddRange(channelLst); + } + } + + } + + public DelegateCommand OpenInvoiceAdd + { + get => new DelegateCommand(() => + { + Status = 1; + bool flag = true; + var list = ChannelLsts.GroupBy(cl => cl.DrugId).ToList(); + if (list != null && list.Count == InOutInvoices.Count) + { + for (int i = 0; i < InOutInvoices.Count; i++) + { + InOutInvoice invoices = InOutInvoices[i]; + //if (invoices.quantity != ChannelStocks.FindAll(it => it.DrugId == invoices.DrugId).Sum(it => it.AddQuantity)) + if (invoices.SumQuantity != ChannelLsts[i].channelStocks.FindAll(it => it.DrugId == invoices.DrugId).Sum(it => it.AddQuantity)) + { + flag = false; + break; + } + } + } + if (flag) + { + ChannelStocks.Clear(); + foreach (ChannelList lst in ChannelLsts) + { + ChannelStocks.AddRange(lst.channelStocks); + } + AddChannels = ChannelStocks.FindAll(it => it.AddQuantity != 0); + //AddChannels = ChannelLsts[i].channelStocks.FindAll(it => it.AddQuantity != 0); + if (AddChannels.Count > 0) + { + for (int i = 0; i < AddChannels.Count; i++) + { + AddChannels[i].ManuNo = AddChannels[i].drugManuNo.ManuNo; + AddChannels[i].EffDate = AddChannels[i].drugManuNo.EffDate; + } + AddChannels.Sort((a, b) => + { + if ((a.DrawerNo - b.DrawerNo) == 0) + { + return a.ColNo - b.ColNo; + } + return a.DrawerNo - b.DrawerNo; + }); + } + //enumerable = ChannelStocks.GroupBy(cs => cs.DrawerNo, cs => cs); + //enumerator = enumerable.GetEnumerator(); + //enumerator.MoveNext(); + //OpenOneByOne(); + OpenOrderDialog(); + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "库位添加数量小于应添加数量", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + }, () => SelectedInvoice != null).ObservesProperty(() => SelectedInvoice); + } + + public async void OpenOrderDialog() + { + if (SelectedInvoice != null && SelectedInvoice.Status == 0) + { + // 此处延时1毫秒,等待页面渲染 + await Task.Delay(TimeSpan.FromMilliseconds(1)); + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("invoice", SelectedInvoice); + dialogParameters.Add("ChannelStocks", AddChannels); + DialogServiceExtensions.ShowDialogHost(_dialogService, "InvoiceAddDialog", dialogParameters, DoDialogResult, "RootDialog"); + } + } + + public DelegateCommand QueryCommand + { + get => new DelegateCommand(() => + { + RequestData(); + }); + } + + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + //if (dialogResult.Result == ButtonResult.OK) + { + SelectedInvoice = null; + RequestData(); + } + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } + + + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 + public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) + { + continuationCallback(true); + } + + public void RequestData() + { + Invoices.Clear(); + int totalCount = 0; + + var sb = new StringBuilder(); + //sb.Append("select i.invoice_no as InvoiceNo, i.invoice_date as InvoiceDate, COUNT(i.id) as `Count`, SUM(i.quantity) as quantity, p1.pharmacy_name as PharmacyName1, p2.pharmacy_name as PharmacyName2 from in_out_invoice i"); + sb.Append(" SELECT count(1) as Count, i.InvoiceNo, i.InvoiceDate, sum(i.quantity) as quantity, p1.pharmacy_name as PharmacyName1, p2.pharmacy_name PharmacyName2 from "); + sb.Append(" (SELECT drug_id,in_pharmacy_id,out_pharmacy_id, invoice_no as InvoiceNo, DATE_FORMAT(Invoice_Date,'%Y-%m-%d') as InvoiceDate, SUM(quantity) as quantity "); + sb.Append(" FROM in_out_invoice where status=@Status and type!=@type and cancel_flag=@CancelFlag GROUP BY invoice_no,drug_id) i "); + sb.Append(" inner join ( select c.drug_id as drug_id from channel_list c where c.machine_id = '" + (ConfigurationManager.AppSettings["machineId"] ?? "DM1") + "' group by c.drug_id ) di on di.drug_id = i.drug_id"); + sb.Append(" left join pharmacy_info p1 on p1.pharmacy_id = i.in_pharmacy_id"); + sb.Append(" left join pharmacy_info p2 on p2.pharmacy_id = i.out_pharmacy_id where 1=1"); + //sb.Append(" where i.status=@Status "); + //sb.Append(" and i.type!=@type "); + //sb.Append(" and i.cancel_flag=@CancelFlag "); + if (OrderDate != null) + { + sb.Append(" and i.InvoiceDate = @CreateTime "); + } + if (!String.IsNullOrEmpty(SearchValue)) + { + sb.Append(" and i.InvoiceNo = @InvoiceNo "); + } + if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["storage"])) + { + sb.Append(" and i.in_pharmacy_id = @OutPharmacyId "); + } + //sb.Append(" group by i.invoice_no"); + sb.Append(" GROUP BY i.InvoiceNo order by i.InvoiceDate "); + Invoices = SqlSugarHelper.Db.SqlQueryable(sb.ToString()) + .AddParameters(new + { + Status = 0, + type = 2, + CancelFlag = 0, + CreateTime = OrderDate, + InvoiceNo = SearchValue, + OutPharmacyId = ConfigurationManager.AppSettings["storage"] + }) + .Select(it => new Invoice()) + .Select("*") + .ToPageList(PageNum, PageSize, ref totalCount); + + TotalCount = totalCount; + PageCount = (int)Math.Ceiling((double)TotalCount / PageSize); + } + //添加批次 + public void AddAction(ChannelList channelLS) + { + if (channelLS != null) + { + ChannelStock cls = new ChannelStock(); + DrugManuNo drugManu = new DrugManuNo(); + cls.DrugInfo = channelLS.Drug; + if (channelLS.channelStocks.Count > 0) + { + cls.drugManuNo = channelLS.channelStocks[0].drugManuNo; + } + else + { + //drugManu= cls.DrugInfo.DrugManuNos[0]; + if (cls.DrugInfo.DrugManuNos.Count > 0) + { + cls.drugManuNo = cls.DrugInfo.DrugManuNos[0]; + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "该药品下没有批次,请先添加批次", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + return; + } + } + //cls.Id = ""; + cls.Chnguid = channelLS.Id; + cls.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; + cls.DrawerNo = channelLS.DrawerNo; + cls.BoardType = channelLS.BoardType; + cls.DrawerType = channelLS.DrawerType; + cls.ColNo = channelLS.ColNo; + cls.DrugId = channelLS.DrugId; + cls.AddQuantity = 0; + List stockList = new List(); + stockList.AddRange(channelLS.channelStocks); + stockList.Add(cls); + channelLS.channelStocks = stockList; + } + } + + //接收导航传过来的参数 现在是在此处初始化了表格数据 + public void OnNavigatedTo(NavigationContext navigationContext) + { + _eventAggregator.GetEvent().Subscribe(AddAction); + RequestData(); + } + + //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + //这个方法用于拦截请求 + public void OnNavigatedFrom(NavigationContext navigationContext) + { + _eventAggregator.GetEvent().Unsubscribe(AddAction); + } + } +} diff --git a/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs b/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs new file mode 100644 index 0000000..0a687df --- /dev/null +++ b/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs @@ -0,0 +1,754 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.select; +using DM_Weight.util; +using log4net; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace DM_Weight.ViewModels +{ + public class InvoiceInNewWindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime + { + private readonly ILog logger = LogManager.GetLogger(typeof(InvoiceInWindowViewModel)); + private int _pageNum = 1; + public int PageNum + { + get => _pageNum; + set + { + SetProperty(ref _pageNum, value); + RequestData(); + } + } + + private int _pageCount = 1; + public int PageCount + { + get => _pageCount; + set + { + SetProperty(ref _pageCount, value); + } + } + + private int _pageSize = 8; + public int PageSize + { + get => _pageSize; + set + { + SetProperty(ref _pageSize, value); + } + } + + private int _totalCount = 0; + public int TotalCount + { + get => _totalCount; + set + { + SetProperty(ref _totalCount, value); + } + } + private int _status = 0; + + public int Status { get => _status; set => SetProperty(ref _status, value); } + + IDialogService _dialogService; + + + IEventAggregator _eventAggregator; + + private DelegateCommand _rowSelected; + + public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(GetChannelByInvoice); + ////private SqlSugarScope SqlSugarHelper.Db; + private PortUtil _portUtil; + public InvoiceInNewWindowViewModel(PortUtil portUtil, IDialogService DialogService, IEventAggregator eventAggregator) + { + _portUtil = portUtil; + _dialogService = DialogService; + _eventAggregator = eventAggregator; + ////this.SqlSugarHelper.Db = sqlSugarScope; + } + void DoMyPrismEvent(DeviceMsg msg) + { + + if (msg.WindowName.Equals(WindowName)) + { + IGrouping grouping = enumerator.Current; + int DrawerNo = grouping.Key; + List channelStocks = grouping.ToList(); + + switch (msg.EventType) + { + // 抽屉打开 + case EventType.DRAWEROPEN: + + + if (Status == 1) + { + if (channelStocks[0].process == 1) + { + channelStocks.ForEach(it => it.process = 2); + } + } + + break; + // 抽屉关闭 + case EventType.DRAWERCLOSE: + if (Status == 1) + { + if (channelStocks[0].process == 2) + { + channelStocks.ForEach(it => it.process = 3); + } + IGrouping groupingBefore = enumerator.Current; + int DrawerNoBefore = groupingBefore.Key; + if (enumerator.MoveNext()) + { + IGrouping groupingAfter = enumerator.Current; + int DrawerNoAfter = groupingAfter.Key; + if (DrawerNoBefore < 9 && DrawerNoAfter > 8) + { + Thread.Sleep(50); + } + OpenOneByOne(); + } + // 已经全部取出 + else + { + Status = 3; + } + } + break; + // 数量变化 + case EventType.UPDATEQUANTITY: + if (Status == 1) + { + + logger.Info($"抽屉【{DrawerNo}】库位药品数量【{msg.Quantitys}】"); + } + break; + // 打开失败 + case EventType.OPENERROR: + AlertMsg alertMsg = new AlertMsg + { + Message = msg.Message, + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Status = 0; + break; + } + } + + } + + public static List StaticOrderTakeSelects = new() + { + new OrderTakeSelect + { + Code = "invoiceNo", + Name = "凭证单号" + } + }; + + private List _orderTakeSelects = StaticOrderTakeSelects; + + public List OrderTakeSelects + { + get { return _orderTakeSelects; } + set + { + SetProperty(ref _orderTakeSelects, value); + } + } + + private OrderTakeSelect _selectedItem = StaticOrderTakeSelects[0]; + /// + /// 查询条件 查询字段 + /// + public OrderTakeSelect SelectedItem + { + get { return _selectedItem; } + set + { + SetProperty(ref _selectedItem, value); + RequestData(); + } + } + + private Invoice? _selectedInvoice; + + public Invoice? SelectedInvoice + { + get { return _selectedInvoice; } + set + { + SetProperty(ref _selectedInvoice, value); + + //OpenOrderDialog(); + } + } + + + private string _orderDate = DateTime.Now.ToString("yyyy-MM-dd"); + /// + /// 查询条件 处方日期 + /// + public string OrderDate + { + get { return _orderDate; } + set + { + if (!String.IsNullOrEmpty(value)) + { + SetProperty(ref _orderDate, DateTime.Parse(value).ToString("yyyy-MM-dd")); + } + else + { + SetProperty(ref _orderDate, value); + } + + RequestData(); + } + } + + private string? _searchValue; + + /// + /// 查询条件 查询字段值 + /// + public string? SearchValue + { + get { return _searchValue; } + set + { + SetProperty(ref _searchValue, value); + RequestData(); + } + } + + private List _invoices = new(); + + public List Invoices { get { return _invoices; } set { SetProperty(ref _invoices, value); } } + + + private List _inOutInvoices = new(); + + public List InOutInvoices { get { return _inOutInvoices; } set { SetProperty(ref _inOutInvoices, value); } } + + + private ObservableCollection? _channelLsts = new(); + + public ObservableCollection? ChannelLsts + { + get => _channelLsts; + set => SetProperty(ref _channelLsts, value); + } + private List _channelStocks = new List(); + public List ChannelStocks + { + get => _channelStocks; + set => SetProperty(ref _channelStocks, value); + } + private IEnumerable> enumerable; + private IEnumerator> enumerator; + private string WindowName = "InvoiceAddWindow"; + //private List _channelStocks = new(); + + //public List ChannelStocks { get { return _channelStocks; } set { SetProperty(ref _channelStocks, value); } } + + + + private List _addChannels = new(); + + public List AddChannels { get { return _addChannels; } set { SetProperty(ref _addChannels, value); } } + //左侧点击事件 + public void GetChannelByInvoice() + { + //ChannelStocks.Clear(); + ChannelLsts.Clear(); + InOutInvoices.Clear(); + List iChannelStock = new List(); + 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"; + + var invoices = SqlSugarHelper.Db.SqlQueryable(strSql) + .AddParameters(new + { + INVOICE_NO = SelectedInvoice.InvoiceNo + }) + .Select(it => new InOutInvoice()) + .Select("*").ToList(); + for (int i = 0; i < invoices.Count; i++) + { + //查询药品是否绑定 + List channelL = SqlSugarHelper.Db.Queryable() + .Includes(cl => cl.Drug, di => di.DrugManuNos) + //.Includes(cl => cl.channelStocks, dr => dr.DrugInfo, d => d.DrugManuNos) + .Where(cl => cl.DrugId == invoices[i].DrugId && cl.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM1")).ToList(); + ChannelList channelLst = channelL.Count > 0 ? channelL[0] : null; + if (channelLst == null || channelLst.Id is null) + { + //药品未绑定库位,需要先绑药 + //AlertMsg alertMsg = new AlertMsg + //{ + // Message = "药品未绑定库位,请先绑定库位", + // Type = MsgType.ERROR, + //}; + //_eventAggregator.GetEvent().Publish(alertMsg); + continue; + } + ChannelStock stock = new ChannelStock(); + //查询每种药有多少个批次 + var invoicesManuNo = SqlSugarHelper.Db.Queryable() + .Where(iManuNo => iManuNo.InvoiceNo == invoices[i].InvoiceNo && iManuNo.DrugId == invoices[i].DrugId).ToList(); + for (int j = 0; j < invoicesManuNo.Count; j++) + { + //查询是否有库存 + List stockList = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.ManuNo == invoicesManuNo[j].DrugManuNo && cs.DrugId == invoicesManuNo[j].DrugId && cs.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM1")).ToList(); + stock = stockList.Count > 0 ? stockList[0] : new ChannelStock(); + List manuNoList = SqlSugarHelper.Db.Queryable().Where(dm => dm.ManuNo == invoicesManuNo[j].DrugManuNo && dm.DrugId == invoicesManuNo[j].DrugId).ToList(); + if (stock == null || stock.Id is null) + { + if (manuNoList == null || manuNoList.Count <= 0) + { + //药品批次不存在 + AlertMsg alertMsg = new AlertMsg + { + Message = $"药品批次{invoicesManuNo[j].DrugManuNo}不存在,请核对药品批次信息!", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + continue; + } + //没有库存写入一条数据 + stock.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; + stock.DrawerNo = channelLst.DrawerNo; + stock.BoardType = channelLst.BoardType; + stock.DrawerType = channelLst.DrawerType; + stock.ColNo = channelLst.ColNo; + stock.DrugId = channelLst.DrugId; + stock.ManuNo = invoicesManuNo[j].DrugManuNo; + stock.EffDate = manuNoList[0].EffDate; + stock.Chnguid = channelLst.Id; + } + stock.AddQuantity = invoicesManuNo[j].quantity; + if (channelLst.channelStocks == null) + { + channelLst.channelStocks = new List(); + } + channelLst.channelStocks.Add(stock); + } + + InOutInvoice copy = TransExpV2.Trans(invoices[i]); + InOutInvoices.Add(copy); + ChannelLsts.Add(channelLst); + } + } + + } + + public DelegateCommand OpenInvoiceAdd + { + get => new DelegateCommand(() => + { + bool flag = true; + ChannelStocks.Clear(); + foreach (ChannelList lst in ChannelLsts) + { + ChannelStocks.AddRange(lst.channelStocks); + } + AddChannels = ChannelStocks.FindAll(it => it.AddQuantity != 0); + + enumerable = AddChannels.GroupBy(cs => cs.DrawerNo, cs => cs); + enumerator = enumerable.GetEnumerator(); + OpenDrawer(AddChannels); + }, () => SelectedInvoice != null).ObservesProperty(() => SelectedInvoice); + } + + private void OpenDrawer(List AddChannels) + { + if (Status == 0) + { + enumerator.MoveNext(); + Status = 1; + OpenOneByOne(); + } + } + private async void OpenOneByOne() + { + IGrouping grouping = enumerator.Current; + int DrawerNo = grouping.Key; + List channelStocks = grouping.ToList(); + channelStocks.ForEach(it => it.process = 1); + _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + List singleChannels = channelStocks.GroupBy(it => new + { + it.DrawerNo, + it.ColNo + }).Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(itx => itx.Quantity); + ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList().FindAll(it => it.BoardType != 1); + + _portUtil.WindowName = WindowName; + _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; + _portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray(); + _portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); + _portUtil.DrawerNo = DrawerNo; + + if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + { + List ChannelLst = channelStocks.Where(it => it.BoardType != 1) + .GroupBy(it => it.ColNo) + .Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(itx => itx.Quantity); + ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList(); + // 发送加药数量 + singleChannels.ForEach(it => + { + _portUtil.TakeQuantity(DrawerNo, it.ColNo, it.AddQuantity, it.Quantity + it.AddQuantity); + }); + } + + if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 6) + { + for (int i = 0; i < singleChannels.Count; i++) + { + ChannelStock it = singleChannels[i]; + _portUtil.ClearCount(it.DrawerNo, it.ColNo); + await Task.Delay(50); + } + } + + _portUtil.Start(); + } + private bool _isFinishClick = false; + // 完成按钮 + public DelegateCommand TakeFinish + { + get => new DelegateCommand(async () => + { + if (!_isFinishClick) + { + _isFinishClick = true; + List record = ChannelStocks.ToList(); + string InvoiceId = SelectedInvoice.InvoiceNo; + 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++) + { + + + ChannelStock it = record[i]; + if (it.BoardType == 6 && it.PosNo == 0) + { + _portUtil.SetNumCount(it.DrawerNo, it.ColNo, it.AddQuantity); + } + if (it.Id != null) + { + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = it.Quantity + it.AddQuantity, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + Id = it.Id, + }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); + } + else + { + //如果批号重复则不让添加 + List csCount = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == it.DrawerNo && cs.ColNo == it.ColNo && cs.ManuNo == it.ManuNo && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.Quantity > 0).ToList(); + if (csCount.Count > 0) + { + //repeatList.Add(it.ManuNo); + //stockRepeats.Add(it); + continue; + } + //查询现有库位中是否有库存为0的记录,如果有直接update + ChannelStock recordHistory = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == it.DrawerNo && cs.ColNo == it.ColNo && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.Quantity <= 0).First(); + if (recordHistory!=null&& recordHistory.Id!=null) + { + SqlSugarHelper.Db.Updateable().SetColumns(item => new ChannelStock() + { + Quantity = it.AddQuantity, + ManuNo = it.ManuNo, + EffDate = it.EffDate + }).Where(item => item.Id == recordHistory.Id).ExecuteCommand(); + } + else + { + // 更新数据 库存信息 + SqlSugarHelper.Db.Insertable(new ChannelStock() + { + Quantity = it.AddQuantity, + Chnguid = it.Chnguid, + ManuNo = it.ManuNo, + EffDate = it.EffDate, + DrawerNo = it.DrawerNo, + ColNo = it.ColNo, + DrugId = it.DrugId, + DrawerType = it.DrawerType, + BoardType = it.BoardType, + Id = Guid.NewGuid().ToString(), + MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1" + }).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 = it.AddQuantity, + Type = 1, + InvoiceId = InvoiceId, + StockQuantity = nowChannels.Sum(it => it.Quantity), + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity), + SupplierDept = SelectedInvoice.PharmacyName1 ?? ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = SelectedInvoice.PharmacyName2 ?? ConfigurationManager.AppSettings["receiveDept"].ToString() + }).ExecuteCommand(); + } + if (ChannelLsts != null && ChannelLsts.Count > 0) + { + for (int i = 0; i < ChannelLsts.Count; i++) + { + //根据ChannelLsts中的库位,删除该库位库存为0的记录 + SqlSugarHelper.Db.Deleteable() + .Where(cs => cs.Quantity <= 0 && cs.DrawerNo == ChannelLsts[i].channelStocks[0].DrawerNo && cs.ColNo == ChannelLsts[i].channelStocks[0].ColNo).ExecuteCommand(); + } + } + return true; + }); + if (f.Data) + { + // 更新屏显库存 + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = record.Where(it => it.BoardType != 1) + .GroupBy(it => new { it.DrawerNo, it.ColNo }) + .Select(it => + { + var ret = it.First(); + //ret.Quantity = it.Sum(itx => itx.Quantity); + //ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }) + .ToList(); + if (singleChannels != null && singleChannels.Count > 0) + { + for (int i = 0; i < singleChannels.Count; i++) + { + if (singleChannels[i].BoardType == 5) + { + List channelStockEffDate = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId==singleChannels[i].MachineId) + .Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo) + .Where(cs => cs.ColNo == singleChannels[i].ColNo) + .OrderBy(cs => cs.EffDate).ToList(); + int totalQuantity = channelStockEffDate.Sum(it => it.Quantity); + + //将库位多批次的总库存数更新标签 + _portUtil.WriteQuantity(channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo, totalQuantity); + Thread.Sleep(200); + _portUtil.WriteChannelInfo(6, channelStockEffDate[0].EffDate == null ? "" : channelStockEffDate[0].EffDate, channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); + Thread.Sleep(200); + _portUtil.WriteChannelInfo(5, channelStockEffDate[0].ManuNo, channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); + Thread.Sleep(200); + _portUtil.ShowContent(channelStockEffDate[0].DrawerNo, channelStockEffDate[0].ColNo); + } + } + } + + + + + 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; + _isFinishClick = false; + + } + RequestData(); + }); + } + // 取消按钮 + public DelegateCommand CancleTake + { + get => new DelegateCommand(() => + { + RequestData(); + _portUtil.ResetData(); + Status = 0; + }); + } + public async void OpenOrderDialog() + { + //if (SelectedInvoice != null && SelectedInvoice.Status == 0) + //{ + // // 此处延时1毫秒,等待页面渲染 + // await Task.Delay(TimeSpan.FromMilliseconds(1)); + // DialogParameters dialogParameters = new DialogParameters(); + // dialogParameters.Add("invoice", SelectedInvoice); + // dialogParameters.Add("ChannelStocks", AddChannels); + // DialogServiceExtensions.ShowDialogHost(_dialogService, "InvoiceAddDialog", dialogParameters, DoDialogResult, "RootDialog"); + //} + } + + public DelegateCommand QueryCommand + { + get => new DelegateCommand(() => + { + RequestData(); + }); + } + + public bool KeepAlive => true; + + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + //if (dialogResult.Result == ButtonResult.OK) + { + SelectedInvoice = null; + RequestData(); + } + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } + + + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 + public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) + { + continuationCallback(true); + } + + public void RequestData() + { + Invoices.Clear(); + int totalCount = 0; + + var sb = new StringBuilder(); + //sb.Append("select i.invoice_no as InvoiceNo, i.invoice_date as InvoiceDate, COUNT(i.id) as `Count`, SUM(i.quantity) as quantity, p1.pharmacy_name as PharmacyName1, p2.pharmacy_name as PharmacyName2 from in_out_invoice i"); + sb.Append(" SELECT count(1) as Count, i.InvoiceNo, i.InvoiceDate, sum(i.quantity) as quantity, p1.pharmacy_name as PharmacyName1, p2.pharmacy_name PharmacyName2 from "); + sb.Append(" (SELECT drug_id,in_pharmacy_id,out_pharmacy_id, invoice_no as InvoiceNo, DATE_FORMAT(Invoice_Date,'%Y-%m-%d') as InvoiceDate, SUM(quantity) as quantity "); + sb.Append(" FROM in_out_invoice where status=@Status and type!=@type and cancel_flag=@CancelFlag GROUP BY invoice_no,drug_id) i "); + sb.Append(" inner join ( select c.drug_id as drug_id from channel_list c where c.machine_id = '" + (ConfigurationManager.AppSettings["machineId"] ?? "DM1") + "' group by c.drug_id ) di on di.drug_id = i.drug_id"); + sb.Append(" left join pharmacy_info p1 on p1.pharmacy_id = i.in_pharmacy_id"); + sb.Append(" left join pharmacy_info p2 on p2.pharmacy_id = i.out_pharmacy_id where 1=1"); + //sb.Append(" where i.status=@Status "); + //sb.Append(" and i.type!=@type "); + //sb.Append(" and i.cancel_flag=@CancelFlag "); + if (OrderDate != null) + { + sb.Append(" and i.InvoiceDate = @CreateTime "); + } + if (!String.IsNullOrEmpty(SearchValue)) + { + sb.Append(" and i.InvoiceNo = @InvoiceNo "); + } + if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["storage"])) + { + sb.Append(" and i.in_pharmacy_id = @OutPharmacyId "); + } + //sb.Append(" group by i.invoice_no"); + sb.Append(" GROUP BY i.InvoiceNo order by i.InvoiceDate "); + Invoices = SqlSugarHelper.Db.SqlQueryable(sb.ToString()) + .AddParameters(new + { + Status = 0, + type = 2, + CancelFlag = 0, + CreateTime = OrderDate, + InvoiceNo = SearchValue, + OutPharmacyId = ConfigurationManager.AppSettings["storage"] + }) + .Select(it => new Invoice()) + .Select("*") + .ToPageList(PageNum, PageSize, ref totalCount); + + TotalCount = totalCount; + PageCount = (int)Math.Ceiling((double)TotalCount / PageSize); + } + //接收导航传过来的参数 现在是在此处初始化了表格数据 + public void OnNavigatedTo(NavigationContext navigationContext) + { + _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + RequestData(); + } + + //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + //这个方法用于拦截请求 + public void OnNavigatedFrom(NavigationContext navigationContext) + { + _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + } +} diff --git a/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs b/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs index 76a86f8..9eafbe1 100644 --- a/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceInWindowViewModel.cs @@ -77,12 +77,12 @@ namespace DM_Weight.ViewModels private DelegateCommand _rowSelected; public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(GetChannelByInvoice); - private SqlSugarScope _sqlSugarScope1; - public InvoiceInWindowViewModel(IDialogService DialogService, IEventAggregator eventAggregator,SqlSugarScope sqlSugarScope) + //private SqlSugarScope SqlSugarHelper.Db; + public InvoiceInWindowViewModel(IDialogService DialogService, IEventAggregator eventAggregator) { _dialogService = DialogService; _eventAggregator = eventAggregator; - this._sqlSugarScope1= sqlSugarScope; + //this.SqlSugarHelper.Db= sqlSugarScope; } public static List StaticOrderTakeSelects = new() @@ -179,7 +179,6 @@ namespace DM_Weight.ViewModels public List InOutInvoices { get { return _inOutInvoices; } set { SetProperty(ref _inOutInvoices, value); } } - public bool KeepAlive => false; private List _channelStocks = new(); @@ -198,14 +197,14 @@ namespace DM_Weight.ViewModels List i = new List(); if (SelectedInvoice != null) { - var invoices = _sqlSugarScope1.Queryable() + var invoices = SqlSugarHelper.Db.Queryable() .Includes(i => i.DrugInfo) - .InnerJoin(_sqlSugarScope1.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (i, t) => i.DrugId == t.DrugId) + .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (i, t) => i.DrugId == t.DrugId) .Where(i => i.InvoiceNo == SelectedInvoice.InvoiceNo) .ToList(); foreach (var invoice in invoices) { - List q = _sqlSugarScope1.Queryable() + List q = SqlSugarHelper.Db.Queryable() .Includes(cs => cs.DrugInfo) .WhereIF(!string.IsNullOrEmpty(invoice.DrugEffDate), cs => cs.EffDate.Equals(invoice.DrugEffDate)) .WhereIF(!string.IsNullOrEmpty(invoice.DrugManuNo), cs => cs.ManuNo.Equals(invoice.DrugManuNo)) @@ -300,6 +299,8 @@ namespace DM_Weight.ViewModels }); } + public bool KeepAlive => true; + private void DoDialogResult(IDialogResult dialogResult) { // 委托 被动执行 被子窗口执行 @@ -325,28 +326,31 @@ namespace DM_Weight.ViewModels int totalCount = 0; var sb = new StringBuilder(); - sb.Append("select i.invoice_no as InvoiceNo, i.invoice_date as InvoiceDate, COUNT(i.id) as `Count`, SUM(i.quantity) as quantity, p1.pharmacy_name as PharmacyName1, p2.pharmacy_name as PharmacyName2 from in_out_invoice i"); + //sb.Append("select i.invoice_no as InvoiceNo, i.invoice_date as InvoiceDate, COUNT(i.id) as `Count`, SUM(i.quantity) as quantity, p1.pharmacy_name as PharmacyName1, p2.pharmacy_name as PharmacyName2 from in_out_invoice i"); + sb.Append(" SELECT i.InvoiceNo, i.InvoiceDate, i.Count, i.quantity, p1.pharmacy_name as PharmacyName1, p2.pharmacy_name PharmacyName2 from "); + sb.Append(" (SELECT drug_id,in_pharmacy_id,out_pharmacy_id, invoice_no as InvoiceNo, invoice_date as InvoiceDate, COUNT(id) as `Count`, SUM(quantity) as quantity "); + sb.Append(" FROM in_out_invoice where status=@Status and type!=@type and cancel_flag=@CancelFlag GROUP BY invoice_no) i "); sb.Append(" inner join ( select c.drug_id as drug_id from channel_stock c where c.machine_id = '" + (ConfigurationManager.AppSettings["machineId"] ?? "DM1") + "' group by c.drug_id ) di on di.drug_id = i.drug_id"); sb.Append(" left join pharmacy_info p1 on p1.pharmacy_id = i.in_pharmacy_id"); sb.Append(" left join pharmacy_info p2 on p2.pharmacy_id = i.out_pharmacy_id"); - sb.Append(" where i.status=@Status "); - sb.Append(" and i.type!=@type "); - sb.Append(" and i.cancel_flag=@CancelFlag "); + //sb.Append(" where i.status=@Status "); + //sb.Append(" and i.type!=@type "); + //sb.Append(" and i.cancel_flag=@CancelFlag "); if (OrderDate != null) { - sb.Append(" and i.invoice_date = @CreateTime "); + sb.Append(" and i.InvoiceDate = @CreateTime "); } if (!String.IsNullOrEmpty(SearchValue)) { - sb.Append(" and i.invoice_no = @InvoiceNo "); + sb.Append(" and i.InvoiceNo = @InvoiceNo "); } if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["storage"])) { sb.Append(" and i.in_pharmacy_id = @OutPharmacyId "); } - sb.Append(" group by i.invoice_no"); - sb.Append(" order by i.invoice_date "); - Invoices = _sqlSugarScope1.SqlQueryable(sb.ToString()) + //sb.Append(" group by i.invoice_no"); + sb.Append(" order by i.InvoiceDate "); + Invoices = SqlSugarHelper.Db.SqlQueryable(sb.ToString()) .AddParameters(new { Status = 0, diff --git a/DM_Weight/ViewModels/InvoiceOutWindowViewModel.cs b/DM_Weight/ViewModels/InvoiceOutWindowViewModel.cs index 367709e..e404bcb 100644 --- a/DM_Weight/ViewModels/InvoiceOutWindowViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceOutWindowViewModel.cs @@ -67,11 +67,11 @@ namespace DM_Weight.ViewModels private DelegateCommand _rowSelected; public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(OpenOrderDialog); - private SqlSugarScope _sqlSugarScope1; - public InvoiceOutWindowViewModel(IDialogService DialogService,SqlSugarScope sqlSugarScope) + //private SqlSugarScope SqlSugarHelper.Db; + public InvoiceOutWindowViewModel(IDialogService DialogService) { _dialogService = DialogService; - this._sqlSugarScope1= sqlSugarScope; + //this.SqlSugarHelper.Db= sqlSugarScope; } public static List StaticOrderTakeSelects = new() @@ -163,7 +163,6 @@ namespace DM_Weight.ViewModels public List Invoices { get { return _invoices; } set { SetProperty(ref _invoices, value); } } - public bool KeepAlive => false; public async void OpenOrderDialog() { @@ -186,6 +185,8 @@ namespace DM_Weight.ViewModels }); } + public bool KeepAlive => true; + private void DoDialogResult(IDialogResult dialogResult) { // 委托 被动执行 被子窗口执行 @@ -232,7 +233,7 @@ namespace DM_Weight.ViewModels } sb.Append(" group by i.invoice_no"); sb.Append(" order by i.invoice_date "); - Invoices = _sqlSugarScope1.SqlQueryable(sb.ToString()) + Invoices = SqlSugarHelper.Db.SqlQueryable(sb.ToString()) .AddParameters(new { Status = 0, diff --git a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs index bef77cb..b3b19f7 100644 --- a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs @@ -38,13 +38,13 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IEventAggregator _eventAggregator; IDialogService _dialogService; - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public InvoiceTakeDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService DialogService, SqlSugarScope sqlSugarScope) { _dialogService = DialogService; _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) @@ -171,9 +171,9 @@ namespace DM_Weight.ViewModels public void RequestData() { - invoices = _sqlSugarScope1.Queryable() + invoices = SqlSugarHelper.Db.Queryable() .Includes(i => i.DrugInfo) - .InnerJoin(_sqlSugarScope1.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs =>cs.DrugId),(i,t) => i.DrugId == t.DrugId) + .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs =>cs.DrugId),(i,t) => i.DrugId == t.DrugId) .Where(i => i.InvoiceNo == Invoice.InvoiceNo) .ToList(); @@ -183,8 +183,9 @@ namespace DM_Weight.ViewModels { InOutInvoice invoice = invoices[i]; - List HasQChannels = _sqlSugarScope1.Queryable() + List HasQChannels = SqlSugarHelper.Db.Queryable() .Includes(cs => cs.DrugInfo) + .InnerJoin((cs, cl) => cs.Chnguid == cl.Id && cs.DrugId == cl.DrugId) .Where(cs => cs.Quantity > 0) .Where(cs => cs.DrawerType == 1) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) @@ -298,9 +299,9 @@ namespace DM_Weight.ViewModels if (record.Count > 0) { string InvoiceId = Invoice.InvoiceNo; - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { - _sqlSugarScope1.Updateable(new InOutInvoice() + SqlSugarHelper.Db.Updateable(new InOutInvoice() { Status = 1, InvoiceNo = Invoice.InvoiceNo @@ -310,7 +311,7 @@ namespace DM_Weight.ViewModels { ChannelStock it = record[i]; // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + SqlSugarHelper.Db.Updateable(new ChannelStock() { Quantity = it.Quantity - it.TakeQuantity, ManuNo = it.ManuNo, @@ -318,14 +319,14 @@ namespace DM_Weight.ViewModels Id = it.Id, }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + 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(); // 保存数据 出库记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = it.MachineId, DrawerNo = it.DrawerNo, @@ -340,7 +341,9 @@ namespace DM_Weight.ViewModels Type = 2, InvoiceId = InvoiceId, StockQuantity = nowChannels.Sum(it => it.Quantity), - ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity), + SupplierDept = Invoice.PharmacyName1 ?? ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = Invoice.PharmacyName2 ?? ConfigurationManager.AppSettings["receiveDept"].ToString() }).ExecuteCommand(); } return true; @@ -348,13 +351,25 @@ namespace DM_Weight.ViewModels if (f.Data) { // 更新屏显库存 - List singleChannels = record.FindAll(it => it.BoardType != 1); + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = record.Where(it => it.BoardType != 1) + .GroupBy(it => it.ColNo) + .Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(itx => itx.Quantity); + ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList(); if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) { - singleChannels.ForEach(it => - { - _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity); - }); + //将库位多批次的总库存数更新标签 + _portUtil.WriteQuantity(singleChannels[0].DrawerNo, singleChannels[0].ColNo, singleChannels.Sum(it => it.Quantity) - singleChannels.Sum(it => it.AddQuantity)); + + //singleChannels.ForEach(it => + //{ + // _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity); + //}); } AlertMsg alertMsg = new AlertMsg { @@ -423,6 +438,6 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => false; + public bool KeepAlive => true; } } diff --git a/DM_Weight/ViewModels/LoginWindowViewModel.cs b/DM_Weight/ViewModels/LoginWindowViewModel.cs index b828389..048a019 100644 --- a/DM_Weight/ViewModels/LoginWindowViewModel.cs +++ b/DM_Weight/ViewModels/LoginWindowViewModel.cs @@ -25,6 +25,7 @@ using Microsoft.Win32; using System.Xml; using System.Diagnostics; using SqlSugar; +using DM_Weight.Services; namespace DM_Weight.ViewModels { @@ -62,8 +63,11 @@ namespace DM_Weight.ViewModels public string Username { get { return username; } set { SetProperty(ref username, value); } } - public UserList Operator { get; set; } - public UserList Reviewer { get; set; } + private UserList _operator; + public UserList Operator { get=> _operator; set=> SetProperty(ref _operator,value); } + + private UserList _reviewer; + public UserList Reviewer { get=> _reviewer; set=>SetProperty(ref _reviewer,value); } public bool DrawerPortMsg { @@ -81,7 +85,7 @@ namespace DM_Weight.ViewModels get => _fingerMsg; set => SetProperty(ref _fingerMsg, value); } - private SqlSugarScope _sqlSugarScope1; + ////private SqlSugarScope SqlSugarHelper.Db; //public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil, FingerprintUtil fingerprintUtil) //{ // _fingerprintUtil = fingerprintUtil; @@ -89,13 +93,13 @@ namespace DM_Weight.ViewModels // _regionManager = regionManager; // _eventAggregator = eventAggregator; //} - public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil,SqlSugarScope sqlSugarScope) + public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil, FingerprintUtil fingerprintUtil) { - //_fingerprintUtil = fingerprintUtil; + _fingerprintUtil = fingerprintUtil; _portUtil = portUtil; _regionManager = regionManager; _eventAggregator = eventAggregator; - _sqlSugarScope1= sqlSugarScope; + //SqlSugarHelper.Db = sqlSugarScope; } private DelegateCommand? _loginCommand; @@ -109,7 +113,7 @@ _exitCommand ??= new DelegateCommand(Exit); public bool KeepAlive => false; - void Login() + void Login() { LoginBtnEnable = false; if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) @@ -142,15 +146,15 @@ _exitCommand ??= new DelegateCommand(Exit); } else { - //UserList userList = _sqlSugarScope1.Queryable() + UserList userList = SqlSugarHelper.Db.Queryable() - // .Includes(u => u.Role) - // .First(u => u.UserName == username && ConfigurationManager.AppSettings["machineId"].ToString().Equals(u.MachineId)); - - UserList userList = _sqlSugarScope1.Queryable() .Includes(u => u.Role) - .InnerJoin((u,r) => u.RoleId==r.Id) - .First(u => u.UserName == username && ConfigurationManager.AppSettings["machineId"].ToString().Equals(u.MachineId)); + .First(u => u.UserName == username && ConfigurationManager.AppSettings["machineId"].ToString().Equals(u.MachineId)); + + //UserList userList = SqlSugarHelper.Db.Queryable() + // .Includes(u => u.Role) + // .InnerJoin((u, r) => u.RoleId == r.Id) + // .First(u => u.UserName == username && ConfigurationManager.AppSettings["machineId"].ToString().Equals(u.MachineId)); if (userList == null) { @@ -213,17 +217,21 @@ _exitCommand ??= new DelegateCommand(Exit); // 单人登录模式 if (SingleLogin) { + logger.Info($"SetUser:单人登录模式"); App.CurrentFaUserList = user; //添加参数,键值对格式 keys.Add("operator", user); System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { + logger.Info($"SetUser:单人登录模式,页面跳转"); _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); })); } // 双人登录模式 else { + + logger.Info($"SetUser:双人登录模式"); // 如果已经录入了发药人,已经有一个用户登录 if (keys.ContainsKey("operator")) { @@ -231,11 +239,13 @@ _exitCommand ??= new DelegateCommand(Exit); { keys.Add("reviewer", user); Reviewer = user; + logger.Info($"Reviewer:{Reviewer.Nickname}"); RaisePropertyChanged("Reviewer"); - App.CurrentShenUserList= user; + App.CurrentShenUserList = user; //_regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { + logger.Info($"SetUser:双人登录模式,页面跳转"); _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); })); } @@ -256,13 +266,16 @@ _exitCommand ??= new DelegateCommand(Exit); { keys.Add("operator", user); Operator = user; + logger.Info($"Operator:{Operator.Nickname}"); RaisePropertyChanged("Operator"); - App.CurrentFaUserList= user; + App.CurrentFaUserList = user; //_regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); - System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => - { - _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); - })); + System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => + { + + logger.Info($"SetUser:双人登录模式,页面跳转"); + _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); + })); } else @@ -284,17 +297,21 @@ _exitCommand ??= new DelegateCommand(Exit); Operator = user; RaisePropertyChanged("Operator"); App.CurrentFaUserList = user; + + logger.Info($"SetUser:双人登录模式,user:{user.Nickname};Operator{Operator.Nickname}"); } else { keys.Add("reviewer", user); Reviewer = user; + logger.Info($"SetUser:双人登录模式,user:{user.Nickname};Reviewer{Reviewer.Nickname}"); RaisePropertyChanged("Reviewer"); App.CurrentShenUserList = user; } Username = string.Empty; - Password =string.Empty; + Password = string.Empty; } + logger.Info($"SetUser:双人登录模式,user:{user.Nickname};Operator{Operator?.Nickname};Reviewer{Reviewer?.Nickname}"); } } @@ -308,49 +325,61 @@ _exitCommand ??= new DelegateCommand(Exit); void LoginEvent(FingerprintMsg msg) { - logger.Info(msg.ToString()); - if (msg.Message.Equals("CONNECT")) + try { - FingerMsg = !msg.Result; - } - if (LoginBtnEnable) - { - if (msg.Message.Equals("LOGIN")) + + logger.Info(msg.ToString()); + if (msg.Message.Equals("CONNECT")) { - UserList userList = _sqlSugarScope1.Queryable() + FingerMsg = !msg.Result; + } + logger.Info($"LoginBtnEnable:{LoginBtnEnable}"); + if (LoginBtnEnable) + { + logger.Info($"msg.Message.Equals:{msg.Message}"); + if (msg.Message.Equals("LOGIN")) + { + UserList userList = SqlSugarHelper.Db.Queryable() + .Includes(u => u.Role) + .First(u => u.Id == msg.Id); - .Includes(u => u.Role) - .First(u => u.Id == msg.Id); + //UserList userList = new UserService().CheckUserByFingerPrinter(msg.Id); - if (userList == null) - { - AlertMsg alertMsg = new AlertMsg + logger.Info($"userList是空?{userList == null}"); + if (userList == null) { - Message = "无此用户", - Type = MsgType.ERROR - }; - _eventAggregator.GetEvent().Publish(alertMsg); - Username = ""; - Password = ""; - } - else if (userList.Role == null) - { - AlertMsg alertMsg = new AlertMsg + AlertMsg alertMsg = new AlertMsg + { + Message = "无此用户", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Username = ""; + Password = ""; + } + else if (userList.Role == null) { - Message = "用户还未设置权限,请联系管理员", - Type = MsgType.ERROR - }; - _eventAggregator.GetEvent().Publish(alertMsg); - Username = ""; - Password = ""; - } - else - { - SetUser(userList); + AlertMsg alertMsg = new AlertMsg + { + Message = "用户还未设置权限,请联系管理员", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + Username = ""; + Password = ""; + } + else + { + SetUser(userList); + } } } - } + } + catch (Exception e) + { + logger.Info($"LoginEvent存在异常:{e.Message}"); + } } //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 @@ -364,7 +393,7 @@ _exitCommand ??= new DelegateCommand(Exit); //接收导航传过来的参数 现在是在此处初始化了表格数据 public void OnNavigatedTo(NavigationContext navigationContext) { - FingerMsg = false;// !_fingerprintUtil.bIsConnected; + FingerMsg = !_fingerprintUtil.bIsConnected;//false; _eventAggregator.GetEvent().Subscribe(LoginEvent); } diff --git a/DM_Weight/ViewModels/MachineRecordWindowViewModel.cs b/DM_Weight/ViewModels/MachineRecordWindowViewModel.cs index f04b9bc..2169348 100644 --- a/DM_Weight/ViewModels/MachineRecordWindowViewModel.cs +++ b/DM_Weight/ViewModels/MachineRecordWindowViewModel.cs @@ -20,6 +20,8 @@ using System.Configuration; using System.Reflection.PortableExecutable; using DM_Weight.msg; using Prism.Events; +using Prism.Services.Dialogs; +using System.Threading.Channels; namespace DM_Weight.ViewModels { @@ -143,17 +145,24 @@ namespace DM_Weight.ViewModels get { return machineRecords; } set { SetProperty(ref machineRecords, value); } } + + //盘点记录 导出账册 选中的数据 + private List? selectMachineRecords; + public List? SelectMachineRecords + { + get => selectMachineRecords; + set { SetProperty(ref selectMachineRecords, value);} + } + public List? OldInvoiceIdLst = new List(); - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public MachineRecordWindowViewModel(IEventAggregator eventAggregator, SqlSugarScope sqlSugarScope) { vm = this; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } - public bool KeepAlive => false; - public DelegateCommand Query { @@ -167,18 +176,27 @@ namespace DM_Weight.ViewModels { get => new DelegateCommand(() => { - GridReportUtil.PrintReportMechineRecord(Type, StartDate, EndDate); - + //if (Type == 4) + //{ + // if (SelectMachineRecords != null && SelectMachineRecords.Count > 0) + // { + // GridReportUtil.PrintReportMechineRecordForSelect(SelectMachineRecords); + // } + //} + //else + { + GridReportUtil.PrintReportMechineRecord(Type, StartDate, EndDate); + } }); } - public DelegateCommand DownloadAccountBook - { - get => new DelegateCommand(() => - { - GridReportUtil.PrintReportAccountBook(StartDate, EndDate, DrugInfo == null ? "" : DrugInfo.DrugId); + //public DelegateCommand DownloadAccountBook + //{ + // get => new DelegateCommand(() => + // { + // GridReportUtil.PrintReportAccountBook(StartDate, EndDate, DrugInfo == null ? "" : DrugInfo.DrugId); - }); - } + // }); + //} public DelegateCommand SaveCommand { @@ -190,14 +208,14 @@ namespace DM_Weight.ViewModels } private void UpdatPZHSave() { - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { for (int i = 0; i < MachineRecords.Count; i++) { - string oldInvoiceId = OldInvoiceIdLst[i]; + string oldInvoiceId = OldInvoiceIdLst[i]; // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new MachineRecord() + SqlSugarHelper.Db.Updateable(new MachineRecord() { Id = MachineRecords[i].Id, InvoiceId = MachineRecords[i].InvoiceId @@ -254,7 +272,7 @@ namespace DM_Weight.ViewModels { int totalCount = 0; string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; - MachineRecords = _sqlSugarScope1.Queryable() + MachineRecords = SqlSugarHelper.Db.Queryable() .Includes(mr => mr.DrugInfo) .Includes(mr => mr.User) .Where(mr => mr.MachineId == machineId) @@ -285,7 +303,7 @@ namespace DM_Weight.ViewModels private void GetAllDrugInfos() { string str = "SELECT d.drug_id,d.py_code,d.drug_barcode,d.drug_name,d.drug_brand_name,d.drug_spec,d.dosage,d.pack_unit,d.manufactory,d.max_stock,CONCAT(drug_name,' ',drug_spec)as drug_name_spec FROM `drug_info` d"; - DrugInfos = _sqlSugarScope1.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); + DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); } public void UpdateComboBoxItems(string text) @@ -294,7 +312,7 @@ namespace DM_Weight.ViewModels d.manufactory,d.max_stock,CONCAT(drug_name,' ',drug_spec)as drug_name_spec FROM `drug_info` d"; if (string.IsNullOrEmpty(text)) { - DrugInfos = _sqlSugarScope1.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); + DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); return; } if (DrugInfos != null) @@ -302,8 +320,27 @@ namespace DM_Weight.ViewModels DrugInfos.Clear(); } - DrugInfos = _sqlSugarScope1.SqlQueryable(str).Where(di => di.DrugName.Contains(text) || di.PyCode.Contains(text) || di.DrugId.Contains(text)).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); + DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).Where(di => di.DrugName.Contains(text) || di.PyCode.Contains(text) || di.DrugId.Contains(text)).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); } + public DelegateCommand RowSelected + { + get => new DelegateCommand(() => + { + if (MachineRecords != null) + { + SelectMachineRecords = MachineRecords.Select(x => + { + x.IsSelected = !x.IsSelected; + return x; + }).ToList(); + + + } + }); + } + + public bool KeepAlive => true; } } + diff --git a/DM_Weight/ViewModels/MainWindowViewModel.cs b/DM_Weight/ViewModels/MainWindowViewModel.cs index 83fa8c0..6c13274 100644 --- a/DM_Weight/ViewModels/MainWindowViewModel.cs +++ b/DM_Weight/ViewModels/MainWindowViewModel.cs @@ -62,33 +62,30 @@ namespace DM_Weight.ViewModels // this.eventAggregator.GetEvent().Subscribe(doMyPrismEvent2); // _screenUtil = screenUtil; //} - private FingerprintUtil _fingerprintUtil; IRegionManager _regionManager; IUnityContainer _container; PortUtil _portUtil; private List _channelStocks = new List(); - private SqlSugarScope _sqlSugarScope1; - public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil, ScreenUtil screenUtil, PortUtil portUtil,SqlSugarScope sqlSugarScope) + //private SqlSugarScope SqlSugarHelper.Db; + public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, ScreenUtil screenUtil, PortUtil portUtil) { //_portUtil = portUtil; this.eventAggregator = eventAggregator; this.eventAggregator.GetEvent().Subscribe(doMyPrismEvent2); _screenUtil = screenUtil; - _fingerprintUtil = fingerprintUtil; _regionManager = regionManager; _container = container; _portUtil = portUtil; - this._sqlSugarScope1=sqlSugarScope; + //this.SqlSugarHelper.Db=sqlSugarScope; System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { - _container.RegisterType("LoginWindow"); _regionManager.RequestNavigate("MainRegion", "LoginWindow"); })); - Task.Factory.StartNew(()=>BindStock()); + Task.Factory.StartNew(() => BindStock()); } void doMyPrismEvent2(AlertMsg msg) @@ -96,13 +93,13 @@ namespace DM_Weight.ViewModels switch (msg.Type) { case MsgType.INFO: - this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676")); + Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676")); break; case MsgType.ERROR: - this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); break; default: - this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676")); + Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676")); break; } SnackbarMessageQueue.Enqueue(msg.Message); @@ -110,8 +107,13 @@ namespace DM_Weight.ViewModels //写标签数量 async Task BindStock() { - List singleChannels = _sqlSugarScope1.Queryable().Where(cs => cs.BoardType == 5).Where(cs => cs.DrugId !=null).ToList(); - + List singleChannels = SqlSugarHelper.Db.Queryable().Where(cs => cs.BoardType == 5&&cs.Quantity>0).Where(cs => cs.DrugId !=null).ToList(); + singleChannels = singleChannels.GroupBy(cs => new { cs.DrawerNo, cs.ColNo }) + .Select(cs => { + var ret = cs.First(); + ret.Quantity = cs.Sum(xt => xt.Quantity); + return ret; + }).ToList(); for (int i = 0; i < singleChannels.Count; i++) { _portUtil.WriteQuantity(singleChannels[i].DrawerNo, singleChannels[i].ColNo, singleChannels[i].Quantity); diff --git a/DM_Weight/ViewModels/MaskDialogViewModel.cs b/DM_Weight/ViewModels/MaskDialogViewModel.cs new file mode 100644 index 0000000..2acfedb --- /dev/null +++ b/DM_Weight/ViewModels/MaskDialogViewModel.cs @@ -0,0 +1,33 @@ +using Prism.Mvvm; +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 MaskDialogViewModel : BindableBase, IDialogAware + { + public string Title => throw new NotImplementedException(); + + public event Action RequestClose; + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + + } + + public void OnDialogOpened(IDialogParameters parameters) + { + + + } + } +} diff --git a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs index 4968c1a..6472456 100644 --- a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs @@ -38,13 +38,13 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IEventAggregator _eventAggregator; IDialogService _dialogService; - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public OrderReturnDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService DialogService, SqlSugarScope sqlSugarScope) { _dialogService = DialogService; _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) @@ -172,9 +172,9 @@ namespace DM_Weight.ViewModels public void RequestData() { - orderDetails = _sqlSugarScope1.Queryable() + orderDetails = SqlSugarHelper.Db.Queryable() .Includes(od => od.DrugInfo) - .InnerJoin(_sqlSugarScope1.Queryable().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().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.OrderNo == OrderInfo.OrderNo) .ToList(); @@ -184,7 +184,7 @@ namespace DM_Weight.ViewModels { OrderDetail orderDetail = orderDetails[i]; - List HasQChannels = _sqlSugarScope1.Queryable() + List HasQChannels = SqlSugarHelper.Db.Queryable() .Includes(cs => cs.DrugInfo) .Where(cs => cs.DrawerType == 1) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) @@ -266,7 +266,17 @@ namespace DM_Weight.ViewModels _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); + List singleChannels = channelStocks + .GroupBy(it => new { it.DrawerNo, it.ColNo }) + .Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(it => it.Quantity); + ret.TakeQuantity = it.Sum(it => it.TakeQuantity); + return ret; + }) + .ToList() + .FindAll(it => it.BoardType != 1); // 发送还药数量 singleChannels.ForEach(it => @@ -295,9 +305,9 @@ namespace DM_Weight.ViewModels //if (record.Count > 0) //{ string InvoiceId = OrderInfo.OrderNo; - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { - _sqlSugarScope1.Updateable(new OrderInfo() + SqlSugarHelper.Db.Updateable(new OrderInfo() { DmStatus = 2, OrderNo = OrderInfo.OrderNo @@ -306,7 +316,7 @@ namespace DM_Weight.ViewModels { ChannelStock it = record[i]; // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + SqlSugarHelper.Db.Updateable(new ChannelStock() { //Quantity = it.Quantity + it.TakeQuantity, Quantity = it.Quantity + it.ReturnQuantity, @@ -315,14 +325,14 @@ namespace DM_Weight.ViewModels Id = it.Id, }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + 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(); // 保存数据 还药记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = it.MachineId, DrawerNo = it.DrawerNo, @@ -346,14 +356,41 @@ namespace DM_Weight.ViewModels if (f.Data) { // 更新屏显库存 - List singleChannels = record.FindAll(it => it.BoardType != 1); - if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = record.Where(it => it.BoardType != 1) + .GroupBy(it => new { it.DrawerNo, it.ColNo }) + .Select(it => + { + var ret = it.First(); + //ret.Quantity = it.Sum(itx => itx.Quantity); + //ret.TakeQuantity = it.Sum(itx => itx.TakeQuantity); + return ret; + }).ToList(); + //if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + //{ + //将库位多批次的总库存数更新标签 + //singleChannels.ForEach(it => + //{ + // _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.TakeQuantity); + //}); + //} + if (singleChannels.Count > 0) { - singleChannels.ForEach(it => + for (int i = 0; i < singleChannels.Count; i++) { - _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.TakeQuantity); - }); + if (singleChannels[i].BoardType == 5) + { + int totalQuantity = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId == singleChannels[i].MachineId) + .Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo) + .Where(cs => cs.ColNo == singleChannels[i].ColNo) + .Sum(it => it.Quantity); + //将库位多批次的总库存数更新标签 + _portUtil.WriteQuantity(singleChannels[i].DrawerNo, singleChannels[i].ColNo, totalQuantity); + } + } } + AlertMsg alertMsg = new AlertMsg { Message = "处方退药完成,库存已更新", @@ -412,6 +449,6 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => false; + public bool KeepAlive => true; } } diff --git a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs index 3753ba0..212041b 100644 --- a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs @@ -38,13 +38,13 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IEventAggregator _eventAggregator; IDialogService _dialogService; - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public OrderTakeDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService DialogService, SqlSugarScope sqlSugarScope) { _dialogService = DialogService; _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) @@ -79,15 +79,15 @@ namespace DM_Weight.ViewModels { channelStocks.ForEach(it => it.process = 3); } - IGrouping groupingBefore = enumerator.Current; - int DrawerNoBefore = groupingBefore.Key; + //IGrouping groupingBefore = enumerator.Current; + //int DrawerNoBefore = groupingBefore.Key; if (enumerator.MoveNext()) { - IGrouping groupingAfter = enumerator.Current; - int DrawerNoAfter = groupingAfter.Key; - if (DrawerNoBefore < 9 && DrawerNoAfter > 8) + //IGrouping groupingAfter = enumerator.Current; + //int DrawerNoAfter = groupingAfter.Key; + //if (DrawerNoBefore < 9 && DrawerNoAfter > 8) { - Thread.Sleep(50); + Thread.Sleep(80); } OpenOneByOne(); } @@ -171,9 +171,9 @@ namespace DM_Weight.ViewModels public void RequestData() { - orderDetails = _sqlSugarScope1.Queryable() + orderDetails = SqlSugarHelper.Db.Queryable() .Includes(od => od.DrugInfo) - .InnerJoin(_sqlSugarScope1.Queryable().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().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.OrderNo == OrderInfo.OrderNo) .ToList(); @@ -183,8 +183,9 @@ namespace DM_Weight.ViewModels { OrderDetail orderDetail = orderDetails[i]; - List HasQChannels = _sqlSugarScope1.Queryable() + List HasQChannels = SqlSugarHelper.Db.Queryable() .Includes(cs => cs.DrugInfo) + .InnerJoin((cs, cl) => cs.Chnguid == cl.Id && cs.DrugId == cl.DrugId) .Where(cs => cs.Quantity > 0) .Where(cs => cs.DrawerType == 1) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) @@ -193,6 +194,7 @@ namespace DM_Weight.ViewModels .Where(cs => cs.DrugId == orderDetail.DrugId) .OrderBy(cs => cs.EffDate) .OrderBy(cs => cs.DrawerNo) + .OrderBy(cs=> cs.ManuNo) .ToList(); int total = HasQChannels.Sum(it => it.Quantity); int TakeQ = orderDetail.Quantity; @@ -269,7 +271,18 @@ namespace DM_Weight.ViewModels channelStocks.ForEach(it => it.process = 1); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); + //List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); + List singleChannels = channelStocks + .GroupBy(it => new { it.DrawerNo, it.ColNo }) + .Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(it => it.Quantity); + ret.TakeQuantity = it.Sum(it => it.TakeQuantity); + return ret; + }) + .ToList() + .FindAll(it => it.BoardType != 1); // 发送取药数量 singleChannels.ForEach(it => @@ -291,8 +304,8 @@ namespace DM_Weight.ViewModels }); _portUtil.WindowName = "OrderTakeDrugWindow"; _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; - _portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray(); - _portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); + _portUtil.ColNos = new int[] { };// singleChannels.Select(it => it.ColNo).ToArray(); + //_portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); _portUtil.DrawerNo = DrawerNo; _portUtil.Start(); } @@ -310,15 +323,15 @@ namespace DM_Weight.ViewModels if (record.Count > 0) { string InvoiceId = OrderInfo.OrderNo; - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { - _sqlSugarScope1.Updateable(new OrderInfo() + SqlSugarHelper.Db.Updateable(new OrderInfo() { DmStatus = 1, OrderNo = OrderInfo.OrderNo }).UpdateColumns(it => new { it.DmStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand(); - _sqlSugarScope1.Insertable(new OrderFinish() + SqlSugarHelper.Db.Insertable(new OrderFinish() { OrderNo = OrderInfo.OrderNo, PatientId = OrderInfo.PatientId, @@ -331,7 +344,7 @@ namespace DM_Weight.ViewModels { ChannelStock it = record[i]; // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + SqlSugarHelper.Db.Updateable(new ChannelStock() { Quantity = it.Quantity - it.TakeQuantity, ManuNo = it.ManuNo, @@ -339,14 +352,14 @@ namespace DM_Weight.ViewModels Id = it.Id, }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + 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(); // 保存数据 出库记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = it.MachineId, DrawerNo = it.DrawerNo, @@ -361,7 +374,9 @@ namespace DM_Weight.ViewModels Type = 2, InvoiceId = InvoiceId, StockQuantity = nowChannels.Sum(it => it.Quantity), - ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity), + SupplierDept = ConfigurationManager.AppSettings["receiveDept"].ToString(), + ReceiveDept = OrderInfo.DeptName }).ExecuteCommand(); } return true; @@ -369,13 +384,38 @@ namespace DM_Weight.ViewModels if (f.Data) { // 更新屏显库存 - List singleChannels = record.FindAll(it => it.BoardType != 1); - if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = record.Where(it => it.BoardType != 1) + .GroupBy(it => it.ColNo) + .Select(it => + { + var ret = it.First(); + //ret.Quantity = it.Sum(itx => itx.Quantity); + //ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList(); + //if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + //{ + //singleChannels.ForEach(it => + //{ + // _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity); + //}); + //} + if(singleChannels.Count > 0) { - singleChannels.ForEach(it => + for (int i = 0; i < singleChannels.Count; i++) { - _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity); - }); + if (singleChannels[i].BoardType == 5) + { + int totalQuantity = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId == singleChannels[i].MachineId) + .Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo) + .Where(cs => cs.ColNo == singleChannels[i].ColNo) + .Sum(it => it.Quantity); + //将库位多批次的总库存数更新标签 + _portUtil.WriteQuantity(singleChannels[i].DrawerNo, singleChannels[i].ColNo, totalQuantity); + } + } } AlertMsg alertMsg = new AlertMsg { @@ -445,6 +485,6 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => false; + public bool KeepAlive => true; } } diff --git a/DM_Weight/ViewModels/OrderTakeDrugWindowViewModel.cs b/DM_Weight/ViewModels/OrderTakeDrugWindowViewModel.cs index c3fcd7f..52f36f0 100644 --- a/DM_Weight/ViewModels/OrderTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/OrderTakeDrugWindowViewModel.cs @@ -16,6 +16,10 @@ using DM_Weight.util; using DM_Weight.msg; using Prism.Events; using SqlSugar; +using System.Threading; +using System.Timers; +using log4net.Repository.Hierarchy; +using log4net; namespace DM_Weight.ViewModels { @@ -70,12 +74,15 @@ namespace DM_Weight.ViewModels private DelegateCommand _rowSelected; public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(OpenOrderDialog); - private SqlSugarScope _sqlSugarScope1; - public OrderTakeDrugWindowViewModel(IDialogService DialogService, IEventAggregator eventAggregator,SqlSugarScope sqlSugarScope) + //private SqlSugarScope SqlSugarHelper.Db; + private readonly ILog logger = LogManager.GetLogger(typeof(OrderTakeDrugWindowViewModel)); + public OrderTakeDrugWindowViewModel(IDialogService DialogService, IEventAggregator eventAggregator) { + + logger.Info("进入OrderTakeDrugWindowViewModel构造函数"); _dialogService = DialogService; _eventAggregator = eventAggregator; - this._sqlSugarScope1= sqlSugarScope; + //this.SqlSugarHelper.Db= sqlSugarScope; } public static List StaticOrderTakeSelects = new() @@ -168,31 +175,30 @@ namespace DM_Weight.ViewModels public List OrderInfos { get { return _orderInfos; } set { SetProperty(ref _orderInfos, value); } } - public bool KeepAlive => false; public async void OpenOrderDialog() { if (SelectedOrder != null && SelectedOrder.DmStatus == 0 && SelectedOrder.CancelFlag == 0 && SelectedOrder.HisDispFlag == 0) { - // 此处延时1毫秒,等待页面渲染 + // 此处延时1毫秒,等待页面渲染(规避工控机上手指点击弹出的页面上的按钮无效问题) await Task.Delay(TimeSpan.FromMilliseconds(1)); DialogParameters dialogParameters = new DialogParameters(); dialogParameters.Add("orderInfo", SelectedOrder); DialogServiceExtensions.ShowDialogHost(_dialogService, "OrderTakeDialog", dialogParameters, DoDialogResult, "RootDialog"); - + } - + } private void DoDialogResult(IDialogResult dialogResult) { // 委托 被动执行 被子窗口执行 - // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 - //if(dialogResult.Result == ButtonResult.OK) - //{ + //dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + if (dialogResult.Result == ButtonResult.OK) + { SelectedOrder = null; RequestData(); - //} + } //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); } @@ -211,13 +217,17 @@ namespace DM_Weight.ViewModels }); } + public bool KeepAlive => true; + public void RequestData() { + + logger.Info("开始OrderTakeDrugWindowViewModel_查询数据"); OrderInfos.Clear(); int totalCount = 0; - List queryData = _sqlSugarScope1.Queryable() + List queryData = SqlSugarHelper.Db.Queryable() .InnerJoin((oi, od) => oi.OrderNo == od.OrderNo) - .InnerJoin(_sqlSugarScope1.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (oi, od, t) => od.DrugId == t.DrugId) + .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (oi, od, t) => od.DrugId == t.DrugId) .WhereIF(OrderDate != null, oi => oi.RecvDate.ToString("yyyy-MM-dd") == OrderDate) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("OrderNo"), oi => oi.OrderNo == SearchValue) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PatientId"), oi => oi.PatientId == SearchValue) @@ -232,13 +242,22 @@ namespace DM_Weight.ViewModels OrderInfos = queryData; TotalCount = totalCount; PageCount = (int)Math.Ceiling((double)TotalCount / PageSize); + + logger.Info("结束OrderTakeDrugWindowViewModel_查询数据"); } //接收导航传过来的参数 现在是在此处初始化了表格数据 public void OnNavigatedTo(NavigationContext navigationContext) { + + logger.Info("进入OrderTakeDrugWindowViewModel_OnNavigatedTo"); _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); - RequestData(); + //RequestData(); + Task.Factory.StartNew(() => RequestData()); + + logger.Info("结束OrderTakeDrugWindowViewModel_OnNavigatedTo"); + //Task t = new Task(() => { RequestData(); }); + //t.Start(); } //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 diff --git a/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs index d8a22aa..86d2aef 100644 --- a/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs +++ b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs @@ -42,12 +42,12 @@ namespace DM_Weight.ViewModels get { return _machineRecord; } set { SetProperty(ref _machineRecord, value); } } - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public ReturnDrugDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, SqlSugarScope sqlSugarScope) { _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) @@ -175,7 +175,7 @@ namespace DM_Weight.ViewModels public void RequestData() { - List queryData = _sqlSugarScope1.Queryable() + List queryData = SqlSugarHelper.Db.Queryable() .Where(cs => cs.DrugId == MachineRecord.DrugId) .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) .WhereIF(MachineRecord.ManuNo != null,cs => cs.ManuNo == MachineRecord.ManuNo) @@ -229,24 +229,24 @@ namespace DM_Weight.ViewModels { IsFinishClick = true; string InvoiceId = "RETURN_" + CurrentTimeMillis(); - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + SqlSugarHelper.Db.Updateable(new ChannelStock() { Quantity = ChannelStock.Quantity + ReturnQuantity, Id = ChannelStock.Id, }).UpdateColumns(it => new { it.Quantity }).ExecuteCommand(); // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + List nowChannels = SqlSugarHelper.Db.Queryable() .Where(cs => cs.MachineId.Equals(ChannelStock.MachineId)) .Where(cs => cs.DrugId.Equals(ChannelStock.DrugId)) .Where(cs => cs.DrawerType == 1) .ToList(); // 更新数据 取药记录 设置还药数量、状态 - _sqlSugarScope1.Updateable(new MachineRecord() + SqlSugarHelper.Db.Updateable(new MachineRecord() { ReturnQuantity1 = MachineRecord.ReturnQuantity1 + ReturnQuantity, Id = MachineRecord.Id, @@ -254,7 +254,7 @@ namespace DM_Weight.ViewModels }).UpdateColumns(it => new { it.ReturnQuantity1, it.Status }).ExecuteCommand(); // 保存数据 还药记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = ChannelStock.MachineId, DrawerNo = ChannelStock.DrawerNo, @@ -279,7 +279,14 @@ namespace DM_Weight.ViewModels // 更新屏显库存 if (ChannelStock.BoardType == 5) { - _portUtil.WriteQuantity(ChannelStock.DrawerNo, ChannelStock.ColNo, ChannelStock.Quantity + ReturnQuantity); + //_portUtil.WriteQuantity(ChannelStock.DrawerNo, ChannelStock.ColNo, ChannelStock.Quantity + ReturnQuantity); + int totalQuantity = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId.Equals(ChannelStock.MachineId)) + .Where(cs => cs.DrawerNo == ChannelStock.DrawerNo) + .Where(cs => cs.ColNo == ChannelStock.ColNo) + .Sum(it => it.Quantity); + + _portUtil.WriteQuantity(ChannelStock.DrawerNo, ChannelStock.ColNo, totalQuantity); } AlertMsg alertMsg = new AlertMsg @@ -330,7 +337,7 @@ namespace DM_Weight.ViewModels }, () => Status == 0).ObservesProperty(() => Status); } - public bool KeepAlive => false; + public bool KeepAlive => true; } } diff --git a/DM_Weight/ViewModels/ReturnDrugWindow2ViewModel.cs b/DM_Weight/ViewModels/ReturnDrugWindow2ViewModel.cs index ebe6b1a..280ec39 100644 --- a/DM_Weight/ViewModels/ReturnDrugWindow2ViewModel.cs +++ b/DM_Weight/ViewModels/ReturnDrugWindow2ViewModel.cs @@ -76,11 +76,11 @@ namespace DM_Weight.ViewModels private DelegateCommand _rowSelected; public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(OpenOrderDialog); - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public ReturnDrugWindow2ViewModel(IDialogService DialogService,SqlSugarScope sqlSugarScope) { _dialogService = DialogService; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } public static List StaticOrderTakeSelects = new() @@ -177,7 +177,7 @@ namespace DM_Weight.ViewModels public List OrderInfos { get { return _orderInfos; } set { SetProperty(ref _orderInfos, value); } } - public bool KeepAlive => false; + public bool KeepAlive => true; public async void OpenOrderDialog() { @@ -216,9 +216,9 @@ namespace DM_Weight.ViewModels { OrderInfos.Clear(); int totalCount = 0; - List queryData = _sqlSugarScope1.Queryable() + List queryData = SqlSugarHelper.Db.Queryable() .InnerJoin((oi, od) => oi.OrderNo == od.OrderNo) - .InnerJoin(_sqlSugarScope1.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (oi, od, t) => od.DrugId == t.DrugId) + .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (oi, od, t) => od.DrugId == t.DrugId) .WhereIF(OrderDate != null, oi => oi.OrderDate.ToString("yyyy-MM-dd") == OrderDate) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("OrderNo"), oi => oi.OrderNo == SearchValue) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PatientId"), oi => oi.PatientId == SearchValue) @@ -238,7 +238,7 @@ namespace DM_Weight.ViewModels //接收导航传过来的参数 现在是在此处初始化了表格数据 public void OnNavigatedTo(NavigationContext navigationContext) { - RequestData(); + Task.Factory.StartNew(() => RequestData()); } //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 diff --git a/DM_Weight/ViewModels/ReturnDrugWindowViewModel.cs b/DM_Weight/ViewModels/ReturnDrugWindowViewModel.cs index 192480b..b319fa9 100644 --- a/DM_Weight/ViewModels/ReturnDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/ReturnDrugWindowViewModel.cs @@ -23,11 +23,11 @@ namespace DM_Weight.ViewModels private DelegateCommand _rowSelected; public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(OpenOrderDialog); - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public ReturnDrugWindowViewModel(IDialogService DialogService, SqlSugarScope sqlSugarScope) { _dialogService = DialogService; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } public static List StaticSelects = new() @@ -134,6 +134,7 @@ namespace DM_Weight.ViewModels public List MachineRecords { get { return _machineRecords; } set { SetProperty(ref _machineRecords, value); } } + public bool KeepAlive => true; public async void OpenOrderDialog() { @@ -162,7 +163,6 @@ namespace DM_Weight.ViewModels //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); } - public bool KeepAlive => false; //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) @@ -173,7 +173,7 @@ namespace DM_Weight.ViewModels public void RequestData() { - List queryData = _sqlSugarScope1.Queryable() + List queryData = SqlSugarHelper.Db.Queryable() .Includes(mr => mr.DrugInfo) .Includes(mr => mr.User) .Where(mr => mr.Type == 2) @@ -192,7 +192,7 @@ namespace DM_Weight.ViewModels //接收导航传过来的参数 现在是在此处初始化了表格数据 public void OnNavigatedTo(NavigationContext navigationContext) { - RequestData(); + Task.Factory.StartNew(() => RequestData()); } //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 diff --git a/DM_Weight/ViewModels/ReturnEmptyDialogViewModel.cs b/DM_Weight/ViewModels/ReturnEmptyDialogViewModel.cs index e403b9f..99e63cb 100644 --- a/DM_Weight/ViewModels/ReturnEmptyDialogViewModel.cs +++ b/DM_Weight/ViewModels/ReturnEmptyDialogViewModel.cs @@ -39,12 +39,12 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IEventAggregator _eventAggregator; - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public ReturnEmptyDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, SqlSugarScope sqlSugarScope) { _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) @@ -170,7 +170,7 @@ namespace DM_Weight.ViewModels public void RequestData() { - List queryData = _sqlSugarScope1.Queryable() + List queryData = SqlSugarHelper.Db.Queryable() .Includes(mr => mr.User) .Where(mr => mr.DrugId == ChannelStock.DrugId) .Where(mr => mr.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) @@ -247,18 +247,18 @@ namespace DM_Weight.ViewModels if (records.Count > 0 && records.Sum(it => it.Quantity - it.ReturnQuantity1) == ReturnQuantity) { string InvoiceId = "RETURN_" + CurrentTimeMillis(); - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + SqlSugarHelper.Db.Updateable(new ChannelStock() { Quantity = ChannelStock.Quantity + ReturnQuantity, Id = ChannelStock.Id, }).UpdateColumns(it => new { it.Quantity }).ExecuteCommand(); // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + List nowChannels = SqlSugarHelper.Db.Queryable() .Where(cs => cs.MachineId.Equals(ChannelStock.MachineId)) .Where(cs => cs.DrugId.Equals(ChannelStock.DrugId)) .Where(cs => cs.DrawerType == 1) @@ -268,7 +268,7 @@ namespace DM_Weight.ViewModels { MachineRecord _MachineRecord = records[i]; // 更新数据 取药记录 设置还药数量、状态 - _sqlSugarScope1.Updateable(new MachineRecord() + SqlSugarHelper.Db.Updateable(new MachineRecord() { ReturnQuantity2 = _MachineRecord.Quantity - _MachineRecord.ReturnQuantity1, Id = _MachineRecord.Id, @@ -276,7 +276,7 @@ namespace DM_Weight.ViewModels }).UpdateColumns(it => new { it.ReturnQuantity1, it.Status }).ExecuteCommand(); // 保存数据 还药空瓶记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = ChannelStock.MachineId, DrawerNo = ChannelStock.DrawerNo, @@ -371,6 +371,6 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => false; + public bool KeepAlive => true; } } diff --git a/DM_Weight/ViewModels/ReturnEmptyWindowViewModel.cs b/DM_Weight/ViewModels/ReturnEmptyWindowViewModel.cs index 390d08e..700257d 100644 --- a/DM_Weight/ViewModels/ReturnEmptyWindowViewModel.cs +++ b/DM_Weight/ViewModels/ReturnEmptyWindowViewModel.cs @@ -35,11 +35,11 @@ namespace DM_Weight.ViewModels } IDialogService _dialogService; - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public ReturnEmptyWindowViewModel(IDialogService dialogService, SqlSugarScope sqlSugarScope) { _dialogService = dialogService; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } public DelegateCommand RowSelected @@ -71,7 +71,6 @@ namespace DM_Weight.ViewModels //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); } - public bool KeepAlive => false; public DelegateCommand Query @@ -82,6 +81,8 @@ namespace DM_Weight.ViewModels }); } + public bool KeepAlive => true; + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) { @@ -99,7 +100,7 @@ namespace DM_Weight.ViewModels void RequestData() { - Channels = _sqlSugarScope1.Queryable() + Channels = SqlSugarHelper.Db.Queryable() .LeftJoin((cs,di) => cs.DrugId == di.DrugId.ToString()) .Where((cs) => cs.DrawerType != 1) .Select((cs, di) => new ChannelStock{ diff --git a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs index 1346955..e5f59da 100644 --- a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs +++ b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs @@ -30,11 +30,11 @@ namespace DM_Weight.ViewModels get { return _roleList; } set { SetProperty(ref _roleList, value); } } - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public RoleManagerWindowViewModel(SqlSugarScope sqlSugarScope) { //_allPremissions = Clone(defaultAll); - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } public static ObservableCollection Clone(object List) @@ -214,17 +214,23 @@ namespace DM_Weight.ViewModels PremissionImage = "/Images/TbJiay.png", }; ObservableCollection jiayaoChild = new ObservableCollection(); - PremissionDm jiayao1 = new PremissionDm + PremissionDm jiayao2 = new PremissionDm { Id = 21, PremissionName = "自选加药", PremissionPath = "SelfAddWindow", }; - PremissionDm jiayao2 = new PremissionDm + //PremissionDm jiayao2 = new PremissionDm + //{ + // Id = 22, + // PremissionName = "调拨入库", + // PremissionPath = "InvoiceInWindow", + //}; + PremissionDm jiayao1 = new PremissionDm { Id = 22, PremissionName = "调拨入库", - PremissionPath = "InvoiceInWindow", + PremissionPath = "InvoiceInNewWindow", }; PremissionDm jiayao3 = new PremissionDm { @@ -234,13 +240,20 @@ namespace DM_Weight.ViewModels }; PremissionDm jiayao4 = new PremissionDm { - Id = 24, + Id = 25, PremissionName = "加药记录", PremissionPath = "AddRecordWindow", }; + PremissionDm jiayao5 = new PremissionDm + { + Id = 24, + PremissionName = "多批次抽屉加药", + PremissionPath = "AddDrugControl", + }; jiayaoChild.Add(jiayao1); jiayaoChild.Add(jiayao2); jiayaoChild.Add(jiayao3); + jiayaoChild.Add(jiayao5); jiayaoChild.Add(jiayao4); jiayao.Children = jiayaoChild; defaultAll.Add(jiayao); @@ -301,13 +314,20 @@ namespace DM_Weight.ViewModels { Id = 42, PremissionName = "库存盘点", - PremissionPath = "CheckStockWindow", + PremissionPath = "CheckStockNewWindow",// "CheckStockWindow", }; + //PremissionDm kuguan3 = new PremissionDm + //{ + // Id = 43, + // PremissionName = "盘点记录", + // PremissionPath = "CheckRecordWindow", + //}; + PremissionDm kuguan3 = new PremissionDm { Id = 43, PremissionName = "盘点记录", - PremissionPath = "CheckRecordWindow", + PremissionPath = "CheckRecordNewWindow", }; PremissionDm kuguan4 = new PremissionDm { @@ -321,11 +341,25 @@ namespace DM_Weight.ViewModels PremissionName = "交接班记录", PremissionPath = "ChangeShiftsListWindow", }; + PremissionDm kuguan6 = new PremissionDm + { + Id = 46, + PremissionName = "账册", + PremissionPath = "AccountWindow", + }; + //PremissionDm kuguan7 = new PremissionDm + //{ + // Id = 47, + // PremissionName = "库存盘点", + // PremissionPath = "CheckStockNew2Window", + //}; kuguanChild.Add(kuguan1); kuguanChild.Add(kuguan2); kuguanChild.Add(kuguan3); kuguanChild.Add(kuguan4); kuguanChild.Add(kuguan5); + kuguanChild.Add(kuguan6); + //kuguanChild.Add(kuguan7); kuguan.Children = kuguanChild; defaultAll.Add(kuguan); #endregion @@ -400,7 +434,6 @@ namespace DM_Weight.ViewModels set => SetProperty(ref _rightPremission, value); } - public bool KeepAlive => false; public T DeepCopyByReflect(T obj) { @@ -664,14 +697,14 @@ namespace DM_Weight.ViewModels Role.Id = 0; Role.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; Role.Permissions = RightPremissions.ToList(); - List roleList = _sqlSugarScope1.Queryable().Where(r => r.RoleName == Role.RoleName).ToList(); + List roleList = SqlSugarHelper.Db.Queryable().Where(r => r.RoleName == Role.RoleName).ToList(); if(roleList.Count>0) { SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); SnackbarMessageQueue.Enqueue("该角色已存在!"); return; } - _sqlSugarScope1.Insertable(Role).ExecuteCommand(); + SqlSugarHelper.Db.Insertable(Role).ExecuteCommand(); RequestData(); }); } @@ -681,11 +714,13 @@ namespace DM_Weight.ViewModels get => new DelegateCommand(() => { Role.Permissions = RightPremissions.ToList(); - _sqlSugarScope1.Updateable(Role).ExecuteCommand(); + SqlSugarHelper.Db.Updateable(Role).ExecuteCommand(); RequestData(); }); } + public bool KeepAlive => true; + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) { @@ -704,7 +739,7 @@ namespace DM_Weight.ViewModels void RequestData() { - RoleList = _sqlSugarScope1.Queryable() + RoleList = SqlSugarHelper.Db.Queryable() .Where(di => di.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) .WhereIF(!String.IsNullOrEmpty(SearchValue), (di) => di.RoleName.Contains(SearchValue??"")) .Select(r => r) diff --git a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs index c9d6ea4..a8c6354 100644 --- a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs @@ -19,6 +19,7 @@ using DM_Weight.util; using DM_Weight.Views; using System.Threading; using SqlSugar; +using System.Configuration; namespace DM_Weight.ViewModels { @@ -41,12 +42,12 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IEventAggregator _eventAggregator; - private SqlSugarScope _sqlSugarScope1; - public SelfAddDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, SqlSugarScope sqlSugarScope) + ////private SqlSugarScope SqlSugarHelper.Db; + public SelfAddDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator) { _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + ////this.SqlSugarHelper.Db = sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) @@ -192,7 +193,18 @@ namespace DM_Weight.ViewModels _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); + List singleChannels = channelStocks + .GroupBy(it => new { + it.DrawerNo, it.ColNo + }) + .Select(it => { + var ret = it.First(); + ret.Quantity = it.Sum(it => it.Quantity); + ret.AddQuantity = it.Sum(it => it.AddQuantity); + return ret; + }) + .ToList() + .FindAll(it => it.BoardType != 1); _portUtil.WindowName = WindowName; _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; @@ -202,6 +214,18 @@ namespace DM_Weight.ViewModels if((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) { + //List ChannelLst = channelStocks.Where(it => it.BoardType != 1) + // .GroupBy(it => it.ColNo) + // .Select(it => + // { + // var ret = it.First(); + // ret.Quantity = it.Sum(itx => itx.Quantity); + // ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + // return ret; + // }).ToList(); + ////将库位多批次的总库存数更新标签 + //_portUtil.WriteQuantity(singleChannels[0].DrawerNo, singleChannels[0].ColNo, singleChannels.Sum(it => it.Quantity) + singleChannels.Sum(it => it.AddQuantity)); + // 发送加药数量 singleChannels.ForEach(it => { @@ -234,7 +258,7 @@ namespace DM_Weight.ViewModels List record = ChannelStocks.ToList(); //string InvoiceId = "SELF_" + CurrentTimeMillis(); string InvoiceId = PZH; - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { for (int i = 0; i < record.Count; i++) { @@ -244,7 +268,7 @@ namespace DM_Weight.ViewModels _portUtil.SetNumCount(it.DrawerNo, it.ColNo, it.AddQuantity); } // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + SqlSugarHelper.Db.Updateable(new ChannelStock() { Quantity = it.Quantity + it.AddQuantity, PosNo = 1, @@ -253,14 +277,14 @@ namespace DM_Weight.ViewModels Id = it.Id, }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand(); // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + 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(); // 保存数据 出/入库记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = it.MachineId, DrawerNo = it.DrawerNo, @@ -275,7 +299,9 @@ namespace DM_Weight.ViewModels Type = 1, InvoiceId = InvoiceId, StockQuantity = nowChannels.Sum(it => it.Quantity), - ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity), + SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() }).ExecuteCommand(); } return true; @@ -283,15 +309,43 @@ namespace DM_Weight.ViewModels if (f.Data) { // 更新屏显库存 - List singleChannels = record.FindAll(it => it.BoardType != 1); - if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = record.Where(it => it.BoardType != 1) + .GroupBy(it => new { it.DrawerNo,it.ColNo }) + .Select(it => + { + var ret = it.First(); + //ret.Quantity = it.Sum(itx => itx.Quantity); + //ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList(); + //if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + //{ + // //将库位多批次的总库存数更新标签 + // //_portUtil.WriteQuantity(singleChannels[0].DrawerNo, singleChannels[0].ColNo, singleChannels.Sum(it => it.Quantity) + singleChannels.Sum(it => it.AddQuantity)); + + // singleChannels.ForEach(it => + // { + // _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity); + // }); + //} + if(singleChannels!=null&& singleChannels.Count>0) { - singleChannels.ForEach(it => + for (int i = 0; i < singleChannels.Count; i++) { - _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + it.AddQuantity); - }); + if (singleChannels[i].BoardType == 5) + { + int totalQuantity = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId == singleChannels[i].MachineId) + .Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo) + .Where(cs => cs.ColNo == singleChannels[i].ColNo) + .Sum(it => it.Quantity); + //将库位多批次的总库存数更新标签 + _portUtil.WriteQuantity(singleChannels[i].DrawerNo, singleChannels[i].ColNo, totalQuantity); + } + } } - + AlertMsg alertMsg = new AlertMsg { @@ -350,6 +404,6 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => false; + public bool KeepAlive => true; } } diff --git a/DM_Weight/ViewModels/SelfAddWindowViewModel - 复制.cs b/DM_Weight/ViewModels/SelfAddWindowViewModel - 复制.cs new file mode 100644 index 0000000..f99da84 --- /dev/null +++ b/DM_Weight/ViewModels/SelfAddWindowViewModel - 复制.cs @@ -0,0 +1,211 @@ +using Prism.Commands; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DM_Weight.Models; +using DM_Weight.select; +using DM_Weight.util; +using Prism.Events; +using DM_Weight.msg; +using log4net; + +namespace DM_Weight.ViewModels +{ + public class SelfAddWindowViewModel_Copy : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime + { + IDialogService _dialogService; + IEventAggregator _eventAggregator; + + public static List StaticSelects = new() + { + new OrderTakeSelect + { + Code = "DrugName", + Name = "药品名称" + }, + new OrderTakeSelect + { + Code = "PyCode", + Name = "拼音码" + }, + new OrderTakeSelect + { + Code = "DrugBarcode", + Name = "药品条码" + }, + new OrderTakeSelect + { + Code = "DrugId", + Name = "药品编码" + } + }; + ////private SqlSugarScope SqlSugarHelper.Db; + private readonly ILog logger = LogManager.GetLogger(typeof(SelfAddWindowViewModel)); + public SelfAddWindowViewModel_Copy(IDialogService DialogService,IEventAggregator eventAggregator) + { + logger.Info("进入SelfAddWindowViewModel构造函数"); + _dialogService = DialogService; + _eventAggregator = eventAggregator; + ////this.SqlSugarHelper.Db = sqlSugarScope; + } + + + + private List _selects = StaticSelects; + + public List Selects + { + get { return _selects; } + set + { + SetProperty(ref _selects, value); + } + } + + private OrderTakeSelect _selectedItem = StaticSelects[0]; + /// + /// 查询条件 查询字段 + /// + public OrderTakeSelect SelectedItem + { + get { return _selectedItem; } + set + { + SetProperty(ref _selectedItem, value); + RequestChannelData(); + } + } + + private string? _searchValue; + + /// + /// 查询条件 查询字段值 + /// + public string? SearchValue + { + get { return _searchValue; } + set + { + SetProperty(ref _searchValue, value); + RequestChannelData(); + } + } + + + + + private List _channelStocks = new(); + + public List ChannelStocks { get { return _channelStocks; } set { SetProperty(ref _channelStocks, value); } } + + public DelegateCommand QueryCommand + { + get => new DelegateCommand(() => + { + RequestChannelData(); + }); + } + + + public DelegateCommand OpenSelfDialog + { + get => new DelegateCommand(() => + { + List addChannels = ChannelStocks.FindAll(it => it.AddQuantity > 0).ToList(); + if (addChannels.Count > 0) + { + addChannels.Sort((a, b) => + { + if ((a.DrawerNo - b.DrawerNo) == 0) + { + return a.ColNo - b.ColNo; + } + return a.DrawerNo - b.DrawerNo; + }); + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("ChannelStocks", addChannels); + DialogServiceExtensions.ShowDialogHost(_dialogService, "SelfAddDialog", dialogParameters, DoDialogResult, "RootDialog"); + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "请填写加药数量", + Type = MsgType.ERROR + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + }); + } + + public bool KeepAlive => true; + + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + if (dialogResult.Result == ButtonResult.OK) + { + RequestChannelData(); + } + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } + + + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 + public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) + { + continuationCallback(true); + } + + + + public void RequestChannelData() + { + logger.Info("开始SelfAddWindowViewModel_查询数据"); + List queryData = SqlSugarHelper.Db.Queryable() + .Includes(cs => cs.DrugInfo) + .InnerJoin((cs, cl) => cs.Chnguid == cl.Id && cs.DrugId == cl.DrugId) + .Where(cs => cs.DrugId != null) + .Where(cs => cs.DrawerType == 1) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (cs) => cs.DrugId.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugInfo.DrugName.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.DrugInfo.PyCode.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugInfo.DrugBarcode.Contains(SearchValue)) + .OrderBy(cs => cs.DrugId) + .OrderBy(cs => cs.DrawerNo) + .OrderBy(cs => cs.ColNo) + .ToList(); + ChannelStocks = queryData; + logger.Info("结束SelfAddWindowViewModel_查询数据"); + } + + //接收导航传过来的参数 现在是在此处初始化了表格数据 + public void OnNavigatedTo(NavigationContext navigationContext) + { + logger.Info("进入SelfAddWindowViewModel_OnNavigatedTo"); + Task.Factory.StartNew(() => RequestChannelData()); + logger.Info("结束SelfAddWindowViewModel_OnNavigatedTo"); + } + + //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + //这个方法用于拦截请求 + public void OnNavigatedFrom(NavigationContext navigationContext) + { + + } + } +} diff --git a/DM_Weight/ViewModels/SelfAddWindowViewModel.cs b/DM_Weight/ViewModels/SelfAddWindowViewModel.cs index 267bb87..0fdf91c 100644 --- a/DM_Weight/ViewModels/SelfAddWindowViewModel.cs +++ b/DM_Weight/ViewModels/SelfAddWindowViewModel.cs @@ -14,6 +14,8 @@ using DM_Weight.select; using DM_Weight.util; using Prism.Events; using DM_Weight.msg; +using log4net; +using System.Windows.Documents; namespace DM_Weight.ViewModels { @@ -45,15 +47,17 @@ namespace DM_Weight.ViewModels Name = "药品编码" } }; - private SqlSugarScope _sqlSugarScope1; - public SelfAddWindowViewModel(IDialogService DialogService,IEventAggregator eventAggregator, SqlSugarScope sqlSugarScope) + ////private SqlSugarScope SqlSugarHelper.Db; + private readonly ILog logger = LogManager.GetLogger(typeof(SelfAddWindowViewModel)); + public SelfAddWindowViewModel(IDialogService DialogService, IEventAggregator eventAggregator) { + logger.Info("进入SelfAddWindowViewModel构造函数"); _dialogService = DialogService; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + ////this.SqlSugarHelper.Db = sqlSugarScope; } - + private List _selects = StaticSelects; @@ -78,7 +82,7 @@ namespace DM_Weight.ViewModels SetProperty(ref _selectedItem, value); RequestChannelData(); } - } + } private string? _searchValue; @@ -115,7 +119,18 @@ namespace DM_Weight.ViewModels { get => new DelegateCommand(() => { - List addChannels = ChannelStocks.FindAll(it => it.AddQuantity > 0).ToList(); + + List addChannels = Drugs.Aggregate(new List(), (a, b) => + { + a.AddRange(b.channelStocks.FindAll(it => it.AddQuantity > 0).Select(cs => + { + cs.DrugInfo = b; + return cs; + }).ToList()); + return a; + }); + + //List addChannels = ChannelStocks.FindAll(it => it.AddQuantity > 0).ToList(); if (addChannels.Count > 0) { addChannels.Sort((a, b) => @@ -142,6 +157,8 @@ namespace DM_Weight.ViewModels }); } + public bool KeepAlive => true; + private void DoDialogResult(IDialogResult dialogResult) { // 委托 被动执行 被子窗口执行 @@ -153,7 +170,6 @@ namespace DM_Weight.ViewModels //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); } - public bool KeepAlive => false; //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) @@ -162,29 +178,57 @@ namespace DM_Weight.ViewModels } + private List _drugs = new(); + public List Drugs + { + get => _drugs; + set => SetProperty(ref _drugs, value); + } + private DrugInfo? _drug; + + public DrugInfo? Drug + { + get => _drug; + set => SetProperty(ref _drug, value); + } public void RequestChannelData() { - List queryData = _sqlSugarScope1.Queryable() - .Includes(cs => cs.DrugInfo) - .Where(cs => cs.DrugId != null) - .Where(cs => cs.DrawerType == 1) - .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + logger.Info("开始SelfAddWindowViewModel_查询数据"); + //List queryData = SqlSugarHelper.Db.Queryable() + // .Includes(cs => cs.DrugInfo) + // .InnerJoin((cs, cl) => cs.Chnguid == cl.Id && cs.DrugId == cl.DrugId) + // .Where(cs => cs.DrugId != null) + // .Where(cs => cs.DrawerType == 1) + // .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (cs) => cs.DrugId.Contains(SearchValue)) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugInfo.DrugName.Contains(SearchValue)) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.DrugInfo.PyCode.Contains(SearchValue)) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugInfo.DrugBarcode.Contains(SearchValue)) + // .OrderBy(cs => cs.DrugId) + // .OrderBy(cs => cs.DrawerNo) + // .OrderBy(cs => cs.ColNo) + // .ToList(); + //ChannelStocks = queryData; + List q = SqlSugarHelper.Db.Queryable() + .Includes(di => di.channelStocks.Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null).OrderBy(cs => cs.DrawerNo).OrderBy(cs => cs.ColNo).ToList()) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (cs) => cs.DrugId.Contains(SearchValue)) - .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugInfo.DrugName.Contains(SearchValue)) - .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.DrugInfo.PyCode.Contains(SearchValue)) - .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugInfo.DrugBarcode.Contains(SearchValue)) - .OrderBy(cs => cs.DrugId) - .OrderBy(cs => cs.DrawerNo) - .OrderBy(cs => cs.ColNo) - .ToList(); - ChannelStocks = queryData; + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugName.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.PyCode.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugBarcode.Contains(SearchValue)) + .Where(di => di.channelStocks.Any(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null)) + .OrderBy(cs => cs.DrugId) + .ToList(); + Drugs = q; + logger.Info("结束SelfAddWindowViewModel_查询数据"); } //接收导航传过来的参数 现在是在此处初始化了表格数据 public void OnNavigatedTo(NavigationContext navigationContext) { - RequestChannelData(); + logger.Info("进入SelfAddWindowViewModel_OnNavigatedTo"); + Task.Factory.StartNew(() => RequestChannelData()); + logger.Info("结束SelfAddWindowViewModel_OnNavigatedTo"); } //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 diff --git a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs index e39ef54..427d19e 100644 --- a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs @@ -17,6 +17,7 @@ using DM_Weight.Port; using DM_Weight.util; using System.Threading; using SqlSugar; +using System.Configuration; namespace DM_Weight.ViewModels { @@ -35,12 +36,12 @@ namespace DM_Weight.ViewModels private PortUtil _portUtil; IEventAggregator _eventAggregator; - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public SelfTakeDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, SqlSugarScope sqlSugarScope) { _portUtil = portUtil; _eventAggregator = eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } void DoMyPrismEvent(DeviceMsg msg) @@ -184,7 +185,17 @@ namespace DM_Weight.ViewModels _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); + List singleChannels = channelStocks + .GroupBy(it => new { it.DrawerNo, it.ColNo }) + .Select(it => + { + var ret = it.First(); + ret.Quantity = it.Sum(it => it.Quantity); + ret.TakeQuantity = it.Sum(it => it.TakeQuantity); + return ret; + }) + .ToList() + .FindAll(it => it.BoardType != 1); // 发送取药数量 @@ -211,13 +222,13 @@ namespace DM_Weight.ViewModels _isFinishClick = true; List record = ChannelStocks.ToList(); string InvoiceId = "SELF_" + CurrentTimeMillis(); - var f = _sqlSugarScope1.UseTran(() => + var f = SqlSugarHelper.Db.UseTran(() => { for (int i = 0; i < record.Count; i++) { ChannelStock it = record[i]; // 更新数据 库存信息 - _sqlSugarScope1.Updateable(new ChannelStock() + SqlSugarHelper.Db.Updateable(new ChannelStock() { Quantity = it.Quantity - it.TakeQuantity, ManuNo = it.ManuNo, @@ -225,14 +236,14 @@ namespace DM_Weight.ViewModels Id = it.Id, }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); // 获取更新完库存后的药品库存 - List nowChannels = _sqlSugarScope1.Queryable() + 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(); // 保存数据 出/入库记录 - _sqlSugarScope1.Insertable(new MachineRecord() + SqlSugarHelper.Db.Insertable(new MachineRecord() { MachineId = it.MachineId, DrawerNo = it.DrawerNo, @@ -247,7 +258,9 @@ namespace DM_Weight.ViewModels Type = 2, InvoiceId = InvoiceId, StockQuantity = nowChannels.Sum(it => it.Quantity), - ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity), + SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() }).ExecuteCommand(); } return true; @@ -255,13 +268,41 @@ namespace DM_Weight.ViewModels if (f.Data) { // 更新屏显库存 - List singleChannels = record.FindAll(it => it.BoardType != 1); - if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + //List singleChannels = record.FindAll(it => it.BoardType != 1); + List singleChannels = ChannelStocks.Where(it => it.BoardType != 1) + .GroupBy(it =>new { it.DrawerNo, it.ColNo }) + .Select(it => + { + var ret = it.First(); + //ret.Quantity = it.Sum(itx => itx.Quantity); + //ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + return ret; + }).ToList(); + //if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + //{ + // //将库位多批次的总库存数更新标签 + // //_portUtil.WriteQuantity(singleChannels[0].DrawerNo, singleChannels[0].ColNo, singleChannels.Sum(it => it.Quantity) + singleChannels.Sum(it => it.AddQuantity)); + + // singleChannels.ForEach(it => + // { + // _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity); + // }); + //} + if(singleChannels!=null&&singleChannels.Count>0) { - singleChannels.ForEach(it => + for (int i = 0; i < singleChannels.Count; i++) { - _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity - it.TakeQuantity); - }); + if (singleChannels[i].BoardType == 5) + { + int totalQuantity = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId == singleChannels[i].MachineId) + .Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo) + .Where(cs => cs.ColNo == singleChannels[i].ColNo) + .Sum(it => it.Quantity); + //将库位多批次的总库存数更新标签 + _portUtil.WriteQuantity(singleChannels[i].DrawerNo, singleChannels[i].ColNo, totalQuantity); + } + } } AlertMsg alertMsg = new AlertMsg @@ -320,6 +361,6 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => false; + public bool KeepAlive => true; } } diff --git a/DM_Weight/ViewModels/SelfTakeDrugWindowViewModel.cs b/DM_Weight/ViewModels/SelfTakeDrugWindowViewModel.cs index 9181efc..80769f9 100644 --- a/DM_Weight/ViewModels/SelfTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/SelfTakeDrugWindowViewModel.cs @@ -45,12 +45,12 @@ namespace DM_Weight.ViewModels Name = "药品编码" } }; - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public SelfTakeDrugWindowViewModel(IDialogService DialogService, IEventAggregator eventAggregator, SqlSugarScope sqlSugarScope) { _dialogService = DialogService; _eventAggregator= eventAggregator; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } @@ -105,7 +105,17 @@ namespace DM_Weight.ViewModels { get => new DelegateCommand(() => { - List takeChannels = ChannelStocks.FindAll(it => it.TakeQuantity > 0).ToList(); + //List takeChannels = ChannelStocks.FindAll(it => it.TakeQuantity > 0).ToList(); + + List takeChannels = Drugs.Aggregate(new List(), (a, b) => + { + a.AddRange(b.channelStocks.FindAll(it => it.TakeQuantity > 0).Select(cs => { + cs.DrugInfo = b; + return cs; + }).ToList()); + return a; + }); + if (takeChannels.Count > 0) { takeChannels.Sort((a, b) => @@ -133,6 +143,8 @@ namespace DM_Weight.ViewModels }); } + public bool KeepAlive => true; + private void DoDialogResult(IDialogResult dialogResult) { // 委托 被动执行 被子窗口执行 @@ -144,7 +156,6 @@ namespace DM_Weight.ViewModels //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); } - public bool KeepAlive => false; //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) @@ -152,25 +163,50 @@ namespace DM_Weight.ViewModels continuationCallback(true); } + private List _drugs = new(); + public List Drugs + { + get => _drugs; + set => SetProperty(ref _drugs, value); + } + private DrugInfo? _drug; + + public DrugInfo? Drug + { + get => _drug; + set => SetProperty(ref _drug, value); + } public void RequestChannelData() { - List queryData = _sqlSugarScope1.Queryable() - .Includes(cs => cs.DrugInfo) - .Where(cs => cs.DrugId != null) - .Where(cs => cs.DrawerType == 1) - .Where(cs => cs.Quantity > 0) - .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) - .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (cs) => cs.DrugId.Contains(SearchValue)) - .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugInfo.DrugName.Contains(SearchValue)) - .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.DrugInfo.PyCode.Contains(SearchValue)) - .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugInfo.DrugBarcode.Contains(SearchValue)) - .OrderBy(cs => cs.DrugId) - .OrderBy(cs => cs.DrawerNo) - .OrderBy(cs => cs.ColNo) - .ToList(); - ChannelStocks = queryData; + //List queryData = SqlSugarHelper.Db.Queryable() + // .Includes(cs => cs.DrugInfo) + // .Where(cs => cs.DrugId != null) + // .Where(cs => cs.DrawerType == 1) + // .Where(cs => cs.Quantity > 0) + // .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (cs) => cs.DrugId.Contains(SearchValue)) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugInfo.DrugName.Contains(SearchValue)) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.DrugInfo.PyCode.Contains(SearchValue)) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugInfo.DrugBarcode.Contains(SearchValue)) + // .OrderBy(cs => cs.DrugId) + // .OrderBy(cs => cs.DrawerNo) + // .OrderBy(cs => cs.ColNo) + // .ToList(); + //ChannelStocks = queryData; + List q = SqlSugarHelper.Db.Queryable() + .Includes(di => di.channelStocks.Where(cs => cs.DrawerType == 1) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null&&cs.Quantity>0).OrderBy(cs => cs.DrawerNo).OrderBy(cs => cs.ColNo).ToList()) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (cs) => cs.DrugId.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugName.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.PyCode.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugBarcode.Contains(SearchValue)) + .Where(di => di.channelStocks.Any(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null)) + + .OrderBy(cs => cs.DrugId) + .ToList(); + Drugs = q.Where(di => di.channelStocks.Count() > 0).ToList(); } //接收导航传过来的参数 现在是在此处初始化了表格数据 diff --git a/DM_Weight/ViewModels/SettingWindowViewModel.cs b/DM_Weight/ViewModels/SettingWindowViewModel.cs index 5ea9ec4..34cbecb 100644 --- a/DM_Weight/ViewModels/SettingWindowViewModel.cs +++ b/DM_Weight/ViewModels/SettingWindowViewModel.cs @@ -14,7 +14,6 @@ namespace DM_Weight.ViewModels { public class SettingWindowViewModel : BindableBase, IRegionMemberLifetime { - public bool KeepAlive => false; public static List defaultKeyValuePairs = new() { new OrderTakeSelect() { Code = "operator", Name = "操作人" }, @@ -69,6 +68,9 @@ namespace DM_Weight.ViewModels } }); } + + public bool KeepAlive => true; + //手动实现调用配置的逻辑 规避修改配置文件后不起作用的问题 public string ReadAppSetting(string key) { diff --git a/DM_Weight/ViewModels/StockListAccountDialogViewModel.cs b/DM_Weight/ViewModels/StockListAccountDialogViewModel.cs new file mode 100644 index 0000000..2da4b75 --- /dev/null +++ b/DM_Weight/ViewModels/StockListAccountDialogViewModel.cs @@ -0,0 +1,136 @@ +using DM_Weight.Models; +using DM_Weight.Report; +using DM_Weight.util; +using Prism.Commands; +using Prism.Mvvm; +using Prism.Services.Dialogs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.ViewModels +{ + public class StockListAccountDialogViewModel : BindableBase, IDialogAware + { + public string Title => "导出账册"; + /// + /// 药品库位号 + /// + private string _stock; + public string Stock + { + get => _stock; + set => SetProperty(ref _stock, value); + } + /// + /// 药品ID + /// + private string _drug_id; + public string DrugId + { + get => _drug_id; + set => SetProperty(ref _drug_id, value); + } + /// + /// 开始时间 + /// + private DateTime? _startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); + + public DateTime? StartDate + { + get => _startDate; + set + { + if (value != null) + { + SetProperty(ref _startDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0)); + } + else + { + SetProperty(ref _startDate, value); + } + } + } + /// + /// 结束时间 + /// + private DateTime? _endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); + + public DateTime? EndDate + { + get => _endDate; + set + { + if (value != null) + { + TimeSpan ershisi = new TimeSpan(23, 59, 59); + SetProperty(ref _endDate, new DateTime(value?.Year ?? 0, value?.Month ?? 0, value?.Day ?? 0, 23, 59, 59)); + } + else + { + SetProperty(ref _endDate, value); + } + } + } + //private SqlSugarScope SqlSugarHelper.Db; + public StockListAccountDialogViewModel(SqlSugarScope sqlSugarScope) + { + //this.SqlSugarHelper.Db = sqlSugarScope; + } + public DelegateCommand DownloadAccountBook + { + get => new DelegateCommand(() => + { + GridReportUtil.PrintReportAccountBook(StartDate, EndDate,0, DrugId ?? ""); + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + + }); + } + public DelegateCommand BtnCloseCommand + { + get => new DelegateCommand(() => + { + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + }); + } + + public event Action RequestClose; + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + } + + public void OnDialogOpened(IDialogParameters parameters) + { + if (parameters.ContainsKey("Stock")) + { + Stock = parameters.GetValue("Stock"); + if (!string.IsNullOrEmpty(Stock)) + { + //根据库位信息查询出药品id + string[] strStock = Stock.Split('-'); + if (strStock.Length >= 2) + { + //DrugId = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == Convert.ToInt32(strStock[0]) && cs.ColNo == Convert.ToInt32(strStock[1])).Select(cs => cs.DrugId).ToString(); + var list = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == Convert.ToInt32(strStock[0]) && cs.ColNo == Convert.ToInt32(strStock[1])&& cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).ToList(); + if(list!=null&&list.Count>0) + { + DrugId = list[0].DrugId; + } + } + } + } + } + } +} diff --git a/DM_Weight/ViewModels/StockListWindowViewModel.cs b/DM_Weight/ViewModels/StockListWindowViewModel.cs index e729e49..480340d 100644 --- a/DM_Weight/ViewModels/StockListWindowViewModel.cs +++ b/DM_Weight/ViewModels/StockListWindowViewModel.cs @@ -16,12 +16,17 @@ using DM_Weight.select; using DM_Weight.util; using System.ComponentModel; using System.Windows.Data; +using System.Runtime.InteropServices; +using System.Threading; +using log4net.Repository.Hierarchy; +using log4net; namespace DM_Weight.ViewModels { public class StockListWindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime { - + //public static StockListWindowViewModel vm; + public string drugId; public static List StaticSelects = new() { new OrderTakeSelect @@ -85,13 +90,15 @@ namespace DM_Weight.ViewModels RequestData(); } } - IDialogService _dialogService; - private SqlSugarScope _sqlSugarScope1; - public StockListWindowViewModel(IDialogService dialogService, SqlSugarScope sqlSugarScope) + ////private SqlSugarScope SqlSugarHelper.Db; + private readonly ILog logger = LogManager.GetLogger(typeof(StockListWindowViewModel)); + public StockListWindowViewModel(IDialogService dialogService) { + logger.Info("进入StockListWindowViewModel构造函数"); _dialogService = dialogService; - this._sqlSugarScope1 = sqlSugarScope; + ////this.SqlSugarHelper.Db = sqlSugarScope; + //vm = this; } private ChannelStock? _selectedChannel; @@ -114,7 +121,8 @@ namespace DM_Weight.ViewModels get => new DelegateCommand(() => { DialogParameters dialogParameters = new DialogParameters(); - DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelDialog", dialogParameters, DoDialogResult, "RootDialog"); + //DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelDialog", dialogParameters, DoDialogResult, "RootDialog"); + DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelNewDialog", dialogParameters, DoDialogResult, "RootDialog"); }); } @@ -126,6 +134,22 @@ namespace DM_Weight.ViewModels RequestData(); }); } + /// + /// 导出账册 + /// + public DelegateCommand DownloadAccountBook + { + get => new DelegateCommand(() => + { + AccountAction(); + }); + } + private void AccountAction() + { + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("Stock", drugId); + DialogServiceExtensions.ShowDialogHost(_dialogService, "StockListAccountDialog", dialogParameters, "RootDialog"); + } private void DoDialogResult(IDialogResult dialogResult) { @@ -133,7 +157,7 @@ namespace DM_Weight.ViewModels // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 //if (dialogResult.Result == ButtonResult.OK) //{ - RequestData(); + RequestData(); //} //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); } @@ -146,43 +170,99 @@ namespace DM_Weight.ViewModels }); } + public DelegateCommand ClickCommand + { + get => new DelegateCommand((SelectedChannel) => + { + if (SelectedChannel != null) + { + + } + }); + } + + public bool KeepAlive => true; - public bool KeepAlive => false; - //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) { continuationCallback(true); } + private List? _drugs = new(); + public List? Drugs + { + get => _drugs; + set => SetProperty(ref _drugs, value); + } + private DrugInfo? _drug; + + public DrugInfo? Drug + { + get => _drug; + set => SetProperty(ref _drug, value); + } public void RequestData() { - ChannelStocks.Clear(); - List q = _sqlSugarScope1.Queryable() - .Includes(cs => cs.DrugInfo) - .Where(cs => cs.DrawerType == 1) - .Where(cs =>cs.DrugId != null) - .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) - - .WhereIF(!String.IsNullOrEmpty(SearchValue),cs => cs.DrugInfo.DrugName == SearchValue) - .OrderBy(cs => cs.DrugId) - .OrderBy(cs => cs.DrawerNo) - .OrderBy(cs => cs.ColNo) - .ToList(); + logger.Info("开始StockListWindowViewModel_查询数据"); + //ChannelStocks.Clear(); + //List q = new List(); + //Task.Factory.StartNew(() => + //{ + // List q = SqlSugarHelper.Db.Queryable() + // .Includes(cs => cs.DrugInfo) + // .InnerJoin((cs, cl) => cs.Chnguid == cl.Id && cs.DrugId == cl.DrugId) + // .Where(cs => cs.DrawerType == 1) + // .Where(cs => cs.DrugId != null) + // .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) - ICollectionView vw = CollectionViewSource.GetDefaultView(q); - vw.GroupDescriptions.Add(new PropertyGroupDescription("DrugInfo")); - ChannelStocks = q; - + // .WhereIF(!String.IsNullOrEmpty(SearchValue), cs => cs.DrugInfo.DrugName == SearchValue) + // .OrderBy(cs => cs.DrawerNo) + // .OrderBy(cs => cs.ColNo) + // .OrderBy(cs => cs.DrugId) + // .ToList(); + ////}); + //ChannelStocks = q.Select(it => { it.CheckQuantity = it.Quantity; return it; }).ToList(); + //ICollectionView vw = CollectionViewSource.GetDefaultView(q); + //vw.GroupDescriptions.Add(new PropertyGroupDescription("DrugInfo")); + //ChannelStocks = q; + + //List q = SqlSugarHelper.Db.Queryable() + // .Includes(di => di.channelStocks.Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null).OrderBy(cs => cs.DrawerNo).OrderBy(cs => cs.ColNo).ToList()) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (cs) => cs.DrugId.Contains(SearchValue)) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugName.Contains(SearchValue)) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.PyCode.Contains(SearchValue)) + // .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugBarcode.Contains(SearchValue)) + // .Where(di => di.channelStocks.Any(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null)) + // .OrderBy(cs => cs.DrugId) + // .ToList(); + //Drugs = q; + + List q = SqlSugarHelper.Db.Queryable() + .Includes(di => di.channelStocks.Where(cs => cs.DrawerType == 1) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null).OrderBy(cs => cs.DrawerNo).OrderBy(cs => cs.ColNo).ToList()) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (cs) => cs.DrugId.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (cs) => cs.DrugName.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cs) => cs.PyCode.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cs) => cs.DrugBarcode.Contains(SearchValue)) + .Where(di => di.channelStocks.Any(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null)) + .OrderBy(cs => cs.DrugId) + .ToList(); + Drugs = q; + + logger.Info("结束StockListWindowViewModel_查询数据"); } //接收导航传过来的参数 现在是在此处初始化了表格数据 public void OnNavigatedTo(NavigationContext navigationContext) { - RequestData(); + logger.Info("进入StockListWindowViewModel_OnNavigatedTo"); + //RequestData(); + Task.Factory.StartNew(() => RequestData()); + logger.Info("结束StockListWindowViewModel_OnNavigatedTo"); } @@ -197,5 +277,21 @@ namespace DM_Weight.ViewModels { } + public DelegateCommand RowSelected + { + get => new DelegateCommand(() => + { + //if (ChannelStocks != null) + //{ + // SelectMachineRecords = ChannelStocks.Select(x => + // { + // x.IsSelected = !x.IsSelected; + // return x; + // }).ToList(); + + + //} + }); + } } } diff --git a/DM_Weight/ViewModels/TestCheckBoxViewModel.cs b/DM_Weight/ViewModels/TestCheckBoxViewModel.cs deleted file mode 100644 index f23fa62..0000000 --- a/DM_Weight/ViewModels/TestCheckBoxViewModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Prism.Commands; -using Prism.Mvvm; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DM_Weight.ViewModels -{ - public class TestCheckBoxViewModel:BindableBase - { - public DelegateCommand cbxCommand - { - get =>new DelegateCommand(()=>{ - - }); - } - - - } -} diff --git a/DM_Weight/ViewModels/UserManagerWindowViewModel.cs b/DM_Weight/ViewModels/UserManagerWindowViewModel.cs index 1e1f714..411c630 100644 --- a/DM_Weight/ViewModels/UserManagerWindowViewModel.cs +++ b/DM_Weight/ViewModels/UserManagerWindowViewModel.cs @@ -74,11 +74,11 @@ namespace DM_Weight.ViewModels set { SetProperty(ref _user, value); } } private readonly IDialogService _dialogService; - private SqlSugarScope _sqlSugarScope1; + //private SqlSugarScope SqlSugarHelper.Db; public UserManagerWindowViewModel(IDialogService dialogService, SqlSugarScope sqlSugarScope) { _dialogService = dialogService; - this._sqlSugarScope1 = sqlSugarScope; + //this.SqlSugarHelper.Db = sqlSugarScope; } @@ -96,7 +96,6 @@ namespace DM_Weight.ViewModels RequestData(); } } - public bool KeepAlive => false; public DelegateCommand Query @@ -138,6 +137,8 @@ namespace DM_Weight.ViewModels }); } + public bool KeepAlive => true; + private void DoDialogResult(IDialogResult dialogResult) { // 委托 被动执行 被子窗口执行 @@ -176,7 +177,7 @@ namespace DM_Weight.ViewModels void RequestData() { int totalcount = 0; - UserList = _sqlSugarScope1.Queryable() + UserList = SqlSugarHelper.Db.Queryable() .Includes(ul => ul.Role) .Where(ul => ul.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) .WhereIF(!String.IsNullOrEmpty(SearchValue) , (di) => di.Nickname.Contains(SearchValue)) diff --git a/DM_Weight/Views/AccountWindow.xaml b/DM_Weight/Views/AccountWindow.xaml new file mode 100644 index 0000000..e682a7f --- /dev/null +++ b/DM_Weight/Views/AccountWindow.xaml @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/AccountWindow.xaml.cs b/DM_Weight/Views/AccountWindow.xaml.cs new file mode 100644 index 0000000..62f439d --- /dev/null +++ b/DM_Weight/Views/AccountWindow.xaml.cs @@ -0,0 +1,53 @@ +using DM_Weight.msg; +using DM_Weight.ViewModels; +using Prism.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views +{ + /// + /// AccountWindow.xaml 的交互逻辑 + /// + public partial class AccountWindow : UserControl + { + AccountWindowViewModel vms; + public AccountWindow() + { + InitializeComponent(); + } + /// + /// 药品名称下拉框 + /// + /// + /// + private void ComboBox_KeyUp(object sender, KeyEventArgs e) + { + ComboBox comboBox = sender as ComboBox; + vms.UpdateComboBoxItems(comboBox.Text); + if (this.vms.DrugInfos.Count > 0) + { + comboBox.IsDropDownOpen = true; + } + TextBox textBox = (TextBox)comboBox.Template.FindName("PART_EditableTextBox", comboBox); + textBox.SelectionStart = textBox.Text.Length; + } + + private void UserControl_Loaded(object sender, RoutedEventArgs e) + { + vms = AccountWindowViewModel.vm; + } + } +} diff --git a/DM_Weight/Views/AddDrugControl.xaml b/DM_Weight/Views/AddDrugControl.xaml new file mode 100644 index 0000000..50a0e68 --- /dev/null +++ b/DM_Weight/Views/AddDrugControl.xaml @@ -0,0 +1,395 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/AddDrugControl.xaml.cs b/DM_Weight/Views/AddDrugControl.xaml.cs new file mode 100644 index 0000000..075135a --- /dev/null +++ b/DM_Weight/Views/AddDrugControl.xaml.cs @@ -0,0 +1,41 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.ViewModels; +using Prism.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views +{ + /// + /// AddDrugControl.xaml 的交互逻辑 + /// + public partial class AddDrugControl : UserControl + { + IEventAggregator _eventAggregator; + public AddDrugControl(IEventAggregator eventAggregator) + { + InitializeComponent(); + _eventAggregator= eventAggregator; + } + private void Button_Click(object sender, RoutedEventArgs e) + { + Button btn = (Button)sender; + ChannelList cls = (ChannelList)btn.CommandParameter; + //vms.AddAction(cls); + _eventAggregator.GetEvent().Publish(cls); + } + } +} diff --git a/DM_Weight/Views/CheckRecordNewWindow.xaml b/DM_Weight/Views/CheckRecordNewWindow.xaml new file mode 100644 index 0000000..73d3634 --- /dev/null +++ b/DM_Weight/Views/CheckRecordNewWindow.xaml @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/CheckRecordNewWindow.xaml.cs b/DM_Weight/Views/CheckRecordNewWindow.xaml.cs new file mode 100644 index 0000000..660c0dd --- /dev/null +++ b/DM_Weight/Views/CheckRecordNewWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views +{ + /// + /// CheckRecordWindow.xaml 的交互逻辑 + /// + public partial class CheckRecordNewWindow : UserControl + { + public CheckRecordNewWindow() + { + InitializeComponent(); + } + } +} diff --git a/DM_Weight/Views/CheckStockNew2Window.xaml b/DM_Weight/Views/CheckStockNew2Window.xaml new file mode 100644 index 0000000..82adad2 --- /dev/null +++ b/DM_Weight/Views/CheckStockNew2Window.xaml @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/CheckStockNew2Window.xaml.cs b/DM_Weight/Views/CheckStockNew2Window.xaml.cs new file mode 100644 index 0000000..a138fc8 --- /dev/null +++ b/DM_Weight/Views/CheckStockNew2Window.xaml.cs @@ -0,0 +1,60 @@ +using DM_Weight.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views +{ + /// + /// CheckStockNewWindow.xaml 的交互逻辑 + /// + public partial class CheckStockNew2Window : UserControl + { + //CheckStockNewWindowViewModel vms; + public CheckStockNew2Window() + { + InitializeComponent(); + } + //private void UserControl_Loaded(object sender, RoutedEventArgs e) + //{ + // vms = CheckStockNewWindowViewModel.vm; + //} + ///// + ///// 选中行事件 + ///// + ///// + ///// + //private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) + //{ + // if (dgv1.SelectedIndex >= 0) + // { + // TextBlock txt = dgv1.Columns[0].GetCellContent(dgv1.Items[dgv1.SelectedIndex]) as TextBlock; + // if (txt != null) + // { + // vms.Stock = txt.Text; + // } + // } + //} + //private void Item_GotFocus(object sender, RoutedEventArgs e) + //{ + // var item = (DataGridRow)sender; + // FrameworkElement objElement = dgv1.Columns[0].GetCellContent(item); + // if (objElement != null) + // { + // TextBlock objChk = (TextBlock)objElement; + // vms.Stock = objChk.Text; + // } + //} + } +} diff --git a/DM_Weight/Views/CheckStockNewWindow.xaml b/DM_Weight/Views/CheckStockNewWindow.xaml new file mode 100644 index 0000000..ce05836 --- /dev/null +++ b/DM_Weight/Views/CheckStockNewWindow.xaml @@ -0,0 +1,220 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/CheckStockNewWindow.xaml.cs b/DM_Weight/Views/CheckStockNewWindow.xaml.cs new file mode 100644 index 0000000..f0b0f1a --- /dev/null +++ b/DM_Weight/Views/CheckStockNewWindow.xaml.cs @@ -0,0 +1,60 @@ +using DM_Weight.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views +{ + /// + /// CheckStockNewWindow.xaml 的交互逻辑 + /// + public partial class CheckStockNewWindow : UserControl + { + //CheckStockNewWindowViewModel vms; + public CheckStockNewWindow() + { + InitializeComponent(); + } + //private void UserControl_Loaded(object sender, RoutedEventArgs e) + //{ + // vms = CheckStockNewWindowViewModel.vm; + //} + ///// + ///// 选中行事件 + ///// + ///// + ///// + //private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) + //{ + // if (dgv1.SelectedIndex >= 0) + // { + // TextBlock txt = dgv1.Columns[0].GetCellContent(dgv1.Items[dgv1.SelectedIndex]) as TextBlock; + // if (txt != null) + // { + // vms.Stock = txt.Text; + // } + // } + //} + //private void Item_GotFocus(object sender, RoutedEventArgs e) + //{ + // var item = (DataGridRow)sender; + // FrameworkElement objElement = dgv1.Columns[0].GetCellContent(item); + // if (objElement != null) + // { + // TextBlock objChk = (TextBlock)objElement; + // vms.Stock = objChk.Text; + // } + //} + } +} diff --git a/DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml b/DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml new file mode 100644 index 0000000..2961b14 --- /dev/null +++ b/DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml @@ -0,0 +1,237 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/Dialog/CheckRecordDetailDialog.xaml.cs b/DM_Weight/Views/Dialog/CheckRecordDetailDialog.xaml.cs new file mode 100644 index 0000000..b81ffbf --- /dev/null +++ b/DM_Weight/Views/Dialog/CheckRecordDetailDialog.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views.Dialog +{ + /// + /// CheckRecordDetailDialog.xaml 的交互逻辑 + /// + public partial class CheckRecordDetailDialog : UserControl + { + public CheckRecordDetailDialog() + { + InitializeComponent(); + } + } +} diff --git a/DM_Weight/Views/Dialog/MaskDialog.xaml b/DM_Weight/Views/Dialog/MaskDialog.xaml new file mode 100644 index 0000000..fde2079 --- /dev/null +++ b/DM_Weight/Views/Dialog/MaskDialog.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/DM_Weight/Views/Dialog/MaskDialog.xaml.cs b/DM_Weight/Views/Dialog/MaskDialog.xaml.cs new file mode 100644 index 0000000..edca873 --- /dev/null +++ b/DM_Weight/Views/Dialog/MaskDialog.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views.Dialog +{ + /// + /// MaskDialog.xaml 的交互逻辑 + /// + public partial class MaskDialog : UserControl + { + public MaskDialog() + { + InitializeComponent(); + } + } +} diff --git a/DM_Weight/Views/Dialog/StockListAccountDialog.xaml b/DM_Weight/Views/Dialog/StockListAccountDialog.xaml new file mode 100644 index 0000000..14a2fcf --- /dev/null +++ b/DM_Weight/Views/Dialog/StockListAccountDialog.xaml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/Dialog/StockListAccountDialog.xaml.cs b/DM_Weight/Views/Dialog/StockListAccountDialog.xaml.cs new file mode 100644 index 0000000..9dce87a --- /dev/null +++ b/DM_Weight/Views/Dialog/StockListAccountDialog.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views.Dialog +{ + /// + /// StockListAccountDialog.xaml 的交互逻辑 + /// + public partial class StockListAccountDialog : UserControl + { + public StockListAccountDialog() + { + InitializeComponent(); + } + } +} diff --git a/DM_Weight/Views/DrawerAddDrugWindow.xaml b/DM_Weight/Views/DrawerAddDrugWindow.xaml index e89dc8a..d87e7f2 100644 --- a/DM_Weight/Views/DrawerAddDrugWindow.xaml +++ b/DM_Weight/Views/DrawerAddDrugWindow.xaml @@ -229,11 +229,16 @@ Header="规格" IsReadOnly="True" ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"/> - + ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"/> + - @@ -263,7 +268,7 @@ Binding="{Binding drugManuNo.EffDate}" Header="效期" IsReadOnly="True" - ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"/> + ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"/>--> + @@ -26,10 +27,11 @@ - + - + + @@ -46,7 +48,22 @@ + + @@ -59,7 +76,11 @@ - + + + + + @@ -74,16 +95,6 @@ - - - - diff --git a/DM_Weight/Views/InvoiceInNewWindow.xaml b/DM_Weight/Views/InvoiceInNewWindow.xaml new file mode 100644 index 0000000..e8c5bec --- /dev/null +++ b/DM_Weight/Views/InvoiceInNewWindow.xaml @@ -0,0 +1,309 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/InvoiceInNewWindow.xaml.cs b/DM_Weight/Views/InvoiceInNewWindow.xaml.cs new file mode 100644 index 0000000..75373d0 --- /dev/null +++ b/DM_Weight/Views/InvoiceInNewWindow.xaml.cs @@ -0,0 +1,40 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using Prism.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views +{ + /// + /// InvoiceInNewWindow.xaml 的交互逻辑 + /// + public partial class InvoiceInNewWindow : UserControl + { + IEventAggregator _eventAggregator; + public InvoiceInNewWindow(IEventAggregator eventAggregator) + { + InitializeComponent(); + _eventAggregator = eventAggregator; + } + private void Button_Click(object sender, RoutedEventArgs e) + { + Button btn = (Button)sender; + ChannelList cls = (ChannelList)btn.CommandParameter; + //vms.AddAction(cls); + _eventAggregator.GetEvent().Publish(cls); + } + } +} diff --git a/DM_Weight/Views/LoginWindow.xaml b/DM_Weight/Views/LoginWindow.xaml index 6fe3a46..43a95d2 100644 --- a/DM_Weight/Views/LoginWindow.xaml +++ b/DM_Weight/Views/LoginWindow.xaml @@ -179,7 +179,7 @@ FontSize="14" FontWeight="Bold" Foreground="{DynamicResource MaterialDesignPaper}" - Grid.Row="0" Grid.Column="2" Text="{Binding Operator.Nickname}" /> + Grid.Row="0" Grid.Column="2" Text="{Binding Operator.Nickname,UpdateSourceTrigger=PropertyChanged}" /> + Grid.Row="1" Grid.Column="2" Text="{Binding Reviewer.Nickname,UpdateSourceTrigger=PropertyChanged}" /> diff --git a/DM_Weight/Views/MachineRecordWindow.xaml b/DM_Weight/Views/MachineRecordWindow.xaml index 5b7b446..61a15f7 100644 --- a/DM_Weight/Views/MachineRecordWindow.xaml +++ b/DM_Weight/Views/MachineRecordWindow.xaml @@ -66,7 +66,7 @@ Visibility="{Binding Type, Converter={StaticResource MachineTypeConverter},ConverterParameter=drugNameSearch}"/> - + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/SelfAddWindow - 复制.xaml.cs b/DM_Weight/Views/SelfAddWindow - 复制.xaml.cs new file mode 100644 index 0000000..4cc47e5 --- /dev/null +++ b/DM_Weight/Views/SelfAddWindow - 复制.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DM_Weight.Views +{ + /// + /// SelfAddWindow.xaml 的交互逻辑 + /// + public partial class SelfAddWindow_Copy : UserControl + { + public SelfAddWindow_Copy() + { + InitializeComponent(); + } + } +} diff --git a/DM_Weight/Views/SelfAddWindow.xaml b/DM_Weight/Views/SelfAddWindow.xaml index b7880d9..2a392fc 100644 --- a/DM_Weight/Views/SelfAddWindow.xaml +++ b/DM_Weight/Views/SelfAddWindow.xaml @@ -11,12 +11,13 @@ mc:Ignorable="d"> - + + @@ -67,7 +68,7 @@ - - + - + --> + - - - - - - + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/SelfTakeDrugWindow.xaml b/DM_Weight/Views/SelfTakeDrugWindow.xaml index ce4ffba..ae459e2 100644 --- a/DM_Weight/Views/SelfTakeDrugWindow.xaml +++ b/DM_Weight/Views/SelfTakeDrugWindow.xaml @@ -12,12 +12,13 @@ mc:Ignorable="d"> - + + @@ -67,7 +68,7 @@ - - + + --> - - - - - - + + + + - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/StockListWindow.xaml b/DM_Weight/Views/StockListWindow.xaml index efc4aa7..4004b4b 100644 --- a/DM_Weight/Views/StockListWindow.xaml +++ b/DM_Weight/Views/StockListWindow.xaml @@ -9,10 +9,19 @@ xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:convert="clr-namespace:DM_Weight.Converter" xmlns:prism="http://prismlibrary.com/" - mc:Ignorable="d"> + mc:Ignorable="d" + d:DesignHeight="450" d:DesignWidth="800"> + + @@ -40,7 +49,16 @@ Style="{StaticResource MaterialDesignOutlinedTextBox}"/> - +