MainViewModel.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  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. public MainViewModel()
  517. {
  518. BaseApp.Instance.Initialize();
  519. ((VirgoUI.Client.ClientApp)BaseApp.Instance).ViewModelSwitcher = this;
  520. this._models = new Dictionary<Type, BaseModel>();
  521. //for login part
  522. Roles = RoleAccountProvider.Instance.GetRoles();
  523. EventLogList = new ObservableCollection<EventItem>();
  524. EventClient.Instance.OnEvent += Instance_OnEvent;
  525. EventClient.Instance.OnDisconnectedWithRT += Instance_OnDisconnectedWithRT;
  526. EventClient.Instance.Start();
  527. WarnEventLogList = new ObservableCollection<EventItem>();
  528. SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  529. }
  530. private void Instance_OnDisconnectedWithRT()
  531. {
  532. MessageBox.Show("Disconnected with RT, UI will exit", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  533. Environment.Exit(0);
  534. }
  535. public void ShowAlarmEvents()
  536. {
  537. AllEventsVisibility = Visibility.Hidden;
  538. WarnEventsVisibility = Visibility.Visible;
  539. this.NotifyOfPropertyChange("AllEventsVisibility");
  540. this.NotifyOfPropertyChange("WarnEventsVisibility");
  541. }
  542. public void ShowAllEvents()
  543. {
  544. AllEventsVisibility = Visibility.Visible;
  545. WarnEventsVisibility = Visibility.Hidden;
  546. this.NotifyOfPropertyChange("AllEventsVisibility");
  547. this.NotifyOfPropertyChange("WarnEventsVisibility");
  548. }
  549. //private void PopDialog(EventItem obj)
  550. //{
  551. // Application.Current.Dispatcher.Invoke(() =>
  552. // {
  553. // DialogBox.ShowInfo(obj.Explaination);
  554. // });
  555. // MessageBox.Show(obj.Explaination, "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  556. //}
  557. void PopDialog(EventItem item)
  558. {
  559. Application.Current.Dispatcher.Invoke(new System.Action(() =>
  560. {
  561. switch (item.Level)
  562. {
  563. case EventLevel.Alarm:
  564. MessageBoxEx.ShowError(item.Description, item.Explaination);
  565. break;
  566. case EventLevel.Warning:
  567. MessageBoxEx.ShowWarning(item.Description, item.Explaination);
  568. break;
  569. case EventLevel.Information:
  570. MessageBoxEx.ShowInfo(item.Description, item.Explaination);
  571. break;
  572. case EventLevel.InformationNoDelay:
  573. ShowLotComplete(item.Explaination);
  574. //MessageBoxEx.ShowInfoNoDelay(item.Description, item.Explaination);
  575. break;
  576. }
  577. }));
  578. }
  579. private void Instance_OnEvent(EventItem obj)
  580. {
  581. switch (obj.Type)
  582. {
  583. case EventType.EventUI_Notify:
  584. LogEvent(obj);
  585. break;
  586. case EventType.Dialog_Nofity:
  587. PopDialog(obj);
  588. break;
  589. case EventType.KickOut_Notify:
  590. break;
  591. case EventType.Sound_Notify:
  592. break;
  593. case EventType.UIMessage_Notify:
  594. //PopUIMessage(obj);
  595. break;
  596. }
  597. }
  598. LotCompleteDialogViewModel _lotCompleteDialog = new LotCompleteDialogViewModel();
  599. void ShowLotComplete(string result)
  600. {
  601. string[] info = result.Split(';');
  602. if (info.Length > 5)
  603. {
  604. var module = info[0];
  605. _lotCompleteDialog.DisplayName = "Information";
  606. //LP;WaferSize;Lot;Number;Start;End;
  607. if (module == "LP1")
  608. {
  609. _lotCompleteDialog.LP1LotComplete.Module = "LP1";
  610. _lotCompleteDialog.LP1LotComplete.LotID = info[2];
  611. _lotCompleteDialog.LP1LotComplete.WaferNumber = info[3];
  612. _lotCompleteDialog.LP1LotComplete.StartTime = info[4];
  613. _lotCompleteDialog.LP1LotComplete.EndTime = info[5];
  614. switch (info[1])
  615. {
  616. case "WS3":
  617. _lotCompleteDialog.LP1LotComplete.WaferSize = $"WS{QueryDataClient.Instance.Service.GetConfig($"System.SmallWafer")}";
  618. break;
  619. case "WS4":
  620. _lotCompleteDialog.LP1LotComplete.WaferSize = $"WS{QueryDataClient.Instance.Service.GetConfig($"System.MidWafer")}";
  621. break;
  622. case "WS6":
  623. _lotCompleteDialog.LP1LotComplete.WaferSize = $"WS{QueryDataClient.Instance.Service.GetConfig($"System.BigWafer")}";
  624. break;
  625. }
  626. _lotCompleteDialog.LP1LotComplete.InvokePropertyChanged();
  627. }
  628. if (module == "LP2")
  629. {
  630. _lotCompleteDialog.LP2LotComplete.Module = "LP2";
  631. _lotCompleteDialog.LP2LotComplete.LotID = info[2];
  632. _lotCompleteDialog.LP2LotComplete.WaferNumber = info[3];
  633. _lotCompleteDialog.LP2LotComplete.StartTime = info[4];
  634. _lotCompleteDialog.LP2LotComplete.EndTime = info[5];
  635. switch (info[1])
  636. {
  637. case "WS3":
  638. _lotCompleteDialog.LP2LotComplete.WaferSize = $"WS{QueryDataClient.Instance.Service.GetConfig($"System.SmallWafer")}";
  639. break;
  640. case "WS4":
  641. _lotCompleteDialog.LP2LotComplete.WaferSize = $"WS{QueryDataClient.Instance.Service.GetConfig($"System.MidWafer")}";
  642. break;
  643. case "WS6":
  644. _lotCompleteDialog.LP2LotComplete.WaferSize = $"WS{QueryDataClient.Instance.Service.GetConfig($"System.BigWafer")}";
  645. break;
  646. }
  647. _lotCompleteDialog.LP2LotComplete.InvokePropertyChanged();
  648. }
  649. _lotCompleteDialog.SetVisible(module, true);
  650. }
  651. if (!_lotCompleteDialog.IsDisplayed)
  652. {
  653. _lotCompleteDialog.IsDisplayed = true;
  654. Task.Run(() =>
  655. {
  656. Application.Current.Dispatcher.Invoke(() =>
  657. {
  658. WindowManager wm = new WindowManager();
  659. bool? bret = wm.ShowDialog(_lotCompleteDialog);
  660. if ((bool)bret)
  661. {
  662. }
  663. _lotCompleteDialog.IsDisplayed = false;
  664. });
  665. });
  666. }
  667. }
  668. void LogEvent(EventItem obj)
  669. {
  670. if (obj.Type != EventType.EventUI_Notify)
  671. return;
  672. Application.Current.Dispatcher.Invoke(() =>
  673. {
  674. while (EventLogList.Count > 100)
  675. {
  676. EventLogList.RemoveAt(0);
  677. }
  678. EventLogList.Add(obj);
  679. if (obj.Level == EventLevel.Alarm)
  680. this.WarnEventLogList.Add(obj);
  681. });
  682. if (this.WarnEventLogList.Count() > 1)
  683. this.IsAlarmListOpen = true;
  684. }
  685. void ResetAlarmList()
  686. {
  687. this.WarnEventLogList.Clear();
  688. }
  689. #region login part
  690. public void Enter(KeyEventArgs args, string loginName, PasswordBox password, Role role)
  691. {
  692. if (args.Key == Key.Enter)
  693. this.Login(loginName, password, role);
  694. }
  695. public void Login(string loginName, PasswordBox password, Role role)
  696. {
  697. try
  698. {
  699. LoginResult result = AccountClient.Instance.Service.LoginEx(loginName, password.Password, role.RoleID);
  700. if (result.ActSucc)
  701. {
  702. ClientApp.Instance.UserContext.LoginId = result.SessionId;
  703. ClientApp.Instance.UserMode = UserMode.Normal;
  704. ClientApp.Instance.UserContext.LoginName = loginName;
  705. ClientApp.Instance.UserContext.Role = role;
  706. ClientApp.Instance.UserContext.RoleID = role.RoleID;
  707. ClientApp.Instance.UserContext.RoleName = role.RoleName;
  708. ClientApp.Instance.UserContext.LoginTime = DateTime.Now;
  709. //ClientApp.Instance.UserContext.Token = token;
  710. ClientApp.Instance.UserContext.LastAccessTime = DateTime.Now;
  711. ClientApp.Instance.UserContext.IsLogin = true;
  712. //Load menu by role
  713. //filer menu if necessary...
  714. ClientApp.Instance.MenuManager.LoadMenu(RoleAccountProvider.Instance.GetMenusByRole(role.RoleID, ClientApp.Instance.MenuLoader.MenuList));
  715. IsAutoLogout = role.IsAutoLogout;
  716. LogoutTime = role.LogoutTime;
  717. InitMenu(); //bind menu to main view
  718. IsLogin = true; //control the display logic of main view
  719. //main view is common page, need register keys with true flag
  720. ClientApp.Instance.StatesManager.Register(new List<string>() { "System.RtStatus" }, true);
  721. LoginName = loginName;
  722. RoleName = role.RoleName;
  723. LOG.Info(string.Format("{0} login as {1}", loginName, role.RoleName));
  724. }
  725. else
  726. {
  727. Enum.TryParse(result.Description, out AuthorizeResult errCode);
  728. switch (errCode)
  729. {
  730. case AuthorizeResult.None:
  731. DialogBox.ShowError("Not connected with RT.");
  732. break;
  733. case AuthorizeResult.WrongPwd:
  734. DialogBox.ShowError("Invalid password.");
  735. break;
  736. case AuthorizeResult.HasLogin:
  737. DialogBox.ShowError("{0} has already logged in.", loginName);
  738. break;
  739. case AuthorizeResult.NoMatchRole:
  740. DialogBox.ShowError("{0} does not match {1} role.", loginName, role.RoleName);
  741. break;
  742. case AuthorizeResult.NoMatchUser:
  743. DialogBox.ShowError("{0} does not exists.", loginName);
  744. break;
  745. case AuthorizeResult.NoSession:
  746. DialogBox.ShowError("The current session is invalid.");
  747. break;
  748. }
  749. }
  750. password.Clear();
  751. }
  752. catch (Exception ex)
  753. {
  754. LOG.Error(ex.Message, ex);
  755. }
  756. }
  757. #endregion login part
  758. public void Logout()
  759. {
  760. this.OnLogoutCommand();
  761. }
  762. public void OnLogoutCommand()
  763. {
  764. WindowManager windowmanager = new WindowManager();
  765. var logoffViewmodel = new LogoffViewModel();
  766. windowmanager.ShowDialog(logoffViewmodel);
  767. BaseApp.Instance.UserMode = logoffViewmodel.DialogResult;
  768. switch (logoffViewmodel.DialogResult)
  769. {
  770. case UserMode.Logoff:
  771. BaseApp.Instance.UserMode = UserMode.Logoff;
  772. if (BaseApp.Instance.UserContext.IsLogin)
  773. {
  774. try
  775. {
  776. AccountClient.Instance.Service.LogoutEx(BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.LoginId);
  777. BaseApp.Instance.UserContext.IsLogin = false;
  778. LOG.Info(string.Format("{0} logoff as {1}", BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.RoleName));
  779. }
  780. catch (Exception exp)
  781. {
  782. LOG.Write(exp);
  783. }
  784. }
  785. IsLogin = false; //no independent login page
  786. break;
  787. case UserMode.Exit:
  788. AccountClient.Instance.Service.LogoutEx(BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.LoginId);
  789. BaseApp.Instance.UserMode = UserMode.Exit;
  790. LOG.Info(string.Format("{0} exit as {1}", BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.RoleName));
  791. MsgPool.TerminateAll();
  792. this.TryClose();
  793. break;
  794. case UserMode.Shutdown:
  795. AccountClient.Instance.Service.LogoutEx(BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.LoginId);
  796. ShutdownWindow = new ShutdownViewModel();
  797. ShutdownThread = ShutdownExecute;
  798. windowmanager.ShowWindow(ShutdownWindow);
  799. ShutdownThread.BeginInvoke(ShutdownCallBack, ShutdownThread);
  800. break;
  801. }
  802. }
  803. public void Reset()
  804. {
  805. _trigGauge.RST = true;
  806. _trigAlarm.RST = true;
  807. _trigPMAStatsAlarm.RST = true;
  808. _trigPMBStatsAlarm.RST = true;
  809. _trigPMAStatsWarning.RST = true;
  810. _trigPMBStatsWarning.RST = true;
  811. InvokeClient.Instance.Service.DoOperation("System.Reset");
  812. this.ResetAlarmList();
  813. }
  814. public void BuzzerOff()
  815. {
  816. InvokeClient.Instance.Service.DoOperation($"{ModuleName.EFEM}.{EfemOperation.TurnOffBuzzer}");
  817. }
  818. public void FAEnable()
  819. {
  820. InvokeClient.Instance.Service.DoOperation($"System.FACommand", "FAEnable");
  821. }
  822. public void FADisable()
  823. {
  824. InvokeClient.Instance.Service.DoOperation($"System.FACommand", "FADisable");
  825. }
  826. #region override functions
  827. public void Logoff()
  828. {
  829. BaseApp.Instance.UserMode = UserMode.Logoff;
  830. if (BaseApp.Instance.UserContext.IsLogin)
  831. {
  832. try
  833. {
  834. AccountClient.Instance.Service.LogoutEx(BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.LoginId);
  835. BaseApp.Instance.UserContext.IsLogin = false;
  836. LOG.Info(string.Format("{0} logoff as {1}", BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.RoleName));
  837. }
  838. catch (Exception exp)
  839. {
  840. LOG.Write(exp);
  841. }
  842. }
  843. IsLogin = false; //no independent login page
  844. Roles = RoleAccountProvider.Instance.GetRoles();
  845. }
  846. protected override bool OnTimer()
  847. {
  848. try
  849. {
  850. base.Poll();
  851. List<Role> roles = RoleAccountProvider.Instance.GetRoles();
  852. if (!string.IsNullOrEmpty(ClientApp.Instance.UserContext.RoleName))
  853. {
  854. Role role = roles.Find(x => x.RoleName == ClientApp.Instance.UserContext.RoleName);
  855. LogoutTime = role.LogoutTime;
  856. IsAutoLogout = role.IsAutoLogout;
  857. int intervaltime = GetLastInputTime();
  858. //if (System.DateTime.Now >= ClientApp.Instance.UserContext.LoginTime.AddMinutes(LogoutTime) && IsLogin && IsAutoLogout)
  859. if (intervaltime >= LogoutTime * 60 && IsLogin && IsAutoLogout)
  860. Logoff();
  861. }
  862. }
  863. catch (Exception ex)
  864. {
  865. LOG.Error(ex.Message);
  866. }
  867. return true;
  868. }
  869. public override void CanClose(Action<bool> callback)
  870. {
  871. if (BaseApp.Instance.UserMode == UserMode.Normal)
  872. {
  873. callback(false);
  874. Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart)delegate
  875. {
  876. this.OnLogoutCommand();
  877. });
  878. }
  879. else
  880. callback(true);
  881. }
  882. protected override void OnInitialize()
  883. {
  884. //display system version or other info...
  885. this.DisplayName = "JetPlasma";
  886. base.OnInitialize();
  887. this.StartTimer();
  888. DrawSciChart();
  889. //TODO, Login
  890. //Login("admin", new PasswordBox() { Password = "admin" }, new Role("0", "Manager", false, 1000, ""));
  891. }
  892. protected override void OnActivate()
  893. {
  894. base.OnActivate();
  895. this.ShowAllEvents();
  896. EnableTimer(true);
  897. }
  898. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  899. {
  900. base.InvokeAfterUpdateProperty(data);
  901. if (LP1Present == 0 && _lotCompleteDialog.IsDisplayed && _lotCompleteDialog.LP1Visibility==Visibility.Visible)
  902. {
  903. _lotCompleteDialog.LP1LotComplete.Clear();
  904. _lotCompleteDialog.SetVisible("LP1", false);
  905. }
  906. if (LP2Present == 0 && _lotCompleteDialog.IsDisplayed && _lotCompleteDialog.LP2Visibility == Visibility.Visible)
  907. {
  908. _lotCompleteDialog.LP2LotComplete.Clear();
  909. _lotCompleteDialog.SetVisible("LP2", false);
  910. }
  911. if (LP1Present == 0 && LP2Present == 0 && _lotCompleteDialog.IsDisplayed)
  912. {
  913. _lotCompleteDialog.TryClose(true);
  914. _lotCompleteDialog.IsDisplayed = false;
  915. }
  916. }
  917. void DrawSciChart()
  918. {
  919. // Create the chart surface
  920. var sciChartSurface = new SciChartSurface();
  921. // Create the X and Y Axis
  922. var xAxis = new NumericAxis() { AxisTitle = "Number of Samples (per series)" };
  923. var yAxis = new NumericAxis() { AxisTitle = "Value" };
  924. sciChartSurface.XAxis = xAxis;
  925. sciChartSurface.YAxis = yAxis;
  926. // Specify Interactivity Modifiers
  927. sciChartSurface.ChartModifier = new ModifierGroup(new RubberBandXyZoomModifier(), new ZoomExtentsModifier());
  928. // Add annotation hints to the user
  929. var textAnnotation = new TextAnnotation()
  930. {
  931. Text = "Hello World!",
  932. X1 = 5.0,
  933. Y1 = 5.0
  934. };
  935. sciChartSurface.Annotations.Add(textAnnotation);
  936. }
  937. protected override void OnViewLoaded(object view)
  938. {
  939. base.OnViewLoaded(view);
  940. this._view = view as MainView;
  941. this._view.tbLoginName.Focus();
  942. }
  943. protected override void OnDeactivate(bool close)
  944. {
  945. base.OnDeactivate(close);
  946. EnableTimer(false);
  947. }
  948. #endregion override functions
  949. #region
  950. #region Sync ShutDown Thread
  951. public delegate void ShutDownSysncThread();
  952. private ShutDownSysncThread ShutdownThread = null;
  953. private ShutdownViewModel ShutdownWindow = null;
  954. private void ShutdownExecute()
  955. {
  956. MsgPool.TerminateAll();
  957. BaseApp.Instance.UserMode = UserMode.Shutdown;
  958. BaseApp.Instance.UserContext.IsLogin = false;
  959. LOG.Info(string.Format("{0} shutdown as {1}", BaseApp.Instance.UserContext.LoginName, BaseApp.Instance.UserContext.RoleName));
  960. this.TryClose();
  961. }
  962. private void ShutdownCallBack(IAsyncResult result)
  963. {
  964. if (ShutdownWindow != null)
  965. {
  966. ShutdownWindow.TryClose();
  967. }
  968. ShutdownThread.EndInvoke(result);
  969. }
  970. #endregion Sync ShutDown Thread
  971. #region Menu Control and page switch
  972. private void InitMenu()
  973. {
  974. this.MenuItems = BaseApp.Instance.MenuManager.MenuItems;
  975. this.HistoryMenus = new ObservableCollection<AppMenu>();
  976. if (this.MenuItems.Count > 0)
  977. {
  978. foreach (AppMenu menuitem in this.MenuItems)
  979. {
  980. if (menuitem.MenuItems.Count > 0)
  981. {
  982. this.SwitchMenuItem(menuitem.MenuItems[0]);
  983. break;
  984. }
  985. }
  986. }
  987. }
  988. public void MainSwitchMenuItem(AppMenu menuViewItem)
  989. {
  990. if (menuViewItem.MenuItems.Count > 0)
  991. {
  992. if (menuViewItem.LastSelectedSubMenu != null)
  993. SwitchMenuItem(menuViewItem.LastSelectedSubMenu);
  994. else
  995. SwitchMenuItem(menuViewItem.MenuItems[0]);
  996. }
  997. }
  998. public void SwitchMenuItem(AppMenu menuViewItem, object queryFilter = null)
  999. {
  1000. if (menuViewItem.ViewModel != null && menuViewItem.ViewModel != string.Empty)
  1001. {
  1002. if (menuViewItem.Model == null)
  1003. {
  1004. menuViewItem.Model = (BaseModel)AssemblyUtil.CreateInstance(AssemblyUtil.GetType(menuViewItem.ViewModel));
  1005. ((BaseModel)menuViewItem.Model).Permission = menuViewItem.Permission;
  1006. ((BaseModel)menuViewItem.Model).Token = BaseApp.Instance.UserContext.Token;
  1007. if (menuViewItem.Model is ISupportMultipleSystem)
  1008. (menuViewItem.Model as ISupportMultipleSystem).SystemName = menuViewItem.System;
  1009. if (menuViewItem.Model is RFCalibrationViewModel)
  1010. {
  1011. var viewModel = (menuViewItem.Model as RFCalibrationViewModel);
  1012. if (viewModel.CustomParameter == null)
  1013. viewModel.CustomParameter = new CustomCalibration(viewModel.SystemName);
  1014. }
  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 (queryFilter != null)
  1031. {
  1032. Task.Delay(1000).ContinueWith((x) =>
  1033. {
  1034. var viewModel = (menuViewItem.Model as Models.History.ProcessHistory.ProcessHistoryViewModel);
  1035. viewModel.Query(queryFilter);
  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 queryFilter = null)
  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, queryFilter);
  1066. return true;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. return false;
  1072. }
  1073. #endregion Menu Control and page switch
  1074. #region Refresh Date Time on page
  1075. private void StartTimer()
  1076. {
  1077. System.Windows.Threading.DispatcherTimer myDispatcherTimer =
  1078. new System.Windows.Threading.DispatcherTimer();
  1079. myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);
  1080. myDispatcherTimer.Tick += new EventHandler(Each_Tick);
  1081. myDispatcherTimer.Start();
  1082. }
  1083. public void Each_Tick(object o, EventArgs sender)
  1084. {
  1085. this.NowDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1086. this.NotifyOfPropertyChange("NowDateTime");
  1087. }
  1088. #endregion Refresh Date Time on page
  1089. #endregion
  1090. public string NowDateTime { get; set; }
  1091. private bool _IsLogin = false;
  1092. public bool IsLogin
  1093. {
  1094. get { return _IsLogin; }
  1095. set { _IsLogin = value; NotifyOfPropertyChange("IsLogin"); }
  1096. }
  1097. private List<Role> roles;
  1098. public List<Role> Roles
  1099. {
  1100. get { return this.roles; }
  1101. set { this.roles = value; this.RaisePropertyChangedEventImmediately("Roles"); }
  1102. }
  1103. private ICommand menuItemClickCommand;
  1104. public ICommand MenuItemClickCommand
  1105. {
  1106. get
  1107. {
  1108. if (this.menuItemClickCommand == null)
  1109. this.menuItemClickCommand = new BaseCommand<AppMenu>((AppMenu menuViewItem) => this.SwitchMenuItem(menuViewItem));
  1110. return this.menuItemClickCommand;
  1111. }
  1112. }
  1113. private ICommand mainmenuItemClickCommand;
  1114. public ICommand MainMenuItemClickCommand
  1115. {
  1116. get
  1117. {
  1118. if (this.mainmenuItemClickCommand == null)
  1119. this.mainmenuItemClickCommand = new BaseCommand<AppMenu>((AppMenu menuViewItem) => this.MainSwitchMenuItem(menuViewItem));
  1120. return this.mainmenuItemClickCommand;
  1121. }
  1122. }
  1123. public List<AppMenu> MenuItems
  1124. {
  1125. get { return this.menuItems; }
  1126. set { this.menuItems = value; this.NotifyOfPropertyChange("MenuItems"); }
  1127. }
  1128. public List<AppMenu> SubMenuItems
  1129. {
  1130. get { return this.subMenuItems; }
  1131. set { this.subMenuItems = value; this.NotifyOfPropertyChange("SubMenuItems"); }
  1132. }
  1133. public ObservableCollection<AppMenu> HistoryMenus
  1134. {
  1135. get { return this.historyItems; }
  1136. set { this.historyItems = value; this.NotifyOfPropertyChange("HistoryMenus"); }
  1137. }
  1138. public string Context
  1139. {
  1140. get { return this.context; }
  1141. set { this.context = value; this.NotifyOfPropertyChange("Context"); }
  1142. }
  1143. public BaseModel CurrentViewModel { get; private set; }
  1144. public UserContext User { get { return BaseApp.Instance.UserContext; } }
  1145. private AppMenu _currentMenuItem;
  1146. private List<AppMenu> menuItems;
  1147. private List<AppMenu> subMenuItems;
  1148. private ObservableCollection<AppMenu> historyItems;
  1149. private string context;
  1150. private MainView _view;
  1151. private Dictionary<Type, BaseModel> _models;
  1152. }
  1153. }