RecipeViewModel.cs 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.IOCore;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.UI.View.Common;
  5. using MECF.Framework.Common.DataCenter;
  6. using MECF.Framework.Common.OperationCenter;
  7. using Microsoft.VisualBasic;
  8. using Newtonsoft.Json;
  9. using Newtonsoft.Json.Linq;
  10. using Prism.Commands;
  11. using Prism.Mvvm;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Collections.ObjectModel;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Reflection;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows;
  21. using System.Windows.Controls;
  22. using System.Windows.Data;
  23. using System.Windows.Input;
  24. using System.Windows.Media;
  25. using System.Xml;
  26. using Venus_Core;
  27. using Venus_Core.Attributes;
  28. using Venus_MainPages.PMs;
  29. using Venus_MainPages.Unity;
  30. using Venus_MainPages.Views;
  31. using Venus_Themes.UserControls;
  32. using WPF.Themes.UserControls;
  33. using MessageBox = System.Windows.MessageBox;
  34. using RecipeStep = Venus_Core.RecipeStep;
  35. namespace Venus_MainPages.ViewModels
  36. {
  37. internal class RecipeViewModel : BindableBase
  38. {
  39. #region 私有字段
  40. public string ModuleName = "PMA";
  41. private string m_CurrentRecipeName;
  42. private UiRecipeManager m_uiRecipeManager = new UiRecipeManager();
  43. private RecipeView recipeView;
  44. private TreeView treeViewRcpList;
  45. private Recipe m_currentRecipe;
  46. private string m_recipeType;
  47. private bool firstLoad = true;
  48. private WrapPanel headWrapPanel;
  49. private StackPanel bodyStackPanel;
  50. private List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>()
  51. {
  52. //new SolidColorBrush(Colors.Cyan),
  53. //new SolidColorBrush(Colors.Lime),
  54. new SolidColorBrush(Colors.Coral),
  55. new SolidColorBrush(Colors.Cyan),
  56. new SolidColorBrush(Colors.Honeydew)
  57. };
  58. private Grid currentRecipeGrid;
  59. private int copyIndex = -1;
  60. private List<string> EPDCfgList = new List<string>();
  61. private EPDType currentEPDType = EPDType.None;
  62. private JetChamber currentChamber;
  63. private bool isInstalledEPD;
  64. private bool m_IsFrozen;
  65. private bool m_PMAIsInstalled;
  66. private bool m_PMBIsInstalled;
  67. private bool m_PMCIsInstalled;
  68. private bool m_PMDIsInstalled;
  69. private List<string> moduleList = new List<string>();
  70. TreeViewFileItem selectedItem;
  71. private string typeFolder = "";
  72. private bool m_HeadExpand=true;
  73. #endregion
  74. #region 属性
  75. public bool HeadExpand
  76. {
  77. get { return m_HeadExpand; }
  78. set { SetProperty(ref m_HeadExpand, value); }
  79. }
  80. public string CurrentRecipeName
  81. {
  82. get { return m_CurrentRecipeName; }
  83. set { SetProperty(ref m_CurrentRecipeName, value); }
  84. }
  85. public Recipe CurrentRecipe
  86. {
  87. get { return m_currentRecipe; }
  88. set
  89. {
  90. m_currentRecipe = value;
  91. RecipeType = m_currentRecipe?.Header?.Type.ToString();
  92. }
  93. }
  94. public string RecipeType
  95. {
  96. get { return m_recipeType; }
  97. set { SetProperty(ref m_recipeType, value); }
  98. }
  99. public bool IsFrozen
  100. {
  101. get { return m_IsFrozen; }
  102. set { SetProperty(ref m_IsFrozen, value); }
  103. }
  104. public bool PMAIsInstalled
  105. {
  106. get { return m_PMAIsInstalled; }
  107. set { SetProperty(ref m_PMAIsInstalled, value); }
  108. }
  109. public bool PMBIsInstalled
  110. {
  111. get { return m_PMBIsInstalled; }
  112. set { SetProperty(ref m_PMBIsInstalled, value); }
  113. }
  114. public bool PMCIsInstalled
  115. {
  116. get { return m_PMCIsInstalled; }
  117. set { SetProperty(ref m_PMCIsInstalled, value); }
  118. }
  119. public bool PMDIsInstalled
  120. {
  121. get { return m_PMDIsInstalled; }
  122. set { SetProperty(ref m_PMDIsInstalled, value); }
  123. }
  124. #endregion
  125. #region 命令
  126. private DelegateCommand<Object> _MouseRightButtonDownCommand;
  127. public DelegateCommand<Object> MouseRightButtonDownCommand =>
  128. _MouseRightButtonDownCommand ?? (_MouseRightButtonDownCommand = new DelegateCommand<Object>(OnMouseRightButtonDown));
  129. private DelegateCommand<Object> _LoadedCommand;
  130. public DelegateCommand<Object> LoadedCommand =>
  131. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand<Object>(OnLoaded));
  132. private DelegateCommand _SaveRecipeCommand;
  133. public DelegateCommand SaveRecipeCommand =>
  134. _SaveRecipeCommand ?? (_SaveRecipeCommand = new DelegateCommand(OnSaveRecipe));
  135. private DelegateCommand<object> _SaveToRecipeCommand;
  136. public DelegateCommand<object> SaveToRecipeCommand =>
  137. _SaveToRecipeCommand ?? (_SaveToRecipeCommand = new DelegateCommand<object>(OnSaveToRecipe));
  138. private DelegateCommand _AddStepCommand;
  139. public DelegateCommand AddStepCommand =>
  140. _AddStepCommand ?? (_AddStepCommand = new DelegateCommand(OnAddStep));
  141. private DelegateCommand _DeleteStepCommand;
  142. public DelegateCommand DeleteStepCommand =>
  143. _DeleteStepCommand ?? (_DeleteStepCommand = new DelegateCommand(OnDeleteStep));
  144. private DelegateCommand _RefreshCommand;
  145. public DelegateCommand RefreshCommand =>
  146. _RefreshCommand ?? (_RefreshCommand = new DelegateCommand(OnRefresh));
  147. private DelegateCommand _ToleranceCommand;
  148. public DelegateCommand ToleranceCommand =>
  149. _ToleranceCommand ?? (_ToleranceCommand = new DelegateCommand(OnTolerance));
  150. private DelegateCommand _ExpandCommand;
  151. public DelegateCommand ExpandCommand =>
  152. _ExpandCommand ?? (_ExpandCommand = new DelegateCommand(OnExpand));
  153. private DelegateCommand _UnloadCommand;
  154. public DelegateCommand UnloadCommand =>
  155. _UnloadCommand ?? (_UnloadCommand = new DelegateCommand(OnUnload));
  156. private DelegateCommand<Object> _MouseLeftButtonDownCommand;
  157. public DelegateCommand<Object> MouseLeftButtonDownCommand =>
  158. _MouseLeftButtonDownCommand ?? (_MouseLeftButtonDownCommand = new DelegateCommand<Object>(OnMouseLeftButtonDown));
  159. #endregion
  160. #region 命令方法
  161. private void OnAddStep()
  162. {
  163. if (CurrentRecipe != null)
  164. {
  165. var index = currentRecipeGrid.ColumnDefinitions.Count;
  166. RecipeStep recipeStep;
  167. if (copyIndex == -1)
  168. {
  169. recipeStep = new RecipeStep();
  170. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  171. CurrentRecipe.Steps.Insert(index - 1, recipeStep);
  172. }
  173. else
  174. {
  175. var t = JsonConvert.SerializeObject(CurrentRecipe);
  176. recipeStep = Recipe.Load(t).Steps[copyIndex - 1];
  177. CurrentRecipe.Steps.Insert(index - 1, recipeStep);
  178. }
  179. RecipeStepToGridColumn(recipeStep, currentRecipeGrid, index, true);
  180. for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
  181. {
  182. CurrentRecipe.Steps[i - 1].StepNo = i;
  183. }
  184. }
  185. }
  186. private void OnDeleteStep()
  187. {
  188. if (CurrentRecipe != null)
  189. {
  190. OnDeleteStep(CurrentRecipe.Steps.Count - 1);
  191. }
  192. }
  193. private void OnSaveRecipe()
  194. {
  195. if (WPFMessageBox.ShowQuestion($"Save recipe file?", "") == MessageBoxResult.Yes)
  196. {
  197. var inUseRecipe = QueryDataClient.Instance.Service.GetData($"Scheduler.InUsingRecipe");
  198. if (inUseRecipe != null)
  199. {
  200. if ((inUseRecipe as List<string>).Contains($"{ModuleName}.{CurrentRecipe.Header.Type}.{CurrentRecipeName}"))
  201. {
  202. WPFMessageBox.ShowError($"{CurrentRecipeName} Recipe is In Use,can not edit");
  203. return;
  204. }
  205. }
  206. }
  207. CurrentRecipe.Header.EditTime = DateTime.Now.ToString();
  208. //SaveRecipe(CurrentRecipeName, RecipeUnity.RecipeToString(CurrentRecipe));
  209. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, CurrentRecipeName + ".rcp");
  210. FileInfo fi = new FileInfo(newrecipePath);
  211. var di = fi.Directory;
  212. if (!di.Exists)
  213. {
  214. di.Create();
  215. }
  216. //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(CurrentRecipe),Encoding.UTF8);
  217. string recipeContent = RecipeUnity.RecipeToString(CurrentRecipe);
  218. SaveRecipe(CurrentRecipe.Header.Name, CurrentRecipe.Header.Type.ToString(), recipeContent);
  219. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  220. SaveEAPRecipe(recipeContent, CurrentRecipe.Steps);
  221. }
  222. private void SaveEAPRecipe(string recipeContent, ObservableCollection<RecipeStep> Steps)
  223. {
  224. if (currentChamber == JetChamber.Kepler2200A || currentChamber == JetChamber.Kepler2200B)
  225. {
  226. var newrecipePath2 = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{typeFolder}_EAP", CurrentRecipeName + ".rcp");
  227. FileInfo fi2 = new FileInfo(newrecipePath2);
  228. var di2 = fi2.Directory;
  229. if (!di2.Exists)
  230. {
  231. di2.Create();
  232. }
  233. var newContent = Recipe.ShowEAPRecipe(recipeContent, CurrentRecipe.Steps);
  234. File.WriteAllText(newrecipePath2, newContent, Encoding.UTF8);
  235. }
  236. }
  237. private void OnSaveToRecipe(object obj)
  238. {
  239. if (CurrentRecipe == null)
  240. {
  241. return;
  242. }
  243. string moduleName = "";
  244. switch (obj.ToString())
  245. {
  246. case "0":
  247. moduleName = "PMA";
  248. break;
  249. case "1":
  250. moduleName = "PMB";
  251. break;
  252. case "2":
  253. moduleName = "PMC";
  254. break;
  255. case "3":
  256. moduleName = "PMD";
  257. break;
  258. case "4":
  259. moduleName = "ALL";
  260. break;
  261. }
  262. if (moduleName == "")
  263. {
  264. return;
  265. }
  266. if (moduleName == "ALL")
  267. {
  268. var newName = Interaction.InputBox(" ", $"Save Recipe To All", CurrentRecipeName, -1, -1);
  269. OnSaveRecipe();
  270. foreach (var x in moduleList)
  271. {
  272. if (newName != "")
  273. {
  274. var targetChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{x}.ChamberType").ToString());
  275. if (currentChamber != targetChamber || x == ModuleName)
  276. {
  277. continue;
  278. }
  279. var newRecipe = CurrentRecipe;
  280. newRecipe.Header.Name = newName;
  281. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  282. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", x, typeFolder, newName + ".rcp");
  283. FileInfo fi = new FileInfo(newrecipePath);
  284. var di = fi.Directory;
  285. if (!di.Exists)
  286. {
  287. di.Create();
  288. }
  289. //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  290. if (m_uiRecipeManager.SaveAsRecipeWithType(x, CurrentRecipe.Header.Type.ToString(), newName, RecipeUnity.RecipeToString(newRecipe)))
  291. {
  292. UpdateRecipeFileList();
  293. }
  294. UpdateRecipeFileList();
  295. }
  296. }
  297. }
  298. else
  299. {
  300. var targetChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{moduleName}.ChamberType").ToString());
  301. if (currentChamber != targetChamber)
  302. {
  303. WPFMessageBox.ShowError($"Recipe can not from {currentChamber.ToString()} copy to {targetChamber.ToString()}");
  304. return;
  305. }
  306. var newName = Interaction.InputBox(" ", $"Save Recipe To {moduleName}", CurrentRecipeName, -1, -1);
  307. if (newName != "")
  308. {
  309. OnSaveRecipe();
  310. var newRecipe = CurrentRecipe;
  311. newRecipe.Header.Name = newName;
  312. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  313. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", moduleName, typeFolder, newName + ".rcp");
  314. FileInfo fi = new FileInfo(newrecipePath);
  315. var di = fi.Directory;
  316. if (!di.Exists)
  317. {
  318. di.Create();
  319. }
  320. //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  321. if (m_uiRecipeManager.SaveAsRecipeWithType(moduleName, CurrentRecipe.Header.Type.ToString(), newName, RecipeUnity.RecipeToString(newRecipe)))
  322. {
  323. UpdateRecipeFileList();
  324. }
  325. //if (SaveAsRecipeWithType(newName, CurrentRecipe.Header.Type.ToString(), RecipeUnity.RecipeToString(newRecipe)))
  326. //{
  327. //}
  328. }
  329. }
  330. }
  331. private async void OnLoaded(Object myrecipeView)
  332. {
  333. if (firstLoad == true)
  334. {
  335. currentChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.ChamberType").ToString());
  336. if (currentChamber != JetChamber.Kepler2200A && currentChamber != JetChamber.Kepler2200B)
  337. {
  338. isInstalledEPD = bool.Parse(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.IsEnabled").ToString());
  339. }
  340. firstLoad = false;
  341. recipeView = myrecipeView as RecipeView;
  342. treeViewRcpList = recipeView.treeViewRcpList;
  343. headWrapPanel = recipeView.headWrapPanel;
  344. bodyStackPanel = recipeView.bodyStackPanel;
  345. UpdateRecipeFileList();
  346. treeViewRcpList.SelectedItemChanged += TreeViewRcpList_SelectedItemChanged;
  347. if (isInstalledEPD)
  348. {
  349. for (int i = 0; i < 5; i++)
  350. {
  351. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.EndPoint.SearchCfg");
  352. await Task.Delay(200);
  353. currentEPDType = (EPDType)System.Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.EPDType"));
  354. if (currentEPDType == EPDType.Socket)
  355. {
  356. EPDCfgList = (List<string>)QueryDataClient.Instance.Service.GetData($"{ModuleName}.EPDCfgList");
  357. }
  358. if (EPDCfgList != null)
  359. {
  360. EPDCfgList.Add("");
  361. break;
  362. }
  363. }
  364. }
  365. string allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString();
  366. if (allModules.Contains("PMA"))
  367. {
  368. PMAIsInstalled = true;
  369. moduleList.Add("PMA");
  370. }
  371. if (allModules.Contains("PMB"))
  372. {
  373. PMBIsInstalled = true;
  374. moduleList.Add("PMB");
  375. }
  376. if (allModules.Contains("PMC"))
  377. {
  378. PMCIsInstalled = true;
  379. moduleList.Add("PMC");
  380. }
  381. if (allModules.Contains("PMD"))
  382. {
  383. PMDIsInstalled = true;
  384. moduleList.Add("PMD");
  385. }
  386. }
  387. UpdateRecipeFileList();
  388. }
  389. private void TreeViewRcpList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  390. {
  391. selectedItem = e.NewValue as TreeViewFileItem;
  392. if (selectedItem == null)
  393. return;
  394. try
  395. {
  396. string[] info = selectedItem.FileName.Split('\\');
  397. //string path;
  398. string xmlRecipeData = "";
  399. if (info.Length == 1)
  400. {
  401. CurrentRecipeName = info[0];
  402. typeFolder = "";
  403. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{CurrentRecipeName}.rcp");
  404. xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  405. }
  406. else if (info.Length == 2)
  407. {
  408. string type = info[0];
  409. typeFolder = type;
  410. CurrentRecipeName = info[1];
  411. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, type, $"{CurrentRecipeName}.rcp");
  412. xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  413. }
  414. else
  415. {
  416. return;
  417. }
  418. if (xmlRecipeData == "")
  419. {
  420. treeViewRcpList.Items.Remove(selectedItem);
  421. return;
  422. }
  423. CurrentRecipe = Recipe.Load(xmlRecipeData);
  424. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  425. LoadRecipe(CurrentRecipe);
  426. }
  427. catch (Exception ex)
  428. {
  429. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  430. }
  431. e.Handled = true;
  432. }
  433. public bool SaveRecipe(string recipeName, string recipeContent)
  434. {
  435. return m_uiRecipeManager.SaveRecipe(ModuleName, recipeName, recipeContent);
  436. }
  437. public bool SaveRecipe(string recipeName,string type, string recipeContent)
  438. {
  439. return m_uiRecipeManager.SaveRecipeWithType(ModuleName,type, recipeName, recipeContent);
  440. }
  441. private void OnMouseRightButtonDown(Object treeView)
  442. {
  443. //treeViewRcpList = treeView as TreeView;
  444. treeViewRcpList.ContextMenu = new ContextMenu() { Background = new SolidColorBrush(Colors.AliceBlue) };
  445. MenuItem menuItem = new MenuItem();
  446. menuItem = new MenuItem();
  447. menuItem.Tag = "\\";
  448. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateRecipe);
  449. menuItem.Header = "New Recipe";
  450. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  451. menuItem = new MenuItem();
  452. menuItem.Tag = "\\";
  453. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_DeleteRecipe);
  454. menuItem.Header = "Delete Recipe";
  455. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  456. menuItem = new MenuItem();
  457. menuItem.Tag = "\\";
  458. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_SaveAsRecipe);
  459. menuItem.Header = "Save As Recipe";
  460. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  461. menuItem = new MenuItem();
  462. menuItem.Tag = "\\";
  463. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_RenameRecipe);
  464. menuItem.Header = "Rename";
  465. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  466. treeViewRcpList.ContextMenu.Visibility = Visibility.Visible;
  467. }
  468. private void OnMouseLeftButtonDown(Object treeView)
  469. {
  470. //treeViewRcpList = treeView as TreeView;
  471. }
  472. private void menuItem_MouseClick_CreateRecipe(object sender, RoutedEventArgs e)
  473. {
  474. MenuItem mit = sender as MenuItem;
  475. string folderName = mit.Tag as string;
  476. PerformCreateRecipe(folderName);
  477. }
  478. private void PerformCreateRecipe(string folderName)
  479. {
  480. try
  481. {
  482. bool hasHV = false;
  483. if (currentChamber == JetChamber.VenusSE || currentChamber == JetChamber.VenusDE)
  484. {
  485. hasHV = true;
  486. }
  487. RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString(), hasHV)
  488. {
  489. Owner = Application.Current.MainWindow
  490. };
  491. if (dlg.ShowDialog() == true)
  492. {
  493. var recipeName = dlg.InputText;
  494. //var recipeName = folderName + dlg.InputText;
  495. //var recipeName = folderName + "\\" + dlg.InputText;
  496. RecipeType type = (RecipeType)Enum.Parse(typeof(RecipeType), dlg.SelectedType);
  497. string newRecipe = RecipeUnity.CreateRecipe(currentChamber, type, dlg.InputText);
  498. if (SaveAsRecipeWithType(recipeName, type.ToString(), newRecipe))
  499. {
  500. UpdateRecipeFileList();
  501. }
  502. }
  503. }
  504. catch (Exception ex)
  505. {
  506. LOG.WriteExeption(ex);
  507. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  508. }
  509. }
  510. private void menuItem_MouseClick_DeleteRecipe(object sender, RoutedEventArgs e)
  511. {
  512. if (CurrentRecipe == null)
  513. {
  514. return;
  515. }
  516. if (WPFMessageBox.ShowQuestion($"Delete {typeFolder}Recipe {CurrentRecipeName}?", "删除后无法恢复!!!") == MessageBoxResult.Yes)
  517. {
  518. MenuItem mit = sender as MenuItem;
  519. //string recipename = mit.Header.ToString();
  520. string path = typeFolder == "" ? CurrentRecipeName : $"{typeFolder}\\{CurrentRecipeName}";
  521. m_uiRecipeManager.DeleteRecipe(ModuleName, path);
  522. //PerformCreateRecipe(folderName);
  523. //treeViewRcpList.Items.Remove(selectedItem);
  524. UpdateRecipeFileList();
  525. }
  526. }
  527. private void menuItem_MouseClick_SaveAsRecipe(object sender, RoutedEventArgs e)
  528. {
  529. if (CurrentRecipe == null)
  530. {
  531. return;
  532. }
  533. var newName = Interaction.InputBox(" ", "Save As Recipe", CurrentRecipeName, -1, -1);
  534. newName=newName.Trim();
  535. if (newName != CurrentRecipeName && newName != "")
  536. {
  537. var newRecipe = CurrentRecipe;
  538. if (WPFMessageBox.ShowQuestion($"Save recipe file {newName} ?", "") == MessageBoxResult.Yes)
  539. {
  540. MessageBox.Show($"Save as recipe {newName} ?", "Save As Recipe", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  541. newRecipe.Header.Name = newName;
  542. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  543. //var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, newName + ".rcp");
  544. //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  545. if (SaveAsRecipeWithType(newName, CurrentRecipe.Header.Type.ToString(), RecipeUnity.RecipeToString(newRecipe)))
  546. {
  547. UpdateRecipeFileList();
  548. CurrentRecipeName = newName;
  549. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  550. LoadRecipe(CurrentRecipe);
  551. }
  552. }
  553. }
  554. else if (newName == CurrentRecipeName || newName == "")
  555. {
  556. WPFMessageBox.Show("Please input right recipename", MessageBoxButton.OK);
  557. }
  558. }
  559. private void menuItem_MouseClick_RenameRecipe(object sender, RoutedEventArgs e)
  560. {
  561. if (CurrentRecipe == null)
  562. {
  563. return;
  564. }
  565. var newName = Interaction.InputBox(" ", "Rename Recipe", CurrentRecipeName, -1, -1);
  566. newName = newName.Trim();
  567. if (newName != CurrentRecipeName && newName != "")
  568. {
  569. var newRecipe = CurrentRecipe;
  570. if (WPFMessageBox.ShowQuestion($"Save recipe file {newName} ?", "") == MessageBoxResult.Yes)
  571. {
  572. newRecipe.Header.Name = newName;
  573. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  574. var oldrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, CurrentRecipeName + ".rcp");
  575. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, newName + ".rcp");
  576. File.Delete(oldrecipePath);
  577. File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  578. UpdateRecipeFileList();
  579. }
  580. }
  581. else if(newName == CurrentRecipeName|| newName=="")
  582. {
  583. WPFMessageBox.Show("Please input right recipename",MessageBoxButton.OK);
  584. }
  585. }
  586. public bool SaveAsRecipe(string recipeName, string recipeContent)
  587. {
  588. return m_uiRecipeManager.SaveAsRecipe(ModuleName, recipeName, recipeContent);
  589. }
  590. public bool SaveAsRecipeWithType(string recipeName, string type, string recipeContent)
  591. {
  592. return m_uiRecipeManager.SaveAsRecipeWithType(ModuleName, type, recipeName, recipeContent);
  593. }
  594. public string GetXmlRecipeList()
  595. {
  596. return m_uiRecipeManager.GetXmlRecipeList(ModuleName, true) ?? "";
  597. }
  598. void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
  599. {
  600. foreach (XmlElement ele in curElementNode.ChildNodes)
  601. {
  602. if (ele.Name == "File")
  603. {
  604. string fileName = ele.Attributes["Name"].Value;
  605. fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
  606. TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
  607. item.Tag = ele.Attributes["Name"].Value;
  608. if (!item.Tag.ToString().Contains("\\"))
  609. {
  610. continue;
  611. }
  612. itemsControl.Items.Add(item);
  613. }
  614. else if (ele.Name == "Folder")
  615. {
  616. string folderName = ele.Attributes["Name"].Value;
  617. folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
  618. if (folderName == Venus_Core.RecipeType.Process.ToString() || folderName == Venus_Core.RecipeType.Clean.ToString() || folderName == Venus_Core.RecipeType.Chuck.ToString() || folderName == Venus_Core.RecipeType.DeChuck.ToString())
  619. {
  620. TreeViewFolderItem item = new TreeViewFolderItem(folderName);
  621. item.Tag = ele.Attributes["Name"].Value;
  622. CreateTreeViewItems(ele, item);
  623. item.IsExpanded = false;
  624. itemsControl.Items.Add(item);
  625. }
  626. }
  627. }
  628. }
  629. private IEnumerable<string> GetFilesNames(string path)
  630. {
  631. if (Directory.Exists(path))
  632. {
  633. return Directory.GetFiles(path, "*.rcp")?
  634. .Select(Path.GetFileNameWithoutExtension);
  635. }
  636. else
  637. {
  638. return new List<string>();
  639. }
  640. }
  641. private void LoadHeadWrapPanel(WrapPanel HeadWrapPanel, Recipe recipe)
  642. {
  643. HeadWrapPanel.Children.Clear();
  644. Type type = recipe.Header.GetType();
  645. foreach (var propertyInfo in type.GetProperties())
  646. {
  647. TextBlock textBlock = new TextBlock();
  648. textBlock.FontSize = 16;
  649. textBlock.Margin=new Thickness(0,20,0,0);
  650. textBlock.Width = 200;
  651. switch (propertyInfo.Name)
  652. {
  653. case "ChuckRecipe":
  654. if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE)
  655. {
  656. continue;
  657. }
  658. textBlock.Text = "Chuck:";
  659. break;
  660. case "DechuckRecipe":
  661. if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE)
  662. {
  663. continue;
  664. }
  665. textBlock.Text = "DeChuck:";
  666. break;
  667. default:
  668. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  669. string name;
  670. if (NameAttrs.Length > 0)
  671. {
  672. name = (NameAttrs[0] as CustomName).Name;
  673. }
  674. else
  675. {
  676. name = propertyInfo.Name;
  677. }
  678. textBlock.Text = name + ":";
  679. break;
  680. }
  681. textBlock.Margin = new Thickness(15, 0, 0, 0);
  682. textBlock.VerticalAlignment = VerticalAlignment.Center;
  683. HeadWrapPanel.Children.Add(textBlock);
  684. Binding binding = new Binding()
  685. {
  686. Source = recipe.Header, // 数据源
  687. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  688. Mode = BindingMode.TwoWay, // 绑定模式
  689. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, //触发器
  690. };
  691. var propertyTypeName = propertyInfo.PropertyType.Name;
  692. var propertyInfoName = propertyInfo.Name;
  693. Control control = new Control();
  694. switch (propertyInfoName)
  695. {
  696. case "ChamberType":
  697. control = new ComboBox();
  698. control.IsEnabled = false;
  699. //control.Height = 23;
  700. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  701. ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  702. break;
  703. case "Type":
  704. ComboBox cb = new ComboBox();
  705. cb.IsEnabled = false;
  706. cb.SelectionChanged += ChangeUI;
  707. control = cb;
  708. //control.Height = 23;
  709. ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  710. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  711. break;
  712. case "ChuckRecipe":
  713. //if (currentChamber != JetChamber.Venus)
  714. //{
  715. // continue;
  716. //}
  717. //string[] chucklist = new string[] { "" };
  718. //ArrayList arrayList = new ArrayList(chucklist.ToList());
  719. //IEnumerable<string> chlist= GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName)).ToList().Where(item => item.ToLower().Contains("chuck") && (item.ToLower().Contains("dechuck") == false));
  720. //foreach (var i in chlist)
  721. //{
  722. // arrayList.Add(i);
  723. //}
  724. //chucklist = (string[])arrayList.ToArray(typeof(string));
  725. StringBuilder stringBuilder = new StringBuilder();
  726. //输出
  727. //for (int i = 0; i < chucklist.Length; i++)
  728. //{
  729. // stringBuilder.Append(chucklist[i] + "\t");
  730. //}
  731. control = new ComboBox()
  732. {
  733. ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck"))
  734. };
  735. //control.Height = 23;
  736. control.MinWidth = 100;
  737. control.MaxWidth = 300;
  738. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  739. control.PreviewMouseLeftButtonDown += ChuckControl_PreviewMouseLeftButtonDown;
  740. break;
  741. case "DechuckRecipe":
  742. //if (currentChamber != JetChamber.Venus)
  743. //{
  744. // continue;
  745. //}
  746. //string[] dechucklist = new string[] { "" };
  747. //ArrayList dearrayList = new ArrayList(dechucklist.ToList());
  748. //IEnumerable<string> delist = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName)).ToList().Where(item => item.ToLower().Contains("dechuck"));
  749. //foreach (var i in delist)
  750. //{
  751. // dearrayList.Add(i);
  752. //}
  753. //dechucklist = (string[])dearrayList.ToArray(typeof(string));
  754. //StringBuilder destringBuilder = new StringBuilder();
  755. //for (int i = 0; i < dechucklist.Length; i++)
  756. //{
  757. // destringBuilder.Append(dechucklist[i] + "\t");
  758. //}
  759. control = new ComboBox()
  760. {
  761. ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck"))
  762. };
  763. //control.Height = 23;
  764. control.MinWidth = 100;
  765. control.MaxWidth = 300;
  766. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  767. control.PreviewMouseLeftButtonDown += DechuckControl_PreviewMouseLeftButtonDown;
  768. break;
  769. case "IsShowTolerance":
  770. control = new CheckBox();
  771. control.SetBinding(CheckBox.IsCheckedProperty, binding);
  772. control.Style = null;
  773. control.VerticalAlignment = VerticalAlignment.Center;
  774. (control as CheckBox).Checked += RecipeViewModel_Checked;
  775. (control as CheckBox).Unchecked += RecipeViewModel_Checked;
  776. break;
  777. default:
  778. control = new TextBox();
  779. control.Margin = new Thickness(1, 0, 0, 0);
  780. control.BorderThickness = new Thickness(0, 0, 0, 1);
  781. control.BorderBrush = Brushes.White;
  782. control.FontSize = 15;
  783. control.Foreground = Brushes.Green;
  784. control.Background = Brushes.Transparent;
  785. control.VerticalAlignment = VerticalAlignment.Center;
  786. control.MinWidth = 15;
  787. control.SetBinding(TextBox.TextProperty, binding);
  788. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  789. if (objAttrs.Length > 0)
  790. {
  791. (control as TextBox).IsReadOnly = true;
  792. }
  793. break;
  794. }
  795. //switch (propertyTypeName)
  796. //{
  797. // case "Int32":
  798. // case "String":
  799. // control = new TextBox();
  800. // control.Margin = new Thickness(1, 0, 0, 0);
  801. // control.BorderThickness = new Thickness(0, 0, 0, 1);
  802. // //control.BorderBrush = Brushes.Black;
  803. // control.FontSize = 15;
  804. // control.Foreground = Brushes.Green;
  805. // control.Background = Brushes.Transparent;
  806. // control.VerticalAlignment = VerticalAlignment.Center;
  807. // control.MinWidth = 15;
  808. // control.SetBinding(TextBox.TextProperty, binding);
  809. // object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  810. // if (objAttrs.Length > 0)
  811. // {
  812. // (control as TextBox).IsReadOnly = true;
  813. // }
  814. // break;
  815. // case "Boolean":
  816. // control = new CheckBox();
  817. // control.SetBinding(CheckBox.IsCheckedProperty, binding);
  818. // break;
  819. // default:
  820. // control = new ComboBox();
  821. // control.Height = 23;
  822. // control.SetBinding(ComboBox.SelectedItemProperty, binding);
  823. // ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  824. // break;
  825. //}
  826. control.Margin = new Thickness(20, 3, 0, 7);
  827. control.Width = 250;
  828. HeadWrapPanel.Children.Add(control);
  829. }
  830. }
  831. private void RecipeViewModel_Checked(object sender, RoutedEventArgs e)
  832. {
  833. bool? isTolerance = (sender as CheckBox).IsChecked;
  834. LoadRecipe(CurrentRecipe);
  835. }
  836. private void Control_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  837. {
  838. }
  839. private void ChuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  840. {
  841. var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck")).ToList();
  842. items.Add("");
  843. (sender as ComboBox).ItemsSource = items;
  844. }
  845. private void DechuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  846. {
  847. var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck")).ToList();
  848. items.Add("");
  849. (sender as ComboBox).ItemsSource = items;
  850. }
  851. private void ChangeUI(object sender, SelectionChangedEventArgs e)
  852. {
  853. var t = sender as ComboBox;
  854. if (t.SelectedValue.ToString() != "Process")
  855. {
  856. headWrapPanel.Children[8].Visibility = Visibility.Collapsed;
  857. headWrapPanel.Children[9].Visibility = Visibility.Collapsed;
  858. headWrapPanel.Children[10].Visibility = Visibility.Collapsed;
  859. headWrapPanel.Children[11].Visibility = Visibility.Collapsed;
  860. }
  861. else
  862. {
  863. headWrapPanel.Children[8].Visibility = Visibility.Visible;
  864. headWrapPanel.Children[9].Visibility = Visibility.Visible;
  865. headWrapPanel.Children[10].Visibility = Visibility.Visible;
  866. headWrapPanel.Children[11].Visibility = Visibility.Visible;
  867. }
  868. }
  869. private void MenuItemLeftInsert_Click(object sender, RoutedEventArgs e)
  870. {
  871. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  872. int insertIndex = Convert.ToInt32(t.Text);
  873. if (copyIndex == -1)
  874. {
  875. var recipeStep = new RecipeStep();
  876. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  877. CurrentRecipe.Steps.Insert(insertIndex - 1, recipeStep);
  878. }
  879. else
  880. {
  881. var t1 = JsonConvert.SerializeObject(CurrentRecipe);
  882. var recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
  883. CurrentRecipe.Steps.Insert(insertIndex - 1, recipeStep);
  884. }
  885. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  886. {
  887. CurrentRecipe.Steps[i].StepNo = i + 1;
  888. }
  889. LoadRecipe(CurrentRecipe);
  890. }
  891. private void MenuItemRightInsert_Click(object sender, RoutedEventArgs e)
  892. {
  893. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  894. int insertIndex = Convert.ToInt32(t.Text);
  895. if (copyIndex == -1)
  896. {
  897. var recipeStep = new RecipeStep();
  898. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  899. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  900. }
  901. else
  902. {
  903. var t1 = JsonConvert.SerializeObject(CurrentRecipe);
  904. var recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
  905. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  906. }
  907. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  908. {
  909. CurrentRecipe.Steps[i].StepNo = i + 1;
  910. }
  911. LoadRecipe(CurrentRecipe);
  912. }
  913. private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
  914. {
  915. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  916. int deleteIndex = Convert.ToInt32(t.Text);
  917. //OnDeleteStep(deleteIndex - 1);
  918. CurrentRecipe.Steps.RemoveAt(deleteIndex - 1);
  919. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  920. {
  921. CurrentRecipe.Steps[i].StepNo = i + 1;
  922. }
  923. LoadRecipe(CurrentRecipe);
  924. }
  925. private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
  926. {
  927. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  928. copyIndex = Convert.ToInt32(t.Text);
  929. }
  930. #endregion
  931. #region 私有方法
  932. private void RecipeStepToGridColumn(RecipeStep recipeStep, Grid grid, int index, bool isInsert)
  933. {
  934. int location = 1;
  935. if (isInsert == true)
  936. {
  937. location -= 1;
  938. }
  939. Type recipeType = recipeStep.GetType();
  940. int cycleCount = 1;
  941. if (index == 0)
  942. {
  943. cycleCount = 2;
  944. }
  945. for (int j = 0; j < cycleCount; j++)
  946. {
  947. int i = 0;
  948. ColumnDefinition col1 = new ColumnDefinition();
  949. //col1.MinWidth = 50;
  950. grid.ColumnDefinitions.Insert(index, col1);
  951. //Binding stepcheckbinding = null;
  952. //grid.MinWidth = 200;
  953. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  954. {
  955. string propertyInfoName = propertyInfo.Name;
  956. string propertyTypeName = propertyInfo.PropertyType.Name;
  957. if (propertyInfoName != "LstUnit")
  958. {
  959. if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime" || propertyInfoName == "OverEtchPercent") && isInstalledEPD == false)
  960. {
  961. continue;
  962. }
  963. if (index == 0 && grid.ColumnDefinitions.Count == 1)
  964. {
  965. RowDefinition row1 = new RowDefinition();
  966. grid.RowDefinitions.Add(row1);
  967. }
  968. if (grid.ColumnDefinitions.Count == 1 && j == 0)
  969. {
  970. TextBox textBlock = new TextBox();
  971. textBlock.IsReadOnly = true;
  972. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  973. string name;
  974. if (NameAttrs.Length > 0)
  975. {
  976. name = (NameAttrs[0] as CustomName).Name;
  977. }
  978. else
  979. {
  980. name = propertyInfo.Name;
  981. }
  982. textBlock.Text = name;
  983. grid.Children.Add(textBlock);
  984. textBlock.Background = new SolidColorBrush(Colors.BurlyWood);
  985. Grid.SetRow(textBlock, i);
  986. Grid.SetColumn(textBlock, 0);
  987. }
  988. else
  989. {
  990. Binding binding = new Binding()
  991. {
  992. Source = recipeStep, // 数据源
  993. Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
  994. Mode = BindingMode.TwoWay, // 绑定模式
  995. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  996. };
  997. switch (propertyTypeName)
  998. {
  999. case "Int32":
  1000. case "String":
  1001. case "Single":
  1002. case "Double":
  1003. if (propertyInfoName == "EPDConfig")
  1004. {
  1005. if (currentEPDType == EPDType.Socket)
  1006. {
  1007. ComboBox EPDcomboBox = new ComboBox();
  1008. EPDcomboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  1009. EPDcomboBox.Background = new SolidColorBrush(Colors.Black);
  1010. EPDcomboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  1011. EPDcomboBox.ItemsSource = EPDCfgList;
  1012. grid.Children.Add(EPDcomboBox);
  1013. Grid.SetRow(EPDcomboBox, i);
  1014. Grid.SetColumn(EPDcomboBox, index + location);
  1015. //EPDcomboBox.DropDownOpened += EPDcomboBox_DropDownOpened;
  1016. }
  1017. else if (currentEPDType == EPDType.WCF)
  1018. {
  1019. Button EPDButton = new Button();
  1020. EPDButton.Content = "EndPoint";
  1021. EPDButton.Cursor = Cursors.Hand;
  1022. EPDButton.Tag = $"{CurrentRecipeName}.{(index + location).ToString()}";
  1023. EPDButton.Style = null;
  1024. EPDButton.Click += EPDButton_Click;
  1025. grid.Children.Add(EPDButton);
  1026. Grid.SetRow(EPDButton, i);
  1027. Grid.SetColumn(EPDButton, index + location);
  1028. }
  1029. break;
  1030. }
  1031. TextBox textBox = new TextBox();
  1032. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  1033. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  1034. textBox.SetBinding(TextBox.TextProperty, binding);
  1035. grid.Children.Add(textBox);
  1036. Grid.SetRow(textBox, i);
  1037. Grid.SetColumn(textBox, index + location);
  1038. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  1039. if (objAttrs.Length > 0)
  1040. {
  1041. textBox.IsReadOnly = true;
  1042. ContextMenu contextmenu = new ContextMenu();
  1043. textBox.ContextMenu = contextmenu;
  1044. MenuItem menuItemDelete = new MenuItem();
  1045. menuItemDelete.Header = "Delete";
  1046. menuItemDelete.Click += MenuItemDelete_Click;
  1047. MenuItem menuItemLeftInsert = new MenuItem();
  1048. menuItemLeftInsert.Header = "Left Insert";
  1049. menuItemLeftInsert.Click += MenuItemLeftInsert_Click;
  1050. MenuItem menuItemRightInsert = new MenuItem();
  1051. menuItemRightInsert.Header = "Right Insert";
  1052. menuItemRightInsert.Click += MenuItemRightInsert_Click;
  1053. MenuItem menuItemCopy = new MenuItem();
  1054. menuItemCopy.Tag = textBox.Text;
  1055. menuItemCopy.Header = "Copy";
  1056. menuItemCopy.Click += MenuItemCopy_Click;
  1057. contextmenu.Items.Add(menuItemCopy);
  1058. contextmenu.Items.Add(menuItemDelete);
  1059. contextmenu.Items.Add(menuItemLeftInsert);
  1060. contextmenu.Items.Add(menuItemRightInsert);
  1061. }
  1062. break;
  1063. case "Boolean":
  1064. CheckBox checkBox = new CheckBox();
  1065. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  1066. grid.Children.Add(checkBox);
  1067. Grid.SetRow(checkBox, i);
  1068. Grid.SetColumn(checkBox, index + location);
  1069. break;
  1070. default:
  1071. ComboBox comboBox = new ComboBox();
  1072. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  1073. //comboBox.BorderThickness = new Thickness(1, 0, 1, 0);
  1074. comboBox.Background = new SolidColorBrush(Colors.Black);
  1075. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  1076. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  1077. grid.Children.Add(comboBox);
  1078. Grid.SetRow(comboBox, i);
  1079. Grid.SetColumn(comboBox, index + location);
  1080. break;
  1081. }
  1082. }
  1083. i++;
  1084. }
  1085. }
  1086. int k = 0;
  1087. foreach (var x in recipeStep.LstUnit.ToList())
  1088. {
  1089. Type unitType = x.GetType();
  1090. //bool isIgnore = false;
  1091. Binding checkbinding = null;
  1092. foreach (PropertyInfo propertyInfo in unitType.GetProperties())
  1093. {
  1094. object[] IgnoreAttrs = propertyInfo.GetCustomAttributes(typeof(IsCanConfigIgnore), true);
  1095. bool IsEnableRecipeExtension = Convert.ToBoolean(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.IsEnableRecipeExtension"));
  1096. if (IgnoreAttrs.Length > 0 && IsEnableRecipeExtension == false)
  1097. {
  1098. break;
  1099. }
  1100. object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
  1101. if (toleranceAttrs.Length > 0 && CurrentRecipe.Header.IsShowTolerance==false)
  1102. {
  1103. continue;
  1104. }
  1105. if (index == 0 && grid.ColumnDefinitions.Count == 1)
  1106. {
  1107. RowDefinition row1 = new RowDefinition();
  1108. grid.RowDefinitions.Add(row1);
  1109. }
  1110. if (grid.ColumnDefinitions.Count == 1 && j == 0)
  1111. {
  1112. TextBox textBlock = new TextBox();
  1113. textBlock.IsReadOnly = true;
  1114. switch (propertyInfo.Name)
  1115. {
  1116. case "Gas1":
  1117. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  1118. textBlock.Text = $"{propertyInfo.Name}({data1.DisplayName},{data1.Scale})";
  1119. break;
  1120. case "Gas2":
  1121. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  1122. textBlock.Text = $"{propertyInfo.Name}({data2.DisplayName},{data2.Scale})";
  1123. break;
  1124. case "Gas3":
  1125. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  1126. textBlock.Text = $"{propertyInfo.Name}({data3.DisplayName},{data3.Scale})";
  1127. break;
  1128. case "Gas4":
  1129. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  1130. textBlock.Text = $"{propertyInfo.Name}({data4.DisplayName},{data4.Scale})";
  1131. break;
  1132. case "Gas5":
  1133. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  1134. textBlock.Text = $"{propertyInfo.Name}({data5.DisplayName},{data5.Scale})";
  1135. break;
  1136. case "Gas6":
  1137. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  1138. textBlock.Text = $"{propertyInfo.Name}({data6.DisplayName},{data6.Scale})";
  1139. break;
  1140. case "Gas7":
  1141. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  1142. textBlock.Text = $"{propertyInfo.Name}({data7.DisplayName},{data7.Scale})";
  1143. break;
  1144. case "Gas8":
  1145. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  1146. textBlock.Text = $"{propertyInfo.Name}({data8.DisplayName},{data8.Scale})";
  1147. break;
  1148. case "Gas9":
  1149. var data9 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas9");
  1150. textBlock.Text = $"{propertyInfo.Name}({data9.DisplayName},{data9.Scale})";
  1151. break;
  1152. case "Gas10":
  1153. var data10 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas10");
  1154. textBlock.Text = $"{propertyInfo.Name}({data10.DisplayName},{data10.Scale})";
  1155. break;
  1156. case "Gas11":
  1157. var data11 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas11");
  1158. textBlock.Text = $"{propertyInfo.Name}({data11.DisplayName},{data11.Scale})";
  1159. break;
  1160. case "Gas12":
  1161. var data12 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas12");
  1162. textBlock.Text = $"{propertyInfo.Name}({data12.DisplayName},{data12.Scale})";
  1163. break;
  1164. //case "HeaterPressure":
  1165. // textBlock.Text = "Pressure(Pa)";
  1166. // break;
  1167. //case "HeaterTemp":
  1168. // textBlock.Text = "Heater Temp(℃)";
  1169. // break;
  1170. //case "HeaterRatio":
  1171. // textBlock.Text = "Heater Ratio";
  1172. // break;
  1173. default:
  1174. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  1175. string name;
  1176. if (NameAttrs.Length > 0)
  1177. {
  1178. name = (NameAttrs[0] as CustomName).Name;
  1179. }
  1180. else
  1181. {
  1182. name = propertyInfo.Name;
  1183. }
  1184. textBlock.Text = name;
  1185. break;
  1186. }
  1187. textBlock.Background = solidColorBrushes[k % solidColorBrushes.Count];
  1188. grid.Children.Add(textBlock);
  1189. Grid.SetRow(textBlock, i);
  1190. Grid.SetColumn(textBlock, 0);
  1191. }
  1192. else
  1193. {
  1194. Binding binding = new Binding()
  1195. {
  1196. Source = recipeStep.LstUnit[k], // 数据源
  1197. //Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
  1198. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  1199. Mode = BindingMode.TwoWay, // 绑定模式
  1200. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  1201. };
  1202. var item = propertyInfo.PropertyType.Name;
  1203. if (propertyInfo.Name == "UnitName")
  1204. {
  1205. TextBox textBlock1 = new TextBox();
  1206. textBlock1.HorizontalContentAlignment = HorizontalAlignment.Center;
  1207. textBlock1.VerticalContentAlignment = VerticalAlignment.Center;
  1208. textBlock1.Text = propertyInfo.GetValue(x).ToString();
  1209. textBlock1.IsReadOnly = true;
  1210. grid.Children.Add(textBlock1);
  1211. Grid.SetRow(textBlock1, i);
  1212. Grid.SetColumn(textBlock1, index + location);
  1213. }
  1214. else
  1215. {
  1216. switch (item)
  1217. {
  1218. case "Int32":
  1219. case "String":
  1220. case "Single":
  1221. case "Double":
  1222. //if (checkbinding != null)
  1223. //{
  1224. // break;
  1225. //}
  1226. TextBox textBox = new TextBox();
  1227. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  1228. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  1229. if (checkbinding == null)
  1230. {
  1231. textBox.IsEnabled = true;
  1232. }
  1233. else
  1234. {
  1235. textBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  1236. }
  1237. //switch (propertyInfo.Name)
  1238. //{
  1239. // case "Gas1":
  1240. // var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  1241. // TextBoxMaxValue.SetMaxValue(textBox, (int)data1.Scale);
  1242. // break;
  1243. // case "Gas2":
  1244. // var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  1245. // TextBoxMaxValue.SetMaxValue(textBox, (int)data2.Scale);
  1246. // break;
  1247. // case "Gas3":
  1248. // var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  1249. // TextBoxMaxValue.SetMaxValue(textBox, (int)data3.Scale);
  1250. // break;
  1251. // case "Gas4":
  1252. // var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  1253. // TextBoxMaxValue.SetMaxValue(textBox, (int)data4.Scale);
  1254. // break;
  1255. // case "Gas5":
  1256. // var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  1257. // TextBoxMaxValue.SetMaxValue(textBox, (int)data5.Scale);
  1258. // break;
  1259. // case "Gas6":
  1260. // var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  1261. // TextBoxMaxValue.SetMaxValue(textBox, (int)data6.Scale);
  1262. // break;
  1263. // case "Gas7":
  1264. // var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  1265. // TextBoxMaxValue.SetMaxValue(textBox, (int)data7.Scale);
  1266. // break;
  1267. // case "Gas8":
  1268. // var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  1269. // TextBoxMaxValue.SetMaxValue(textBox, (int)data8.Scale);
  1270. // break;
  1271. // case "Gas9":
  1272. // var data9 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas9");
  1273. // TextBoxMaxValue.SetMaxValue(textBox, (int)data9.Scale);
  1274. // break;
  1275. // case "Gas10":
  1276. // var data10 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas10");
  1277. // TextBoxMaxValue.SetMaxValue(textBox, (int)data10.Scale);
  1278. // break;
  1279. // case "Gas11":
  1280. // var data11 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas11");
  1281. // TextBoxMaxValue.SetMaxValue(textBox, (int)data11.Scale);
  1282. // break;
  1283. // case "Gas12":
  1284. // var data12 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas12");
  1285. // TextBoxMaxValue.SetMaxValue(textBox, (int)data12.Scale);
  1286. // break;
  1287. //}
  1288. textBox.SetBinding(TextBox.TextProperty, binding);
  1289. grid.Children.Add(textBox);
  1290. Grid.SetRow(textBox, i);
  1291. Grid.SetColumn(textBox, index + location);
  1292. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  1293. if (objAttrs.Length > 0)
  1294. {
  1295. textBox.IsReadOnly = true;
  1296. }
  1297. break;
  1298. case "Boolean":
  1299. CheckBox checkBox = new CheckBox();
  1300. if (checkbinding == null)
  1301. {
  1302. checkbinding = new Binding
  1303. {
  1304. Source = checkBox, // 数据源
  1305. Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
  1306. Mode = BindingMode.TwoWay, // 绑定模式
  1307. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  1308. };
  1309. }
  1310. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  1311. grid.Children.Add(checkBox);
  1312. Grid.SetRow(checkBox, i);
  1313. Grid.SetColumn(checkBox, index + location);
  1314. break;
  1315. default:
  1316. //if (checkbinding != null)
  1317. //{
  1318. // break;
  1319. //}
  1320. ComboBox comboBox = new ComboBox();
  1321. comboBox.BorderBrush = Brushes.Gray;
  1322. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  1323. //comboBox.BorderThickness =new Thickness(1,0,1,0);
  1324. if (checkbinding == null)
  1325. {
  1326. comboBox.IsEnabled = true;
  1327. }
  1328. else
  1329. {
  1330. comboBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  1331. }
  1332. comboBox.Background = Brushes.White;
  1333. string path = propertyInfo.Name;
  1334. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  1335. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  1336. grid.Children.Add(comboBox);
  1337. Grid.SetRow(comboBox, i);
  1338. Grid.SetColumn(comboBox, index + location);
  1339. break;
  1340. }
  1341. }
  1342. }
  1343. i++;
  1344. }
  1345. k++;
  1346. }
  1347. }
  1348. }
  1349. private void EPDButton_Click(object sender, RoutedEventArgs e)
  1350. {
  1351. Button button = sender as Button;
  1352. string para = button.Tag.ToString();
  1353. int stepno = Convert.ToInt32(para.Split('.')[1]) - 1;
  1354. var endpointconfigitem = new MECF.Framework.Common.CommonData.EndPointConfigItem();
  1355. if (CurrentRecipe.Steps[stepno].EPDConfig != null && CurrentRecipe.Steps[stepno].EPDConfig.Length > 20)
  1356. {
  1357. endpointconfigitem.SetValue(CurrentRecipe.Steps[stepno].EPDConfig);
  1358. }
  1359. (new EndPointDlg(para, endpointconfigitem, CurrentRecipe)).ShowDialog();
  1360. }
  1361. private void UpdateRecipeFileList()
  1362. {
  1363. XmlDocument doc = new XmlDocument();
  1364. doc.LoadXml(GetXmlRecipeList());
  1365. treeViewRcpList.Items.Clear();
  1366. CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
  1367. ExpandAllItems(this.treeViewRcpList);
  1368. }
  1369. private void LoadRecipe(Recipe recipe)
  1370. {
  1371. copyIndex = -1;
  1372. bodyStackPanel.Children.Clear();
  1373. //CurrentRecipe = null;
  1374. GC.Collect(); // This should pick up the control removed at a previous MouseDown
  1375. GC.WaitForPendingFinalizers(); // Doesn't help either
  1376. GC.Collect();
  1377. GC.WaitForPendingFinalizers(); // Doesn't help either
  1378. CurrentRecipe = recipe;
  1379. if (CurrentRecipe.Header.Type == Venus_Core.RecipeType.Process && CurrentRecipe.Header.ChuckRecipe != "" && CurrentRecipe.Header.ChuckRecipe != null)
  1380. {
  1381. Grid chuckGrid = new Grid();
  1382. chuckGrid.IsEnabled = false;
  1383. chuckGrid.Margin = new Thickness(15);
  1384. string chuckRecipeData = m_uiRecipeManager.LoadRecipe(ModuleName, $"Chuck\\{CurrentRecipe.Header.ChuckRecipe}");
  1385. if (chuckRecipeData == "")
  1386. {
  1387. return;
  1388. }
  1389. var chuckRecipe = Recipe.Load(chuckRecipeData);
  1390. for (int i = 0; i < chuckRecipe.Steps.Count; i++)
  1391. {
  1392. RecipeStepToGridColumn(chuckRecipe.Steps[i], chuckGrid, i, false);
  1393. }
  1394. bodyStackPanel.Children.Add(chuckGrid);
  1395. }
  1396. Grid proressGrid = new Grid();
  1397. proressGrid.Margin = new Thickness(15);
  1398. //index = 0;
  1399. for (int i = 0; i < recipe.Steps.Count; i++)
  1400. {
  1401. RecipeStepToGridColumn(recipe.Steps[i], proressGrid, i, false);
  1402. }
  1403. bodyStackPanel.Children.Add(proressGrid);
  1404. currentRecipeGrid = proressGrid;
  1405. if (CurrentRecipe.Header.Type == Venus_Core.RecipeType.Process && CurrentRecipe.Header.DechuckRecipe != "" && CurrentRecipe.Header.DechuckRecipe != null)
  1406. {
  1407. Grid deChuckGrid = new Grid();
  1408. deChuckGrid.IsEnabled = false;
  1409. deChuckGrid.Margin = new Thickness(15);
  1410. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, "DeChuck", $"{CurrentRecipe.Header.DechuckRecipe}.rcp");
  1411. string DechuckRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  1412. //index = 0;
  1413. var dechuckRecipe = Recipe.Load(DechuckRecipeData);
  1414. for (int i = 0; i < dechuckRecipe.Steps.Count; i++)
  1415. {
  1416. RecipeStepToGridColumn(dechuckRecipe.Steps[i], deChuckGrid, i, false);
  1417. }
  1418. bodyStackPanel.Children.Add(deChuckGrid);
  1419. }
  1420. string recipeContent = RecipeUnity.RecipeToString(CurrentRecipe);
  1421. SaveEAPRecipe(recipeContent, CurrentRecipe.Steps);
  1422. }
  1423. private void OnDeleteStep(int index)
  1424. {
  1425. if (CurrentRecipe != null && CurrentRecipe.Steps.Count > 1)
  1426. {
  1427. currentRecipeGrid.Children.RemoveRange(currentRecipeGrid.RowDefinitions.Count * (index + 1), currentRecipeGrid.RowDefinitions.Count);
  1428. currentRecipeGrid.ColumnDefinitions.RemoveAt(index);
  1429. for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
  1430. {
  1431. CurrentRecipe.Steps[i - 1].StepNo = i;
  1432. }
  1433. CurrentRecipe.Steps.RemoveAt(index);
  1434. }
  1435. }
  1436. private void OnRefresh()
  1437. {
  1438. if (CurrentRecipeName != "")
  1439. {
  1440. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, $"{CurrentRecipeName}.rcp");
  1441. string xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  1442. CurrentRecipe = Recipe.Load(xmlRecipeData);
  1443. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  1444. LoadRecipe(CurrentRecipe);
  1445. }
  1446. }
  1447. private void OnTolerance()
  1448. {
  1449. }
  1450. private void OnExpand()
  1451. {
  1452. HeadExpand = !HeadExpand;
  1453. if (HeadExpand)
  1454. {
  1455. recipeView.expandGrid.Width = 300;
  1456. }
  1457. else
  1458. {
  1459. recipeView.expandGrid.Width = 30;
  1460. }
  1461. }
  1462. private void OnUnload()
  1463. {
  1464. //if (CurrentRecipeName == null || CurrentRecipeName == "")
  1465. //{
  1466. // return;
  1467. //}
  1468. //if (WPFMessageBox.ShowQuestion($"Is Save Recipe {CurrentRecipeName}", "", false) == MessageBoxResult.Yes)
  1469. //{
  1470. // OnSaveRecipe();
  1471. //}
  1472. }
  1473. private void ExpandAllItems(ItemsControl control)
  1474. {
  1475. if (control == null)
  1476. {
  1477. return;
  1478. }
  1479. foreach (Object item in control.Items)
  1480. {
  1481. System.Windows.Controls.TreeViewItem treeItem = control.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
  1482. if (treeItem == null || !treeItem.HasItems)
  1483. {
  1484. continue;
  1485. }
  1486. treeItem.IsExpanded = true;
  1487. ExpandAllItems(treeItem as ItemsControl);
  1488. }
  1489. }
  1490. #endregion
  1491. }
  1492. }