ShellView.xaml.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. using Prism.Regions;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using CyberX8_Themes.CustomControls;
  5. using Venus_Unity;
  6. using System.Linq;
  7. using System.Threading;
  8. using System;
  9. using CyberX8_MainPages.Views;
  10. using System.Windows.Controls;
  11. using Aitex.Core.UI.View.Frame;
  12. using System.Windows.Media;
  13. using CyberX8_Core;
  14. using System.Reflection;
  15. using CyberX8_MainPages.Unity;
  16. using MECF.Framework.Common.DataCenter;
  17. using MECF.Framework.Common.OperationCenter;
  18. using Aitex.Core.RT.OperationCenter;
  19. using CyberX8_MainPages.ViewModels;
  20. using MECF.Framework.Common.CommonData;
  21. using System.Windows.Controls.Primitives;
  22. using System.Timers;
  23. using System.Windows.Threading;
  24. using CyberX8_Themes.Unity;
  25. using CyberX8_Themes.UserControls;
  26. using OpenSEMI.Ctrlib.Controls;
  27. using OpenSEMI.ClientBase;
  28. using MECF.Framework.Common.Equipment;
  29. using WinInterop = System.Windows.Interop;
  30. using System.Runtime.InteropServices;
  31. using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
  32. using Aitex.Core.RT.IOCore;
  33. using CyberX8_UI.Themes.Attach;
  34. using CyberX8_MainPages.Roles;
  35. using System.Collections.ObjectModel;
  36. using System.Diagnostics;
  37. using System.Windows.Input;
  38. using System.Net.Sockets;
  39. using System.Net;
  40. namespace CyberX8_UI.Views
  41. {
  42. /// <summary>
  43. /// ShellView.xaml 的交互逻辑
  44. /// </summary>
  45. public partial class ShellView : Window
  46. {
  47. IRegionManager m_regionManager;
  48. IRegionNavigationService m_regionNavigationService;
  49. List<VenusMenu> MainMenu;
  50. List<TabControl> centerTabViews = new List<TabControl>();
  51. List<Button> buttonList = new List<Button>();
  52. DispatcherTimer timer = new DispatcherTimer();
  53. List<AduRadioButtonIcon> _aduRadioButtons = new List<AduRadioButtonIcon>();
  54. Dictionary<string, int> _rootTabDic = new Dictionary<string, int>();
  55. Dictionary<string, int> _parentTabDic = new Dictionary<string, int>();
  56. Dictionary<string, int> _childrenTabDic = new Dictionary<string, int>();
  57. /// <summary>
  58. /// 1切多页面字典(key-主页面Id.子页面Id,value-子页面)
  59. /// </summary>
  60. Dictionary<string, TabItem> _multiMenuItemsDictionary = new Dictionary<string, TabItem>();
  61. readonly User _currentUser;
  62. RoleDefine _currentRole;
  63. ObservableCollection<RoleDefine> _roles;
  64. Stopwatch _logoutStopWatch;
  65. int _logoutTime;
  66. int _xPosition;
  67. private bool _isAllViewUnable = true;
  68. public ShellView(IRegionManager regionManager, IRegionNavigationService regionNavigationService)
  69. {
  70. InitializeComponent();
  71. LoginView loginView = new LoginView();
  72. loginView.ShowDialog();
  73. _currentUser = loginView.CurrentUser;
  74. if (!loginView.IsLoginSuccess)
  75. {
  76. this.Close();
  77. }
  78. loginView = null;
  79. m_regionManager = regionManager;
  80. m_regionNavigationService = regionNavigationService;
  81. m_regionManager.RegisterViewWithRegion("TopRegion", typeof(CyberX8_MainPages.Views.TopView));
  82. CyberX8_Core.GlobalEvents.SlotRightClickChangedEvent += Instance_SlotRightClickChangedEvent;
  83. CyberX8_Core.GlobalEvents.SlotWaferTransferEvent += Instance_SlotStartTransferEvent;
  84. CyberX8_Core.GlobalEvents.SwitchFixedTabItem += GlobalEvents_SwitchFixedTabItem;
  85. CyberX8_Core.GlobalEvents.SwitchFixedChildSubItem += GlobalEvents_SwitchFixedChildSubItem;
  86. timer.Tick += timer_Tick;
  87. timer.Interval = TimeSpan.FromSeconds(0.5);
  88. timer.Start();
  89. UIEvents.PMDoorRaiseChangedEvent += UIEvents_PMDoorRaiseChangedEvent;
  90. UIEvents.LLTDoorRaiseChangedEvent += UIEvents_LLTDoorRaiseChangedEvent;
  91. UIEvents.LLEDoorRaiseChangedEvent += UIEvents_LLEDoorRaiseChangedEvent;
  92. UIEvents.ChamberCreateDeleteWaferEvent += UIEvents_ChamberCreateDeleteWaferEvent;
  93. this.SourceInitialized += (o, e) =>
  94. {
  95. System.IntPtr handler = (new WinInterop.WindowInteropHelper(this)).Handle;
  96. WinInterop.HwndSource.FromHwnd(handler).AddHook(new WinInterop.HwndSourceHook(WindowProc));
  97. };
  98. this.MaxHeight = SystemParameters.WorkArea.Height;
  99. ResizeMode = ResizeMode.CanMinimize;
  100. this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
  101. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  102. }
  103. static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  104. {
  105. ShowMessageDialog((Exception)e.ExceptionObject);
  106. }
  107. static void ShowMessageDialog(Exception ex)
  108. {
  109. string message = string.Format(" UI unknown exception:{0},\n", $"{ex.StackTrace} {DateTime.Now}");
  110. System.Windows.MessageBox.Show(message + ex.Message, "Unexpected exception", System.Windows.MessageBoxButton.YesNo,
  111. System.Windows.MessageBoxImage.Exclamation,
  112. System.Windows.MessageBoxResult.No,
  113. System.Windows.MessageBoxOptions.DefaultDesktopOnly);
  114. //Environment.Exit(0);
  115. }
  116. void timer_Tick(object sender, EventArgs e)
  117. {
  118. if (ControlPermission.Instance.Permission && _isAllViewUnable)
  119. {
  120. SetAllViewEnable();
  121. }
  122. if (!ControlPermission.Instance.Permission && !_isAllViewUnable)
  123. {
  124. SetAllViewDisable();
  125. }
  126. if (Anychange.needchange)
  127. {
  128. Anystationchange(Anychange.menuname, Anychange.args);
  129. Anychange.needchange = false;
  130. }
  131. Tag = DateTime.Now;
  132. if (GlobalLogin.Instance.ReLogin)
  133. {
  134. RestartUI();
  135. }
  136. if (_currentRole.IsLocked)
  137. {
  138. if (_xPosition == (int)(Mouse.GetPosition(this).X))
  139. {
  140. if (_logoutStopWatch.ElapsedMilliseconds > _currentRole.LockTime * 1000)
  141. {
  142. RestartUI();
  143. }
  144. }
  145. else
  146. {
  147. _logoutStopWatch.Restart();
  148. }
  149. }
  150. _xPosition = (int)(Mouse.GetPosition(this).X);
  151. }
  152. private void Instance_SlotRightClickChangedEvent(OpenSEMI.Ctrlib.Controls.Slot slot)
  153. {
  154. if (slot != null)
  155. {
  156. ContextMenu cm = ContextMenuManager.Instance.GetSlotMenus(slot);
  157. if (cm != null)
  158. {
  159. slot.ContextMenu = cm;
  160. }
  161. return;
  162. }
  163. }
  164. private void Instance_SlotStartTransferEvent(OpenSEMI.Ctrlib.Controls.DragDropEventArgs e)
  165. {
  166. string info = " from " + e.TranferFrom.ModuleID + " slot " + (e.TranferFrom.SlotID + 1).ToString() + " to " + e.TranferTo.ModuleID + " slot " + (e.TranferTo.SlotID + 1).ToString();
  167. string message = "Are you sure to transfer the wafer: \n" + info;
  168. WaferDialogViewModel vm = new WaferDialogViewModel();
  169. vm.ConfirmText = message;
  170. WaferDialogView dialog = new WaferDialogView()
  171. {
  172. Owner = Application.Current.MainWindow,
  173. };
  174. dialog.DataContext = vm;
  175. dialog.Height = 300;
  176. dialog.Width = 400;
  177. bool alignflag = false;
  178. bool coolingflag = false;
  179. double angel = 0;
  180. double coolingtime = 0;
  181. if (dialog.ShowDialog() == true)
  182. {
  183. alignflag = (bool)dialog.AlignFlag;
  184. coolingflag = (bool)dialog.CoolingFlag;
  185. if (alignflag && !string.IsNullOrEmpty(dialog.Angle))
  186. {
  187. angel = Convert.ToDouble(dialog.Angle);
  188. }
  189. if (coolingflag && !string.IsNullOrEmpty(dialog.CoolingTime))
  190. {
  191. coolingtime = Convert.ToDouble(dialog.CoolingTime);
  192. }
  193. //from robot to robot is illegal. Must be stop
  194. if (e.TranferFrom.ModuleID == e.TranferTo.ModuleID && (e.TranferTo.ModuleID == ModuleName.EfemRobot.ToString()))
  195. {
  196. }
  197. else
  198. InvokeClient.Instance.Service.DoOperation("System.MoveWafer",
  199. e.TranferFrom.ModuleID, e.TranferFrom.SlotID, e.TranferTo.ModuleID, e.TranferTo.SlotID, alignflag, angel, coolingflag, coolingtime, "");
  200. }
  201. else
  202. {
  203. ModuleManager.OnFlashWafer(new FlashWaferInformation() { ModuleName = e.TranferFrom.ModuleID, SoltId = e.TranferFrom.SlotID });
  204. //ModuleManager.OnFlashWafer(new FlashWaferInformation() { ModuleName = e.TranferTo.ModuleID, SoltId = e.TranferTo.SlotID });
  205. }
  206. e.TranferFrom.ClearDragDropStatus();
  207. e.TranferTo.ClearDragDropStatus();
  208. }
  209. /// <summary>
  210. /// 将所有页面设置成disable
  211. /// </summary>
  212. private void SetAllViewDisable()
  213. {
  214. _isAllViewUnable = true;
  215. for (int i = 0; i < MainMenu.Count; i++)
  216. {
  217. TabControl tabcontrol = centerTabViews[0];
  218. VenusMenu item = MainMenu[i];
  219. for (int j = 0; j < item.MenuItem.Count; j++)
  220. {
  221. SubItem subitem = item.MenuItem[j];
  222. if (!subitem.IsShow)
  223. {
  224. continue;
  225. }
  226. if (string.IsNullOrEmpty(subitem.View))
  227. {
  228. if (subitem.MenuItem != null)
  229. {
  230. for (int k = 0; k < subitem.MenuItem.Count; k++)
  231. {
  232. SubItem secSubItem = subitem.MenuItem[k];
  233. if (!string.IsNullOrEmpty(secSubItem.View) && secSubItem.IsShow)
  234. {
  235. TabItem tabItem = _multiMenuItemsDictionary[$"{secSubItem.Name}.{secSubItem.Id}"];
  236. Control control = (tabItem.Content as Control);
  237. control.IsEnabled = false;
  238. }
  239. if (secSubItem.MultiItem != null)
  240. {
  241. for (int h = 0; h < secSubItem.MultiItem.Count; h++)
  242. {
  243. SubItem hideSubItem = secSubItem.MultiItem[h];
  244. if (hideSubItem.View != null)
  245. {
  246. TabItem tabItem = _multiMenuItemsDictionary[$"{hideSubItem.ModuleName}.{hideSubItem.Id}"];
  247. Control control = (tabItem.Content as Control);
  248. control.IsEnabled = false;
  249. }
  250. }
  251. }
  252. }
  253. }
  254. }
  255. else
  256. {
  257. TabItem tabItem = _multiMenuItemsDictionary[$"{subitem.Name}.{subitem.Id}"];
  258. Control ctrl = (tabItem.Content as Control);
  259. ctrl.IsEnabled = false;
  260. }
  261. }
  262. }
  263. }
  264. /// <summary>
  265. /// 将所有页面根据角色权限设置为enable
  266. /// </summary>
  267. private void SetAllViewEnable()
  268. {
  269. _isAllViewUnable = false;
  270. for (int i = 0; i < MainMenu.Count; i++)
  271. {
  272. TabControl tabcontrol = centerTabViews[0];
  273. VenusMenu item = MainMenu[i];
  274. ObservableCollection<CyberX8_MainPages.Roles.Menu> menus = _currentRole.Menus[i].Menus;
  275. for (int j = 0; j < item.MenuItem.Count; j++)
  276. {
  277. SubItem subitem = item.MenuItem[j];
  278. if (!subitem.IsShow)
  279. {
  280. continue;
  281. }
  282. if (string.IsNullOrEmpty(subitem.View))
  283. {
  284. if (subitem.MenuItem != null)
  285. {
  286. ObservableCollection<CyberX8_MainPages.Roles.Menu> submenus = menus[j].Menus;
  287. for (int k = 0; k < subitem.MenuItem.Count; k++)
  288. {
  289. SubItem secSubItem = subitem.MenuItem[k];
  290. if (!string.IsNullOrEmpty(secSubItem.View) && secSubItem.IsShow)
  291. {
  292. if (_multiMenuItemsDictionary.ContainsKey($"{secSubItem.Name}.{secSubItem.Id}"))
  293. {
  294. TabItem tabItem = _multiMenuItemsDictionary[$"{secSubItem.Name}.{secSubItem.Id}"];
  295. Control control = (tabItem.Content as Control);
  296. if (submenus[k] != null && submenus[k].Permission == MenuPermission.ReadWrite)
  297. {
  298. control.IsEnabled = true;
  299. }
  300. }
  301. }
  302. if (secSubItem.MultiItem != null)
  303. {
  304. ObservableCollection<CyberX8_MainPages.Roles.Menu> secSubmenus = submenus[k].Menus;
  305. for (int h = 0; h < secSubItem.MultiItem.Count; h++)
  306. {
  307. SubItem hideSubItem = secSubItem.MultiItem[h];
  308. if (hideSubItem.View != null)
  309. {
  310. if (_multiMenuItemsDictionary.ContainsKey($"{hideSubItem.ModuleName}.{hideSubItem.Id}"))
  311. {
  312. TabItem tabItem = _multiMenuItemsDictionary[$"{hideSubItem.ModuleName}.{hideSubItem.Id}"];
  313. Control control = (tabItem.Content as Control);
  314. if (h < secSubmenus.Count && secSubmenus[h] != null && secSubmenus[h].Permission == MenuPermission.ReadWrite)
  315. {
  316. control.IsEnabled = true;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. }
  325. else
  326. {
  327. if (menus[j] != null && menus[j].Permission == MenuPermission.None)
  328. {
  329. continue;
  330. }
  331. TabItem tabItem = _multiMenuItemsDictionary[$"{subitem.Name}.{subitem.Id}"];
  332. Control ctrl = (tabItem.Content as Control);
  333. if (menus[j] != null && menus[j].Permission == MenuPermission.ReadWrite)
  334. {
  335. ctrl.IsEnabled = true;
  336. }
  337. }
  338. }
  339. }
  340. }
  341. private void CustomWnd_Loaded(object sender, RoutedEventArgs e)
  342. {
  343. var h1 = SystemParameters.WorkArea.Height;
  344. var h2 = SystemParameters.PrimaryScreenHeight;
  345. //this.ResizeMode = ResizeMode.CanResize;
  346. //System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth
  347. MainMenu = SerializeHelper.Instance.ReadFromJsonFile<List<VenusMenu>>($"Config/UIMenu.json");
  348. _roles = SerializeHelper.Instance.ReadFromJsonFile<ObservableCollection<RoleDefine>>($"Config/UIMenu_permission.json");
  349. int role = (int)_currentUser.Role;
  350. _currentRole = _roles[role];
  351. int index = 0;
  352. for (int i = 0; i < MainMenu.Count; i++)
  353. {
  354. if (MainMenu[i].IsShow == false)
  355. {
  356. continue;
  357. }
  358. AduRadioButtonIcon aduRadioButtonIcon = new AduRadioButtonIcon();
  359. if (i == 0)
  360. {
  361. aduRadioButtonIcon.IsChecked = true;
  362. }
  363. IconElement.SetPathData(aduRadioButtonIcon, (Geometry)aduRadioButtonIcon.FindResource($"Icon_{MainMenu[i].Id}"));
  364. aduRadioButtonIcon.Content = MainMenu[i].Name;
  365. aduRadioButtonIcon.Click += AduRadioButtonIcon_Click;
  366. aduRadioButtonIcon.SelectBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#6AD7FF"));
  367. aduRadioButtonIcon.SelectColor = new SolidColorBrush((Colors.Black));
  368. aduRadioButtonIcon.DefaultBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#94BCD7"));
  369. //aduRadioButtonIcon.DefaultBackground = new SolidColorBrush(Colors.DarkGray);
  370. aduRadioButtonIcon.Width = 180;
  371. aduRadioButtonIcon.Height = 40;
  372. //aduRadioButtonIcon.Foreground=Brushes.White;
  373. aduRadioButtonIcon.Tag = index;
  374. index += 1;
  375. Bottom_Frame.Children.Add(aduRadioButtonIcon);
  376. _aduRadioButtons.Add(aduRadioButtonIcon);
  377. TabControl tabControl = new TabControl();
  378. tabControl.TabIndex = index;
  379. _rootTabDic[MainMenu[i].Id] = index;
  380. AddSubItem(tabControl, MainMenu[i].MenuItem,index, _currentRole.Menus[i].Menus);
  381. centerTabViews.Add(tabControl);
  382. }
  383. Main_Frame.Content = centerTabViews[0];
  384. ModuleManager.Initialize();
  385. //用户锁
  386. if (_currentRole.IsLocked == true)
  387. {
  388. _logoutStopWatch = new Stopwatch();
  389. _logoutStopWatch.Start();
  390. _logoutTime = _currentRole.LockTime;
  391. }
  392. }
  393. private void AddSubItem(TabControl tabControl,List<SubItem> subItems,int parentIndex, ObservableCollection<CyberX8_MainPages.Roles.Menu> menus)
  394. {
  395. int index = parentIndex*100;
  396. for(int i=0;i<subItems.Count;i++)
  397. {
  398. object obj = null;
  399. SubItem item= subItems[i];
  400. if(!item.IsShow)
  401. {
  402. continue;
  403. }
  404. if(string.IsNullOrEmpty(item.View))
  405. {
  406. if (item.MenuItem != null)
  407. {
  408. obj = new TabControl();
  409. ((TabControl)obj).Name = item.Id;
  410. AddSubItem((TabControl)obj, item.MenuItem, index, menus[i].Menus);
  411. _parentTabDic[item.Id] = index;
  412. }
  413. else if (item.MultiItem != null)
  414. {
  415. //把reservoir主页也加入子页面字典,用于从主页跳转到reservoir页面
  416. _childrenTabDic[item.MultiItem[0].Id.ToString()] = index;
  417. TabItem mainTabItem = InitializeMultiItem(item.ModuleName, item.MultiItem, menus[i].Menus);
  418. if (mainTabItem != null)
  419. {
  420. mainTabItem.TabIndex = index;
  421. index++;
  422. tabControl.Items.Add(mainTabItem);
  423. }
  424. continue;
  425. }
  426. }
  427. else
  428. {
  429. //None权限
  430. if (menus[i]!= null && menus[i].Permission == MenuPermission.None)
  431. {
  432. continue;
  433. }
  434. string viewClassName = $"CyberX8_MainPages.Views.{item.View}";
  435. Type viewType = Type.GetType($"{viewClassName},CyberX8_MainPages");
  436. obj = System.Activator.CreateInstance(viewType);
  437. _childrenTabDic[item.Id] = index;
  438. }
  439. TabItem tabItem = new TabItem() { Header = item.Name, Content = obj };
  440. Control ctrl = (tabItem.Content as Control);
  441. ctrl.Name = item.ModuleName;
  442. ctrl.IsVisibleChanged += TabItem_IsVisibleChanged;
  443. //登录进去无控制权限
  444. if (_isAllViewUnable)
  445. {
  446. ctrl.IsEnabled = false;
  447. }
  448. //只读权限
  449. if (menus[i] != null && menus[i].Permission == MenuPermission.ReadOnly)
  450. {
  451. ctrl.IsEnabled = false;
  452. }
  453. tabItem.TabIndex=index;
  454. index++;
  455. tabControl.Items.Add(tabItem);
  456. _multiMenuItemsDictionary.Add($"{item.Name}.{item.Id}", tabItem);
  457. //一级标题module某块本身也有一个item对象,任何时刻都要使其可用,确保module二级标题可以点
  458. for (int j = 0; j < subItems.Count; j++)
  459. {
  460. SubItem item1 = subItems[i];
  461. if (string.IsNullOrEmpty(item1.View))
  462. {
  463. TabItem selfItem = _multiMenuItemsDictionary[$"{item1.Name}.{item1.Id}"];
  464. Control selfControl = (selfItem.Content as Control);
  465. selfControl.IsEnabled = true;
  466. }
  467. }
  468. }
  469. if(tabControl.Items.Count!=0)
  470. {
  471. tabControl.SelectedIndex = 0;
  472. }
  473. }
  474. private TabItem InitializeMultiItem(string moduleName, List<SubItem> subItems, ObservableCollection<CyberX8_MainPages.Roles.Menu> menus)
  475. {
  476. TabItem mainTabItem = null;
  477. foreach(SubItem item in subItems)
  478. {
  479. int menusIndex = subItems.IndexOf(item);
  480. //None权限
  481. if (menus[menusIndex] != null & menus[menusIndex].Permission == MenuPermission.None)
  482. {
  483. continue;
  484. }
  485. string viewClassName = $"CyberX8_MainPages.Views.{item.View}";
  486. Type viewType = Type.GetType($"{viewClassName},CyberX8_MainPages");
  487. Object obj = System.Activator.CreateInstance(viewType);
  488. TabItem tabItem = new TabItem() { Header = moduleName, Content = obj };
  489. Control ctrl = (tabItem.Content as Control);
  490. ctrl.Name = item.ModuleName;
  491. ctrl.IsVisibleChanged += TabItem_IsVisibleChanged;
  492. //登录进去无控制权限
  493. if (_isAllViewUnable)
  494. {
  495. ctrl.IsEnabled = false;
  496. }
  497. //只读权限
  498. if (menus[menusIndex] != null && menus[menusIndex].Permission == MenuPermission.ReadOnly)
  499. {
  500. ctrl.IsEnabled = false;
  501. }
  502. _multiMenuItemsDictionary[$"{moduleName}.{item.Id}"] = tabItem;
  503. if (mainTabItem == null&&item.IsShow)
  504. {
  505. mainTabItem = tabItem;
  506. }
  507. }
  508. return mainTabItem;
  509. }
  510. /// <summary>
  511. /// 重启UI
  512. /// </summary>
  513. private void RestartUI()
  514. {
  515. // 获取当前执行的程序集
  516. Assembly assembly = Assembly.GetExecutingAssembly();
  517. // 获取当前执行的程序集的全名
  518. AssemblyName assemblyName = assembly.GetName();
  519. // 构建一个新的进程启动信息,以便重新启动当前应用程序
  520. ProcessStartInfo startInfo = new ProcessStartInfo
  521. {
  522. FileName = assembly.Location,
  523. UseShellExecute = true
  524. };
  525. // 关闭当前应用程序
  526. Application.Current.Shutdown();
  527. // 创建一个新的进程来运行当前应用程序
  528. Process.Start(startInfo);
  529. }
  530. /// <summary>
  531. /// 所有页面可见性发生变化事件
  532. /// </summary>
  533. /// <param name="sender"></param>
  534. /// <param name="e"></param>
  535. private void TabItem_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  536. {
  537. //TabItem control = sender as TabItem;
  538. Control control = sender as Control;
  539. var viewmodel = control.DataContext;
  540. if (viewmodel != null)
  541. {
  542. Type t = viewmodel.GetType();
  543. if (e.NewValue != null)
  544. {
  545. bool isShow = (bool)e.NewValue;
  546. if (isShow)
  547. {
  548. MethodInfo methodInfo = t.GetMethod("LoadData");
  549. methodInfo?.Invoke(viewmodel, new object[] { control.Name });
  550. }
  551. else
  552. {
  553. MethodInfo methodInfo = t.GetMethod("Hide");
  554. methodInfo?.Invoke(viewmodel, null);
  555. }
  556. }
  557. else
  558. {
  559. MethodInfo methodInfo = t.GetMethod("Hide");
  560. methodInfo?.Invoke(viewmodel, null);
  561. }
  562. }
  563. }
  564. public void Anystationchange(string menuviewItem, WaferHistoryWafer queryFilter)
  565. {
  566. UserControl address = new ProcessHistoryView();
  567. ProcessHistoryViewModel vm = new ProcessHistoryViewModel() { };
  568. vm.searchlot(queryFilter.WaferGuid);
  569. //vm.OnDataGridSelectionChanged(vm.Recipes[0]);
  570. address.DataContext = vm;
  571. int s = 0;
  572. for (int i = 0; i < centerTabViews.Count; i++)
  573. {
  574. var item = centerTabViews[i];
  575. foreach (TabItem v in item.Items)
  576. {
  577. if (v.Header.ToString() == "Process History")
  578. {
  579. s = i;
  580. }
  581. }
  582. }
  583. if (s != 0)
  584. {
  585. centerTabViews[s].Items[2] = new TabItem() { Header = menuviewItem, Content = address };
  586. centerTabViews[s].SelectedIndex = 2;
  587. Main_Frame.Content = centerTabViews[s];
  588. }
  589. }
  590. private void AduRadioButtonIcon_Click(object sender, RoutedEventArgs e)
  591. {
  592. var currentButton = sender as AduRadioButtonIcon;
  593. Main_Frame.Content = centerTabViews[Convert.ToInt32(currentButton.Tag)];
  594. }
  595. /// <summary>
  596. /// 手动切换菜单
  597. /// </summary>
  598. /// <param name="root"></param>
  599. /// <param name="parent"></param>
  600. /// <param name="children"></param>
  601. private void GlobalEvents_SwitchFixedTabItem(string root, string parent, string children)
  602. {
  603. if (_rootTabDic.ContainsKey(root))
  604. {
  605. int rootIndex = _rootTabDic[root];
  606. if (rootIndex-1 < centerTabViews.Count)
  607. {
  608. Main_Frame.Content = centerTabViews[rootIndex-1];
  609. TabControl rootTab = centerTabViews[rootIndex-1];
  610. _aduRadioButtons[rootIndex-1].IsChecked=true;
  611. if (!string.IsNullOrEmpty(parent))
  612. {
  613. if (_parentTabDic.ContainsKey(parent))
  614. {
  615. int parentIndex = _parentTabDic[parent];
  616. rootTab.SelectedIndex = parentIndex-rootIndex*100;
  617. TabItem parentTabItem = rootTab.Items[rootTab.SelectedIndex] as TabItem;
  618. if (_childrenTabDic.ContainsKey(children))
  619. {
  620. TabControl parentTab=parentTabItem.Content as TabControl;
  621. int childrenIndex = _childrenTabDic[children];
  622. parentTab.SelectedIndex = childrenIndex-parentIndex*100;
  623. }
  624. }
  625. }
  626. else
  627. {
  628. if (_childrenTabDic.ContainsKey(children))
  629. {
  630. int childeIndex = _childrenTabDic[children];
  631. rootTab.SelectedIndex = childeIndex - rootTab.TabIndex * 100;
  632. }
  633. }
  634. }
  635. }
  636. }
  637. /// <summary>
  638. /// Reservoir切换页面
  639. /// </summary>
  640. /// <param name="child"></param>
  641. /// <param name="subItem"></param>
  642. /// <exception cref="NotImplementedException"></exception>
  643. private void GlobalEvents_SwitchFixedChildSubItem(string child, string subItem)
  644. {
  645. if (_multiMenuItemsDictionary.ContainsKey($"{child}.{subItem}"))
  646. {
  647. TabItem tabItem = _multiMenuItemsDictionary[$"{child}.{subItem}"];
  648. TabControl rootTabControl = (TabControl)Main_Frame.Content;
  649. if (rootTabControl == null) { return; }
  650. if (rootTabControl.SelectedIndex == -1 || rootTabControl.SelectedIndex > rootTabControl.Items.Count - 1)
  651. {
  652. return;
  653. }
  654. TabItem parentTab = rootTabControl.Items[rootTabControl.SelectedIndex] as TabItem;
  655. if(parentTab == null) { return; }
  656. TabControl parentContentTab= parentTab.Content as TabControl;
  657. if(parentContentTab == null) { return; }
  658. if(parentContentTab.SelectedIndex==-1|| parentContentTab.SelectedIndex > parentContentTab.Items.Count - 1)
  659. {
  660. return;
  661. }
  662. int selectedIndex=parentContentTab.SelectedIndex;
  663. parentContentTab.SelectedIndex = -1;
  664. parentContentTab.Items[selectedIndex] = tabItem;
  665. parentContentTab.SelectedIndex = selectedIndex;
  666. }
  667. }
  668. private void CustomWnd_Closed(object sender, EventArgs e)
  669. {
  670. string ipConfigFilter = "";
  671. if (_isAllViewUnable == false)
  672. {
  673. var ipconfig = QueryDataClient.Instance.Service.GetConfig($"System.ControlIPFilter");
  674. if (ipconfig != null)
  675. {
  676. ipConfigFilter = ipconfig.ToString();
  677. }
  678. List<string> localIPs = new List<string>();
  679. string hostName = Dns.GetHostName();
  680. IPHostEntry host = Dns.GetHostEntry(hostName);
  681. foreach (IPAddress ip in host.AddressList)
  682. {
  683. if (ip.AddressFamily == AddressFamily.InterNetwork && ip.ToString().Trim().StartsWith($"{ipConfigFilter}"))
  684. {
  685. localIPs.Add(ip.ToString());
  686. }
  687. }
  688. if (localIPs.Count > 0)
  689. {
  690. InvokeClient.Instance.Service.DoOperation($"ReleaseSystemControl", localIPs[0]);
  691. }
  692. }
  693. System.Diagnostics.Process.GetCurrentProcess().Kill();
  694. }
  695. private void UIEvents_ChamberCreateDeleteWaferEvent(WaferOperation obj)
  696. {
  697. if (obj.IsCreate == true)
  698. {
  699. InvokeClient.Instance.Service.DoOperation("CreateWafer", obj.ModuleName, 0);
  700. }
  701. else
  702. {
  703. InvokeClient.Instance.Service.DoOperation("DeleteWafer", obj.ModuleName, 0);
  704. }
  705. }
  706. private void UIEvents_PMDoorRaiseChangedEvent(DoorPara obj)
  707. {
  708. //InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SlitDoor.{obj?.IsOpen}");
  709. InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SetSlitDoor", obj.IsOpen == "Open" ? true : false);
  710. }
  711. private void UIEvents_LLTDoorRaiseChangedEvent(DoorPara obj)
  712. {
  713. InvokeClient.Instance.Service.DoOperation($"TM.SetMFSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  714. }
  715. private void UIEvents_LLEDoorRaiseChangedEvent(DoorPara obj)
  716. {
  717. InvokeClient.Instance.Service.DoOperation($"TM.SetEFEMSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  718. }
  719. #region 调用api功能部分
  720. void win_SourceInitialized(object sender, EventArgs e)
  721. {
  722. System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
  723. WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
  724. }
  725. private static System.IntPtr WindowProc(
  726. System.IntPtr hwnd,
  727. int msg,
  728. System.IntPtr wParam,
  729. System.IntPtr lParam,
  730. ref bool handled)
  731. {
  732. switch (msg)
  733. {
  734. case 0x0024:
  735. WmGetMinMaxInfo(hwnd, lParam);
  736. handled = true;
  737. break;
  738. }
  739. return (System.IntPtr)0;
  740. }
  741. private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
  742. {
  743. MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
  744. // Adjust the maximized size and position to fit the work area of the correct monitor
  745. int MONITOR_DEFAULTTONEAREST = 0x00000002;
  746. System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
  747. if (monitor != System.IntPtr.Zero)
  748. {
  749. MONITORINFO monitorInfo = new MONITORINFO();
  750. GetMonitorInfo(monitor, monitorInfo);
  751. RECT rcWorkArea = monitorInfo.rcWork;
  752. RECT rcMonitorArea = monitorInfo.rcMonitor;
  753. mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
  754. mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
  755. mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
  756. mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
  757. }
  758. Marshal.StructureToPtr(mmi, lParam, true);
  759. }
  760. /// <summary>
  761. /// POINT aka POINTAPI
  762. /// </summary>
  763. [StructLayout(LayoutKind.Sequential)]
  764. public struct POINT
  765. {
  766. /// <summary>
  767. /// x coordinate of point.
  768. /// </summary>
  769. public int x;
  770. /// <summary>
  771. /// y coordinate of point.
  772. /// </summary>
  773. public int y;
  774. /// <summary>
  775. /// Construct a point of coordinates (x,y).
  776. /// </summary>
  777. public POINT(int x, int y)
  778. {
  779. this.x = x;
  780. this.y = y;
  781. }
  782. }
  783. [StructLayout(LayoutKind.Sequential)]
  784. public struct MINMAXINFO
  785. {
  786. public POINT ptReserved;
  787. public POINT ptMaxSize;
  788. public POINT ptMaxPosition;
  789. public POINT ptMinTrackSize;
  790. public POINT ptMaxTrackSize;
  791. };
  792. /// <summary>
  793. /// </summary>
  794. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  795. public class MONITORINFO
  796. {
  797. /// <summary>
  798. /// </summary>
  799. public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
  800. /// <summary>
  801. /// </summary>
  802. public RECT rcMonitor = new RECT();
  803. /// <summary>
  804. /// </summary>
  805. public RECT rcWork = new RECT();
  806. /// <summary>
  807. /// </summary>
  808. public int dwFlags = 0;
  809. }
  810. /// <summary> Win32 </summary>
  811. [StructLayout(LayoutKind.Sequential, Pack = 0)]
  812. public struct RECT
  813. {
  814. /// <summary> Win32 </summary>
  815. public int left;
  816. /// <summary> Win32 </summary>
  817. public int top;
  818. /// <summary> Win32 </summary>
  819. public int right;
  820. /// <summary> Win32 </summary>
  821. public int bottom;
  822. /// <summary> Win32 </summary>
  823. public static readonly RECT Empty = new RECT();
  824. /// <summary> Win32 </summary>
  825. public int Width
  826. {
  827. get { return Math.Abs(right - left); } // Abs needed for BIDI OS
  828. }
  829. /// <summary> Win32 </summary>
  830. public int Height
  831. {
  832. get { return bottom - top; }
  833. }
  834. /// <summary> Win32 </summary>
  835. public RECT(int left, int top, int right, int bottom)
  836. {
  837. this.left = left;
  838. this.top = top;
  839. this.right = right;
  840. this.bottom = bottom;
  841. }
  842. /// <summary> Win32 </summary>
  843. public RECT(RECT rcSrc)
  844. {
  845. this.left = rcSrc.left;
  846. this.top = rcSrc.top;
  847. this.right = rcSrc.right;
  848. this.bottom = rcSrc.bottom;
  849. }
  850. /// <summary> Win32 </summary>
  851. public bool IsEmpty
  852. {
  853. get
  854. {
  855. // BUGBUG : On Bidi OS (hebrew arabic) left > right
  856. return left >= right || top >= bottom;
  857. }
  858. }
  859. /// <summary> Return a user friendly representation of this struct </summary>
  860. public override string ToString()
  861. {
  862. if (this == RECT.Empty) { return "RECT {Empty}"; }
  863. return "RECT { left : " + left + " / top : " + top + " / right : " + right + " / bottom : " + bottom + " }";
  864. }
  865. /// <summary> Determine if 2 RECT are equal (deep compare) </summary>
  866. public override bool Equals(object obj)
  867. {
  868. if (!(obj is Rect)) { return false; }
  869. return (this == (RECT)obj);
  870. }
  871. /// <summary>Return the HashCode for this struct (not garanteed to be unique)</summary>
  872. public override int GetHashCode()
  873. {
  874. return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
  875. }
  876. /// <summary> Determine if 2 RECT are equal (deep compare)</summary>
  877. public static bool operator ==(RECT rect1, RECT rect2)
  878. {
  879. return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
  880. }
  881. /// <summary> Determine if 2 RECT are different(deep compare)</summary>
  882. public static bool operator !=(RECT rect1, RECT rect2)
  883. {
  884. return !(rect1 == rect2);
  885. }
  886. }
  887. [DllImport("user32")]
  888. internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
  889. /// <summary>
  890. ///
  891. /// </summary>
  892. [DllImport("User32")]
  893. internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
  894. #endregion
  895. }
  896. }