Program.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:Program.cs
  5. * 2.功能描述:系统启动主程序
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 张国印 2014/09/04 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Diagnostics;
  12. using System.IO;
  13. using System.Reflection;
  14. using System.Threading;
  15. using System.Windows.Forms;
  16. using System.Runtime.InteropServices;
  17. using Dongke.IBOSS.PRD.Basics.BaseResources;
  18. using Dongke.IBOSS.PRD.Basics.Library;
  19. using Dongke.IBOSS.PRD.Client.CommonModule;
  20. using Dongke.IBOSS.PRD.Client.DataModels;
  21. using Dongke.IBOSS.PRD.WCF.DataModels;
  22. using Dongke.IBOSS.PRD.WCF.Proxys;
  23. using Timer = System.Windows.Forms.Timer;
  24. using Wongoing.Basic;
  25. namespace Dongke.IBOSS.PRD.Client
  26. {
  27. /// <summary>
  28. /// 系统启动主程序
  29. /// </summary>
  30. static class Program
  31. {
  32. #region 成员变量
  33. // 系统登录窗体
  34. private static F_SYS_0101 _frmLogin = null;
  35. // 主窗体title
  36. private static string _mainFormTitle = null;
  37. private static string _loginFormTitle = null;
  38. private static FileVersionInfo _info = null;
  39. // 程序是否已经登录
  40. private static bool _isLogin = false;
  41. // 配置文件的全路径
  42. private static string _iniFilePath = LocalPath.RootPath + Constant.INI_FILE_NAME;
  43. #endregion
  44. #region 属性
  45. /// <summary>
  46. /// 已经登录标识
  47. /// </summary>
  48. internal static bool IsLogin
  49. {
  50. get
  51. {
  52. return _isLogin;
  53. }
  54. set
  55. {
  56. _isLogin = value;
  57. }
  58. }
  59. #endregion
  60. /// <summary>
  61. /// 应用程序的主入口点。
  62. /// </summary>
  63. [STAThread]
  64. static void Main(string[] args)
  65. {
  66. Curtain.Log.Logger.DefaultLogDirectory = LocalPath.LogRootPath;
  67. // 检查程序是否已经在运行中
  68. bool isCreatedNew = true;
  69. Mutex ibossMutex = null;
  70. //#if DEBUG
  71. //#else
  72. // string ibossMutexName = SystemAPI.UserName + "-iboss.mes-";
  73. // ibossMutex = new Mutex(true, ibossMutexName, out isCreatedNew);
  74. //#endif
  75. // 取得程序的版本
  76. _info = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
  77. _mainFormTitle = Constant.M_SYSTEM_NAME + " - " + Constant.M_SYSTEM_CHINESE_SERIES + " - ver " + _info.FileVersion;
  78. _loginFormTitle = Constant.M_SYSTEM_CHINESE_NAME + " - ver " + _info.FileVersion;
  79. if (isCreatedNew)
  80. {
  81. try
  82. {
  83. Application.EnableVisualStyles();
  84. Application.SetCompatibleTextRenderingDefault(false);
  85. Application.ThreadException += Application_ThreadException;
  86. {
  87. // 更新自动更新程序
  88. if (Directory.Exists(LocalPath.InstallerDownloadPath))
  89. {
  90. string[] downFiles = Directory.GetFiles(LocalPath.InstallerDownloadPath);
  91. if (downFiles.Length > 0)
  92. {
  93. if (args != null)
  94. {
  95. System.Threading.Thread.Sleep(3000);
  96. }
  97. try
  98. {
  99. foreach (string name in downFiles)
  100. {
  101. string filename = Path.GetFileName(name);
  102. if (filename.StartsWith("AutoUpgrade")
  103. || "SharpZipLib.dll".Equals(filename))
  104. {
  105. string localFile = System.Environment.CurrentDirectory + @"\" + filename;
  106. if (File.Exists(localFile))
  107. {
  108. File.Delete(localFile);
  109. }
  110. File.Copy(name, localFile);
  111. File.Delete(name);
  112. }
  113. else
  114. {
  115. File.Delete(name);
  116. }
  117. }
  118. }
  119. catch (Exception ex)
  120. {
  121. Curtain.Log.Logger.Error(ex);
  122. }
  123. }
  124. }
  125. }
  126. // 系统登录
  127. Login(args);
  128. if (_isLogin)
  129. {
  130. //#if DEBUG
  131. // 如果升级版本发布错误,导致客户端都不能升级了。
  132. // 主程序
  133. //using (F_SYS_0201 main = new F_SYS_0201())
  134. //{
  135. // main.Text = _mainFormTitle;
  136. // Application.Run(main);
  137. //}
  138. //#else
  139. // 自动更新
  140. NeedUpgradeResultEntity needUpgradeInfo = DKIBOSSPRDProxy.Service.IsNeedUpgrade(_info.FileVersion);
  141. #region 版本到期提示 2023-05-26 fenglinyong ADD start
  142. //查询后台授权标识
  143. //EMPOWERMENTFLAG授权(1:提示授权到期,2:不提示)
  144. ClientRequestEntity cre = new ClientRequestEntity();
  145. cre.NameSpace = "EMPOWERMENTFLAG";
  146. cre.Name = "EMPOWERMENTFLAG";
  147. ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
  148. if (sre.Status == Basics.BaseResources.Constant.ServiceResultStatus.Success)
  149. {
  150. if (sre.Data != null && sre.Data.Tables.Count > 0 && sre.Data.Tables[0].Rows.Count > 0)
  151. {
  152. if (sre.Data.Tables[0].Rows[0]["EMPOWERMENTFLAG"].ToString() == "1")
  153. {
  154. MessageBoxTimeOut.Show(sre.Data.Tables[0].Rows[0]["SHOWINFO"].ToString(), "提示", 3000);
  155. //MessageBox.Show(sre.Data.Tables[0].Rows[0]["SHOWINFO"].ToString(),
  156. //Messages.MSG_TITLE_I01,
  157. //MessageBoxButtons.OK,
  158. //MessageBoxIcon.Information);
  159. }
  160. }
  161. }
  162. #endregion 2023-05-26 fenglinyong ADD END
  163. if (needUpgradeInfo.UpgradeState)
  164. {
  165. MessageBox.Show("检测到服务器上有最新版本,需要自动更新。",
  166. Messages.MSG_TITLE_I01,
  167. MessageBoxButtons.OK,
  168. MessageBoxIcon.Information);
  169. needUpgradeInfo.GradeInfo =
  170. string.Format("本地程序版本:{0}\r\n最新程序版本:{1}",
  171. _info.FileVersion, needUpgradeInfo.ServerVersion);
  172. // 如果有提示信息提示,没有就跳过
  173. if (!string.IsNullOrEmpty(needUpgradeInfo.GradeInfo))
  174. {
  175. F_SYS_0103 frmAutoUpgradeInfo = new F_SYS_0103(needUpgradeInfo.GradeInfo);
  176. DialogResult dialogResult = frmAutoUpgradeInfo.ShowDialog();
  177. if (dialogResult != DialogResult.OK)
  178. {
  179. Application.Exit();
  180. }
  181. else
  182. {
  183. Application.Exit();
  184. //Process.Start("AutoUpgrade.exe");
  185. Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "AutoUpgrade.exe", "IBOSSPRD.exe " + _frmLogin.Password);
  186. }
  187. }
  188. else
  189. {
  190. Application.Exit();
  191. //Process.Start("AutoUpgrade.exe");
  192. Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "AutoUpgrade.exe", "IBOSSPRD.exe " + _frmLogin.Password);
  193. }
  194. }
  195. // 如果有提示信息,不能连接服务器
  196. else if (!string.IsNullOrEmpty(needUpgradeInfo.GradeInfo))
  197. {
  198. MessageBox.Show(needUpgradeInfo.GradeInfo,
  199. Messages.MSG_TITLE_I01,
  200. MessageBoxButtons.OK,
  201. MessageBoxIcon.Warning);
  202. Application.Exit();
  203. }
  204. else
  205. {
  206. // 主程序
  207. using (F_SYS_0201 main = new F_SYS_0201())
  208. {
  209. main.Text = _mainFormTitle;
  210. Application.Run(main);
  211. }
  212. }
  213. //#endif
  214. }
  215. }
  216. catch (Exception ex)
  217. {
  218. // 对异常进行共通处理
  219. ExceptionManager.HandleEventException("Program.cs", "Main()", Messages.MSG_TITLE_E01, ex);
  220. }
  221. finally
  222. {
  223. if (_isLogin)
  224. {
  225. try
  226. {
  227. // 退出系统
  228. DKIBOSSPRDProxy.Service.Logout(LogInUserInfo.CurrentUser.UserID);
  229. }
  230. catch { }
  231. }
  232. if (ibossMutex != null)
  233. {
  234. ibossMutex.Close();
  235. }
  236. }
  237. }
  238. else
  239. {
  240. IntPtr iptWndMain = Utility.FindWindow(null, _mainFormTitle);
  241. if (iptWndMain == IntPtr.Zero)
  242. {
  243. IntPtr iptWndLogin = Utility.FindWindow(null, _loginFormTitle);
  244. if (iptWndLogin != IntPtr.Zero)
  245. {
  246. Utility.WakeupWindow(iptWndLogin);
  247. }
  248. }
  249. else
  250. {
  251. Utility.WakeupWindow(iptWndMain);
  252. }
  253. }
  254. }
  255. static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
  256. {
  257. //throw new NotImplementedException();
  258. ExceptionManager.HandleEventException(
  259. "Program.cs",
  260. "Application_ThreadException()",
  261. Messages.MSG_TITLE_E01,
  262. e.Exception);
  263. }
  264. #region 私有方法
  265. /// <summary>
  266. /// 调取系统登录页面进行登录验证
  267. /// </summary>
  268. /// <returns></returns>
  269. private static bool Login(string[] args)
  270. {
  271. _frmLogin = new F_SYS_0101();
  272. _frmLogin.Text = _loginFormTitle;
  273. if (args != null)
  274. {
  275. int argsLength = args.Length;
  276. if (argsLength == 1)
  277. {
  278. if ("IsChangedUser" == args[0])
  279. {
  280. _frmLogin.IsChangedUser = true;
  281. }
  282. }
  283. if (argsLength == 2)
  284. {
  285. if ("IBOSSPRD.exe" == args[0])
  286. {
  287. _frmLogin.Password = args[1];
  288. }
  289. }
  290. }
  291. DialogResult dialogResult = _frmLogin.ShowDialog();
  292. if (dialogResult == DialogResult.OK)
  293. {
  294. return true;
  295. }
  296. return false;
  297. }
  298. #endregion
  299. }
  300. }