RecipeJobEditViewModel.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. using Aitex.Core.Util;
  2. using Caliburn.Micro;
  3. using Caliburn.Micro.Core;
  4. using MECF.Framework.Common.DataCenter;
  5. using MECF.Framework.Common.OperationCenter;
  6. using MECF.Framework.Common.RecipeCenter;
  7. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  8. using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
  9. using MECF.Framework.UI.Client.ClientBase;
  10. using OpenSEMI.ClientBase;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Collections.ObjectModel;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Xml;
  18. using System.Windows;
  19. using FurnaceUI.Models;
  20. using FurnaceUI.Views.Recipes;
  21. using ProcessTypeFileItems = MECF.Framework.UI.Client.CenterViews.Editors.Recipe.ProcessTypeFileItem;
  22. using System.Text.RegularExpressions;
  23. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  24. using FurnaceUI.Views.Editors;
  25. namespace FurnaceUI.Views.Recipes
  26. {
  27. public class RecipeJobEditViewModel : FurnaceUIViewModelBase
  28. {
  29. public RecipeJobEditViewModel(string strPrefixPath, string strRecipeName,string permission="")
  30. {
  31. CurrentRecipe.PrefixPath = strPrefixPath;
  32. CurrentRecipe.Name = strRecipeName;
  33. CurrentRecipe.RecipePermission = permission;
  34. }
  35. private readonly RecipeProvider _recipeProvider = new RecipeProvider();
  36. public string SelectRecipeType { get; set; }
  37. public RecipeDataJob CurrentRecipe { get; set; } = new RecipeDataJob();
  38. private string _coolTime;
  39. private WindowManager windowManager;
  40. public string CoolTime
  41. {
  42. get => _coolTime;
  43. set
  44. {
  45. _coolTime = value;
  46. NotifyOfPropertyChange(nameof(CoolTime));
  47. }
  48. }
  49. public bool IsEnable => CGlobal.RecipeJobEditViewEnable;//是否是View模式
  50. protected override void OnInitialize()
  51. {
  52. base.OnInitialize();
  53. LoadData();
  54. }
  55. private void LoadData()
  56. {
  57. CurrentRecipe.Clear();
  58. var recipeContent = _recipeProvider.LoadRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name);
  59. if (string.IsNullOrEmpty(recipeContent))
  60. {
  61. System.Windows.MessageBox.Show($"{CurrentRecipe.PrefixPath}\\{CurrentRecipe.Name} is empty, please confirm the file is valid.");
  62. return;
  63. }
  64. CurrentRecipe.RecipeChamberType = "OriginChamber";
  65. CurrentRecipe.InitData(CurrentRecipe.PrefixPath, CurrentRecipe.Name, recipeContent, "PM1");
  66. if (SystemConfigProvider.Instance.GetValueByName($"PM1.RecipeEditParameter.CoolTime.{CurrentRecipe.CoolTime}").Length > 0)
  67. CoolTime = CurrentRecipe.CoolTime + ":" + SystemConfigProvider.Instance.GetValueByName($"PM1.RecipeEditParameter.CoolTime.{CurrentRecipe.CoolTime}");
  68. else
  69. CoolTime = "Value:" + CurrentRecipe.CoolTime;
  70. }
  71. public void SelectProcessRecipe()
  72. {
  73. RecipeSelectDialogViewModel dialog = new RecipeSelectDialogViewModel();
  74. dialog.DisplayName = "Select Process Recipe";
  75. var recipeProvider = new RecipeProvider();
  76. var processType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedProcessType");
  77. if (processType == null)
  78. {
  79. processType = "Process";
  80. }
  81. var ProcessTypeFileList = new ObservableCollection<ProcessTypeFileItems>();
  82. string[] recipeProcessType = ((string)processType).Split(',');
  83. for (int i = 0; i < recipeProcessType.Length; i++)
  84. {
  85. var type = new ProcessTypeFileItems();
  86. type.ProcessType = recipeProcessType[i];
  87. var prefix = $"Furnace\\{recipeProcessType[i]}";
  88. var recipes = recipeProvider.GetXmlRecipeList(prefix);
  89. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  90. ProcessTypeFileList.Add(type);
  91. }
  92. dialog.ProcessTypeFileList = ProcessTypeFileList;
  93. WindowManager wm = new WindowManager();
  94. bool? bret = wm.ShowDialog(dialog);
  95. if ((bool)bret)
  96. {
  97. //var array = dialog.DialogResult.Split(new char[] { '\\' });
  98. //CurrentRecipe.ProcessRecipe = array[array.Length - 1];
  99. CurrentRecipe.ProcessRecipe = dialog.DialogResult;
  100. }
  101. }
  102. public void SelectLayoutRecipe()
  103. {
  104. RecipeSelectDialogViewModel dialog = new RecipeSelectDialogViewModel();
  105. dialog.DisplayName = "Select Layout Recipe";
  106. var recipeProvider = new RecipeProvider();
  107. //var processType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedLayoutType");
  108. if (SelectRecipeType == null)
  109. {
  110. SelectRecipeType = "Layout";
  111. }
  112. var ProcessTypeFileList = new ObservableCollection<ProcessTypeFileItems>();
  113. string[] recipeProcessType = ((string)SelectRecipeType).Split(',');
  114. for (int i = 0; i < recipeProcessType.Length; i++)
  115. {
  116. var type = new ProcessTypeFileItems();
  117. type.ProcessType = recipeProcessType[i];
  118. var prefix = $"Furnace\\{recipeProcessType[i]}";
  119. var recipes = recipeProvider.GetXmlRecipeList(prefix);
  120. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  121. ProcessTypeFileList.Add(type);
  122. }
  123. dialog.ProcessTypeFileList = ProcessTypeFileList;
  124. WindowManager wm = new WindowManager();
  125. bool? bret = wm.ShowDialog(dialog);
  126. if ((bool)bret)
  127. {
  128. //var array = dialog.DialogResult.Split(new char[] { '\\' });
  129. //CurrentRecipe.LayoutRecipe = array[array.Length - 1];
  130. CurrentRecipe.LayoutRecipe = dialog.DialogResult;
  131. }
  132. }
  133. public void CoolTimeEdit()
  134. {
  135. var windowManager = IoC.Get<IWindowManager>();
  136. RecipeStepTimeViewModel recipeStepTimeViewModel = new RecipeStepTimeViewModel("CoolTime");
  137. recipeStepTimeViewModel.SelectTime = CurrentRecipe.CoolTime;
  138. (windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepTimeViewModel, null, "Cooling Time Set");
  139. if (recipeStepTimeViewModel.IsSave)
  140. {
  141. if (recipeStepTimeViewModel.SelectTime == "Value")
  142. {
  143. CoolTime = recipeStepTimeViewModel.SelectTime + ":" + recipeStepTimeViewModel.SelectValueTime;
  144. CurrentRecipe.CoolTime = recipeStepTimeViewModel.SelectValueTime;
  145. }
  146. else
  147. {
  148. CoolTime = recipeStepTimeViewModel.SelectTime + ":" + recipeStepTimeViewModel.RecipeStepTime[recipeStepTimeViewModel.SelectTime];
  149. CurrentRecipe.CoolTime = recipeStepTimeViewModel.SelectTime;
  150. }
  151. }
  152. }
  153. public void SaveCmd()
  154. {
  155. RecipePermissionSelectViewModel dialog = new RecipePermissionSelectViewModel("Save recipe and permission", CurrentRecipe.RecipePermission);
  156. WindowManager wm = new WindowManager();
  157. bool? dialogReturn = wm.ShowDialog(dialog);
  158. if (!dialogReturn.HasValue || !dialogReturn.Value)
  159. return;
  160. if (string.IsNullOrEmpty(CurrentRecipe.ProcessRecipe))
  161. {
  162. DialogBox.ShowWarning("Process recipe is empty");
  163. return;
  164. }
  165. if (string.IsNullOrEmpty(CurrentRecipe.LayoutRecipe))
  166. {
  167. DialogBox.ShowWarning("Layout recipe is empty");
  168. return;
  169. }
  170. if (string.IsNullOrEmpty(CurrentRecipe.CoolTime))
  171. {
  172. DialogBox.ShowWarning("Cool time is empty");
  173. return;
  174. }
  175. //if (!CheckTimeFormat())
  176. //{
  177. // DialogBox.ShowWarning("Cool time format is error");
  178. // return;
  179. //}
  180. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  181. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  182. this.CurrentRecipe.RecipeLevel = this.LevelDisplay;
  183. this.CurrentRecipe.RecipePermission = dialog.RecipePermission;
  184. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  185. ((Window)GetView()).DialogResult = true;
  186. }
  187. private bool CheckTimeFormat()
  188. {
  189. bool bResult, bTimeH = true, bTimeM = true, bTimeS = true;
  190. string pattern = "^[0-9]*$";
  191. Regex rex = new Regex(pattern);
  192. //if (!rex.IsMatch(CurrentRecipe.CoolTimeH))
  193. //{
  194. // bTimeH = false;
  195. //}
  196. //if (!rex.IsMatch(CurrentRecipe.CoolTimeM))
  197. //{
  198. // bTimeM = false;
  199. //}
  200. //if (!rex.IsMatch(CurrentRecipe.CoolTimeS))
  201. //{
  202. // bTimeS = false;
  203. //}
  204. bResult = bTimeH && bTimeM && bTimeS;
  205. return bResult;
  206. }
  207. public void ClosedCmd()
  208. {
  209. if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, " You confirm that you want to unsave the recipe and exit the interface?") == DialogButton.No)
  210. return;
  211. ((Window)GetView()).DialogResult = false;
  212. }
  213. }
  214. }