ControlJobStatusViewModel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. public void BtnClick(string cmd)
  226. {
  227. switch (cmd)
  228. {
  229. case "HomeAll":
  230. InvokeClient.Instance.Service.DoOperation("System.HomeAll");
  231. break;
  232. case "ABORT":
  233. InvokeClient.Instance.Service.DoOperation("PM1.RecipeAbort");
  234. break;
  235. case "RESET":
  236. InvokeClient.Instance.Service.DoOperation("System.Reset");
  237. break;
  238. case "IDLE":
  239. InvokeClient.Instance.Service.DoOperation("System.HomeAll");
  240. break;
  241. default:
  242. break;
  243. }
  244. }
  245. public void Manual(string module)
  246. {
  247. switch (module)
  248. {
  249. case "All Initialize":
  250. AllInitializeCount++;
  251. if (AllInitializeCount % 2 == 0)
  252. AllInitializeEnable = false;
  253. else
  254. AllInitializeEnable = true;
  255. break;
  256. default:
  257. break;
  258. }
  259. }
  260. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  261. {
  262. base.InvokeAfterUpdateProperty(data);
  263. if (ControlJobs == null || ControlJobs.Count == 0)
  264. {
  265. ControlJobsData.Clear();
  266. }
  267. else
  268. {
  269. int _Numcount = 1;
  270. foreach (var item in ControlJobs)
  271. {
  272. var match = ControlJobsData.ToList().Find(x => x.Name == item.Name);
  273. if (match == null)
  274. {
  275. ControlJobData cj = new ControlJobData();
  276. cj.Name = item.Name;
  277. cj.State = item.State.ToString();
  278. cj.Num = _Numcount;
  279. _Numcount++;
  280. ControlJobsData.Add(cj);
  281. }
  282. else
  283. {
  284. match.State = item.State.ToString();
  285. match.InvokePropertyChanged();
  286. }
  287. }
  288. List<ControlJobData> tobeRemove = new List<ControlJobData>();
  289. foreach (var cj in ControlJobsData)
  290. {
  291. if (ControlJobs.FirstOrDefault(x => x.Name == cj.Name) == null)
  292. tobeRemove.Add(cj);
  293. }
  294. foreach (var cj in tobeRemove)
  295. {
  296. ControlJobsData.Remove(cj);
  297. }
  298. _Numcount = 1;
  299. foreach (var item in ControlJobsData)
  300. {
  301. item.Num = _Numcount;
  302. _Numcount++;
  303. }
  304. }
  305. }
  306. public void ClosedCmd()
  307. {
  308. (GetView() as Window).Close();
  309. }
  310. public void CoolingSkip()
  311. {
  312. if (!DialogBox.Confirm("Are you sure to cooling skip"))
  313. {
  314. return;
  315. }
  316. InvokeClient.Instance.Service.DoOperation("System.CoolingSkip");
  317. }
  318. public void AbortJob()
  319. {
  320. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  321. {
  322. DialogBox.ShowWarning("Control job is not selected");
  323. return;
  324. }
  325. if (!DialogBox.Confirm("Are you sure to abort the control job"))
  326. {
  327. return;
  328. }
  329. var param = new object[] { SelectedControlJobsObjtID };
  330. InvokeClient.Instance.Service.DoOperation("System.AbortJob", param);
  331. }
  332. public void Start()
  333. {
  334. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  335. {
  336. DialogBox.ShowWarning("Control job is not selected");
  337. return;
  338. }
  339. var param = new object[] { SelectedControlJobsObjtID };
  340. InvokeClient.Instance.Service.DoOperation("System.StartJob", param);
  341. }
  342. public void Pause()
  343. {
  344. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  345. {
  346. DialogBox.ShowWarning("Control job is not selected");
  347. return;
  348. }
  349. var param = new object[] { SelectedControlJobsObjtID };
  350. InvokeClient.Instance.Service.DoOperation("System.PauseJob", param);
  351. }
  352. public void Resume()
  353. {
  354. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  355. {
  356. DialogBox.ShowWarning("Control job is not selected");
  357. return;
  358. }
  359. var param = new object[] { SelectedControlJobsObjtID };
  360. InvokeClient.Instance.Service.DoOperation("System.ResumeJob", param);
  361. }
  362. public void Stop()
  363. {
  364. if (string.IsNullOrEmpty(SelectedControlJobsObjtID))
  365. {
  366. DialogBox.ShowWarning("Control job is not selected");
  367. return;
  368. }
  369. var param = new object[] { SelectedControlJobsObjtID };
  370. InvokeClient.Instance.Service.DoOperation("System.StopJob", param);
  371. }
  372. }
  373. }