MainViewModel.cs 48 KB

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