123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using System;
- using System.IO;
- using System.Security.Principal;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW
- {
- static class Program
- {
-
-
-
- [STAThread]
- static void Main()
- {
- try
- {
- WindowsIdentity identity = WindowsIdentity.GetCurrent();
- WindowsPrincipal principal = new WindowsPrincipal(identity);
-
- Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
-
- Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
-
- AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
- #region 应用程序的主入口点
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
-
- GlobalEventsHandler g = new GlobalEventsHandler();
-
- Application.AddMessageFilter(g);
-
- string sysdisc = Environment.GetEnvironmentVariable("windir").Substring(0, 1);
-
- if (!Directory.Exists(ftpOperater.DownLoadTo))
- Directory.CreateDirectory(ftpOperater.DownLoadTo);
- if (!Directory.Exists(SystemInf.LogFolder))
- Directory.CreateDirectory(SystemInf.LogFolder);
- FileStream fs = new FileStream(SystemInf.LogFolder + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
- fs.Close();
-
- if (!Directory.Exists(SystemInf.CacheFolder))
- Directory.CreateDirectory(SystemInf.CacheFolder);
- FileStream fcaches = new FileStream(SystemInf.CacheFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
- fcaches.Close();
- DevExpress.UserSkins.BonusSkins.Register();
- DevExpress.Skins.SkinManager.EnableFormSkins();
- DevExpress.Skins.SkinManager.EnableMdiFormSkins();
-
- FileInfo info = new FileInfo(SystemInf.CacheFilePath);
- if (info.Length == 0)
- {
- XmlDocument doc = new XmlDocument();
-
- XmlNode node = doc.CreateXmlDeclaration("1.0", "utf-8", "");
- doc.AppendChild(node);
-
- XmlElement xeRoot = doc.CreateElement("cacheInfo");
- doc.AppendChild(xeRoot);
- doc.Save(SystemInf.CacheFilePath);
- }
-
- FileStream fas = new FileStream(SystemInf.CacheFolder + "lblprocess.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
- fas.Close();
- if (principal.IsInRole(WindowsBuiltInRole.Administrator))
- Application.Run(new Login());
- else
- {
-
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
-
- startInfo.FileName = Application.ExecutablePath;
-
- startInfo.Verb = "runas";
-
- System.Diagnostics.Process.Start(startInfo);
- }
- #endregion
- }
- catch (Exception ex)
- {
- string str = GetExceptionMsg(ex, string.Empty);
- MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
-
- static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
- {
- string str = GetExceptionMsg(e.Exception, e.ToString());
- LogManager.DoLog(e.Exception.Message + " " + e.Exception.TargetSite + " " + e.Exception.StackTrace);
- MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
-
- static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- string str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());
- LogManager.DoLog(str);
- MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
-
-
-
-
-
-
- static string GetExceptionMsg(Exception ex, string backStr)
- {
- StringBuilder sb = new StringBuilder();
- if (ex != null)
- {
- sb.AppendLine(ex.Message);
- sb.AppendLine("【异常方法】:" + ex.StackTrace);
- }
-
- return sb.ToString();
- }
- }
- }
|