RecipeViewModel.cs 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.UI.View.Common;
  4. //using MECF.Framework.Common.CommonData;
  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;
  13. using System.Collections.Generic;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Reflection;
  17. using System.Text;
  18. using System.Threading;
  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.Windows.Threading;
  25. using System.Xml;
  26. using Venus_Core;
  27. using Venus_Core.Attributes;
  28. using Venus_MainPages.PMs;
  29. using Venus_MainPages.Unity;
  30. using Venus_MainPages.Views;
  31. using Venus_Themes.CustomControls;
  32. using Venus_Themes.UserControls;
  33. using WPF.Themes.UserControls;
  34. using Xceed.Wpf.Toolkit.Primitives;
  35. using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
  36. namespace Venus_MainPages.ViewModels
  37. {
  38. public enum EPDType
  39. {
  40. Socket,
  41. WCF,
  42. None
  43. }
  44. internal class RecipeViewModel : BindableBase
  45. {
  46. #region 私有字段
  47. public string ModuleName = "PMA";
  48. private string m_CurrentRecipeName;
  49. private UiRecipeManager m_uiRecipeManager = new UiRecipeManager();
  50. private RecipeView recipeView;
  51. private TreeView treeViewRcpList;
  52. private Recipe m_currentRecipe;
  53. private string m_recipeType;
  54. private bool firstLoad=true;
  55. private WrapPanel headWrapPanel;
  56. private StackPanel bodyStackPanel;
  57. private List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>()
  58. {
  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. #endregion
  70. #region 属性
  71. public string CurrentRecipeName
  72. {
  73. get { return m_CurrentRecipeName; }
  74. set { SetProperty(ref m_CurrentRecipeName, value); }
  75. }
  76. public Recipe CurrentRecipe
  77. {
  78. get { return m_currentRecipe; }
  79. set
  80. {
  81. m_currentRecipe = value;
  82. RecipeType = m_currentRecipe.Header.Type.ToString();
  83. }
  84. }
  85. public string RecipeType
  86. {
  87. get { return m_recipeType; }
  88. set { SetProperty(ref m_recipeType, value); }
  89. }
  90. #endregion
  91. #region 命令
  92. private DelegateCommand<Object> _MouseRightButtonDownCommand;
  93. public DelegateCommand<Object> MouseRightButtonDownCommand =>
  94. _MouseRightButtonDownCommand ?? (_MouseRightButtonDownCommand = new DelegateCommand<Object>(OnMouseRightButtonDown));
  95. private DelegateCommand<Object> _LoadedCommand;
  96. public DelegateCommand<Object> LoadedCommand =>
  97. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand<Object>(OnLoaded));
  98. private DelegateCommand _SaveRecipeCommand;
  99. public DelegateCommand SaveRecipeCommand =>
  100. _SaveRecipeCommand ?? (_SaveRecipeCommand = new DelegateCommand(OnSaveRecipe));
  101. private DelegateCommand _AddStepCommand;
  102. public DelegateCommand AddStepCommand =>
  103. _AddStepCommand ?? (_AddStepCommand = new DelegateCommand(OnAddStep));
  104. private DelegateCommand _DeleteStepCommand;
  105. public DelegateCommand DeleteStepCommand =>
  106. _DeleteStepCommand ?? (_DeleteStepCommand = new DelegateCommand(OnDeleteStep));
  107. #endregion
  108. #region 构造函数
  109. public RecipeViewModel()
  110. {
  111. }
  112. #endregion
  113. #region 命令方法
  114. private void OnAddStep()
  115. {
  116. if (CurrentRecipe != null)
  117. {
  118. var index = currentRecipeGrid.ColumnDefinitions.Count;
  119. RecipeStep recipeStep;
  120. if (copyIndex == -1)
  121. {
  122. recipeStep = new RecipeStep();
  123. switch (currentChamber)
  124. {
  125. case JetChamber.Venus:
  126. case JetChamber.Kepler2300:
  127. recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
  128. recipeStep.LstUnit.Add(new TCPUnit());
  129. recipeStep.LstUnit.Add(new BiasUnit());
  130. recipeStep.LstUnit.Add(new GasControlUnit());
  131. recipeStep.LstUnit.Add(new ESCHVUnit());
  132. recipeStep.LstUnit.Add(new ProcessKitUnit());
  133. break;
  134. case JetChamber.Kepler2200A:
  135. recipeStep.LstUnit.Add(new Kepler2200GasControlUnit());
  136. recipeStep.LstUnit.Add(new HeaterUnit());
  137. recipeStep.LstUnit.Add(new Kepler2200RFUnit());
  138. break;
  139. }
  140. CurrentRecipe.Steps.Insert(index - 1, recipeStep);
  141. }
  142. else
  143. {
  144. var t = JsonConvert.SerializeObject(CurrentRecipe);
  145. recipeStep = Recipe.Load(t).Steps[copyIndex - 1];
  146. CurrentRecipe.Steps.Insert(index - 1, recipeStep);
  147. }
  148. RecipeStepToGridColumn(recipeStep, currentRecipeGrid, index, true);
  149. for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
  150. {
  151. CurrentRecipe.Steps[i - 1].StepNo = i;
  152. }
  153. }
  154. }
  155. private void OnDeleteStep()
  156. {
  157. if (CurrentRecipe != null)
  158. {
  159. OnDeleteStep(CurrentRecipe.Steps.Count - 1);
  160. }
  161. }
  162. private void OnSaveRecipe()
  163. {
  164. SaveRecipe(CurrentRecipeName, RecipeUnity.RecipeToString(CurrentRecipe));
  165. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  166. }
  167. private void OnLoaded(Object myrecipeView)
  168. {
  169. if (firstLoad == true)
  170. {
  171. currentChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.ChamberType").ToString());
  172. isInstalledEPD = bool.Parse(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.IsEnabled").ToString()) ;
  173. firstLoad = false;
  174. recipeView = myrecipeView as RecipeView;
  175. treeViewRcpList = recipeView.treeViewRcpList;
  176. headWrapPanel = recipeView.headWrapPanel;
  177. bodyStackPanel = recipeView.bodyStackPanel;
  178. UpdateRecipeFileList();
  179. treeViewRcpList.SelectedItemChanged += TreeViewRcpList_SelectedItemChanged;
  180. DispatcherTimer timer = new DispatcherTimer();
  181. timer.Interval = TimeSpan.FromSeconds(1);
  182. timer.Tick += Timer_Tick; ;
  183. timer.Start();
  184. for (int i = 0; i < 5; i++)
  185. {
  186. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.EndPoint.SearchCfg");
  187. Thread.Sleep(200);
  188. currentEPDType = (EPDType)System.Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.EPDType"));
  189. if (currentEPDType == EPDType.Socket)
  190. {
  191. EPDCfgList = (List<string>)QueryDataClient.Instance.Service.GetData($"{ModuleName}.EPDCfgList");
  192. }
  193. if (EPDCfgList != null)
  194. {
  195. break;
  196. }
  197. }
  198. }
  199. }
  200. private void Timer_Tick(object sender, EventArgs e)
  201. {
  202. }
  203. TreeViewFileItem selectedItem;
  204. private void TreeViewRcpList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  205. {
  206. selectedItem = e.NewValue as TreeViewFileItem;
  207. if (selectedItem == null)
  208. return;
  209. try
  210. {
  211. CurrentRecipeName = selectedItem.FileName;
  212. string xmlRecipeData = m_uiRecipeManager.LoadRecipe(ModuleName, selectedItem.FileName);
  213. if (xmlRecipeData == "")
  214. {
  215. treeViewRcpList.Items.Remove(selectedItem);
  216. return;
  217. }
  218. CurrentRecipe = Recipe.Load(xmlRecipeData);
  219. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  220. LoadRecipe(CurrentRecipe);
  221. }
  222. catch (Exception ex)
  223. {
  224. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  225. }
  226. e.Handled = true;
  227. }
  228. public bool SaveRecipe(string recipeName, string recipeContent)
  229. {
  230. return m_uiRecipeManager.SaveRecipe(ModuleName, recipeName, recipeContent);
  231. }
  232. private void OnMouseRightButtonDown(Object treeView)
  233. {
  234. //treeViewRcpList = treeView as TreeView;
  235. treeViewRcpList.ContextMenu = new ContextMenu() { Background = new SolidColorBrush(Colors.AliceBlue)};
  236. MenuItem menuItem = new MenuItem();
  237. menuItem = new MenuItem();
  238. menuItem.Tag = "\\";
  239. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateRecipe);
  240. menuItem.Header = "New Recipe";
  241. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  242. menuItem = new MenuItem();
  243. menuItem.Tag = "\\";
  244. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_DeleteRecipe);
  245. menuItem.Header = "Delete Recipe";
  246. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  247. menuItem = new MenuItem();
  248. menuItem.Tag = "\\";
  249. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_SaveAsRecipe);
  250. menuItem.Header = "Save As Recipe";
  251. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  252. menuItem = new MenuItem();
  253. menuItem.Tag = "\\";
  254. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_RenameRecipe);
  255. menuItem.Header = "Rename";
  256. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  257. treeViewRcpList.ContextMenu.Visibility = Visibility.Visible;
  258. }
  259. private void menuItem_MouseClick_CreateRecipe(object sender, RoutedEventArgs e)
  260. {
  261. MenuItem mit = sender as MenuItem;
  262. string folderName = mit.Tag as string;
  263. PerformCreateRecipe(folderName);
  264. }
  265. private void PerformCreateRecipe(string folderName)
  266. {
  267. try
  268. {
  269. RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
  270. {
  271. Owner = Application.Current.MainWindow
  272. };
  273. if (dlg.ShowDialog() == true)
  274. {
  275. var recipeName = folderName + "\\" + dlg.InputText;
  276. RecipeType type = (RecipeType)Enum.Parse(typeof(RecipeType), dlg.SelectedType);
  277. string newRecipe =RecipeUnity.CreateRecipe(currentChamber,type, dlg.InputText);
  278. //string recipeContent = m_uiRecipeManager.GetRecipeTemplate(ModuleName);
  279. //m_uiRecipeManager.SaveAsRecipe(ModuleName, recipeName, m_uiRecipeManager.LoadRecipe("system",folderName));
  280. if (SaveAsRecipe(recipeName, newRecipe))
  281. {
  282. //UpdateRecipeFileList();
  283. //SelectRecipe(recipeName);
  284. treeViewRcpList.Items.Add(new TreeViewFileItem(dlg.InputText));
  285. }
  286. else
  287. {
  288. WPFMessageBox.ShowError("Error");
  289. }
  290. }
  291. }
  292. catch (Exception ex)
  293. {
  294. LOG.WriteExeption(ex);
  295. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  296. }
  297. }
  298. private void menuItem_MouseClick_DeleteRecipe(object sender, RoutedEventArgs e)
  299. {
  300. if (CurrentRecipe == null)
  301. {
  302. return;
  303. }
  304. if (WPFMessageBox.ShowQuestion($"Delete {CurrentRecipeName}?","删除后无法恢复!!!") == MessageBoxResult.Yes)
  305. {
  306. MenuItem mit = sender as MenuItem;
  307. //string recipename = mit.Header.ToString();
  308. m_uiRecipeManager.DeleteRecipe(ModuleName, CurrentRecipeName);
  309. //PerformCreateRecipe(folderName);
  310. treeViewRcpList.Items.Remove(selectedItem);
  311. }
  312. }
  313. private void menuItem_MouseClick_SaveAsRecipe(object sender, RoutedEventArgs e)
  314. {
  315. if (CurrentRecipe == null)
  316. {
  317. return;
  318. }
  319. var newName = Interaction.InputBox(" ", "Save As Recipe", CurrentRecipeName, -1, -1);
  320. if (newName != CurrentRecipeName && newName != "")
  321. {
  322. var newRecipe = CurrentRecipe;
  323. newRecipe.Header.Name = newName;
  324. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  325. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, newName + ".rcp");
  326. File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  327. UpdateRecipeFileList();
  328. }
  329. }
  330. private void menuItem_MouseClick_RenameRecipe(object sender, RoutedEventArgs e)
  331. {
  332. if (CurrentRecipe == null)
  333. {
  334. return;
  335. }
  336. var newName= Interaction.InputBox(" ", "Rename Recipe", CurrentRecipeName, -1, -1);
  337. if (newName != CurrentRecipeName && newName!="")
  338. {
  339. var oldrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, CurrentRecipeName + ".rcp");
  340. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, newName + ".rcp");
  341. CurrentRecipe.Header.Name = newName;
  342. SaveRecipe(CurrentRecipeName, RecipeUnity.RecipeToString(CurrentRecipe));
  343. File.Move(oldrecipePath, newrecipePath);
  344. UpdateRecipeFileList();
  345. }
  346. }
  347. public bool SaveAsRecipe(string recipeName, string recipeContent)
  348. {
  349. return m_uiRecipeManager.SaveAsRecipe(ModuleName, recipeName, recipeContent);
  350. }
  351. public string GetXmlRecipeList()
  352. {
  353. return m_uiRecipeManager.GetXmlRecipeList(ModuleName, true) ?? "";
  354. }
  355. void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
  356. {
  357. foreach (XmlElement ele in curElementNode.ChildNodes)
  358. {
  359. if (ele.Name == "File")
  360. {
  361. string fileName = ele.Attributes["Name"].Value;
  362. fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
  363. TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
  364. item.Tag = ele.Attributes["Name"].Value;
  365. //item.ToolTip = fileName;
  366. itemsControl.Items.Add(item);
  367. }
  368. else if (ele.Name == "Folder")
  369. {
  370. string folderName = ele.Attributes["Name"].Value;
  371. folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
  372. TreeViewFolderItem item = new TreeViewFolderItem(folderName);
  373. item.Tag = ele.Attributes["Name"].Value;
  374. CreateTreeViewItems(ele, item);
  375. item.IsExpanded = false;
  376. itemsControl.Items.Add(item);
  377. }
  378. }
  379. }
  380. private IEnumerable<string> GetFilesNames(string path)
  381. {
  382. return Directory.GetFiles(path, "*.rcp")
  383. .Select(Path.GetFileNameWithoutExtension);
  384. }
  385. private void LoadHeadWrapPanel(WrapPanel HeadWrapPanel, Recipe recipe)
  386. {
  387. HeadWrapPanel.Children.Clear();
  388. Type type = recipe.Header.GetType();
  389. foreach (var propertyInfo in type.GetProperties())
  390. {
  391. TextBlock textBlock = new TextBlock();
  392. textBlock.FontSize = 15;
  393. //textBlock.Width = 100;
  394. textBlock.Text = propertyInfo.Name + ":";
  395. textBlock.Margin = new Thickness(15, 0, 0, 0);
  396. textBlock.VerticalAlignment = VerticalAlignment.Center;
  397. HeadWrapPanel.Children.Add(textBlock);
  398. Binding binding = new Binding()
  399. {
  400. Source = recipe.Header, // 数据源
  401. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  402. Mode = BindingMode.TwoWay, // 绑定模式
  403. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, //触发器
  404. };
  405. var propertyTypeName = propertyInfo.PropertyType.Name;
  406. var propertyInfoName = propertyInfo.Name;
  407. Control control = new Control();
  408. switch (propertyInfoName)
  409. {
  410. case "ChamberType":
  411. control = new ComboBox();
  412. control.Height = 23;
  413. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  414. ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  415. break;
  416. case "Type":
  417. ComboBox cb = new ComboBox();
  418. cb.SelectionChanged += ChangeUI;
  419. control = cb;
  420. control.Height = 23;
  421. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  422. ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  423. break;
  424. case "ChuckRecipe":
  425. string[] chucklist = new string[] {"" };
  426. ArrayList arrayList = new ArrayList(chucklist.ToList());
  427. 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));
  428. foreach (var i in chlist)
  429. {
  430. arrayList.Add(i);
  431. }
  432. chucklist = (string[])arrayList.ToArray(typeof(string));
  433. StringBuilder stringBuilder = new StringBuilder();
  434. //输出
  435. for (int i = 0; i < chucklist.Length; i++)
  436. {
  437. stringBuilder.Append(chucklist[i] + "\t");
  438. }
  439. control = new ComboBox()
  440. {
  441. ItemsSource = chucklist
  442. };
  443. control.Height = 23;
  444. control.MinWidth = 100;
  445. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  446. break;
  447. case "DechuckRecipe":
  448. string[] dechucklist = new string[] { "" };
  449. ArrayList dearrayList = new ArrayList(dechucklist.ToList());
  450. IEnumerable<string> delist = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName)).ToList().Where(item => item.ToLower().Contains("dechuck"));
  451. foreach (var i in delist)
  452. {
  453. dearrayList.Add(i);
  454. }
  455. dechucklist = (string[])dearrayList.ToArray(typeof(string));
  456. StringBuilder destringBuilder = new StringBuilder();
  457. for (int i = 0; i < dechucklist.Length; i++)
  458. {
  459. destringBuilder.Append(dechucklist[i] + "\t");
  460. }
  461. control = new ComboBox()
  462. {
  463. ItemsSource= dechucklist
  464. };
  465. control.Height = 23;
  466. control.MinWidth = 100;
  467. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  468. break;
  469. default:
  470. control = new TextBox();
  471. control.Margin = new Thickness(1, 0, 0, 0);
  472. control.BorderThickness = new Thickness(0, 0, 0, 1);
  473. //control.BorderBrush = Brushes.Black;
  474. control.FontSize = 15;
  475. control.Foreground = Brushes.Green;
  476. control.Background = Brushes.Transparent;
  477. control.VerticalAlignment = VerticalAlignment.Center;
  478. control.MinWidth = 15;
  479. control.SetBinding(TextBox.TextProperty, binding);
  480. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  481. if (objAttrs.Length > 0)
  482. {
  483. (control as TextBox).IsReadOnly = true;
  484. }
  485. break;
  486. }
  487. //switch (propertyTypeName)
  488. //{
  489. // case "Int32":
  490. // case "String":
  491. // control = new TextBox();
  492. // control.Margin = new Thickness(1, 0, 0, 0);
  493. // control.BorderThickness = new Thickness(0, 0, 0, 1);
  494. // //control.BorderBrush = Brushes.Black;
  495. // control.FontSize = 15;
  496. // control.Foreground = Brushes.Green;
  497. // control.Background = Brushes.Transparent;
  498. // control.VerticalAlignment = VerticalAlignment.Center;
  499. // control.MinWidth = 15;
  500. // control.SetBinding(TextBox.TextProperty, binding);
  501. // object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  502. // if (objAttrs.Length > 0)
  503. // {
  504. // (control as TextBox).IsReadOnly = true;
  505. // }
  506. // break;
  507. // case "Boolean":
  508. // control = new CheckBox();
  509. // control.SetBinding(CheckBox.IsCheckedProperty, binding);
  510. // break;
  511. // default:
  512. // control = new ComboBox();
  513. // control.Height = 23;
  514. // control.SetBinding(ComboBox.SelectedItemProperty, binding);
  515. // ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  516. // break;
  517. //}
  518. HeadWrapPanel.Children.Add(control);
  519. }
  520. }
  521. private void ChangeUI(object sender, SelectionChangedEventArgs e)
  522. {
  523. var t = sender as ComboBox;
  524. if (t.SelectedValue.ToString() == "Chuck" || t.SelectedValue.ToString() == "DeChuck")
  525. {
  526. headWrapPanel.Children[8].Visibility = Visibility.Collapsed;
  527. headWrapPanel.Children[9].Visibility = Visibility.Collapsed;
  528. headWrapPanel.Children[10].Visibility = Visibility.Collapsed;
  529. headWrapPanel.Children[11].Visibility = Visibility.Collapsed;
  530. }
  531. else
  532. {
  533. headWrapPanel.Children[8].Visibility = Visibility.Visible;
  534. headWrapPanel.Children[9].Visibility = Visibility.Visible;
  535. headWrapPanel.Children[10].Visibility = Visibility.Visible;
  536. headWrapPanel.Children[11].Visibility = Visibility.Visible;
  537. }
  538. }
  539. private void MenuItemLeftInsert_Click(object sender, RoutedEventArgs e)
  540. {
  541. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  542. int insertIndex = Convert.ToInt32(t.Text);
  543. OnAddStep(insertIndex);
  544. }
  545. private void MenuItemRightInsert_Click(object sender, RoutedEventArgs e)
  546. {
  547. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  548. int insertIndex = Convert.ToInt32(t.Text);
  549. OnAddStep(insertIndex + 1);
  550. }
  551. private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
  552. {
  553. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  554. int deleteIndex = Convert.ToInt32(t.Text);
  555. OnDeleteStep(deleteIndex - 1);
  556. }
  557. private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
  558. {
  559. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  560. copyIndex = Convert.ToInt32(t.Text);
  561. }
  562. #endregion
  563. #region 私有方法
  564. private void RecipeStepToGridColumn(RecipeStep recipeStep, Grid grid, int index, bool isInsert)
  565. {
  566. int location = 1;
  567. if (isInsert == true)
  568. {
  569. location -= 1;
  570. }
  571. Type recipeType = recipeStep.GetType();
  572. int cycleCount = 1;
  573. if (index == 0)
  574. {
  575. cycleCount = 2;
  576. }
  577. for (int j = 0; j < cycleCount; j++)
  578. {
  579. int i = 0;
  580. ColumnDefinition col1 = new ColumnDefinition();
  581. //col1.MinWidth = 50;
  582. grid.ColumnDefinitions.Insert(index, col1);
  583. Binding stepcheckbinding = null;
  584. //grid.MinWidth = 200;
  585. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  586. {
  587. string propertyInfoName = propertyInfo.Name;
  588. string propertyTypeName = propertyInfo.PropertyType.Name;
  589. if (propertyInfoName != "LstUnit")
  590. {
  591. if (index == 0 && grid.ColumnDefinitions.Count == 1)
  592. {
  593. RowDefinition row1 = new RowDefinition();
  594. grid.RowDefinitions.Add(row1);
  595. if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime") && isInstalledEPD == false)
  596. {
  597. row1.Height = new GridLength(0);
  598. }
  599. }
  600. if (grid.ColumnDefinitions.Count == 1 && j == 0)
  601. {
  602. TextBox textBlock = new TextBox();
  603. textBlock.IsReadOnly = true;
  604. textBlock.Text = propertyInfoName;
  605. grid.Children.Add(textBlock);
  606. textBlock.Background = new SolidColorBrush(Colors.BurlyWood);
  607. Grid.SetRow(textBlock, i);
  608. Grid.SetColumn(textBlock, 0);
  609. }
  610. else
  611. {
  612. Binding binding = new Binding()
  613. {
  614. Source = recipeStep, // 数据源
  615. Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
  616. Mode = BindingMode.TwoWay, // 绑定模式
  617. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  618. };
  619. switch (propertyTypeName)
  620. {
  621. case "Int32":
  622. case "String":
  623. if (propertyInfoName == "EPDConfig")
  624. {
  625. if (currentEPDType == EPDType.Socket)
  626. {
  627. ComboBox EPDcomboBox = new ComboBox();
  628. EPDcomboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  629. EPDcomboBox.Background = new SolidColorBrush(Colors.Black);
  630. EPDcomboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  631. EPDcomboBox.ItemsSource = EPDCfgList;
  632. grid.Children.Add(EPDcomboBox);
  633. Grid.SetRow(EPDcomboBox, i);
  634. Grid.SetColumn(EPDcomboBox, index + location);
  635. EPDcomboBox.DropDownOpened += EPDcomboBox_DropDownOpened;
  636. }
  637. else if (currentEPDType == EPDType.WCF)
  638. {
  639. Button EPDButton = new Button();
  640. EPDButton.Content = "EndPoint";
  641. EPDButton.Cursor = Cursors.Hand;
  642. EPDButton.Tag = $"{CurrentRecipeName}.{(index + location).ToString()}";
  643. EPDButton.Style = null;
  644. EPDButton.Click += EPDButton_Click;
  645. grid.Children.Add(EPDButton);
  646. Grid.SetRow(EPDButton, i);
  647. Grid.SetColumn(EPDButton, index + location);
  648. }
  649. break;
  650. }
  651. TextBox textBox = new TextBox();
  652. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  653. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  654. if (stepcheckbinding == null)
  655. {
  656. textBox.IsEnabled = true;
  657. }
  658. else
  659. {
  660. textBox.SetBinding(TextBox.IsEnabledProperty, stepcheckbinding);
  661. }
  662. textBox.SetBinding(TextBox.TextProperty, binding);
  663. grid.Children.Add(textBox);
  664. Grid.SetRow(textBox, i);
  665. Grid.SetColumn(textBox, index + location);
  666. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  667. if (objAttrs.Length > 0)
  668. {
  669. textBox.IsReadOnly = true;
  670. ContextMenu contextmenu = new ContextMenu();
  671. textBox.ContextMenu = contextmenu;
  672. MenuItem menuItemDelete = new MenuItem();
  673. menuItemDelete.Header = "删除";
  674. menuItemDelete.Click += MenuItemDelete_Click;
  675. MenuItem menuItemLeftInsert = new MenuItem();
  676. menuItemLeftInsert.Header = "左插入";
  677. menuItemLeftInsert.Click += MenuItemLeftInsert_Click;
  678. MenuItem menuItemRightInsert = new MenuItem();
  679. menuItemRightInsert.Header = "右插入";
  680. menuItemRightInsert.Click += MenuItemRightInsert_Click;
  681. MenuItem menuItemCopy = new MenuItem();
  682. menuItemCopy.Tag = textBox.Text;
  683. menuItemCopy.Header = "复制";
  684. menuItemCopy.Click += MenuItemCopy_Click;
  685. contextmenu.Items.Add(menuItemCopy);
  686. contextmenu.Items.Add(menuItemDelete);
  687. contextmenu.Items.Add(menuItemLeftInsert);
  688. contextmenu.Items.Add(menuItemRightInsert);
  689. }
  690. break;
  691. case "Boolean":
  692. CheckBox checkBox = new CheckBox();
  693. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  694. grid.Children.Add(checkBox);
  695. Grid.SetRow(checkBox, i);
  696. Grid.SetColumn(checkBox, index + location);
  697. //if (stepcheckbinding == null)
  698. //{
  699. // stepcheckbinding = new Binding
  700. // {
  701. // Source = checkBox, // 数据源
  702. // Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
  703. // Mode = BindingMode.TwoWay, // 绑定模式
  704. // UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  705. // };
  706. //}
  707. //else
  708. //{
  709. //}
  710. if (stepcheckbinding == null)
  711. {
  712. checkBox.IsEnabled = true;
  713. }
  714. else
  715. {
  716. checkBox.SetBinding(TextBox.IsEnabledProperty, stepcheckbinding);
  717. }
  718. break;
  719. default:
  720. ComboBox comboBox = new ComboBox();
  721. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  722. comboBox.Background = new SolidColorBrush(Colors.Black);
  723. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  724. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  725. grid.Children.Add(comboBox);
  726. Grid.SetRow(comboBox, i);
  727. Grid.SetColumn(comboBox, index + location);
  728. if (stepcheckbinding == null)
  729. {
  730. comboBox.IsEnabled = true;
  731. }
  732. else
  733. {
  734. comboBox.SetBinding(TextBox.IsEnabledProperty, stepcheckbinding);
  735. }
  736. break;
  737. }
  738. }
  739. i++;
  740. }
  741. }
  742. int k = 0;
  743. recipeStep.LstUnit.ToList().ForEach(x =>
  744. {
  745. Type unitType = x.GetType();
  746. Binding checkbinding = null;
  747. foreach (PropertyInfo propertyInfo in unitType.GetProperties())
  748. {
  749. if (index == 0 && grid.ColumnDefinitions.Count == 1)
  750. {
  751. RowDefinition row1 = new RowDefinition();
  752. grid.RowDefinitions.Add(row1);
  753. }
  754. if (grid.ColumnDefinitions.Count == 1 && j == 0)
  755. {
  756. TextBox textBlock = new TextBox();
  757. textBlock.IsReadOnly = true;
  758. switch (propertyInfo.Name)
  759. {
  760. case "Gas1":
  761. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  762. textBlock.Text = $"{propertyInfo.Name}({data1.DisplayName},{data1.Scale})";
  763. break;
  764. case "Gas2":
  765. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  766. textBlock.Text = $"{propertyInfo.Name}({data2.DisplayName},{data2.Scale})";
  767. break;
  768. case "Gas3":
  769. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  770. textBlock.Text = $"{propertyInfo.Name}({data3.DisplayName},{data3.Scale})";
  771. break;
  772. case "Gas4":
  773. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  774. textBlock.Text = $"{propertyInfo.Name}({data4.DisplayName},{data4.Scale})";
  775. break;
  776. case "Gas5":
  777. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  778. textBlock.Text = $"{propertyInfo.Name}({data5.DisplayName},{data5.Scale})";
  779. break;
  780. case "Gas6":
  781. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  782. textBlock.Text = $"{propertyInfo.Name}({data6.DisplayName},{data6.Scale})";
  783. break;
  784. case "Gas7":
  785. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  786. textBlock.Text = $"{propertyInfo.Name}({data7.DisplayName},{data7.Scale})";
  787. break;
  788. case "Gas8":
  789. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  790. textBlock.Text = $"{propertyInfo.Name}({data8.DisplayName},{data8.Scale})";
  791. break;
  792. case "HeaterPressure":
  793. textBlock.Text = "Pressure(Pa)";
  794. break;
  795. case "HeaterTemp":
  796. textBlock.Text = "Heater Temp(℃)";
  797. break;
  798. case "HeaterRatio":
  799. textBlock.Text = "Heater Ratio";
  800. break;
  801. default:
  802. textBlock.Text = propertyInfo.Name;
  803. break;
  804. }
  805. textBlock.Background = solidColorBrushes[k % 3];
  806. grid.Children.Add(textBlock);
  807. Grid.SetRow(textBlock, i);
  808. Grid.SetColumn(textBlock, 0);
  809. }
  810. else
  811. {
  812. Binding binding = new Binding()
  813. {
  814. Source = recipeStep.LstUnit[k], // 数据源
  815. //Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
  816. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  817. Mode = BindingMode.TwoWay, // 绑定模式
  818. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  819. };
  820. var item = propertyInfo.PropertyType.Name;
  821. if (propertyInfo.Name == "UnitName")
  822. {
  823. TextBox textBlock1 = new TextBox();
  824. textBlock1.HorizontalContentAlignment = HorizontalAlignment.Center;
  825. textBlock1.VerticalContentAlignment =VerticalAlignment.Center;
  826. textBlock1.Text = propertyInfo.GetValue(x).ToString();
  827. textBlock1.IsReadOnly = true;
  828. grid.Children.Add(textBlock1);
  829. Grid.SetRow(textBlock1, i);
  830. Grid.SetColumn(textBlock1, index + location);
  831. }
  832. else
  833. {
  834. switch (item)
  835. {
  836. case "Int32":
  837. case "String":
  838. TextBox textBox = new TextBox();
  839. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  840. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  841. if (checkbinding == null)
  842. {
  843. textBox.IsEnabled = true;
  844. }
  845. else
  846. {
  847. textBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  848. }
  849. switch (propertyInfo.Name)
  850. {
  851. case "Gas1":
  852. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  853. TextBoxMaxValue.SetMaxValue(textBox, (int)data1.Scale);
  854. break;
  855. case "Gas2":
  856. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  857. TextBoxMaxValue.SetMaxValue(textBox, (int)data2.Scale);
  858. break;
  859. case "Gas3":
  860. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  861. break;
  862. case "Gas4":
  863. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  864. break;
  865. case "Gas5":
  866. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  867. break;
  868. case "Gas6":
  869. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  870. break;
  871. case "Gas7":
  872. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  873. break;
  874. case "Gas8":
  875. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  876. break;
  877. }
  878. textBox.SetBinding(TextBox.TextProperty, binding);
  879. grid.Children.Add(textBox);
  880. Grid.SetRow(textBox, i);
  881. Grid.SetColumn(textBox, index + location);
  882. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  883. if (objAttrs.Length > 0)
  884. {
  885. textBox.IsReadOnly = true;
  886. }
  887. break;
  888. case "Boolean":
  889. CheckBox checkBox = new CheckBox();
  890. if (checkbinding == null)
  891. {
  892. checkbinding = new Binding
  893. {
  894. Source = checkBox, // 数据源
  895. Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
  896. Mode = BindingMode.TwoWay, // 绑定模式
  897. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  898. };
  899. }
  900. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  901. grid.Children.Add(checkBox);
  902. Grid.SetRow(checkBox, i);
  903. Grid.SetColumn(checkBox, index + location);
  904. break;
  905. default:
  906. ComboBox comboBox = new ComboBox();
  907. comboBox.BorderBrush = Brushes.Gray;
  908. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  909. if (checkbinding == null)
  910. {
  911. comboBox.IsEnabled = true;
  912. }
  913. else
  914. {
  915. comboBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  916. }
  917. comboBox.Background = Brushes.White;
  918. string path = propertyInfo.Name;
  919. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  920. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  921. grid.Children.Add(comboBox);
  922. Grid.SetRow(comboBox, i);
  923. Grid.SetColumn(comboBox, index + location);
  924. break;
  925. }
  926. }
  927. }
  928. i++;
  929. }
  930. k++;
  931. });
  932. //index++;
  933. }
  934. }
  935. private void EPDcomboBox_DropDownOpened(object sender, EventArgs e)
  936. {
  937. }
  938. private void EPDButton_Click(object sender, RoutedEventArgs e)
  939. {
  940. Button button = sender as Button;
  941. string para = button.Tag.ToString();
  942. int stepno = Convert.ToInt32(para.Split('.')[1])-1;
  943. var endpointconfigitem = new MECF.Framework.Common.CommonData.EndPointConfigItem();
  944. if (CurrentRecipe.Steps[stepno].EPDConfig!=null && CurrentRecipe.Steps[stepno].EPDConfig.Length>20)
  945. {
  946. endpointconfigitem.SetValue(CurrentRecipe.Steps[stepno].EPDConfig);
  947. }
  948. (new EndPointDlg(para, endpointconfigitem,CurrentRecipe)).ShowDialog();
  949. }
  950. private void UpdateRecipeFileList()
  951. {
  952. XmlDocument doc = new XmlDocument();
  953. doc.LoadXml(GetXmlRecipeList());
  954. treeViewRcpList.Items.Clear();
  955. CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
  956. }
  957. private void LoadRecipe(Recipe recipe)
  958. {
  959. copyIndex = -1;
  960. bodyStackPanel.Children.Clear();
  961. //CurrentRecipe = null;
  962. GC.Collect(); // This should pick up the control removed at a previous MouseDown
  963. GC.WaitForPendingFinalizers(); // Doesn't help either
  964. GC.Collect();
  965. GC.WaitForPendingFinalizers(); // Doesn't help either
  966. CurrentRecipe = recipe;
  967. Grid grid = new Grid();
  968. grid.Margin = new Thickness(15);
  969. //index = 0;
  970. for (int i = 0; i < recipe.Steps.Count; i++)
  971. {
  972. RecipeStepToGridColumn(recipe.Steps[i], grid, i, false);
  973. }
  974. bodyStackPanel.Children.Add(grid);
  975. currentRecipeGrid = grid;
  976. }
  977. private void OnAddStep(int index)
  978. {
  979. if (CurrentRecipe != null)
  980. {
  981. RecipeStep recipeStep;
  982. if (copyIndex == -1)
  983. {
  984. recipeStep = new RecipeStep();
  985. //recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
  986. //recipeStep.LstUnit.Add(new TCPUnit());
  987. //recipeStep.LstUnit.Add(new BiasUnit());
  988. //recipeStep.LstUnit.Add(new GasControlUnit());
  989. //recipeStep.LstUnit.Add(new ESCHVUnit());
  990. //recipeStep.LstUnit.Add(new ProcessKitUnit());
  991. switch (currentChamber)
  992. {
  993. case JetChamber.Venus:
  994. case JetChamber.Kepler2300:
  995. recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
  996. recipeStep.LstUnit.Add(new TCPUnit());
  997. recipeStep.LstUnit.Add(new BiasUnit());
  998. recipeStep.LstUnit.Add(new GasControlUnit());
  999. recipeStep.LstUnit.Add(new ESCHVUnit());
  1000. recipeStep.LstUnit.Add(new ProcessKitUnit());
  1001. break;
  1002. case JetChamber.Kepler2200A:
  1003. recipeStep.LstUnit.Add(new Kepler2200GasControlUnit());
  1004. recipeStep.LstUnit.Add(new HeaterUnit());
  1005. recipeStep.LstUnit.Add(new Kepler2200RFUnit());
  1006. break;
  1007. }
  1008. CurrentRecipe.Steps.Insert(index - 1, recipeStep);
  1009. }
  1010. else
  1011. {
  1012. var t = JsonConvert.SerializeObject(CurrentRecipe);
  1013. recipeStep = Recipe.Load(t).Steps[copyIndex - 1];
  1014. CurrentRecipe.Steps.Insert(index - 1, recipeStep);
  1015. }
  1016. RecipeStepToGridColumn(recipeStep, currentRecipeGrid, index, true);
  1017. for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
  1018. {
  1019. CurrentRecipe.Steps[i - 1].StepNo = i;
  1020. }
  1021. }
  1022. }
  1023. private void OnDeleteStep(int index)
  1024. {
  1025. if (CurrentRecipe != null && CurrentRecipe.Steps.Count > 1)
  1026. {
  1027. CurrentRecipe.Steps.RemoveAt(index);
  1028. currentRecipeGrid.Children.RemoveRange(currentRecipeGrid.RowDefinitions.Count * (index + 1), currentRecipeGrid.RowDefinitions.Count);
  1029. currentRecipeGrid.ColumnDefinitions.RemoveAt(index);
  1030. for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
  1031. {
  1032. CurrentRecipe.Steps[i - 1].StepNo = i;
  1033. }
  1034. }
  1035. }
  1036. #endregion
  1037. }
  1038. }