KeplerProcessHistoryViewModel.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  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.LotID = dbData.Rows[i]["lot_id"].ToString();
  198. item.CarrierId = dbData.Rows[i]["carrier_id"].ToString();
  199. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  200. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  201. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  202. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  203. Recipes.Add(item);
  204. }
  205. }
  206. private void LoadRecipeCheckBox()
  207. {
  208. List<string> chamber = new List<string>() { "PMA", "PMB", "PMC", "PMD" };
  209. CheboxRecipes.Clear();
  210. foreach (string item in chamber)
  211. {
  212. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", item);
  213. if (Directory.Exists(path))
  214. {
  215. string[] dir = Directory.GetFiles(path);
  216. for (int i = 0; i < dir.Length; i++)
  217. {
  218. CheboxRecipes.Add(new Recipeslist { BoxName = Path.GetFileName(dir[i]) });
  219. }
  220. }
  221. }
  222. }
  223. public void SearchRecipes()
  224. {
  225. SearchRecipe(this.view.wfTimeFrom.Value, this.view.wfTimeTo.Value);
  226. }
  227. public void searchlot(string id)
  228. {
  229. Recipes.Clear();
  230. try
  231. {
  232. string sql1 = string.Format($"SELECT * FROM \"lot_wafer_data\" where guid ='{id}'; ");
  233. DataTable dbData1 = QueryDataClient.Instance.Service.QueryData(sql1);
  234. string lot_data_guid = dbData1.Rows[0]["wafer_data_guid"].ToString();
  235. string sql = string.Format($"SELECT * FROM \"process_data\" where wafer_data_guid ='{lot_data_guid}'");
  236. if (!string.IsNullOrEmpty(SelectedValuePM))
  237. {
  238. string[] pms = SelectedValuePM.Split(',');
  239. if (pms.Length > 0)
  240. {
  241. sql += " and (FALSE ";
  242. foreach (var pm in pms)
  243. {
  244. sql += $" OR \"process_in\"='{pm}' ";
  245. }
  246. sql += " ) ";
  247. }
  248. }
  249. if (!string.IsNullOrEmpty(RecipeName))
  250. {
  251. sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  252. }
  253. sql += " order by \"process_begin_time\" ASC;";
  254. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  255. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  256. {
  257. if (dbData == null || dbData.Rows.Count == 0) return;
  258. for (int i = 0; i < dbData.Rows.Count; i++)
  259. {
  260. RecipeItem item = new RecipeItem();
  261. item.Selected = false;
  262. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  263. item.CarrierId = dbData.Rows[i]["carrier_id"].ToString();
  264. item.Guid = dbData.Rows[i]["guid"].ToString();
  265. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  266. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  267. item.Status = dbData.Rows[i]["process_status"].ToString();
  268. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  269. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  270. item.RecipeType = dbData.Rows[i]["recipe_type"].ToString();
  271. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  272. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  273. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  274. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  275. Recipes.Add(item);
  276. }
  277. }));
  278. }
  279. catch (Exception e)
  280. {
  281. LOG.WriteExeption(e);
  282. }
  283. }
  284. public void SearchRecipe(DateTime start, DateTime end)
  285. {
  286. this.StartDateTime = start;
  287. this.EndDateTime = end;
  288. Recipes.Clear();
  289. try
  290. {
  291. 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")}' ";
  292. if (!string.IsNullOrEmpty(SelectedValuePM))
  293. {
  294. string[] pms = SelectedValuePM.Split(',');
  295. if (pms.Length > 0)
  296. {
  297. sqlGetCount += " and (FALSE ";
  298. foreach (var pm in pms)
  299. {
  300. sqlGetCount += $" OR \"process_in\"='{pm}' ";
  301. }
  302. sqlGetCount += " ) ";
  303. }
  304. }
  305. if (!string.IsNullOrEmpty(RecipeName))
  306. {
  307. sqlGetCount += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  308. }
  309. sqlGetCount += " ;";
  310. Total = QueryDataClient.Instance.Service.GetDBEventAllCount(sqlGetCount);
  311. PageCount = (Total / m_onePageCounts) + 1;
  312. 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")}' ";
  313. if (!string.IsNullOrEmpty(SelectedValuePM))
  314. {
  315. string[] pms = SelectedValuePM.Split(',');
  316. if (pms.Length > 0)
  317. {
  318. sql += " and (FALSE ";
  319. foreach (var pm in pms)
  320. {
  321. sql += $" OR \"process_in\"='{pm}' ";
  322. }
  323. sql += " ) ";
  324. }
  325. }
  326. if (!string.IsNullOrEmpty(RecipeName))
  327. {
  328. sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  329. }
  330. sql += $" order by \"process_begin_time\" ASC ";
  331. if (PageCount > 5)
  332. {
  333. sql += $" limit {m_onePageCounts} offset {(1 - 1) * m_onePageCounts};";
  334. }
  335. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  336. if (dbData == null || dbData.Rows.Count == 0) return;
  337. for (int i = 0; i < dbData.Rows.Count; i++)
  338. {
  339. RecipeItem item = new RecipeItem();
  340. item.Selected = false;
  341. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  342. item.Guid = dbData.Rows[i]["guid"].ToString();
  343. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  344. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  345. item.Status = dbData.Rows[i]["process_status"].ToString();
  346. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  347. item.RecipeType = dbData.Rows[i]["recipe_type"].ToString();
  348. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  349. item.CarrierId = dbData.Rows[i]["carrier_id"].ToString();
  350. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  351. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  352. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  353. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss");
  354. Recipes.Add(item);
  355. }
  356. }
  357. catch (Exception e)
  358. {
  359. LOG.WriteExeption(e);
  360. }
  361. }
  362. private void CalKeys(ParameterNode parameterNode)
  363. {
  364. if (parameterNode.ChildNodes.Count > 0)
  365. {
  366. foreach (var item in parameterNode.ChildNodes)
  367. {
  368. CalKeys(item);
  369. }
  370. }
  371. else
  372. {
  373. if (parameterNode.Selected == true)
  374. {
  375. keys.Add(parameterNode.Name);
  376. }
  377. }
  378. }
  379. private Dictionary<string, List<HistoryDataItem>> GetData(List<string> keys, DateTime from, DateTime to)
  380. {
  381. string sql = "select time AS InternalTimeStamp";
  382. foreach (var dataId in keys)
  383. {
  384. sql += "," + string.Format("\"{0}\"", dataId);
  385. }
  386. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc",
  387. from.ToString("yyyyMMdd") + "." + "Data", from.Ticks, to.Ticks);
  388. DataTable dataTable = QueryDataClient.Instance.Service.QueryData(sql);
  389. Dictionary<string, List<HistoryDataItem>> historyData = new Dictionary<string, List<HistoryDataItem>>();
  390. if (dataTable == null || dataTable.Rows.Count == 0)
  391. return null;
  392. DateTime dt = new DateTime();
  393. Dictionary<int, string> colName = new Dictionary<int, string>();
  394. for (int colNo = 0; colNo < dataTable.Columns.Count; colNo++)
  395. {
  396. colName.Add(colNo, dataTable.Columns[colNo].ColumnName);
  397. historyData[dataTable.Columns[colNo].ColumnName] = new List<HistoryDataItem>();
  398. }
  399. for (int rowNo = 0; rowNo < dataTable.Rows.Count; rowNo++)
  400. {
  401. PointCollection points = new PointCollection();
  402. var row = dataTable.Rows[rowNo];
  403. for (int i = 0; i < dataTable.Columns.Count; i++)
  404. {
  405. HistoryDataItem data = new HistoryDataItem();
  406. if (i == 0)
  407. {
  408. long ticks = (long)row[i];
  409. dt = new DateTime(ticks);
  410. continue;
  411. }
  412. else
  413. {
  414. string dataId = colName[i];
  415. if (row[i] is DBNull || row[i] == null)
  416. {
  417. data.dateTime = dt;
  418. data.dbName = colName[i];
  419. data.value = 0;
  420. }
  421. else if (row[i] is bool)
  422. {
  423. data.dateTime = dt;
  424. data.dbName = colName[i];
  425. data.value = (bool)row[i] ? 1 : 0;
  426. }
  427. else
  428. {
  429. data.dateTime = dt;
  430. data.dbName = colName[i];
  431. data.value = float.Parse(row[i].ToString());
  432. }
  433. }
  434. historyData[data.dbName].Add(data);
  435. }
  436. }
  437. foreach (var item in historyData)
  438. {
  439. item.Value.Sort((x, y) => DateTime.Compare(x.dateTime, y.dateTime));
  440. }
  441. return historyData;
  442. }
  443. private bool RefreshTreeStatusToChild(ParameterNode node)
  444. {
  445. if (node.ChildNodes.Count > 0)
  446. {
  447. for (int i = 0; i < node.ChildNodes.Count; i++)
  448. {
  449. ParameterNode n = node.ChildNodes[i];
  450. n.Selected = node.Selected;
  451. if (!RefreshTreeStatusToChild(n))
  452. {
  453. //uncheck left node
  454. for (int j = i; j < node.ChildNodes.Count; j++)
  455. {
  456. node.ChildNodes[j].Selected = !node.Selected;
  457. }
  458. //node.Selected = !node.Selected;
  459. return false;
  460. }
  461. }
  462. }
  463. //else
  464. //{
  465. // if (node.Selected == true)
  466. // {
  467. // keys.Add(node.Name);
  468. // }
  469. // else
  470. // {
  471. // keys.Remove(node.Name);
  472. // }
  473. //}
  474. return true;
  475. }
  476. private void RefreshTreeStatusToParent(ParameterNode node)
  477. {
  478. if (node.ParentNode != null)
  479. {
  480. if (node.Selected)
  481. {
  482. bool flag = true;
  483. for (int i = 0; i < node.ParentNode.ChildNodes.Count; i++)
  484. {
  485. if (!node.ParentNode.ChildNodes[i].Selected)
  486. {
  487. flag = false; //as least one child is unselected
  488. break;
  489. }
  490. }
  491. if (flag)
  492. node.ParentNode.Selected = true;
  493. }
  494. else
  495. {
  496. node.ParentNode.Selected = false;
  497. }
  498. RefreshTreeStatusToParent(node.ParentNode);
  499. }
  500. }
  501. public static T DeepCopyJson<T>(T obj)
  502. {
  503. // 序列化
  504. string json = JsonConvert.SerializeObject(obj);
  505. // 反序列化
  506. return JsonConvert.DeserializeObject<T>(json);
  507. }
  508. private void OnParameterCheck(object obj)
  509. {
  510. ParameterNode node = obj as ParameterNode;
  511. if (!RefreshTreeStatusToChild(node))
  512. {
  513. node.Selected = !node.Selected;
  514. }
  515. else
  516. {
  517. RefreshTreeStatusToParent(node);
  518. }
  519. keys.Clear();
  520. for (int i = 0; i < ParameterNodes.Count; i++)
  521. {
  522. CalKeys(ParameterNodes[i]);
  523. }
  524. if (keys.Count > 10)
  525. {
  526. WPFMessageBox.ShowWarning("最多显示10个数据");
  527. return;
  528. }
  529. OldPdKeyDataCollection.Clear();
  530. OldPdKeyDataCollection = DeepCopyJson(PdKeyDataCollection);
  531. PdKeyDataCollection.Clear();
  532. for (int i = 0; i < keys.Count; i++)
  533. {
  534. if (i == 10)
  535. {
  536. break;
  537. }
  538. PdKeyDataCollection.Add(new PdKeyData() { Key = keys[i], Color = solidColorBrushes[i], UniqueId = i });
  539. }
  540. //Compare(OldPdKeyDataCollection, PdKeyDataCollection);
  541. //PdKeyDataCollection = DeepCopyJson(OldPdKeyDataCollection);
  542. }
  543. public void Compare(ObservableCollection<PdKeyData> olddata, ObservableCollection<PdKeyData> newdata)
  544. {
  545. if (newdata != null)
  546. {
  547. for (int i = 0; i < newdata.Count; i++)
  548. {
  549. var lists = olddata.ToList().Find(t => t.Key == newdata[i].Key);
  550. if (lists == null)
  551. {
  552. olddata.Add(new PdKeyData() { Key = newdata[i].Key, Color = solidColorBrushes[i], UniqueId = olddata.Count + 1 });
  553. }
  554. }
  555. for (int i = 0; i < olddata.Count; i++)
  556. {
  557. var lists = newdata.ToList().Find(t => t.Key == olddata[i].Key);
  558. if (lists == null)
  559. {
  560. olddata.Remove(olddata[i]);
  561. }
  562. }
  563. }
  564. }
  565. public void UpdateData(RecipeItem dataLog)
  566. {
  567. OnClearData();
  568. //CheckRecipe(dataLog.Guid);
  569. }
  570. public void CheckRecipe(string RecipeGuid)
  571. {
  572. string sql = $"SELECT * FROM \"recipe_step_data\" where \"process_data_guid\" = '{RecipeGuid}' order by step_number ASC;";
  573. var dbData = QueryDataClient.Instance.Service.QueryData(sql);
  574. List<StepData> steps = new List<StepData>();
  575. if (dbData != null && dbData.Rows.Count > 0)
  576. {
  577. for (int i = 0; i < dbData.Rows.Count; i++)
  578. {
  579. StepData item = new StepData();
  580. item.No = int.Parse(dbData.Rows[i]["step_number"].ToString());
  581. item.Name = dbData.Rows[i]["step_name"].ToString();
  582. if (!dbData.Rows[i]["step_begin_time"].Equals(DBNull.Value))
  583. item.StartTime = (DateTime)dbData.Rows[i]["step_begin_time"];
  584. if (!dbData.Rows[i]["step_end_time"].Equals(DBNull.Value))
  585. item.EndTime = (DateTime)dbData.Rows[i]["step_end_time"];
  586. item.ActualTime = item.EndTime.CompareTo(item.StartTime) <= 0 ? "" : item.EndTime.Subtract(item.StartTime).TotalSeconds.ToString();
  587. item.SettingTime = dbData.Rows[i]["step_time"].ToString();
  588. //annotation.Add(VerLine(Brushes.Blue, item.StartTime, Brushes.Blue, $"{item.No}:{item.Name}"));
  589. }
  590. }
  591. }
  592. public void OnDataGridSelectionChanged(object obj)
  593. {
  594. selectedRecipeItem = obj as RecipeItem;
  595. if (selectedRecipeItem == null)
  596. {
  597. return;
  598. }
  599. if (selectedRecipeItem?.Chamber != _lastSelectChamber)
  600. {
  601. ParameterNodes = new ObservableCollection<ParameterNode>(_provider.GetParameters().Where(x => x.Name == selectedRecipeItem?.Chamber));
  602. _lastSelectChamber = selectedRecipeItem.Chamber;
  603. }
  604. }
  605. public void OnSearchData()
  606. {
  607. ProcessData.Clear();
  608. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  609. var Keys = new List<string>();
  610. PdKeyDataCollection.ToList().ForEach(key =>
  611. {
  612. Keys.Add(key.Key);
  613. });
  614. if (keys.Count == 0)
  615. {
  616. return;
  617. }
  618. if (selectedRecipeItem == null)
  619. {
  620. return;
  621. }
  622. resultDictionary = GetData(Keys.Distinct().ToList(), Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime).AddSeconds(1));
  623. if (resultDictionary == null)
  624. {
  625. return;
  626. }
  627. List<PointCollection> cls = new List<PointCollection>();
  628. for (int i = 0; i < Keys.Count; i++)
  629. {
  630. PointCollection points = new PointCollection();
  631. int k = 1;
  632. resultDictionary[Keys[i]].ForEach(point =>
  633. {
  634. ProcessData.Add(new HistoryDataItem() { dateTime = point.dateTime, dbName = Keys[i], value = point.value });
  635. points.Add(new Point() { X = point.dateTime.ToOADate(), Y = point.value });
  636. k += 1;
  637. });
  638. cls.Add(points);
  639. }
  640. for (int i = 0; i < PdKeyDataCollection.Count(); i++)
  641. {
  642. var _color = PdKeyDataCollection[i].Color.Color;
  643. view.MyDrawGraphicsControl.m_PenCollencteions[i] = new System.Drawing.Pen(System.Drawing.Color.FromArgb(_color.A, _color.R, _color.G, _color.B), 2);
  644. }
  645. this.view.MyDrawGraphicsControl.PointCollections = cls;
  646. this.view.MyDrawGraphicsControl.FitControl();
  647. this.view.MyDrawGraphicsControl.YPoints.Clear();
  648. //var item = QueryDataClient.Instance.Service.GetHistorySteps(Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  649. //if (item!=null)
  650. //{
  651. // item.ForEach(x =>
  652. // {
  653. // this.view.MyDrawGraphicsControl.YPoints.Add(new Venus_Core.StepItem() { StartValue = x.StartTime.ToOADate(), Information = $"{x.RecipeId}:{x.StepNo}" });
  654. // });
  655. //}
  656. if (IsShowStep)
  657. {
  658. var item2 = QueryDataClient.Instance.Service.GetHistorySteps(Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  659. item2?.ForEach(x =>
  660. {
  661. if (x.RecipeId == selectedRecipeItem.Chamber)
  662. {
  663. 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")}" });
  664. }
  665. });
  666. }
  667. }
  668. private void CloseAll(ObservableCollection<ParameterNode> parameterNodes)
  669. {
  670. if (parameterNodes != null)
  671. {
  672. foreach (var item in parameterNodes)
  673. {
  674. item.Selected = false;
  675. if (item.ChildNodes.Count > 0)
  676. {
  677. CloseAll(item.ChildNodes);
  678. }
  679. }
  680. }
  681. }
  682. private void OnClearData()
  683. {
  684. this.view.MyDrawGraphicsControl.YPoints.Clear();
  685. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  686. PdKeyDataCollection.Clear();
  687. CloseAll(ParameterNodes);
  688. }
  689. public void ColorChanged()
  690. {
  691. for (int i = 0; i < PdKeyDataCollection.Count(); i++)
  692. {
  693. var _color = PdKeyDataCollection[i].Color.Color;
  694. this.view.MyDrawGraphicsControl.m_PenCollencteions[i] = new System.Drawing.Pen(System.Drawing.Color.FromArgb(_color.A, _color.R, _color.G, _color.B), 2);
  695. }
  696. }
  697. //private void OnExportRecipes()
  698. //{
  699. // try
  700. // {
  701. // Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  702. // dlg.DefaultExt = ".xls"; // Default file extension
  703. // dlg.Filter = "Excel数据表格文件(*.xls)|*.xls"; // Filter files by extension
  704. // Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  705. // if (result == true) // Process open file dialog box results
  706. // {
  707. // System.Data.DataSet ds = new System.Data.DataSet();
  708. // ds.Tables.Add(new System.Data.DataTable("Recipes"));
  709. // ds.Tables[0].Columns.Add("Start");
  710. // ds.Tables[0].Columns.Add("End");
  711. // ds.Tables[0].Columns.Add("Chamber");
  712. // ds.Tables[0].Columns.Add("Guid");
  713. // ds.Tables[0].Columns.Add("WaferID");
  714. // ds.Tables[0].Columns.Add("Recipe");
  715. // ds.Tables[0].Columns.Add("Status");
  716. // foreach (var item in Recipes)
  717. // {
  718. // var row = ds.Tables[0].NewRow();
  719. // row[0] = item.StartTime;
  720. // row[1] = item.EndTime;
  721. // row[2] = item.Chamber;
  722. // row[3] = item.Guid;
  723. // row[4] = item.LotID;
  724. // row[5] = item.Recipe;
  725. // row[6] = item.Status;
  726. // ds.Tables[0].Rows.Add(row);
  727. // }
  728. // ds.WriteXml(dlg.FileName);
  729. // }
  730. // }
  731. // catch
  732. // {
  733. // MessageBox.Show("导出系统日志发生错误", "导出失败", MessageBoxButton.OK, MessageBoxImage.Warning);
  734. // }
  735. //}
  736. private void OnExportRecipeData()
  737. {
  738. try
  739. {
  740. RecipeItem log = (this.view.dataGrid_RecipeList.SelectedItem) as RecipeItem;
  741. if (log == null)
  742. {
  743. WPFMessageBox.ShowError("没有数据,先从列表中选择一个批次");
  744. return;
  745. }
  746. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  747. dlg.DefaultExt = ".xls"; // Default file extension
  748. dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  749. dlg.FileName = string.Format("{0}-{1}", StartDateTime.ToString("yyyyMMdd"), log.Recipe.Replace(" ", "").Replace("/", ""));
  750. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  751. if (result != true) // Process open file dialog box results
  752. return;
  753. System.Data.DataSet ds = new System.Data.DataSet();
  754. ds.Tables.Add(new System.Data.DataTable("RecipeData"));
  755. int columnIndex = 0;
  756. int rowIndex = 0;
  757. ds.Tables[0].Columns.Add($"Time");
  758. foreach (var item in resultDictionary)
  759. {
  760. rowIndex = 0;
  761. if (item.Value.Count == 0)
  762. {
  763. continue;
  764. }
  765. ds.Tables[0].Columns.Add(item.Key);
  766. item.Value.ForEach(x =>
  767. {
  768. if (columnIndex == 0)
  769. {
  770. var row = ds.Tables[0].NewRow();
  771. row[0] = x.dateTime;
  772. row[columnIndex + 1] = x.value;
  773. ds.Tables[0].Rows.Add(row);
  774. }
  775. else
  776. {
  777. ds.Tables[0].Rows[rowIndex][columnIndex + 1] = x.value;
  778. }
  779. rowIndex += 1;
  780. });
  781. columnIndex += 1;
  782. }
  783. ds.WriteXml(dlg.FileName);
  784. }
  785. catch (Exception ex)
  786. {
  787. WPFMessageBox.ShowError($"导出系统日志发生错误{ex.Message}");
  788. }
  789. }
  790. }
  791. #endregion
  792. #region 数据类
  793. //public class RecipeItem : BindableBase
  794. //{
  795. // public bool Selected { get; set; }
  796. // public string Recipe { get; set; }
  797. // public string Guid { get; set; }
  798. // public string RecipeRunGuid { get; set; }
  799. // public string Chamber { get; set; }
  800. // public string Status { get; set; }
  801. // public string StartTime { get; set; }
  802. // public string EndTime { get; set; }
  803. // public string LotID { get; set; }
  804. // public string SlotID { get; set; }
  805. // public string RecipeType { get; set; }
  806. // public string CarrierId { get; set; }
  807. //}
  808. //public class StepData
  809. //{
  810. // [DataMember]
  811. // public int No { get; set; }
  812. // [DataMember]
  813. // public string Name { get; set; }
  814. // [DataMember]
  815. // public DateTime StartTime { get; set; }
  816. // [DataMember]
  817. // public DateTime EndTime { get; set; }
  818. // [DataMember]
  819. // public string ActualTime { get; set; }
  820. // [DataMember]
  821. // public string SettingTime { get; set; }
  822. //}
  823. //public class PdKeyData : BindableBase, ICloneable
  824. //{
  825. // public string Key { get; set; }
  826. // public SolidColorBrush _Color;
  827. // public SolidColorBrush Color
  828. // {
  829. // get { return _Color; }
  830. // set { SetProperty(ref _Color, value); }
  831. // }
  832. // public int UniqueId { get; set; }
  833. // public object Clone()
  834. // {
  835. // return MemberwiseClone();
  836. // }
  837. //}
  838. #endregion
  839. }