KeplerProcessHistoryViewModel.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  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 Prism.Commands;
  8. using Prism.Mvvm;
  9. using Venus_MainPages.Unity;
  10. using Venus_MainPages.Views;
  11. using System.Collections.ObjectModel;
  12. using System.Windows.Threading;
  13. using System.Windows;
  14. using Aitex.Core.RT.Log;
  15. using Aitex.Core.UI.ControlDataContext;
  16. using WPF.Themes.UserControls;
  17. using System.IO;
  18. using Newtonsoft.Json;
  19. using System.Runtime.Serialization;
  20. using Microsoft.VisualBasic.Logging;
  21. using ExcelLibrary.BinaryFileFormat;
  22. using ExcelLibrary.SpreadSheet;
  23. using Venus_Themes.UserControls;
  24. using System.Windows.Forms;
  25. namespace Venus_MainPages.ViewModels
  26. {
  27. public class KeplerProcessHistoryViewModel : BindableBase
  28. {
  29. #region 私有字段
  30. private KeplerProcessHistoryView view;
  31. List<string> keys = new List<string>();
  32. RealtimeProvider _provider = new RealtimeProvider();
  33. private ObservableCollection<ParameterNode> _ParameterNodes;
  34. DispatcherTimer timer = new DispatcherTimer();
  35. ObservableCollection<PdKeyData> _PdKeyDataObservation = new ObservableCollection<PdKeyData>();
  36. public List<string> RecipesAdd = new List<string>();
  37. public List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>();
  38. //DateTime currentTime;
  39. private RecipeItem selectedRecipeItem;
  40. private bool m_IsShowStep;
  41. private int m_PageCount;
  42. private int m_onePageCounts = 7;
  43. private int m_Total;
  44. private bool m_FirstLoadFlag = true;
  45. private Dictionary<string, List<HistoryDataItem>> resultDictionary;
  46. private string _lastSelectChamber;
  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. public bool IsShowStep
  77. {
  78. get { return m_IsShowStep; }
  79. set { SetProperty(ref m_IsShowStep, value); }
  80. }
  81. public int PageCount
  82. {
  83. get { return m_PageCount; }
  84. set
  85. {
  86. SetProperty(ref m_PageCount, value);
  87. }
  88. }
  89. public int Total
  90. {
  91. get { return m_Total; }
  92. set
  93. {
  94. SetProperty(ref m_Total, value);
  95. }
  96. }
  97. #endregion
  98. #region 命令
  99. private DelegateCommand<object> _LoadCommandPD;
  100. public DelegateCommand<object> LoadCommandPD =>
  101. _LoadCommandPD ?? (_LoadCommandPD = new DelegateCommand<object>(OnLoadPd));
  102. private DelegateCommand _SearchRecipeCommand;
  103. public DelegateCommand SearchRecipeCommand =>
  104. _SearchRecipeCommand ?? (_SearchRecipeCommand = new DelegateCommand(SearchRecipes));
  105. private DelegateCommand<object> _PdParameterCheckCommand;
  106. public DelegateCommand<object> PdParameterCheckCommand =>
  107. _PdParameterCheckCommand ?? (_PdParameterCheckCommand = new DelegateCommand<object>(OnParameterCheck));
  108. private DelegateCommand<object> _DataGridSelectionChangedCommand;
  109. public DelegateCommand<object> DataGridSelectionChangedCommand =>
  110. _DataGridSelectionChangedCommand ?? (_DataGridSelectionChangedCommand = new DelegateCommand<object>(OnDataGridSelectionChanged));
  111. private DelegateCommand _SearchDataCommand;
  112. public DelegateCommand SearchDataCommand =>
  113. _SearchDataCommand ?? (_SearchDataCommand = new DelegateCommand(OnSearchData));
  114. private DelegateCommand _ClearDataCommand;
  115. public DelegateCommand ClearDataCommand =>
  116. _ClearDataCommand ?? (_ClearDataCommand = new DelegateCommand(OnClearData));
  117. //private DelegateCommand _ExportRecipesCommand;
  118. //public DelegateCommand ExportRecipesCommand =>
  119. //_ExportRecipesCommand ?? (_ExportRecipesCommand = new DelegateCommand(OnExportRecipes));
  120. private DelegateCommand _RecipeDataExportCommand;
  121. public DelegateCommand RecipeDataExportCommand =>
  122. _RecipeDataExportCommand ?? (_RecipeDataExportCommand = new DelegateCommand(OnExportRecipeData));
  123. #endregion
  124. #region 构造函数
  125. public KeplerProcessHistoryViewModel()
  126. {
  127. ProcessData = new List<HistoryDataItem>() { };
  128. ProcessChartData = new ProcessDataChartDataItem(60000);
  129. Recipes = new ObservableCollection<RecipeItem>();
  130. timer.Interval = TimeSpan.FromSeconds(0.5);
  131. OldPdKeyDataCollection = new ObservableCollection<PdKeyData>();
  132. CheboxRecipes = new List<Recipeslist>();
  133. solidColorBrushes.Add(new SolidColorBrush(Colors.Green));
  134. solidColorBrushes.Add(new SolidColorBrush(Colors.Red));
  135. solidColorBrushes.Add(new SolidColorBrush(Colors.Blue));
  136. solidColorBrushes.Add(new SolidColorBrush(Colors.Orange));
  137. solidColorBrushes.Add(new SolidColorBrush(Colors.Yellow));
  138. solidColorBrushes.Add(new SolidColorBrush(Colors.YellowGreen));
  139. solidColorBrushes.Add(new SolidColorBrush(Colors.AliceBlue));
  140. solidColorBrushes.Add(new SolidColorBrush(Colors.Chocolate));
  141. solidColorBrushes.Add(new SolidColorBrush(Colors.Cyan));
  142. solidColorBrushes.Add(new SolidColorBrush(Colors.DarkGreen));
  143. }
  144. #endregion
  145. #region 命令方法
  146. private void OnLoadPd(Object eventView)
  147. {
  148. if (m_FirstLoadFlag)
  149. {
  150. m_FirstLoadFlag = false;
  151. this.view = (KeplerProcessHistoryView)eventView;
  152. this.view.wfTimeFrom.Value = DateTime.Today;
  153. this.view.wfTimeTo.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59, 999);
  154. this.LoadRecipeCheckBox();
  155. this.view.pageControl.CurrentPageChanged += PageControl_CurrentPageChanged;
  156. }
  157. }
  158. private void PageControl_CurrentPageChanged(int currentPage)
  159. {
  160. PageChanged(currentPage);
  161. }
  162. public void PageChanged(int CurrentPage)
  163. {
  164. Recipes.Clear();
  165. 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")}' ";
  166. if (!string.IsNullOrEmpty(SelectedValuePM))
  167. {
  168. string[] pms = SelectedValuePM.Split(',');
  169. if (pms.Length > 0)
  170. {
  171. sql += " and (FALSE ";
  172. foreach (var pm in pms)
  173. {
  174. sql += $" OR \"process_in\"='{pm}' ";
  175. }
  176. sql += " ) ";
  177. }
  178. }
  179. if (!string.IsNullOrEmpty(RecipeName))
  180. {
  181. sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  182. }
  183. sql += $" order by \"process_begin_time\" ASC limit {m_onePageCounts} offset {(CurrentPage - 1) * m_onePageCounts};";
  184. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  185. if (dbData == null || dbData.Rows.Count == 0) return;
  186. for (int i = 0; i < dbData.Rows.Count; i++)
  187. {
  188. RecipeItem item = new RecipeItem();
  189. item.Selected = false;
  190. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  191. item.Guid = dbData.Rows[i]["guid"].ToString();
  192. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  193. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  194. item.Status = dbData.Rows[i]["process_status"].ToString();
  195. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  196. item.RecipeType = dbData.Rows[i]["recipe_type"].ToString();
  197. item.WaferId = dbData.Rows[i]["wafer_data_guid"].ToString();
  198. item.LotType = dbData.Rows[i]["lot_type"].ToString();
  199. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  200. item.CarrierId = dbData.Rows[i]["carrier_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.CarrierId = dbData.Rows[i]["carrier_id"].ToString();
  266. item.Guid = dbData.Rows[i]["guid"].ToString();
  267. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  268. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  269. item.Status = dbData.Rows[i]["process_status"].ToString();
  270. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  271. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  272. item.WaferId = dbData.Rows[i]["wafer_data_guid"].ToString();
  273. item.LotType = dbData.Rows[i]["lot_type"].ToString();
  274. item.RecipeType = dbData.Rows[i]["recipe_type"].ToString();
  275. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  276. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  277. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  278. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  279. Recipes.Add(item);
  280. }
  281. }));
  282. }
  283. catch (Exception e)
  284. {
  285. LOG.WriteExeption(e);
  286. }
  287. }
  288. public void SearchRecipe(DateTime start, DateTime end)
  289. {
  290. this.StartDateTime = start;
  291. this.EndDateTime = end;
  292. Recipes.Clear();
  293. try
  294. {
  295. 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")}' ";
  296. if (!string.IsNullOrEmpty(SelectedValuePM))
  297. {
  298. string[] pms = SelectedValuePM.Split(',');
  299. if (pms.Length > 0)
  300. {
  301. sqlGetCount += " and (FALSE ";
  302. foreach (var pm in pms)
  303. {
  304. sqlGetCount += $" OR \"process_in\"='{pm}' ";
  305. }
  306. sqlGetCount += " ) ";
  307. }
  308. }
  309. if (!string.IsNullOrEmpty(RecipeName))
  310. {
  311. sqlGetCount += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  312. }
  313. sqlGetCount += " ;";
  314. Total = QueryDataClient.Instance.Service.GetDBEventAllCount(sqlGetCount);
  315. PageCount = (Total / m_onePageCounts) + 1;
  316. 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")}' ";
  317. if (!string.IsNullOrEmpty(SelectedValuePM))
  318. {
  319. string[] pms = SelectedValuePM.Split(',');
  320. if (pms.Length > 0)
  321. {
  322. sql += " and (FALSE ";
  323. foreach (var pm in pms)
  324. {
  325. sql += $" OR \"process_in\"='{pm}' ";
  326. }
  327. sql += " ) ";
  328. }
  329. }
  330. if (!string.IsNullOrEmpty(RecipeName))
  331. {
  332. sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  333. }
  334. sql += $" order by \"process_begin_time\" ASC ";
  335. if (PageCount > 5)
  336. {
  337. sql += $" limit {m_onePageCounts} offset {(1 - 1) * m_onePageCounts};";
  338. }
  339. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  340. if (dbData == null || dbData.Rows.Count == 0) return;
  341. for (int i = 0; i < dbData.Rows.Count; i++)
  342. {
  343. RecipeItem item = new RecipeItem();
  344. item.Selected = false;
  345. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  346. item.Guid = dbData.Rows[i]["guid"].ToString();
  347. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  348. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  349. item.Status = dbData.Rows[i]["process_status"].ToString();
  350. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  351. item.RecipeType = dbData.Rows[i]["recipe_type"].ToString();
  352. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  353. item.CarrierId = dbData.Rows[i]["carrier_id"].ToString();
  354. item.WaferId = dbData.Rows[i]["wafer_data_guid"].ToString();
  355. item.LotType = dbData.Rows[i]["lot_type"].ToString();
  356. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  357. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  358. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  359. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  360. Recipes.Add(item);
  361. }
  362. }
  363. catch (Exception e)
  364. {
  365. LOG.WriteExeption(e);
  366. }
  367. }
  368. private void CalKeys(ParameterNode parameterNode)
  369. {
  370. if (parameterNode.ChildNodes.Count > 0)
  371. {
  372. foreach (var item in parameterNode.ChildNodes)
  373. {
  374. CalKeys(item);
  375. }
  376. }
  377. else
  378. {
  379. if (parameterNode.Selected == true)
  380. {
  381. keys.Add(parameterNode.Name);
  382. }
  383. }
  384. }
  385. private Dictionary<string, List<HistoryDataItem>> GetData(List<string> keys, DateTime from, DateTime to)
  386. {
  387. string sql = "select time AS InternalTimeStamp";
  388. foreach (var dataId in keys)
  389. {
  390. sql += "," + string.Format("\"{0}\"", dataId);
  391. }
  392. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc",
  393. from.ToString("yyyyMMdd") + "." + "Data", from.Ticks, to.Ticks);
  394. DataTable dataTable = QueryDataClient.Instance.Service.QueryData(sql);
  395. Dictionary<string, List<HistoryDataItem>> historyData = new Dictionary<string, List<HistoryDataItem>>();
  396. if (dataTable == null || dataTable.Rows.Count == 0)
  397. return null;
  398. DateTime dt = new DateTime();
  399. Dictionary<int, string> colName = new Dictionary<int, string>();
  400. for (int colNo = 0; colNo < dataTable.Columns.Count; colNo++)
  401. {
  402. colName.Add(colNo, dataTable.Columns[colNo].ColumnName);
  403. historyData[dataTable.Columns[colNo].ColumnName] = new List<HistoryDataItem>();
  404. }
  405. for (int rowNo = 0; rowNo < dataTable.Rows.Count; rowNo++)
  406. {
  407. PointCollection points = new PointCollection();
  408. var row = dataTable.Rows[rowNo];
  409. for (int i = 0; i < dataTable.Columns.Count; i++)
  410. {
  411. HistoryDataItem data = new HistoryDataItem();
  412. if (i == 0)
  413. {
  414. long ticks = (long)row[i];
  415. dt = new DateTime(ticks);
  416. continue;
  417. }
  418. else
  419. {
  420. string dataId = colName[i];
  421. if (row[i] is DBNull || row[i] == null)
  422. {
  423. data.dateTime = dt;
  424. data.dbName = colName[i];
  425. data.value = 0;
  426. }
  427. else if (row[i] is bool)
  428. {
  429. data.dateTime = dt;
  430. data.dbName = colName[i];
  431. data.value = (bool)row[i] ? 1 : 0;
  432. }
  433. else
  434. {
  435. data.dateTime = dt;
  436. data.dbName = colName[i];
  437. data.value = float.Parse(row[i].ToString());
  438. }
  439. }
  440. historyData[data.dbName].Add(data);
  441. }
  442. }
  443. foreach (var item in historyData)
  444. {
  445. item.Value.Sort((x, y) => DateTime.Compare(x.dateTime, y.dateTime));
  446. }
  447. return historyData;
  448. }
  449. private bool RefreshTreeStatusToChild(ParameterNode node)
  450. {
  451. if (node.ChildNodes.Count > 0)
  452. {
  453. for (int i = 0; i < node.ChildNodes.Count; i++)
  454. {
  455. ParameterNode n = node.ChildNodes[i];
  456. n.Selected = node.Selected;
  457. if (!RefreshTreeStatusToChild(n))
  458. {
  459. //uncheck left node
  460. for (int j = i; j < node.ChildNodes.Count; j++)
  461. {
  462. node.ChildNodes[j].Selected = !node.Selected;
  463. }
  464. //node.Selected = !node.Selected;
  465. return false;
  466. }
  467. }
  468. }
  469. //else
  470. //{
  471. // if (node.Selected == true)
  472. // {
  473. // keys.Add(node.Name);
  474. // }
  475. // else
  476. // {
  477. // keys.Remove(node.Name);
  478. // }
  479. //}
  480. return true;
  481. }
  482. private void RefreshTreeStatusToParent(ParameterNode node)
  483. {
  484. if (node.ParentNode != null)
  485. {
  486. if (node.Selected)
  487. {
  488. bool flag = true;
  489. for (int i = 0; i < node.ParentNode.ChildNodes.Count; i++)
  490. {
  491. if (!node.ParentNode.ChildNodes[i].Selected)
  492. {
  493. flag = false; //as least one child is unselected
  494. break;
  495. }
  496. }
  497. if (flag)
  498. node.ParentNode.Selected = true;
  499. }
  500. else
  501. {
  502. node.ParentNode.Selected = false;
  503. }
  504. RefreshTreeStatusToParent(node.ParentNode);
  505. }
  506. }
  507. public static T DeepCopyJson<T>(T obj)
  508. {
  509. // 序列化
  510. string json = JsonConvert.SerializeObject(obj);
  511. // 反序列化
  512. return JsonConvert.DeserializeObject<T>(json);
  513. }
  514. private void OnParameterCheck(object obj)
  515. {
  516. ParameterNode node = obj as ParameterNode;
  517. if (!RefreshTreeStatusToChild(node))
  518. {
  519. node.Selected = !node.Selected;
  520. }
  521. else
  522. {
  523. RefreshTreeStatusToParent(node);
  524. }
  525. keys.Clear();
  526. for (int i = 0; i < ParameterNodes.Count; i++)
  527. {
  528. CalKeys(ParameterNodes[i]);
  529. }
  530. if (keys.Count > 10)
  531. {
  532. WPFMessageBox.ShowWarning("最多显示10个数据");
  533. return;
  534. }
  535. OldPdKeyDataCollection.Clear();
  536. OldPdKeyDataCollection = DeepCopyJson(PdKeyDataCollection);
  537. PdKeyDataCollection.Clear();
  538. for (int i = 0; i < keys.Count; i++)
  539. {
  540. if (i == 10)
  541. {
  542. break;
  543. }
  544. PdKeyDataCollection.Add(new PdKeyData() { Key = keys[i], Color = solidColorBrushes[i], UniqueId = i });
  545. }
  546. //Compare(OldPdKeyDataCollection, PdKeyDataCollection);
  547. //PdKeyDataCollection = DeepCopyJson(OldPdKeyDataCollection);
  548. }
  549. public void Compare(ObservableCollection<PdKeyData> olddata, ObservableCollection<PdKeyData> newdata)
  550. {
  551. if (newdata != null)
  552. {
  553. for (int i = 0; i < newdata.Count; i++)
  554. {
  555. var lists = olddata.ToList().Find(t => t.Key == newdata[i].Key);
  556. if (lists == null)
  557. {
  558. olddata.Add(new PdKeyData() { Key = newdata[i].Key, Color = solidColorBrushes[i], UniqueId = olddata.Count + 1 });
  559. }
  560. }
  561. for (int i = 0; i < olddata.Count; i++)
  562. {
  563. var lists = newdata.ToList().Find(t => t.Key == olddata[i].Key);
  564. if (lists == null)
  565. {
  566. olddata.Remove(olddata[i]);
  567. }
  568. }
  569. }
  570. }
  571. public void UpdateData(RecipeItem dataLog)
  572. {
  573. OnClearData();
  574. //CheckRecipe(dataLog.Guid);
  575. }
  576. public void CheckRecipe(string RecipeGuid)
  577. {
  578. string sql = $"SELECT * FROM \"recipe_step_data\" where \"process_data_guid\" = '{RecipeGuid}' order by step_number ASC;";
  579. var dbData = QueryDataClient.Instance.Service.QueryData(sql);
  580. List<StepData> steps = new List<StepData>();
  581. if (dbData != null && dbData.Rows.Count > 0)
  582. {
  583. for (int i = 0; i < dbData.Rows.Count; i++)
  584. {
  585. StepData item = new StepData();
  586. item.No = int.Parse(dbData.Rows[i]["step_number"].ToString());
  587. item.Name = dbData.Rows[i]["step_name"].ToString();
  588. if (!dbData.Rows[i]["step_begin_time"].Equals(DBNull.Value))
  589. item.StartTime = (DateTime)dbData.Rows[i]["step_begin_time"];
  590. if (!dbData.Rows[i]["step_end_time"].Equals(DBNull.Value))
  591. item.EndTime = (DateTime)dbData.Rows[i]["step_end_time"];
  592. item.ActualTime = item.EndTime.CompareTo(item.StartTime) <= 0 ? "" : item.EndTime.Subtract(item.StartTime).TotalSeconds.ToString();
  593. item.SettingTime = dbData.Rows[i]["step_time"].ToString();
  594. //annotation.Add(VerLine(Brushes.Blue, item.StartTime, Brushes.Blue, $"{item.No}:{item.Name}"));
  595. }
  596. }
  597. }
  598. public void OnDataGridSelectionChanged(object obj)
  599. {
  600. selectedRecipeItem = obj as RecipeItem;
  601. if (selectedRecipeItem == null)
  602. {
  603. return;
  604. }
  605. if (selectedRecipeItem?.Chamber != _lastSelectChamber)
  606. {
  607. ParameterNodes = new ObservableCollection<ParameterNode>(_provider.GetParameters().Where(x => x.Name == selectedRecipeItem?.Chamber));
  608. _lastSelectChamber = selectedRecipeItem.Chamber;
  609. }
  610. }
  611. public void OnSearchData()
  612. {
  613. ProcessData.Clear();
  614. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  615. var Keys = new List<string>();
  616. PdKeyDataCollection.ToList().ForEach(key =>
  617. {
  618. Keys.Add(key.Key);
  619. });
  620. if (keys.Count == 0)
  621. {
  622. return;
  623. }
  624. if (selectedRecipeItem == null)
  625. {
  626. return;
  627. }
  628. resultDictionary = GetData(Keys.Distinct().ToList(), Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime).AddSeconds(1));
  629. if (resultDictionary == null)
  630. {
  631. return;
  632. }
  633. List<PointCollection> cls = new List<PointCollection>();
  634. for (int i = 0; i < Keys.Count; i++)
  635. {
  636. PointCollection points = new PointCollection();
  637. int k = 1;
  638. resultDictionary[Keys[i]].ForEach(point =>
  639. {
  640. ProcessData.Add(new HistoryDataItem() { dateTime = point.dateTime, dbName = Keys[i], value = point.value });
  641. points.Add(new Point() { X = point.dateTime.ToOADate(), Y = point.value });
  642. k += 1;
  643. });
  644. cls.Add(points);
  645. }
  646. for (int i = 0; i < PdKeyDataCollection.Count(); i++)
  647. {
  648. var _color = PdKeyDataCollection[i].Color.Color;
  649. view.MyDrawGraphicsControl.m_PenCollencteions[i] = new System.Drawing.Pen(System.Drawing.Color.FromArgb(_color.A, _color.R, _color.G, _color.B), 2);
  650. }
  651. this.view.MyDrawGraphicsControl.PointCollections = cls;
  652. this.view.MyDrawGraphicsControl.FitControl();
  653. this.view.MyDrawGraphicsControl.YPoints.Clear();
  654. //var item = QueryDataClient.Instance.Service.GetHistorySteps(Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  655. //if (item!=null)
  656. //{
  657. // item.ForEach(x =>
  658. // {
  659. // this.view.MyDrawGraphicsControl.YPoints.Add(new Venus_Core.StepItem() { StartValue = x.StartTime.ToOADate(), Information = $"{x.RecipeId}:{x.StepNo}" });
  660. // });
  661. //}
  662. if (IsShowStep)
  663. {
  664. var item2 = QueryDataClient.Instance.Service.GetHistorySteps(Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  665. item2?.ForEach(x =>
  666. {
  667. if (x.RecipeId == selectedRecipeItem.Chamber)
  668. {
  669. 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")}" });
  670. }
  671. });
  672. }
  673. }
  674. private void CloseAll(ObservableCollection<ParameterNode> parameterNodes)
  675. {
  676. if (parameterNodes != null)
  677. {
  678. foreach (var item in parameterNodes)
  679. {
  680. item.Selected = false;
  681. if (item.ChildNodes.Count > 0)
  682. {
  683. CloseAll(item.ChildNodes);
  684. }
  685. }
  686. }
  687. }
  688. private void OnClearData()
  689. {
  690. this.view.MyDrawGraphicsControl.YPoints.Clear();
  691. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  692. PdKeyDataCollection.Clear();
  693. CloseAll(ParameterNodes);
  694. }
  695. public void ColorChanged()
  696. {
  697. for (int i = 0; i < PdKeyDataCollection.Count(); i++)
  698. {
  699. var _color = PdKeyDataCollection[i].Color.Color;
  700. this.view.MyDrawGraphicsControl.m_PenCollencteions[i] = new System.Drawing.Pen(System.Drawing.Color.FromArgb(_color.A, _color.R, _color.G, _color.B), 2);
  701. }
  702. }
  703. //private void OnExportRecipes()
  704. //{
  705. // try
  706. // {
  707. // Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  708. // dlg.DefaultExt = ".xls"; // Default file extension
  709. // dlg.Filter = "Excel数据表格文件(*.xls)|*.xls"; // Filter files by extension
  710. // Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  711. // if (result == true) // Process open file dialog box results
  712. // {
  713. // System.Data.DataSet ds = new System.Data.DataSet();
  714. // ds.Tables.Add(new System.Data.DataTable("Recipes"));
  715. // ds.Tables[0].Columns.Add("Start");
  716. // ds.Tables[0].Columns.Add("End");
  717. // ds.Tables[0].Columns.Add("Chamber");
  718. // ds.Tables[0].Columns.Add("Guid");
  719. // ds.Tables[0].Columns.Add("WaferID");
  720. // ds.Tables[0].Columns.Add("Recipe");
  721. // ds.Tables[0].Columns.Add("Status");
  722. // foreach (var item in Recipes)
  723. // {
  724. // var row = ds.Tables[0].NewRow();
  725. // row[0] = item.StartTime;
  726. // row[1] = item.EndTime;
  727. // row[2] = item.Chamber;
  728. // row[3] = item.Guid;
  729. // row[4] = item.LotID;
  730. // row[5] = item.Recipe;
  731. // row[6] = item.Status;
  732. // ds.Tables[0].Rows.Add(row);
  733. // }
  734. // ds.WriteXml(dlg.FileName);
  735. // }
  736. // }
  737. // catch
  738. // {
  739. // MessageBox.Show("导出系统日志发生错误", "导出失败", MessageBoxButton.OK, MessageBoxImage.Warning);
  740. // }
  741. //}
  742. private void OnExportRecipeData()
  743. {
  744. try
  745. {
  746. RecipeItem log = (this.view.dataGrid_RecipeList.SelectedItem) as RecipeItem;
  747. if (log == null)
  748. {
  749. WPFMessageBox.ShowError("没有数据,先从列表中选择一个批次");
  750. return;
  751. }
  752. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  753. dlg.DefaultExt = ".xls"; // Default file extension
  754. dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  755. dlg.FileName = string.Format("{0}-{1}", StartDateTime.ToString("yyyyMMdd"), log.Recipe.Replace(" ", "").Replace("/", ""));
  756. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  757. if (result != true) // Process open file dialog box results
  758. return;
  759. System.Data.DataSet ds = new System.Data.DataSet();
  760. ds.Tables.Add(new System.Data.DataTable("RecipeData"));
  761. int columnIndex = 0;
  762. int rowIndex = 0;
  763. ds.Tables[0].Columns.Add($"Time");
  764. foreach (var item in resultDictionary)
  765. {
  766. rowIndex = 0;
  767. if (item.Value.Count == 0)
  768. {
  769. continue;
  770. }
  771. ds.Tables[0].Columns.Add(item.Key);
  772. item.Value.ForEach(x =>
  773. {
  774. if (columnIndex == 0)
  775. {
  776. var row = ds.Tables[0].NewRow();
  777. row[0] = x.dateTime;
  778. row[columnIndex + 1] = x.value;
  779. ds.Tables[0].Rows.Add(row);
  780. }
  781. else
  782. {
  783. ds.Tables[0].Rows[rowIndex][columnIndex + 1] = x.value;
  784. }
  785. rowIndex += 1;
  786. });
  787. columnIndex += 1;
  788. }
  789. ds.WriteXml(dlg.FileName);
  790. }
  791. catch (Exception ex)
  792. {
  793. WPFMessageBox.ShowError($"导出系统日志发生错误{ex.Message}");
  794. }
  795. }
  796. }
  797. #endregion
  798. #region 数据类
  799. //public class RecipeItem : BindableBase
  800. //{
  801. // public bool Selected { get; set; }
  802. // public string Recipe { get; set; }
  803. // public string Guid { get; set; }
  804. // public string RecipeRunGuid { get; set; }
  805. // public string Chamber { get; set; }
  806. // public string Status { get; set; }
  807. // public string StartTime { get; set; }
  808. // public string EndTime { get; set; }
  809. // public string LotID { get; set; }
  810. // public string SlotID { get; set; }
  811. // public string RecipeType { get; set; }
  812. // public string CarrierId { get; set; }
  813. //}
  814. //public class StepData
  815. //{
  816. // [DataMember]
  817. // public int No { get; set; }
  818. // [DataMember]
  819. // public string Name { get; set; }
  820. // [DataMember]
  821. // public DateTime StartTime { get; set; }
  822. // [DataMember]
  823. // public DateTime EndTime { get; set; }
  824. // [DataMember]
  825. // public string ActualTime { get; set; }
  826. // [DataMember]
  827. // public string SettingTime { get; set; }
  828. //}
  829. //public class PdKeyData : BindableBase, ICloneable
  830. //{
  831. // public string Key { get; set; }
  832. // public SolidColorBrush _Color;
  833. // public SolidColorBrush Color
  834. // {
  835. // get { return _Color; }
  836. // set { SetProperty(ref _Color, value); }
  837. // }
  838. // public int UniqueId { get; set; }
  839. // public object Clone()
  840. // {
  841. // return MemberwiseClone();
  842. // }
  843. //}
  844. #endregion
  845. }