duheng
2024-07-12 09f8dfa6d6b382ed21e262e0a34704f61dab5e82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using DevExpress.LookAndFeel;
using DevExpress.XtraEditors.Controls;
using HStation.DAL;
using HStation.DeskTop;
using Mapster;
using System;
using System.Reflection;
using System.Windows.Forms;
 
namespace HStation.Desktop
{
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        private static void Main()
        {
            using (var mutex = new System.Threading.Mutex(true, Application.ProductName, out bool createNew))
            {
                if (!createNew)
                {
                    MessageBox.Show("程序正在运行中...");
                    Application.Exit();
                    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");
 
                //处理未捕获的异常
                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;
 
                DevExpress.XtraEditors.Controls.Localizer.Active = new XtraMessBoxClass();
                //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);
 
                //扫描全局DTO映射
                TypeAdapterConfig.GlobalSettings.Scan(Assembly.Load("Yw.BLL.Auth.Core"), Assembly.Load("HStation.BLL.Xhs.Core"));
 
                var loginHelper = new LoginHelper();
                if (!loginHelper.Login())
                    return;
                var databaseHelper = new HStation.DAL.DbFirstHelper();
                var result = databaseHelper.Initial(out string msg);
                Application.Run(new GuideMain());
            }
        }
 
        ///<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}");
        }
 
        public class XtraMessBoxClass : Localizer
        {
            public override string GetLocalizedString(DevExpress.XtraEditors.Controls.StringId id)
            {
                switch (id)
                {
                    case StringId.XtraMessageBoxCancelButtonText:
                        return "取消";
 
                    case StringId.XtraMessageBoxOkButtonText:
                        return "确定";
 
                    case StringId.XtraMessageBoxYesButtonText:
                        return "是";
 
                    case StringId.XtraMessageBoxNoButtonText:
                        return "否";
 
                    case StringId.XtraMessageBoxIgnoreButtonText:
                        return "忽略";
 
                    case StringId.XtraMessageBoxAbortButtonText:
                        return "中止";
 
                    case StringId.XtraMessageBoxRetryButtonText:
                        return "重试";
 
                    default:
                        return base.GetLocalizedString(id);
                }
            }
        }
    }
}