ProcessHistoryViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. using MECF.Framework.Common.DataCenter;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Windows.Media;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Venus_Core;
  10. using Prism.Commands;
  11. using Prism.Mvvm;
  12. using Venus_MainPages.Unity;
  13. using Venus_MainPages.Views;
  14. using System.Collections.ObjectModel;
  15. using System.Windows.Threading;
  16. using System.Windows;
  17. using Aitex.Core.RT.Log;
  18. using Aitex.Core.UI.ControlDataContext;
  19. using WPF.Themes.UserControls;
  20. using System.IO;
  21. using System.Diagnostics;
  22. using Aitex.Core.RT.Routine;
  23. using System.Xml.Linq;
  24. using System.Windows.Forms;
  25. using ExcelLibrary.BinaryFileFormat;
  26. using Aitex.Core.UI.View.Common;
  27. using Aitex.Core.RT.DataCenter;
  28. using System.Xml;
  29. using System.Security.Cryptography.X509Certificates;
  30. using System.Reflection;
  31. using Newtonsoft.Json;
  32. namespace Venus_MainPages.ViewModels
  33. {
  34. public class ProcessHistoryViewModel : BindableBase
  35. {
  36. #region 私有字段
  37. private ProcessHistoryView view;
  38. List<string> keys = new List<string>();
  39. RealtimeProvider _provider = new RealtimeProvider();
  40. private ObservableCollection<ParameterNode> _ParameterNodes;
  41. DispatcherTimer timer = new DispatcherTimer();
  42. ObservableCollection<PdKeyData> _PdKeyDataObservation = new ObservableCollection<PdKeyData>();
  43. public List<string> RecipesAdd = new List<string>();
  44. public List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>();
  45. DateTime currentTime;
  46. private RecipeItem selectedRecipeItem;
  47. #endregion
  48. #region 属性
  49. public List<HistoryDataItem> ProcessData { get; set; }
  50. public List<Recipeslist> CheboxRecipes { get; set; }
  51. public ProcessDataChartDataItem ProcessChartData { get; set; }
  52. public DateTime StartDateTime { get; set; }
  53. public DateTime EndDateTime { get; set; }
  54. public string SelectedValuePM { get; set; }
  55. public string RecipeName { get; set; }
  56. public ObservableCollection<PdKeyData> OldPdKeyDataCollection { get; set; }
  57. public ObservableCollection<RecipeItem> Recipes { get; set; }
  58. public class Recipeslist
  59. {
  60. public string BoxName { get; set; }
  61. }
  62. public class RecipeAdd
  63. {
  64. public string Recipesname { get; set; }
  65. }
  66. public ObservableCollection<ParameterNode> ParameterNodes
  67. {
  68. get { return _ParameterNodes; }
  69. set { SetProperty(ref _ParameterNodes, value); }
  70. }
  71. public ObservableCollection<PdKeyData> PdKeyDataCollection
  72. {
  73. get { return _PdKeyDataObservation; }
  74. set { SetProperty(ref _PdKeyDataObservation, value); }
  75. }
  76. #endregion
  77. #region 命令
  78. private DelegateCommand<object> _LoadCommandPD;
  79. public DelegateCommand<object> LoadCommandPD =>
  80. _LoadCommandPD ?? (_LoadCommandPD = new DelegateCommand<object>(OnLoadPd));
  81. private DelegateCommand _SearchRecipeCommand;
  82. public DelegateCommand SearchRecipeCommand =>
  83. _SearchRecipeCommand ?? (_SearchRecipeCommand = new DelegateCommand(SearchRecipes));
  84. private DelegateCommand<object> _PdParameterCheckCommand;
  85. public DelegateCommand<object> PdParameterCheckCommand =>
  86. _PdParameterCheckCommand ?? (_PdParameterCheckCommand = new DelegateCommand<object>(OnParameterCheck));
  87. private DelegateCommand<object> _DataGridSelectionChangedCommand;
  88. public DelegateCommand<object> DataGridSelectionChangedCommand =>
  89. _DataGridSelectionChangedCommand ?? (_DataGridSelectionChangedCommand = new DelegateCommand<object>(OnDataGridSelectionChanged));
  90. private DelegateCommand _SearchDataCommand;
  91. public DelegateCommand SearchDataCommand =>
  92. _SearchDataCommand ?? (_SearchDataCommand = new DelegateCommand(OnSearchData));
  93. private DelegateCommand _ClearDataCommand;
  94. public DelegateCommand ClearDataCommand =>
  95. _ClearDataCommand ?? (_ClearDataCommand = new DelegateCommand(OnClearData));
  96. #endregion
  97. #region 构造函数
  98. public ProcessHistoryViewModel()
  99. {
  100. ProcessChartData = new ProcessDataChartDataItem(60000);
  101. Recipes = new ObservableCollection<RecipeItem>();
  102. timer.Interval = TimeSpan.FromSeconds(0.5);
  103. OldPdKeyDataCollection = new ObservableCollection<PdKeyData>();
  104. CheboxRecipes = new List<Recipeslist>();
  105. solidColorBrushes.Add(new SolidColorBrush(Colors.Green));
  106. solidColorBrushes.Add(new SolidColorBrush(Colors.Red));
  107. solidColorBrushes.Add(new SolidColorBrush(Colors.Blue));
  108. solidColorBrushes.Add(new SolidColorBrush(Colors.Orange));
  109. solidColorBrushes.Add(new SolidColorBrush(Colors.Yellow));
  110. solidColorBrushes.Add(new SolidColorBrush(Colors.YellowGreen));
  111. solidColorBrushes.Add(new SolidColorBrush(Colors.AliceBlue));
  112. solidColorBrushes.Add(new SolidColorBrush(Colors.Chocolate));
  113. solidColorBrushes.Add(new SolidColorBrush(Colors.Cyan));
  114. solidColorBrushes.Add(new SolidColorBrush(Colors.DarkGreen));
  115. }
  116. #endregion
  117. #region 命令方法
  118. private void OnLoadPd(Object eventView)
  119. {
  120. this.view = (ProcessHistoryView)eventView;
  121. this.view.wfTimeFrom.Value = DateTime.Today;
  122. this.view.wfTimeTo.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59, 999);
  123. this.LoadRecipeCheckBox();
  124. }
  125. private void LoadRecipeCheckBox()
  126. {
  127. List<string> chamber = new List<string>() { "PMA", "PMB", "PMC", "PMD" };
  128. CheboxRecipes.Clear();
  129. foreach (string item in chamber)
  130. {
  131. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", item);
  132. if (Directory.Exists(path))
  133. {
  134. string[] dir = Directory.GetFiles(path);
  135. for (int i = 0; i < dir.Length; i++)
  136. {
  137. CheboxRecipes.Add(new Recipeslist { BoxName = Path.GetFileName(dir[i]) });
  138. }
  139. }
  140. }
  141. }
  142. public void SearchRecipes()
  143. {
  144. SearchRecipe(this.view.wfTimeFrom.Value, this.view.wfTimeTo.Value);
  145. }
  146. public void searchlot(string id)
  147. {
  148. Recipes.Clear();
  149. try
  150. {
  151. string sql1 = string.Format($"SELECT * FROM \"lot_wafer_data\" where guid ='{id}'; ");
  152. DataTable dbData1 = QueryDataClient.Instance.Service.QueryData(sql1);
  153. string lot_data_guid = dbData1.Rows[0]["wafer_data_guid"].ToString();
  154. string sql = string.Format($"SELECT * FROM \"process_data\" where guid ='{lot_data_guid}'");
  155. if (!string.IsNullOrEmpty(SelectedValuePM))
  156. {
  157. string[] pms = SelectedValuePM.Split(',');
  158. if (pms.Length > 0)
  159. {
  160. sql += " and (FALSE ";
  161. foreach (var pm in pms)
  162. {
  163. sql += $" OR \"process_in\"='{pm}' ";
  164. }
  165. sql += " ) ";
  166. }
  167. }
  168. if (!string.IsNullOrEmpty(RecipeName))
  169. {
  170. sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  171. }
  172. sql += " order by \"process_begin_time\" ASC;";
  173. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  174. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  175. {
  176. if (dbData == null || dbData.Rows.Count == 0) return;
  177. for (int i = 0; i < dbData.Rows.Count; i++)
  178. {
  179. RecipeItem item = new RecipeItem();
  180. item.Selected = false;
  181. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  182. item.Guid = dbData.Rows[i]["guid"].ToString();
  183. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  184. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  185. item.Status = dbData.Rows[i]["process_status"].ToString();
  186. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  187. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  188. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  189. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  190. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  191. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  192. Recipes.Add(item);
  193. }
  194. }));
  195. }
  196. catch (Exception e)
  197. {
  198. LOG.WriteExeption(e);
  199. }
  200. }
  201. public void SearchRecipe(DateTime start, DateTime end)
  202. {
  203. this.StartDateTime = start;
  204. this.EndDateTime = end;
  205. Recipes.Clear();
  206. try
  207. {
  208. string sql = $"SELECT * FROM \"process_data\" where \"process_begin_time\" >='{StartDateTime.ToString("yyyy/MM/dd HH:mm:ss.fff")}' and \"process_begin_time\" <='{EndDateTime.ToString("yyyy/MM/dd HH:mm:ss.fff")}' ";
  209. if (!string.IsNullOrEmpty(SelectedValuePM))
  210. {
  211. string[] pms = SelectedValuePM.Split(',');
  212. if (pms.Length > 0)
  213. {
  214. sql += " and (FALSE ";
  215. foreach (var pm in pms)
  216. {
  217. sql += $" OR \"process_in\"='{pm}' ";
  218. }
  219. sql += " ) ";
  220. }
  221. }
  222. if (!string.IsNullOrEmpty(RecipeName))
  223. {
  224. sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  225. }
  226. sql += " order by \"process_begin_time\" ASC;";
  227. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  228. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  229. {
  230. if (dbData == null || dbData.Rows.Count == 0) return;
  231. for (int i = 0; i < dbData.Rows.Count; i++)
  232. {
  233. RecipeItem item = new RecipeItem();
  234. item.Selected = false;
  235. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  236. item.Guid = dbData.Rows[i]["guid"].ToString();
  237. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  238. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  239. item.Status = dbData.Rows[i]["process_status"].ToString();
  240. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  241. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  242. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  243. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  244. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  245. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  246. Recipes.Add(item);
  247. }
  248. }));
  249. }
  250. catch (Exception e)
  251. {
  252. LOG.WriteExeption(e);
  253. }
  254. }
  255. private void CalKeys(ParameterNode parameterNode)
  256. {
  257. if (parameterNode.ChildNodes.Count > 0)
  258. {
  259. foreach (var item in parameterNode.ChildNodes)
  260. {
  261. CalKeys(item);
  262. }
  263. }
  264. else
  265. {
  266. if (parameterNode.Selected == true)
  267. {
  268. keys.Add(parameterNode.Name);
  269. }
  270. }
  271. }
  272. private Dictionary<string, List<HistoryDataItem>> GetData(List<string> keys, DateTime from, DateTime to)
  273. {
  274. string sql = "select time AS InternalTimeStamp";
  275. foreach (var dataId in keys)
  276. {
  277. sql += "," + string.Format("\"{0}\"", dataId);
  278. }
  279. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc",
  280. from.ToString("yyyyMMdd") + "." + "Data", from.Ticks, to.Ticks);
  281. DataTable dataTable = QueryDataClient.Instance.Service.QueryData(sql);
  282. Dictionary<string, List<HistoryDataItem>> historyData = new Dictionary<string, List<HistoryDataItem>>();
  283. if (dataTable == null || dataTable.Rows.Count == 0)
  284. return null;
  285. DateTime dt = new DateTime();
  286. Dictionary<int, string> colName = new Dictionary<int, string>();
  287. for (int colNo = 0; colNo < dataTable.Columns.Count; colNo++)
  288. {
  289. colName.Add(colNo, dataTable.Columns[colNo].ColumnName);
  290. historyData[dataTable.Columns[colNo].ColumnName] = new List<HistoryDataItem>();
  291. }
  292. for (int rowNo = 0; rowNo < dataTable.Rows.Count; rowNo++)
  293. {
  294. PointCollection points = new PointCollection();
  295. var row = dataTable.Rows[rowNo];
  296. for (int i = 0; i < dataTable.Columns.Count; i++)
  297. {
  298. HistoryDataItem data = new HistoryDataItem();
  299. if (i == 0)
  300. {
  301. long ticks = (long)row[i];
  302. dt = new DateTime(ticks);
  303. continue;
  304. }
  305. else
  306. {
  307. string dataId = colName[i];
  308. if (row[i] is DBNull || row[i] == null)
  309. {
  310. data.dateTime = dt;
  311. data.dbName = colName[i];
  312. data.value = 0;
  313. }
  314. else if (row[i] is bool)
  315. {
  316. data.dateTime = dt;
  317. data.dbName = colName[i];
  318. data.value = (bool)row[i] ? 1 : 0;
  319. }
  320. else
  321. {
  322. data.dateTime = dt;
  323. data.dbName = colName[i];
  324. data.value = float.Parse(row[i].ToString());
  325. }
  326. }
  327. historyData[data.dbName].Add(data);
  328. }
  329. }
  330. foreach (var item in historyData)
  331. {
  332. item.Value.Sort((x, y) => DateTime.Compare(x.dateTime, y.dateTime));
  333. }
  334. return historyData;
  335. }
  336. private bool RefreshTreeStatusToChild(ParameterNode node)
  337. {
  338. if (node.ChildNodes.Count > 0)
  339. {
  340. for (int i = 0; i < node.ChildNodes.Count; i++)
  341. {
  342. ParameterNode n = node.ChildNodes[i];
  343. n.Selected = node.Selected;
  344. if (!RefreshTreeStatusToChild(n))
  345. {
  346. //uncheck left node
  347. for (int j = i; j < node.ChildNodes.Count; j++)
  348. {
  349. node.ChildNodes[j].Selected = !node.Selected;
  350. }
  351. //node.Selected = !node.Selected;
  352. return false;
  353. }
  354. }
  355. }
  356. //else
  357. //{
  358. // if (node.Selected == true)
  359. // {
  360. // keys.Add(node.Name);
  361. // }
  362. // else
  363. // {
  364. // keys.Remove(node.Name);
  365. // }
  366. //}
  367. return true;
  368. }
  369. private void RefreshTreeStatusToParent(ParameterNode node)
  370. {
  371. if (node.ParentNode != null)
  372. {
  373. if (node.Selected)
  374. {
  375. bool flag = true;
  376. for (int i = 0; i < node.ParentNode.ChildNodes.Count; i++)
  377. {
  378. if (!node.ParentNode.ChildNodes[i].Selected)
  379. {
  380. flag = false; //as least one child is unselected
  381. break;
  382. }
  383. }
  384. if (flag)
  385. node.ParentNode.Selected = true;
  386. }
  387. else
  388. {
  389. node.ParentNode.Selected = false;
  390. }
  391. RefreshTreeStatusToParent(node.ParentNode);
  392. }
  393. }
  394. public static T DeepCopyJson<T>(T obj)
  395. {
  396. // 序列化
  397. string json = JsonConvert.SerializeObject(obj);
  398. // 反序列化
  399. return JsonConvert.DeserializeObject<T>(json);
  400. }
  401. private void OnParameterCheck(object obj)
  402. {
  403. ParameterNode node = obj as ParameterNode;
  404. if (!RefreshTreeStatusToChild(node))
  405. {
  406. node.Selected = !node.Selected;
  407. }
  408. else
  409. {
  410. RefreshTreeStatusToParent(node);
  411. }
  412. keys.Clear();
  413. for (int i = 0; i < ParameterNodes.Count; i++)
  414. {
  415. CalKeys(ParameterNodes[i]);
  416. }
  417. if (keys.Count > 10)
  418. {
  419. WPFMessageBox.ShowWarning("最多显示10个数据");
  420. return;
  421. }
  422. OldPdKeyDataCollection.Clear();
  423. OldPdKeyDataCollection = DeepCopyJson(PdKeyDataCollection);
  424. PdKeyDataCollection.Clear();
  425. for (int i = 0; i < keys.Count; i++)
  426. {
  427. if (i == 10)
  428. {
  429. break;
  430. }
  431. PdKeyDataCollection.Add(new PdKeyData() { Key = keys[i], Color = solidColorBrushes[i], UniqueId = i });
  432. }
  433. Compare(OldPdKeyDataCollection, PdKeyDataCollection);
  434. PdKeyDataCollection = DeepCopyJson(OldPdKeyDataCollection);
  435. }
  436. public void Compare(ObservableCollection<PdKeyData> olddata, ObservableCollection<PdKeyData> newdata)
  437. {
  438. if (newdata != null)
  439. {
  440. for (int i = 0; i < newdata.Count; i++)
  441. {
  442. var lists = olddata.ToList().Find(t => t.Key == newdata[i].Key);
  443. if (lists == null)
  444. {
  445. olddata.Add(new PdKeyData() { Key = newdata[i].Key, Color = solidColorBrushes[i], UniqueId = olddata.Count + 1 });
  446. }
  447. }
  448. for (int i = 0; i < olddata.Count; i++)
  449. {
  450. var lists = newdata.ToList().Find(t => t.Key == olddata[i].Key);
  451. if (lists == null)
  452. {
  453. olddata.Remove(olddata[i]);
  454. }
  455. }
  456. }
  457. }
  458. public void UpdateData(RecipeItem dataLog)
  459. {
  460. if (dataLog == null)
  461. {
  462. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  463. return;
  464. }
  465. keys.Clear();
  466. for (int i = 0; i < ParameterNodes.Count; i++)
  467. {
  468. CalKeys(ParameterNodes[i]);
  469. }
  470. if (keys.Count > 10)
  471. {
  472. WPFMessageBox.ShowWarning("最多显示10个数据");
  473. return;
  474. }
  475. //Application.Current.Dispatcher.Invoke(new Action(() =>
  476. //{
  477. // string type = "A";
  478. // string s = dataLog.Chamber;
  479. // if (dataLog.Chamber == "PMA")
  480. // {
  481. // //keys = new List<string> { "IO.PMA.AI_Chamber_Pressure", "PMA.Rf.PowerSetPoint", "PMA.Rf.ForwardPower", "PMA.Rf.ReflectPower", "PMA.IoMfc.MfcGas1.FeedBack", "PMA.IoMfc.MfcGas1.SetPoint", "PMA.IoMfc.MfcGas2.FeedBack", "PMA.IoMfc.MfcGas2.SetPoint", "PMA.IoMfc.MfcGas3.FeedBack", "PMA.IoMfc.MfcGas3.SetPoint" };
  482. // if ((bool)QueryDataClient.Instance.Service.GetConfig($"PMA.BiasRf.EnableBiasRF"))
  483. // type = "A";
  484. // }
  485. // else if (dataLog.Chamber == "PMB")
  486. // {
  487. // // keys = new List<string> { "IO.PMB.AI_Chamber_Pressure", "PMB.Rf.PowerSetPoint", "PMB.Rf.ForwardPower", "PMB.Rf.ReflectPower", "PMB.IoMfc.MfcGas1.FeedBack", "PMB.IoMfc.MfcGas1.SetPoint", "PMB.IoMfc.MfcGas2.FeedBack", "PMB.IoMfc.MfcGas2.SetPoint", "PMB.IoMfc.MfcGas3.FeedBack", "PMB.IoMfc.MfcGas3.SetPoint" };
  488. // if ((bool)QueryDataClient.Instance.Service.GetConfig($"PMB.BiasRf.EnableBiasRF"))
  489. // type = "B";
  490. // }
  491. //}));
  492. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  493. //DateTime dtFrom = dataLog.StartTime;
  494. DateTime dtFrom = Convert.ToDateTime(dataLog.StartTime);
  495. //DateTime dtTo = dtFrom.AddMinutes(10);
  496. DateTime dtTo = Convert.ToDateTime(dataLog.EndTime);
  497. //if (!string.IsNullOrEmpty(dataLog.EndTime))
  498. //{
  499. // dtTo = Convert.ToDateTime(dataLog.EndTime);
  500. //}
  501. var result = GetData(keys.Distinct().ToList(), dtFrom, dtTo);
  502. List<PointCollection> cls = new List<PointCollection>();
  503. for (int i = 0; i < keys.Count; i++)
  504. {
  505. PointCollection points = new PointCollection();
  506. int k = 1;
  507. result[keys[i]].ForEach(point =>
  508. {
  509. points.Add(new Point() { X = point.dateTime.ToOADate(), Y = point.value });
  510. k += 1;
  511. });
  512. cls.Add(points);
  513. }
  514. this.view.MyDrawGraphicsControl.PointCollections = cls;
  515. this.view.MyDrawGraphicsControl.FitControl();
  516. }
  517. public void OnDataGridSelectionChanged(object obj)
  518. {
  519. selectedRecipeItem = obj as RecipeItem;
  520. ParameterNodes = new ObservableCollection<ParameterNode>(_provider.GetParameters().Where(x => x.Name == selectedRecipeItem?.Chamber));
  521. }
  522. public void OnSearchData()
  523. {
  524. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  525. var Keys = new List<string>();
  526. PdKeyDataCollection.ToList().ForEach(key =>
  527. {
  528. Keys.Add(key.Key);
  529. });
  530. if (keys.Count == 0)
  531. {
  532. return;
  533. }
  534. var result = GetData(Keys.Distinct().ToList(), Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  535. if (result == null)
  536. {
  537. return;
  538. }
  539. List<PointCollection> cls = new List<PointCollection>();
  540. for (int i = 0; i < Keys.Count; i++)
  541. {
  542. PointCollection points = new PointCollection();
  543. int k = 1;
  544. result[Keys[i]].ForEach(point =>
  545. {
  546. points.Add(new Point() { X = point.dateTime.ToOADate(), Y = point.value });
  547. k += 1;
  548. });
  549. cls.Add(points);
  550. }
  551. this.view.MyDrawGraphicsControl.PointCollections = cls;
  552. this.view.MyDrawGraphicsControl.FitControl();
  553. }
  554. private void CloseAll(ObservableCollection<ParameterNode> parameterNodes)
  555. {
  556. foreach (var item in parameterNodes)
  557. {
  558. item.Selected = false;
  559. if (item.ChildNodes.Count > 0)
  560. {
  561. CloseAll(item.ChildNodes);
  562. }
  563. }
  564. }
  565. private void OnClearData()
  566. {
  567. PdKeyDataCollection.Clear();
  568. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  569. CloseAll(ParameterNodes);
  570. }
  571. }
  572. #endregion
  573. #region 数据类
  574. public class RecipeItem : BindableBase
  575. {
  576. public bool Selected { get; set; }
  577. public string Recipe { get; set; }
  578. public string Guid { get; set; }
  579. public string RecipeRunGuid { get; set; }
  580. public string Chamber { get; set; }
  581. public string Status { get; set; }
  582. public string StartTime { get; set; }
  583. public string EndTime { get; set; }
  584. public string LotID { get; set; }
  585. public string SlotID { get; set; }
  586. }
  587. public class PdKeyData : BindableBase, ICloneable
  588. {
  589. public string Key { get; set; }
  590. public SolidColorBrush _Color;
  591. public SolidColorBrush Color
  592. {
  593. get { return _Color; }
  594. set { SetProperty(ref _Color, value); }
  595. }
  596. public int UniqueId { get; set; }
  597. public object Clone()
  598. {
  599. return MemberwiseClone();
  600. }
  601. }
  602. #endregion
  603. }