using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; namespace TouchCashier { /// /// App.xaml 的交互逻辑 /// public partial class App : Application { System.Threading.Mutex mutex; public App() { DispatcherUnhandledException += App_DispatcherUnhandledException; //非UI线程未捕获异常处理事件 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Startup += new StartupEventHandler(App_Startup); } /// /// UI线程异常处理事件 /// /// /// void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { //MessageBox.Show(e.Exception.ToString()); //Shutdown(1); try { ESSupport.Lib.LogHelper.WriteServiceLog($"主线程错误:{e.Exception.Message}"); } catch { } e.Handled = true; } /// /// 非UI线程异常处理事件 /// /// /// void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { //Loger.WriteErrorLog("捕获未处理异常:" + e.ExceptionObject); try { ESSupport.Lib.LogHelper.WriteServiceLog("子线程错误:" + (e.ExceptionObject as Exception).Message); } catch { } //MessageBox.Show(e.ExceptionObject.ToString()); } /// /// 程序启动处理 /// /// /// void App_Startup(object sender, StartupEventArgs e) { bool ret; mutex = new System.Threading.Mutex(true, "TouchCashier", out ret); if (!ret) { //ActivateOtherWindow(); //MessageBox.Show("Program has started, you can't start again!"); Environment.Exit(0); } else { MainFontSizeChange(); SecondMainFontSizeChange(); MainWindow _MainWindow = new MainWindow(); _MainWindow.Show(); } } /// /// 主屏幕窗口字体大小计算 /// private void MainFontSizeChange() { //超大号字体 double supersize = ((SystemParameters.PrimaryScreenWidth / 6.5) / 3 * 2) / 5; if (supersize < 28) { supersize = 28; } System.Windows.Application.Current.Resources.Remove("SuperFontSize"); System.Windows.Application.Current.Resources.Add("SuperFontSize", supersize); double titlesize = ((SystemParameters.PrimaryScreenWidth / 10) / 3 * 2) / 5; if (titlesize < 18) { titlesize = 18; } System.Windows.Application.Current.Resources.Remove("TitleFontSize"); System.Windows.Application.Current.Resources.Add("TitleFontSize", titlesize); double tabsize = ((SystemParameters.PrimaryScreenWidth / 10) / 3 * 2) / 5 * 0.9; if (tabsize < 16) { tabsize = 16; } System.Windows.Application.Current.Resources.Remove("TabFontSize"); System.Windows.Application.Current.Resources.Add("TabFontSize", tabsize); double gridsize = ((SystemParameters.PrimaryScreenWidth / 10) / 3 * 2) / 5 * 0.8; if (gridsize < 14) { gridsize = 14; } System.Windows.Application.Current.Resources.Remove("GridFontSize"); System.Windows.Application.Current.Resources.Add("GridFontSize", gridsize); double controlsize = ((SystemParameters.PrimaryScreenWidth / 10) / 3 * 2) / 5 * 0.7; if (controlsize < 12) { controlsize = 12; } System.Windows.Application.Current.Resources.Remove("ControlFontSize"); System.Windows.Application.Current.Resources.Add("ControlFontSize", controlsize); } /// /// 副屏幕窗口字体大小计算 /// private void SecondMainFontSizeChange() { double db_ScreenWidth = SystemParameters.PrimaryScreenWidth; if (System.Windows.Forms.Screen.AllScreens.Length > 1) { db_ScreenWidth = System.Windows.Forms.Screen.AllScreens[1].Bounds.Width; } //超大号字体 double supersize = ((db_ScreenWidth / 6.5) / 3 * 2) / 5; if (supersize < 28) { supersize = 28; } System.Windows.Application.Current.Resources.Remove("SecondSuperFontSize"); System.Windows.Application.Current.Resources.Add("SecondSuperFontSize", supersize); double titlesize = ((db_ScreenWidth / 9) / 3 * 2) / 5; if (titlesize < 20) { titlesize = 20; } System.Windows.Application.Current.Resources.Remove("SecondTitleFontSize"); System.Windows.Application.Current.Resources.Add("SecondTitleFontSize", titlesize); double tabsize = ((db_ScreenWidth / 10) / 3 * 2) / 5; if (tabsize < 16) { tabsize = 16; } System.Windows.Application.Current.Resources.Remove("SecondTabFontSize"); System.Windows.Application.Current.Resources.Add("SecondTabFontSize", tabsize); double gridsize = ((db_ScreenWidth / 10) / 3 * 2) / 5 * 0.8; if (gridsize < 14) { gridsize = 14; } System.Windows.Application.Current.Resources.Remove("SecondGridFontSize"); System.Windows.Application.Current.Resources.Add("SecondGridFontSize", gridsize); double controlsize = ((SystemParameters.PrimaryScreenWidth / 10) / 3 * 2) / 5 * 0.7; if (controlsize < 12) { controlsize = 12; } System.Windows.Application.Current.Resources.Remove("SecondControlFontSize"); System.Windows.Application.Current.Resources.Add("SecondControlFontSize", controlsize); } } }