RecipeViewModel.cs 74 KB

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