ProcessHistoryViewModel.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  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 Newtonsoft.Json;
  22. using System.Runtime.Serialization;
  23. using Microsoft.VisualBasic.Logging;
  24. using ExcelLibrary.BinaryFileFormat;
  25. using ExcelLibrary.SpreadSheet;
  26. using Venus_Themes.UserControls;
  27. using System.Windows.Forms;
  28. namespace Venus_MainPages.ViewModels
  29. {
  30. public class ProcessHistoryViewModel : BindableBase
  31. {
  32. #region 私有字段
  33. private ProcessHistoryView view;
  34. List<string> keys = new List<string>();
  35. RealtimeProvider _provider = new RealtimeProvider();
  36. private ObservableCollection<ParameterNode> _ParameterNodes;
  37. DispatcherTimer timer = new DispatcherTimer();
  38. ObservableCollection<PdKeyData> _PdKeyDataObservation = new ObservableCollection<PdKeyData>();
  39. public List<string> RecipesAdd = new List<string>();
  40. public List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>();
  41. //DateTime currentTime;
  42. private RecipeItem selectedRecipeItem;
  43. private bool m_IsShowStep;
  44. private int m_PageCount;
  45. private int m_onePageCounts = 7;
  46. private int m_Total;
  47. private bool m_FirstLoadFlag = true;
  48. private Dictionary<string, List<HistoryDataItem>> resultDictionary;
  49. private string _lastSelectChamber;
  50. #endregion
  51. #region 属性
  52. public List<HistoryDataItem> ProcessData { get; set; }
  53. public List<Recipeslist> CheboxRecipes { get; set; }
  54. public ProcessDataChartDataItem ProcessChartData { get; set; }
  55. public DateTime StartDateTime { get; set; }
  56. public DateTime EndDateTime { get; set; }
  57. public string SelectedValuePM { get; set; }
  58. public string RecipeName { get; set; }
  59. public ObservableCollection<PdKeyData> OldPdKeyDataCollection { get; set; }
  60. public ObservableCollection<RecipeItem> Recipes { get; set; }
  61. public class Recipeslist
  62. {
  63. public string BoxName { get; set; }
  64. }
  65. public class RecipeAdd
  66. {
  67. public string Recipesname { get; set; }
  68. }
  69. public ObservableCollection<ParameterNode> ParameterNodes
  70. {
  71. get { return _ParameterNodes; }
  72. set { SetProperty(ref _ParameterNodes, value); }
  73. }
  74. public ObservableCollection<PdKeyData> PdKeyDataCollection
  75. {
  76. get { return _PdKeyDataObservation; }
  77. set { SetProperty(ref _PdKeyDataObservation, value); }
  78. }
  79. public bool IsShowStep
  80. {
  81. get { return m_IsShowStep; }
  82. set { SetProperty(ref m_IsShowStep, value); }
  83. }
  84. public int PageCount
  85. {
  86. get { return m_PageCount; }
  87. set
  88. {
  89. SetProperty(ref m_PageCount, value);
  90. }
  91. }
  92. public int Total
  93. {
  94. get { return m_Total; }
  95. set
  96. {
  97. SetProperty(ref m_Total, value);
  98. }
  99. }
  100. #endregion
  101. #region 命令
  102. private DelegateCommand<object> _LoadCommandPD;
  103. public DelegateCommand<object> LoadCommandPD =>
  104. _LoadCommandPD ?? (_LoadCommandPD = new DelegateCommand<object>(OnLoadPd));
  105. private DelegateCommand _SearchRecipeCommand;
  106. public DelegateCommand SearchRecipeCommand =>
  107. _SearchRecipeCommand ?? (_SearchRecipeCommand = new DelegateCommand(SearchRecipes));
  108. private DelegateCommand<object> _PdParameterCheckCommand;
  109. public DelegateCommand<object> PdParameterCheckCommand =>
  110. _PdParameterCheckCommand ?? (_PdParameterCheckCommand = new DelegateCommand<object>(OnParameterCheck));
  111. private DelegateCommand<object> _DataGridSelectionChangedCommand;
  112. public DelegateCommand<object> DataGridSelectionChangedCommand =>
  113. _DataGridSelectionChangedCommand ?? (_DataGridSelectionChangedCommand = new DelegateCommand<object>(OnDataGridSelectionChanged));
  114. private DelegateCommand _SearchDataCommand;
  115. public DelegateCommand SearchDataCommand =>
  116. _SearchDataCommand ?? (_SearchDataCommand = new DelegateCommand(OnSearchData));
  117. private DelegateCommand _ClearDataCommand;
  118. public DelegateCommand ClearDataCommand =>
  119. _ClearDataCommand ?? (_ClearDataCommand = new DelegateCommand(OnClearData));
  120. //private DelegateCommand _ExportRecipesCommand;
  121. //public DelegateCommand ExportRecipesCommand =>
  122. //_ExportRecipesCommand ?? (_ExportRecipesCommand = new DelegateCommand(OnExportRecipes));
  123. private DelegateCommand _RecipeDataExportCommand;
  124. public DelegateCommand RecipeDataExportCommand =>
  125. _RecipeDataExportCommand ?? (_RecipeDataExportCommand = new DelegateCommand(OnExportRecipeData));
  126. #endregion
  127. #region 构造函数
  128. public ProcessHistoryViewModel()
  129. {
  130. ProcessData = new List<HistoryDataItem>() { };
  131. ProcessChartData = new ProcessDataChartDataItem(60000);
  132. Recipes = new ObservableCollection<RecipeItem>();
  133. timer.Interval = TimeSpan.FromSeconds(0.5);
  134. OldPdKeyDataCollection = new ObservableCollection<PdKeyData>();
  135. CheboxRecipes = new List<Recipeslist>();
  136. solidColorBrushes.Add(new SolidColorBrush(Colors.Green));
  137. solidColorBrushes.Add(new SolidColorBrush(Colors.Red));
  138. solidColorBrushes.Add(new SolidColorBrush(Colors.Blue));
  139. solidColorBrushes.Add(new SolidColorBrush(Colors.Orange));
  140. solidColorBrushes.Add(new SolidColorBrush(Colors.Yellow));
  141. solidColorBrushes.Add(new SolidColorBrush(Colors.YellowGreen));
  142. solidColorBrushes.Add(new SolidColorBrush(Colors.AliceBlue));
  143. solidColorBrushes.Add(new SolidColorBrush(Colors.Chocolate));
  144. solidColorBrushes.Add(new SolidColorBrush(Colors.Cyan));
  145. solidColorBrushes.Add(new SolidColorBrush(Colors.DarkGreen));
  146. }
  147. #endregion
  148. #region 命令方法
  149. private void OnLoadPd(Object eventView)
  150. {
  151. if (m_FirstLoadFlag)
  152. {
  153. m_FirstLoadFlag = false;
  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 ";
  332. if (PageCount > 5)
  333. {
  334. sql += $" limit {m_onePageCounts} offset {(1 - 1) * m_onePageCounts};";
  335. }
  336. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  337. if (dbData == null || dbData.Rows.Count == 0) return;
  338. for (int i = 0; i < dbData.Rows.Count; i++)
  339. {
  340. RecipeItem item = new RecipeItem();
  341. item.Selected = false;
  342. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  343. item.Guid = dbData.Rows[i]["guid"].ToString();
  344. item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
  345. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  346. item.Status = dbData.Rows[i]["process_status"].ToString();
  347. item.SlotID = dbData.Rows[i]["slot_id"].ToString();
  348. item.RecipeType = dbData.Rows[i]["recipe_type"].ToString();
  349. item.LotID = dbData.Rows[i]["lot_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. resultDictionary = GetData(Keys.Distinct().ToList(), Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  619. if (resultDictionary == null)
  620. {
  621. return;
  622. }
  623. List<PointCollection> cls = new List<PointCollection>();
  624. for (int i = 0; i < Keys.Count; i++)
  625. {
  626. PointCollection points = new PointCollection();
  627. int k = 1;
  628. resultDictionary[Keys[i]].ForEach(point =>
  629. {
  630. ProcessData.Add(new HistoryDataItem() { dateTime = point.dateTime, dbName = Keys[i], value = point.value });
  631. points.Add(new Point() { X = point.dateTime.ToOADate(), Y = point.value });
  632. k += 1;
  633. });
  634. cls.Add(points);
  635. }
  636. for (int i = 0; i < PdKeyDataCollection.Count(); i++)
  637. {
  638. var _color = PdKeyDataCollection[i].Color.Color;
  639. view.MyDrawGraphicsControl.m_PenCollencteions[i] = new System.Drawing.Pen(System.Drawing.Color.FromArgb(_color.A, _color.R, _color.G, _color.B), 2);
  640. }
  641. this.view.MyDrawGraphicsControl.PointCollections = cls;
  642. this.view.MyDrawGraphicsControl.FitControl();
  643. this.view.MyDrawGraphicsControl.YPoints.Clear();
  644. //var item = QueryDataClient.Instance.Service.GetHistorySteps(Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  645. //if (item!=null)
  646. //{
  647. // item.ForEach(x =>
  648. // {
  649. // this.view.MyDrawGraphicsControl.YPoints.Add(new Venus_Core.StepItem() { StartValue = x.StartTime.ToOADate(), Information = $"{x.RecipeId}:{x.StepNo}" });
  650. // });
  651. //}
  652. if (IsShowStep)
  653. {
  654. var item2 = QueryDataClient.Instance.Service.GetHistorySteps(Convert.ToDateTime(selectedRecipeItem?.StartTime), Convert.ToDateTime(selectedRecipeItem?.EndTime));
  655. item2?.ForEach(x =>
  656. {
  657. if (x.RecipeId == selectedRecipeItem.Chamber)
  658. {
  659. 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")}" });
  660. }
  661. });
  662. }
  663. }
  664. private void CloseAll(ObservableCollection<ParameterNode> parameterNodes)
  665. {
  666. if (parameterNodes != null)
  667. {
  668. foreach (var item in parameterNodes)
  669. {
  670. item.Selected = false;
  671. if (item.ChildNodes.Count > 0)
  672. {
  673. CloseAll(item.ChildNodes);
  674. }
  675. }
  676. }
  677. }
  678. private void OnClearData()
  679. {
  680. this.view.MyDrawGraphicsControl.YPoints.Clear();
  681. this.view.MyDrawGraphicsControl.ClearPlotPoints();
  682. PdKeyDataCollection.Clear();
  683. CloseAll(ParameterNodes);
  684. }
  685. public void ColorChanged()
  686. {
  687. for (int i = 0; i < PdKeyDataCollection.Count(); i++)
  688. {
  689. var _color = PdKeyDataCollection[i].Color.Color;
  690. this.view.MyDrawGraphicsControl.m_PenCollencteions[i] = new System.Drawing.Pen(System.Drawing.Color.FromArgb(_color.A, _color.R, _color.G, _color.B), 2);
  691. }
  692. }
  693. //private void OnExportRecipes()
  694. //{
  695. // try
  696. // {
  697. // Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  698. // dlg.DefaultExt = ".xls"; // Default file extension
  699. // dlg.Filter = "Excel数据表格文件(*.xls)|*.xls"; // Filter files by extension
  700. // Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  701. // if (result == true) // Process open file dialog box results
  702. // {
  703. // System.Data.DataSet ds = new System.Data.DataSet();
  704. // ds.Tables.Add(new System.Data.DataTable("Recipes"));
  705. // ds.Tables[0].Columns.Add("Start");
  706. // ds.Tables[0].Columns.Add("End");
  707. // ds.Tables[0].Columns.Add("Chamber");
  708. // ds.Tables[0].Columns.Add("Guid");
  709. // ds.Tables[0].Columns.Add("WaferID");
  710. // ds.Tables[0].Columns.Add("Recipe");
  711. // ds.Tables[0].Columns.Add("Status");
  712. // foreach (var item in Recipes)
  713. // {
  714. // var row = ds.Tables[0].NewRow();
  715. // row[0] = item.StartTime;
  716. // row[1] = item.EndTime;
  717. // row[2] = item.Chamber;
  718. // row[3] = item.Guid;
  719. // row[4] = item.LotID;
  720. // row[5] = item.Recipe;
  721. // row[6] = item.Status;
  722. // ds.Tables[0].Rows.Add(row);
  723. // }
  724. // ds.WriteXml(dlg.FileName);
  725. // }
  726. // }
  727. // catch
  728. // {
  729. // MessageBox.Show("导出系统日志发生错误", "导出失败", MessageBoxButton.OK, MessageBoxImage.Warning);
  730. // }
  731. //}
  732. private void OnExportRecipeData()
  733. {
  734. try
  735. {
  736. RecipeItem log = (this.view.dataGrid_RecipeList.SelectedItem) as RecipeItem;
  737. if (log == null)
  738. {
  739. WPFMessageBox.ShowError("没有数据,先从列表中选择一个批次");
  740. return;
  741. }
  742. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  743. dlg.DefaultExt = ".xls"; // Default file extension
  744. dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  745. dlg.FileName = string.Format("{0}-{1}", StartDateTime.ToString("yyyyMMdd"), log.Recipe.Replace(" ", "").Replace("/", ""));
  746. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  747. if (result != true) // Process open file dialog box results
  748. return;
  749. System.Data.DataSet ds = new System.Data.DataSet();
  750. ds.Tables.Add(new System.Data.DataTable("RecipeData"));
  751. int columnIndex = 0;
  752. int rowIndex = 0;
  753. ds.Tables[0].Columns.Add($"Time");
  754. foreach (var item in resultDictionary)
  755. {
  756. rowIndex = 0;
  757. if (item.Value.Count == 0)
  758. {
  759. continue;
  760. }
  761. ds.Tables[0].Columns.Add(item.Key);
  762. item.Value.ForEach(x =>
  763. {
  764. if (columnIndex == 0)
  765. {
  766. var row = ds.Tables[0].NewRow();
  767. row[0] = x.dateTime;
  768. row[columnIndex + 1] = x.value;
  769. ds.Tables[0].Rows.Add(row);
  770. }
  771. else
  772. {
  773. ds.Tables[0].Rows[rowIndex][columnIndex + 1] = x.value;
  774. }
  775. rowIndex += 1;
  776. });
  777. columnIndex += 1;
  778. }
  779. ds.WriteXml(dlg.FileName);
  780. }
  781. catch (Exception ex)
  782. {
  783. WPFMessageBox.ShowError($"导出系统日志发生错误{ex.Message}");
  784. }
  785. }
  786. }
  787. #endregion
  788. #region 数据类
  789. public class RecipeItem : BindableBase
  790. {
  791. public bool Selected { get; set; }
  792. public string Recipe { get; set; }
  793. public string Guid { get; set; }
  794. public string RecipeRunGuid { get; set; }
  795. public string Chamber { get; set; }
  796. public string Status { get; set; }
  797. public string StartTime { get; set; }
  798. public string EndTime { get; set; }
  799. public string LotID { get; set; }
  800. public string SlotID { get; set; }
  801. public string CarrierId { get; set; }
  802. public string RecipeType { get; set; }
  803. }
  804. public class StepData
  805. {
  806. [DataMember]
  807. public int No { get; set; }
  808. [DataMember]
  809. public string Name { get; set; }
  810. [DataMember]
  811. public DateTime StartTime { get; set; }
  812. [DataMember]
  813. public DateTime EndTime { get; set; }
  814. [DataMember]
  815. public string ActualTime { get; set; }
  816. [DataMember]
  817. public string SettingTime { get; set; }
  818. }
  819. public class PdKeyData : BindableBase, ICloneable
  820. {
  821. public string Key { get; set; }
  822. public SolidColorBrush _Color;
  823. public SolidColorBrush Color
  824. {
  825. get { return _Color; }
  826. set { SetProperty(ref _Color, value); }
  827. }
  828. public int UniqueId { get; set; }
  829. public object Clone()
  830. {
  831. return MemberwiseClone();
  832. }
  833. }
  834. #endregion
  835. }