RecipeEditorViewModel.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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.Triton160.UI;
  12. using Aitex.UI.RecipeEditor;
  13. namespace Triton160.UI.ViewModel
  14. {
  15. class RecipeEditorViewModel : ViewModelBase
  16. {
  17. #region 控件used
  18. public ICommand OpenLocalRecipeCommand { get; set; }
  19. public ICommand RightClickCommand { get; set; }
  20. public ICommand RecipeHelpDocCommand { get; set; }
  21. public ICommand SaveRecipeCommand { get; set; }
  22. public ICommand UndoCommand { get; set; }
  23. public ICommand RedoCommand { get; set; }
  24. public ICommand ExpandGroupCommand { get; set; }
  25. public ICommand CollapseGroupCommand { get; set; }
  26. public ICommand ToggleHideSameCommand { get; set; }
  27. public ICommand RecipeExport2ExcelCommand { get; set; }
  28. public ICommand ShowDetailedErrInfoCommand { get; set; }
  29. public ICommand EditRecipeInfoCommand { get; set; }
  30. public Visibility SingleAppElementVisibility { get; set; }
  31. public Visibility RecipeInfoTextVisibility { get; set; }
  32. public bool IsUndoEnabled { get; set; }
  33. public bool IsRedoEnabled { get; set; }
  34. public object RecipeHead { get; set; }
  35. public string Errors { get; set; }
  36. public string RecipeInfo { get; set; }
  37. public ObservableCollection<RecipeRow> RecipeRows { get; set; }
  38. public Visibility IsBarcodeVisibility
  39. {
  40. get; set;
  41. }
  42. #endregion 控件used
  43. private IUiRecipeManager _recipeManager;
  44. private string _chamberId;
  45. private SCValue _config = new SCValue();
  46. private string _currentRecipeName = string.Empty;
  47. public RecipeEditorViewModel(IUiRecipeManager recipeManager, string chamberId)
  48. {
  49. _recipeManager = recipeManager;
  50. _chamberId = chamberId;
  51. _config.SetKeys(new List<string>() { SCName.BarcodeConfig_EnableBarcode });
  52. }
  53. /// <summary>
  54. /// Recipe template
  55. /// </summary>
  56. public string RecipeTemplate
  57. {
  58. get
  59. {
  60. return _recipeManager.GetRecipeTemplate(_chamberId);
  61. }
  62. }
  63. public bool IsBarcodeEnabled
  64. {
  65. get
  66. {
  67. return _config.BarcodeConfig.EnableBarcode;
  68. }
  69. }
  70. public Dictionary<string, AitexTableRecipeFormatCatalogGroup> RecipePermission
  71. {
  72. get
  73. {
  74. try
  75. {
  76. string recipetemplate = RecipeTemplate;
  77. System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
  78. doc.LoadXml(RecipeTemplate);
  79. Dictionary<string, AitexTableRecipeFormatCatalogGroup> ret = new Dictionary<string, AitexTableRecipeFormatCatalogGroup>();
  80. XmlNodeList nodeList = doc.SelectNodes("TableRecipeData/Step");
  81. foreach (XmlNode node in nodeList)
  82. {
  83. AitexTableRecipeFormatCatalogGroup group = new AitexTableRecipeFormatCatalogGroup();
  84. if (node.BaseURI.ToLower() != "mos")
  85. {
  86. group.DisplayName = node.BaseURI;
  87. bool hasper = false;
  88. bool.TryParse(node.Attributes["Permission"].Value, out hasper);
  89. group.HasPermission = hasper;
  90. ret.Add(group.DisplayName, group);
  91. }
  92. }
  93. return ret;
  94. }
  95. catch (Exception ex)
  96. {
  97. LOG.Write(ex);
  98. }
  99. return new Dictionary<string, AitexTableRecipeFormatCatalogGroup>();
  100. }
  101. }
  102. public string RecipeVersion()
  103. {
  104. try
  105. {
  106. System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
  107. doc.LoadXml(RecipeTemplate);
  108. return doc.DocumentElement.Attributes["RecipeVersion"].Value;
  109. }
  110. catch (Exception ex)
  111. {
  112. LOG.Write(ex);
  113. }
  114. return "1.0";
  115. }
  116. /// <summary>
  117. /// Recipe format
  118. /// </summary>
  119. public string RecipeFormat
  120. {
  121. get
  122. {
  123. return _recipeManager.GetRecipeFormatXml(_chamberId);
  124. }
  125. }
  126. /// <summary>
  127. /// Name list of all recipes.
  128. /// </summary>
  129. public IEnumerable<string> RecipeNames
  130. {
  131. get
  132. {
  133. return _recipeManager.GetRecipes(_chamberId, true);
  134. }
  135. }
  136. /// <summary>
  137. /// Name list of all recipes.
  138. /// </summary>
  139. public string CurrentRecipeName { get { return _currentRecipeName; } set { if (value != _currentRecipeName) _currentRecipeName = value; InvokePropertyChanged("CurrentRecipeName"); } }
  140. /// <summary>
  141. /// Load recipe data by recipe name
  142. /// </summary>
  143. /// <param name="receipeName"></param>
  144. /// <returns></returns>
  145. public string LoadRecipe(string receipeName)
  146. {
  147. return _recipeManager.LoadRecipe(_chamberId, receipeName);
  148. }
  149. /// <summary>
  150. /// Get a list of all recipe names.
  151. /// </summary>
  152. /// <returns></returns>
  153. public IEnumerable<string> GetRecipes()
  154. {
  155. return _recipeManager.GetRecipes(_chamberId, true);
  156. }
  157. /// <summary>
  158. /// move recipe file
  159. /// </summary>
  160. /// <param name="folderName"></param>
  161. /// <param name="tragetFolderName"></param>
  162. /// <returns></returns>
  163. public bool MoveRecipeFile(string folderName, string tragetFolderName)
  164. {
  165. return _recipeManager.MoveRecipeFile(_chamberId, folderName, tragetFolderName);
  166. }
  167. /// <summary>
  168. /// delete a recipe by recipe name
  169. /// </summary>
  170. /// <param name="recipeName"></param>
  171. /// <returns></returns>
  172. public bool DeleteRecipe(string recipeName)
  173. {
  174. return _recipeManager.DeleteRecipe(_chamberId, recipeName);
  175. }
  176. /// <summary>
  177. /// Save recipe by recipe name and recipe data
  178. /// </summary>
  179. /// <param name="recipeName"></param>
  180. /// <param name="recipe"></param>
  181. /// <returns></returns>
  182. public bool SaveRecipe(string recipeName, string recipeContent)
  183. {
  184. return _recipeManager.SaveRecipe(_chamberId, recipeName, recipeContent);
  185. }
  186. /// <summary>
  187. /// SaveAs recipe by recipe name and recipe data
  188. /// </summary>
  189. /// <param name="recipeName"></param>
  190. /// <param name="recipe"></param>
  191. /// <returns></returns>
  192. public bool SaveAsRecipe(string recipeName, string recipeContent)
  193. {
  194. return _recipeManager.SaveAsRecipe(_chamberId, recipeName, recipeContent);
  195. }
  196. /// <summary>
  197. /// Rename recipe
  198. /// </summary>
  199. /// <param name="oldName"></param>
  200. /// <param name="newName"></param>
  201. /// <returns></returns>
  202. public bool RenameRecipe(string oldName, string newName)
  203. {
  204. return _recipeManager.RenameRecipe(_chamberId, oldName, newName);
  205. }
  206. /// <summary>
  207. /// Create recipe folder
  208. /// </summary>
  209. /// <param name="oldName"></param>
  210. /// <param name="newName"></param>
  211. /// <returns></returns>
  212. public bool CreateFolder(string folderName)
  213. {
  214. return _recipeManager.CreateFolder(_chamberId, folderName);
  215. }
  216. /// <summary>
  217. /// Get recipe list in xml format
  218. /// </summary>
  219. /// <returns></returns>
  220. public string GetXmlRecipeList()
  221. {
  222. return _recipeManager.GetXmlRecipeList(_chamberId, true) ?? "";
  223. }
  224. /// <summary>
  225. /// Delete recipe folder
  226. /// </summary>
  227. /// <param name="foldName"></param>
  228. /// <returns></returns>
  229. public bool DeleteFolder(string foldName)
  230. {
  231. return _recipeManager.DeleteFolder(_chamberId, foldName);
  232. }
  233. /// <summary>
  234. /// Rename recipe folder
  235. /// </summary>
  236. /// <param name="oldName"></param>
  237. /// <param name="newName"></param>
  238. /// <returns></returns>
  239. public bool RenameFolder(string oldName, string newName)
  240. {
  241. return _recipeManager.RenameFolder(_chamberId, oldName, newName);
  242. }
  243. public void UpdateAllConfig()
  244. {
  245. _config.Update(Triton160UiSystem.Instance.WCF.Query.PollConfig(_config.GetKeys()));
  246. }
  247. }
  248. }