From d2cee56db11f0ee475e9f9dbdc8bfd03ad982e18 Mon Sep 17 00:00:00 2001
From: Shuxia Ning <NingShuxia0927@outlook.com>
Date: 星期一, 12 八月 2024 09:42:01 +0800
Subject: [PATCH] 报错

---
 Desktop/HStation.Desktop.Xhs.Core/Program.cs |  104 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 91 insertions(+), 13 deletions(-)

diff --git a/Desktop/HStation.Desktop.Xhs.Core/Program.cs b/Desktop/HStation.Desktop.Xhs.Core/Program.cs
index c62c4ff..5efd33f 100644
--- a/Desktop/HStation.Desktop.Xhs.Core/Program.cs
+++ b/Desktop/HStation.Desktop.Xhs.Core/Program.cs
@@ -1,3 +1,4 @@
+using DevExpress.LookAndFeel;
 using Mapster;
 using System.Reflection;
 
@@ -11,23 +12,100 @@
         [STAThread]
         static void Main()
         {
-            // To customize application configuration such as set high DPI settings or default font,
-            // see https://aka.ms/applicationconfiguration.
-            ApplicationConfiguration.Initialize();
+            using (var mutex = new System.Threading.Mutex(true, Application.ProductName, out bool createNew))
+            {
+                if (!createNew)
+                {
+                    MessageBox.Show("程序正在运行中...");
+                    Application.Exit();
+                    return;
+                }
 
-            //if (!LoginHelper.Login())
-            //{
-            //    return;
-            //}
+                //DevExpress.UserSkins.BonusSkins.Register();
+                DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle("Bezier");//Visual Studio 2013 Light
+                DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(SkinSvgPalette.Bezier.OfficeColorful);
+                DevExpress.Skins.SkinManager.EnableFormSkins();
+                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-Hans");
+                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-Hans");
 
-            //Yw.FileFolderZipHelper.Zip(@"C:\Users\admin\Desktop\居家办公工作\RevitTest", @"C:\Users\admin\Desktop\居家办公工作\RevitTest.ywrvt");
+                //处理未捕获的异常
+                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
+                //处理UI线程异常
+                Application.ThreadException += Application_ThreadException;
+                //处理非UI线程异常
+                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
+
+                Application.EnableVisualStyles();
+                Application.SetCompatibleTextRenderingDefault(false);
+
+                //字体
+                // var font = new System.Drawing.Font("微软雅黑", 10);
+                // DevExpress.XtraEditors.WindowsFormsSettings.DefaultFont = font;
+                // DevExpress.XtraEditors.WindowsFormsSettings.DefaultMenuFont = font;
+                // DevExpress.Utils.AppearanceObject.DefaultFont = font;
+
+                //zh-Hans界面翻译
+                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-Hans");
+                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-Hans");
+
+                //皮肤
+                //DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(SkinStyle.WXICompact);
+                DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(SkinStyle.WXICompact);
+
+                // To customize application configuration such as set high DPI settings or default font,
+                // see https://aka.ms/applicationconfiguration.
+                ApplicationConfiguration.Initialize();
+
+                //if (!LoginHelper.Login())
+                //{
+                //    return;
+                //}
+
+                Yw.FileFolderZipHelper.Zip(@"C:\Users\admin\Desktop\居家办公工作\简单用例", @"C:\Users\admin\Desktop\居家办公工作\简单用例.ywrvt");
+
+                //var json = RevitTestHelper.GenerateJson();
+
+                //var jsonFileName = @"C:\Users\admin\Desktop\居家办公工作\二开压缩文件\hydro.json";
+                //var jsonContent = File.ReadAllText(jsonFileName);
+                //var jsonModel = JsonHelper.Json2Object<HStation.Model.RevitModel>(jsonContent);
+
+                //扫描全局DTO映射
+                TypeAdapterConfig.GlobalSettings.Scan
+                    (
+                        Assembly.Load("Yw.BLL.Auth.Core"),
+                        Assembly.Load("Yw.BLL.Bimface.Core"),
+                        Assembly.Load("Yw.BLL.Hydro.Core"),
+                        Assembly.Load("Yw.BLL.Map.Core"),
+                        Assembly.Load("HStation.BLL.Xhs.Core")
+                    );
+                DbFirstHelper.Initial();
+                Application.Run(new MainForm());
+            }
 
 
-            //扫描全局DTO映射
-            //TypeAdapterConfig.GlobalSettings.Scan(Assembly.Load("Yw.BLL.Auth.Core"), Assembly.Load("HStation.BLL.Xhs.Core"));
-            DbFirstHelper.Initial();
-            //TestHelper.AddTestProject();
-            Application.Run(new MainForm());
         }
+
+
+        ///<summary>
+        ///  这就是我们要在发生未处理异常时处理的方法,我这是写出错详细信息到文本,如出错后弹出一个漂亮的出错提示窗体,给大家做个参考
+        ///  做法很多,可以是把出错详细信息记录到文本、数据库,发送出错邮件到作者信箱或出错后重新初始化等等
+        ///  这就是仁者见仁智者见智,大家自己做了。
+        ///</summary>
+        ///<param name="sender"> </param>
+        ///<param name="e"> </param>
+        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
+        {
+            var ex = e.Exception;
+            Yw.LogHelper.Error("系统出现未知异常,ERROR:249", ex);
+            MessageBox.Show($"系统出现未知异常,请重启系统!\r\n{ex.Message}");
+        }
+
+        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+        {
+            var ex = e.ExceptionObject as Exception;
+            Yw.LogHelper.Error("系统出现未知异常,ERROR:255", ex);
+            MessageBox.Show($"系统出现未知异常,请重启系统!\r\n{ex.Message}");
+        }
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3