Program.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Permission;
  2. using PlcCom;
  3. using PlcUiControl;
  4. using PlcUiForm;
  5. using Sunny.UI.Win32;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Runtime.Remoting.Contexts;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using XmlToTreeView;
  14. using YangjieTester.用户管理;
  15. namespace YangjieTester
  16. {
  17. internal static class Program
  18. {
  19. /// <summary>
  20. /// 应用程序的主入口点。
  21. /// </summary>
  22. [STAThread]
  23. static void Main()
  24. {
  25. const string mutexName = "YangjieTester";
  26. using (var mutex = new System.Threading.Mutex(true, mutexName, out bool createdNew))
  27. {
  28. if (createdNew)
  29. {
  30. //Application.Run(new PermissionConfigForm());
  31. //return;
  32. DatabaseHelper.InitializeDatabase();
  33. if (BatchService.GetLatestBatchID(out string batchID, out bool finished, out string errorMessage) && !finished)
  34. {
  35. AppSession.CurrentBatch.BatchID = batchID;
  36. }
  37. var batch = BatchService.GetLatestBatch(out string err);
  38. if (batch != null)
  39. {
  40. AppSession.CurrentBatch = batch;
  41. }
  42. Application.EnableVisualStyles();
  43. Application.SetCompatibleTextRenderingDefault(false);
  44. //Application.Run(new BatchReportForm());
  45. //return;
  46. var netConfig = new DeltaAxPLCNetConfig();
  47. DeltaAxCommProtocol deltaIACommProtocol = new DeltaAxCommProtocol(netConfig);
  48. PlcBaseForm.SetDefaultProtocol(deltaIACommProtocol);
  49. BackgroundService.Instance = new BackgroundService(deltaIACommProtocol);
  50. var con = deltaIACommProtocol.ConnectPLC();
  51. if (con.rt != 0)
  52. {
  53. MessageBox.Show($"PLC连接失败:代码0X{con.rt:X}。请排查!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  54. }
  55. //初始化权限系统
  56. PermissionManager.Initialize();
  57. var signInForm = new SignInForm("developer", "developer123");
  58. Application.Run(signInForm);
  59. if (signInForm.DialogResult == DialogResult.OK)
  60. {
  61. BackgroundService.Instance.Start();
  62. Application.AddMessageFilter(new InputMessageFilter());
  63. Application.Run(new MainForm());
  64. BackgroundService.Instance.Stop();
  65. }
  66. if (con.rt == 0)
  67. deltaIACommProtocol.Close();
  68. }
  69. else
  70. {
  71. Application.Exit();
  72. }
  73. }
  74. }
  75. }
  76. }