ControlJobStatusViewModel.cs 13 KB

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