ShellView.xaml.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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 (!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<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 (!item.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))
  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<CyberX8_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<CyberX8_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 = $"CyberX8_MainPages.Views.{item.View}";
  429. Type viewType = Type.GetType($"{viewClassName},CyberX8_MainPages");
  430. obj = System.Activator.CreateInstance(viewType);
  431. _childrenTabDic[item.Id] = index;
  432. }
  433. TabItem tabItem = new TabItem() { Header = item.Name, Content = obj };
  434. Control ctrl = (tabItem.Content as Control);
  435. ctrl.Name = item.ModuleName;
  436. ctrl.IsVisibleChanged += TabItem_IsVisibleChanged;
  437. //登录进去无控制权限
  438. if (_isAllViewUnable)
  439. {
  440. ctrl.IsEnabled = false;
  441. }
  442. //只读权限
  443. if (menus[i] != null && menus[i].Permission == MenuPermission.ReadOnly)
  444. {
  445. ctrl.IsEnabled = false;
  446. }
  447. tabItem.TabIndex=index;
  448. index++;
  449. tabControl.Items.Add(tabItem);
  450. _multiMenuItemsDictionary.Add($"{item.Name}.{item.Id}", tabItem);
  451. //一级标题module某块本身也有一个item对象,任何时刻都要使其可用,确保module二级标题可以点
  452. for (int j = 0; j < subItems.Count; j++)
  453. {
  454. SubItem item1 = subItems[i];
  455. if (string.IsNullOrEmpty(item1.View))
  456. {
  457. TabItem selfItem = _multiMenuItemsDictionary[$"{item1.Name}.{item1.Id}"];
  458. Control selfControl = (selfItem.Content as Control);
  459. selfControl.IsEnabled = true;
  460. }
  461. }
  462. }
  463. if(tabControl.Items.Count!=0)
  464. {
  465. tabControl.SelectedIndex = 0;
  466. }
  467. }
  468. private TabItem InitializeMultiItem(string moduleName, List<SubItem> subItems, ObservableCollection<CyberX8_MainPages.Roles.Menu> menus)
  469. {
  470. TabItem mainTabItem = null;
  471. foreach(SubItem item in subItems)
  472. {
  473. int menusIndex = subItems.IndexOf(item);
  474. //None权限
  475. if (menus[menusIndex] != null & menus[menusIndex].Permission == MenuPermission.None)
  476. {
  477. continue;
  478. }
  479. string viewClassName = $"CyberX8_MainPages.Views.{item.View}";
  480. Type viewType = Type.GetType($"{viewClassName},CyberX8_MainPages");
  481. Object obj = System.Activator.CreateInstance(viewType);
  482. TabItem tabItem = new TabItem() { Header = moduleName, Content = obj };
  483. Control ctrl = (tabItem.Content as Control);
  484. ctrl.Name = item.ModuleName;
  485. ctrl.IsVisibleChanged += TabItem_IsVisibleChanged;
  486. //登录进去无控制权限
  487. if (_isAllViewUnable)
  488. {
  489. ctrl.IsEnabled = false;
  490. }
  491. //只读权限
  492. if (menus[menusIndex] != null && menus[menusIndex].Permission == MenuPermission.ReadOnly)
  493. {
  494. ctrl.IsEnabled = false;
  495. }
  496. _multiMenuItemsDictionary[$"{moduleName}.{item.Id}"] = tabItem;
  497. if (mainTabItem == null&&item.IsShow)
  498. {
  499. mainTabItem = tabItem;
  500. }
  501. }
  502. return mainTabItem;
  503. }
  504. /// <summary>
  505. /// 重启UI
  506. /// </summary>
  507. private void RestartUI()
  508. {
  509. // 获取当前执行的程序集
  510. Assembly assembly = Assembly.GetExecutingAssembly();
  511. // 获取当前执行的程序集的全名
  512. AssemblyName assemblyName = assembly.GetName();
  513. // 构建一个新的进程启动信息,以便重新启动当前应用程序
  514. ProcessStartInfo startInfo = new ProcessStartInfo
  515. {
  516. FileName = assembly.Location,
  517. UseShellExecute = true
  518. };
  519. // 关闭当前应用程序
  520. Application.Current.Shutdown();
  521. // 创建一个新的进程来运行当前应用程序
  522. Process.Start(startInfo);
  523. }
  524. /// <summary>
  525. /// 所有页面可见性发生变化事件
  526. /// </summary>
  527. /// <param name="sender"></param>
  528. /// <param name="e"></param>
  529. private void TabItem_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  530. {
  531. //TabItem control = sender as TabItem;
  532. Control control = sender as Control;
  533. var viewmodel = control.DataContext;
  534. if (viewmodel != null)
  535. {
  536. Type t = viewmodel.GetType();
  537. if (e.NewValue != null)
  538. {
  539. bool isShow = (bool)e.NewValue;
  540. if (isShow)
  541. {
  542. MethodInfo methodInfo = t.GetMethod("LoadData");
  543. methodInfo?.Invoke(viewmodel, new object[] { control.Name });
  544. }
  545. else
  546. {
  547. MethodInfo methodInfo = t.GetMethod("Hide");
  548. methodInfo?.Invoke(viewmodel, null);
  549. }
  550. }
  551. else
  552. {
  553. MethodInfo methodInfo = t.GetMethod("Hide");
  554. methodInfo?.Invoke(viewmodel, null);
  555. }
  556. }
  557. }
  558. public void Anystationchange(string menuviewItem, WaferHistoryWafer queryFilter)
  559. {
  560. UserControl address = new ProcessHistoryView();
  561. ProcessHistoryViewModel vm = new ProcessHistoryViewModel() { };
  562. vm.searchlot(queryFilter.WaferGuid);
  563. //vm.OnDataGridSelectionChanged(vm.Recipes[0]);
  564. address.DataContext = vm;
  565. int s = 0;
  566. for (int i = 0; i < centerTabViews.Count; i++)
  567. {
  568. var item = centerTabViews[i];
  569. foreach (TabItem v in item.Items)
  570. {
  571. if (v.Header.ToString() == "Process History")
  572. {
  573. s = i;
  574. }
  575. }
  576. }
  577. if (s != 0)
  578. {
  579. centerTabViews[s].Items[2] = new TabItem() { Header = menuviewItem, Content = address };
  580. centerTabViews[s].SelectedIndex = 2;
  581. Main_Frame.Content = centerTabViews[s];
  582. }
  583. }
  584. private void AduRadioButtonIcon_Click(object sender, RoutedEventArgs e)
  585. {
  586. var currentButton = sender as AduRadioButtonIcon;
  587. Main_Frame.Content = centerTabViews[Convert.ToInt32(currentButton.Tag)];
  588. }
  589. /// <summary>
  590. /// 手动切换菜单
  591. /// </summary>
  592. /// <param name="root"></param>
  593. /// <param name="parent"></param>
  594. /// <param name="children"></param>
  595. private void GlobalEvents_SwitchFixedTabItem(string root, string parent, string children)
  596. {
  597. if (_rootTabDic.ContainsKey(root))
  598. {
  599. int rootIndex = _rootTabDic[root];
  600. if (rootIndex-1 < centerTabViews.Count)
  601. {
  602. Main_Frame.Content = centerTabViews[rootIndex-1];
  603. TabControl rootTab = centerTabViews[rootIndex-1];
  604. _aduRadioButtons[rootIndex-1].IsChecked=true;
  605. if (!string.IsNullOrEmpty(parent))
  606. {
  607. if (_parentTabDic.ContainsKey(parent))
  608. {
  609. int parentIndex = _parentTabDic[parent];
  610. rootTab.SelectedIndex = parentIndex-rootIndex*100;
  611. TabItem parentTabItem = rootTab.Items[rootTab.SelectedIndex] as TabItem;
  612. if (_childrenTabDic.ContainsKey(children))
  613. {
  614. TabControl parentTab=parentTabItem.Content as TabControl;
  615. int childrenIndex = _childrenTabDic[children];
  616. parentTab.SelectedIndex = childrenIndex-parentIndex*100;
  617. }
  618. }
  619. }
  620. else
  621. {
  622. if (_childrenTabDic.ContainsKey(children))
  623. {
  624. int childeIndex = _childrenTabDic[children];
  625. rootTab.SelectedIndex = childeIndex - rootTab.TabIndex * 100;
  626. }
  627. }
  628. }
  629. }
  630. }
  631. /// <summary>
  632. /// Reservoir切换页面
  633. /// </summary>
  634. /// <param name="child"></param>
  635. /// <param name="subItem"></param>
  636. /// <exception cref="NotImplementedException"></exception>
  637. private void GlobalEvents_SwitchFixedChildSubItem(string child, string subItem)
  638. {
  639. if (_multiMenuItemsDictionary.ContainsKey($"{child}.{subItem}"))
  640. {
  641. TabItem tabItem = _multiMenuItemsDictionary[$"{child}.{subItem}"];
  642. TabControl rootTabControl = (TabControl)Main_Frame.Content;
  643. if (rootTabControl == null) { return; }
  644. if (rootTabControl.SelectedIndex == -1 || rootTabControl.SelectedIndex > rootTabControl.Items.Count - 1)
  645. {
  646. return;
  647. }
  648. TabItem parentTab = rootTabControl.Items[rootTabControl.SelectedIndex] as TabItem;
  649. if(parentTab == null) { return; }
  650. TabControl parentContentTab= parentTab.Content as TabControl;
  651. if(parentContentTab == null) { return; }
  652. if(parentContentTab.SelectedIndex==-1|| parentContentTab.SelectedIndex > parentContentTab.Items.Count - 1)
  653. {
  654. return;
  655. }
  656. int selectedIndex=parentContentTab.SelectedIndex;
  657. parentContentTab.SelectedIndex = -1;
  658. parentContentTab.Items[selectedIndex] = tabItem;
  659. parentContentTab.SelectedIndex = selectedIndex;
  660. }
  661. }
  662. private void CustomWnd_Closed(object sender, EventArgs e)
  663. {
  664. string ipConfigFilter = "";
  665. if (_isAllViewUnable == false)
  666. {
  667. var ipconfig = QueryDataClient.Instance.Service.GetConfig($"System.ControlIPFilter");
  668. if (ipconfig != null)
  669. {
  670. ipConfigFilter = ipconfig.ToString();
  671. }
  672. List<string> localIPs = new List<string>();
  673. string hostName = Dns.GetHostName();
  674. IPHostEntry host = Dns.GetHostEntry(hostName);
  675. foreach (IPAddress ip in host.AddressList)
  676. {
  677. if (ip.AddressFamily == AddressFamily.InterNetwork && ip.ToString().Trim().StartsWith($"{ipConfigFilter}"))
  678. {
  679. localIPs.Add(ip.ToString());
  680. }
  681. }
  682. if (localIPs.Count > 0)
  683. {
  684. InvokeClient.Instance.Service.DoOperation($"ReleaseSystemControl", localIPs[0]);
  685. }
  686. }
  687. System.Diagnostics.Process.GetCurrentProcess().Kill();
  688. }
  689. private void UIEvents_ChamberCreateDeleteWaferEvent(WaferOperation obj)
  690. {
  691. if (obj.IsCreate == true)
  692. {
  693. InvokeClient.Instance.Service.DoOperation("CreateWafer", obj.ModuleName, 0);
  694. }
  695. else
  696. {
  697. InvokeClient.Instance.Service.DoOperation("DeleteWafer", obj.ModuleName, 0);
  698. }
  699. }
  700. private void UIEvents_PMDoorRaiseChangedEvent(DoorPara obj)
  701. {
  702. //InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SlitDoor.{obj?.IsOpen}");
  703. InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SetSlitDoor", obj.IsOpen == "Open" ? true : false);
  704. }
  705. private void UIEvents_LLTDoorRaiseChangedEvent(DoorPara obj)
  706. {
  707. InvokeClient.Instance.Service.DoOperation($"TM.SetMFSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  708. }
  709. private void UIEvents_LLEDoorRaiseChangedEvent(DoorPara obj)
  710. {
  711. InvokeClient.Instance.Service.DoOperation($"TM.SetEFEMSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  712. }
  713. #region 调用api功能部分
  714. void win_SourceInitialized(object sender, EventArgs e)
  715. {
  716. System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
  717. WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
  718. }
  719. private static System.IntPtr WindowProc(
  720. System.IntPtr hwnd,
  721. int msg,
  722. System.IntPtr wParam,
  723. System.IntPtr lParam,
  724. ref bool handled)
  725. {
  726. switch (msg)
  727. {
  728. case 0x0024:
  729. WmGetMinMaxInfo(hwnd, lParam);
  730. handled = true;
  731. break;
  732. }
  733. return (System.IntPtr)0;
  734. }
  735. private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
  736. {
  737. MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
  738. // Adjust the maximized size and position to fit the work area of the correct monitor
  739. int MONITOR_DEFAULTTONEAREST = 0x00000002;
  740. System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
  741. if (monitor != System.IntPtr.Zero)
  742. {
  743. MONITORINFO monitorInfo = new MONITORINFO();
  744. GetMonitorInfo(monitor, monitorInfo);
  745. RECT rcWorkArea = monitorInfo.rcWork;
  746. RECT rcMonitorArea = monitorInfo.rcMonitor;
  747. mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
  748. mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
  749. mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
  750. mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
  751. }
  752. Marshal.StructureToPtr(mmi, lParam, true);
  753. }
  754. /// <summary>
  755. /// POINT aka POINTAPI
  756. /// </summary>
  757. [StructLayout(LayoutKind.Sequential)]
  758. public struct POINT
  759. {
  760. /// <summary>
  761. /// x coordinate of point.
  762. /// </summary>
  763. public int x;
  764. /// <summary>
  765. /// y coordinate of point.
  766. /// </summary>
  767. public int y;
  768. /// <summary>
  769. /// Construct a point of coordinates (x,y).
  770. /// </summary>
  771. public POINT(int x, int y)
  772. {
  773. this.x = x;
  774. this.y = y;
  775. }
  776. }
  777. [StructLayout(LayoutKind.Sequential)]
  778. public struct MINMAXINFO
  779. {
  780. public POINT ptReserved;
  781. public POINT ptMaxSize;
  782. public POINT ptMaxPosition;
  783. public POINT ptMinTrackSize;
  784. public POINT ptMaxTrackSize;
  785. };
  786. /// <summary>
  787. /// </summary>
  788. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  789. public class MONITORINFO
  790. {
  791. /// <summary>
  792. /// </summary>
  793. public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
  794. /// <summary>
  795. /// </summary>
  796. public RECT rcMonitor = new RECT();
  797. /// <summary>
  798. /// </summary>
  799. public RECT rcWork = new RECT();
  800. /// <summary>
  801. /// </summary>
  802. public int dwFlags = 0;
  803. }
  804. /// <summary> Win32 </summary>
  805. [StructLayout(LayoutKind.Sequential, Pack = 0)]
  806. public struct RECT
  807. {
  808. /// <summary> Win32 </summary>
  809. public int left;
  810. /// <summary> Win32 </summary>
  811. public int top;
  812. /// <summary> Win32 </summary>
  813. public int right;
  814. /// <summary> Win32 </summary>
  815. public int bottom;
  816. /// <summary> Win32 </summary>
  817. public static readonly RECT Empty = new RECT();
  818. /// <summary> Win32 </summary>
  819. public int Width
  820. {
  821. get { return Math.Abs(right - left); } // Abs needed for BIDI OS
  822. }
  823. /// <summary> Win32 </summary>
  824. public int Height
  825. {
  826. get { return bottom - top; }
  827. }
  828. /// <summary> Win32 </summary>
  829. public RECT(int left, int top, int right, int bottom)
  830. {
  831. this.left = left;
  832. this.top = top;
  833. this.right = right;
  834. this.bottom = bottom;
  835. }
  836. /// <summary> Win32 </summary>
  837. public RECT(RECT rcSrc)
  838. {
  839. this.left = rcSrc.left;
  840. this.top = rcSrc.top;
  841. this.right = rcSrc.right;
  842. this.bottom = rcSrc.bottom;
  843. }
  844. /// <summary> Win32 </summary>
  845. public bool IsEmpty
  846. {
  847. get
  848. {
  849. // BUGBUG : On Bidi OS (hebrew arabic) left > right
  850. return left >= right || top >= bottom;
  851. }
  852. }
  853. /// <summary> Return a user friendly representation of this struct </summary>
  854. public override string ToString()
  855. {
  856. if (this == RECT.Empty) { return "RECT {Empty}"; }
  857. return "RECT { left : " + left + " / top : " + top + " / right : " + right + " / bottom : " + bottom + " }";
  858. }
  859. /// <summary> Determine if 2 RECT are equal (deep compare) </summary>
  860. public override bool Equals(object obj)
  861. {
  862. if (!(obj is Rect)) { return false; }
  863. return (this == (RECT)obj);
  864. }
  865. /// <summary>Return the HashCode for this struct (not garanteed to be unique)</summary>
  866. public override int GetHashCode()
  867. {
  868. return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
  869. }
  870. /// <summary> Determine if 2 RECT are equal (deep compare)</summary>
  871. public static bool operator ==(RECT rect1, RECT rect2)
  872. {
  873. return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
  874. }
  875. /// <summary> Determine if 2 RECT are different(deep compare)</summary>
  876. public static bool operator !=(RECT rect1, RECT rect2)
  877. {
  878. return !(rect1 == rect2);
  879. }
  880. }
  881. [DllImport("user32")]
  882. internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
  883. /// <summary>
  884. ///
  885. /// </summary>
  886. [DllImport("User32")]
  887. internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
  888. #endregion
  889. }
  890. }