| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:Program.cs
- * 2.功能描述:系统启动主程序
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 张国印 2014/09/04 1.00 新建
- *******************************************************************************/
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Reflection;
- using System.Threading;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Basics.Library;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.Client.DataModels;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.IBOSS.PRD.WCF.Proxys.DKIBOSSPRDService;
- namespace Dongke.IBOSS.PRD.Client
- {
- /// <summary>
- /// 系统启动主程序
- /// </summary>
- static class Program
- {
- #region 成员变量
- // 系统登录窗体
- private static F_SYS_0101 _frmLogin = null;
- // 主窗体title
- private static string _mainFormTitle = null;
- private static string _loginFormTitle = null;
- private static FileVersionInfo _info = null;
- // 程序是否已经登录
- private static bool _isLogin = false;
- // 配置文件的全路径
- private static string _iniFilePath = LocalPath.RootPath + Constant.INI_FILE_NAME;
- #endregion
- #region 属性
- /// <summary>
- /// 已经登录标识
- /// </summary>
- internal static bool IsLogin
- {
- get
- {
- return _isLogin;
- }
- set
- {
- _isLogin = value;
- }
- }
- #endregion
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main(string[] args)
- {
- // 检查程序是否已经在运行中
- bool isCreatedNew = true;
- Mutex ibossMutex = null;
- //#if DEBUG
- //#else
- // string ibossMutexName = SystemAPI.UserName + "-iboss.mes-";
- // ibossMutex = new Mutex(true, ibossMutexName, out isCreatedNew);
- //#endif
- // 取得程序的版本
- _info = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
- _mainFormTitle = Constant.M_SYSTEM_NAME + " - " + Constant.M_SYSTEM_CHINESE_SERIES + " - ver " + _info.FileVersion;
- _loginFormTitle = Constant.M_SYSTEM_CHINESE_NAME + " - ver " + _info.FileVersion;
- if (isCreatedNew)
- {
- try
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.ThreadException += Application_ThreadException;
- {
- // 更新自动更新程序
- if (Directory.Exists(LocalPath.InstallerDownloadPath))
- {
- string[] downFiles = Directory.GetFiles(LocalPath.InstallerDownloadPath);
- if (downFiles.Length > 0)
- {
- foreach (string name in downFiles)
- {
- string filename = Path.GetFileName(name);
- if (filename.StartsWith("AutoUpgrade")
- || "SharpZipLib.dll".Equals(filename))
- {
- string localFile = System.Environment.CurrentDirectory + @"\" + filename;
- if (File.Exists(localFile))
- {
- File.Delete(localFile);
- }
- File.Copy(name, localFile);
- File.Delete(name);
- }
- else
- {
- File.Delete(name);
- }
- }
- }
- }
- }
- // 系统登录
- Login(args);
- if (_isLogin)
- {
- //#if DEBUG
- // 如果升级版本发布错误,导致客户端都不能升级了。
- // 主程序
- //using (F_SYS_0201 main = new F_SYS_0201())
- //{
- // main.Text = _mainFormTitle;
- // Application.Run(main);
- //}
- //#else
- // 自动更新
- NeedUpgradeResultEntity needUpgradeInfo = DKIBOSSPRDProxy.Service.IsNeedUpgrade(_info.FileVersion);
- if (needUpgradeInfo.UpgradeState)
- {
- MessageBox.Show("检测到服务器上有最新版本,需要自动更新。",
- Messages.MSG_TITLE_I01,
- MessageBoxButtons.OK,
- MessageBoxIcon.Information);
- needUpgradeInfo.GradeInfo =
- string.Format("本地程序版本:{0}\r\n最新程序版本:{1}",
- _info.FileVersion, needUpgradeInfo.ServerVersion);
- // 如果有提示信息提示,没有就跳过
- if (!string.IsNullOrEmpty(needUpgradeInfo.GradeInfo))
- {
- F_SYS_0103 frmAutoUpgradeInfo = new F_SYS_0103(needUpgradeInfo.GradeInfo);
- DialogResult dialogResult = frmAutoUpgradeInfo.ShowDialog();
- if (dialogResult != DialogResult.OK)
- {
- Application.Exit();
- }
- else
- {
- Application.Exit();
- //Process.Start("AutoUpgrade.exe");
- Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "AutoUpgrade.exe", "IBOSSPRD.exe " + _frmLogin.Password);
- }
- }
- else
- {
- Application.Exit();
- //Process.Start("AutoUpgrade.exe");
- Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "AutoUpgrade.exe", "IBOSSPRD.exe " + _frmLogin.Password);
- }
- }
- // 如果有提示信息,不能连接服务器
- else if (!string.IsNullOrEmpty(needUpgradeInfo.GradeInfo))
- {
- MessageBox.Show(needUpgradeInfo.GradeInfo,
- Messages.MSG_TITLE_I01,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- Application.Exit();
- }
- else
- {
- // 主程序
- using (F_SYS_0201 main = new F_SYS_0201())
- {
- main.Text = _mainFormTitle;
- Application.Run(main);
- }
- }
- //#endif
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException("Program.cs", "Main()", Messages.MSG_TITLE_E01, ex);
- }
- finally
- {
- if (_isLogin)
- {
- try
- {
- // 退出系统
- DKIBOSSPRDProxy.Service.Logout(LogInUserInfo.CurrentUser.UserID);
- }
- catch { }
- }
- if (ibossMutex != null)
- {
- ibossMutex.Close();
- }
- }
- }
- else
- {
- IntPtr iptWndMain = Utility.FindWindow(null, _mainFormTitle);
- if (iptWndMain == IntPtr.Zero)
- {
- IntPtr iptWndLogin = Utility.FindWindow(null, _loginFormTitle);
- if (iptWndLogin != IntPtr.Zero)
- {
- Utility.WakeupWindow(iptWndLogin);
- }
- }
- else
- {
- Utility.WakeupWindow(iptWndMain);
- }
- }
- }
- static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
- {
- //throw new NotImplementedException();
- ExceptionManager.HandleEventException(
- "Program.cs",
- "Application_ThreadException()",
- Messages.MSG_TITLE_E01,
- e.Exception);
- }
- #region 私有方法
- /// <summary>
- /// 调取系统登录页面进行登录验证
- /// </summary>
- /// <returns></returns>
- private static bool Login(string[] args)
- {
- _frmLogin = new F_SYS_0101();
- _frmLogin.Text = _loginFormTitle;
- if (args != null)
- {
- int argsLength = args.Length;
- if (argsLength == 1)
- {
- if ("IsChangedUser" == args[0])
- {
- _frmLogin.IsChangedUser = true;
- }
- }
- if (argsLength == 2)
- {
- if ("IBOSSPRD.exe" == args[0])
- {
- _frmLogin.Password = args[1];
- }
- }
- }
- DialogResult dialogResult = _frmLogin.ShowDialog();
- if (dialogResult == DialogResult.OK)
- {
- return true;
- }
- return false;
- }
- #endregion
- }
- }
|