RecipeEditorViewModel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Windows;
  5. using System.Windows.Input;
  6. using System.Xml;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.RecipeCenter;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.UI.MVVM;
  11. using Aitex.UI.RecipeEditor;
  12. using MECF.Framework.Common.DataCenter;
  13. using OpenSEMI.ClientBase;
  14. using VirgoUI.Client.Models.Sys;
  15. namespace VirgoUI.Client.Models.PMs
  16. {
  17. class RecipeEditorViewModel : ModuleUiViewModelBase, ISupportMultipleSystem
  18. {
  19. #region 控件used
  20. public ICommand OpenLocalRecipeCommand { get; set; }
  21. public ICommand RightClickCommand { get; set; }
  22. public ICommand RecipeHelpDocCommand { get; set; }
  23. public ICommand SaveRecipeCommand { get; set; }
  24. public ICommand UndoCommand { get; set; }
  25. public ICommand RedoCommand { get; set; }
  26. public ICommand ExpandGroupCommand { get; set; }
  27. public ICommand CollapseGroupCommand { get; set; }
  28. public ICommand ToggleHideSameCommand { get; set; }
  29. public ICommand RecipeExport2ExcelCommand { get; set; }
  30. public ICommand ShowDetailedErrInfoCommand { get; set; }
  31. public ICommand EditRecipeInfoCommand { get; set; }
  32. public Visibility SingleAppElementVisibility { get; set; }
  33. public Visibility RecipeInfoTextVisibility { get; set; }
  34. public bool IsUndoEnabled { get; set; }
  35. public bool IsRedoEnabled { get; set; }
  36. public object RecipeHead { get; set; }
  37. public string Errors { get; set; }
  38. public string RecipeInfo { get; set; }
  39. public ObservableCollection<RecipeRow> RecipeRows { get; set; }
  40. public Visibility IsBarcodeVisibility
  41. {
  42. get; set;
  43. }
  44. #endregion 控件used
  45. private IUiRecipeManager _recipeManager;
  46. private string _chamberId;
  47. private SCValue _config = new SCValue();
  48. private string _currentRecipeName = string.Empty;
  49. public bool _recipeSplit
  50. {
  51. get
  52. {
  53. return (bool)QueryDataClient.Instance.Service.GetConfig("System.RecipeSplit");
  54. }
  55. }
  56. public RecipeEditorViewModel()
  57. {
  58. // _config.SetKeys(new List<string>() { SCName.BarcodeConfig_EnableBarcode });
  59. }
  60. public RecipeEditorViewModel(IUiRecipeManager recipeManager, string chamberId)
  61. {
  62. _recipeManager = recipeManager;
  63. _chamberId = chamberId;
  64. // _config.SetKeys(new List<string>() { SCName.BarcodeConfig_EnableBarcode });
  65. }
  66. public string ChamberId
  67. {
  68. set { _chamberId = value; }
  69. get { return _chamberId; }
  70. }
  71. public int ProcessTypeIndexSelection { get; set; } = (bool)QueryDataClient.Instance.Service.GetConfig("System.RecipeSplit") ? 1 : 0;
  72. public Visibility RecipeSplitEnable => (bool)QueryDataClient.Instance.Service.GetConfig("System.RecipeSplit") ? Visibility.Visible : Visibility.Collapsed;
  73. public Visibility RecipeSplitDisable => (bool)QueryDataClient.Instance.Service.GetConfig("System.RecipeSplit") ? Visibility.Collapsed : Visibility.Visible;
  74. /// <summary>
  75. /// Recipe template
  76. /// </summary>
  77. public string RecipeTemplate
  78. {
  79. get
  80. {
  81. return _recipeManager.GetRecipeTemplate(_chamberId);
  82. }
  83. }
  84. public bool IsBarcodeEnabled
  85. {
  86. get
  87. {
  88. return false;
  89. }
  90. }
  91. public Dictionary<string, AitexTableRecipeFormatCatalogGroup> RecipePermission
  92. {
  93. get
  94. {
  95. try
  96. {
  97. string recipetemplate = RecipeTemplate;
  98. System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
  99. doc.LoadXml(RecipeTemplate);
  100. Dictionary<string, AitexTableRecipeFormatCatalogGroup> ret = new Dictionary<string, AitexTableRecipeFormatCatalogGroup>();
  101. XmlNodeList nodeList = doc.SelectNodes("TableRecipeData/Step");
  102. foreach (XmlNode node in nodeList)
  103. {
  104. AitexTableRecipeFormatCatalogGroup group = new AitexTableRecipeFormatCatalogGroup();
  105. if (node.BaseURI.ToLower() != "mos")
  106. {
  107. group.DisplayName = node.BaseURI;
  108. bool hasper = false;
  109. bool.TryParse(node.Attributes["Permission"].Value, out hasper);
  110. group.HasPermission = hasper;
  111. ret.Add(group.DisplayName, group);
  112. }
  113. }
  114. return ret;
  115. }
  116. catch (Exception ex)
  117. {
  118. LOG.Write(ex);
  119. }
  120. return new Dictionary<string, AitexTableRecipeFormatCatalogGroup>();
  121. }
  122. }
  123. public string RecipeVersion()
  124. {
  125. try
  126. {
  127. System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
  128. doc.LoadXml(RecipeTemplate);
  129. return doc.DocumentElement.Attributes["RecipeVersion"].Value;
  130. }
  131. catch (Exception ex)
  132. {
  133. LOG.Write(ex);
  134. }
  135. return "1.0";
  136. }
  137. /// <summary>
  138. /// Recipe format
  139. /// </summary>
  140. public string RecipeFormat
  141. {
  142. get
  143. {
  144. return _recipeManager.GetRecipeFormatXml(_chamberId);
  145. }
  146. }
  147. /// <summary>
  148. /// Name list of all recipes.
  149. /// </summary>
  150. public IEnumerable<string> RecipeNames
  151. {
  152. get
  153. {
  154. return _recipeManager.GetRecipes(_chamberId, true);
  155. }
  156. }
  157. /// <summary>
  158. /// Name list of all recipes.
  159. /// </summary>
  160. public string CurrentRecipeName { get { return _currentRecipeName; } set { if (value != _currentRecipeName) _currentRecipeName = value; InvokePropertyChanged("CurrentRecipeName"); } }
  161. /// <summary>
  162. /// Load recipe data by recipe name
  163. /// </summary>
  164. /// <param name="receipeName"></param>
  165. /// <returns></returns>
  166. public string LoadRecipe(string receipeName, string rcpType)
  167. {
  168. if (_recipeSplit)
  169. {
  170. return _recipeManager.LoadRecipe(_chamberId + "\\" + rcpType, receipeName);
  171. }
  172. return _recipeManager.LoadRecipe(_chamberId, receipeName);
  173. }
  174. /// <summary>
  175. /// Get a list of all recipe names.
  176. /// </summary>
  177. /// <returns></returns>
  178. public IEnumerable<string> GetRecipes(string rcpType)
  179. {
  180. if (_recipeSplit)
  181. {
  182. return _recipeManager.GetRecipes(_chamberId + "\\" + rcpType, true);
  183. }
  184. return _recipeManager.GetRecipes(_chamberId, true);
  185. }
  186. /// <summary>
  187. /// delete a recipe by recipe name
  188. /// </summary>
  189. /// <param name="recipeName"></param>
  190. /// <returns></returns>
  191. public bool DeleteRecipe(string recipeName, string rcpType)
  192. {
  193. if (_recipeSplit)
  194. {
  195. return _recipeManager.DeleteRecipe(_chamberId + "\\" + rcpType, recipeName);
  196. }
  197. return _recipeManager.DeleteRecipe(_chamberId, recipeName);
  198. }
  199. /// <summary>
  200. /// Save recipe by recipe name and recipe data
  201. /// </summary>
  202. /// <param name="recipeName"></param>
  203. /// <param name="recipe"></param>
  204. /// <returns></returns>
  205. public bool SaveRecipe(string recipeName, string rcpType, string recipeContent)
  206. {
  207. if (_recipeSplit)
  208. {
  209. return _recipeManager.SaveRecipe(_chamberId + "\\" + rcpType, recipeName, recipeContent);
  210. }
  211. return _recipeManager.SaveRecipe(_chamberId, recipeName, recipeContent);
  212. }
  213. /// <summary>
  214. /// Save recipe by recipe name and recipe data
  215. /// </summary>
  216. /// <param name="recipeName"></param>
  217. /// <param name="recipe"></param>
  218. /// <returns></returns>
  219. public bool SaveRecipeDouble(string recipeName, string rcpType, string recipeContent)
  220. {
  221. if (_recipeSplit)
  222. {
  223. return _recipeManager.SaveRecipe(_chamberId + "\\" + rcpType, recipeName, recipeContent) && _recipeManager.SaveRecipe((_chamberId == "PMA" ? "PMB" : "PMA") + "\\" + rcpType, recipeName, recipeContent);
  224. }
  225. return _recipeManager.SaveRecipe(_chamberId, recipeName, recipeContent) && _recipeManager.SaveRecipe((_chamberId == "PMA" ? "PMB" : "PMA"), recipeName, recipeContent);
  226. }
  227. /// <summary>
  228. /// SaveAs recipe by recipe name and recipe data
  229. /// </summary>
  230. /// <param name="recipeName"></param>
  231. /// <param name="recipe"></param>
  232. /// <returns></returns>
  233. public bool SaveAsRecipe(string recipeName, string rcpType, string recipeContent)
  234. {
  235. if (_recipeSplit)
  236. {
  237. return _recipeManager.SaveAsRecipe(_chamberId + "\\" + rcpType, recipeName, recipeContent);
  238. }
  239. return _recipeManager.SaveAsRecipe(_chamberId, recipeName, recipeContent);
  240. }
  241. /// <summary>
  242. /// Rename recipe
  243. /// </summary>
  244. /// <param name="oldName"></param>
  245. /// <param name="newName"></param>
  246. /// <returns></returns>
  247. public bool RenameRecipe(string oldName, string rcpType, string newName)
  248. {
  249. if (_recipeSplit)
  250. {
  251. return _recipeManager.RenameRecipe(_chamberId + "\\" + rcpType, oldName, newName);
  252. }
  253. return _recipeManager.RenameRecipe(_chamberId, oldName, newName);
  254. }
  255. /// <summary>
  256. /// Create recipe folder
  257. /// </summary>
  258. /// <param name="oldName"></param>
  259. /// <param name="newName"></param>
  260. /// <returns></returns>
  261. public bool CreateFolder(string folderName, string rcpType)
  262. {
  263. if (_recipeSplit)
  264. {
  265. return _recipeManager.CreateFolder(_chamberId + "\\" + rcpType, folderName);
  266. }
  267. return _recipeManager.CreateFolder(_chamberId, folderName);
  268. }
  269. /// <summary>
  270. /// move recipe file
  271. /// </summary>
  272. /// <param name="folderName"></param>
  273. /// <param name="tragetFolderName"></param>
  274. /// <returns></returns>
  275. public bool MoveRecipeFile(string folderName, string rcpType, string tragetFolderName)
  276. {
  277. if (_recipeSplit)
  278. {
  279. return _recipeManager.MoveRecipeFile(_chamberId + "\\" + rcpType, folderName, tragetFolderName);
  280. }
  281. return _recipeManager.MoveRecipeFile(_chamberId, folderName, tragetFolderName);
  282. }
  283. /// <summary>
  284. /// Get recipe list in xml format
  285. /// </summary>
  286. /// <returns></returns>
  287. public string GetXmlRecipeList(string rcpType)
  288. {
  289. if (_recipeSplit)
  290. {
  291. return _recipeManager.GetXmlRecipeList(_chamberId + "\\" + rcpType, true) ?? "";
  292. }
  293. return _recipeManager.GetXmlRecipeList(_chamberId, true) ?? "";
  294. }
  295. /// <summary>
  296. /// Delete recipe folder
  297. /// </summary>
  298. /// <param name="foldName"></param>
  299. /// <returns></returns>
  300. public bool DeleteFolder(string foldName, string rcpType)
  301. {
  302. if (_recipeSplit)
  303. {
  304. return _recipeManager.DeleteFolder(_chamberId, foldName);
  305. }
  306. return _recipeManager.DeleteFolder(_chamberId + "\\" + rcpType, foldName);
  307. }
  308. /// <summary>
  309. /// Rename recipe folder
  310. /// </summary>
  311. /// <param name="oldName"></param>
  312. /// <param name="newName"></param>
  313. /// <returns></returns>
  314. public bool RenameFolder(string oldName, string rcpType, string newName)
  315. {
  316. if (_recipeSplit)
  317. {
  318. return _recipeManager.RenameFolder(_chamberId + "\\" + rcpType, oldName, newName);
  319. }
  320. return _recipeManager.RenameFolder(_chamberId, oldName, newName);
  321. }
  322. public void UpdateAllConfig()
  323. {
  324. //_config.Update(VirgoUiSystem.Instance.WCF.Query.PollConfig(_config.GetKeys()));
  325. }
  326. }
  327. }