118 lines
4.0 KiB
C#
118 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace TouchCashier
|
|
{
|
|
/// <summary>
|
|
/// App.xaml 的交互逻辑
|
|
/// </summary>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// UI线程异常处理事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
|
{
|
|
//MessageBox.Show(e.Exception.ToString());
|
|
//Shutdown(1);
|
|
try
|
|
{
|
|
LogHelper.WriteServiceLog($"主线程错误:{e.Exception.Message}");
|
|
}
|
|
catch { }
|
|
e.Handled = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 非UI线程异常处理事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
{
|
|
//Loger.WriteErrorLog("捕获未处理异常:" + e.ExceptionObject);
|
|
try
|
|
{
|
|
LogHelper.WriteServiceLog("子线程错误:" + (e.ExceptionObject as Exception).Message);
|
|
}
|
|
catch { }
|
|
//MessageBox.Show(e.ExceptionObject.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 程序启动处理
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
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
|
|
{
|
|
FontSizeChange();
|
|
MainWindow _MainWindow = new MainWindow();
|
|
_MainWindow.Show();
|
|
}
|
|
}
|
|
private void FontSizeChange()
|
|
{
|
|
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);
|
|
}
|
|
|
|
}
|
|
}
|