MainViewModel.cs 49 KB

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