ProcessHistoryViewModel.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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. using Venus_Themes.UserControls;
  33. using Aitex.Core.UI.Control;
  34. using System.Windows.Annotations;
  35. using System.Runtime.Serialization;
  36. using static System.Net.Mime.MediaTypeNames;
  37. namespace Venus_MainPages.ViewModels
  38. {
  39. public class ProcessHistoryViewModel : BindableBase
  40. {
  41. #region 私有字段
  42. private ProcessHistoryView view;
  43. List<string> keys = new List<string>();
  44. RealtimeProvider _provider = new RealtimeProvider();
  45. private ObservableCollection<ParameterNode> _ParameterNodes;
  46. DispatcherTimer timer = new DispatcherTimer();
  47. ObservableCollection<PdKeyData> _PdKeyDataObservation = new ObservableCollection<PdKeyData>();
  48. public List<string> RecipesAdd = new List<string>();
  49. public List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>();
  50. //DateTime currentTime;
  51. private RecipeItem selectedRecipeItem;
  52. private bool m_IsShowStep;
  53. private int m_PageCount;
  54. private int m_onePageCounts = 7;
  55. private int m_Total;
  56. private bool m_FirstLoadFlag = true;
  57. #endregion
  58. #region 属性
  59. public List<HistoryDataItem> ProcessData { get; set; }
  60. public List<Recipeslist> CheboxRecipes { get; set; }
  61. public ProcessDataChartDataItem ProcessChartData { get; set; }
  62. public DateTime StartDateTime { get; set; }
  63. public DateTime EndDateTime { get; set; }
  64. public string SelectedValuePM { get; set; }
  65. public string RecipeName { get; set; }
  66. public ObservableCollection<PdKeyData> OldPdKeyDataCollection { get; set; }
  67. public ObservableCollection<RecipeItem> Recipes { get; set; }
  68. public class Recipeslist
  69. {
  70. public string BoxName { get; set; }
  71. }
  72. public class RecipeAdd
  73. {
  74. public string Recipesname { get; set; }
  75. }
  76. public ObservableCollection<ParameterNode> ParameterNodes
  77. {
  78. get { return _ParameterNodes; }
  79. set { SetProperty(ref _ParameterNodes, value); }
  80. }
  81. public ObservableCollection<PdKeyData> PdKeyDataCollection
  82. {
  83. get { return _PdKeyDataObservation; }
  84. set { SetProperty(ref _PdKeyDataObservation, value); }
  85. }
  86. public bool IsShowStep
  87. {
  88. get { return m_IsShowStep; }
  89. set { SetProperty(ref m_IsShowStep, value); }
  90. }
  91. public int PageCount
  92. {
  93. get { return m_PageCount; }
  94. set
  95. {
  96. SetProperty(ref m_PageCount, value);
  97. }
  98. }
  99. public int Total
  100. {
  101. get { return m_Total; }
  102. set
  103. {
  104. SetProperty(ref m_Total, value);
  105. }
  106. }
  107. #endregion
  108. #region 命令
  109. private DelegateCommand<object> _LoadCommandPD;
  110. public DelegateCommand<object> LoadCommandPD =>
  111. _LoadCommandPD ?? (_LoadCommandPD = new DelegateCommand<object>(OnLoadPd));
  112. private DelegateCommand _SearchRecipeCommand;
  113. public DelegateCommand SearchRecipeCommand =>
  114. _SearchRecipeCommand ?? (_SearchRecipeCommand = new DelegateCommand(SearchRecipes));
  115. private DelegateCommand<object> _PdParameterCheckCommand;
  116. public DelegateCommand<object> PdParameterCheckCommand =>
  117. _PdParameterCheckCommand ?? (_PdParameterCheckCommand = new DelegateCommand<object>(OnParameterCheck));
  118. private DelegateCommand<object> _DataGridSelectionChangedCommand;
  119. public DelegateCommand<object> DataGridSelectionChangedCommand =>
  120. _DataGridSelectionChangedCommand ?? (_DataGridSelectionChangedCommand = new DelegateCommand<object>(OnDataGridSelectionChanged));
  121. private DelegateCommand _SearchDataCommand;
  122. public DelegateCommand SearchDataCommand =>
  123. _SearchDataCommand ?? (_SearchDataCommand = new DelegateCommand(OnSearchData));
  124. private DelegateCommand _ClearDataCommand;
  125. public DelegateCommand ClearDataCommand =>
  126. _ClearDataCommand ?? (_ClearDataCommand = new DelegateCommand(OnClearData));
  127. #endregion
  128. #region 构造函数
  129. public ProcessHistoryViewModel()
  130. {
  131. ProcessData = new List<HistoryDataItem>() { };
  132. ProcessChartData = new ProcessDataChartDataItem(60000);
  133. Recipes = new ObservableCollection<RecipeItem>();
  134. timer.Interval = TimeSpan.FromSeconds(0.5);
  135. OldPdKeyDataCollection = new ObservableCollection<PdKeyData>();
  136. CheboxRecipes = new List<Recipeslist>();
  137. solidColorBrushes.Add(new SolidColorBrush(Colors.Green));
  138. solidColorBrushes.Add(new SolidColorBrush(Colors.Red));
  139. solidColorBrushes.Add(new SolidColorBrush(Colors.Blue));
  140. solidColorBrushes.Add(new SolidColorBrush(Colors.Orange));
  141. solidColorBrushes.Add(new SolidColorBrush(Colors.Yellow));
  142. solidColorBrushes.Add(new SolidColorBrush(Colors.YellowGreen));
  143. solidColorBrushes.Add(new SolidColorBrush(Colors.AliceBlue));
  144. solidColorBrushes.Add(new SolidColorBrush(Colors.Chocolate));
  145. solidColorBrushes.Add(new SolidColorBrush(Colors.Cyan));
  146. solidColorBrushes.Add(new SolidColorBrush(Colors.DarkGreen));
  147. }
  148. #endregion
  149. #region 命令方法
  150. private void OnLoadPd(Object eventView)
  151. {
  152. if (m_FirstLoadFlag)
  153. {
  154. this.view = (ProcessHistoryView)eventView;
  155. this.view.wfTimeFrom.Value = DateTime.Today;
  156. this.view.wfTimeTo.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59, 999);
  157. this.LoadRecipeCheckBox();
  158. this.view.pageControl.CurrentPageChanged += PageControl_CurrentPageChanged;
  159. }
  160. }
  161. private void PageControl_CurrentPageChanged(int currentPage)
  162. {
  163. PageChanged(currentPage);
  164. }
  165. public void PageChanged(int CurrentPage)
  166. {
  167. Recipes.Clear();
  168. 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")}' ";
  169. if (!string.IsNullOrEmpty(SelectedValuePM))
  170. {
  171. string[] pms = SelectedValuePM.Split(',');
  172. if (pms.Length > 0)
  173. {
  174. sql += " and (FALSE ";
  175. foreach (var pm in pms)
  176. {
  177. sql += $" OR \"process_in\"='{pm}' ";
  178. }
  179. sql += " ) ";
  180. }
  181. }
  182. if (!string.IsNullOrEmpty(RecipeName))
  183. {
  184. sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  185. }
  186. sql += $" order by \"process_begin_time\" ASC limit {m_onePageCounts} offset {(CurrentPage - 1) * m_onePageCounts};";
  187. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  188. if (dbData == null || dbData.Rows.Count == 0) return;
  189. for (int i = 0; i < dbData.Rows.Count; i++)
  190. {
  191. RecipeItem item = new RecipeItem();
  192. item.Selected = false;
  193. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  194. item.Guid = dbData.Rows[i]["guid"].ToString();
  195. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  196. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  197. item.Status = dbData.Rows[i]["process_status"].ToString();
  198. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  199. item.RecipeType = dbData.Rows[i]["recipe_type"].ToString();
  200. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  201. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  202. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  203. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  204. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  205. Recipes.Add(item);
  206. }
  207. }
  208. private void LoadRecipeCheckBox()
  209. {
  210. List<string> chamber = new List<string>() { "PMA", "PMB", "PMC", "PMD" };
  211. CheboxRecipes.Clear();
  212. foreach (string item in chamber)
  213. {
  214. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", item);
  215. if (Directory.Exists(path))
  216. {
  217. string[] dir = Directory.GetFiles(path);
  218. for (int i = 0; i < dir.Length; i++)
  219. {
  220. CheboxRecipes.Add(new Recipeslist { BoxName = Path.GetFileName(dir[i]) });
  221. }
  222. }
  223. }
  224. }
  225. public void SearchRecipes()
  226. {
  227. SearchRecipe(this.view.wfTimeFrom.Value, this.view.wfTimeTo.Value);
  228. }
  229. public void searchlot(string id)
  230. {
  231. Recipes.Clear();
  232. try
  233. {
  234. string sql1 = string.Format($"SELECT * FROM \"lot_wafer_data\" where guid ='{id}'; ");
  235. DataTable dbData1 = QueryDataClient.Instance.Service.QueryData(sql1);
  236. string lot_data_guid = dbData1.Rows[0]["wafer_data_guid"].ToString();
  237. string sql = string.Format($"SELECT * FROM \"process_data\" where wafer_data_guid ='{lot_data_guid}'");
  238. if (!string.IsNullOrEmpty(SelectedValuePM))
  239. {
  240. string[] pms = SelectedValuePM.Split(',');
  241. if (pms.Length > 0)
  242. {
  243. sql += " and (FALSE ";
  244. foreach (var pm in pms)
  245. {
  246. sql += $" OR \"process_in\"='{pm}' ";
  247. }
  248. sql += " ) ";
  249. }
  250. }
  251. if (!string.IsNullOrEmpty(RecipeName))
  252. {
  253. sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  254. }
  255. sql += " order by \"process_begin_time\" ASC;";
  256. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  257. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  258. {
  259. if (dbData == null || dbData.Rows.Count == 0) return;
  260. for (int i = 0; i < dbData.Rows.Count; i++)
  261. {
  262. RecipeItem item = new RecipeItem();
  263. item.Selected = false;
  264. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  265. item.Guid = dbData.Rows[i]["guid"].ToString();
  266. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  267. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  268. item.Status = dbData.Rows[i]["process_status"].ToString();
  269. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  270. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  271. item.RecipeType = dbData.Rows[i]["recipe_type"].ToString();
  272. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  273. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  274. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  275. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  276. Recipes.Add(item);
  277. }
  278. }));
  279. }
  280. catch (Exception e)
  281. {
  282. LOG.WriteExeption(e);
  283. }
  284. }
  285. public void SearchRecipe(DateTime start, DateTime end)
  286. {
  287. this.StartDateTime = start;
  288. this.EndDateTime = end;
  289. Recipes.Clear();
  290. try
  291. {
  292. string sqlGetCount = $"SELECT COUNT(*) 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")}' ";
  293. if (!string.IsNullOrEmpty(SelectedValuePM))
  294. {
  295. string[] pms = SelectedValuePM.Split(',');
  296. if (pms.Length > 0)
  297. {
  298. sqlGetCount += " and (FALSE ";
  299. foreach (var pm in pms)
  300. {
  301. sqlGetCount += $" OR \"process_in\"='{pm}' ";
  302. }
  303. sqlGetCount += " ) ";
  304. }
  305. }
  306. if (!string.IsNullOrEmpty(RecipeName))
  307. {
  308. sqlGetCount += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  309. }
  310. sqlGetCount += " ;";
  311. Total = QueryDataClient.Instance.Service.GetDBEventAllCount(sqlGetCount);
  312. PageCount = (Total / m_onePageCounts) + 1;
  313. 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")}' ";
  314. if (!string.IsNullOrEmpty(SelectedValuePM))
  315. {
  316. string[] pms = SelectedValuePM.Split(',');
  317. if (pms.Length > 0)
  318. {
  319. sql += " and (FALSE ";
  320. foreach (var pm in pms)
  321. {
  322. sql += $" OR \"process_in\"='{pm}' ";
  323. }
  324. sql += " ) ";
  325. }
  326. }
  327. if (!string.IsNullOrEmpty(RecipeName))
  328. {
  329. sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  330. }
  331. sql += $" order by \"process_begin_time\" ASC limit {m_onePageCounts} offset {(1 - 1) * m_onePageCounts};";
  332. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  333. if (dbData == null || dbData.Rows.Count == 0) return;
  334. for (int i = 0; i < dbData.Rows.Count; i++)
  335. {
  336. RecipeItem item = new RecipeItem();
  337. item.Selected = false;
  338. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  339. item.Guid = dbData.Rows[i]["guid"].ToString();
  340. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  341. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  342. item.Status = dbData.Rows[i]["process_status"].ToString();
  343. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  344. item.RecipeType = dbData.Rows[i]["recipe_type"].ToString();
  345. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  346. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  347. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  348. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  349. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  350. Recipes.Add(item);
  351. }
  352. }
  353. catch (Exception e)
  354. {
  355. LOG.WriteExeption(e);
  356. }
  357. }
  358. private void CalKeys(ParameterNode parameterNode)
  359. {
  360. if (parameterNode.ChildNodes.Count > 0)
  361. {
  362. foreach (var item in parameterNode.ChildNodes)
  363. {
  364. CalKeys(item);
  365. }
  366. }
  367. else
  368. {
  369. if (parameterNode.Selected == true)
  370. {
  371. keys.Add(parameterNode.Name);
  372. }
  373. }
  374. }
  375. private Dictionary<string, List<HistoryDataItem>> GetData(List<string> keys, DateTime from, DateTime to)
  376. {
  377. string sql = "select time AS InternalTimeStamp";
  378. foreach (var dataId in keys)
  379. {
  380. sql += "," + string.Format("\"{0}\"", dataId);
  381. }
  382. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc",
  383. from.ToString("yyyyMMdd") + "." + "Data", from.Ticks, to.Ticks);
  384. DataTable dataTable = QueryDataClient.Instance.Service.QueryData(sql);
  385. Dictionary<string, List<HistoryDataItem>> historyData = new Dictionary<string, List<HistoryDataItem>>();
  386. if (dataTable == null || dataTable.Rows.Count == 0)
  387. return null;
  388. DateTime dt = new DateTime();
  389. Dictionary<int, string> colName = new Dictionary<int, string>();
  390. for (int colNo = 0; colNo < dataTable.Columns.Count; colNo++)
  391. {
  392. colName.Add(colNo, dataTable.Columns[colNo].ColumnName);
  393. historyData[dataTable.Columns[colNo].ColumnName] = new List<HistoryDataItem>();
  394. }
  395. for (int rowNo = 0; rowNo < dataTable.Rows.Count; rowNo++)
  396. {
  397. PointCollection points = new PointCollection();
  398. var row = dataTable.Rows[rowNo];
  399. for (int i = 0; i < dataTable.Columns.Count; i++)
  400. {
  401. HistoryDataItem data = new HistoryDataItem();
  402. if (i == 0)
  403. {
  404. long ticks = (long)row[i];
  405. dt = new DateTime(ticks);
  406. continue;
  407. }
  408. else
  409. {
  410. string dataId = colName[i];
  411. if (row[i] is DBNull || row[i] == null)
  412. {
  413. data.dateTime = dt;
  414. data.dbName = colName[i];
  415. data.value = 0;
  416. }
  417. else if (row[i] is bool)
  418. {
  419. data.dateTime = dt;
  420. data.dbName = colName[i];
  421. data.value = (bool)row[i] ? 1 : 0;
  422. }
  423. else
  424. {
  425. data.dateTime = dt;
  426. data.dbName = colName[i];
  427. data.value = float.Parse(row[i].ToString());
  428. }
  429. }
  430. historyData[data.dbName].Add(data);
  431. }
  432. }
  433. foreach (var item in historyData)
  434. {
  435. item.Value.Sort((x, y) => DateTime.Compare(x.dateTime, y.dateTime));
  436. }
  437. return historyData;
  438. }
  439. private bool RefreshTreeStatusToChild(ParameterNode node)
  440. {
  441. if (node.ChildNodes.Count > 0)
  442. {
  443. for (int i = 0; i < node.ChildNodes.Count; i++)
  444. {
  445. ParameterNode n = node.ChildNodes[i];
  446. n.Selected = node.Selected;
  447. if (!RefreshTreeStatusToChild(n))
  448. {
  449. //uncheck left node
  450. for (int j = i; j < node.ChildNodes.Count; j++)
  451. {
  452. node.ChildNodes[j].Selected = !node.Selected;
  453. }
  454. //node.Selected = !node.Selected;
  455. return false;
  456. }
  457. }
  458. }
  459. //else
  460. //{
  461. // if (node.Selected == true)
  462. // {
  463. // keys.Add(node.Name);
  464. // }
  465. // else
  466. // {
  467. // keys.Remove(node.Name);
  468. // }
  469. //}
  470. return true;
  471. }
  472. private void RefreshTreeStatusToParent(ParameterNode node)
  473. {
  474. if (node.ParentNode != null)
  475. {
  476. if (node.Selected)
  477. {
  478. bool flag = true;
  479. for (int i = 0; i < node.ParentNode.ChildNodes.Count; i++)
  480. {
  481. if (!node.ParentNode.ChildNodes[i].Selected)
  482. {
  483. flag = false; //as least one child is unselected
  484. break;
  485. }
  486. }
  487. if (flag)
  488. node.ParentNode.Selected = true;
  489. }
  490. else
  491. {
  492. node.ParentNode.Selected = false;
  493. }
  494. RefreshTreeStatusToParent(node.ParentNode);
  495. }
  496. }
  497. public static T DeepCopyJson<T>(T obj)
  498. {
  499. // 序列化
  500. string json = JsonConvert.SerializeObject(obj);
  501. // 反序列化
  502. return JsonConvert.DeserializeObject<T>(json);
  503. }
  504. private void OnParameterCheck(object obj)
  505. {
  506. ParameterNode node = obj as ParameterNode;
  507. if (!RefreshTreeStatusToChild(node))
  508. {
  509. node.Selected = !node.Selected;
  510. }
  511. else
  512. {
  513. RefreshTreeStatusToParent(node);
  514. }
  515. keys.Clear();
  516. for (int i = 0; i < ParameterNodes.Count; i++)
  517. {
  518. CalKeys(ParameterNodes[i]);
  519. }
  520. if (keys.Count > 10)
  521. {
  522. WPFMessageBox.ShowWarning("最多显示10个数据");
  523. return;
  524. }
  525. OldPdKeyDataCollection.Clear();
  526. OldPdKeyDataCollection = DeepCopyJson(PdKeyDataCollection);
  527. PdKeyDataCollection.Clear();
  528. for (int i = 0; i < keys.Count; i++)
  529. {
  530. if (i == 10)
  531. {
  532. break;
  533. }
  534. PdKeyDataCollection.Add(new PdKeyData() { Key = keys[i], Color = solidColorBrushes[i], UniqueId = i });
  535. }
  536. Compare(OldPdKeyDataCollection, PdKeyDataCollection);
  537. PdKeyDataCollection = DeepCopyJson(OldPdKeyDataCollection);
  538. }
  539. public void Compare(ObservableCollection<PdKeyData> olddata, ObservableCollection<PdKeyData> newdata)
  540. {
  541. if (newdata != null)
  542. {
  543. for (int i = 0; i < newdata.Count; i++)
  544. {
  545. var lists = olddata.ToList().Find(t => t.Key == newdata[i].Key);
  546. if (lists == null)
  547. {
  548. olddata.Add(new PdKeyData() { Key = newdata[i].Key, Color = solidColorBrushes[i], UniqueId = olddata.Count + 1 });
  549. }
  550. }
  551. for (int i = 0; i < olddata.Count; i++)
  552. {
  553. var lists = newdata.ToList().Find(t => t.Key == olddata[i].Key);
  554. if (lists == null)
  555. {
  556. olddata.Remove(olddata[i]);
  557. }
  558. }
  559. }
  560. }
  561. public void UpdateData(RecipeItem dataLog)
  562. {
  563. OnClearData();
  564. //CheckRecipe(dataLog.Guid);
  565. }
  566. public void CheckRecipe(string RecipeGuid)
  567. {
  568. string sql = $"SELECT * FROM \"recipe_step_data\" where \"process_data_guid\" = '{RecipeGuid}' order by step_number ASC;";
  569. var dbData = QueryDataClient.Instance.Service.QueryData(sql);
  570. List<StepData> steps = new List<StepData>();
  571. if (dbData != null && dbData.Rows.Count > 0)
  572. {
  573. for (int i = 0; i < dbData.Rows.Count; i++)
  574. {
  575. StepData item = new StepData();
  576. item.No = int.Parse(dbData.Rows[i]["step_number"].ToString());
  577. item.Name = dbData.Rows[i]["step_name"].ToString();
  578. if (!dbData.Rows[i]["step_begin_time"].Equals(DBNull.Value))
  579. item.StartTime = (DateTime)dbData.Rows[i]["step_begin_time"];
  580. if (!dbData.Rows[i]["step_end_time"].Equals(DBNull.Value))
  581. item.EndTime = (DateTime)dbData.Rows[i]["step_end_time"];
  582. item.ActualTime = item.EndTime.CompareTo(item.StartTime) <= 0 ? "" : item.EndTime.Subtract(item.StartTime).TotalSeconds.ToString();
  583. item.SettingTime = dbData.Rows[i]["step_time"].ToString();
  584. //annotation.Add(VerLine(Brushes.Blue, item.StartTime, Brushes.Blue, $"{item.No}:{item.Name}"));
  585. }
  586. }
  587. }
  588. public void OnDataGridSelectionChanged(object obj)
  589. {
  590. selectedRecipeItem = obj as RecipeItem;
  591. ParameterNodes = new ObservableCollection<ParameterNode>(_provider.GetParameters().Where(x => x.Name == selectedRecipeItem?.Chamber));
  592. }
  593. public void OnSearchData()
  594. {
  595. ProcessData.Clear();
  596. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  597. var Keys = new List<string>();
  598. PdKeyDataCollection.ToList().ForEach(key =>
  599. {
  600. Keys.Add(key.Key);
  601. });
  602. if (keys.Count == 0)
  603. {
  604. return;
  605. }
  606. var result = GetData(Keys.Distinct().ToList(), Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  607. if (result == null)
  608. {
  609. return;
  610. }
  611. List<PointCollection> cls = new List<PointCollection>();
  612. for (int i = 0; i < Keys.Count; i++)
  613. {
  614. PointCollection points = new PointCollection();
  615. int k = 1;
  616. result[Keys[i]].ForEach(point =>
  617. {
  618. ProcessData.Add(new HistoryDataItem() { dateTime = point.dateTime, dbName = Keys[i], value = point.value });
  619. points.Add(new Point() { X = point.dateTime.ToOADate(), Y = point.value });
  620. k += 1;
  621. });
  622. cls.Add(points);
  623. }
  624. for (int i = 0; i < PdKeyDataCollection.Count(); i++)
  625. {
  626. var _color = PdKeyDataCollection[i].Color.Color;
  627. view.MyDrawGraphicsControl.m_PenCollencteions[i] = new System.Drawing.Pen(System.Drawing.Color.FromArgb(_color.A, _color.R, _color.G, _color.B), 2);
  628. }
  629. this.view.MyDrawGraphicsControl.PointCollections = cls;
  630. this.view.MyDrawGraphicsControl.FitControl();
  631. this.view.MyDrawGraphicsControl.YPoints.Clear();
  632. //var item = QueryDataClient.Instance.Service.GetHistorySteps(Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  633. //if (item!=null)
  634. //{
  635. // item.ForEach(x =>
  636. // {
  637. // this.view.MyDrawGraphicsControl.YPoints.Add(new Venus_Core.StepItem() { StartValue = x.StartTime.ToOADate(), Information = $"{x.RecipeId}:{x.StepNo}" });
  638. // });
  639. //}
  640. if (IsShowStep)
  641. {
  642. var item2 = QueryDataClient.Instance.Service.GetHistorySteps(Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  643. item2?.ForEach(x =>
  644. {
  645. if (x.RecipeId == selectedRecipeItem.Chamber)
  646. {
  647. this.view.MyDrawGraphicsControl.YPoints.Add(new Venus_Core.StepItem() { StartValue = x.StartTime.ToOADate(), Information = $"{x.RecipeId}\n{x.StepNo}\n{x.StartTime.ToString("HH:mm:ss:fff")}" });
  648. }
  649. });
  650. }
  651. }
  652. private void CloseAll(ObservableCollection<ParameterNode> parameterNodes)
  653. {
  654. if (parameterNodes != null)
  655. {
  656. foreach (var item in parameterNodes)
  657. {
  658. item.Selected = false;
  659. if (item.ChildNodes.Count > 0)
  660. {
  661. CloseAll(item.ChildNodes);
  662. }
  663. }
  664. }
  665. }
  666. private void OnClearData()
  667. {
  668. this.view.MyDrawGraphicsControl.YPoints.Clear();
  669. PdKeyDataCollection.Clear();
  670. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  671. CloseAll(ParameterNodes);
  672. }
  673. public void ColorChanged()
  674. {
  675. for (int i = 0; i < PdKeyDataCollection.Count(); i++)
  676. {
  677. var _color = PdKeyDataCollection[i].Color.Color;
  678. this.view.MyDrawGraphicsControl.m_PenCollencteions[i] = new System.Drawing.Pen(System.Drawing.Color.FromArgb(_color.A, _color.R, _color.G, _color.B), 2);
  679. }
  680. }
  681. }
  682. #endregion
  683. #region 数据类
  684. public class RecipeItem : BindableBase
  685. {
  686. public bool Selected { get; set; }
  687. public string Recipe { get; set; }
  688. public string Guid { get; set; }
  689. public string RecipeRunGuid { get; set; }
  690. public string Chamber { get; set; }
  691. public string Status { get; set; }
  692. public string StartTime { get; set; }
  693. public string EndTime { get; set; }
  694. public string LotID { get; set; }
  695. public string SlotID { get; set; }
  696. public string RecipeType { get; set; }
  697. }
  698. public class StepData
  699. {
  700. [DataMember]
  701. public int No { get; set; }
  702. [DataMember]
  703. public string Name { get; set; }
  704. [DataMember]
  705. public DateTime StartTime { get; set; }
  706. [DataMember]
  707. public DateTime EndTime { get; set; }
  708. [DataMember]
  709. public string ActualTime { get; set; }
  710. [DataMember]
  711. public string SettingTime { get; set; }
  712. }
  713. public class PdKeyData : BindableBase, ICloneable
  714. {
  715. public string Key { get; set; }
  716. public SolidColorBrush _Color;
  717. public SolidColorBrush Color
  718. {
  719. get { return _Color; }
  720. set { SetProperty(ref _Color, value); }
  721. }
  722. public int UniqueId { get; set; }
  723. public object Clone()
  724. {
  725. return MemberwiseClone();
  726. }
  727. }
  728. #endregion
  729. }