From 0d2d10deabe809fad6efcd50692b93d6eae3c054 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Wed, 17 Jul 2024 10:02:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8A=B6=E6=80=81=E8=BD=AC=E6=8D=A2=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20=20//=E7=A1=AE=E8=AE=A4=E6=A0=B8=E9=94=80=E3=80=81?= =?UTF-8?q?=E5=88=B7=E6=96=B0=20=E5=BD=95=E5=83=8F=E6=9C=BA=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=9B=91=E6=B5=8B=E6=97=A5=E5=BF=97=20channel=5Fstock?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0dm=5Fmachine=5Frecord=E8=A1=A8id=E5=80=BC=20d?= =?UTF-8?q?rug=5Finfo=E8=A1=A8=E6=B7=BB=E5=8A=A0=E8=8D=AF=E5=93=81?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5=20machinerecord=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=B7=B2=E6=A0=B8=E9=94=80=E6=95=B0=E9=87=8F=E3=80=81?= =?UTF-8?q?=E6=A0=B8=E9=94=80=E6=95=B0=E9=87=8F=20orderinfo=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0machineId=20=E6=B7=BB=E5=8A=A0SurgicalSchedule?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=20=E6=B7=BB=E5=8A=A0SurgicalScheduleDetail?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=20=E6=B7=BB=E5=8A=A0=E6=89=8B=E6=9C=AF?= =?UTF-8?q?=E6=A0=B8=E9=94=80=E3=80=81=E8=BF=98=E7=A9=BA=E7=93=B6=E9=94=80?= =?UTF-8?q?=E6=AF=81=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/App.config | 4 +- DM_Weight/App.xaml.cs | 22 +- DM_Weight/Converter/StatusConverter.cs | 12 + DM_Weight/HIKVISION/CHKFunction.cs | 232 +++-- DM_Weight/Models/ChannelStock.cs | 4 + DM_Weight/Models/CollectDrug.cs | 6 +- DM_Weight/Models/DrugInfo.cs | 7 + DM_Weight/Models/DrugPleaseClaim.cs | 8 +- DM_Weight/Models/MachineRecord.cs | 56 +- DM_Weight/Models/OrderInfo.cs | 8 + DM_Weight/Models/SurgicalSchedule.cs | 176 ++++ DM_Weight/Models/SurgicalScheduleDetail.cs | 68 ++ .../ReturnEmptyDistory_template.grf | 2 +- DM_Weight/ReportTemp/machine_log_add.grf | 2 +- DM_Weight/ReportTemp/machine_log_check.grf | 2 +- DM_Weight/ReportTemp/machine_log_return.grf | 2 +- DM_Weight/ReportTemp/machine_log_take.grf | 2 +- DM_Weight/ReportTemp/orderUse_template.grf | 2 +- DM_Weight/ReportTemp/stock_template.grf | 2 +- .../ViewModels/AddDrugControlViewModel.cs | 9 +- .../ViewModels/AddSurgeryDialogViewModel.cs | 949 ++++++++++++++++++ .../ViewModels/ApplyInStockWindowViewModel.cs | 22 +- .../ViewModels/ApplyListWindowViewModel.cs | 19 +- .../ViewModels/CollectDrugDialogViewModel.cs | 3 +- .../ViewModels/CollectDrugWindowViewModel.cs | 33 + .../DrawerAddDrugWindowViewModel.cs | 16 +- .../DrawerTakeDrugWindowViewModel.cs | 19 +- .../ViewModels/EditUserDialogViewModel.cs | 4 +- .../ViewModels/InvoiceAddDialogViewModel.cs | 13 +- .../ViewModels/InvoiceTakeDialogViewModel.cs | 12 +- DM_Weight/ViewModels/MainWindowViewModel.cs | 10 +- .../MultiOrderTakeDrugWindowViewModel.cs | 2 +- .../ViewModels/OrderReturnDialogViewModel.cs | 15 +- .../ViewModels/OrderTakeDialogViewModel.cs | 18 +- .../ViewModels/ReturnDrugDialogViewModel.cs | 5 +- .../ViewModels/ReturnDrugWindow2ViewModel.cs | 2 +- .../ViewModels/ReturnDrugWindowViewModel.cs | 2 +- .../ReturnEmptyDestoryWindowViewModel.cs | 310 ++++++ .../ViewModels/RoleManagerWindowViewModel.cs | 24 +- .../ViewModels/SelfAddDialogViewModel.cs | 13 +- .../ViewModels/SelfTakeDialogViewModel.cs | 13 +- .../ViewModels/SelfTakeDrugWindowViewModel.cs | 2 +- .../ViewModels/StockListWindowViewModel.cs | 6 +- .../ViewModels/SurgeryTakeDialogViewModel.cs | 859 ++++++++++++++++ .../ViewModels/SurgeryTakeWindowViewModel.cs | 230 +++++ .../ViewModels/UserManagerWindowViewModel.cs | 2 +- DM_Weight/Views/ApplyInStockWindow.xaml | 28 +- DM_Weight/Views/ApplyListWindow.xaml | 38 +- DM_Weight/Views/CollectDrugWindow.xaml | 4 +- DM_Weight/Views/Dialog/AddSurgeryDialog.xaml | 329 ++++++ .../Views/Dialog/AddSurgeryDialog.xaml.cs | 28 + DM_Weight/Views/Dialog/SurgeryTakeDialog.xaml | 242 +++++ .../Views/Dialog/SurgeryTakeDialog.xaml.cs | 28 + DM_Weight/Views/MachineRecordWindow.xaml | 8 +- DM_Weight/Views/MainWindow.xaml.cs | 4 + DM_Weight/Views/ReturnEmptyDestoryWindow.xaml | 110 ++ .../Views/ReturnEmptyDestoryWindow.xaml.cs | 28 + DM_Weight/Views/SurgeryTakeWindow.xaml | 134 +++ DM_Weight/Views/SurgeryTakeWindow.xaml.cs | 28 + 59 files changed, 4067 insertions(+), 171 deletions(-) create mode 100644 DM_Weight/Models/SurgicalSchedule.cs create mode 100644 DM_Weight/Models/SurgicalScheduleDetail.cs create mode 100644 DM_Weight/ViewModels/AddSurgeryDialogViewModel.cs create mode 100644 DM_Weight/ViewModels/ReturnEmptyDestoryWindowViewModel.cs create mode 100644 DM_Weight/ViewModels/SurgeryTakeDialogViewModel.cs create mode 100644 DM_Weight/ViewModels/SurgeryTakeWindowViewModel.cs create mode 100644 DM_Weight/Views/Dialog/AddSurgeryDialog.xaml create mode 100644 DM_Weight/Views/Dialog/AddSurgeryDialog.xaml.cs create mode 100644 DM_Weight/Views/Dialog/SurgeryTakeDialog.xaml create mode 100644 DM_Weight/Views/Dialog/SurgeryTakeDialog.xaml.cs create mode 100644 DM_Weight/Views/ReturnEmptyDestoryWindow.xaml create mode 100644 DM_Weight/Views/ReturnEmptyDestoryWindow.xaml.cs create mode 100644 DM_Weight/Views/SurgeryTakeWindow.xaml create mode 100644 DM_Weight/Views/SurgeryTakeWindow.xaml.cs diff --git a/DM_Weight/App.config b/DM_Weight/App.config index 2684df2..66b66d8 100644 --- a/DM_Weight/App.config +++ b/DM_Weight/App.config @@ -33,7 +33,7 @@ - + @@ -60,7 +60,7 @@ - + diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index 759d43c..c8816a3 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -44,6 +44,7 @@ namespace DM_Weight protected override Window CreateShell() { + logger.Info("进入APP-CreateShell"); //UI线程未捕获异常处理事件 this.DispatcherUnhandledException += OnDispatcherUnhandledException; //Task线程内未捕获异常处理事件 @@ -51,6 +52,7 @@ namespace DM_Weight //多线程异常 AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; + logger.Info("进入APP-CreateShell-2"); return Container.Resolve(); } @@ -86,6 +88,8 @@ namespace DM_Weight protected override void RegisterTypes(IContainerRegistry containerRegistry) { + + logger.Info("进入APP-RegisterTypes"); // 注入日志 XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config")); //containerRegistry.RegisterInstance(LogManager.GetLogger("")); @@ -95,7 +99,7 @@ namespace DM_Weight // 指纹机工具 containerRegistry.RegisterSingleton(); // 组态屏工具 - containerRegistry.RegisterSingleton(); + //containerRegistry.RegisterSingleton(); // 录像机 containerRegistry.RegisterSingleton(); @@ -144,6 +148,14 @@ namespace DM_Weight containerRegistry.RegisterDialog(); containerRegistry.RegisterForNavigation(); + //手术排程 + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterDialog(); + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterDialog(); + containerRegistry.RegisterForNavigation(); + + #endregion #region 加药 @@ -189,12 +201,18 @@ namespace DM_Weight containerRegistry.RegisterForNavigation(); // 还空瓶页面 containerRegistry.RegisterForNavigation(); + + //空瓶销毁页面 + containerRegistry.RegisterForNavigation(); + // 归还空瓶模态框 containerRegistry.RegisterDialog(); containerRegistry.RegisterForNavigation(); // 空瓶销毁模态框 containerRegistry.RegisterDialog(); containerRegistry.RegisterForNavigation(); + + #endregion #region 库存管理 @@ -245,6 +263,8 @@ namespace DM_Weight containerRegistry.RegisterForNavigation(); + logger.Info("结束APP-RegisterTypes"); + } } } diff --git a/DM_Weight/Converter/StatusConverter.cs b/DM_Weight/Converter/StatusConverter.cs index 85d7166..261a159 100644 --- a/DM_Weight/Converter/StatusConverter.cs +++ b/DM_Weight/Converter/StatusConverter.cs @@ -73,6 +73,18 @@ namespace DM_Weight.Converter return Visibility.Collapsed; } } + //确认核销、刷新 + if (parameter.ToString().Equals("ConfirmVsRefresh")) + { + if (status == 0) + { + return Visibility.Visible; + } + else + { + return Visibility.Collapsed; + } + } return Visibility.Collapsed; } diff --git a/DM_Weight/HIKVISION/CHKFunction.cs b/DM_Weight/HIKVISION/CHKFunction.cs index 188d6fd..7375c2d 100644 --- a/DM_Weight/HIKVISION/CHKFunction.cs +++ b/DM_Weight/HIKVISION/CHKFunction.cs @@ -32,142 +32,200 @@ namespace DM_Weight.HIKVISION public CHKFunction() { + logger.Info("CHKFunction"); HIKInit(); HIKLogin(); } public bool HIKInit() { - m_bInitSDK = CHCNetSDK.NET_DVR_Init(); - if (m_bInitSDK == false) + try { - //MessageBox.Show("NET_DVR_Init error!"); - //return; - logger.Info("NET_DVR_Init error!"); + + + logger.Info("HIKInit"); + + m_bInitSDK = CHCNetSDK.NET_DVR_Init(); + + logger.Info($"HIKInit-{m_bInitSDK}"); + if (m_bInitSDK == false) + { + //MessageBox.Show("NET_DVR_Init error!"); + //return; + logger.Info("NET_DVR_Init error!"); + } + else + { + //保存SDK日志 To save the SDK log + CHCNetSDK.NET_DVR_SetLogToFile(3, "C:\\SdkLog\\", true); + } } - else + catch (Exception ex) { - //保存SDK日志 To save the SDK log - CHCNetSDK.NET_DVR_SetLogToFile(3, "C:\\SdkLog\\", true); + logger.Info($"HIKInit Exception:{ex.Message}"); } return m_bInitSDK; } public int HIKLogin() { - string ip = ReadApp.ReadAppSetting("HIKIP"); - string port = ReadApp.ReadAppSetting("HIKPort"); - string userName = ReadApp.ReadAppSetting("HIKUser"); - string password = ReadApp.ReadAppSetting("HIKPassword"); - if (HKUserId < 0) + try { - - struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO(); - - //设备IP地址或者域名 - byte[] byIP = System.Text.Encoding.Default.GetBytes(ip); - struLogInfo.sDeviceAddress = new byte[129]; - byIP.CopyTo(struLogInfo.sDeviceAddress, 0); - - //设备用户名 - byte[] byUserName = System.Text.Encoding.Default.GetBytes(userName); - struLogInfo.sUserName = new byte[64]; - byUserName.CopyTo(struLogInfo.sUserName, 0); - - //设备密码 - byte[] byPassword = System.Text.Encoding.Default.GetBytes(password); - struLogInfo.sPassword = new byte[64]; - byPassword.CopyTo(struLogInfo.sPassword, 0); - - struLogInfo.wPort = ushort.Parse(port);//设备服务端口号 - - //if (LoginCallBack == null) - //{ - // LoginCallBack = new CHCNetSDK.LOGINRESULTCALLBACK(cbLoginCallBack);//注册回调函数 - //} - //struLogInfo.cbLoginResult = LoginCallBack; - struLogInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是 - - DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40(); - - //登录设备 Login the device - HKUserId = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo); + logger.Info("HIKLogin"); + string ip = ReadApp.ReadAppSetting("HIKIP"); + string port = ReadApp.ReadAppSetting("HIKPort"); + string userName = ReadApp.ReadAppSetting("HIKUser"); + string password = ReadApp.ReadAppSetting("HIKPassword"); if (HKUserId < 0) { - iLastErr = CHCNetSDK.NET_DVR_GetLastError(); - str = "NET_DVR_Login_V40 failed, error code= " + iLastErr; //登录失败,输出错误号 - logger.Info(str); + + struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO(); + + //设备IP地址或者域名 + byte[] byIP = System.Text.Encoding.Default.GetBytes(ip); + struLogInfo.sDeviceAddress = new byte[129]; + byIP.CopyTo(struLogInfo.sDeviceAddress, 0); + + //设备用户名 + byte[] byUserName = System.Text.Encoding.Default.GetBytes(userName); + struLogInfo.sUserName = new byte[64]; + byUserName.CopyTo(struLogInfo.sUserName, 0); + + //设备密码 + byte[] byPassword = System.Text.Encoding.Default.GetBytes(password); + struLogInfo.sPassword = new byte[64]; + byPassword.CopyTo(struLogInfo.sPassword, 0); + + struLogInfo.wPort = ushort.Parse(port);//设备服务端口号 + + //if (LoginCallBack == null) + //{ + // LoginCallBack = new CHCNetSDK.LOGINRESULTCALLBACK(cbLoginCallBack);//注册回调函数 + //} + //struLogInfo.cbLoginResult = LoginCallBack; + struLogInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是 + + DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40(); + + //登录设备 Login the device + HKUserId = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo); + if (HKUserId < 0) + { + iLastErr = CHCNetSDK.NET_DVR_GetLastError(); + str = "NET_DVR_Login_V40 failed, error code= " + iLastErr; //登录失败,输出错误号 + logger.Info(str); + } + else + { + //登录成功 + //MessageBox.Show("Login Success!"); + logger.Info("Login Success!"); + } + } else { - //登录成功 - //MessageBox.Show("Login Success!"); - logger.Info("Login Success!"); - } + //注销登录 Logout the device + if (m_lRealHandle >= 0) + { + //MessageBox.Show("Please stop live view firstly"); + logger.Info("Please stop live view firstly"); + } + if (!CHCNetSDK.NET_DVR_Logout(HKUserId)) + { + iLastErr = CHCNetSDK.NET_DVR_GetLastError(); + str = "NET_DVR_Logout failed, error code= " + iLastErr; + logger.Info(str); + } + HKUserId = -1; + } } - else + catch (Exception ex) { - //注销登录 Logout the device - if (m_lRealHandle >= 0) - { - //MessageBox.Show("Please stop live view firstly"); - logger.Info("Please stop live view firstly"); - } - if (!CHCNetSDK.NET_DVR_Logout(HKUserId)) - { - iLastErr = CHCNetSDK.NET_DVR_GetLastError(); - str = "NET_DVR_Logout failed, error code= " + iLastErr; - logger.Info(str); - } - HKUserId = -1; + logger.Info($"HIKLogin Exception:{ex.Message}"); } return HKUserId; } public void HIKLoginOut() { - if (m_lRealHandle >= 0) + try { - bool stopRealPlay = CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle); - logger.Info($"录像机NET_DVR_StopRealPlay接口返回{stopRealPlay}"); + + if (m_lRealHandle >= 0) + { + bool stopRealPlay = CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle); + logger.Info($"录像机NET_DVR_StopRealPlay接口返回{stopRealPlay}"); + } + if (HKUserId >= 0) + { + bool logout = CHCNetSDK.NET_DVR_Logout(HKUserId); + logger.Info($"录像机NET_DVR_Logout接口返回{logout}"); + } + if (m_bInitSDK == true) + { + bool cleanUp = CHCNetSDK.NET_DVR_Cleanup(); + logger.Info($"录像机NET_DVR_Cleanup接口返回{cleanUp}"); + } + } - if (HKUserId >= 0) + catch (Exception ex) { - bool logout = CHCNetSDK.NET_DVR_Logout(HKUserId); - logger.Info($"录像机NET_DVR_Logout接口返回{logout}"); - } - if (m_bInitSDK == true) - { - bool cleanUp = CHCNetSDK.NET_DVR_Cleanup(); - logger.Info($"录像机NET_DVR_Cleanup接口返回{cleanUp}"); + logger.Info($"HIKLoginOut Exception{ex.Message}"); } } public bool HIKStartDVRRecord() { - bool isStart = CHCNetSDK.NET_DVR_StartDVRRecord(HKUserId, 0xffff, 0); - logger.Info($"录像机NET_DVR_StartDVRRecord接口返回{isStart}"); + bool isStart = false; + try + { + + isStart = CHCNetSDK.NET_DVR_StartDVRRecord(HKUserId, 0xffff, 0); + logger.Info($"录像机NET_DVR_StartDVRRecord接口返回{isStart}"); + } + catch (Exception ex) + { + logger.Info($"HIKStartDVRRecord Exception{ex.Message}"); + } return isStart; } public bool HIKStopDVRRecord() { - bool isStop = CHCNetSDK.NET_DVR_StopDVRRecord(HKUserId, 0xffff); - logger.Info($"录像机NET_DVR_StopDVRRecord接口返回{isStop}"); + bool isStop = false; + try + { + + isStop = CHCNetSDK.NET_DVR_StopDVRRecord(HKUserId, 0xffff); + logger.Info($"录像机NET_DVR_StopDVRRecord接口返回{isStop}"); + } + catch (Exception ex) + { + logger.Info($"HIKStopDVRRecord Exception{ex.Message}"); + } return isStop; } public void HIK_DVR_TIME() { - UInt32 dwReturn = 0; - Int32 nSize = Marshal.SizeOf(m_struTimeCfg); - IntPtr ptrTimeCfg = Marshal.AllocHGlobal(nSize); - Marshal.StructureToPtr(m_struTimeCfg, ptrTimeCfg, false); - if (CHCNetSDK.NET_DVR_GetDVRConfig(HKUserId, CHCNetSDK.NET_DVR_GET_TIMECFG, -1, ptrTimeCfg, (UInt32)nSize, ref dwReturn)) + try { - m_struTimeCfg = (CHCNetSDK.NET_DVR_TIME)Marshal.PtrToStructure(ptrTimeCfg, typeof(CHCNetSDK.NET_DVR_TIME)); - logger.Info($"录像机时间接口{Convert.ToString(m_struTimeCfg.dwYear)}- {Convert.ToString(m_struTimeCfg.dwMonth)}- {Convert.ToString(m_struTimeCfg.dwDay)}- {Convert.ToString(m_struTimeCfg.dwHour)}- {Convert.ToString(m_struTimeCfg.dwMinute)}- {Convert.ToString(m_struTimeCfg.dwSecond)}"); + UInt32 dwReturn = 0; + Int32 nSize = Marshal.SizeOf(m_struTimeCfg); + IntPtr ptrTimeCfg = Marshal.AllocHGlobal(nSize); + Marshal.StructureToPtr(m_struTimeCfg, ptrTimeCfg, false); + if (CHCNetSDK.NET_DVR_GetDVRConfig(HKUserId, CHCNetSDK.NET_DVR_GET_TIMECFG, -1, ptrTimeCfg, (UInt32)nSize, ref dwReturn)) + { + + m_struTimeCfg = (CHCNetSDK.NET_DVR_TIME)Marshal.PtrToStructure(ptrTimeCfg, typeof(CHCNetSDK.NET_DVR_TIME)); + logger.Info($"录像机时间接口{Convert.ToString(m_struTimeCfg.dwYear)}- {Convert.ToString(m_struTimeCfg.dwMonth)}- {Convert.ToString(m_struTimeCfg.dwDay)}- {Convert.ToString(m_struTimeCfg.dwHour)}- {Convert.ToString(m_struTimeCfg.dwMinute)}- {Convert.ToString(m_struTimeCfg.dwSecond)}"); + } + } + catch (Exception ex) + { + logger.Info($"HIK_DVR_TIME Exception{ex.Message}"); } } /// diff --git a/DM_Weight/Models/ChannelStock.cs b/DM_Weight/Models/ChannelStock.cs index fe2462c..98690e6 100644 --- a/DM_Weight/Models/ChannelStock.cs +++ b/DM_Weight/Models/ChannelStock.cs @@ -187,5 +187,9 @@ namespace DM_Weight.Models [SugarColumn(IsIgnore = true)] public DrugPleaseClaim PleaseClaim { get; set; } + //dm_machine_record表id值 + [SugarColumn(IsIgnore = true)] + public int? MachineRecordId { get; set; } + } } \ No newline at end of file diff --git a/DM_Weight/Models/CollectDrug.cs b/DM_Weight/Models/CollectDrug.cs index 7954c88..6be463e 100644 --- a/DM_Weight/Models/CollectDrug.cs +++ b/DM_Weight/Models/CollectDrug.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; +using Newtonsoft.Json; using SqlSugar; namespace DM_Weight.Models @@ -23,7 +24,7 @@ namespace DM_Weight.Models /// /// 主键 /// - [SugarColumn(ColumnName = "Applyid")] + [SugarColumn(ColumnName = "Applyid",IsPrimaryKey =true)] public int Applyid { get; set; } /// /// 药品请领单号 @@ -114,5 +115,8 @@ namespace DM_Weight.Models /// [Navigate(NavigateType.ManyToOne, nameof(DrugPleaseClaimId))] public DrugPleaseClaim drugPleaseClaim { get; set; } + + [SugarColumn(IsIgnore = true)] + public List ManuNoList { get; set; } } } diff --git a/DM_Weight/Models/DrugInfo.cs b/DM_Weight/Models/DrugInfo.cs index ed5ee52..9416dd7 100644 --- a/DM_Weight/Models/DrugInfo.cs +++ b/DM_Weight/Models/DrugInfo.cs @@ -72,6 +72,13 @@ namespace DM_Weight.Models /// [SugarColumn(ColumnName = "max_stock")] public int? MaxStock { get; set; } + + /// + /// 药品类型 + /// + [SugarColumn(ColumnName ="drug_type")] + public string DrugType { get; set; } + //[SugarColumn(IsIgnore=true)] [Navigate(NavigateType.OneToMany, nameof(ChannelStock.DrugId), nameof(DrugId))]//BookA表中的studenId public List channelStocks { get; set; } diff --git a/DM_Weight/Models/DrugPleaseClaim.cs b/DM_Weight/Models/DrugPleaseClaim.cs index 22f42e7..c9e2e49 100644 --- a/DM_Weight/Models/DrugPleaseClaim.cs +++ b/DM_Weight/Models/DrugPleaseClaim.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Newtonsoft.Json; using SqlSugar; namespace DM_Weight.Models @@ -54,7 +55,8 @@ namespace DM_Weight.Models /// 批次(多条) /// [SugarColumn(ColumnName = "drug_manu_no")] - public string DrugManuNo { get; set; } + [JsonProperty("drug_manu_no")] + public string _DrugManuNos { get; set; } /// /// 备注1 @@ -124,5 +126,9 @@ namespace DM_Weight.Models [Navigate(NavigateType.OneToOne, nameof(DrugId))] public DrugInfo DrugInfo { get; set; } + + + //private List manuNoList = new List(); + //public List ManuNoList { get=>manuNoList; set=>{ DrugManuNo}; } } } diff --git a/DM_Weight/Models/MachineRecord.cs b/DM_Weight/Models/MachineRecord.cs index 49adde4..9b3cbfd 100644 --- a/DM_Weight/Models/MachineRecord.cs +++ b/DM_Weight/Models/MachineRecord.cs @@ -1,4 +1,5 @@ -using SqlSugar; +using Prism.Mvvm; +using SqlSugar; using System; using System.Collections.Generic; using System.Linq; @@ -9,7 +10,7 @@ using System.Threading.Tasks; namespace DM_Weight.Models { [SugarTable("dm_machine_record")] - public class MachineRecord + public class MachineRecord : BindableBase { /// /// 主键 @@ -41,7 +42,7 @@ namespace DM_Weight.Models //[SugarColumn(ColumnName = "check_quantity")] //public int? CheckQuantity { get; set; } - + /// /// 批号 /// @@ -106,14 +107,16 @@ namespace DM_Weight.Models /// 退药量 /// 默认值: 0 /// + private int returnQuantity1; [SugarColumn(ColumnName = "return_quantity1", IsOnlyIgnoreInsert = true)] - public int ReturnQuantity1 { get; set; } + public int ReturnQuantity1 { get => returnQuantity1; set => SetProperty(ref returnQuantity1, value); } /// /// 退空瓶量 /// 默认值: 0 /// + private int returnQuantity2; [SugarColumn(ColumnName = "return_quantity2", IsOnlyIgnoreInsert = true)] - public int ReturnQuantity2 { get; set; } + public int ReturnQuantity2 { get => returnQuantity2; set => SetProperty(ref returnQuantity2, value); } /// /// 取药记录id /// @@ -124,8 +127,8 @@ namespace DM_Weight.Models /// 默认值: 0 /// [SugarColumn(ColumnName = "is_destroy", IsOnlyIgnoreInsert = true)] - public int? IsDestroy { get; set; } - + public int? IsDestroy { get; set; } + /// /// 销毁操作人 /// 默认值: 0 @@ -145,10 +148,47 @@ namespace DM_Weight.Models public int CanReturnQuantity { get => Quantity - ReturnQuantity1 - ReturnQuantity2; - + } [SugarColumn(IsIgnore = true)] public bool IsSelected { get; set; } + + /// + /// 已核销数量 + /// + private int hasCheckNum; + [SugarColumn(IsIgnore = true)] + public int HasCheckNum + { + get => hasCheckNum; + set => SetProperty(ref hasCheckNum, value); + } + + + private int checkQuantity; + /// + /// 核销数量 + /// + [SugarColumn(IsIgnore = true)] + public int CheckQuantity + { + get => checkQuantity; + set + { + if (value > Quantity - hasCheckNum) + { + throw new ArgumentException("核销数量不能大于取药数量"); + } + //退空瓶 + ReturnQuantity2 = value + hasCheckNum; + //退药量 + ReturnQuantity1 = Quantity - value - hasCheckNum; + SetProperty(ref checkQuantity, value); + } + } + + [Navigate(NavigateType.OneToMany, nameof(SurgicalScheduleDetail.GetRecordId))] + public List _SurgicalScheduleDetailLst { get; set; } } } diff --git a/DM_Weight/Models/OrderInfo.cs b/DM_Weight/Models/OrderInfo.cs index c073e2e..d13386b 100644 --- a/DM_Weight/Models/OrderInfo.cs +++ b/DM_Weight/Models/OrderInfo.cs @@ -184,6 +184,14 @@ namespace DM_Weight.Models [SugarColumn(ColumnName = "apply_status")] public int ApplyStatus { get;set; } + + /// + /// + /// 默认值: NULL + /// + [SugarColumn(ColumnName = "machine_id")] + public string MachineId { get; set; } + /// /// /// 默认值: NULL diff --git a/DM_Weight/Models/SurgicalSchedule.cs b/DM_Weight/Models/SurgicalSchedule.cs new file mode 100644 index 0000000..457a9f0 --- /dev/null +++ b/DM_Weight/Models/SurgicalSchedule.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; + +namespace DM_Weight.Models +{ + [SugarTable("surgical_schedule")] + public class SurgicalSchedule + { + /// + /// 主键 + /// + [SugarColumn(ColumnName = "id", IsPrimaryKey = true)] + public int Id { get; set; } + + /// + /// 手术ID + /// + [SugarColumn(ColumnName = "operation_id")] + public string OperationId { get; set; } + /// + /// 患者id + /// + [SugarColumn(ColumnName = "patient_id")] + public string PatientId { get; set; } + /// + /// 患者姓名 + /// + [SugarColumn(ColumnName = "patient_name")] + public string PName { get; set; } + /// + /// 住院号 + /// + [SugarColumn(ColumnName = "hospital_no")] + public string HospitalNo { get; set; } + /// + /// 床号 + /// + [SugarColumn(ColumnName = "bed_no")] + public string BedNo { get; set; } + /// + /// 性别 + /// + [SugarColumn(ColumnName = "sex")] + public string Sex { get; set; } + /// + /// 年龄 + /// + [SugarColumn(ColumnName = "age")] + public string Age { get; set; } + /// + /// 出生日期 + /// + [SugarColumn(ColumnName = "birthday")] + public DateTime Birthday { get; set; } + /// + /// 身份证号 + /// + [SugarColumn(ColumnName = "id_number")] + public string IdNumber { get; set; } + /// + /// 住院病区 + /// + [SugarColumn(ColumnName = "ward_code")] + public string WardCode { get; set; } + + /// + /// 联系电话 + /// + [SugarColumn(ColumnName = "link_tel")] + public string LinkTel { get; set; } + + /// + /// 联系地址 + /// + [SugarColumn(ColumnName = "link_addr")] + public string LinkAddr { get; set; } + + /// + /// 入院日期 + /// + [SugarColumn(ColumnName = "in_date")] + public string Indate { get; set; } + + /// + /// 入院诊断 + /// + [SugarColumn(ColumnName = "in_diagnosis")] + public string Indiagnosis { get; set; } + + /// + /// 医生姓名 + /// + [SugarColumn(ColumnName = "doctor_name")] + public string DoctorName { get; set; } + + /// + /// 手术间代码 + /// + [SugarColumn(ColumnName = "op_room_code")] + public string OpRoomCode { get; set; } + + /// + /// 手术间名称 + /// + [SugarColumn(ColumnName = "op_room_name")] + public string OpRoomName { get; set; } + + /// + /// 麻醉医生编码 + /// + [SugarColumn(ColumnName = "ana_doctor_code")] + public string AnaDoctorCode { get; set; } + + /// + /// 麻醉医生姓名 + /// + [SugarColumn(ColumnName = "ana_doctor_name")] + public string AnaDoctorName { get; set; } + + /// + /// 手术开始时间 + /// + [SugarColumn(ColumnName = "begin_time")] + public DateTime BeginTime { get; set; } + + /// + /// 手术计划开始时间 + /// + [SugarColumn(ColumnName = "schedule_time")] + public DateTime ScheduleTime { get; set; } + + /// + /// 手术完成时间 + /// + [SugarColumn(ColumnName = "end_time")] + public DateTime EndTime { get; set; } + + /// + /// 数据插入时间 + /// + [SugarColumn(ColumnName = "insert_time")] + public DateTime InsertTime { get; set; } + + /// + /// 最后一次更新时间 + /// + [SugarColumn(ColumnName = "update_time")] + public DateTime UpdateTime { get; set; } + + /// + /// HIS状态1:新开2:作废 + /// + [SugarColumn(ColumnName = "his_state")] + public int HisState { get; set; } + + /// + ///取药状态0未取1已取2已还 + /// + [SugarColumn(ColumnName = "dm_status")] + public int DmStatus { get; set; } + + + [SugarColumn(ColumnName = "anaesthesia")] + public string Anaesthesia { get; set; } + + + [Navigate(NavigateType.OneToMany, nameof(SurgicalSchedule.OperationId))] + public SurgicalScheduleDetail _SurgicalScheduleDetail { get; set; } + + + } +} diff --git a/DM_Weight/Models/SurgicalScheduleDetail.cs b/DM_Weight/Models/SurgicalScheduleDetail.cs new file mode 100644 index 0000000..4c59a66 --- /dev/null +++ b/DM_Weight/Models/SurgicalScheduleDetail.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; + +namespace DM_Weight.Models +{ + [SugarTable("surgical_schedule_detail")] + public class SurgicalScheduleDetail + { + /// + /// 主键 + /// + [SugarColumn(ColumnName = "id",IsPrimaryKey =true)] + public int Id { get; set; } + + /// + /// 手术id + /// + [SugarColumn(ColumnName = "operation_id")] + public string OperationId { get; set; } + + /// + /// 取药记录id + /// + [SugarColumn(ColumnName = "get_record_id")] + public int GetRecordId { get; set; } + + /// + /// 处方数量 + /// + [SugarColumn(ColumnName = "quantity")] + public int Quantity { get; set; } + + /// + /// 药品id + /// + [SugarColumn(ColumnName = "drug_id")] + public string DrugId { get; set; } + + /// + /// 批次 + /// + [SugarColumn(ColumnName = "manu_no")] + public string ManuNo { get; set; } + + /// + /// 效期 + /// + [SugarColumn(ColumnName = "eff_date")] + public string EffDate { get;set; } + + /// + /// 状态 + /// + [SugarColumn(ColumnName = "status")] + public int Status { get; set; } + + /// + /// 操作人 + /// + [SugarColumn(ColumnName = "insert_user_id")] + public int? InsertUserId { get; set; } + + } +} diff --git a/DM_Weight/ReportTemp/ReturnEmptyDistory_template.grf b/DM_Weight/ReportTemp/ReturnEmptyDistory_template.grf index 9b5ac42..9e93c00 100644 --- a/DM_Weight/ReportTemp/ReturnEmptyDistory_template.grf +++ b/DM_Weight/ReportTemp/ReturnEmptyDistory_template.grf @@ -400,7 +400,7 @@ "Parameter":[ { "Name":"machine_id", - "Value":"DM1" + "Value":"DM3" } ], "ReportHeader":[ diff --git a/DM_Weight/ReportTemp/machine_log_add.grf b/DM_Weight/ReportTemp/machine_log_add.grf index bf9031e..18d3c52 100644 --- a/DM_Weight/ReportTemp/machine_log_add.grf +++ b/DM_Weight/ReportTemp/machine_log_add.grf @@ -252,7 +252,7 @@ }, { "Name":"machine_id", - "Value":"DM1" + "Value":"DM3" } ], "ReportHeader":[ diff --git a/DM_Weight/ReportTemp/machine_log_check.grf b/DM_Weight/ReportTemp/machine_log_check.grf index 09cc4ae..a1d12a3 100644 --- a/DM_Weight/ReportTemp/machine_log_check.grf +++ b/DM_Weight/ReportTemp/machine_log_check.grf @@ -252,7 +252,7 @@ }, { "Name":"machine_id", - "Value":"DM1" + "Value":"DM3" } ], "ReportHeader":[ diff --git a/DM_Weight/ReportTemp/machine_log_return.grf b/DM_Weight/ReportTemp/machine_log_return.grf index 493f661..35b4421 100644 --- a/DM_Weight/ReportTemp/machine_log_return.grf +++ b/DM_Weight/ReportTemp/machine_log_return.grf @@ -252,7 +252,7 @@ }, { "Name":"machine_id", - "Value":"DM1" + "Value":"DM3" } ], "ReportHeader":[ diff --git a/DM_Weight/ReportTemp/machine_log_take.grf b/DM_Weight/ReportTemp/machine_log_take.grf index 32fe037..e0cb07b 100644 --- a/DM_Weight/ReportTemp/machine_log_take.grf +++ b/DM_Weight/ReportTemp/machine_log_take.grf @@ -252,7 +252,7 @@ }, { "Name":"machine_id", - "Value":"DM1" + "Value":"DM3" } ], "ReportHeader":[ diff --git a/DM_Weight/ReportTemp/orderUse_template.grf b/DM_Weight/ReportTemp/orderUse_template.grf index b9b956d..ff9502f 100644 --- a/DM_Weight/ReportTemp/orderUse_template.grf +++ b/DM_Weight/ReportTemp/orderUse_template.grf @@ -602,7 +602,7 @@ }, { "Name":"machine_id", - "Value":"DM1" + "Value":"DM3" } ], "ReportHeader":[ diff --git a/DM_Weight/ReportTemp/stock_template.grf b/DM_Weight/ReportTemp/stock_template.grf index 6a2d5fb..ce38bbc 100644 --- a/DM_Weight/ReportTemp/stock_template.grf +++ b/DM_Weight/ReportTemp/stock_template.grf @@ -314,7 +314,7 @@ "Parameter":[ { "Name":"machine_id", - "Value":"DM1" + "Value":"DM3" } ], "ReportHeader":[ diff --git a/DM_Weight/ViewModels/AddDrugControlViewModel.cs b/DM_Weight/ViewModels/AddDrugControlViewModel.cs index a332048..4511402 100644 --- a/DM_Weight/ViewModels/AddDrugControlViewModel.cs +++ b/DM_Weight/ViewModels/AddDrugControlViewModel.cs @@ -101,7 +101,7 @@ namespace DM_Weight.ViewModels } void DoMyPrismEvent(DeviceMsg msg) { - if (msg.WindowName == "DrawerAddDrugWindow") + if (msg.WindowName == "AddDrugControl") { switch (msg.EventType) { @@ -140,10 +140,6 @@ namespace DM_Weight.ViewModels } } - if (msg.WindowName == "AddDrugControl") - { - - } } @@ -188,8 +184,7 @@ namespace DM_Weight.ViewModels get => new DelegateCommand(() => { Status = 1; - _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); - + _portUtil.SpeakAsync($"正在打开" + DrawerNo + "号抽屉"); try { //List singleChannels = ChannelStocks.FindAll(it => it.BoardType != 1); diff --git a/DM_Weight/ViewModels/AddSurgeryDialogViewModel.cs b/DM_Weight/ViewModels/AddSurgeryDialogViewModel.cs new file mode 100644 index 0000000..5e0ac9e --- /dev/null +++ b/DM_Weight/ViewModels/AddSurgeryDialogViewModel.cs @@ -0,0 +1,949 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.select; +using DM_Weight.util; +using log4net; +using MaterialDesignThemes.Wpf; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace DM_Weight.ViewModels +{ + public class AddSurgeryDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime + { + public string Title => "录入手术"; + + public bool KeepAlive => false; + + private List machineRecordList; + public List MachineRecordList { get => machineRecordList; set => SetProperty(ref machineRecordList, value); } + + private SolidColorBrush _colorBrush; + + public SolidColorBrush SnackbarBackground + { + get => _colorBrush; + set => SetProperty(ref _colorBrush, value); + } + + private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3)); + + public ISnackbarMessageQueue SnackbarMessageQueue + { + get => _snackbarMessageQueue; + set => SetProperty(ref _snackbarMessageQueue, value); + } + + + private string? _searchValue; + + /// + /// 查询条件 查询字段值 + /// + public string? SearchValue + { + get { return _searchValue; } + set + { + SetProperty(ref _searchValue, value); + RequestData(); + } + } + + 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 static List> keyValuePairs = new List>() + { + new Dictionary(){ {0,"男"} },new Dictionary(){ { 1, "女" } } + }; + public List> SexKeyValue + { + get { return keyValuePairs; } + set { SetProperty(ref keyValuePairs, value); } + } + private Dictionary _selectedSex = keyValuePairs[0]; + public Dictionary SelectedSex + { + get => _selectedSex; + set => SetProperty(ref _selectedSex, value); + } + + private SurgicalSchedule surgicalSchedule = new SurgicalSchedule(); + + public SurgicalSchedule _SurgicalSchedule + { + get => surgicalSchedule; + set => SetProperty(ref surgicalSchedule, 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); + RequestData(); + } + } + + private int _pageCount = 1; + public int PageCount + { + get => _pageCount; + set + { + SetProperty(ref _pageCount, value); + } + } + + private int _pageSize = 5; + public int PageSize + { + get => _pageSize; + set + { + SetProperty(ref _pageSize, value); + } + } + + private int _status = 0; + + public int Status + { + get => _status; set => SetProperty(ref _status, value); + } + + + List ReturnStockLst; + + private IEnumerable> enumerable; + private IEnumerator> enumerator; + + private OrderTakeSelect _selectedItem = StaticSelects[0]; + /// + /// 查询条件 查询字段 + /// + public OrderTakeSelect SelectedItem + { + get { return _selectedItem; } + set + { + SetProperty(ref _selectedItem, value); + RequestData(); + } + } + + private MachineRecord selectedRecord; + public MachineRecord SelectedRecord { get => selectedRecord; set => SetProperty(ref selectedRecord, value); } + + + private static readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + private readonly ILog logger = LogManager.GetLogger(typeof(OrderTakeDialogViewModel)); + + + public event Action RequestClose; + + public bool CanCloseDialog() + { + return Status == 0; + } + + public void OnDialogClosed() + { + // 取消消息订阅 + _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + + public void OnDialogOpened(IDialogParameters parameters) + { + _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + RequestData(); + } + private PortUtil _portUtil; + IEventAggregator _eventAggregator; + IDialogService _dialogService; + public AddSurgeryDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService DialogService) + { + surgicalSchedule.ScheduleTime= DateTime.Now; + _SurgicalSchedule.Indate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + _dialogService = DialogService; + _portUtil = portUtil; + _eventAggregator = eventAggregator; + } + public async void RequestData() + { + int totalCount = 0; + MachineRecordList = SqlSugarHelper.Db.Queryable() + .Includes(mr => mr.DrugInfo) + .Includes(mr => mr.User) + .Includes(mr => mr._SurgicalScheduleDetailLst) + .Where(mr => mr.Type == 2) + .Where(mr => mr.Status < 2) + .Where(mr => mr.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) + //.WhereIF(QueryDate != null, mr => mr.OperationTime.ToString("yyyy-MM-dd") == QueryDate) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (mr) => mr.DrugInfo.DrugId.ToString().Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (mr) => mr.DrugInfo.DrugName.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (mr) => mr.DrugInfo.PyCode.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (mr) => mr.DrugInfo.DrugBarcode.Contains(SearchValue)) + .OrderBy(mr => mr.OperationTime) + .ToPageList(PageNum, PageSize, ref totalCount); + + MachineRecordList.ForEach(mr => mr.HasCheckNum = mr._SurgicalScheduleDetailLst.Sum(sd => sd.Quantity)); + TotalCount = totalCount; + } + + public DelegateCommand BtnCloseCommand + { + get => new DelegateCommand(() => + { + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + }); + } + + /// + /// 选中行事件 + /// + public DelegateCommand RowSelected + { + get => new DelegateCommand(() => + { + if (SelectedRecord != null && selectedRecord.Id != null) + { + MachineRecordList = MachineRecordList.Select(x => + { + if (x.Id == SelectedRecord.Id) + { + x.IsSelected = !x.IsSelected; + if (x.IsSelected) + { + if (SelectedRecord._SurgicalScheduleDetailLst != null && SelectedRecord._SurgicalScheduleDetailLst.Count > 0) + { + //已经核销数 + int HasCheckNum = SelectedRecord._SurgicalScheduleDetailLst.Sum(sd => sd.Quantity); + x.CheckQuantity = SelectedRecord.Quantity - HasCheckNum; + x.ReturnQuantity1 = SelectedRecord.Quantity - HasCheckNum - x.CheckQuantity; + x.ReturnQuantity2 = HasCheckNum + x.CheckQuantity; + } + else + { + x.CheckQuantity = SelectedRecord.Quantity; + x.ReturnQuantity1 = 0; + x.ReturnQuantity2 = SelectedRecord.Quantity; + } + } + else + { + x.CheckQuantity = 0; + x.ReturnQuantity1 = 0; + x.ReturnQuantity2 = 0; + } + } + return x; + }).ToList(); + + + } + }); + } + + /// + /// 保存并核销 + /// + public DelegateCommand AddSurgeryCommand + { + get => new DelegateCommand(() => + { + if (!string.IsNullOrEmpty(_SurgicalSchedule.OperationId)) + { + //检查是否有该手术号,手术号不能重复 + int iCount= SqlSugarHelper.Db.Queryable().Where(ss => ss.OperationId == _SurgicalSchedule.OperationId).Count(); + if(iCount>0) + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("该手术号已添加,请勿重复创建"); + return; + } + List RecordsLst = MachineRecordList.FindAll(rl => rl.IsSelected && rl.CheckQuantity > 0).ToList(); + if (RecordsLst.Count > 0) + { + + //string operationId = Guid.NewGuid().ToString(); + var f = SqlSugarHelper.Db.UseTran(() => + { + SqlSugarHelper.Db.Insertable(new SurgicalSchedule() + { + PName = _SurgicalSchedule.PName, + Sex = SelectedSex.ContainsKey(0) is true ? SelectedSex[0] : SelectedSex[1], + Age = _SurgicalSchedule.Age, + IdNumber = _SurgicalSchedule.IdNumber, + OpRoomCode = _SurgicalSchedule.OpRoomCode, + OpRoomName = _SurgicalSchedule.OpRoomName, + OperationId = _SurgicalSchedule.OperationId, + ScheduleTime = _SurgicalSchedule.ScheduleTime, + InsertTime=DateTime.Now, + Indiagnosis=_SurgicalSchedule.Indiagnosis, + Indate=_SurgicalSchedule.Indate, + DmStatus = 1, + }).ExecuteCommand(); + for (int i = 0; i < RecordsLst.Count; i++) + { + SqlSugarHelper.Db.Insertable(new SurgicalScheduleDetail() + { + OperationId = _SurgicalSchedule.OperationId, + GetRecordId = RecordsLst[i].Id, + Quantity = RecordsLst[i].CheckQuantity, + DrugId = RecordsLst[i].DrugId, + ManuNo = RecordsLst[i].ManuNo, + EffDate = RecordsLst[i].EffDate.ToString(), + InsertUserId = HomeWindowViewModel.Operator?.Id, + }).ExecuteCommand(); + + int hasQuantity = RecordsLst[i]._SurgicalScheduleDetailLst.Sum(sd => sd.Quantity); + int dmStatus = 0; + //已经全部挂上钩,修改dm_machine_record状态为完成 + //if (hasQuantity + RecordsLst[i].CheckQuantity == RecordsLst[i].Quantity) + //{ + // dmStatus = 2; + //} + //else + { + dmStatus = 1; + } + SqlSugarHelper.Db.Updateable(new MachineRecord() + { + Status = dmStatus, + Id = RecordsLst[i].Id + }).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.Id }).ExecuteCommand(); + + + } + }); + if (f.IsSuccess) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "核销完成", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("核销异常,未核销数据"); + } + } + else + { + int iRet = SqlSugarHelper.Db.Insertable(new SurgicalSchedule() + { + PName = _SurgicalSchedule.PName, + Sex = SelectedSex.ContainsKey(0) is true ? SelectedSex[0] : SelectedSex[1], + Age = _SurgicalSchedule.Age, + IdNumber = _SurgicalSchedule.IdNumber, + OpRoomCode = _SurgicalSchedule.OpRoomCode, + OpRoomName = _SurgicalSchedule.OpRoomName, + OperationId = _SurgicalSchedule.OperationId, + ScheduleTime= _SurgicalSchedule.ScheduleTime, + Indiagnosis = _SurgicalSchedule.Indiagnosis, + Indate = _SurgicalSchedule.Indate, + InsertTime = DateTime.Now, + DmStatus = 0, + HisState=1 + }).ExecuteCommand(); + if (iRet > 0) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "手术录入成功,未核销药品", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + + } + else + { + + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("手术录入失败"); + } + } + } + else + { + + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("手术号不能为空"); + } + }); + } + /// + /// 全部归还(还药、还空瓶) + /// + public DelegateCommand ReturnCommand + { + get => new DelegateCommand(() => + { + List RecordsLst = MachineRecordList.FindAll(rl => rl.IsSelected && rl.CheckQuantity == 0).ToList(); + ReturnStockLst = new List(); + if (RecordsLst.Count > 0) + { + + //待还药的记录 + List ReturnDrugLst = RecordsLst.Where(rl => rl.ReturnQuantity1 > 0).ToList(); + //待还空瓶的记录 + List ReturnEmptyLst = RecordsLst.Where(rl => rl.ReturnQuantity2 > 0).ToList(); + + + for (int i = 0; i < ReturnDrugLst.Count; i++) + { + ChannelStock queryData = SqlSugarHelper.Db.Queryable() + .Includes(cs => cs.DrugInfo) + .Where(cs => cs.DrugId == ReturnDrugLst[i].DrugId) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) + .Where(cs => cs.ManuNo == ReturnDrugLst[i].ManuNo) + .OrderBy(cs => cs.Quantity).First(); + if (queryData != null) + { + queryData.AddQuantity = ReturnDrugLst[i].ReturnQuantity1; + queryData.MachineRecordId = ReturnDrugLst[i].Id; + ReturnStockLst.Add(queryData); + } + } + for (int j = 0; j < ReturnEmptyLst.Count; j++) + { + ChannelStock queryData = SqlSugarHelper.Db.Queryable() + .Includes(cs => cs.DrugInfo) + .Where(cs => cs.DrugId == ReturnEmptyLst[j].DrugId) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) + //.Where(cs => cs.ManuNo == ReturnEmptyLst[j].ManuNo) + .Where(cs => cs.DrawerType == 2) + .OrderBy(cs => cs.Quantity).First(); + if (queryData != null) + { + queryData.ReturnQuantity = ReturnEmptyLst[j].ReturnQuantity2; + queryData.MachineRecordId = ReturnEmptyLst[j].Id; + ReturnStockLst.Add(queryData); + } + } + if (ReturnStockLst != null && ReturnStockLst.Count > 0) + { + ReturnStockLst = ReturnStockLst.OrderBy(cls => cls.DrawerNo).ToList(); + //还药时AddQuantity有值;还空瓶时ReturnQuantity有值 + enumerable = ReturnStockLst.GroupBy(cs => cs.DrawerNo, cs => cs); + enumerator = enumerable.GetEnumerator(); + enumerator.MoveNext(); + Status = 1; + OpenOneByOne(); + } + else + { + + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("选中数据未绑定库位,请先进行绑定库位"); + } + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("未选中数据,或选中数据核销数量不为0"); + } + }); + } + /// + /// 刷新 + /// + public DelegateCommand QueryCommand + { + get => new DelegateCommand(() => + { + RequestData(); + }); + } + void DoMyPrismEvent(DeviceMsg msg) + { + + if (msg.WindowName == "SurgeryTakeWindow") + { + 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; + + //保存数据 + + //TakeFinish(); + } + } + 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 void OpenOneByOne() + { + IGrouping grouping = enumerator.Current; + int DrawerNo = grouping.Key; + List channelStocks = grouping.ToList(); + channelStocks.ForEach(it => it.process = 1); + + string drugName = channelStocks[0].DrugInfo.DrugName; + + int drugQuantity = channelStocks.Sum(cs => cs.AddQuantity); + + int emptyQuantity = channelStocks.Sum(cs => cs.ReturnQuantity); + string speakTxt = $"正在打开{DrawerNo}号抽屉,请将{drugName}的"; + if (drugQuantity > 0) + { + speakTxt += $"{drugQuantity}个药放入抽屉!"; + } + if (emptyQuantity > 0) + { + speakTxt += $"{emptyQuantity}个空瓶放入抽屉!"; + } + _portUtil.SpeakAsync(speakTxt); + + //List singleChannels = channelStocks.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 = "SurgeryTakeWindow"; + _portUtil.BoardType = channelStocks.Count > 0 ? channelStocks[0].BoardType : 1; + _portUtil.ColNos = channelStocks.Select(it => it.ColNo).ToArray(); + _portUtil.DrawerNo = DrawerNo; + _portUtil.Start(); + } + + + private bool _isFinishClick = false; + + public bool IsFinishClick { get => _isFinishClick; set => SetProperty(ref _isFinishClick, value); } + //完成 + private void TakeFinish() + { + IsFinishClick = true; + bool bRet = false; + var f = SqlSugarHelper.Db.UseTran(() => + { + for (int i = 0; i < ReturnStockLst.Count; i++) + { + ChannelStock it = ReturnStockLst[i]; + int quantity = 0; + if (it.AddQuantity > 0) //还药 + { + quantity = it.AddQuantity; + bRet = ReturnDrug(it); + + } + else + { + quantity = it.ReturnQuantity; + bRet = ReturnEmpty(it); + } + if (!bRet) + { + break; + } + // 更新屏显库存 + if (it.BoardType == 5) + { + _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + quantity); + } + + AlertMsg alertMsg = new AlertMsg + { + Message = "操作完成,库存已更新", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + } + return bRet; + }); + if (!f.IsSuccess || !f.Data) + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("库存更新失败!"); + + } + Status = 0; + IsFinishClick = false; + RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); + } + /// + /// 还药 + /// + private bool ReturnDrug(ChannelStock stock) + { + try + { + var f = SqlSugarHelper.Db.UseTran(() => + { + string InvoiceId = "RETURN_" + CurrentTimeMillis(); ; + MachineRecord recordInfo = SqlSugarHelper.Db.Queryable().Where(rd => rd.Id == stock.MachineRecordId).First(); + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = stock.Quantity + stock.AddQuantity, + Id = stock.Id, + }).UpdateColumns(it => new { it.Quantity }).ExecuteCommand(); + // 获取更新完库存后的药品库存 + List nowChannels = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId.Equals(stock.MachineId)) + .Where(cs => cs.DrugId.Equals(stock.DrugId)) + .Where(cs => cs.DrawerType == 1) + .ToList(); + // 更新数据 取药记录 设置还药数量、状态 + SqlSugarHelper.Db.Updateable(new MachineRecord() + { + ReturnQuantity1 = recordInfo.ReturnQuantity1 + stock.AddQuantity, + Id = recordInfo.Id, + Status = (recordInfo.CanReturnQuantity - stock.AddQuantity) == 0 ? 2 : 1, + }).UpdateColumns(it => new { it.ReturnQuantity1, it.Status }).ExecuteCommand(); + + // 保存数据 还药记录 + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = stock.MachineId, + DrawerNo = stock.DrawerNo, + ColNo = stock.ColNo, + DrugId = stock.DrugId, + ManuNo = stock.ManuNo, + EffDate = !String.IsNullOrEmpty(stock.EffDate) ? DateTime.ParseExact(stock.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + OperationTime = DateTime.Now, + Quantity = stock.AddQuantity, + Type = 31, + InvoiceId = InvoiceId, + GetId = stock.MachineRecordId + //,StockQuantity = nowChannels.Sum(it => it.Quantity) + }).ExecuteCommand(); + + //保存账册 + SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(stock.DrugId), + Type = 1, + Department = ConfigurationManager.AppSettings["department"].ToString(), + InvoiceNo = InvoiceId, + ManuNo = stock.ManuNo, + EffDate = stock.EffDate, + AddQuantity = stock.AddQuantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + CreateTime = DateTime.Now + + }).ExecuteCommand(); + //修改凌晨生成的日结存数据 + AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(stock.MachineId)) + .Where(ab => ab.Type == 3) + .Where(ab => ab.DrugId == Convert.ToInt32(stock.DrugId)) + .Where(ab => ab.ManuNo == stock.ManuNo) + .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + stock.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(stock.DrugId), + Type = 3, + ManuNo = stock.ManuNo, + EffDate = stock.EffDate, + YQuantity = 0, + ManuStock = stock.ReturnQuantity, + TotalStock = stock.ReturnQuantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + InvoiceNo = "日结存" + }).ExecuteCommand(); + if (iDayResult <= 0) + { + logger.Info($"未写入日结存数据{stock.DrugId}-{stock.ManuNo}-{stock.EffDate}-{stock.AddQuantity}"); + } + } + //修改凌晨生成的总结存数据 + AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(stock.MachineId)) + .Where(ab => ab.Type == 4) + .Where(ab => ab.DrugId == Convert.ToInt32(stock.DrugId)) + .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + stock.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(stock.DrugId), + Type = 4, + YQuantity = 0, + ManuStock = stock.ReturnQuantity, + TotalStock = stock.ReturnQuantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + InvoiceNo = "总结存" + }).ExecuteCommand(); + if (iTotalResult <= 0) + { + logger.Info($"未写入总结存数据{stock.DrugId}-{stock.AddQuantity}"); + } + } + }); + if (f.IsSuccess) + { + return true; + } + else + { + return false; + } + } + catch (Exception) + { + + throw; + } + } + /// + /// 还空瓶 + /// + private bool ReturnEmpty(ChannelStock stock) + { + string InvoiceId = "RETURN_" + CurrentTimeMillis(); + var f = SqlSugarHelper.Db.UseTran(() => + { + + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = stock.Quantity + stock.ReturnQuantity, + Id = stock.Id, + }).UpdateColumns(it => new { it.Quantity }).ExecuteCommand(); + + // 获取更新完库存后的药品库存 + List nowChannels = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId.Equals(stock.MachineId)) + .Where(cs => cs.DrugId.Equals(stock.DrugId)) + .Where(cs => cs.DrawerType == 1) + .ToList(); + + MachineRecord recordInfo = SqlSugarHelper.Db.Queryable().Where(rd => rd.Id == stock.MachineRecordId).First(); + + // 更新数据 取药记录 设置还药数量、状态 + SqlSugarHelper.Db.Updateable(new MachineRecord() + { + ReturnQuantity2 = stock.ReturnQuantity, + Id = recordInfo.Id, + Status = 2, + }).UpdateColumns(it => new { it.ReturnQuantity2, it.Status }).ExecuteCommand(); + + // 保存数据 还药空瓶记录 + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = stock.MachineId, + DrawerNo = stock.DrawerNo, + ColNo = stock.ColNo, + DrugId = stock.DrugId, + ManuNo = stock.ManuNo, + EffDate = !String.IsNullOrEmpty(stock.EffDate) ? DateTime.ParseExact(stock.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + Reviewer = HomeWindowViewModel.Reviewer?.Id, + OperationTime = DateTime.Now, + Quantity = stock.ReturnQuantity, //ReturnQuantity, + Type = 32, + InvoiceId = InvoiceId, + GetId = stock.MachineRecordId + //,StockQuantity = nowChannels.Sum(it => it.Quantity) + }).ExecuteCommand(); + + return true; + }); + + if (!f.IsSuccess || !f.Data) + { + return false; + } + else + { + return true; + } + } + public long CurrentTimeMillis() + { + return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; + } + /// + /// 取消 + /// + public DelegateCommand CancleTake + { + get => new DelegateCommand(() => + { + _portUtil.ResetData(); + Status = 0; + }); + } + // 完成按钮 + public DelegateCommand TakeFinishCommand + { + get => new DelegateCommand(TakeFinish); + } + + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + //if(dialogResult.Result == ButtonResult.OK) + //{ + // 关闭当前窗口 + //RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + //} + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } + } +} diff --git a/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs b/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs index 65e6475..6d84af0 100644 --- a/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs +++ b/DM_Weight/ViewModels/ApplyInStockWindowViewModel.cs @@ -256,7 +256,18 @@ namespace DM_Weight.ViewModels int DrawerNo = grouping.Key; List channelStocks = grouping.ToList(); channelStocks.ForEach(it => it.process = 1); - _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + + + + IEnumerable strDrugName = channelStocks.Select(cs => cs.DrugInfo.DrugName); + string strNames = string.Empty; + foreach (string name in strDrugName) + { + strNames += name; + } + int sumQuantity = channelStocks.Sum(cs => cs.AddQuantity); + + _portUtil.SpeakAsync($"正在打开{DrawerNo}号抽屉,请加药{strNames},数量共计{sumQuantity}"); List singleChannels = new List(); for (int i = 0; i < channelStocks.Count; i++) { @@ -330,7 +341,7 @@ namespace DM_Weight.ViewModels { if (SelectDrugPleaseClaim.GetQuantity == 1) { - if (SelectDrugPleaseClaim.DrugManuNo is null) + if (SelectDrugPleaseClaim._DrugManuNos is null) { AlertMsg alertMsg = new AlertMsg { @@ -341,13 +352,12 @@ namespace DM_Weight.ViewModels return; } //请领单里只有一种药 - List drugManuInfoList = JsonConvert.DeserializeObject>(SelectDrugPleaseClaim.DrugManuNo); + List drugManuInfoList = JsonConvert.DeserializeObject>(SelectDrugPleaseClaim._DrugManuNos); drugManuInfoList.ForEach(dm => dm.DrugId = SelectDrugPleaseClaim.DrugId); for (int i = 0; i < drugManuInfoList.Count; i++) { DrugPleaseManuNo drugPleaseManuNo = drugManuInfoList[i]; - ChannelStock q = SqlSugarHelper.Db.Queryable() .Includes(cs => cs.DrugInfo) .WhereIF(!string.IsNullOrEmpty(drugPleaseManuNo.EffDate), cs => cs.EffDate.Equals(drugPleaseManuNo.EffDate)) @@ -383,7 +393,7 @@ namespace DM_Weight.ViewModels { foreach (DrugPleaseClaim item in pleaseClaimList) { - List drugManuInfoList = JsonConvert.DeserializeObject>(item.DrugManuNo); + List drugManuInfoList = JsonConvert.DeserializeObject>(item._DrugManuNos); drugManuInfoList.ForEach(dm => dm.DrugId = item.DrugId); for (int i = 0; i < drugManuInfoList.Count; i++) { @@ -453,7 +463,7 @@ namespace DM_Weight.ViewModels if (OrderDate != null) { - sb.Append(" and i.do_date = @CreateTime "); + sb.Append(" and DATE_FORMAT(i.do_date,'%Y-%m-%d') = @CreateTime "); } if (!String.IsNullOrEmpty(SearchValue)) { diff --git a/DM_Weight/ViewModels/ApplyListWindowViewModel.cs b/DM_Weight/ViewModels/ApplyListWindowViewModel.cs index 0469b63..369f0d6 100644 --- a/DM_Weight/ViewModels/ApplyListWindowViewModel.cs +++ b/DM_Weight/ViewModels/ApplyListWindowViewModel.cs @@ -1,6 +1,7 @@ using DM_Weight.Models; using DM_Weight.select; using DM_Weight.util; +using Newtonsoft.Json; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; @@ -150,11 +151,27 @@ namespace DM_Weight.ViewModels .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (cd) => cd.drugInfo.PyCode.Contains(SearchValue)) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (cd) => cd.drugInfo.DrugBarcode.Contains(SearchValue)) .WhereIF((_DrugPleaseState!=null&& _DrugPleaseState.StateValue>=0),(cd,dp)=>dp.State==_DrugPleaseState.StateValue) - .GroupBy(cd=>cd.Applyid) + .GroupBy(cd=>cd.DrugPleaseClaimId) + .GroupBy(cd => cd.DrugId) .OrderByDescending(cd => cd.Createdate) .OrderByDescending(cd => cd.DrugId) .ToList(); + if (CollectDrugLst != null && CollectDrugLst.Count > 0) + { + for (int i = 0; i < CollectDrugLst.Count; i++) + { + CollectDrugLst[i].ManuNoList = new List(); + DrugPleaseClaim drugManuNoStr = SqlSugarHelper.Db.Queryable().Where(dp => dp.PleaseNo == CollectDrugLst[i].DrugPleaseClaimId && dp.DrugId == CollectDrugLst[i].DrugId).First(); + + CollectDrugLst[i].Quantity = drugManuNoStr.GetQuantity; + if (!string.IsNullOrEmpty(drugManuNoStr._DrugManuNos)) + { + CollectDrugLst[i].ManuNoList = JsonConvert.DeserializeObject>(drugManuNoStr._DrugManuNos); + + } + } + } } /// /// 刷新 diff --git a/DM_Weight/ViewModels/CollectDrugDialogViewModel.cs b/DM_Weight/ViewModels/CollectDrugDialogViewModel.cs index f2b6ea8..a686b75 100644 --- a/DM_Weight/ViewModels/CollectDrugDialogViewModel.cs +++ b/DM_Weight/ViewModels/CollectDrugDialogViewModel.cs @@ -175,7 +175,8 @@ namespace DM_Weight.ViewModels SqlSugarHelper.Db.Updateable(new OrderInfo() { ApplyStatus = 1, - OrderNo = collectDrug.OrderNo + OrderNo = collectDrug.OrderNo, + MachineId= ConfigurationManager.AppSettings["machineId"].ToString(), }).UpdateColumns(it => new { it.ApplyStatus }).Where(it => it.OrderNo == collectDrug.OrderNo).ExecuteCommand(); //保存处方、请领申请中间表 diff --git a/DM_Weight/ViewModels/CollectDrugWindowViewModel.cs b/DM_Weight/ViewModels/CollectDrugWindowViewModel.cs index 5f40ae7..114c3c6 100644 --- a/DM_Weight/ViewModels/CollectDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/CollectDrugWindowViewModel.cs @@ -162,6 +162,39 @@ namespace DM_Weight.ViewModels RequestData(); } } + void RequestData_for_SurgicalShedule() + { + int totalCount = 0; + List queryData = SqlSugarHelper.Db.Queryable() + .InnerJoin((oi, od) => oi.OperationId == od.OperationId) + .InnerJoin((oi, od, di) => od.DrugId == di.DrugId.ToString()) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (oi, od, di) => di.DrugId.ToString() == SearchValue) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (oi, od, di) => di.DrugName.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (oi, od, di) => di.PyCode.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (oi, od, di) => di.DrugBarcode.Contains(SearchValue)) + .Where(oi => oi.DmStatus == 1) + .Where(oi => oi.HisState == 1) + .GroupBy(oi => oi.ScheduleTime) + .Select((oi, od, di) => new CollectDrug + { + PatientId = oi.PatientId, + PName = oi.PName, + Sex = oi.Sex, + Age = oi.Age, + IdNumber = oi.IdNumber, + OrderNo = oi.OperationId, + //DeptName = oi.DeptName, + DrugName = di.DrugName, + Quantity = od.Quantity, + DrugSpec = di.DrugSpec, + Manufactory = di.Manufactory, + DrugId = di.DrugId.ToString(), + }).ToList(); + CollectDrugs = queryData; + TotalCount = totalCount; + PageCount = (int)Math.Ceiling((double)TotalCount / PageSize); + + } void RequestData() { int totalCount = 0; diff --git a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs index 90263bd..81ad5a2 100644 --- a/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerAddDrugWindowViewModel.cs @@ -126,12 +126,26 @@ namespace DM_Weight.ViewModels get => new DelegateCommand(() => { Status = 1; - _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); try { List singleChannels = ChannelStocks.FindAll(it => it.BoardType != 1); + + + IEnumerable strDrugName = ChannelStocks.Select(cs => cs.DrugInfo.DrugName); + string strNames = string.Empty; + foreach (string name in strDrugName) + { + if (!strNames.Contains(name)) + { + strNames += name + "; ;"; + } + } + int sumQuantity = ChannelStocks.Sum(cs => cs.AddQuantity); + _portUtil.SpeakAsync($"正在打开 {DrawerNo} 号抽屉,请加药 {strNames} ,数量共计{sumQuantity}"); + + _portUtil.WindowName = "DrawerAddDrugWindow"; _portUtil.Operate = true; _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; diff --git a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs index 50b9dee..7c79563 100644 --- a/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/DrawerTakeDrugWindowViewModel.cs @@ -136,8 +136,19 @@ namespace DM_Weight.ViewModels if (Status == 0) { Status = 1; - _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + //_portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + IEnumerable strDrugName = ChannelStocks.Select(cs => cs.DrugInfo.DrugName); + string strNames = string.Empty; + foreach (string name in strDrugName) + { + if (!strNames.Contains(name)) + { + strNames += name + ";"; + } + } + int sumQuantity = ChannelStocks.Sum(cs => cs.TakeQuantity); + _portUtil.SpeakAsync($"正在打开 {DrawerNo} 号抽屉,请取药 {strNames} ,数量共计 {sumQuantity}"); List singleChannels = ChannelStocks.FindAll(it => it.BoardType != 1); @@ -360,12 +371,12 @@ namespace DM_Weight.ViewModels if (ConfigurationManager.AppSettings["MultiBatch"].ToString().Equals("1")) { 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(); + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); } else { 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(); + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")).GroupBy(cs => cs.DrawerNo).Select(cs => SqlFunc.AggregateCount(cs.DrawerNo)).Count(); } Is8Drawer = count < 9; Is16Drawer = count >= 16; @@ -386,7 +397,7 @@ namespace DM_Weight.ViewModels .Includes(cs => cs.DrugInfo) .Where(cs => cs.DrawerNo == DrawerNo) .Where(cs => cs.DrugId != null) - .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) .Where(cs => cs.DrawerType == 1) .Where(cs => cs.Quantity > 0) .OrderBy(cs => cs.ColNo) diff --git a/DM_Weight/ViewModels/EditUserDialogViewModel.cs b/DM_Weight/ViewModels/EditUserDialogViewModel.cs index 55621d9..17751bd 100644 --- a/DM_Weight/ViewModels/EditUserDialogViewModel.cs +++ b/DM_Weight/ViewModels/EditUserDialogViewModel.cs @@ -132,7 +132,7 @@ namespace DM_Weight.ViewModels else { UserList.PassWord = MD5.GetMD5Hash(NewPass); - UserList.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; + UserList.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM3"; // 插入 SqlSugarHelper.Db.Insertable(UserList).InsertColumns(u => new { u.Id, u.Nickname, u.UserName, u.PassWord, u.UserBarcode, u.RoleId, u.MachineId }).ExecuteCommand(); } @@ -154,7 +154,7 @@ namespace DM_Weight.ViewModels void GetAllRole() { - Roles = SqlSugarHelper.Db.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"] ?? "DM3")).OrderBy(r => r.Id).ToList(); RaisePropertyChanged("Roles"); } diff --git a/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs b/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs index 37e6a99..97bd037 100644 --- a/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceAddDialogViewModel.cs @@ -189,7 +189,18 @@ namespace DM_Weight.ViewModels int DrawerNo = grouping.Key; List channelStocks = grouping.ToList(); channelStocks.ForEach(it => it.process = 1); - _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + + IEnumerable strDrugName = channelStocks.Select(cs => cs.DrugInfo.DrugName); + string strNames = string.Empty; + foreach (string name in strDrugName) + { + if (!strNames.Contains(name)) + { + strNames += name + " ; "; + } + } + int sumQuantity = channelStocks.Sum(cs => cs.AddQuantity); + _portUtil.SpeakAsync($"正在打开 {DrawerNo} 号抽屉,请加药 {strNames} ,数量共计 {sumQuantity}个"); List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); diff --git a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs index cb0a1be..7b58c76 100644 --- a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs @@ -266,7 +266,17 @@ namespace DM_Weight.ViewModels int DrawerNo = grouping.Key; List channelStocks = grouping.ToList(); channelStocks.ForEach(it => it.process = 1); - _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + IEnumerable strDrugName = channelStocks.Select(cs => cs.DrugInfo.DrugName); + string strNames = string.Empty; + foreach (string name in strDrugName) + { + if (!strNames.Contains(name)) + { + strNames += name + " ; "; + } + } + int sumQuantity = channelStocks.Sum(cs => cs.TakeQuantity); + _portUtil.SpeakAsync($"正在打开 {DrawerNo} 号抽屉,请取药 {strNames} ,数量共计 {sumQuantity}"); List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); diff --git a/DM_Weight/ViewModels/MainWindowViewModel.cs b/DM_Weight/ViewModels/MainWindowViewModel.cs index 25e24a0..22ce93a 100644 --- a/DM_Weight/ViewModels/MainWindowViewModel.cs +++ b/DM_Weight/ViewModels/MainWindowViewModel.cs @@ -16,6 +16,8 @@ using DM_Weight.Finger; using DM_Weight.Views; using Unity; using DM_Weight.HIKVISION; +using log4net.Repository.Hierarchy; +using log4net; namespace DM_Weight.ViewModels { @@ -30,7 +32,7 @@ namespace DM_Weight.ViewModels //private PortUtil _portUtil; - private ScreenUtil _screenUtil; + //private ScreenUtil _screenUtil; public SolidColorBrush Background { @@ -64,16 +66,17 @@ namespace DM_Weight.ViewModels IRegionManager _regionManager; IUnityContainer _container; private CHKFunction _cHKFunction; - public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil, ScreenUtil screenUtil, CHKFunction cHKFunction) + private readonly ILog logger = LogManager.GetLogger(typeof(PortUtil)); + public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil, CHKFunction cHKFunction) { //_portUtil = portUtil; this.eventAggregator = eventAggregator; this.eventAggregator.GetEvent().Subscribe(doMyPrismEvent2); - _screenUtil = screenUtil; _fingerprintUtil = fingerprintUtil; _regionManager = regionManager; _container = container; _cHKFunction = cHKFunction; + System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { @@ -81,6 +84,7 @@ namespace DM_Weight.ViewModels _regionManager.RequestNavigate("MainRegion", "LoginWindow"); })); + } void doMyPrismEvent2(AlertMsg msg) diff --git a/DM_Weight/ViewModels/MultiOrderTakeDrugWindowViewModel.cs b/DM_Weight/ViewModels/MultiOrderTakeDrugWindowViewModel.cs index ad3ab24..6fcebe9 100644 --- a/DM_Weight/ViewModels/MultiOrderTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/MultiOrderTakeDrugWindowViewModel.cs @@ -311,7 +311,7 @@ namespace DM_Weight.ViewModels //} List queryData = SqlSugarHelper.Db.Queryable() .InnerJoin((oi, od) => oi.OrderNo == od.OrderNo) - .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) + .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")).GroupBy(cs => cs.DrugId), (oi, od, t) => od.DrugId == t.DrugId) .WhereIF(OrderDate != null, oi => oi.OrderDate.ToString("yyyy-MM-dd") == OrderDate) .WhereIF(!(OrderDepartment.DeptName.Equals("全部")), oi => oi.DeptName == OrderDepartment.DeptName) //.WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PatientId"), oi => oi.PatientId == SearchValue) diff --git a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs index 21e37f0..c73471e 100644 --- a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs @@ -261,11 +261,24 @@ namespace DM_Weight.ViewModels int DrawerNo = grouping.Key; List channelStocks = grouping.ToList(); channelStocks.ForEach(it => it.process = 1); - _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + //_portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); + + IEnumerable strDrugName = singleChannels.Select(cs => cs.DrugInfo.DrugName); + string strNames = string.Empty; + foreach (string name in strDrugName) + { + if (!strNames.Contains(name)) + { + strNames += name; + } + } + int sumQuantity = singleChannels.Sum(cs => cs.ReturnQuantity); + _portUtil.SpeakAsync($"正在打开{DrawerNo}号抽屉,请加药{strNames},数量共计{sumQuantity}个"); + // 发送还药数量 singleChannels.ForEach(it => { diff --git a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs index e290581..5bace18 100644 --- a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs @@ -169,7 +169,7 @@ namespace DM_Weight.ViewModels { orderDetails = SqlSugarHelper.Db.Queryable() .Includes(od => od.DrugInfo) - .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) + .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")).GroupBy(cs => cs.DrugId), (od, t) => od.DrugId == t.DrugId) .Where(od => od.OrderNo == OrderInfo.OrderNo) .ToList(); @@ -183,7 +183,7 @@ namespace DM_Weight.ViewModels .Includes(cs => cs.DrugInfo) .Where(cs => cs.Quantity > 0) .Where(cs => cs.DrawerType == 1) - .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) .WhereIF(!string.IsNullOrEmpty(orderDetail.SetEffDate), cs => cs.EffDate.Equals(orderDetail.SetEffDate)) .WhereIF(!string.IsNullOrEmpty(orderDetail.SetManuNo), cs => cs.ManuNo.Equals(orderDetail.SetManuNo)) .Where(cs => cs.DrugId == orderDetail.DrugId) @@ -263,7 +263,19 @@ namespace DM_Weight.ViewModels int DrawerNo = grouping.Key; List channelStocks = grouping.ToList(); channelStocks.ForEach(it => it.process = 1); - _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + + + IEnumerable strDrugName = channelStocks.Select(cs => cs.DrugInfo.DrugName); + string strNames = string.Empty; + foreach (string name in strDrugName) + { + if (!strNames.Contains(name)) + { + strNames += name+";"; + } + } + int sumQuantity = channelStocks.Sum(cs => cs.TakeQuantity); + _portUtil.SpeakAsync($"正在打开 {DrawerNo} 号抽屉,请取药 {strNames} ,数量共计 {sumQuantity}"); List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); diff --git a/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs index de3da3e..533e6ee 100644 --- a/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs +++ b/DM_Weight/ViewModels/ReturnDrugDialogViewModel.cs @@ -195,7 +195,10 @@ namespace DM_Weight.ViewModels { Status = 1; - _portUtil.SpeakAsync("正在打开" + ChannelStock.DrawerNo + "号抽屉"); + //_portUtil.SpeakAsync("正在打开" + ChannelStock.DrawerNo + "号抽屉"); + + + _portUtil.SpeakAsync($"正在打开 {ChannelStock.DrawerNo} 号抽屉,请加药 {MachineRecord.DrugInfo.DrugName} ,数量共计 {ReturnQuantity}个"); _portUtil.WindowName = WindowName; _portUtil.BoardType = ChannelStock.BoardType; diff --git a/DM_Weight/ViewModels/ReturnDrugWindow2ViewModel.cs b/DM_Weight/ViewModels/ReturnDrugWindow2ViewModel.cs index 207c0bb..0593bad 100644 --- a/DM_Weight/ViewModels/ReturnDrugWindow2ViewModel.cs +++ b/DM_Weight/ViewModels/ReturnDrugWindow2ViewModel.cs @@ -216,7 +216,7 @@ namespace DM_Weight.ViewModels int totalCount = 0; List queryData = SqlSugarHelper.Db.Queryable() .InnerJoin((oi, od) => oi.OrderNo == od.OrderNo) - .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) + .InnerJoin(SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")).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) diff --git a/DM_Weight/ViewModels/ReturnDrugWindowViewModel.cs b/DM_Weight/ViewModels/ReturnDrugWindowViewModel.cs index ac8733b..374bf99 100644 --- a/DM_Weight/ViewModels/ReturnDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/ReturnDrugWindowViewModel.cs @@ -184,7 +184,7 @@ namespace DM_Weight.ViewModels .Includes(mr => mr.User) .Where(mr => mr.Type == 2) .Where(mr => mr.Status < 2) - .Where(mr => mr.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .Where(mr => mr.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) //.WhereIF(QueryDate != null, mr => mr.OperationTime.ToString("yyyy-MM-dd") == QueryDate) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (mr) => mr.DrugInfo.DrugId.ToString().Contains(SearchValue)) .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (mr) => mr.DrugInfo.DrugName.Contains(SearchValue)) diff --git a/DM_Weight/ViewModels/ReturnEmptyDestoryWindowViewModel.cs b/DM_Weight/ViewModels/ReturnEmptyDestoryWindowViewModel.cs new file mode 100644 index 0000000..de83f89 --- /dev/null +++ b/DM_Weight/ViewModels/ReturnEmptyDestoryWindowViewModel.cs @@ -0,0 +1,310 @@ +using DM_Weight.Models; +using DM_Weight.msg; +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.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.ViewModels +{ + public class ReturnEmptyDestoryWindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime + { + private List? _channelStocks; + + public List? Channels + { + get { return _channelStocks; } + set { SetProperty(ref _channelStocks, value); } + } + + private ChannelStock _channelStock; + + public ChannelStock Channel + { + get { return _channelStock; } + set { SetProperty(ref _channelStock, 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(); + } + } + + IDialogService _dialogService; + IEventAggregator _eventAggregator; + public ReturnEmptyDestoryWindowViewModel(IDialogService dialogService, IEventAggregator eventAggregator) + { + _dialogService = dialogService; + _eventAggregator = eventAggregator; + } + + public DelegateCommand RowSelected + { + get => new DelegateCommand(() => + { + + if (Channel != null && Channel.DrugId == null) + { + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("DrawerNo", Channel.DrawerNo); + DialogServiceExtensions.ShowDialogHost(_dialogService, "BindingChannelDialog", dialogParameters, DoDialogResult, "RootDialog"); + } + else if (Channel != null && Channel.CanReturnQuantity > 0) + { + Channels = Channels.Select(x => + { + if (x.Id == Channel.Id) + { + x.IsSelected = !x.IsSelected; + } + return x; + }).ToList(); + //DialogParameters dialogParameters = new DialogParameters(); + //dialogParameters.Add("channel", Channel); + //DialogServiceExtensions.ShowDialogHost(_dialogService, "ReturnEmptyDialog", dialogParameters, DoDialogResult, "RootDialog"); + } + }); + } + + + private List csList = new List(); + + //销毁 + public DelegateCommand DestoryCommand + { + get => new DelegateCommand(() => + { + if (Channels != null && Channels.Count > 0) + { + csList = Channels.FindAll(it => it.IsSelected && it.Quantity > 0).ToList(); + if (csList != null && csList.Count > 0) + { + //RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + //DialogParameters dialogParameters = new DialogParameters(); + //List msg = new List(); + //msg.Add("确认"); + //msg.Add("确认要销毁吗?"); + //dialogParameters.Add("msgInfo", msg); + //DialogServiceExtensions.ShowDialogHost(_dialogService, "ConfirmMessageDialog", dialogParameters, DestoryDialogResult, "RootDialog"); + var f = SqlSugarHelper.Db.UseTran(() => + { + for (int i = 0; i < csList.Count; i++) + { + ChannelStock channelStock = csList[i]; + channelStock.Quantity = 0; + SqlSugarHelper.Db.Updateable(channelStock).ExecuteCommand(); + MachineRecord machines = SqlSugarHelper.Db.Queryable() + //.InnerJoin((mr, cs) => mr.DrugId == cs.DrugId) + //.Where(mr => mr.DrugId.Contains(csList.Select(it => it.DrugId).ToList()) && mr.Type = 32) + .Where(mr => mr.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) + .Where(mr => mr.DrugId == channelStock.DrugId) + .Where(mr => mr.Type == 32) + .First(); + SqlSugarHelper.Db.Updateable(machines).ReSetValue(mr => + { + mr.IsDestroy = 1; + mr.TakeUser = HomeWindowViewModel.Operator?.Id.ToString(); + mr.DestoryReviewerUser = HomeWindowViewModel.Reviewer?.Id.ToString(); + }).ExecuteCommand(); + } + return true; + }); + + + if (f.Data) + { + + RequestData(); + AlertMsg alertMsg = new AlertMsg + { + Message = "销毁完成", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + if (!f.IsSuccess) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "销毁失败!", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "未勾选要销毁的数据或勾选的数据库存为0", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "没有要操作销毁的数据", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + }); + } + + //空瓶销毁(根据还的空瓶) + public DelegateCommand DestoryEmptyCommand { get => new DelegateCommand(DestoryEmptyAction); } + private void DestoryEmptyAction() + { + //List records = Channels.FindAll(it => it.IsSelected).ToList(); + //if (records.Count > 0) + if (Channel != null && Channel.DrugId != null && Channel.Quantity > 0) + { + + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("channel", Channel); + DialogServiceExtensions.ShowDialogHost(_dialogService, "DestoryEmptyDialog", dialogParameters, DoDialogResult, "RootDialog"); + } + else + { + AlertMsg alertMsg = new AlertMsg + { + Message = "请选择有库存的数据", + Type = MsgType.ERROR, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + } + + } + + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + RequestData(); + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } + + //导出回收销毁记录 + public DelegateCommand DownloadRecordCommand + { + get => new DelegateCommand(() => { + + GridReportUtil.PrintEmptyDestoryReport(StartDate, EndDate); + + }); + } + + public bool KeepAlive => false; + + + public DelegateCommand Query + { + get => new DelegateCommand(() => + { + RequestData(); + }); + } + + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 + public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) + { + continuationCallback(true); + } + + + //接收导航传过来的参数 + public void OnNavigatedTo(NavigationContext navigationContext) + { + //查询表格数据 + RequestData(); + } + + void RequestData() + { + + Channels = SqlSugarHelper.Db.Queryable() + .LeftJoin((cs, di) => cs.DrugId == di.DrugId.ToString()) + .Where((cs) => cs.DrawerType != 1).Where(cs => cs.MachineId == ConfigurationManager.AppSettings["machineId"]) + .Where(cs=>cs.Quantity>0) + .Select((cs, di) => new ChannelStock + { + CanReturnQuantity = SqlFunc.Subqueryable().Where(mr => mr.DrugId == cs.DrugId && mr.MachineId == ConfigurationManager.AppSettings["machineId"]).Where(mr => mr.Type == 2).Where(mr => mr.Status != 2).Select(mr => SqlFunc.IsNull(SqlFunc.AggregateSumNoNull(mr.Quantity - mr.ReturnQuantity1 - mr.ReturnQuantity2), 0)), + DrugInfo = new DrugInfo + { + DrugId = di.DrugId, + DrugName = di.DrugName, + DrugSpec = di.DrugSpec, + Manufactory = di.Manufactory, + PackUnit = di.PackUnit, + }, + Quantity = cs.Quantity + }, true) + .OrderBy(cs => cs.DrawerNo) + .OrderBy(cs => cs.ColNo) + .ToList() + ; + _ = Channels.Count; + } + + //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建 + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + //这个方法用于拦截请求 + public void OnNavigatedFrom(NavigationContext navigationContext) + { + + } + } +} diff --git a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs index b64c3e7..36e1d43 100644 --- a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs +++ b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs @@ -206,6 +206,7 @@ namespace DM_Weight.ViewModels //quyaoChild.Add(mulityOrder); } + quyaoChild.Add(quyao1); quyaoChild.Add(quyao2); quyaoChild.Add(quyao3); @@ -278,10 +279,10 @@ namespace DM_Weight.ViewModels jiayaoChild.Add(jiayao1); jiayaoChild.Add(jiayao2); jiayaoChild.Add(jiayao3); - jiayaoChild.Add(jiayao4); jiayaoChild.Add(jiayao6); jiayaoChild.Add(jiayao7); jiayaoChild.Add(jiayao8); + jiayaoChild.Add(jiayao4); jiayao.Children = jiayaoChild; defaultAll.Add(jiayao); #endregion @@ -305,11 +306,17 @@ namespace DM_Weight.ViewModels PremissionName = "归还药品", PremissionPath = "ReturnDrugWindow2", }; + //PremissionDm huanyao2 = new PremissionDm + //{ + // Id = 32, + // PremissionName = "归还空瓶", + // PremissionPath = "ReturnEmptyWindow", + //}; PremissionDm huanyao2 = new PremissionDm { Id = 32, - PremissionName = "归还空瓶", - PremissionPath = "ReturnEmptyWindow", + PremissionName = "空瓶销毁", + PremissionPath = "ReturnEmptyDestoryWindow", }; PremissionDm huanyao3 = new PremissionDm { @@ -317,8 +324,15 @@ namespace DM_Weight.ViewModels PremissionName = "归还记录", PremissionPath = "ReturnRecordWindow", }; + PremissionDm surgery = new PremissionDm + { + Id = 17, + PremissionName = "手术核销", + PremissionPath = "SurgeryTakeWindow" + }; huanyaoChild.Add(Convert.ToInt32(ConfigurationManager.AppSettings["returnDrugMode"]) == 1 ? huanyao11 : huanyao1); huanyaoChild.Add(huanyao2); + huanyaoChild.Add(surgery); huanyaoChild.Add(huanyao3); huanyao.Children = huanyaoChild; defaultAll.Add(huanyao); @@ -369,10 +383,10 @@ namespace DM_Weight.ViewModels }; kuguanChild.Add(kuguan1); kuguanChild.Add(kuguan2); - kuguanChild.Add(kuguan3); kuguanChild.Add(kuguan4); - kuguanChild.Add(kuguan5); kuguanChild.Add(kuguan6); + kuguanChild.Add(kuguan3); + kuguanChild.Add(kuguan5); kuguan.Children = kuguanChild; defaultAll.Add(kuguan); #endregion diff --git a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs index 7a4770a..9d50c7e 100644 --- a/DM_Weight/ViewModels/SelfAddDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfAddDialogViewModel.cs @@ -183,8 +183,19 @@ namespace DM_Weight.ViewModels int DrawerNo = grouping.Key; List channelStocks = grouping.ToList(); channelStocks.ForEach(it => it.process = 1); - _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + //_portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + IEnumerable strDrugName = channelStocks.Select(cs => cs.DrugInfo.DrugName); + string strNames = string.Empty; + foreach (string name in strDrugName) + { + if (!strNames.Contains(name)) + { + strNames += name; + } + } + int sumQuantity = channelStocks.Sum(cs => cs.AddQuantity); + _portUtil.SpeakAsync($"正在打开 {DrawerNo} 号抽屉,请加药 {strNames} ,数量共计 {sumQuantity}"); List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); _portUtil.WindowName = WindowName; diff --git a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs index dce4974..d00f066 100644 --- a/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/SelfTakeDialogViewModel.cs @@ -179,7 +179,18 @@ namespace DM_Weight.ViewModels int DrawerNo = grouping.Key; List channelStocks = grouping.ToList(); channelStocks.ForEach(it => it.process = 1); - _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); + IEnumerable strDrugName = channelStocks.Select(cs => cs.DrugInfo.DrugName); + string strNames = string.Empty; + foreach (string name in strDrugName) + { + if (!strNames.Contains(name)) + { + strNames += name+" ; "; + } + } + int sumQuantity = channelStocks.Sum(cs => cs.TakeQuantity); + _portUtil.SpeakAsync($"正在打开 {DrawerNo} 号抽屉,请取药 {strNames} ,数量共计 {sumQuantity}"); + List singleChannels = channelStocks.FindAll(it => it.BoardType != 1); diff --git a/DM_Weight/ViewModels/SelfTakeDrugWindowViewModel.cs b/DM_Weight/ViewModels/SelfTakeDrugWindowViewModel.cs index 178d03f..d5577e6 100644 --- a/DM_Weight/ViewModels/SelfTakeDrugWindowViewModel.cs +++ b/DM_Weight/ViewModels/SelfTakeDrugWindowViewModel.cs @@ -159,7 +159,7 @@ namespace DM_Weight.ViewModels .Where(cs => cs.DrugId != null) .Where(cs => cs.DrawerType == 1) .Where(cs => cs.Quantity > 0) - .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) .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)) diff --git a/DM_Weight/ViewModels/StockListWindowViewModel.cs b/DM_Weight/ViewModels/StockListWindowViewModel.cs index e905481..9fc1f9d 100644 --- a/DM_Weight/ViewModels/StockListWindowViewModel.cs +++ b/DM_Weight/ViewModels/StockListWindowViewModel.cs @@ -183,7 +183,7 @@ namespace DM_Weight.ViewModels // .Includes(cs => cs.DrugInfo) // .Where(cs => cs.DrawerType == 1) // .Where(cs =>cs.DrugId != null) - // .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + // .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) // .WhereIF(!String.IsNullOrEmpty(SearchValue),cs => cs.DrugInfo.DrugName == SearchValue) // .OrderBy(cs => cs.DrugId) @@ -198,9 +198,9 @@ namespace DM_Weight.ViewModels ChannelStocks.Clear(); 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()) + .Includes(di => di.channelStocks.Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3") && cs.DrugId != null).OrderBy(cs => cs.DrawerNo).OrderBy(cs => cs.ColNo).ToList()) .WhereIF(!String.IsNullOrEmpty(SearchValue), di => di.DrugName == SearchValue) - .Where(di => di.channelStocks.Any(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.DrugId != null)) + .Where(di => di.channelStocks.Any(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3") && cs.DrugId != null)) .OrderBy(cs => cs.DrugId) .ToList(); Drugs = q; diff --git a/DM_Weight/ViewModels/SurgeryTakeDialogViewModel.cs b/DM_Weight/ViewModels/SurgeryTakeDialogViewModel.cs new file mode 100644 index 0000000..7207f54 --- /dev/null +++ b/DM_Weight/ViewModels/SurgeryTakeDialogViewModel.cs @@ -0,0 +1,859 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.Port; +using DM_Weight.select; +using DM_Weight.util; +using log4net; +using MaterialDesignThemes.Wpf; +using Newtonsoft.Json.Linq; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Channels; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace DM_Weight.ViewModels +{ + public class SurgeryTakeDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime + { + private static readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + private readonly ILog logger = LogManager.GetLogger(typeof(OrderTakeDialogViewModel)); + public string Title => "手术核销"; + + private SurgicalSchedule _surgicalSchedule; + public SurgicalSchedule _SurgicalSchedule { get => _surgicalSchedule; set => SetProperty(ref _surgicalSchedule, value); } + + private List machineRecordList; + public List MachineRecordList { get => machineRecordList; set => SetProperty(ref machineRecordList, value); } + + + private string? _searchValue; + + /// + /// 查询条件 查询字段值 + /// + public string? SearchValue + { + get { return _searchValue; } + set + { + SetProperty(ref _searchValue, value); + RequestData(); + } + } + + 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 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); + RequestData(); + } + } + + private int _pageCount = 1; + public int PageCount + { + get => _pageCount; + set + { + SetProperty(ref _pageCount, value); + } + } + + private int _pageSize = 9; + public int PageSize + { + get => _pageSize; + set + { + SetProperty(ref _pageSize, value); + } + } + + private int _status = 0; + + public int Status + { + get => _status; set => SetProperty(ref _status, value); + } + + private SolidColorBrush _colorBrush; + + public SolidColorBrush SnackbarBackground + { + get => _colorBrush; + set => SetProperty(ref _colorBrush, value); + } + private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3)); + + public ISnackbarMessageQueue SnackbarMessageQueue + { + get => _snackbarMessageQueue; + set => SetProperty(ref _snackbarMessageQueue, value); + } + + List ReturnStockLst; + + private IEnumerable> enumerable; + private IEnumerator> enumerator; + + private OrderTakeSelect _selectedItem = StaticSelects[0]; + /// + /// 查询条件 查询字段 + /// + public OrderTakeSelect SelectedItem + { + get { return _selectedItem; } + set + { + SetProperty(ref _selectedItem, value); + RequestData(); + } + } + + private MachineRecord selectedRecord; + public MachineRecord SelectedRecord { get => selectedRecord; set => SetProperty(ref selectedRecord, value); } + + private PortUtil _portUtil; + IEventAggregator _eventAggregator; + IDialogService _dialogService; + public SurgeryTakeDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator, IDialogService DialogService) + { + _dialogService = DialogService; + _portUtil = portUtil; + _eventAggregator = eventAggregator; + } + + public bool KeepAlive => false; + + public event Action RequestClose; + + public bool CanCloseDialog() + { + return Status == 0; + } + + public void OnDialogClosed() + { + // 取消消息订阅 + _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + + public void OnDialogOpened(IDialogParameters parameters) + { + _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + SurgicalSchedule ss = parameters.GetValue("SurgeryInfo"); + _SurgicalSchedule = ss; + RequestData(); + } + public async void RequestData() + { + int totalCount = 0; + MachineRecordList = SqlSugarHelper.Db.Queryable() + .Includes(mr => mr.DrugInfo) + .Includes(mr => mr.User) + .Includes(mr => mr._SurgicalScheduleDetailLst) + .Where(mr => mr.Type == 2) + .Where(mr => mr.Status < 2) + .Where(mr => mr.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) + //.WhereIF(QueryDate != null, mr => mr.OperationTime.ToString("yyyy-MM-dd") == QueryDate) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (mr) => mr.DrugInfo.DrugId.ToString().Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (mr) => mr.DrugInfo.DrugName.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (mr) => mr.DrugInfo.PyCode.Contains(SearchValue)) + .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (mr) => mr.DrugInfo.DrugBarcode.Contains(SearchValue)) + .OrderBy(mr => mr.OperationTime) + .ToPageList(PageNum, PageSize, ref totalCount); + + MachineRecordList.ForEach(mr => mr.HasCheckNum = mr._SurgicalScheduleDetailLst.Sum(sd => sd.Quantity)); + TotalCount = totalCount; + } + + public DelegateCommand BtnCloseCommand + { + get => new DelegateCommand(() => + { + // 关闭当前窗口 + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + }); + } + + /// + /// 选中行事件 + /// + public DelegateCommand RowSelected + { + get => new DelegateCommand(() => + { + if (SelectedRecord != null && selectedRecord.Id != null) + { + MachineRecordList = MachineRecordList.Select(x => + { + if (x.Id == SelectedRecord.Id) + { + x.IsSelected = !x.IsSelected; + if (x.IsSelected) + { + if (SelectedRecord._SurgicalScheduleDetailLst != null && SelectedRecord._SurgicalScheduleDetailLst.Count > 0) + { + //已经核销数 + int HasCheckNum = SelectedRecord._SurgicalScheduleDetailLst.Sum(sd => sd.Quantity); + x.CheckQuantity = SelectedRecord.Quantity - HasCheckNum; + x.ReturnQuantity1 = SelectedRecord.Quantity - HasCheckNum - x.CheckQuantity; + x.ReturnQuantity2 = HasCheckNum + x.CheckQuantity; + } + else + { + x.CheckQuantity = SelectedRecord.Quantity; + x.ReturnQuantity1 = 0; + x.ReturnQuantity2 = SelectedRecord.Quantity; + } + } + else + { + x.CheckQuantity = 0; + x.ReturnQuantity1 = 0; + x.ReturnQuantity2 = 0; + } + } + return x; + }).ToList(); + + + } + }); + } + + /// + /// 确认核销 + /// + public DelegateCommand AddSurgeryCommand + { + get => new DelegateCommand(() => + { + List RecordsLst = MachineRecordList.FindAll(rl => rl.IsSelected && rl.CheckQuantity > 0).ToList(); + if (_SurgicalSchedule != null && RecordsLst.Count > 0) + { + string operationId = _SurgicalSchedule.OperationId; + var f = SqlSugarHelper.Db.UseTran(() => + { + SqlSugarHelper.Db.Updateable(new SurgicalSchedule() + { + DmStatus = 1, + Id = _SurgicalSchedule.Id + }).UpdateColumns(it => new { it.DmStatus }).WhereColumns(it => new { it.Id }).ExecuteCommand(); + for (int i = 0; i < RecordsLst.Count; i++) + { + SqlSugarHelper.Db.Insertable(new SurgicalScheduleDetail() + { + OperationId = operationId, + GetRecordId = RecordsLst[i].Id, + Quantity = RecordsLst[i].CheckQuantity, + DrugId = RecordsLst[i].DrugId, + ManuNo = RecordsLst[i].ManuNo, + EffDate = RecordsLst[i].EffDate.ToString(), + InsertUserId = HomeWindowViewModel.Operator?.Id, + }).ExecuteCommand(); + + int hasQuantity = RecordsLst[i]._SurgicalScheduleDetailLst.Sum(sd => sd.Quantity); + int dmStatus = 0; + //已经全部挂上钩,修改dm_machine_record状态为完成 + //if (hasQuantity + RecordsLst[i].CheckQuantity == RecordsLst[i].Quantity) + //{ + // dmStatus = 2; + //} + //else + { + dmStatus = 1; + } + SqlSugarHelper.Db.Updateable(new MachineRecord() + { + Status = dmStatus, + Id = RecordsLst[i].Id + }).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.Id }).ExecuteCommand(); + + + } + }); + if (f.IsSuccess) + { + AlertMsg alertMsg = new AlertMsg + { + Message = "核销完成", + Type = MsgType.SUCCESS, + }; + _eventAggregator.GetEvent().Publish(alertMsg); + RequestData(); + + } + else + { + logger.Info($"核销异常"); + + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("核销异常!"); + } + } + else + { + + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("未选中数据,或选中数据核销数量为0"); + } + }); + } + /// + /// 全部归还(还药、还空瓶) + /// + public DelegateCommand ReturnCommand + { + get => new DelegateCommand(() => + { + List RecordsLst = MachineRecordList.FindAll(rl => rl.IsSelected && rl.CheckQuantity == 0).ToList(); + ReturnStockLst = new List(); + if (RecordsLst.Count > 0) + { + + //待还药的记录 + List ReturnDrugLst = RecordsLst.Where(rl => rl.ReturnQuantity1 > 0).ToList(); + //待还空瓶的记录 + List ReturnEmptyLst = RecordsLst.Where(rl => rl.ReturnQuantity2 > 0).ToList(); + + + for (int i = 0; i < ReturnDrugLst.Count; i++) + { + ChannelStock queryData = SqlSugarHelper.Db.Queryable() + .Includes(cs => cs.DrugInfo) + .Where(cs => cs.DrugId == ReturnDrugLst[i].DrugId) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) + .Where(cs => cs.ManuNo == ReturnDrugLst[i].ManuNo) + .OrderBy(cs => cs.Quantity).First(); + if (queryData != null) + { + queryData.AddQuantity = ReturnDrugLst[i].ReturnQuantity1; + queryData.MachineRecordId = ReturnDrugLst[i].Id; + ReturnStockLst.Add(queryData); + } + } + for (int j = 0; j < ReturnEmptyLst.Count; j++) + { + ChannelStock queryData = SqlSugarHelper.Db.Queryable() + .Includes(cs => cs.DrugInfo) + .Where(cs => cs.DrugId == ReturnEmptyLst[j].DrugId) + .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) + //.Where(cs => cs.ManuNo == ReturnEmptyLst[j].ManuNo) + .Where(cs => cs.DrawerType == 2) + .OrderBy(cs => cs.Quantity).First(); + if (queryData != null) + { + queryData.ReturnQuantity = ReturnEmptyLst[j].ReturnQuantity2; + queryData.MachineRecordId = ReturnEmptyLst[j].Id; + ReturnStockLst.Add(queryData); + } + } + if (ReturnStockLst != null && ReturnStockLst.Count > 0) + { + ReturnStockLst = ReturnStockLst.OrderBy(cls => cls.DrawerNo).ToList(); + //还药时AddQuantity有值;还空瓶时ReturnQuantity有值 + enumerable = ReturnStockLst.GroupBy(cs => cs.DrawerNo, cs => cs); + enumerator = enumerable.GetEnumerator(); + enumerator.MoveNext(); + Status = 1; + OpenOneByOne(); + } + else + { + + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("选中数据未绑定库位,请先进行绑定库位"); + } + } + else + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("未选中数据,或选中数据核销数量不为0"); + } + }); + } + /// + /// 刷新 + /// + public DelegateCommand QueryCommand + { + get => new DelegateCommand(() => + { + RequestData(); + }); + } + void DoMyPrismEvent(DeviceMsg msg) + { + + if (msg.WindowName == "SurgeryTakeWindow") + { + 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; + + //保存数据 + + //TakeFinish(); + } + } + 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 void OpenOneByOne() + { + IGrouping grouping = enumerator.Current; + int DrawerNo = grouping.Key; + List channelStocks = grouping.ToList(); + channelStocks.ForEach(it => it.process = 1); + + IEnumerable strDrugName = channelStocks.Select(cs => cs.DrugInfo.DrugName); + string strNames = string.Empty; + foreach (string name in strDrugName) + { + strNames += name; + } + + + + + int drugQuantity = channelStocks.Sum(cs => cs.AddQuantity); + + int emptyQuantity = channelStocks.Sum(cs => cs.ReturnQuantity); + string speakTxt = $"正在打开{DrawerNo}号抽屉,请将{strNames}的"; + if (drugQuantity > 0) + { + speakTxt += $"共计{drugQuantity}个药放入抽屉!"; + } + if (emptyQuantity > 0) + { + speakTxt += $"共计{emptyQuantity}个空瓶放入抽屉!"; + } + _portUtil.SpeakAsync(speakTxt); + + //List singleChannels = channelStocks.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 = "SurgeryTakeWindow"; + _portUtil.BoardType = channelStocks.Count > 0 ? channelStocks[0].BoardType : 1; + _portUtil.ColNos = channelStocks.Select(it => it.ColNo).ToArray(); + _portUtil.DrawerNo = DrawerNo; + _portUtil.Start(); + } + + + private bool _isFinishClick = false; + + public bool IsFinishClick { get => _isFinishClick; set => SetProperty(ref _isFinishClick, value); } + //完成 + private void TakeFinish() + { + IsFinishClick = true; + bool bRet = false; + var f = SqlSugarHelper.Db.UseTran(() => + { + for (int i = 0; i < ReturnStockLst.Count; i++) + { + ChannelStock it = ReturnStockLst[i]; + int quantity = 0; + if (it.AddQuantity > 0) //还药 + { + quantity = it.AddQuantity; + bRet = ReturnDrug(it); + + } + else + { + quantity = it.ReturnQuantity; + bRet = ReturnEmpty(it); + } + if (!bRet) + { + break; + } + // 更新屏显库存 + if (it.BoardType == 5) + { + _portUtil.WriteQuantity(it.DrawerNo, it.ColNo, it.Quantity + quantity); + } + + + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676")); + SnackbarMessageQueue.Enqueue("操作完成,库存已更新!"); + } + return bRet; + }); + if (!f.IsSuccess || !f.Data) + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("库存更新失败!"); + } + Status = 0; + IsFinishClick = false; + RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); + } + /// + /// 还药 + /// + private bool ReturnDrug(ChannelStock stock) + { + try + { + var f = SqlSugarHelper.Db.UseTran(() => + { + string InvoiceId = "RETURN_" + CurrentTimeMillis(); + MachineRecord recordInfo = SqlSugarHelper.Db.Queryable().Where(rd => rd.Id == stock.MachineRecordId).First(); + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = stock.Quantity + stock.AddQuantity, + Id = stock.Id, + }).UpdateColumns(it => new { it.Quantity }).ExecuteCommand(); + // 获取更新完库存后的药品库存 + List nowChannels = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId.Equals(stock.MachineId)) + .Where(cs => cs.DrugId.Equals(stock.DrugId)) + .Where(cs => cs.DrawerType == 1) + .ToList(); + // 更新数据 取药记录 设置还药数量、状态 + SqlSugarHelper.Db.Updateable(new MachineRecord() + { + ReturnQuantity1 = recordInfo.ReturnQuantity1 + stock.AddQuantity, + Id = recordInfo.Id, + Status = (recordInfo.CanReturnQuantity - stock.AddQuantity) == 0 ? 2 : 1, + }).UpdateColumns(it => new { it.ReturnQuantity1, it.Status }).ExecuteCommand(); + + // 保存数据 还药记录 + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = stock.MachineId, + DrawerNo = stock.DrawerNo, + ColNo = stock.ColNo, + DrugId = stock.DrugId, + ManuNo = stock.ManuNo, + EffDate = !String.IsNullOrEmpty(stock.EffDate) ? DateTime.ParseExact(stock.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + OperationTime = DateTime.Now, + Quantity = stock.AddQuantity, + Type = 31, + InvoiceId = InvoiceId, + GetId = stock.MachineRecordId + //,StockQuantity = nowChannels.Sum(it => it.Quantity) + }).ExecuteCommand(); + + //保存账册 + SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(stock.DrugId), + Type = 1, + Department = ConfigurationManager.AppSettings["department"].ToString(), + InvoiceNo = InvoiceId, + ManuNo = stock.ManuNo, + EffDate = stock.EffDate, + AddQuantity = stock.AddQuantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + CreateTime = DateTime.Now + + }).ExecuteCommand(); + //修改凌晨生成的日结存数据 + AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(stock.MachineId)) + .Where(ab => ab.Type == 3) + .Where(ab => ab.DrugId == Convert.ToInt32(stock.DrugId)) + .Where(ab => ab.ManuNo == stock.ManuNo) + .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + stock.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(stock.DrugId), + Type = 3, + ManuNo = stock.ManuNo, + EffDate = stock.EffDate, + YQuantity = 0, + ManuStock = stock.ReturnQuantity, + TotalStock = stock.ReturnQuantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + InvoiceNo = "日结存" + }).ExecuteCommand(); + if (iDayResult <= 0) + { + logger.Info($"未写入日结存数据{stock.DrugId}-{stock.ManuNo}-{stock.EffDate}-{stock.AddQuantity}"); + } + } + //修改凌晨生成的总结存数据 + AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(stock.MachineId)) + .Where(ab => ab.Type == 4) + .Where(ab => ab.DrugId == Convert.ToInt32(stock.DrugId)) + .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock + stock.AddQuantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = Convert.ToInt32(stock.DrugId), + Type = 4, + YQuantity = 0, + ManuStock = stock.ReturnQuantity, + TotalStock = stock.ReturnQuantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + InvoiceNo = "总结存" + }).ExecuteCommand(); + if (iTotalResult <= 0) + { + logger.Info($"未写入总结存数据{stock.DrugId}-{stock.AddQuantity}"); + } + } + }); + if (f.IsSuccess) + { + return true; + } + else + { + return false; + } + } + catch (Exception) + { + + throw; + } + } + /// + /// 还空瓶 + /// + private bool ReturnEmpty(ChannelStock stock) + { + string InvoiceId = "RETURN_" + CurrentTimeMillis(); + var f = SqlSugarHelper.Db.UseTran(() => + { + + // 更新数据 库存信息 + SqlSugarHelper.Db.Updateable(new ChannelStock() + { + Quantity = stock.Quantity + stock.ReturnQuantity, + Id = stock.Id, + }).UpdateColumns(it => new { it.Quantity }).ExecuteCommand(); + + // 获取更新完库存后的药品库存 + List nowChannels = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.MachineId.Equals(stock.MachineId)) + .Where(cs => cs.DrugId.Equals(stock.DrugId)) + .Where(cs => cs.DrawerType == 1) + .ToList(); + + MachineRecord recordInfo = SqlSugarHelper.Db.Queryable().Where(rd => rd.Id == stock.MachineRecordId).First(); + + // 更新数据 取药记录 设置还药数量、状态 + SqlSugarHelper.Db.Updateable(new MachineRecord() + { + ReturnQuantity2 = stock.ReturnQuantity, + Id = recordInfo.Id, + Status = 2, + }).UpdateColumns(it => new { it.ReturnQuantity2, it.Status }).ExecuteCommand(); + + // 保存数据 还药空瓶记录 + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = stock.MachineId, + DrawerNo = stock.DrawerNo, + ColNo = stock.ColNo, + DrugId = stock.DrugId, + ManuNo = stock.ManuNo, + EffDate = !String.IsNullOrEmpty(stock.EffDate) ? DateTime.ParseExact(stock.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + Reviewer = HomeWindowViewModel.Reviewer?.Id, + OperationTime = DateTime.Now, + Quantity = stock.ReturnQuantity, //ReturnQuantity, + Type = 32, + InvoiceId = InvoiceId, + GetId = stock.MachineRecordId + //,StockQuantity = nowChannels.Sum(it => it.Quantity) + }).ExecuteCommand(); + + return true; + }); + + if (!f.IsSuccess || !f.Data) + { + return false; + } + else + { + return true; + } + } + public long CurrentTimeMillis() + { + return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; + } + /// + /// 取消 + /// + public DelegateCommand CancleTake + { + get => new DelegateCommand(() => + { + _portUtil.ResetData(); + Status = 0; + }); + } + // 完成按钮 + public DelegateCommand TakeFinishCommand + { + get => new DelegateCommand(TakeFinish); + } + } + +} diff --git a/DM_Weight/ViewModels/SurgeryTakeWindowViewModel.cs b/DM_Weight/ViewModels/SurgeryTakeWindowViewModel.cs new file mode 100644 index 0000000..d25503a --- /dev/null +++ b/DM_Weight/ViewModels/SurgeryTakeWindowViewModel.cs @@ -0,0 +1,230 @@ +using DM_Weight.Models; +using DM_Weight.msg; +using DM_Weight.select; +using DM_Weight.util; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DM_Weight.ViewModels +{ + public class SurgeryTakeWindowViewModel : BindableBase, IConfirmNavigationRequest, 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); + } + } + + + IDialogService _dialogService; + IEventAggregator _eventAggregator; + + private DelegateCommand _rowSelected; + + public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(OpenOrderDialog); + + + public SurgeryTakeWindowViewModel(IDialogService DialogService, IEventAggregator eventAggregator) + { + _dialogService = DialogService; + _eventAggregator = eventAggregator; + } + + public static List StaticOrderTakeSelects = new() + { + new OrderTakeSelect + { + Code = "OrderNo", + Name = "手术号" + } + }; + private SurgicalSchedule? _selectedSurgicalSchedule; + + public SurgicalSchedule? SelectedSurgicalSchedule + { + get { return _selectedSurgicalSchedule; } + set + { + SetProperty(ref _selectedSurgicalSchedule, value); + + //OpenOrderDialog(); + } + } + + + private string _scheduleTime = DateTime.Now.ToString("yyyy-MM-dd"); + /// + /// 查询条件 手术计划开始时间 + /// + public string ScheduleTime + { + get { return _scheduleTime; } + set + { + if (!String.IsNullOrEmpty(value)) + { + SetProperty(ref _scheduleTime, DateTime.Parse(value).ToString("yyyy-MM-dd")); + } + else + { + SetProperty(ref _scheduleTime, value); + } + + RequestData(); + } + } + + private string? _searchValue; + + /// + /// 查询条件 查询字段值 + /// + public string? SearchValue + { + get { return _searchValue; } + set + { + SetProperty(ref _searchValue, value); + RequestData(); + } + } + + private List _surgicalSchedule = new(); + + public List _SurgicalSchedule { get { return _surgicalSchedule; } set { SetProperty(ref _surgicalSchedule, value); } } + + public bool KeepAlive => false; + + public async void OpenOrderDialog() + { + if (SelectedSurgicalSchedule != null && SelectedSurgicalSchedule.DmStatus == 0 && SelectedSurgicalSchedule.HisState == 1) + { + // 此处延时1毫秒,等待页面渲染 + await Task.Delay(TimeSpan.FromMilliseconds(1)); + DialogParameters dialogParameters = new DialogParameters(); + dialogParameters.Add("SurgeryInfo", SelectedSurgicalSchedule); + DialogServiceExtensions.ShowDialogHost(_dialogService, "SurgeryTakeDialog", dialogParameters, DoDialogResult, "RootDialog"); + + } + + } + + private void DoDialogResult(IDialogResult dialogResult) + { + // 委托 被动执行 被子窗口执行 + // dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态 + //if(dialogResult.Result == ButtonResult.OK) + //{ + SelectedSurgicalSchedule = null; + RequestData(); + //} + //MessageBox.Show("返回值:" + dialogResult.Result.ToString()); + } + + + //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 + public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) + { + continuationCallback(true); + } + /// + /// 录入手术 + /// + public DelegateCommand AddSurgeryCommand + { + get => new DelegateCommand(() => { + DialogServiceExtensions.ShowDialogHost(_dialogService, "AddSurgeryDialog", null, DoDialogResult, "RootDialog"); + }); + } + + public DelegateCommand QueryCommand + { + get => new DelegateCommand(() => + { + RequestData(); + }); + } + + public void RequestData() + { + _SurgicalSchedule.Clear(); + int totalCount = 0; + List queryData = SqlSugarHelper.Db.Queryable() + .WhereIF(ScheduleTime != null, ss => ss.ScheduleTime.ToString("yyyy-MM-dd") == ScheduleTime) + .WhereIF(!String.IsNullOrEmpty(SearchValue), ss => ss.OperationId == SearchValue) + .Where(ss => ss.DmStatus == 0) + .Where(ss => ss.HisState == 1) + .GroupBy(ss => ss.OperationId) + .ToPageList(PageNum, PageSize, ref totalCount); + _SurgicalSchedule = queryData; + TotalCount = totalCount; + PageCount = (int)Math.Ceiling((double)TotalCount / PageSize); + } + public bool IsNavigationTarget(NavigationContext navigationContext) + { + return true; + } + + public void OnNavigatedFrom(NavigationContext navigationContext) + { + // 取消消息订阅 + _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); + } + void DoMyPrismEvent(DeviceMsg msg) + { + if (msg.EventType == EventType.CODESCAN) + { + SearchValue = msg.Code; + } + + } + public void OnNavigatedTo(NavigationContext navigationContext) + { + _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); + RequestData(); + } + } +} diff --git a/DM_Weight/ViewModels/UserManagerWindowViewModel.cs b/DM_Weight/ViewModels/UserManagerWindowViewModel.cs index 2ecadba..3c36898 100644 --- a/DM_Weight/ViewModels/UserManagerWindowViewModel.cs +++ b/DM_Weight/ViewModels/UserManagerWindowViewModel.cs @@ -175,7 +175,7 @@ namespace DM_Weight.ViewModels int totalcount = 0; UserList = SqlSugarHelper.Db.Queryable() .Includes(ul => ul.Role) - .Where(ul => ul.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) + .Where(ul => ul.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM3")) .WhereIF(!String.IsNullOrEmpty(SearchValue) , (di) => di.Nickname.Contains(SearchValue)) .ToPageList(PageNum, PageSize, ref totalcount) //.ToList() diff --git a/DM_Weight/Views/ApplyInStockWindow.xaml b/DM_Weight/Views/ApplyInStockWindow.xaml index cede7ab..594c4bb 100644 --- a/DM_Weight/Views/ApplyInStockWindow.xaml +++ b/DM_Weight/Views/ApplyInStockWindow.xaml @@ -190,9 +190,9 @@ - + + --> + --> - + + + + + + - - - diff --git a/DM_Weight/Views/ApplyListWindow.xaml b/DM_Weight/Views/ApplyListWindow.xaml index c3687f2..06796fe 100644 --- a/DM_Weight/Views/ApplyListWindow.xaml +++ b/DM_Weight/Views/ApplyListWindow.xaml @@ -145,11 +145,11 @@ - + ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"/>--> - + ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"> + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/Dialog/AddSurgeryDialog.xaml b/DM_Weight/Views/Dialog/AddSurgeryDialog.xaml new file mode 100644 index 0000000..655fa7b --- /dev/null +++ b/DM_Weight/Views/Dialog/AddSurgeryDialog.xaml @@ -0,0 +1,329 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/Dialog/AddSurgeryDialog.xaml.cs b/DM_Weight/Views/Dialog/AddSurgeryDialog.xaml.cs new file mode 100644 index 0000000..b2cc3b8 --- /dev/null +++ b/DM_Weight/Views/Dialog/AddSurgeryDialog.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 +{ + /// + /// AddSurgeryDialog.xaml 的交互逻辑 + /// + public partial class AddSurgeryDialog : UserControl + { + public AddSurgeryDialog() + { + InitializeComponent(); + } + } +} diff --git a/DM_Weight/Views/Dialog/SurgeryTakeDialog.xaml b/DM_Weight/Views/Dialog/SurgeryTakeDialog.xaml new file mode 100644 index 0000000..74d9cff --- /dev/null +++ b/DM_Weight/Views/Dialog/SurgeryTakeDialog.xaml @@ -0,0 +1,242 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/Dialog/SurgeryTakeDialog.xaml.cs b/DM_Weight/Views/Dialog/SurgeryTakeDialog.xaml.cs new file mode 100644 index 0000000..e108180 --- /dev/null +++ b/DM_Weight/Views/Dialog/SurgeryTakeDialog.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 +{ + /// + /// SurgeryTakeDialog.xaml 的交互逻辑 + /// + public partial class SurgeryTakeDialog : UserControl + { + public SurgeryTakeDialog() + { + InitializeComponent(); + } + } +} diff --git a/DM_Weight/Views/MachineRecordWindow.xaml b/DM_Weight/Views/MachineRecordWindow.xaml index 24f20e5..aa77b71 100644 --- a/DM_Weight/Views/MachineRecordWindow.xaml +++ b/DM_Weight/Views/MachineRecordWindow.xaml @@ -52,7 +52,13 @@ materialDesign:HintAssist.Hint="结束时间" Style="{StaticResource MaterialDesignOutlinedDatePicker}" /> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DM_Weight/Views/SurgeryTakeWindow.xaml.cs b/DM_Weight/Views/SurgeryTakeWindow.xaml.cs new file mode 100644 index 0000000..6b5c5b8 --- /dev/null +++ b/DM_Weight/Views/SurgeryTakeWindow.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 +{ + /// + /// SurgeryTakeWindow.xaml 的交互逻辑 + /// + public partial class SurgeryTakeWindow : UserControl + { + public SurgeryTakeWindow() + { + InitializeComponent(); + } + } +}