ControlJobStatusViewModel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. using Aitex.Core.UI.MVVM;
  2. using Aitex.Core.Util;
  3. using MECF.Framework.Common.CommonData;
  4. using MECF.Framework.Common.Jobs;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Runtime.Serialization;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Input;
  14. using FurnaceUI.Models;
  15. using MECF.Framework.Common.OperationCenter;
  16. using OpenSEMI.ClientBase;
  17. namespace FurnaceUI.Views.Status
  18. {
  19. class ControlJobStatusViewModel : FurnaceUIViewModelBase
  20. {
  21. public bool IsPermission { get => this.Permission == 3; }
  22. public class ControlJobData : NotifiableItem
  23. {
  24. [DataMember]
  25. public int Num { get; set; }
  26. [DataMember]
  27. public string Name { get; set; }
  28. [DataMember]
  29. public string State { get; set; }
  30. [DataMember]
  31. public bool Auto { get; set; }
  32. }
  33. public ObservableCollection<ControlJobData> ControlJobsData { get; set; }
  34. [Subscription("Rt.Status")]
  35. public string RtStatus { get; set; }
  36. public ICommand ControlJobsCommand { get; set; }
  37. [Subscription("Scheduler.ControlJobList")]
  38. public List<ControlJobInfo> ControlJobs
  39. {
  40. get;
  41. set;
  42. }
  43. [Subscription("Scheduler.CurrentProcessJob")]
  44. public ProcessJobInfo CurrentProcessJob
  45. {
  46. get;
  47. set;
  48. }
  49. public ControlJobStatusViewModel()/* : base("MonitorJobViewModel")*/
  50. {
  51. ControlJobsData = new ObservableCollection<ControlJobData>();
  52. }
  53. public ControlJobData SelectedControlJob { get; set; }
  54. public string SelectedControlJobsObjtID
  55. {
  56. get
  57. {
  58. return SelectedControlJob != null ? SelectedControlJob.Name : "";
  59. }
  60. }
  61. public string SelectedControlJobsState
  62. {
  63. get
  64. {
  65. if (SelectedControlJob == null)
  66. {
  67. return " ";
  68. }
  69. return SelectedControlJob.State.ToString();
  70. }
  71. }
  72. public bool IsEnablePause
  73. {
  74. get
  75. {
  76. if (SelectedControlJob == null)
  77. return false;
  78. return SelectedControlJob.State.ToString() == "Executing";
  79. }
  80. }
  81. public bool IsEnableCoolingSkip
  82. {
  83. get
  84. {
  85. if (CurrentProcessJob == null)
  86. return false;
  87. return CurrentProcessJob.ProcessingState.ToString() == "CoolingBeforeDischarge";
  88. }
  89. }
  90. public bool IsEnableResume
  91. {
  92. get
  93. {
  94. if (SelectedControlJob == null)
  95. return false;
  96. return SelectedControlJob.State.ToString() == "Paused";
  97. }
  98. }
  99. public int AllInitializeCount { get; set; }
  100. private bool _AllInitializeEnable = true;
  101. public bool AllInitializeEnable
  102. {
  103. get => _AllInitializeEnable;
  104. set
  105. {
  106. _AllInitializeEnable = value;
  107. NotifyOfPropertyChange("AllInitializeEnable");
  108. }
  109. }
  110. public bool IsEnableInitialize
  111. {
  112. get { return (RtStatus == "Init" || RtStatus == "Idle") && AllInitializeEnable; }
  113. }
  114. public bool IsEnableStop
  115. {
  116. get
  117. {
  118. if (SelectedControlJob == null)
  119. return false;
  120. return SelectedControlJob.State.ToString() == "Executing" ||
  121. SelectedControlJob.State.ToString() == "Paused" ||
  122. SelectedControlJob.State.ToString() == "WaitingForStart" ||
  123. SelectedControlJob.State.ToString() == "Queued";
  124. }
  125. }
  126. public string CurrentStartMode
  127. {
  128. get
  129. {
  130. if (SelectedControlJob == null)
  131. {
  132. return "Waiting For Start";
  133. }
  134. return ((SelectedControlJob.State.ToString() == "Queued") || (SelectedControlJob.State.ToString() == "Completed")) ? "Waiting For Start" : "Active";
  135. }
  136. }
  137. public string CurrentStateIsActive
  138. {
  139. get
  140. {
  141. if (SelectedControlJob == null)
  142. {
  143. return "Transparent";
  144. }
  145. return ((SelectedControlJob.State.ToString() == "Queued") || (SelectedControlJob.State.ToString() == "Completed")) ? "Transparent" : "Green";
  146. }
  147. }
  148. public string CurrentStateIsActiveForeground
  149. {
  150. get
  151. {
  152. if (CurrentStateIsActive == "Green")
  153. {
  154. return "White";
  155. }
  156. return "Black";
  157. }
  158. }
  159. public string CurrentStateIsQueued
  160. {
  161. get
  162. {
  163. if (SelectedControlJob == null)
  164. {
  165. return "Transparent";
  166. }
  167. return SelectedControlJob.State.ToString() == "Queued" ? "Green" : "Transparent";
  168. }
  169. }
  170. public string CurrentStateIsSelected
  171. {
  172. get
  173. {
  174. if (SelectedControlJob == null)
  175. {
  176. return "Transparent";
  177. }
  178. return SelectedControlJob.State.ToString() == "Selected" ? "Green" : "Transparent";
  179. }
  180. }
  181. public string CurrentStateIsWaitingForStart
  182. {
  183. get
  184. {
  185. if (SelectedControlJob == null)
  186. {
  187. return "Transparent";
  188. }
  189. return SelectedControlJob.State.ToString() == "WaitingForStart" ? "Green" : "Transparent";
  190. }
  191. }
  192. public string CurrentStateIsExecuting
  193. {
  194. get
  195. {
  196. if (SelectedControlJob == null)
  197. {
  198. return "Transparent";
  199. }
  200. return SelectedControlJob.State.ToString() == "Executing" ? "Green" : "Transparent";
  201. }
  202. }
  203. public string CurrentStateIsPaused
  204. {
  205. get
  206. {
  207. if (SelectedControlJob == null)
  208. {
  209. return "Transparent";
  210. }
  211. return SelectedControlJob.State.ToString() == "Paused" ? "Green" : "Transparent";
  212. }
  213. }
  214. public string CurrentStateIsCompleted
  215. {
  216. get
  217. {
  218. if (SelectedControlJob == null)
  219. {
  220. return "Transparent";
  221. }
  222. return SelectedControlJob.State.ToString() == "Completed" ? "Green" : "Transparent";
  223. }
  224. }
  225. [Subscription("ProcessFlow.Status")]
  226. public string ProcessFlowStatus { get; set; }
  227. public void BtnClick(string cmd)
  228. {
  229. switch (cmd)
  230. {
  231. case "HomeAll":
  232. InvokeClient.Instance.Service.DoOperation("System.HomeAll");
  233. break;
  234. case "ABORT":
  235. InvokeClient.Instance.Service.DoOperation("PM1.RecipeAbort");
  236. break;
  237. case "RESET":
  238. InvokeClient.Instance.Service.DoOperation("System.Reset");
  239. break;
  240. case "IDLE":
  241. InvokeClient.Instance.Service.DoOperation("PM1.RecipeIdle");
  242. break;
  243. default:
  244. break;
  245. }
  246. }
  247. public void Manual(string module)
  248. {
  249. switch (module)
  250. {
  251. case "All Initialize":
  252. AllInitializeCount++;
  253. if (AllInitializeCount % 2 == 0)
  254. AllInitializeEnable = false;
  255. else
  256. AllInitializeEnable = true;
  257. break;
  258. default:
  259. break;
  260. }
  261. }
  262. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  263. {
  264. base.InvokeAfterUpdateProperty(data);
  265. if (ControlJobs == null || ControlJobs.Count == 0)
  266. {
  267. ControlJobsData.Clear();
  268. }
  269. else
  270. {
  271. int _Numcount = 1;
  272. foreach (var item in ControlJobs)
  273. {
  274. var match = ControlJobsData.ToList().Find(x => x.Name == item.Name);
  275. if (match == null)
  276. {
  277. ControlJobData cj = new ControlJobData();
  278. cj.Name = item.Name;
  279. cj.State = item.State.ToString();
  280. cj.Num = _Numcount;
  281. _Numcount++;
  282. ControlJobsData.Add(cj);
  283. }
  284. else
  285. {
  286. match.State = item.State.ToString();
  287. match.InvokePropertyChanged();
  288. }
  289. }
  290. List<ControlJobData> tobeRemove = new List<ControlJobData>();
  291. foreach (var cj in ControlJobsData)
  292. {
  293. if (ControlJobs.FirstOrDefault(x => x.Name == cj.Name) == null)
  294. tobeRemove.Add(cj);
  295. }
  296. foreach (var cj in tobeRemove)
  297. {
  298. ControlJobsData.Remove(cj);
  299. }
  300. _Numcount = 1;
  301. foreach (var item in ControlJobsData)
  302. {
  303. item.Num = _Numcount;
  304. _Numcount++;
  305. }
  306. }
  307. }
  308. public void ClosedCmd()
  309. {
  310. (GetView() as Window).Close();
  311. }
  312. public void CoolingSkip()
  313. {
  314. if (!DialogBox.Confirm("Are you sure to cooling skip"))
  315. {
  316. return;
  317. }
  318. InvokeClient.Instance.Service.DoOperation("System.CoolingSkip");
  319. }
  320. public void AbortJob()
  321. {
  322. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  323. {
  324. DialogBox.ShowWarning("Control job is not selected");
  325. return;
  326. }
  327. if (!DialogBox.Confirm("Are you sure to abort the control job"))
  328. {
  329. return;
  330. }
  331. var param = new object[] { SelectedControlJobsObjtID };
  332. InvokeClient.Instance.Service.DoOperation("System.AbortJob", param);
  333. }
  334. public void Start()
  335. {
  336. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  337. {
  338. DialogBox.ShowWarning("Control job is not selected");
  339. return;
  340. }
  341. var param = new object[] { SelectedControlJobsObjtID };
  342. InvokeClient.Instance.Service.DoOperation("System.StartJob", param);
  343. }
  344. public void Pause()
  345. {
  346. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  347. {
  348. DialogBox.ShowWarning("Control job is not selected");
  349. return;
  350. }
  351. var param = new object[] { SelectedControlJobsObjtID };
  352. InvokeClient.Instance.Service.DoOperation("System.PauseJob", param);
  353. }
  354. public void Resume()
  355. {
  356. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  357. {
  358. DialogBox.ShowWarning("Control job is not selected");
  359. return;
  360. }
  361. var param = new object[] { SelectedControlJobsObjtID };
  362. InvokeClient.Instance.Service.DoOperation("System.ResumeJob", param);
  363. }
  364. public void Stop()
  365. {
  366. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  367. {
  368. DialogBox.ShowWarning("Control job is not selected");
  369. return;
  370. }
  371. var param = new object[] { SelectedControlJobsObjtID };
  372. InvokeClient.Instance.Service.DoOperation("System.StopJob", param);
  373. }
  374. }
  375. }