RecipeViewModel.cs 71 KB

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