RecipeViewModel.cs 74 KB

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