MainViewModel.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. using Aitex.Core.Account;
  2. using Aitex.Core.Common.DeviceData;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.Util;
  6. using Aitex.Core.WCF;
  7. using Caliburn.Micro;
  8. using MECF.Framework.Common.Account.Extends;
  9. using MECF.Framework.Common.DataCenter;
  10. using MECF.Framework.Common.OperationCenter;
  11. using MECF.Framework.UI.Client.CenterViews.DataLogs.DataHistory;
  12. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  13. using MECF.Framework.UI.Client.CenterViews.LogOnOff;
  14. using MECF.Framework.UI.Client.ClientBase;
  15. using MECF.Framework.UI.Core.Accounts;
  16. using OpenSEMI.ClientBase;
  17. using OpenSEMI.ClientBase.Command;
  18. using OpenSEMI.ClientBase.Utility;
  19. using SciChart.Charting.ChartModifiers;
  20. using SciChart.Charting.Visuals;
  21. using SciChart.Charting.Visuals.Annotations;
  22. using SciChart.Charting.Visuals.Axes;
  23. using System;
  24. using System.Collections.Concurrent;
  25. using System.Collections.Generic;
  26. using System.Collections.ObjectModel;
  27. using System.IO;
  28. using System.Linq;
  29. using System.Reflection;
  30. using System.Runtime.InteropServices;
  31. using System.Threading;
  32. using System.Threading.Tasks;
  33. using System.Windows;
  34. using System.Windows.Controls;
  35. using System.Windows.Input;
  36. using System.Windows.Threading;
  37. using FurnaceUI.Config;
  38. using Cali = Caliburn.Micro.Core;
  39. using MECF.Framework.Common.Jobs;
  40. namespace FurnaceUI.Client
  41. {
  42. public class TimeredMainViewModel : Cali.Conductor<Cali.Screen>.Collection.OneActive
  43. {
  44. PeriodicJob _timer;
  45. ConcurrentBag<string> _subscribedKeys = new ConcurrentBag<string>();
  46. Func<object, bool> _isSubscriptionAttribute;
  47. Func<MemberInfo, bool> _hasSubscriptionAttribute;
  48. public TimeredMainViewModel()
  49. {
  50. _timer = new PeriodicJob(1000, this.OnTimer, "UIUpdaterThread - " + GetType().Name);
  51. _isSubscriptionAttribute = attribute => attribute is SubscriptionAttribute;
  52. _hasSubscriptionAttribute = mi => mi.GetCustomAttributes(false).Any(_isSubscriptionAttribute);
  53. SubscribeKeys(this);
  54. }
  55. [StructLayout(LayoutKind.Sequential)]
  56. internal struct LASTINPUTINFO
  57. {
  58. [MarshalAs(UnmanagedType.U4)]
  59. public int cbSize;
  60. [MarshalAs(UnmanagedType.U4)]
  61. public int dwTime;
  62. }
  63. [DllImport("user32.dll")]
  64. internal static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
  65. /// <summary>
  66. /// 获取鼠标键盘不活动的时间
  67. /// </summary>
  68. /// <returns>结果</returns>
  69. public static int GetLastInputTime()
  70. {
  71. LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
  72. lastInputInfo.cbSize = Marshal.SizeOf(lastInputInfo);
  73. lastInputInfo.dwTime = 0;
  74. int idleTime = 0;
  75. if (GetLastInputInfo(ref lastInputInfo))
  76. {
  77. idleTime = Environment.TickCount - lastInputInfo.dwTime;
  78. }
  79. return ((idleTime > 0) ? (idleTime / 1000) : 0);
  80. }
  81. protected virtual bool OnTimer()
  82. {
  83. try
  84. {
  85. Poll();
  86. }
  87. catch (Exception ex)
  88. {
  89. LOG.Error(ex.Message);
  90. }
  91. return true;
  92. }
  93. public virtual void EnableTimer(bool enable)
  94. {
  95. if (enable) _timer.Start();
  96. else _timer.Pause();
  97. }
  98. protected virtual void Poll()
  99. {
  100. if (_subscribedKeys.Count > 0)
  101. {
  102. Dictionary<string, object> result = QueryDataClient.Instance.Service.PollData(_subscribedKeys);
  103. if (result == null)
  104. {
  105. LOG.Error("获取RT数据失败");
  106. return;
  107. }
  108. if (result.Count != _subscribedKeys.Count)
  109. {
  110. string unknowKeys = string.Empty;
  111. foreach (string key in _subscribedKeys)
  112. {
  113. if (!result.ContainsKey(key))
  114. {
  115. unknowKeys += key + "\r\n";
  116. }
  117. }
  118. //System.Diagnostics.Debug.Assert(false, unknowKeys);
  119. }
  120. InvokeBeforeUpdateProperty(result);
  121. UpdateValue(result);
  122. Application.Current.Dispatcher.Invoke(new System.Action(() =>
  123. {
  124. InvokePropertyChanged();
  125. InvokeAfterUpdateProperty(result);
  126. }));
  127. }
  128. }
  129. private void InvokePropertyChanged()
  130. {
  131. Refresh();
  132. }
  133. protected virtual void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  134. {
  135. }
  136. protected virtual void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  137. {
  138. }
  139. void UpdateValue(Dictionary<string, object> data)
  140. {
  141. if (data == null)
  142. return;
  143. UpdateSubscribe(data, this);
  144. var properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetCustomAttribute<SubscriptionModuleAttribute>() != null);
  145. foreach (var property in properties)
  146. {
  147. var moduleAttr = property.GetCustomAttribute<SubscriptionModuleAttribute>();
  148. UpdateSubscribe(data, property.GetValue(this), moduleAttr.Module);
  149. }
  150. }
  151. protected void Subscribe(string key)
  152. {
  153. if (!string.IsNullOrEmpty(key))
  154. {
  155. _subscribedKeys.Add(key);
  156. }
  157. }
  158. public void SubscribeKeys(TimeredMainViewModel target)
  159. {
  160. Parallel.ForEach(target.GetType().GetProperties().Where(_hasSubscriptionAttribute),
  161. property =>
  162. {
  163. SubscriptionAttribute subscription = property.GetCustomAttributes(false).First(_isSubscriptionAttribute) as SubscriptionAttribute;
  164. string key = subscription.ModuleKey;
  165. if (!_subscribedKeys.Contains(key))
  166. _subscribedKeys.Add(key);
  167. });
  168. Parallel.ForEach(target.GetType().GetFields().Where(_hasSubscriptionAttribute),
  169. method =>
  170. {
  171. SubscriptionAttribute subscription = method.GetCustomAttributes(false).First(_isSubscriptionAttribute) as SubscriptionAttribute;
  172. string key = subscription.ModuleKey;
  173. if (!_subscribedKeys.Contains(key))
  174. _subscribedKeys.Add(key);
  175. });
  176. }
  177. public void UpdateSubscribe(Dictionary<string, object> data, object target, string module = null)
  178. {
  179. Parallel.ForEach(target.GetType().GetProperties().Where(_hasSubscriptionAttribute),
  180. property =>
  181. {
  182. PropertyInfo pi = (PropertyInfo)property;
  183. SubscriptionAttribute subscription = property.GetCustomAttributes(false).First(_isSubscriptionAttribute) as SubscriptionAttribute;
  184. string key = subscription.ModuleKey;
  185. key = module == null ? key : string.Format("{0}.{1}", module, key);
  186. if (_subscribedKeys.Contains(key) && data.ContainsKey(key))
  187. {
  188. try
  189. {
  190. var convertedValue = Convert.ChangeType(data[key], pi.PropertyType);
  191. var originValue = Convert.ChangeType(pi.GetValue(target, null), pi.PropertyType);
  192. if (originValue != convertedValue)
  193. {
  194. if (pi.Name == "PumpLimitSetPoint")
  195. pi.SetValue(target, convertedValue, null);
  196. else
  197. pi.SetValue(target, convertedValue, null);
  198. }
  199. }
  200. catch (Exception ex)
  201. {
  202. LOG.Error("由RT返回的数据更新失败" + key, ex);
  203. }
  204. }
  205. });
  206. Parallel.ForEach(target.GetType().GetFields().Where(_hasSubscriptionAttribute),
  207. property =>
  208. {
  209. FieldInfo pi = (FieldInfo)property;
  210. SubscriptionAttribute subscription = property.GetCustomAttributes(false).First(_isSubscriptionAttribute) as SubscriptionAttribute;
  211. string key = subscription.ModuleKey;
  212. if (_subscribedKeys.Contains(key) && data.ContainsKey(key))
  213. {
  214. try
  215. {
  216. var convertedValue = Convert.ChangeType(data[key], pi.FieldType);
  217. pi.SetValue(target, convertedValue);
  218. }
  219. catch (Exception ex)
  220. {
  221. LOG.Error("由RT返回的数据更新失败" + key, ex);
  222. }
  223. }
  224. });
  225. }
  226. }
  227. public class MainViewModel : TimeredMainViewModel
  228. {
  229. #region Menus
  230. public string NowDateTime { get; set; }
  231. private bool _IsLogin = false;
  232. public bool IsLogin
  233. {
  234. get { return _IsLogin; }
  235. set { _IsLogin = value; NotifyOfPropertyChange("IsLogin"); }
  236. }
  237. private List<Role> roles;
  238. public List<Role> Roles
  239. {
  240. get { return this.roles; }
  241. set
  242. {
  243. this.roles = value;
  244. ShowRoles = new List<Role>(value);
  245. this.RaisePropertyChangedEventImmediately("Roles");
  246. }
  247. }
  248. private List<Role> showRoles;
  249. public List<Role> ShowRoles
  250. {
  251. get { return showRoles; }
  252. set { showRoles = value; this.RaisePropertyChangedEventImmediately("ShowRoles"); }
  253. }
  254. private string lockString;
  255. public string LockString
  256. {
  257. get
  258. {
  259. return lockString;
  260. }
  261. set
  262. {
  263. lockString = value;
  264. NotifyOfPropertyChange("LockString");
  265. }
  266. }
  267. private ICommand menuItemClickCommand;
  268. public ICommand MenuItemClickCommand
  269. {
  270. get
  271. {
  272. if (this.menuItemClickCommand == null)
  273. this.menuItemClickCommand = new BaseCommand<AppMenu>((AppMenu menuViewItem) => this.SwitchMenuItem(menuViewItem));
  274. return this.menuItemClickCommand;
  275. }
  276. }
  277. private ICommand mainmenuItemClickCommand;
  278. public ICommand MainMenuItemClickCommand
  279. {
  280. get
  281. {
  282. if (this.mainmenuItemClickCommand == null)
  283. this.mainmenuItemClickCommand = new BaseCommand<AppMenu>((AppMenu menuViewItem) => this.MainSwitchMenuItem(menuViewItem));
  284. return this.mainmenuItemClickCommand;
  285. }
  286. }
  287. public List<AppMenu> MenuItems
  288. {
  289. get { return this.menuItems; }
  290. set { this.menuItems = value; this.NotifyOfPropertyChange("MenuItems"); }
  291. }
  292. public List<AppMenu> SubMenuItems
  293. {
  294. get { return this.subMenuItems; }
  295. set { this.subMenuItems = value; this.NotifyOfPropertyChange("SubMenuItems"); }
  296. }
  297. public ObservableCollection<AppMenu> HistoryMenus
  298. {
  299. get { return this.historyItems; }
  300. set { this.historyItems = value; this.NotifyOfPropertyChange("HistoryMenus"); }
  301. }
  302. public string Context
  303. {
  304. get { return this.context; }
  305. set { this.context = value; this.NotifyOfPropertyChange("Context"); }
  306. }
  307. public BaseModel CurrentViewModel { get; private set; }
  308. public UserContext User { get { return BaseApp.Instance.UserContext; } }
  309. private AppMenu _currentMenuItem;
  310. private List<AppMenu> menuItems;
  311. private List<AppMenu> subMenuItems;
  312. private ObservableCollection<AppMenu> historyItems;
  313. private string context;
  314. private MainView _view;
  315. private Dictionary<Type, BaseModel> _models;
  316. #endregion
  317. public bool IsPermission { get; set; }
  318. public bool IsAutoLogout { get; set; }
  319. public int LogoutTime { get; set; }
  320. [Subscription("System.LiveAlarmEvent")]
  321. public List<EventItem> AlarmLogList { get; set; }
  322. public ObservableCollection<EventItem> WarnEventLogList { get; set; }
  323. public ObservableCollection<EventItem> EventLogList { get; set; }
  324. public Visibility AllEventsVisibility { get; set; }
  325. public Visibility WarnEventsVisibility { get; set; }
  326. [Subscription("LP1.Status")]
  327. public string LP1Status { get; set; }
  328. [Subscription("LP2.Status")]
  329. public string LP2Status { get; set; }
  330. public string LP1StatusBackground
  331. {
  332. get { return ModuleStatusBackground.GetStatusBackground(LP1Status); }
  333. }
  334. public string LP2StatusBackground
  335. {
  336. get { return ModuleStatusBackground.GetStatusBackground(LP2Status); }
  337. }
  338. [Subscription("Rt.Status")]
  339. public string RtStatus { get; set; }
  340. [Subscription("System.TransferJobStatus")]
  341. public string TransferJobStatus { get; set; }
  342. [Subscription("System.ProcessJobStatus")]
  343. public string ProcessJobStatus { get; set; }
  344. public string SystemStatus
  345. {
  346. get
  347. {
  348. switch (RtStatus)
  349. {
  350. case "ChargeProcessDischarging":
  351. return ProcessJobStatus;
  352. case "LoadProcessStockering":
  353. case "LoadProcessUnloading":
  354. return ProcessJobStatus == "Idle" ? TransferJobStatus : ProcessJobStatus;
  355. }
  356. return RtStatus;
  357. }
  358. set
  359. {
  360. }
  361. }
  362. public string RtStatusBackground
  363. {
  364. get { return ModuleStatusBackground.GetStatusBackground(SystemStatus); }
  365. }
  366. private bool _isLock = false;
  367. public bool IsLock
  368. {
  369. get
  370. {
  371. return _isLock;
  372. }
  373. set
  374. {
  375. _isLock = value;
  376. AppSettingsHelper.SetConfigValue("IsLock", value.ToString());
  377. LockString = _isLock ? "Lock" : "Unlock";
  378. NotifyOfPropertyChange("IsLock");
  379. }
  380. }
  381. #region FA
  382. [Subscription("System.ControlStatus")]
  383. public string SystemControlStatus
  384. {
  385. get;
  386. set;
  387. }
  388. public string ControlStatus
  389. {
  390. get
  391. {
  392. return SystemControlStatus;
  393. }
  394. set
  395. {
  396. }
  397. }
  398. public string ControlStatusBackground
  399. {
  400. get
  401. {
  402. switch (SystemControlStatus)
  403. {
  404. case "Unknown":
  405. return "Yellow";
  406. case "EquipmentOffline":
  407. case "AttemptOnline":
  408. case "HostOffline":
  409. return "Transparent";
  410. case "OnlineLocal":
  411. case "OnlineRemote":
  412. return "LawnGreen";
  413. default:
  414. return "Yellow";
  415. }
  416. }
  417. }
  418. /// Disabled = 0,
  419. /// Enabled = 1,
  420. /// EnabledNotCommunicating = 2,
  421. /// EnabledCommunicating = 3,
  422. /// WaitCRA = 4,
  423. /// WaitDelay = 5,
  424. /// WaitCRFromHost = 6,
  425. public string HostCommunicationStatusBackground
  426. {
  427. get
  428. {
  429. switch (HostCommunicationStatus)
  430. {
  431. case "Unknown":
  432. return "Yellow";
  433. case "EquipmentOffline":
  434. case "AttemptOnline":
  435. case "HostOffline":
  436. return "Transparent";
  437. case "OnlineLocal":
  438. case "EnabledCommunicating":
  439. return "LawnGreen";
  440. default:
  441. return "Yellow";
  442. }
  443. }
  444. }
  445. [Subscription("System.CommunicationStatus")]
  446. public string HostCommunicationStatus
  447. {
  448. get;
  449. set;
  450. }
  451. public bool IsEnableFAEnable
  452. {
  453. get
  454. {
  455. return HostCommunicationStatus == "Disabled";
  456. }
  457. }
  458. public bool IsDisableFAEnable
  459. {
  460. get
  461. {
  462. return HostCommunicationStatus != "Disabled";
  463. }
  464. }
  465. public string FAButtonContent => HostCommunicationStatus == "Disabled" ? "FA Enable" : "FA Disable";
  466. #endregion
  467. public string PM1Status
  468. {
  469. get { return $"{PM1EntityStatus}"; }
  470. set { }
  471. }
  472. [Subscription("PM1.Status")]
  473. public string PM1EntityStatus { get; set; }
  474. private string _newPM1EntityStatus;
  475. public string NewPM1EntityStatus
  476. {
  477. get { return _newPM1EntityStatus; }
  478. set { _newPM1EntityStatus = value; NotifyOfPropertyChange("NewPM1EntityStatus"); }
  479. }
  480. public string PM1StatusBackground
  481. {
  482. get { return ModuleStatusBackground.GetStatusBackground(NewPM1EntityStatus); }
  483. }
  484. [Subscription("System.SignalTower.DeviceData")]
  485. public AITSignalTowerData SignalTowerData { get; set; }
  486. public string SoftwareVersion
  487. {
  488. get;
  489. set;
  490. }
  491. public string RunTime
  492. {
  493. get
  494. {
  495. return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  496. }
  497. }
  498. public string LogoTooltip
  499. {
  500. get
  501. {
  502. return $"Software Version: {SoftwareVersion}";
  503. }
  504. }
  505. [Subscription("Scheduler.ControlJobList")]
  506. public List<ControlJobInfo> ControlJobs
  507. {
  508. get;
  509. set;
  510. }
  511. [Subscription("Scheduler.SecondPj")]
  512. public List<ProcessJobInfo> SecondPjList
  513. {
  514. get;
  515. set;
  516. }
  517. [Subscription("PM1.IsOnline")]
  518. public bool IsOnlinePM1 { get; set; }
  519. [Subscription("System.HasActiveAlarm")]
  520. public bool SystemHasAlarm { get; set; }
  521. private AppMenu _alarmMenu;
  522. public MainViewModel()
  523. {
  524. BaseApp.Instance.Initialize();
  525. ((FurnaceUI.Client.ClientApp)BaseApp.Instance).ViewModelSwitcher = this;
  526. this._models = new Dictionary<Type, BaseModel>();
  527. //for login part
  528. Roles = RoleAccountProvider.Instance.GetRoles();
  529. EventLogList = new ObservableCollection<EventItem>();
  530. WarnEventLogList = new ObservableCollection<EventItem>();
  531. SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  532. EventClient.Instance.OnEvent += Instance_OnEvent;
  533. EventClient.Instance.LockAndUnlockEvent += Instance_LockAndUnlockEvent;
  534. EventClient.Instance.OnDisconnectedWithRT += Instance_OnDisconnectedWithRT;
  535. EventClient.Instance.Start();
  536. //if (Debugger.IsAttached)
  537. //{
  538. // Login("admin", new PasswordBox() { Password = "admin" }, Roles.Find(it => it.RoleName == "Manager"));
  539. //}
  540. //Reset();
  541. var exeFilePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
  542. var tempPath = exeFilePath.Substring(0, exeFilePath.LastIndexOf("\\"));
  543. exeFilePath = tempPath.Substring(0, tempPath.LastIndexOf("\\")) + "\\FurnaceGasPanelUI\\" + "FurnaceGasPanelUI.exe";
  544. if (File.Exists(exeFilePath))
  545. {
  546. System.Diagnostics.Process.Start(exeFilePath);
  547. }
  548. }
  549. //设置LockAndUnLock
  550. private void Instance_LockAndUnlockEvent(bool obj)
  551. {
  552. // throw new NotImplementedException();
  553. IsLock = obj;
  554. }
  555. private void Instance_OnDisconnectedWithRT()
  556. {
  557. MessageBox.Show("Disconnected with RT, UI will exit", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  558. Environment.Exit(0);
  559. }
  560. public void ShowAlarmEvents()
  561. {
  562. AllEventsVisibility = Visibility.Hidden;
  563. WarnEventsVisibility = Visibility.Visible;
  564. this.NotifyOfPropertyChange("AllEventsVisibility");
  565. this.NotifyOfPropertyChange("WarnEventsVisibility");
  566. }
  567. public void ShowAllEvents()
  568. {
  569. AllEventsVisibility = Visibility.Visible;
  570. WarnEventsVisibility = Visibility.Hidden;
  571. this.NotifyOfPropertyChange("AllEventsVisibility");
  572. this.NotifyOfPropertyChange("WarnEventsVisibility");
  573. }
  574. private void Instance_OnEvent(EventItem obj)
  575. {
  576. switch (obj.Type)
  577. {
  578. case EventType.EventUI_Notify:
  579. LogEvent(obj);
  580. break;
  581. case EventType.Dialog_Nofity:
  582. //PopDialog(obj);
  583. break;
  584. case EventType.KickOut_Notify:
  585. if (obj.Description == "ShutDown")
  586. {
  587. AccountClient.Instance.Service.LogoutEx(BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.LoginId);
  588. ShutdownThread = ShutdownExecute;
  589. ShutdownThread.BeginInvoke(ShutdownCallBack, ShutdownThread);
  590. }
  591. break;
  592. case EventType.Sound_Notify:
  593. break;
  594. case EventType.UIMessage_Notify:
  595. //PopUIMessage(obj);
  596. break;
  597. }
  598. }
  599. void LogEvent(EventItem obj)
  600. {
  601. if (obj.Type != EventType.EventUI_Notify)
  602. return;
  603. Application.Current.Dispatcher.Invoke(() =>
  604. {
  605. while (EventLogList.Count > 100)
  606. {
  607. EventLogList.RemoveAt(0);
  608. }
  609. EventLogList.Add(obj);
  610. if (obj.Level == EventLevel.Alarm || obj.Level == EventLevel.Warning)
  611. {
  612. this.WarnEventLogList.Add(obj);
  613. }
  614. });
  615. }
  616. public void FAEnable()
  617. {
  618. InvokeClient.Instance.Service.DoOperation($"FACommand", "FAEnable");
  619. }
  620. public void FADisable(object para)
  621. {
  622. if (para.ToString() == "FA Disable")
  623. {
  624. InvokeClient.Instance.Service.DoOperation($"FACommand", "FADisable");
  625. }
  626. else
  627. {
  628. InvokeClient.Instance.Service.DoOperation($"FACommand", "FAEnable");
  629. }
  630. }
  631. #region login part
  632. public void Enter(KeyEventArgs args, string loginName, PasswordBox password, Role role)
  633. {
  634. if (args.Key == Key.Enter)
  635. this.Login(loginName, password, role);
  636. }
  637. public void Login(string loginName, PasswordBox password, Role role)
  638. {
  639. try
  640. {
  641. LoginResult result = AccountClient.Instance.Service.LoginEx(loginName, password.Password, role.RoleID);
  642. if (result.ActSucc)
  643. {
  644. ClientApp.Instance.UserContext.LoginId = result.SessionId;
  645. ClientApp.Instance.UserMode = UserMode.Normal;
  646. ClientApp.Instance.UserContext.LoginName = loginName;
  647. ClientApp.Instance.UserContext.Role = role;
  648. ClientApp.Instance.UserContext.RoleID = role.RoleID;
  649. ClientApp.Instance.UserContext.RoleName = role.RoleName;
  650. ClientApp.Instance.UserContext.LoginTime = DateTime.Now;
  651. //ClientApp.Instance.UserContext.Token = token;
  652. ClientApp.Instance.UserContext.LastAccessTime = DateTime.Now;
  653. ClientApp.Instance.UserContext.IsLogin = true;
  654. //Load menu by role
  655. //filer menu if necessary...
  656. ClientApp.Instance.MenuManager.LoadMenu(RoleAccountProvider.Instance.GetMenusByRole(role.RoleID, ClientApp.Instance.MenuLoader.MenuList));
  657. IsAutoLogout = role.IsAutoLogout;
  658. LogoutTime = role.LogoutTime;
  659. IsPermission = RoleAccountProvider.Instance.GetMenuPermission(role.RoleID, "Header") == 3;
  660. InitMenu(); //bind menu to main view
  661. IsLogin = true; //control the display logic of main view
  662. if (GetView() != null)
  663. {
  664. ((Window)GetView()).Dispatcher.BeginInvoke(new System.Action(() =>
  665. {
  666. foreach (var item in Application.Current.Windows)
  667. {
  668. if (item is Window && item != Application.Current.MainWindow)
  669. {
  670. ((Window)item).Visibility = Visibility.Visible
  671. ;
  672. }
  673. }
  674. }));
  675. }
  676. LOG.Info(string.Format("{0} login as {1}", loginName, role.RoleName));
  677. }
  678. else
  679. {
  680. Enum.TryParse(result.Description, out AuthorizeResult errCode);
  681. switch (errCode)
  682. {
  683. case AuthorizeResult.None:
  684. DialogBox.ShowError("Not connected with RT.");
  685. break;
  686. case AuthorizeResult.WrongPwd:
  687. DialogBox.ShowError("Invalid password.");
  688. break;
  689. case AuthorizeResult.HasLogin:
  690. DialogBox.ShowError("{0} has already logged in.", loginName);
  691. break;
  692. case AuthorizeResult.NoMatchRole:
  693. DialogBox.ShowError("{0} does not match {1} role.", loginName, role.RoleName);
  694. break;
  695. case AuthorizeResult.NoMatchUser:
  696. DialogBox.ShowError("{0} does not exists.", loginName);
  697. break;
  698. case AuthorizeResult.NoSession:
  699. DialogBox.ShowError("The current session is invalid.");
  700. break;
  701. }
  702. }
  703. password.Clear();
  704. }
  705. catch (Exception ex)
  706. {
  707. LOG.Error(ex.Message, ex);
  708. }
  709. }
  710. public void TxtLoginNameLostFocus(object sender, RoutedEventArgs e)
  711. {
  712. var userName = ((TextBox)sender).Text;
  713. if (!string.IsNullOrEmpty(userName))
  714. {
  715. var accounts = AccountClient.Instance.Service.GetAccounts();
  716. var user = accounts.Where(x => x.LoginName == userName).FirstOrDefault();
  717. if (user != null)
  718. {
  719. ShowRoles = RoleAccountProvider.Instance.GetRoles().Where(it => user.RoleIDs.Contains(it.RoleID)).ToList();
  720. if (_view != null)
  721. {
  722. if (_view.cbRole.Items.Count > 0)
  723. {
  724. _view.cbRole.SelectedIndex = 0;
  725. }
  726. }
  727. }
  728. }
  729. }
  730. #endregion
  731. public void PutModuleOnline(string module)
  732. {
  733. InvokeClient.Instance.Service.DoOperation($"{module}.PutOnline");
  734. }
  735. public void PutModuleOffline(string module)
  736. {
  737. InvokeClient.Instance.Service.DoOperation($"{module}.PutOffline");
  738. }
  739. public void Logout()
  740. {
  741. this.OnLogoutCommand();
  742. }
  743. public void LockClick()
  744. {
  745. string cmd = "Lock";
  746. if (IsLock == true)
  747. { cmd = "Unlock"; }
  748. else
  749. { cmd = "Lock"; }
  750. //EventClient.Instance.Service.Register
  751. InvokeClient.Instance.Service.DoOperation("System.SetLockAndUnlock", new object[] { cmd, EventClient.Instance.ClientGuid });
  752. }
  753. public void OnLogoutCommand()
  754. {
  755. WindowManager windowmanager = new WindowManager();
  756. var logoffViewmodel = new LogoffViewModel();
  757. windowmanager.ShowDialog(logoffViewmodel);
  758. BaseApp.Instance.UserMode = logoffViewmodel.DialogResult;
  759. switch (logoffViewmodel.DialogResult)
  760. {
  761. case UserMode.Logoff:
  762. Logoff();
  763. break;
  764. case UserMode.Exit:
  765. AccountClient.Instance.Service.LogoutEx(BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.LoginId);
  766. BaseApp.Instance.UserMode = UserMode.Exit;
  767. LOG.Info(string.Format("{0} exit a" +
  768. "s {1}", BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.RoleName));
  769. this.TryClose();
  770. break;
  771. case UserMode.Lock:
  772. Login("logoff", new PasswordBox() { Password = "admin" }, Roles.Find(it => it.RoleName == "Logoff"));
  773. break;
  774. case UserMode.Shutdown:
  775. Roles = RoleAccountProvider.Instance.GetRoles();
  776. InvokeClient.Instance.Service.DoOperation("System.ShutDown");
  777. break;
  778. }
  779. }
  780. public void Logoff()
  781. {
  782. BaseApp.Instance.UserMode = UserMode.Logoff;
  783. if (BaseApp.Instance.UserContext.IsLogin)
  784. {
  785. try
  786. {
  787. AccountClient.Instance.Service.LogoutEx(BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.LoginId);
  788. BaseApp.Instance.UserContext.IsLogin = false;
  789. LOG.Info(string.Format("{0} logoff as {1}", BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.RoleName));
  790. }
  791. catch (Exception exp)
  792. {
  793. LOG.Write(exp);
  794. }
  795. }
  796. IsLogin = false; //no independent login page
  797. Roles = RoleAccountProvider.Instance.GetRoles();
  798. ((Window)GetView()).Dispatcher.BeginInvoke(new System.Action(() =>
  799. {
  800. foreach (var item in Application.Current.Windows)
  801. {
  802. if (item is Window && item != Application.Current.MainWindow)
  803. {
  804. ((Window)item).Visibility = Visibility.Hidden;
  805. }
  806. }
  807. }));
  808. }
  809. public void Reset()
  810. {
  811. InvokeClient.Instance.Service.DoOperation("System.Reset");
  812. }
  813. public void BuzzerOff()
  814. {
  815. InvokeClient.Instance.Service.DoOperation($"System.SignalTower.{AITSignalTowerOperation.SwitchOffBuzzer}");
  816. }
  817. #region override functions
  818. public override void CanClose(Action<bool> callback)
  819. {
  820. if (BaseApp.Instance.UserMode == UserMode.Normal)
  821. {
  822. callback(false);
  823. Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart)delegate
  824. {
  825. this.OnLogoutCommand();
  826. });
  827. }
  828. else
  829. callback(true);
  830. }
  831. protected override void OnInitialize()
  832. {
  833. //display system version or other info...
  834. this.DisplayName = $"Furnace (V{SoftwareVersion})";
  835. base.OnInitialize();
  836. this.StartTimer();
  837. DrawSciChart();
  838. // Login("admin", new PasswordBox() { Password = "admin" }, new Role("0", "Manager", false, 1000, ""));
  839. }
  840. protected override void OnActivate()
  841. {
  842. base.OnActivate();
  843. this.ShowAllEvents();
  844. EnableTimer(true);
  845. }
  846. void DrawSciChart()
  847. {
  848. // Create the chart surface
  849. var sciChartSurface = new SciChartSurface();
  850. // Create the X and Y Axis
  851. var xAxis = new NumericAxis() { AxisTitle = "Number of Samples (per series)" };
  852. var yAxis = new NumericAxis() { AxisTitle = "Value" };
  853. sciChartSurface.XAxis = xAxis;
  854. sciChartSurface.YAxis = yAxis;
  855. // Specify Interactivity Modifiers
  856. sciChartSurface.ChartModifier = new ModifierGroup(new RubberBandXyZoomModifier(), new ZoomExtentsModifier());
  857. // Add annotation hints to the user
  858. var textAnnotation = new TextAnnotation()
  859. {
  860. Text = "Hello World!",
  861. X1 = 5.0,
  862. Y1 = 5.0
  863. };
  864. sciChartSurface.Annotations.Add(textAnnotation);
  865. }
  866. protected override void OnViewLoaded(object view)
  867. {
  868. base.OnViewLoaded(view);
  869. this._view = view as MainView;
  870. this._view.tbLoginName.Focus();
  871. IsLock = bool.Parse(AppSettingsHelper.GetConfigValue("IsLock"));
  872. }
  873. protected override void OnDeactivate(bool close)
  874. {
  875. base.OnDeactivate(close);
  876. EnableTimer(false);
  877. }
  878. #endregion
  879. #region
  880. #region Sync ShutDown Thread
  881. public delegate void ShutDownSysncThread();
  882. ShutDownSysncThread ShutdownThread = null;
  883. ShutdownViewModel ShutdownWindow = null;
  884. private void ShutdownExecute()
  885. {
  886. BaseApp.Instance.UserMode = UserMode.Shutdown;
  887. BaseApp.Instance.UserContext.IsLogin = false;
  888. LOG.Info(string.Format("{0} shutdown as {1}", BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.RoleName));
  889. this.TryClose();
  890. }
  891. private void ShutdownCallBack(IAsyncResult result)
  892. {
  893. if (ShutdownWindow != null)
  894. {
  895. ShutdownWindow.TryClose();
  896. }
  897. ShutdownThread.EndInvoke(result);
  898. }
  899. #endregion
  900. #region Menu Control and page switch
  901. private void InitMenu()
  902. {
  903. this.MenuItems = BaseApp.Instance.MenuManager.MenuItems;
  904. this.SubMenuItems = new List<AppMenu>();
  905. this.HistoryMenus = new ObservableCollection<AppMenu>();
  906. if (this.MenuItems.Count > 0)
  907. {
  908. AppMenu _default = null;
  909. foreach (AppMenu menuitem in this.MenuItems)
  910. {
  911. if (menuitem.MenuItems.Count > 0)
  912. {
  913. if (menuitem.AlarmModule == "System")
  914. {
  915. _alarmMenu = menuitem;
  916. continue;
  917. }
  918. #region PM Filter
  919. List<AppMenu> filtered = new List<AppMenu>();
  920. string toolType = (string)QueryDataClient.Instance.Service.GetConfig("System.SetUp.ToolType");
  921. if (string.IsNullOrEmpty(toolType)) continue;
  922. foreach (var menuItemMenuItem in menuitem.MenuItems)
  923. {
  924. if (string.IsNullOrEmpty(menuItemMenuItem.Type))
  925. { continue; }
  926. else
  927. {
  928. if (!menuItemMenuItem.Type.Contains(toolType))
  929. filtered.Add(menuItemMenuItem);
  930. }
  931. }
  932. foreach (var appMenu in filtered)
  933. {
  934. menuitem.MenuItems.Remove(appMenu);
  935. }
  936. }
  937. #endregion
  938. if (menuitem.MenuItems.Count > 0 && _default == null)
  939. _default = menuitem.MenuItems[0];
  940. }
  941. this.SwitchMenuItem(_default);
  942. }
  943. }
  944. public void MainSwitchMenuItem(AppMenu menuViewItem)
  945. {
  946. if (menuViewItem.MenuItems.Count > 0)
  947. {
  948. if (menuViewItem.LastSelectedSubMenu != null)
  949. SwitchMenuItem(menuViewItem.LastSelectedSubMenu);
  950. else
  951. SwitchMenuItem(menuViewItem.MenuItems[0]);
  952. }
  953. }
  954. private Dictionary<string, object> _menus = new Dictionary<string, object>();
  955. public void SwitchMenuItem(AppMenu menuViewItem, object parameter = null)
  956. {
  957. if (menuViewItem != null && menuViewItem.ViewModel != null && menuViewItem.ViewModel != string.Empty)
  958. {
  959. //if (menuViewItem.MenuID.ToLower() == "layoutrecipe")
  960. //{
  961. // if (parameter == null)
  962. // parameter = "Layout.List";
  963. // if (!_menus.ContainsKey(parameter.ToString()))
  964. // {
  965. // if (parameter.ToString() == "Layout.List")
  966. // {
  967. // menuViewItem.Model = (BaseModel)AssemblyUtil.CreateInstance(AssemblyUtil.GetType("FurnaceUI.Views.Recipes.RecipeLayoutViewModel, FurnaceUI"));
  968. // _menus["Layout.List"] = menuViewItem.Model;
  969. // }
  970. // if (parameter.ToString() == "Layout.Editor")
  971. // {
  972. // menuViewItem.Model = (BaseModel)AssemblyUtil.CreateInstance(AssemblyUtil.GetType("FurnaceUI.Views.Recipes.LayoutRecipes.LayoutRecipeEditorViewModel, FurnaceUI"));
  973. // _menus["Layout.Editor"] = menuViewItem.Model;
  974. // }
  975. // }
  976. // else
  977. // {
  978. // menuViewItem.Model = _menus[parameter.ToString()];
  979. // }
  980. //}
  981. if (menuViewItem.Model == null)
  982. {
  983. menuViewItem.Model = (BaseModel)AssemblyUtil.CreateInstance(AssemblyUtil.GetType(menuViewItem.ViewModel));
  984. ((BaseModel)menuViewItem.Model).Permission = menuViewItem.Permission;
  985. ((BaseModel)menuViewItem.Model).Token = BaseApp.Instance.UserContext.Token;
  986. if (menuViewItem.Model is ISupportMultipleSystem)
  987. (menuViewItem.Model as ISupportMultipleSystem).SystemName = menuViewItem.System;
  988. }
  989. switch (menuViewItem.MenuID.ToLower())
  990. {
  991. case "jobrecipe":
  992. ((BaseModel)menuViewItem.Model).CurrentMenuID = "Job";
  993. break;
  994. case "processrecipe":
  995. ((BaseModel)menuViewItem.Model).CurrentMenuID = "Process";
  996. break;
  997. case "subrecipe":
  998. ((BaseModel)menuViewItem.Model).CurrentMenuID = "sub";
  999. break;
  1000. case "alarmrecipe":
  1001. ((BaseModel)menuViewItem.Model).CurrentMenuID = "alarm";
  1002. break;
  1003. case "abortrecipe":
  1004. ((BaseModel)menuViewItem.Model).CurrentMenuID = "abort";
  1005. break;
  1006. case "resetrecipe":
  1007. ((BaseModel)menuViewItem.Model).CurrentMenuID = "reset";
  1008. break;
  1009. case "idlerecipe":
  1010. ((BaseModel)menuViewItem.Model).CurrentMenuID = "idle";
  1011. break;
  1012. case "layoutrecipe":
  1013. ((BaseModel)menuViewItem.Model).CurrentMenuID = "Layout";
  1014. break;
  1015. }
  1016. this.ActivateItem(((BaseModel)menuViewItem.Model));
  1017. CurrentViewModel = ((BaseModel)menuViewItem.Model);
  1018. //if (((BaseModel)menuViewItem.Model).Page != PageID.MAX_PAGE)
  1019. // BaseApp.Instance.SetCurrentPage(((BaseModel)menuViewItem.Model).Page);
  1020. this.HandleSubAndHistoryMenu(menuViewItem);
  1021. if (this._currentMenuItem != null)
  1022. {
  1023. this._currentMenuItem.Selected = false;
  1024. this._currentMenuItem.Parent.Selected = false;
  1025. }
  1026. menuViewItem.Selected = true;
  1027. menuViewItem.Parent.Selected = true;
  1028. menuViewItem.Parent.LastSelectedSubMenu = menuViewItem;
  1029. this._currentMenuItem = menuViewItem;
  1030. if (menuViewItem.Model is DataViewModel && parameter != null)
  1031. {
  1032. Task.Delay(200).ContinueWith((x) =>
  1033. {
  1034. var viewModel = (menuViewItem.Model as DataViewModel);
  1035. viewModel.Query(parameter);
  1036. });
  1037. }
  1038. }
  1039. }
  1040. private void HandleSubAndHistoryMenu(AppMenu menuitem)
  1041. {
  1042. this.SubMenuItems = menuitem.Parent.MenuItems;
  1043. if (!this.HistoryMenus.Contains(menuitem))
  1044. {
  1045. if (this.HistoryMenus.Count >= 8)
  1046. this.HistoryMenus.RemoveAt(7);
  1047. this.HistoryMenus.Insert(0, menuitem);
  1048. }
  1049. else
  1050. {
  1051. this.HistoryMenus.Remove(menuitem);
  1052. this.HistoryMenus.Insert(0, menuitem);
  1053. }
  1054. }
  1055. public bool SwitchPage(string firstLevelMenuID, string secondLevelMenuID, object parameter)
  1056. {
  1057. foreach (AppMenu menuitem in BaseApp.Instance.MenuManager.MenuItems)
  1058. {
  1059. if (menuitem.MenuID == firstLevelMenuID)
  1060. {
  1061. foreach (AppMenu menu in menuitem.MenuItems)
  1062. {
  1063. if (menu.MenuID == secondLevelMenuID)
  1064. {
  1065. SwitchMenuItem(menu, parameter);
  1066. return true;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. return false;
  1072. }
  1073. #endregion
  1074. #region Refresh Date Time on page
  1075. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  1076. {
  1077. if (_alarmMenu != null)
  1078. _alarmMenu.IsAlarm = SystemHasAlarm;
  1079. SetTubeStatus();
  1080. }
  1081. private void SetTubeStatus()
  1082. {
  1083. if (SecondPjList != null && SecondPjList.Count > 0 && SecondPjList.FirstOrDefault() != null && ControlJobs != null && ControlJobs.Count > 0)
  1084. {
  1085. var secondPj = SecondPjList.FirstOrDefault();
  1086. var actualPjName = ControlJobs.FirstOrDefault().ProcessJobNameList.FirstOrDefault();
  1087. if (secondPj.Name.Equals(actualPjName) && (int)secondPj.ProcessingState <= (int)EnumProcessingState.Processing)
  1088. {
  1089. NewPM1EntityStatus = "Process";
  1090. }
  1091. else
  1092. {
  1093. NewPM1EntityStatus = PM1EntityStatus;
  1094. }
  1095. }
  1096. else
  1097. {
  1098. NewPM1EntityStatus = PM1EntityStatus;
  1099. }
  1100. }
  1101. protected override bool OnTimer()
  1102. {
  1103. try
  1104. {
  1105. base.Poll();
  1106. //List<Role> roles = RoleAccountProvider.Instance.GetRoles();
  1107. if (!string.IsNullOrEmpty(ClientApp.Instance.UserContext.RoleName))
  1108. {
  1109. Role role = roles.Find(x => x.RoleName == ClientApp.Instance.UserContext.RoleName);
  1110. if (role == null) return true;
  1111. LogoutTime = role.LogoutTime;
  1112. IsAutoLogout = role.IsAutoLogout;
  1113. int intervaltime = GetLastInputTime();
  1114. //if (System.DateTime.Now >= ClientApp.Instance.UserContext.LoginTime.AddMinutes(LogoutTime) && IsLogin && IsAutoLogout)
  1115. // Console.WriteLine(intervaltime);
  1116. //if (intervaltime >= LogoutTime * 60 && IsLogin && IsAutoLogout)
  1117. // Logoff();
  1118. }
  1119. }
  1120. catch (Exception ex)
  1121. {
  1122. LOG.Error(ex.Message);
  1123. }
  1124. return true;
  1125. }
  1126. private void StartTimer()
  1127. {
  1128. System.Windows.Threading.DispatcherTimer myDispatcherTimer =
  1129. new System.Windows.Threading.DispatcherTimer();
  1130. myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);
  1131. myDispatcherTimer.Tick += new EventHandler(Each_Tick);
  1132. myDispatcherTimer.Start();
  1133. }
  1134. public void Each_Tick(object o, EventArgs sender)
  1135. {
  1136. this.NowDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1137. this.DisplayName = $"Furnace (Ver:{SoftwareVersion})";
  1138. this.NotifyOfPropertyChange("NowDateTime");
  1139. }
  1140. #endregion
  1141. #endregion
  1142. public void PasswordMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1143. {
  1144. if (sender is PasswordBox)
  1145. {
  1146. string strRet = ShowKeyboard(sender, ((PasswordBox)sender).Password);
  1147. ((PasswordBox)sender).Password = strRet;
  1148. }
  1149. }
  1150. private string ShowKeyboard(object sender, string strDefaultValue)
  1151. {
  1152. bool EnablePopupKeyboard = false;
  1153. Control control = sender as Control;
  1154. string strRet = string.Empty;
  1155. if (QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard") != null)
  1156. EnablePopupKeyboard = (bool)QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard");
  1157. if (!EnablePopupKeyboard) { return string.Empty; }
  1158. FullKeyboard fullKeyboard = new FullKeyboard("", strDefaultValue);
  1159. var point = control.PointFromScreen(new Point(0, 0));
  1160. double x = SystemParameters.WorkArea.Width;
  1161. double y = SystemParameters.WorkArea.Height;
  1162. if (-point.Y + control.ActualHeight + 5 + fullKeyboard.Height < y)
  1163. {
  1164. fullKeyboard.Top = -point.Y + control.ActualHeight + 5;
  1165. }
  1166. else
  1167. {
  1168. fullKeyboard.Top = -point.Y - fullKeyboard.Height - 5;
  1169. }
  1170. if (-point.X + fullKeyboard.Width < x)
  1171. {
  1172. fullKeyboard.Left = -point.X;
  1173. }
  1174. else
  1175. {
  1176. fullKeyboard.Left = -point.X - (fullKeyboard.Width - control.ActualWidth);
  1177. }
  1178. if ((bool)fullKeyboard.ShowDialog()) strRet = fullKeyboard.ValueString;
  1179. return strRet;
  1180. }
  1181. }
  1182. }