Program.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. 
  2. using System;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Reflection;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using Dongke.IBOSS.PRD.Basics.BaseResources;
  9. using Dongke.IBOSS.PRD.Basics.Library;
  10. using Dongke.IBOSS.PRD.Client.CommonModule;
  11. namespace Dongke.IBOSS.PRD.Client.Public
  12. {
  13. static class Program
  14. {
  15. /// <summary>
  16. /// 应用程序的主入口点。
  17. /// </summary>
  18. [STAThread]
  19. static void Main()
  20. {
  21. //Application.EnableVisualStyles();
  22. //Application.SetCompatibleTextRenderingDefault(false);
  23. //Application.Run(new F_P_00001());
  24. // 检查程序是否已经在运行中
  25. bool isCreatedNew = true;
  26. string ibossMutexName = SystemAPI.UserName + "-iboss.prd.public-";
  27. Mutex ibossMutex = new Mutex(true, ibossMutexName, out isCreatedNew);
  28. // 取得程序的版本
  29. FileVersionInfo info = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
  30. string _mainFormTitle = "查询系统" + " - " + Constant.M_SYSTEM_CHINESE_SERIES + " - ver " + info.FileVersion;
  31. if (isCreatedNew)
  32. {
  33. try
  34. {
  35. Application.EnableVisualStyles();
  36. Application.SetCompatibleTextRenderingDefault(false);
  37. Application.ThreadException += Application_ThreadException;
  38. {
  39. // 更新自动更新程序
  40. if (Directory.Exists(LocalPath.InstallerPublicDownloadPath))
  41. {
  42. string[] downFiles = Directory.GetFiles(LocalPath.InstallerPublicDownloadPath);
  43. if (downFiles.Length > 0)
  44. {
  45. foreach (string name in downFiles)
  46. {
  47. string filename = Path.GetFileName(name);
  48. if (filename.StartsWith("AutoUpgrade")
  49. || "SharpZipLib.dll".Equals(filename))
  50. {
  51. string localFile = System.Environment.CurrentDirectory + @"\" + filename;
  52. if (File.Exists(localFile))
  53. {
  54. File.Delete(localFile);
  55. }
  56. File.Copy(name, localFile);
  57. File.Delete(name);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. // 主程序
  64. using (F_P_00001 main = new F_P_00001())
  65. {
  66. main.Text = _mainFormTitle;
  67. Application.Run(main);
  68. }
  69. }
  70. catch (Exception ex)
  71. {
  72. // 对异常进行共通处理
  73. ExceptionManager.HandleEventException("PublicProgram.cs", "Main()", Messages.MSG_TITLE_E01, ex);
  74. }
  75. finally
  76. {
  77. if (ibossMutex != null)
  78. {
  79. ibossMutex.Close();
  80. }
  81. }
  82. }
  83. else
  84. {
  85. IntPtr iptWndMain = Utility.FindWindow(null, _mainFormTitle);
  86. if (iptWndMain == IntPtr.Zero)
  87. {
  88. }
  89. else
  90. {
  91. Utility.WakeupWindow(iptWndMain);
  92. }
  93. }
  94. }
  95. private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
  96. {
  97. //throw new NotImplementedException();
  98. ExceptionManager.HandleEventException(
  99. "PublicProgram.cs",
  100. "Application_ThreadException()",
  101. Messages.MSG_TITLE_E01,
  102. e.Exception);
  103. }
  104. }
  105. }