MainWindow.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using ivf_tl_Operate.View;
  2. using ivf_tl_Operate.ViewModel;
  3. using ivf_tl_Operate.Windows;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace ivf_tl_Operate
  20. {
  21. /// <summary>
  22. /// Interaction logic for MainWindow.xaml
  23. /// </summary>
  24. public partial class MainWindow : Window
  25. {
  26. public MainWindow()
  27. {
  28. InitializeComponent();
  29. //DisableWPFTabletSupport();
  30. Loaded += MainWindow_Loaded;
  31. // M4-01-1:自适应竖屏框架。原仅 #if DEBUG 才用 Viewbox 等比缩放,
  32. // 导致 Release 无缩放、换分辨率必错位。此处去掉条件编译,让 Viewbox
  33. // 在所有配置(含 Release)生效:MainGrid → Viewbox(Stretch=Uniform,等比保竖屏比例) → 窗口内容。
  34. // 窗口尺寸由 WindowState=Maximized 铺满实际屏幕,不再硬编码 1824×2736(已删 .xaml 写死 Width/Height)。
  35. // [D6] 最终是否需 Stretch=Fill 或切真弹性布局、设计基准分辨率取值依赖 Surface 真机,登记待验证。
  36. Grid originalCanvas = MainGrid;
  37. this.Content = null;
  38. Viewbox viewbox = new Viewbox
  39. {
  40. Child = originalCanvas,
  41. Stretch = Stretch.Uniform
  42. };
  43. this.Content = viewbox;
  44. }
  45. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  46. {
  47. var a = new LoginWindow(this).ShowDialog();
  48. if (a != true)
  49. {
  50. this.Close();
  51. return;
  52. }
  53. AppData.Instance.MainWindow = this;
  54. MainPageViewModel mainPageViewModel = new MainPageViewModel(AppData.Instance.TlSn);
  55. MainPageView mainPageView = new MainPageView();
  56. mainPageView.DataContext = mainPageViewModel;
  57. AppData.Instance.MainPageView = mainPageView;
  58. LoadPage(mainPageView);
  59. // 双进程改造:control 已剥离为独立进程 ivf_tl_ControlHost.exe。
  60. // operate 登录后只负责"确保 control 在跑"(探活→不在则拉起→轮询就绪),
  61. // 不再在本进程内跑 StartRun。operate 关闭后 control 继续驱动机器。
  62. System.Threading.Tasks.Task.Run(() =>
  63. {
  64. try
  65. {
  66. string account = AppData.Instance.CurrentUserInfo.account;
  67. string password = AppData.Instance.CurrentUserInfo.password;
  68. string cacheDisk = System.Configuration.ConfigurationManager.AppSettings["cacheDisk"] ?? "C";
  69. if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
  70. {
  71. ivf_tl_Services.Log4netHelper.WriteLog("跳过拉起 control:operate 登录账号/密码为空");
  72. return;
  73. }
  74. bool ok = ivf_tl_Operate.Helpers.ControlProcessLauncher.EnsureRunning(
  75. account, password, cacheDisk,
  76. msg => ivf_tl_Services.Log4netHelper.WriteLog(msg));
  77. ivf_tl_Services.Log4netHelper.WriteLog(ok ? "control 进程就绪" : "control 进程未就绪(降级:operate 仍可用)");
  78. }
  79. catch (Exception ex)
  80. {
  81. ivf_tl_Services.Log4netHelper.WriteLog("确保 control 运行异常", ex);
  82. }
  83. });
  84. }
  85. public void LoadPage(UserControl t)
  86. {
  87. _container.Content = t;
  88. }
  89. /// <summary>
  90. /// 显示与隐藏遮罩层
  91. /// </summary>
  92. /// <param name="v"></param>
  93. public void Mark(bool v)
  94. {
  95. Application.Current.Dispatcher.Invoke(() =>
  96. {
  97. if (v == true)
  98. {
  99. this._mask.Visibility = Visibility.Visible;
  100. }
  101. else
  102. {
  103. this._mask.Visibility = Visibility.Hidden;
  104. }
  105. });
  106. }
  107. public void DisableWPFTabletSupport()
  108. {
  109. TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;
  110. if (devices.Count > 0)
  111. {
  112. Type inputManagerType = typeof(System.Windows.Input.InputManager);
  113. object stylusLogic = inputManagerType.InvokeMember("StylusLogic", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, InputManager.Current, null);
  114. if (stylusLogic != null)
  115. {
  116. Type stylusLogicType = stylusLogic.GetType();
  117. while (devices.Count > 0)
  118. {
  119. stylusLogicType.InvokeMember("OnTabletRemoved",
  120. BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
  121. null, stylusLogic, new object[] { (uint)0 });
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }