RecipeEditorControlViewModel.cs 32 KB

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