RecipeEditorControlViewModel.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Media;
  11. using Venus_Core;
  12. using Venus_Core.Attributes;
  13. namespace Aitex.UI.RecipeEditor
  14. {
  15. public class RecipeEditorControlViewModel : INotifyPropertyChanged
  16. {
  17. //当前选中的配方
  18. private Recipe m_currentRecipe;
  19. public Recipe CurrentRecipe
  20. {
  21. get { return m_currentRecipe; }
  22. set { m_currentRecipe = value; InvokePropertyChanged("CurrentRecipe"); }
  23. }
  24. public StackPanel GridStackPanel { get; set; } //step容器
  25. List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>();//step模块颜色
  26. public WrapPanel HeadWrapPanel { get; set; } //head容器
  27. public RecipeEditorControlViewModel()
  28. {
  29. }
  30. public void OnAddStep()
  31. {
  32. if (CurrentRecipe != null)
  33. {
  34. RecipeStep recipeStep = new RecipeStep();
  35. recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
  36. recipeStep.LstUnit.Add(new TCPUnit());
  37. recipeStep.LstUnit.Add(new BiasUnit());
  38. recipeStep.LstUnit.Add(new GasControlUnit());
  39. recipeStep.LstUnit.Add(new ESCHVUnit());
  40. recipeStep.LstUnit.Add(new ProcessKitUnit());
  41. recipeStep.StepNo = GridStackPanel.Children.Count+1;
  42. CurrentRecipe.Steps.Add(recipeStep);
  43. var item = RecipeStepToGrid(recipeStep);
  44. GridStackPanel.Children.Add(item.Item1);
  45. }
  46. }
  47. public void OnDeleteStep()
  48. {
  49. if (CurrentRecipe != null&& CurrentRecipe.Steps.Count>0)
  50. {
  51. CurrentRecipe.Steps.RemoveAt(CurrentRecipe.Steps.Count - 1);
  52. GridStackPanel.Children.RemoveAt(GridStackPanel.Children.Count - 1);
  53. }
  54. }
  55. /// <summary>
  56. /// 选中recipe,显示界面
  57. /// </summary>
  58. /// <param name="recipe"></param>
  59. public void LoadRecipe(Recipe recipe)
  60. {
  61. GridStackPanel.Children.Clear();
  62. CurrentRecipe = null;
  63. GC.Collect(); // This should pick up the control removed at a previous MouseDown
  64. GC.WaitForPendingFinalizers(); // Doesn't help either
  65. GC.Collect();
  66. GC.WaitForPendingFinalizers(); // Doesn't help either
  67. CurrentRecipe = recipe;
  68. recipe.Steps.ToList().ForEach(x =>
  69. {
  70. var tupleValue = RecipeStepToGrid(x);
  71. GridStackPanel.Children.Add(tupleValue.Item1);
  72. });
  73. LoadHeadWrapPanel(recipe);
  74. }
  75. /// <summary>
  76. /// 选中recipe,头部界面显示
  77. /// </summary>
  78. /// <param name="recipe"></param>
  79. private void LoadHeadWrapPanel(Recipe recipe)
  80. {
  81. HeadWrapPanel.Children.Clear();
  82. Type type = recipe.Header.GetType();
  83. foreach (var propertyInfo in type.GetProperties())
  84. {
  85. TextBlock textBlock = new TextBlock();
  86. textBlock.FontSize = 15;
  87. //textBlock.Width = 100;
  88. textBlock.Text = propertyInfo.Name + ":";
  89. textBlock.Margin = new Thickness(15, 0, 0, 0);
  90. textBlock.VerticalAlignment = VerticalAlignment.Center;
  91. HeadWrapPanel.Children.Add(textBlock);
  92. Binding binding = new Binding()
  93. {
  94. Source = recipe.Header, // 数据源
  95. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  96. Mode = BindingMode.TwoWay, // 绑定模式
  97. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  98. };
  99. var propertyTypeName = propertyInfo.PropertyType.Name;
  100. var propertyInfoName=propertyInfo.Name;
  101. Control control = new Control();
  102. switch (propertyTypeName)
  103. {
  104. case "Int32":
  105. case "String":
  106. control = new TextBox();
  107. control.Margin = new Thickness(1, 0, 0, 0);
  108. control.BorderThickness = new Thickness(0,0,0,1);
  109. //control.BorderBrush = Brushes.Black;
  110. control.FontSize = 15;
  111. control.Foreground = Brushes.Green;
  112. control.Background = Brushes.Transparent;
  113. control.VerticalAlignment = VerticalAlignment.Center;
  114. control.MinWidth = 15;
  115. //control.Width = 200;
  116. control.SetBinding(TextBox.TextProperty, binding);
  117. //if (propertyInfoName == "Name" || propertyInfoName == "CreateTime" || propertyInfoName == "LastModifiedBy")
  118. //{
  119. // (control as TextBox).IsReadOnly = true;
  120. //}
  121. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  122. if (objAttrs.Length > 0)
  123. {
  124. (control as TextBox).IsReadOnly = true;
  125. }
  126. break;
  127. case "Boolean":
  128. control = new CheckBox();
  129. control.SetBinding(CheckBox.IsCheckedProperty, binding);
  130. break;
  131. default:
  132. control = new ComboBox();
  133. control.Height = 23;
  134. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  135. ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  136. break;
  137. }
  138. HeadWrapPanel.Children.Add(control);
  139. }
  140. }
  141. /// <summary>
  142. /// step转换为Grid
  143. /// </summary>
  144. /// <param name="recipeStep"></param>
  145. /// <returns></returns>
  146. private ValueTuple<Grid, List<int>> RecipeStepToGrid(RecipeStep recipeStep)
  147. {
  148. Grid grid = new Grid();
  149. ContextMenu contextmenu = new ContextMenu();
  150. contextmenu.Tag = grid;
  151. grid.ContextMenu= contextmenu;
  152. MenuItem menuItemDelete = new MenuItem();
  153. menuItemDelete.Header = "删除";
  154. menuItemDelete.Click += MenuItemDelete_Click;
  155. MenuItem menuItemInsert = new MenuItem();
  156. menuItemInsert.Header = "左插入";
  157. menuItemInsert.Click += MenuItemInsert_Click;
  158. contextmenu.Items.Add(menuItemDelete);
  159. contextmenu.Items.Add(menuItemInsert);
  160. List<int> ints = new List<int>();
  161. ColumnDefinition col1 = new ColumnDefinition();//Key
  162. ColumnDefinition col2 = new ColumnDefinition();//Value
  163. grid.ColumnDefinitions.Add(col1);
  164. grid.ColumnDefinitions.Add(col2);
  165. GridOptions.SetShowBorder(grid, true);
  166. GridOptions.SetLineBrush(grid, Brushes.White);
  167. GridOptions.SetLineThickness(grid, 1);
  168. grid.Margin = new Thickness(15, 5, 0, 0);
  169. Type recipeType = recipeStep.GetType();
  170. int i = 0;
  171. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  172. {
  173. string propertyInfoName = propertyInfo.Name;
  174. string propertyTypeName = propertyInfo.PropertyType.Name;
  175. if (propertyInfoName != "LstUnit")
  176. {
  177. RowDefinition row1 = new RowDefinition();
  178. grid.RowDefinitions.Add(row1);
  179. Binding binding = new Binding()
  180. {
  181. Source = recipeStep, // 数据源
  182. Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
  183. Mode = BindingMode.TwoWay, // 绑定模式
  184. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  185. };
  186. switch (propertyTypeName)
  187. {
  188. case "Int32":
  189. case "String":
  190. TextBox textBox = new TextBox();
  191. textBox.SetBinding(TextBox.TextProperty, binding);
  192. grid.Children.Add(textBox);
  193. Grid.SetRow(textBox, i);
  194. Grid.SetColumn(textBox, 1);
  195. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  196. if (objAttrs.Length > 0)
  197. {
  198. textBox.IsReadOnly = true;
  199. }
  200. break;
  201. case "Boolean":
  202. CheckBox checkBox = new CheckBox();
  203. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  204. grid.Children.Add(checkBox);
  205. Grid.SetRow(checkBox, i);
  206. Grid.SetColumn(checkBox, 1);
  207. break;
  208. default:
  209. ComboBox comboBox = new ComboBox();
  210. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  211. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  212. grid.Children.Add(comboBox);
  213. Grid.SetRow(comboBox, i);
  214. Grid.SetColumn(comboBox, 1);
  215. if (propertyInfo.Name == "PressureUnitMode")
  216. {
  217. comboBox.SelectionChanged += ComboBox_SelectionChanged;
  218. }
  219. break;
  220. }
  221. TextBlock textBlock = new TextBlock();
  222. textBlock.Text = propertyInfoName;
  223. grid.Children.Add(textBlock);
  224. Grid.SetRow(textBlock, i);
  225. Grid.SetColumn(textBlock, 0);
  226. i++;
  227. }
  228. }
  229. ints.Add(recipeType.GetProperties().Length);
  230. int k = 0;
  231. recipeStep.LstUnit.ToList().ForEach(x =>
  232. {
  233. Type unitType = x.GetType();
  234. foreach (PropertyInfo propertyInfo in unitType.GetProperties())
  235. {
  236. Binding binding = new Binding()
  237. {
  238. Source = recipeStep.LstUnit[k], // 数据源
  239. //Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
  240. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  241. Mode = BindingMode.TwoWay, // 绑定模式
  242. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  243. };
  244. RowDefinition row1 = new RowDefinition();
  245. grid.RowDefinitions.Add(row1);
  246. var item = propertyInfo.PropertyType.Name;
  247. if (propertyInfo.Name == "UnitName")
  248. {
  249. TextBlock textBlock1 = new TextBlock();
  250. //textBlock1.SetBinding(TextBlock.TextProperty, binding);
  251. textBlock1.Text = propertyInfo.GetValue(x).ToString();
  252. textBlock1.Foreground = Brushes.Red;
  253. //textBlock1.HorizontalAlignment = HorizontalAlignment.Center;
  254. grid.Children.Add(textBlock1);
  255. Grid.SetRow(textBlock1, i);
  256. Grid.SetColumn(textBlock1, 1);
  257. }
  258. else
  259. {
  260. switch (item)
  261. {
  262. case "Int32":
  263. case "String":
  264. TextBox textBox = new TextBox();
  265. textBox.BorderBrush = Brushes.Transparent;
  266. textBox.SetBinding(TextBox.TextProperty, binding);
  267. grid.Children.Add(textBox);
  268. Grid.SetRow(textBox, i);
  269. Grid.SetColumn(textBox, 1);
  270. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  271. if (objAttrs.Length > 0)
  272. {
  273. textBox.IsReadOnly = true;
  274. }
  275. break;
  276. case "Boolean":
  277. CheckBox checkBox = new CheckBox();
  278. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  279. grid.Children.Add(checkBox);
  280. Grid.SetRow(checkBox, i);
  281. Grid.SetColumn(checkBox, 1);
  282. break;
  283. default:
  284. ComboBox comboBox = new ComboBox();
  285. comboBox.BorderBrush = Brushes.Transparent;
  286. //comboBox.Background = Brushes.White;
  287. string path = propertyInfo.Name;
  288. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  289. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  290. grid.Children.Add(comboBox);
  291. Grid.SetRow(comboBox, i);
  292. Grid.SetColumn(comboBox, 1);
  293. break;
  294. }
  295. }
  296. TextBlock textBlock = new TextBlock();
  297. textBlock.Text = propertyInfo.Name;
  298. grid.Children.Add(textBlock);
  299. Grid.SetRow(textBlock, i);
  300. Grid.SetColumn(textBlock, 0);
  301. i++;
  302. }
  303. ints.Add(unitType.GetProperties().Length);
  304. k++;
  305. });
  306. return new ValueTuple<Grid, List<int>>(grid, ints);
  307. }
  308. private void MenuItemInsert_Click(object sender, RoutedEventArgs e)
  309. {
  310. MenuItem item = sender as MenuItem;
  311. ContextMenu contextMenu = item.Parent as ContextMenu;
  312. Grid grid = contextMenu.Tag as Grid;
  313. int index = GridStackPanel.Children.IndexOf(grid);
  314. RecipeStep recipeStep = new RecipeStep();
  315. recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
  316. recipeStep.LstUnit.Add(new TCPUnit());
  317. recipeStep.LstUnit.Add(new BiasUnit());
  318. recipeStep.LstUnit.Add(new GasControlUnit());
  319. recipeStep.LstUnit.Add(new ESCHVUnit());
  320. recipeStep.LstUnit.Add(new ProcessKitUnit());
  321. CurrentRecipe.Steps.Insert(index , recipeStep);
  322. var item2 = RecipeStepToGrid(recipeStep);
  323. GridStackPanel.Children.Insert(index, item2.Item1);
  324. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  325. {
  326. CurrentRecipe.Steps[i].StepNo = i+1;
  327. }
  328. }
  329. private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
  330. {
  331. MenuItem item = sender as MenuItem;
  332. ContextMenu contextMenu = item.Parent as ContextMenu;
  333. Grid grid = contextMenu.Tag as Grid;
  334. int index = GridStackPanel.Children.IndexOf(grid);
  335. GridStackPanel.Children.Remove(grid);
  336. CurrentRecipe.Steps.RemoveAt(index);
  337. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  338. {
  339. CurrentRecipe.Steps[i].StepNo = i + 1;
  340. }
  341. }
  342. /// <summary>
  343. /// 获取父控件
  344. /// </summary>
  345. /// <typeparam name="T"></typeparam>
  346. /// <param name="obj"></param>
  347. /// <param name="name"></param>
  348. /// <returns></returns>
  349. public T GetParentObject2<T>(DependencyObject obj, string name) where T : FrameworkElement
  350. {
  351. DependencyObject parent = VisualTreeHelper.GetParent(obj);
  352. while (parent != null)
  353. {
  354. if (parent is T && (((T)parent).Name == name || string.IsNullOrEmpty(name)))
  355. {
  356. return (T)parent;
  357. }
  358. parent = VisualTreeHelper.GetParent(parent);
  359. }
  360. return null;
  361. }
  362. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  363. {
  364. if (e.RemovedItems.Count > 0)
  365. {
  366. ComboBox comboBox = sender as ComboBox;
  367. Grid grid = GetParentObject<Grid>(comboBox, "");
  368. int index= GridStackPanel.Children.IndexOf(grid);
  369. RecipeStep recipeStep = CurrentRecipe.Steps[index];
  370. recipeStep.LstUnit.RemoveAt(0);
  371. if (comboBox.SelectedIndex == 0)
  372. {
  373. recipeStep.LstUnit.Insert(0, new PressureByPressureModeUnit());
  374. }
  375. else
  376. {
  377. recipeStep.LstUnit.Insert(0, new PressureByValveModeUnit());
  378. }
  379. GridStackPanel.Children.Remove(grid);
  380. GridStackPanel.Children.Insert(index, RecipeStepToGrid(recipeStep).Item1);
  381. }
  382. }
  383. /// <summary>
  384. /// 获取父控件
  385. /// </summary>
  386. /// <typeparam name="T"></typeparam>
  387. /// <param name="obj"></param>
  388. /// <param name="name"></param>
  389. /// <returns></returns>
  390. public T GetParentObject<T>(DependencyObject obj, string name) where T : FrameworkElement
  391. {
  392. DependencyObject parent = VisualTreeHelper.GetParent(obj);
  393. while (parent != null)
  394. {
  395. if (parent is T && (((T)parent).Name == name || string.IsNullOrEmpty(name)))
  396. {
  397. return (T)parent;
  398. }
  399. parent = VisualTreeHelper.GetParent(parent);
  400. }
  401. return null;
  402. }
  403. private Tuple<DataGrid,List<int>> RecipeStepToDataGrid(RecipeStep recipeStep)
  404. {
  405. DataGrid dataGrid = new DataGrid();
  406. List<int> ints = new List<int>();
  407. DataTable dataTable = new DataTable();
  408. dataTable.Columns.Add("Key");
  409. dataTable.Columns.Add("Value");
  410. dataGrid.CanUserAddRows = false;
  411. dataGrid.AutoGenerateColumns = true;
  412. dataGrid.SelectionUnit = DataGridSelectionUnit.Cell;
  413. dataGrid.SetValue(System.Windows.Controls.VirtualizingStackPanel.IsVirtualizingProperty, false);
  414. Type recipeType = recipeStep.GetType();
  415. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  416. {
  417. if (propertyInfo.Name != "LstUnit")
  418. {
  419. dataTable.Rows.Add(propertyInfo.Name, propertyInfo.GetValue(recipeStep));
  420. }
  421. }
  422. ints.Add(dataTable.Rows.Count);
  423. recipeStep.LstUnit.ToList().ForEach(k =>
  424. {
  425. //List<dynamic> dynamics = new List<dynamic>();
  426. Type type = k.GetType();
  427. ints.Add(type.GetProperties().Length);
  428. foreach (PropertyInfo propertyInfo in type.GetProperties())
  429. {
  430. var name = propertyInfo.Name;
  431. var value = propertyInfo.GetValue(k);
  432. //dynamicModel.PropertyName = name;
  433. //dynamicModel.Property = value;
  434. dataTable.Rows.Add(name, value);
  435. }
  436. });
  437. dataGrid.ItemsSource = dataTable.DefaultView;
  438. //});
  439. return new Tuple<DataGrid, List<int>>(dataGrid, ints);
  440. }
  441. private void ChangeDataGridRowColor(DataGrid dataGrid,List<int> ints)
  442. {
  443. int count = 0;
  444. for (int i = 0; i < ints.Count; i++)
  445. {
  446. for (int j = 0; j < ints[i]; j++)
  447. {
  448. dataGrid.UpdateLayout();
  449. int index = count + j;
  450. DataGridRow row = dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.Items[index]) as DataGridRow;
  451. row.Background = solidColorBrushes[i];
  452. }
  453. count += ints[i];
  454. }
  455. }
  456. private void ChangeGridRowColor(Grid grid, List<int> ints)
  457. {
  458. int count = 0;
  459. for (int i = 0; i < ints.Count; i++)
  460. {
  461. for (int j = 0; j < ints[i]; j++)
  462. {
  463. //dataGrid.UpdateLayout();
  464. int index = count + j;
  465. //DataGridRow row = dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.Items[index]) as DataGridRow;
  466. //grid.RowDefinitions[index]
  467. }
  468. count += ints[i];
  469. }
  470. }
  471. #region 旧代码
  472. /// <summary>
  473. /// Open local recipe operation
  474. /// </summary>
  475. /// <param name="recipeDefineFilePath"></param>
  476. //public void OpenLocalRecipe(string recipeVariationName = "")
  477. //{
  478. // var dlg = new OpenFileDialog();
  479. // dlg.DefaultExt = ".rcp";
  480. // dlg.Filter = "Recipe File (.rcp)|*.rcp|All (*.*)|*.*";
  481. // if (dlg.ShowDialog() == true)
  482. // {
  483. // try
  484. // {
  485. // XmlDocument rcpDoc = new XmlDocument();
  486. // rcpDoc.Load(dlg.FileName);
  487. // string recipeVariation = recipeVariationName;
  488. // if (string.IsNullOrEmpty(recipeVariation))
  489. // {
  490. // var root = rcpDoc.SelectSingleNode("/TableRecipeData") as XmlElement;
  491. // recipeVariation = root.Attributes["RecipeVersion"].Value;
  492. // }
  493. // var startupPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
  494. // string dir = System.IO.Path.GetDirectoryName(startupPath);
  495. // List<Aitex.Controls.RecipeCompare.Item> map = CustomXmlSerializer.Deserialize<List<Aitex.Controls.RecipeCompare.Item>>(new System.IO.FileInfo(System.IO.Path.Combine(dir, "map.xml")));
  496. // Func<Aitex.Controls.RecipeCompare.Item, bool> predicate = item => item.Name.Equals(recipeVariation);
  497. // System.IO.FileInfo fi = new System.IO.FileInfo(string.Format("{0}\\config\\{1}.xml", dir, map.Any(predicate) ? map.Single(predicate).No : recipeVariation));
  498. // if (fi.Exists)
  499. // {
  500. // XmlDocument doc = new XmlDocument();
  501. // doc.Load(fi.FullName);
  502. // string formatXml = doc.SelectSingleNode("/Aitex/TableRecipeFormat").OuterXml;
  503. // string recipeXml = rcpDoc.SelectSingleNode("/TableRecipeData").OuterXml;
  504. // //LoadRecipe(formatXml, recipeXml);
  505. // if (OnLocalRecipeOpened != null)
  506. // OnLocalRecipeOpened.Invoke(new Tuple<string, string>(recipeVariation, dlg.FileName), null);
  507. // }
  508. // else
  509. // {
  510. // MessageBox.Show(string.Format("工艺程序版本{0}的描述文件不存在,无法正确识别该版本的工艺程序文件。", recipeVariation), "工艺程序打开失败",
  511. // MessageBoxButton.OK, MessageBoxImage.Error);
  512. // }
  513. // }
  514. // catch (Exception ex)
  515. // {
  516. // System.Diagnostics.Debug.WriteLine(ex.Message);
  517. // MessageBox.Show(string.Format("open recipe {0} failed,please confirm the recipe file is exist and valid。\r\n{1}", dlg.FileName, ex.Message), "Open recipe failed",
  518. // MessageBoxButton.OK, MessageBoxImage.Error);
  519. // }
  520. // }
  521. //}
  522. /// <summary>
  523. /// Save recipe file
  524. /// </summary>
  525. //private void SaveRecipeFile()
  526. //{
  527. // //try
  528. // //{
  529. // // if (Errors != null && Errors.Count > 0)
  530. // // {
  531. // // var ret = MessageBox.Show(string.Format("Recipe have {0} error,continue save?", Errors.Count), "Save", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
  532. // // if (ret != MessageBoxResult.Yes)
  533. // // return;
  534. // // }
  535. // // if (OnSaveRecipeFile != null)
  536. // // {
  537. // // IsRecipeModified = false;
  538. // // }
  539. // //}
  540. // //catch (Exception ex)
  541. // //{
  542. // // System.Diagnostics.Debug.WriteLine(ex.Message);
  543. // // MessageBox.Show("save recipe failed!\r\n\r\n" + ex.Message, "Save", MessageBoxButton.OK, MessageBoxImage.Warning);
  544. // //}
  545. //}
  546. /// <summary>
  547. /// calc recipe total time
  548. /// </summary>
  549. private void CalcRecipeTime()
  550. {
  551. //int timeStepRowId = -1;
  552. //int loopStepRowId = -1;
  553. //for (int i = 0; i < RecipeRows.Count; i++)
  554. //{
  555. // if (RecipeRows[i].TechnicalName == "Time")
  556. // timeStepRowId = i;
  557. // if (RecipeRows[i].TechnicalName == "Loop")
  558. // loopStepRowId = i;
  559. // if (loopStepRowId != -1 && timeStepRowId != -1)
  560. // break;
  561. //}
  562. //TimeSpan tspan = new TimeSpan();
  563. //for (int stepNo = 0; stepNo < RecipeRows[timeStepRowId].RecipeItems.Count; stepNo++)
  564. //{
  565. // string loopStr = RecipeRows[loopStepRowId].RecipeItems[stepNo].Value;
  566. // bool isLoopStart = Regex.IsMatch(loopStr, @"^Loop\x20\d+$");
  567. // if (isLoopStart)
  568. // {
  569. // int loopNum = int.Parse(loopStr.ToLower().Replace("loop", "").Replace(" ", ""));
  570. // TimeSpan ts = new TimeSpan();
  571. // for (int innerStepNo = stepNo; innerStepNo < RecipeRows[timeStepRowId].RecipeItems.Count; innerStepNo++)
  572. // {
  573. // loopStr = RecipeRows[loopStepRowId].RecipeItems[innerStepNo].Value;
  574. // stepNo = innerStepNo;
  575. // string timeDuration = RecipeRows[timeStepRowId].RecipeItems[innerStepNo].Value;
  576. // string[] timeArr = timeDuration.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  577. // if (timeArr.Length == 3)
  578. // {
  579. // int h, mi, s;
  580. // if (int.TryParse(timeArr[0], out h) && int.TryParse(timeArr[1], out mi) && int.TryParse(timeArr[2], out s))
  581. // {
  582. // var tt = new TimeSpan(h, mi, s);
  583. // ts += tt;
  584. // }
  585. // }
  586. // bool isLoopEnd = Regex.IsMatch(loopStr, @"^Loop End$");
  587. // if (isLoopEnd)
  588. // {
  589. // tspan += new TimeSpan(ts.Ticks * loopNum);
  590. // break;
  591. // }
  592. // }
  593. // }
  594. // else
  595. // {
  596. // string timeDuration = RecipeRows[timeStepRowId].RecipeItems[stepNo].Value;
  597. // string[] timeArr = timeDuration.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  598. // if (timeArr.Length == 3)
  599. // {
  600. // int h, mi, s;
  601. // if (int.TryParse(timeArr[0], out h) && int.TryParse(timeArr[1], out mi) && int.TryParse(timeArr[2], out s))
  602. // {
  603. // var ts = new TimeSpan(h, mi, s);
  604. // tspan += ts;
  605. // }
  606. // }
  607. // }
  608. //}
  609. //RecipeInfo = string.Format("共{0}步,总时间{1}:{2}:{3}", RecipeRows[0].RecipeItems.Count, (int)tspan.TotalHours, tspan.Minutes.ToString("00"), tspan.Seconds.ToString("00"));
  610. //InvokePropertyChanged("RecipeInfo");
  611. }
  612. #region INotifyPropertyChanged
  613. public event PropertyChangedEventHandler PropertyChanged;
  614. public void InvokePropertyChanged(string propertyName)
  615. {
  616. if (PropertyChanged != null)
  617. {
  618. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  619. }
  620. }
  621. #endregion INotifyPropertyChanged
  622. }
  623. //public class RecipeRow
  624. //{
  625. // //private ObservableCollection<SmartCellData> _recipeItems = new ObservableCollection<SmartCellData>();
  626. // //public RecipeRow(params SmartCellData[] vars)
  627. // //{
  628. // // foreach (var var in vars)
  629. // // _recipeItems.Add(var);
  630. // //}
  631. // //public string CatalogName { get; set; }
  632. // //public string FriendlyName { get; set; }
  633. // //public string TechnicalName { get; set; }
  634. // //public ObservableCollection<SmartCellData> RecipeItems
  635. // //{
  636. // // get { return _recipeItems; }
  637. // // set { _recipeItems = value; }
  638. // //}
  639. //}
  640. ///// <summary>
  641. ///// Recipe head
  642. ///// </summary>
  643. //public class RecipeHead
  644. //{
  645. // //public string RecipeVariation { get; set; }
  646. // //public string CreationTime { get; set; }
  647. // //public string LastRevisionTime { get; set; }
  648. // //public string CreatedBy { get; set; }
  649. // //public string LastModifiedBy { get; set; }
  650. // //public string PressureMode { get; set; }
  651. // //public string Description { get; set; }
  652. // //public string BasePressure
  653. // //{
  654. // // get; set;
  655. // //}
  656. // //public string PumpDownLimit
  657. // //{
  658. // // get; set;
  659. // //}
  660. // //public string PurgeActive
  661. // //{
  662. // // get; set;
  663. // //}
  664. // //public string NotToPurgeOrVent
  665. // //{
  666. // // get; set;
  667. // //}
  668. // //public string Barcode
  669. // //{
  670. // // get; set;
  671. // //}
  672. // //public string SubstrateTemp
  673. // //{
  674. // // get; set;
  675. // //}
  676. // //public string PumpingPinState
  677. // //{
  678. // // get; set;
  679. // //}
  680. // //public string VentingPinState
  681. // //{
  682. // // get; set;
  683. // //}
  684. // //public string PinDownPressure
  685. // //{
  686. // // get; set;
  687. // //}
  688. //}
  689. //public class EndPointConfigItem : INotifyPropertyChanged
  690. //{
  691. // public event PropertyChangedEventHandler PropertyChanged;
  692. // public void InvokePropertyChanged(string propertyName)
  693. // {
  694. // if (PropertyChanged != null)
  695. // {
  696. // PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  697. // }
  698. // }
  699. // //public string ExposureTime { get; set; }
  700. // //public string WaveLengthA { get; set; }
  701. // //public string BinningA { get; set; }
  702. // //public string WaveLengthB { get; set; }
  703. // //public string BinningB { get; set; }
  704. // //public string WaveLengthC { get; set; }
  705. // //public string BinningC { get; set; }
  706. // //public string WaveLengthD { get; set; }
  707. // //public string BinningD { get; set; }
  708. // //public string Fd { get; set; }
  709. // //public string PrefilterTime { get; set; }
  710. // //public string PostfilterTime { get; set; }
  711. // //public string AlgorithmType { get; set; }
  712. // //public string Criteria { get; set; }
  713. // //public string DelayTime { get; set; }
  714. // //public string ValidationTime { get; set; }
  715. // //public string ValidationValue { get; set; }
  716. // //public string TimeWindow { get; set; }
  717. // //public string MinimalTime { get; set; }
  718. // //public string PostponeTime { get; set; }
  719. // //public bool Control { get; set; }
  720. // //public bool Normalization { get; set; }
  721. // //public bool EnablePostponePercent { get; set; }
  722. // //public bool EnableCriterialPercent { get; set; }
  723. // //public bool EnableEventTrigger { get; set; }
  724. // //public bool IsFaultIfNoTrigger { get; set; }
  725. // //public string ToValue()
  726. // //{
  727. // // return
  728. // // $@"ExposureTime={ExposureTime};WaveLengthA={WaveLengthA};BinningA={BinningA};WaveLengthB={WaveLengthB};" +
  729. // // $@"BinningB={BinningB};WaveLengthC={WaveLengthC};BinningC={BinningC};WaveLengthD={WaveLengthD};BinningD={BinningD};Fd={Fd};" +
  730. // // $@"PrefilterTime={PrefilterTime};PostfilterTime={PostfilterTime};AlgorithmType={AlgorithmType};Criteria={Criteria};DelayTime={DelayTime};ValidationTime={ValidationTime};" +
  731. // // $@"ValidationValue={ValidationValue};TimeWindow={TimeWindow};MinimalTime={MinimalTime};PostponeTime={PostponeTime};Control={Control};Normalization={Normalization};" +
  732. // // $@"EnablePostponePercent={EnablePostponePercent};EnableCriterialPercent={EnableCriterialPercent};EnableEventTrigger={EnableEventTrigger};IsFaultIfNoTrigger={IsFaultIfNoTrigger};"
  733. // // ;
  734. // //}
  735. // //public void SetValue(string config)
  736. // //{
  737. // // if (string.IsNullOrEmpty(config))
  738. // // return;
  739. // // string[] items = config.Split(';');
  740. // // foreach (var item in items)
  741. // // {
  742. // // if (string.IsNullOrEmpty(item))
  743. // // continue;
  744. // // string[] pairs = item.Split('=');
  745. // // if (pairs.Length != 2)
  746. // // continue;
  747. // // Parallel.ForEach(this.GetType().GetProperties(),
  748. // // property =>
  749. // // {
  750. // // PropertyInfo pi = (PropertyInfo) property;
  751. // // if (pi.Name == pairs[0])
  752. // // {
  753. // // try
  754. // // {
  755. // // var convertedValue = Convert.ChangeType(pairs[1], pi.PropertyType);
  756. // // var originValue = Convert.ChangeType(pi.GetValue(this, null), pi.PropertyType);
  757. // // if (originValue != convertedValue)
  758. // // {
  759. // // pi.SetValue(this, convertedValue, null);
  760. // // }
  761. // // }
  762. // // catch (Exception)
  763. // // {
  764. // // }
  765. // // }
  766. // // });
  767. // // }
  768. // //}
  769. //}
  770. #endregion
  771. }