1
yhj
2024-07-24 5e5d945e91568b973faa27d8ab0bcef99fc4a6c5
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#region
 
using System;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
using CSFrameworkV5.Business;
using CSFrameworkV5.Common;
using CSFrameworkV5.Core;
using CSFrameworkV5.Core.Common;
using CSFrameworkV5.Core.SystemSecurity;
using CSFrameworkV5.Language;
using CSFrameworkV5.Library;
using CSFrameworkV5.Library.CommonClass;
using CSFrameworkV5.Library.CommonForms;
using CSFrameworkV5.Library.Entry;
using DevExpress.LookAndFeel;
using DevExpress.Skins;
using DevExpress.UserSkins;
 
#endregion
 
namespace CSFrameworkV5.Main
{
    ///*************************************************************************/
    ///* 文件名    :Program.cs    
    ///* 程序说明  :主程序入口,注意代码顺序
    ///* 原创作者  :www.csframework.com 
    ///* Copyright 2006-2021 C/S框架网 www.csframework.com
    ///**************************************************************************/
    internal static class Program
    {
        private static void Application_ApplicationExit(object sender,
            EventArgs e)
        {
            try
            {
                //用户登出
                if (SystemAuthentication.Current != null)
                    SystemAuthentication.Current.Logout();
            }
            catch
            {
                //关闭程序出现异常,不提示消息
            }
        }
 
        private static void Application_ThreadException(object sender,
            ThreadExceptionEventArgs e)
        {
            try
            {
                //仅记录系统异常,CustomException是自定义异常类
                if (e.Exception.GetType().Name != typeof(CustomException).Name)
                    LogUserOperate.Write(e.Exception);
 
                //显示异常信息
                Msg.ShowException(e.Exception);
            }
            catch (Exception ex)
            {
                //写入本地文件日志-系统异常日志
                LogLocalException.Log.WriteLog(LogTypeSystem.Exception,
                    ex.Message);
 
                Msg.ShowError("Application_ThreadException:\r\n" + ex.Message);
            }
        }
 
        /// <summary>
        ///     检查程序是否运行多实例
        /// </summary>
        public static void CheckInstance()
        {
            bool createdNew; //返回是否赋予了使用线程的互斥体初始所属权
            var instance = new Mutex(true, Globals.DEF_PROGRAM_NAME,
                out createdNew);
            if (createdNew) //首次使用互斥体
                instance.ReleaseMutex();
            else
                throw new CustomException("您已经运行程序,系统禁止运行多个实例!");
        }
 
        /// <summary>
        ///     加载语言包
        /// </summary>
        private static void InitLanguage()
        {
            //将XML文件的语言数据同步到数据库, 注意:只需要初始化一次即可
            //LanLib.InitDB();
 
            //XML语言库策略
            //LanLib.LanguageData = new LanXML();
 
            //数据库存储的语言库策略
            LanLib.LanguageData = new LanDatabase();
        }
 
        [STAThread]
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException +=
                Application_ThreadException; //捕获系统产生的异常。
            Application.ApplicationExit += Application_ApplicationExit;
 
            try
            {
                #region 初始化工作
 
                frmWaitingEx.ShowMe(null, "正在初始化系统环境,请稍候...");
 
                //初始化对称加密预设的秘钥
                KeyProvider.Default =
                    new KeyProviderRijndael("%SaFz$^p", "3aW%^&Fd");
                //KeyProvider.Default.Decrypt("asdfasdfasdf");
 
                //加密
                //string pwd1 = KeyProvider.Default.Encrypt("wcfuser");//HS+AHKm26rokVfWqabT5TA==
                //string pwd2 = KeyProvider.Default.Encrypt("123456");//Snj6+Q3dGGb1ukbEi0igFw==
                //string pwd3 = KeyProvider.Default.Encrypt("C26xjf34");//V6gTKX+nZUB+5imSHNpMTg==
 
                Thread.CurrentThread.CurrentUICulture =
                    new CultureInfo("zh-Hans"); //汉化DevExpress
 
                UserConfig.Current.Load(); //读取用户自定义设置,config\user.ini
 
                BonusSkins.Register(); //注册Dev酷皮肤
                SkinManager
                    .EnableFormSkins(); //启用窗体支持换肤特性                                
                UserLookAndFeel.Default.SetSkinStyle(
                    UserConfig.Current.SkinName); //设置主题样式
 
                #endregion
 
                #region 初始化桥接功能,测试连接,运行登录窗体
 
                if (BridgeFactory.InitializeBridge()) //初始化桥接功能,测试连接
                {
                    frmWaitingEx.HideMe();
 
                    InitLanguage(); //初始化语言系统
 
                    //未登陆:加载系统参数配置
                    var dtConfig = CommonData.GetSystemSettings4Program("", "");
                    SystemSettings.Current.Load(dtConfig);
 
                    //启动版本自动升级程序                    
                    //if (SystemSettings.Current.CheckVersion)
                    //{
                    //    bool exitApp = false;
                    //    VersionCheckNEW.AutoUpgrader(ref exitApp);
                    //    if (exitApp) return;//退出程序
                    //}
 
                    //检查程序是否运行多实例                               
                    if (!SystemSettings.Current.MultiInstance) CheckInstance();
 
                    //注意:先打开登陆窗体,登陆成功后正式运行程序(MDI主窗体)            
                    if (frmLogin.Login())
                    {
                        MdiTools.MainForm.Show();
 
                        //启动自动检测最新升级包,强制升级定时器。
                        frmAutoUpgraderWaiting.StartAutoUpgrading(
                            MdiTools.MainForm);
 
                        Application.Run();
                    }
                }
 
                #endregion
            }
            catch (Exception ex)
            {
                //写入本地文件日志-系统异常日志
                LogLocalException.Log.WriteLog(LogTypeSystem.Exception,
                    ex.Message);
 
                Msg.ShowError("运行系统时发生错误!\r\n" + ex.Message);
                Application.Exit();
            }
        }
    }
}