RecipeViewModel.cs 67 KB

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