版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 3.7 KiB

2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 
  2. using Models;
  3. using ProductionControl.UI;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Windows.Forms;
  15. namespace ProductionControl
  16. {
  17. internal static class Program
  18. {
  19. /// <summary>
  20. /// 应用程序的主入口点。
  21. /// </summary>
  22. [STAThread]
  23. static void Main()
  24. {
  25. //Application.Run(new Form3());
  26. //return;
  27. //byte[] buff = File.ReadAllBytes(@"D:\AZTCode\HBBank\证书\国mi-生产证书ssl\CFCA_ACS_SM2_OCA31.cer");
  28. //string s = Convert.ToBase64String(buff);
  29. //string bmppath = @"f:\abc.bmp";
  30. //Order order=new Order();
  31. //order.DefectInfoList = new List<DefectInfo>() {
  32. // new DefectInfo(){ X=100,Y=100, Code="dk"},
  33. // new DefectInfo(){ X=200,Y=100, Code="dk"},
  34. // new DefectInfo(){ X=100,Y=200, Code="zk"},
  35. // new DefectInfo(){ X=200,Y=220, Code="xws"},
  36. //};
  37. //Application.Run(new FrmShowDefectImage(bmppath, order));
  38. //return;
  39. Thread.Sleep(500);
  40. Process instance = RunningInstance();
  41. if (instance == null)
  42. {
  43. Application.ThreadException += Application_ThreadException;
  44. Application.EnableVisualStyles();
  45. Application.SetCompatibleTextRenderingDefault(false);
  46. Config.LoadAllConfig();
  47. Service.InitDB.ConnectionString = Config.DBConStr;
  48. //Application.Run(new FrmScannerShow2(new Size(300,300)));
  49. Application.Run(new FrmLogin());
  50. }
  51. else
  52. {
  53. MessageBox.Show("当前程序已经运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 0);
  54. }
  55. }
  56. //不允许有两个程序同时启动
  57. public static Process RunningInstance()
  58. {
  59. Process current = Process.GetCurrentProcess();
  60. Process[] processes = Process.GetProcessesByName(current.ProcessName);
  61. //遍历正在有相同名字运行的例程
  62. foreach (Process process in processes)
  63. {
  64. //忽略现有的例程
  65. if (process.Id != current.Id)
  66. {
  67. //确保例程从EXE文件运行
  68. if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") ==
  69. current.MainModule.FileName)
  70. {
  71. //返回另一个例程实例
  72. return process;
  73. }
  74. }
  75. }
  76. //没有其它的例程,返回Null
  77. return null;
  78. }
  79. static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
  80. {
  81. Exception ex = e.Exception;
  82. using (StreamWriter sw = new StreamWriter(Directory.GetCurrentDirectory() + "\\Log.txt", true))
  83. {
  84. sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  85. sw.WriteLine("Global捕获到未处理异常:" + ex.GetType().ToString());
  86. sw.WriteLine("异常信息:" + ex.Message);
  87. sw.WriteLine("异常堆栈:" + ex.StackTrace);
  88. sw.WriteLine();
  89. }
  90. MessageBox.Show(string.Format("捕获到未处理异常:{0}\r\n异常信息:{1}\r\n异常堆栈:{2}", ex.GetType(), ex.Message, ex.StackTrace));
  91. }
  92. }
  93. }