XiangTan_JiaoJie_Bak/DM_Weight/App.xaml.cs

364 lines
17 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DM_Weight.Finger;
using DM_Weight.Port;
using DM_Weight.util.TabTip;
using DM_Weight.util;
using DM_Weight.ViewModels;
using DM_Weight.Views.Dialog;
using DM_Weight.Views;
using log4net.Config;
using Prism.Ioc;
using Prism.Services.Dialogs;
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Prism.Unity;
using log4net;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace DM_Weight
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : PrismApplication
{
public static bool DbConnectionFail { get; set; } = false;
private readonly ILog logger = LogManager.GetLogger(typeof(App));
public App()
{
TabTipAutomation.IgnoreHardwareKeyboard = HardwareKeyboardIgnoreOptions.IgnoreAll;
TabTipAutomation.BindTo<TextBox>();
TabTipAutomation.BindTo<PasswordBox>();
}
protected override Window CreateShell()
{
logger.Info("进入APP-CreateShell");
//UI线程未捕获异常处理事件
this.DispatcherUnhandledException += OnDispatcherUnhandledException;
//Task线程内未捕获异常处理事件
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
//多线程异常
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
logger.Info("进入APP-CreateShell-2");
return Container.Resolve<MainWindow>();
}
void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
logger.Error($"发生错误:{e.Exception.Message}");
e.Handled = true; if (e.Exception.Message.Contains("连接数据库过程中发生错误"))
{
DbConnectionFail = true;
Container.Resolve<MainWindow>();
}
}
void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
foreach (Exception item in e.Exception.InnerExceptions)
{
logger.Error($"异常类型:{item.GetType()}{Environment.NewLine}来自:{item.Source}{Environment.NewLine}异常内容:{item.Message}");
}
//将异常标识为已经观察到
e.SetObserved();
}
void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
logger.Error($"Unhandled exception.{e.ToString()}");
}
protected override void InitializeShell(Window shell)
{
base.InitializeShell(shell);
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
logger.Info("进入APP-RegisterTypes");
// 注入日志
XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));
//containerRegistry.RegisterInstance<ILog>(LogManager.GetLogger(""));
// 串口工具
containerRegistry.RegisterSingleton<PortUtil>();
containerRegistry.RegisterSingleton<SocketHelper>();
// 指纹机工具
containerRegistry.RegisterSingleton<FingerprintUtil>();
// 组态屏工具
//containerRegistry.RegisterSingleton<ScreenUtil>();
// 录像机
//containerRegistry.RegisterSingleton<CHKFunction>();
containerRegistry.Register<IDialogService, MaterialDialogService>();
// 主窗口
containerRegistry.Register<MainWindow>();
containerRegistry.RegisterForNavigation<MainWindow, MainWindowViewModel>();
// 分页
//containerRegistry.Register<Pagination>();
//containerRegistry.Register<PaginationViewModel>();
// 登录页面
containerRegistry.RegisterForNavigation<LoginWindow, LoginWindowViewModel>();
// 布局页面
containerRegistry.RegisterForNavigation<HomeWindow, HomeWindowViewModel>();
// 录入指纹模态框
containerRegistry.RegisterDialog<FingerprintDialog>();
containerRegistry.RegisterForNavigation<FingerprintDialog, FingerprintDialogViewModel>();
#region
// 处方取药页面
//containerRegistry.RegisterForNavigation<OrderTakeDrugWindow, OrderTakeDrugWindowViewModel>();
//containerRegistry.RegisterForNavigation<OrderTakeDrugNewWindow, OrderTakeDrugNewWindowViewModel>();
//containerRegistry.RegisterForNavigation<OrderTakeAllDrugDialog, OrderTakeAllDrugDialogViewModel>();
//containerRegistry.RegisterForNavigation<OrderTakeNewDialog, OrderTakeNewDialogViewModel>();
////交接柜补药
//containerRegistry.RegisterForNavigation<AddToJiaoJieWindow, AddToJiaoJieWindowViewModel>();
// 处方取药模态框
//containerRegistry.RegisterDialog<OrderTakeDialog>();
//containerRegistry.RegisterForNavigation<OrderTakeDialog, OrderTakeDialogViewModel>();
//// 调拨取药页面
//containerRegistry.RegisterForNavigation<InvoiceOutWindow, InvoiceOutWindowViewModel>();
//// 调拨取药模态框
//containerRegistry.RegisterDialog<InvoiceTakeDialog>();
//containerRegistry.RegisterForNavigation<InvoiceTakeDialog, InvoiceTakeDialogViewModel>();
//// 抽屉取药页面
//containerRegistry.RegisterForNavigation<DrawerTakeDrugWindow, DrawerTakeDrugWindowViewModel>();
//// 自选取药模态框
//containerRegistry.RegisterDialog<SelfTakeDialog>();
//containerRegistry.RegisterForNavigation<SelfTakeDialog, SelfTakeDialogViewModel>();
//// 自选取药页面
//containerRegistry.RegisterForNavigation<SelfTakeDrugWindow, SelfTakeDrugWindowViewModel>();
////多处方取药
//containerRegistry.RegisterForNavigation<MultiOrderTakeDrugWindow, MultiOrderTakeDrugWindowViewModel>();
//containerRegistry.RegisterDialog<MultiOrderTakeDialog>();
//containerRegistry.RegisterForNavigation<MultiOrderTakeDialog,MultiOrderTakeDialogViewModel>();
////手术排程
//containerRegistry.RegisterForNavigation<SurgeryTakeWindow, SurgeryTakeWindowViewModel>();
//containerRegistry.RegisterDialog<SurgeryTakeDialog>();
//containerRegistry.RegisterForNavigation<SurgeryTakeDialog, SurgeryTakeDialogViewModel>();
//containerRegistry.RegisterDialog<AddSurgeryDialog>();
//containerRegistry.RegisterForNavigation<AddSurgeryDialog, AddSurgeryDialogViewModel>();
//开药箱
containerRegistry.RegisterForNavigation<OpenBoxWindow, OpenBoxWindowViewModel>();
containerRegistry.RegisterForNavigation<OpenBoxNewWindow, OpenBoxNewWindowViewModel>();
//交接柜补药
containerRegistry.RegisterForNavigation<AdditionWindow, AdditionWindowViewModel>();
//核对处方
//containerRegistry.RegisterForNavigation<CheckOrderWindow, CheckOrderWindowViewModel>();
//管理员根据药箱进行核对处方
containerRegistry.RegisterForNavigation<CheckOrderNewWindow, CheckOrderNewWindowViewModel>();
//麻醉师核对其名下单子
containerRegistry.RegisterForNavigation<CheckSelfOrderWindow, CheckSelfOrderWindowViewModel>();
#endregion
//#region 加药
// 自选加药页面
//containerRegistry.RegisterForNavigation<SelfAddWindow, SelfAddWindowViewModel>();
//// 调拨加药页面
//containerRegistry.RegisterForNavigation<InvoiceInWindow, InvoiceInWindowViewModel>();
//// 调拨取药模态框
//containerRegistry.RegisterDialog<InvoiceAddDialog>();
//containerRegistry.RegisterForNavigation<InvoiceAddDialog, InvoiceAddDialogViewModel>();
//// 抽屉加药页面
//containerRegistry.RegisterForNavigation<DrawerAddDrugWindow, DrawerAddDrugWindowViewModel>();
//// 自选加药模态框
//containerRegistry.RegisterDialog<SelfAddDialog>();
//containerRegistry.RegisterForNavigation<SelfAddDialog, SelfAddDialogViewModel>();
////多批次抽屉加药
//containerRegistry.RegisterForNavigation<AddDrugControl, AddDrugControlViewModel>();
////药品请领
//containerRegistry.RegisterForNavigation<CollectDrugWindow, CollectDrugWindowViewModel>();
//// 药品请领模态框
//containerRegistry.RegisterDialog<CollectDrugDialog>();
//containerRegistry.RegisterForNavigation<CollectDrugDialog, CollectDrugDialogViewModel>();
////请领列表
//containerRegistry.RegisterForNavigation<ApplyListWindow, ApplyListWindowViewModel>();
////请领入库
//containerRegistry.RegisterForNavigation<ApplyInStockWindow, ApplyInStockWindowViewModel>();
//#endregion
//#region 还药
//// 还药页面
//containerRegistry.RegisterForNavigation<ReturnDrugWindow, ReturnDrugWindowViewModel>();
//// 按记录归还药品模态框
//containerRegistry.RegisterDialog<ReturnDrugDialog>();
//containerRegistry.RegisterForNavigation<ReturnDrugDialog, ReturnDrugDialogViewModel>();
//// 还药页面2
//containerRegistry.RegisterForNavigation<ReturnDrugWindow2, ReturnDrugWindow2ViewModel>();
//// 按处方归还药品模态框
//containerRegistry.RegisterDialog<OrderReturnDialog>();
//containerRegistry.RegisterForNavigation<OrderReturnDialog, OrderReturnDialogViewModel>();
//// 还空瓶页面
//containerRegistry.RegisterForNavigation<ReturnEmptyWindow, ReturnEmptyWindowViewModel>();
////空瓶销毁页面
//containerRegistry.RegisterForNavigation<ReturnEmptyDestoryWindow, ReturnEmptyDestoryWindowViewModel>();
//// 归还空瓶模态框
//containerRegistry.RegisterDialog<ReturnEmptyDialog>();
//containerRegistry.RegisterForNavigation<ReturnEmptyDialog, ReturnEmptyDialogViewModel>();
//// 空瓶销毁模态框
//containerRegistry.RegisterDialog<DestoryEmptyDialog>();
//containerRegistry.RegisterForNavigation<DestoryEmptyDialog, DestoryEmptyDialogViewModel>();
//#endregion
//#region 库存管理
//// 库存列表页面
//containerRegistry.RegisterForNavigation<StockListWindow, StockListWindowViewModel>();
//// 库位绑定模态框
//containerRegistry.RegisterDialog<BindingChannelDialog>();
//containerRegistry.RegisterForNavigation<BindingChannelDialog, BindingChannelDialogViewModel>();
////同一药品多批次库位绑定
//containerRegistry.RegisterForNavigation<BindingChannelNewDialog, BindingChannelNewDialogViewModel>();
//// 库存盘点页面
//containerRegistry.RegisterForNavigation<CheckStockWindow, CheckStockWindowViewModel>();
//// 药品列表页面
//containerRegistry.RegisterForNavigation<DrugListWindow, DrugListWindowViewModel>();
////交接班记录
//containerRegistry.RegisterForNavigation<ChangeShiftsListWindow, ChangeShiftsListWindowViewModel>();
////交接班弹窗
//containerRegistry.RegisterDialog<ChangeShiftsDialog>();
//containerRegistry.RegisterForNavigation<ChangeShiftsDialog, ChangeShiftsDialogViewModel>();
//containerRegistry.RegisterForNavigation<AccountWindow,AccountWindowViewModel>();
//#endregion
#region
// 用户管理页面
containerRegistry.RegisterForNavigation<UserManagerWindow, UserManagerWindowViewModel>();
// 编辑用户模态框
containerRegistry.RegisterDialog<EditUserDialog>();
containerRegistry.RegisterForNavigation<EditUserDialog, EditUserDialogViewModel>();
containerRegistry.RegisterDialog<DelUserDialog>();
containerRegistry.RegisterForNavigation<DelUserDialog, DelUserDialogViewModel>();
// 角色管理页面
containerRegistry.RegisterForNavigation<RoleManagerWindow, RoleManagerWindowViewModel>();
// 系统设置
containerRegistry.RegisterForNavigation<SettingWindow, SettingWindowViewModel>();
// 调试页面
//containerRegistry.RegisterForNavigation<DebugWindow, DebugWindowViewModel>();
//主设置页面
containerRegistry.RegisterForNavigation<SettingMainWindow, SettingMainWindowViewModel>();
//两个冰箱抽屉设置页面
//containerRegistry.RegisterForNavigation<FridgeWindow, FridgeWindowViewModel>();
////只有一个冰箱抽屉设置页面
//containerRegistry.RegisterForNavigation<FridgeOnlyWindow, FridgeOnlyWindowViewModel>();
//药箱绑定
containerRegistry.RegisterForNavigation<BindBoxPackageWindow, BindBoxPackageWindowViewModel>();
//药箱设置
containerRegistry.RegisterForNavigation<SettingBoxWindow, SettingBoxWindowViewModel>();
//操作记录
containerRegistry.RegisterForNavigation<MachineRecordWindow, MachineRecordWindowViewModel>();
//温湿度记录
containerRegistry.RegisterForNavigation<WSDRecordWindow, WSDRecordWindowViewModel>();
containerRegistry.RegisterForNavigation<SetMenuWindow, SetMenuWindowViewModel>();
containerRegistry.RegisterDialog<AddNewMenuDialog>();
containerRegistry.RegisterForNavigation<AddNewMenuDialog, AddNewMenuDialogViewModel>();
//盘点
containerRegistry.RegisterForNavigation<CheckStockWindow, CheckStockWindowViewModel>();
containerRegistry.RegisterDialog<ConfirmDialog>();
containerRegistry.RegisterForNavigation<ConfirmDialog, ConfirmDialogViewModel>();
//账册
containerRegistry.RegisterForNavigation<AccountWindow, AccountWindowViewModel>();
//药品转移药箱
containerRegistry.RegisterForNavigation<ExchangeWindow, ExchangeWindowViewModel>();
containerRegistry.RegisterForNavigation<ExchangeDialog, ExchangeDialogViewModel>();
containerRegistry.RegisterForNavigation<RemoveDialog, RemoveDialogViewModel>();
containerRegistry.RegisterDialog<ExchangeDialog>();
containerRegistry.RegisterDialog<RemoveDialog>();
#endregion
// 设备记录页面
//containerRegistry.RegisterForNavigation<MachineRecordWindow, MachineRecordWindowViewModel>();
containerRegistry.RegisterForNavigation<ShowMessageDialog, ShowMessageDialogViewModel>();
//空页面用于跳出登录时跳转以避免不走OnNavigatedFrom情况
containerRegistry.RegisterForNavigation<EmptyWindow, EmptyWindowViewModel>();
//紧急开锁页面
containerRegistry.RegisterForNavigation<EmergencyWindow, EmergencyWindowViewModel>();
logger.Info("结束APP-RegisterTypes");
}
private void PrismApplication_Startup(object sender, StartupEventArgs e)
{
//获取欲启动程序名
string processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
logger.Info($"欲启动程序名:{processName}");
//检查程序是否已经启动,已经启动则显示提示退出程序
if (System.Diagnostics.Process.GetProcessesByName(processName).Length > 1)
{
logger.Info($"系统在运行!");
//系统在运行
RaiseOtherProcess();
Application.Current.Shutdown();
return;
}
}
private static void RaiseOtherProcess()
{
Process proc = Process.GetCurrentProcess();
foreach (Process otherProc in Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName))
{
if (proc.Id != otherProc.Id)
{
IntPtr hWnd = otherProc.MainWindowHandle;
if (IsIconic(hWnd))
{
ShowWindowAsync(hWnd, 9);
}
SetForegroundWindow(hWnd);
break;
}
}
}
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);
}
}