using Svg;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace formula_manage
{
///
/// App.xaml 的交互逻辑
///
public partial class App : Application
{ ///
///公共变量来自Login的用户名
///
public static string USER_Purview { get; set; }
public App()
{
this.Startup += new StartupEventHandler(App_Startup);
this.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
}
System.Threading.Mutex mutex;
void App_Startup(object sender, StartupEventArgs e) //程序只允许启动一次
{
bool ret;
mutex = new System.Threading.Mutex(true, "ElectronicNeedleTherapySystem", out ret);
if (!ret)
{
MessageBox.Show("SUNLIGHT:单据管理已启动");
Environment.Exit(0);
}
}
protected override void OnStartup(StartupEventArgs e) //跟踪报错信息
{
base.OnStartup(e);
//UI线程的异常捕捉
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
}
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
//string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
e.Handled = true;
if (e.Exception.InnerException == null)
{
MessageBox.Show("发生了一个无法处理的错误!请联系SUNLIGHT处理!" + Environment.NewLine
// + "(2)错误源:" + e.Exception.Source + Environment.NewLine
+ "详细信息:" + e.Exception.Message + Environment.NewLine
// + "(4)报错区域:" + e.Exception.StackTrace
);
}
else
{
MessageBox.Show("发生了一个无法处理的错误!请联系SUNLIGHT处理!" + Environment.NewLine
// + "(2)错误源:" + e.Exception.InnerException.Source + Environment.NewLine
+ "错误信息:" + e.Exception.Message + Environment.NewLine
// + "(4)详细信息:" + e.Exception.InnerException.Message + Environment.NewLine
// + "(5)报错区域:" + e.Exception.InnerException.StackTrace
);
}
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录
if (!File.Exists(logpath + Log_time + "Log.txt"))//检查日志文件并写入启动日志
{
FileStream fs = new FileStream(logpath + Log_time + "Log.txt", FileMode.CreateNew, FileAccess.Write);//创建写入文件
StreamWriter wr = new StreamWriter(fs);//创建文件
wr.WriteLine("||["+ Log_time + "];[Error source] ||" + e.Exception.Source + Environment.NewLine);
wr.WriteLine("||[" + Log_time + "];[Details] ||" + e.Exception.Source + Environment.NewLine);
wr.WriteLine("||[" + Log_time + "];[Error area] ||" + e.Exception.Source + Environment.NewLine);
wr.Close();
}
else
{
FileStream fs = new FileStream(logpath + Log_time + "Log.txt", FileMode.CreateNew, FileAccess.Write);//创建写入文件
StreamWriter wr = new StreamWriter(fs);//创建文件
wr.WriteLine("||[" + Log_time + "];[Error source] ||" + e.Exception.Source + Environment.NewLine);
wr.WriteLine("||[" + Log_time + "];[Details] ||" + e.Exception.Source + Environment.NewLine);
wr.WriteLine("||[" + Log_time + "];[Error area] ||" + e.Exception.Source + Environment.NewLine);
wr.Close();
}
}
///
/// 启动初始页面
///
private void Application_Startup(object sender, StartupEventArgs e)
{
Application.Current.StartupUri = new Uri("Login.xaml", UriKind.Relative);//和MainWindwo同一目录
//Application.Current.StartupUri = new Uri("EX/ExProgram.xaml", UriKind.Relative);//在目录下
}
}
}