#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);
}
}
///
/// 检查程序是否运行多实例
///
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("您已经运行程序,系统禁止运行多个实例!");
}
///
/// 加载语言包
///
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();
}
}
}
}