ShellView.xaml.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  1. using Prism.Regions;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using PunkHPX8_Themes.CustomControls;
  5. using Venus_Unity;
  6. using System.Linq;
  7. using System.Threading;
  8. using System;
  9. using PunkHPX8_MainPages.Views;
  10. using System.Windows.Controls;
  11. using Aitex.Core.UI.View.Frame;
  12. using System.Windows.Media;
  13. using PunkHPX8_Core;
  14. using System.Reflection;
  15. using PunkHPX8_MainPages.Unity;
  16. using MECF.Framework.Common.DataCenter;
  17. using MECF.Framework.Common.OperationCenter;
  18. using Aitex.Core.RT.OperationCenter;
  19. using PunkHPX8_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 PunkHPX8_Themes.Unity;
  25. using PunkHPX8_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 PunkHPX8_UI.Themes.Attach;
  34. using PunkHPX8_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 PunkHPX8_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(PunkHPX8_MainPages.Views.TopView));
  82. PunkHPX8_Core.GlobalEvents.SlotRightClickChangedEvent += Instance_SlotRightClickChangedEvent;
  83. PunkHPX8_Core.GlobalEvents.SlotWaferTransferEvent += Instance_SlotStartTransferEvent;
  84. PunkHPX8_Core.GlobalEvents.SwitchFixedTabItem += GlobalEvents_SwitchFixedTabItem;
  85. PunkHPX8_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 (!item.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))
  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<PunkHPX8_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 (!item.IsShow)
  279. {
  280. continue;
  281. }
  282. if (string.IsNullOrEmpty(subitem.View))
  283. {
  284. if (subitem.MenuItem != null)
  285. {
  286. ObservableCollection<PunkHPX8_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))
  291. {
  292. TabItem tabItem = _multiMenuItemsDictionary[$"{secSubItem.Name}.{secSubItem.Id}"];
  293. Control control = (tabItem.Content as Control);
  294. if (submenus[k] != null && submenus[k].Permission == MenuPermission.ReadWrite)
  295. {
  296. control.IsEnabled = true;
  297. }
  298. }
  299. if (secSubItem.MultiItem != null)
  300. {
  301. ObservableCollection<PunkHPX8_MainPages.Roles.Menu> secSubmenus = submenus[k].Menus;
  302. for (int h = 0; h < secSubItem.MultiItem.Count; h++)
  303. {
  304. SubItem hideSubItem = secSubItem.MultiItem[h];
  305. if (hideSubItem.View != null)
  306. {
  307. TabItem tabItem = _multiMenuItemsDictionary[$"{hideSubItem.ModuleName}.{hideSubItem.Id}"];
  308. Control control = (tabItem.Content as Control);
  309. if (secSubmenus[h] != null && secSubmenus[h].Permission == MenuPermission.ReadWrite)
  310. {
  311. control.IsEnabled = true;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. else
  320. {
  321. if (menus[j] != null && menus[j].Permission == MenuPermission.None)
  322. {
  323. continue;
  324. }
  325. TabItem tabItem = _multiMenuItemsDictionary[$"{subitem.Name}.{subitem.Id}"];
  326. Control ctrl = (tabItem.Content as Control);
  327. if (menus[j] != null && menus[j].Permission == MenuPermission.ReadWrite)
  328. {
  329. ctrl.IsEnabled = true;
  330. }
  331. }
  332. }
  333. }
  334. }
  335. private void CustomWnd_Loaded(object sender, RoutedEventArgs e)
  336. {
  337. var h1 = SystemParameters.WorkArea.Height;
  338. var h2 = SystemParameters.PrimaryScreenHeight;
  339. //this.ResizeMode = ResizeMode.CanResize;
  340. //System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth
  341. MainMenu = SerializeHelper.Instance.ReadFromJsonFile<List<VenusMenu>>($"Config/UIMenu.json");
  342. _roles = SerializeHelper.Instance.ReadFromJsonFile<ObservableCollection<RoleDefine>>($"Config/UIMenu_permission.json");
  343. int role = (int)_currentUser.Role;
  344. _currentRole = _roles[role];
  345. int index = 0;
  346. for (int i = 0; i < MainMenu.Count; i++)
  347. {
  348. if (MainMenu[i].IsShow == false)
  349. {
  350. continue;
  351. }
  352. AduRadioButtonIcon aduRadioButtonIcon = new AduRadioButtonIcon();
  353. if (i == 0)
  354. {
  355. aduRadioButtonIcon.IsChecked = true;
  356. }
  357. IconElement.SetPathData(aduRadioButtonIcon, (Geometry)aduRadioButtonIcon.FindResource($"Icon_{MainMenu[i].Id}"));
  358. aduRadioButtonIcon.Content = MainMenu[i].Name;
  359. aduRadioButtonIcon.Click += AduRadioButtonIcon_Click;
  360. aduRadioButtonIcon.SelectBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#6AD7FF"));
  361. aduRadioButtonIcon.SelectColor = new SolidColorBrush((Colors.Black));
  362. aduRadioButtonIcon.DefaultBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#94BCD7"));
  363. //aduRadioButtonIcon.DefaultBackground = new SolidColorBrush(Colors.DarkGray);
  364. aduRadioButtonIcon.Width = 180;
  365. aduRadioButtonIcon.Height = 40;
  366. //aduRadioButtonIcon.Foreground=Brushes.White;
  367. aduRadioButtonIcon.Tag = index;
  368. index += 1;
  369. Bottom_Frame.Children.Add(aduRadioButtonIcon);
  370. _aduRadioButtons.Add(aduRadioButtonIcon);
  371. TabControl tabControl = new TabControl();
  372. tabControl.TabIndex = index;
  373. _rootTabDic[MainMenu[i].Id] = index;
  374. AddSubItem(tabControl, MainMenu[i].MenuItem,index, _currentRole.Menus[i].Menus);
  375. centerTabViews.Add(tabControl);
  376. }
  377. Main_Frame.Content = centerTabViews[0];
  378. ModuleManager.Initialize();
  379. //用户锁
  380. if (_currentRole.IsLocked == true)
  381. {
  382. _logoutStopWatch = new Stopwatch();
  383. _logoutStopWatch.Start();
  384. _logoutTime = _currentRole.LockTime;
  385. }
  386. }
  387. private void AddSubItem(TabControl tabControl,List<SubItem> subItems,int parentIndex, ObservableCollection<PunkHPX8_MainPages.Roles.Menu> menus)
  388. {
  389. int index = parentIndex*100;
  390. for(int i=0;i<subItems.Count;i++)
  391. {
  392. object obj = null;
  393. SubItem item= subItems[i];
  394. if(!item.IsShow)
  395. {
  396. continue;
  397. }
  398. if(string.IsNullOrEmpty(item.View))
  399. {
  400. if (item.MenuItem != null)
  401. {
  402. obj = new TabControl();
  403. ((TabControl)obj).Name = item.Id;
  404. AddSubItem((TabControl)obj, item.MenuItem, index, menus[i].Menus);
  405. _parentTabDic[item.Id] = index;
  406. }
  407. else if (item.MultiItem != null)
  408. {
  409. //把reservoir主页也加入子页面字典,用于从主页跳转到reservoir页面
  410. _childrenTabDic[item.MultiItem[0].Id.ToString()] = index;
  411. TabItem mainTabItem = InitializeMultiItem(item.ModuleName, item.MultiItem, menus[i].Menus);
  412. if (mainTabItem != null)
  413. {
  414. mainTabItem.TabIndex = index;
  415. index++;
  416. tabControl.Items.Add(mainTabItem);
  417. }
  418. continue;
  419. }
  420. }
  421. else
  422. {
  423. //None权限
  424. if (menus[i]!= null && menus[i].Permission == MenuPermission.None)
  425. {
  426. continue;
  427. }
  428. string viewClassName = $"PunkHPX8_MainPages.Views.{item.View}";
  429. Type viewType = Type.GetType($"{viewClassName},PunkHPX8_MainPages");
  430. if (viewType == null)
  431. {
  432. continue;
  433. }
  434. obj = System.Activator.CreateInstance(viewType);
  435. _childrenTabDic[item.Id] = index;
  436. }
  437. TabItem tabItem = new TabItem() { Header = item.Name, Content = obj };
  438. Control ctrl = (tabItem.Content as Control);
  439. ctrl.Name = item.ModuleName;
  440. ctrl.IsVisibleChanged += TabItem_IsVisibleChanged;
  441. //登录进去无控制权限
  442. if (_isAllViewUnable)
  443. {
  444. ctrl.IsEnabled = false;
  445. }
  446. //只读权限
  447. if (menus[i] != null && menus[i].Permission == MenuPermission.ReadOnly)
  448. {
  449. ctrl.IsEnabled = false;
  450. }
  451. tabItem.TabIndex=index;
  452. index++;
  453. tabControl.Items.Add(tabItem);
  454. _multiMenuItemsDictionary.Add($"{item.Name}.{item.Id}", tabItem);
  455. //一级标题module某块本身也有一个item对象,任何时刻都要使其可用,确保module二级标题可以点
  456. for (int j = 0; j < subItems.Count; j++)
  457. {
  458. SubItem item1 = subItems[i];
  459. if (string.IsNullOrEmpty(item1.View))
  460. {
  461. TabItem selfItem = _multiMenuItemsDictionary[$"{item1.Name}.{item1.Id}"];
  462. Control selfControl = (selfItem.Content as Control);
  463. selfControl.IsEnabled = true;
  464. }
  465. }
  466. }
  467. if(tabControl.Items.Count!=0)
  468. {
  469. tabControl.SelectedIndex = 0;
  470. }
  471. }
  472. private TabItem InitializeMultiItem(string moduleName, List<SubItem> subItems, ObservableCollection<PunkHPX8_MainPages.Roles.Menu> menus)
  473. {
  474. TabItem mainTabItem = null;
  475. foreach(SubItem item in subItems)
  476. {
  477. int menusIndex = subItems.IndexOf(item);
  478. //None权限
  479. if (menus[menusIndex] != null & menus[menusIndex].Permission == MenuPermission.None)
  480. {
  481. continue;
  482. }
  483. string viewClassName = $"PunkHPX8_MainPages.Views.{item.View}";
  484. Type viewType = Type.GetType($"{viewClassName},PunkHPX8_MainPages");
  485. Object obj = System.Activator.CreateInstance(viewType);
  486. TabItem tabItem = new TabItem() { Header = moduleName, Content = obj };
  487. Control ctrl = (tabItem.Content as Control);
  488. ctrl.Name = item.ModuleName;
  489. ctrl.IsVisibleChanged += TabItem_IsVisibleChanged;
  490. //登录进去无控制权限
  491. if (_isAllViewUnable)
  492. {
  493. ctrl.IsEnabled = false;
  494. }
  495. //只读权限
  496. if (menus[menusIndex] != null && menus[menusIndex].Permission == MenuPermission.ReadOnly)
  497. {
  498. ctrl.IsEnabled = false;
  499. }
  500. _multiMenuItemsDictionary[$"{moduleName}.{item.Id}"] = tabItem;
  501. if (mainTabItem == null&&item.IsShow)
  502. {
  503. mainTabItem = tabItem;
  504. }
  505. }
  506. return mainTabItem;
  507. }
  508. /// <summary>
  509. /// 重启UI
  510. /// </summary>
  511. private void RestartUI()
  512. {
  513. // 获取当前执行的程序集
  514. Assembly assembly = Assembly.GetExecutingAssembly();
  515. // 获取当前执行的程序集的全名
  516. AssemblyName assemblyName = assembly.GetName();
  517. // 构建一个新的进程启动信息,以便重新启动当前应用程序
  518. ProcessStartInfo startInfo = new ProcessStartInfo
  519. {
  520. FileName = assembly.Location,
  521. UseShellExecute = true
  522. };
  523. // 关闭当前应用程序
  524. Application.Current.Shutdown();
  525. // 创建一个新的进程来运行当前应用程序
  526. Process.Start(startInfo);
  527. }
  528. /// <summary>
  529. /// 所有页面可见性发生变化事件
  530. /// </summary>
  531. /// <param name="sender"></param>
  532. /// <param name="e"></param>
  533. private void TabItem_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  534. {
  535. //TabItem control = sender as TabItem;
  536. Control control = sender as Control;
  537. var viewmodel = control.DataContext;
  538. if (viewmodel != null)
  539. {
  540. Type t = viewmodel.GetType();
  541. if (e.NewValue != null)
  542. {
  543. bool isShow = (bool)e.NewValue;
  544. if (isShow)
  545. {
  546. MethodInfo methodInfo = t.GetMethod("LoadData");
  547. methodInfo?.Invoke(viewmodel, new object[] { control.Name });
  548. }
  549. else
  550. {
  551. MethodInfo methodInfo = t.GetMethod("Hide");
  552. methodInfo?.Invoke(viewmodel, null);
  553. }
  554. }
  555. else
  556. {
  557. MethodInfo methodInfo = t.GetMethod("Hide");
  558. methodInfo?.Invoke(viewmodel, null);
  559. }
  560. }
  561. }
  562. public void Anystationchange(string menuviewItem, WaferHistoryWafer queryFilter)
  563. {
  564. UserControl address = new ProcessHistoryView();
  565. ProcessHistoryViewModel vm = new ProcessHistoryViewModel() { };
  566. vm.searchlot(queryFilter.WaferGuid);
  567. //vm.OnDataGridSelectionChanged(vm.Recipes[0]);
  568. address.DataContext = vm;
  569. int s = 0;
  570. for (int i = 0; i < centerTabViews.Count; i++)
  571. {
  572. var item = centerTabViews[i];
  573. foreach (TabItem v in item.Items)
  574. {
  575. if (v.Header.ToString() == "Process History")
  576. {
  577. s = i;
  578. }
  579. }
  580. }
  581. if (s != 0)
  582. {
  583. centerTabViews[s].Items[2] = new TabItem() { Header = menuviewItem, Content = address };
  584. centerTabViews[s].SelectedIndex = 2;
  585. Main_Frame.Content = centerTabViews[s];
  586. }
  587. }
  588. private void AduRadioButtonIcon_Click(object sender, RoutedEventArgs e)
  589. {
  590. var currentButton = sender as AduRadioButtonIcon;
  591. Main_Frame.Content = centerTabViews[Convert.ToInt32(currentButton.Tag)];
  592. }
  593. /// <summary>
  594. /// 手动切换菜单
  595. /// </summary>
  596. /// <param name="root"></param>
  597. /// <param name="parent"></param>
  598. /// <param name="children"></param>
  599. private void GlobalEvents_SwitchFixedTabItem(string root, string parent, string children)
  600. {
  601. if (_rootTabDic.ContainsKey(root))
  602. {
  603. int rootIndex = _rootTabDic[root];
  604. if (rootIndex-1 < centerTabViews.Count)
  605. {
  606. Main_Frame.Content = centerTabViews[rootIndex-1];
  607. TabControl rootTab = centerTabViews[rootIndex-1];
  608. _aduRadioButtons[rootIndex-1].IsChecked=true;
  609. if (!string.IsNullOrEmpty(parent))
  610. {
  611. if (_parentTabDic.ContainsKey(parent))
  612. {
  613. int parentIndex = _parentTabDic[parent];
  614. rootTab.SelectedIndex = parentIndex-rootIndex*100;
  615. TabItem parentTabItem = rootTab.Items[rootTab.SelectedIndex] as TabItem;
  616. if (_childrenTabDic.ContainsKey(children))
  617. {
  618. TabControl parentTab=parentTabItem.Content as TabControl;
  619. int childrenIndex = _childrenTabDic[children];
  620. parentTab.SelectedIndex = childrenIndex-parentIndex*100;
  621. }
  622. }
  623. }
  624. else
  625. {
  626. if (_childrenTabDic.ContainsKey(children))
  627. {
  628. int childeIndex = _childrenTabDic[children];
  629. rootTab.SelectedIndex = childeIndex - rootTab.TabIndex * 100;
  630. }
  631. }
  632. }
  633. }
  634. }
  635. /// <summary>
  636. /// Reservoir切换页面
  637. /// </summary>
  638. /// <param name="child"></param>
  639. /// <param name="subItem"></param>
  640. /// <exception cref="NotImplementedException"></exception>
  641. private void GlobalEvents_SwitchFixedChildSubItem(string child, string subItem)
  642. {
  643. if (_multiMenuItemsDictionary.ContainsKey($"{child}.{subItem}"))
  644. {
  645. TabItem tabItem = _multiMenuItemsDictionary[$"{child}.{subItem}"];
  646. TabControl rootTabControl = (TabControl)Main_Frame.Content;
  647. if (rootTabControl == null) { return; }
  648. if (rootTabControl.SelectedIndex == -1 || rootTabControl.SelectedIndex > rootTabControl.Items.Count - 1)
  649. {
  650. return;
  651. }
  652. TabItem parentTab = rootTabControl.Items[rootTabControl.SelectedIndex] as TabItem;
  653. if(parentTab == null) { return; }
  654. TabControl parentContentTab= parentTab.Content as TabControl;
  655. if(parentContentTab == null) { return; }
  656. if(parentContentTab.SelectedIndex==-1|| parentContentTab.SelectedIndex > parentContentTab.Items.Count - 1)
  657. {
  658. return;
  659. }
  660. int selectedIndex=parentContentTab.SelectedIndex;
  661. parentContentTab.SelectedIndex = -1;
  662. parentContentTab.Items[selectedIndex] = tabItem;
  663. parentContentTab.SelectedIndex = selectedIndex;
  664. }
  665. }
  666. private void CustomWnd_Closed(object sender, EventArgs e)
  667. {
  668. string ipConfigFilter = "";
  669. if (_isAllViewUnable == false)
  670. {
  671. var ipconfig = QueryDataClient.Instance.Service.GetConfig($"System.ControlIPFilter");
  672. if (ipconfig != null)
  673. {
  674. ipConfigFilter = ipconfig.ToString();
  675. }
  676. List<string> localIPs = new List<string>();
  677. string hostName = Dns.GetHostName();
  678. IPHostEntry host = Dns.GetHostEntry(hostName);
  679. foreach (IPAddress ip in host.AddressList)
  680. {
  681. if (ip.AddressFamily == AddressFamily.InterNetwork && ip.ToString().Trim().StartsWith($"{ipConfigFilter}"))
  682. {
  683. localIPs.Add(ip.ToString());
  684. }
  685. }
  686. if (localIPs.Count > 0)
  687. {
  688. InvokeClient.Instance.Service.DoOperation($"ReleaseSystemControl", localIPs[0]);
  689. }
  690. }
  691. System.Diagnostics.Process.GetCurrentProcess().Kill();
  692. }
  693. private void UIEvents_ChamberCreateDeleteWaferEvent(WaferOperation obj)
  694. {
  695. if (obj.IsCreate == true)
  696. {
  697. InvokeClient.Instance.Service.DoOperation("CreateWafer", obj.ModuleName, 0);
  698. }
  699. else
  700. {
  701. InvokeClient.Instance.Service.DoOperation("DeleteWafer", obj.ModuleName, 0);
  702. }
  703. }
  704. private void UIEvents_PMDoorRaiseChangedEvent(DoorPara obj)
  705. {
  706. //InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SlitDoor.{obj?.IsOpen}");
  707. InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SetSlitDoor", obj.IsOpen == "Open" ? true : false);
  708. }
  709. private void UIEvents_LLTDoorRaiseChangedEvent(DoorPara obj)
  710. {
  711. InvokeClient.Instance.Service.DoOperation($"TM.SetMFSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  712. }
  713. private void UIEvents_LLEDoorRaiseChangedEvent(DoorPara obj)
  714. {
  715. InvokeClient.Instance.Service.DoOperation($"TM.SetEFEMSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  716. }
  717. #region 调用api功能部分
  718. void win_SourceInitialized(object sender, EventArgs e)
  719. {
  720. System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
  721. WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
  722. }
  723. private static System.IntPtr WindowProc(
  724. System.IntPtr hwnd,
  725. int msg,
  726. System.IntPtr wParam,
  727. System.IntPtr lParam,
  728. ref bool handled)
  729. {
  730. switch (msg)
  731. {
  732. case 0x0024:
  733. WmGetMinMaxInfo(hwnd, lParam);
  734. handled = true;
  735. break;
  736. }
  737. return (System.IntPtr)0;
  738. }
  739. private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
  740. {
  741. MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
  742. // Adjust the maximized size and position to fit the work area of the correct monitor
  743. int MONITOR_DEFAULTTONEAREST = 0x00000002;
  744. System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
  745. if (monitor != System.IntPtr.Zero)
  746. {
  747. MONITORINFO monitorInfo = new MONITORINFO();
  748. GetMonitorInfo(monitor, monitorInfo);
  749. RECT rcWorkArea = monitorInfo.rcWork;
  750. RECT rcMonitorArea = monitorInfo.rcMonitor;
  751. mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
  752. mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
  753. mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
  754. mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
  755. }
  756. Marshal.StructureToPtr(mmi, lParam, true);
  757. }
  758. /// <summary>
  759. /// POINT aka POINTAPI
  760. /// </summary>
  761. [StructLayout(LayoutKind.Sequential)]
  762. public struct POINT
  763. {
  764. /// <summary>
  765. /// x coordinate of point.
  766. /// </summary>
  767. public int x;
  768. /// <summary>
  769. /// y coordinate of point.
  770. /// </summary>
  771. public int y;
  772. /// <summary>
  773. /// Construct a point of coordinates (x,y).
  774. /// </summary>
  775. public POINT(int x, int y)
  776. {
  777. this.x = x;
  778. this.y = y;
  779. }
  780. }
  781. [StructLayout(LayoutKind.Sequential)]
  782. public struct MINMAXINFO
  783. {
  784. public POINT ptReserved;
  785. public POINT ptMaxSize;
  786. public POINT ptMaxPosition;
  787. public POINT ptMinTrackSize;
  788. public POINT ptMaxTrackSize;
  789. };
  790. /// <summary>
  791. /// </summary>
  792. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  793. public class MONITORINFO
  794. {
  795. /// <summary>
  796. /// </summary>
  797. public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
  798. /// <summary>
  799. /// </summary>
  800. public RECT rcMonitor = new RECT();
  801. /// <summary>
  802. /// </summary>
  803. public RECT rcWork = new RECT();
  804. /// <summary>
  805. /// </summary>
  806. public int dwFlags = 0;
  807. }
  808. /// <summary> Win32 </summary>
  809. [StructLayout(LayoutKind.Sequential, Pack = 0)]
  810. public struct RECT
  811. {
  812. /// <summary> Win32 </summary>
  813. public int left;
  814. /// <summary> Win32 </summary>
  815. public int top;
  816. /// <summary> Win32 </summary>
  817. public int right;
  818. /// <summary> Win32 </summary>
  819. public int bottom;
  820. /// <summary> Win32 </summary>
  821. public static readonly RECT Empty = new RECT();
  822. /// <summary> Win32 </summary>
  823. public int Width
  824. {
  825. get { return Math.Abs(right - left); } // Abs needed for BIDI OS
  826. }
  827. /// <summary> Win32 </summary>
  828. public int Height
  829. {
  830. get { return bottom - top; }
  831. }
  832. /// <summary> Win32 </summary>
  833. public RECT(int left, int top, int right, int bottom)
  834. {
  835. this.left = left;
  836. this.top = top;
  837. this.right = right;
  838. this.bottom = bottom;
  839. }
  840. /// <summary> Win32 </summary>
  841. public RECT(RECT rcSrc)
  842. {
  843. this.left = rcSrc.left;
  844. this.top = rcSrc.top;
  845. this.right = rcSrc.right;
  846. this.bottom = rcSrc.bottom;
  847. }
  848. /// <summary> Win32 </summary>
  849. public bool IsEmpty
  850. {
  851. get
  852. {
  853. // BUGBUG : On Bidi OS (hebrew arabic) left > right
  854. return left >= right || top >= bottom;
  855. }
  856. }
  857. /// <summary> Return a user friendly representation of this struct </summary>
  858. public override string ToString()
  859. {
  860. if (this == RECT.Empty) { return "RECT {Empty}"; }
  861. return "RECT { left : " + left + " / top : " + top + " / right : " + right + " / bottom : " + bottom + " }";
  862. }
  863. /// <summary> Determine if 2 RECT are equal (deep compare) </summary>
  864. public override bool Equals(object obj)
  865. {
  866. if (!(obj is Rect)) { return false; }
  867. return (this == (RECT)obj);
  868. }
  869. /// <summary>Return the HashCode for this struct (not garanteed to be unique)</summary>
  870. public override int GetHashCode()
  871. {
  872. return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
  873. }
  874. /// <summary> Determine if 2 RECT are equal (deep compare)</summary>
  875. public static bool operator ==(RECT rect1, RECT rect2)
  876. {
  877. return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
  878. }
  879. /// <summary> Determine if 2 RECT are different(deep compare)</summary>
  880. public static bool operator !=(RECT rect1, RECT rect2)
  881. {
  882. return !(rect1 == rect2);
  883. }
  884. }
  885. [DllImport("user32")]
  886. internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
  887. /// <summary>
  888. ///
  889. /// </summary>
  890. [DllImport("User32")]
  891. internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
  892. #endregion
  893. }
  894. }