DataHistoryViewModel.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. using Aitex.Core.UI.ControlDataContext;
  2. using ExcelLibrary.BinaryFileFormat;
  3. using MECF.Framework.Common.DataCenter;
  4. using Newtonsoft.Json;
  5. using Prism.Commands;
  6. using Prism.Mvvm;
  7. using System;
  8. using System.Collections.Concurrent;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Data;
  12. using System.Linq;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Media;
  16. using System.Windows.Threading;
  17. using Venus_MainPages.Unity;
  18. using Venus_MainPages.Views;
  19. using WPF.Themes.UserControls;
  20. namespace Venus_MainPages.ViewModels
  21. {
  22. public class DataHistoryViewModel : BindableBase
  23. {
  24. #region 私有字段
  25. private DataHistoryView DataHistoryView;
  26. private ObservableCollection<ParameterNode> _ParameterNodes;
  27. RealtimeProvider _provider = new RealtimeProvider();
  28. //private object _lockSelection = new object();
  29. //ConcurrentBag<QueryIndexer> _lstTokenTimeData = new ConcurrentBag<QueryIndexer>();
  30. ObservableCollection<string> m_Keys = new ObservableCollection<string>();
  31. ObservableCollection<KeyData> m_KeyDataObservableCollection = new ObservableCollection<KeyData>();
  32. DispatcherTimer timer = new DispatcherTimer();
  33. public List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>();
  34. DateTime currentTime;
  35. private bool firstFlag = true;
  36. private DateTime startTime = DateTime.Now;
  37. private bool m_IsShowStep;
  38. private bool m_IsPMAChecked = true;
  39. private bool m_IsPMBChecked = true;
  40. private bool m_IsPMCChecked = true;
  41. private bool m_IsPMDChecked = true;
  42. private bool m_PMAIsInstalled;
  43. private bool m_PMBIsInstalled;
  44. private bool m_PMCIsInstalled;
  45. private bool m_PMDIsInstalled;
  46. private bool m_IsEnter;
  47. #endregion
  48. #region 属性
  49. public ObservableCollection<KeyData> OldKeyDataCollection { get; set; }
  50. public ObservableCollection<ParameterNode> ParameterNodes
  51. {
  52. get { return _ParameterNodes; }
  53. set { SetProperty(ref _ParameterNodes, value); }
  54. }
  55. public ObservableCollection<string> Keys
  56. {
  57. get { return m_Keys; }
  58. set { SetProperty(ref m_Keys, value); }
  59. }
  60. public ObservableCollection<KeyData> KeyDataObservableCollection
  61. {
  62. get { return m_KeyDataObservableCollection; }
  63. set { SetProperty(ref m_KeyDataObservableCollection, value); }
  64. }
  65. public bool IsShowStep
  66. {
  67. get { return m_IsShowStep; }
  68. set { SetProperty(ref m_IsShowStep, value); }
  69. }
  70. public bool IsPMAChecked
  71. {
  72. get { return m_IsPMAChecked; }
  73. set { SetProperty(ref m_IsPMAChecked, value); }
  74. }
  75. public bool IsPMBChecked
  76. {
  77. get { return m_IsPMBChecked; }
  78. set { SetProperty(ref m_IsPMBChecked, value); }
  79. }
  80. public bool IsPMCChecked
  81. {
  82. get { return m_IsPMCChecked; }
  83. set { SetProperty(ref m_IsPMCChecked, value); }
  84. }
  85. public bool IsPMDChecked
  86. {
  87. get { return m_IsPMDChecked; }
  88. set { SetProperty(ref m_IsPMDChecked, value); }
  89. }
  90. public bool PMAIsInstalled
  91. {
  92. get { return m_PMAIsInstalled; }
  93. set { SetProperty(ref m_PMAIsInstalled, value); }
  94. }
  95. public bool PMBIsInstalled
  96. {
  97. get { return m_PMBIsInstalled; }
  98. set { SetProperty(ref m_PMBIsInstalled, value); }
  99. }
  100. public bool PMCIsInstalled
  101. {
  102. get { return m_PMCIsInstalled; }
  103. set { SetProperty(ref m_PMCIsInstalled, value); }
  104. }
  105. public bool PMDIsInstalled
  106. {
  107. get { return m_PMDIsInstalled; }
  108. set { SetProperty(ref m_PMDIsInstalled, value); }
  109. }
  110. #endregion
  111. #region 命令
  112. private DelegateCommand<object> _LoadCommand;
  113. public DelegateCommand<object> LoadCommand =>
  114. _LoadCommand ?? (_LoadCommand = new DelegateCommand<object>(OnLoad));
  115. private DelegateCommand _UnLoadCommand;
  116. public DelegateCommand UnLoadCommand =>
  117. _UnLoadCommand ?? (_UnLoadCommand = new DelegateCommand(OnUnLoad));
  118. private DelegateCommand<object> _ParameterCheckCommand;
  119. public DelegateCommand<object> ParameterCheckCommand =>
  120. _ParameterCheckCommand ?? (_ParameterCheckCommand = new DelegateCommand<object>(OnParameterCheck));
  121. private DelegateCommand _StartCommand;
  122. public DelegateCommand StartCommand =>
  123. _StartCommand ?? (_StartCommand = new DelegateCommand(OnStart));
  124. private DelegateCommand _ClearCommand;
  125. public DelegateCommand ClearCommand =>
  126. _ClearCommand ?? (_ClearCommand = new DelegateCommand(OnClear));
  127. private DelegateCommand<object> _StartRealTimeCommand;
  128. public DelegateCommand<object> StartRealTimeCommand =>
  129. _StartRealTimeCommand ?? (_StartRealTimeCommand = new DelegateCommand<object>(OnStartRealTime));
  130. private DelegateCommand _StopRealTimeCommand;
  131. public DelegateCommand StopRealTimeCommand =>
  132. _StopRealTimeCommand ?? (_StopRealTimeCommand = new DelegateCommand(OnStopRealTime));
  133. private DelegateCommand _ExportCommand;
  134. public DelegateCommand ExportCommand =>
  135. _ExportCommand ?? (_ExportCommand = new DelegateCommand(OnExport));
  136. #endregion
  137. #region 构造函数
  138. public DataHistoryViewModel()
  139. {
  140. OldKeyDataCollection = new ObservableCollection<KeyData>();
  141. ParameterNodes = _provider.GetParameters();
  142. timer.Interval = TimeSpan.FromSeconds(1);
  143. timer.Tick += Timer_Tick;
  144. solidColorBrushes.Add(new SolidColorBrush(Colors.Green));
  145. solidColorBrushes.Add(new SolidColorBrush(Colors.Red));
  146. solidColorBrushes.Add(new SolidColorBrush(Colors.Blue));
  147. solidColorBrushes.Add(new SolidColorBrush(Colors.Orange));
  148. solidColorBrushes.Add(new SolidColorBrush(Colors.Yellow));
  149. solidColorBrushes.Add(new SolidColorBrush(Colors.YellowGreen));
  150. solidColorBrushes.Add(new SolidColorBrush(Colors.AliceBlue));
  151. solidColorBrushes.Add(new SolidColorBrush(Colors.Chocolate));
  152. solidColorBrushes.Add(new SolidColorBrush(Colors.Cyan));
  153. solidColorBrushes.Add(new SolidColorBrush(Colors.DarkGreen));
  154. string allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString();
  155. PMAIsInstalled = allModules.Contains("PMA");
  156. PMBIsInstalled = allModules.Contains("PMB");
  157. PMCIsInstalled = allModules.Contains("PMC");
  158. PMDIsInstalled = allModules.Contains("PMD");
  159. }
  160. #endregion
  161. #region 命令方法
  162. private void OnLoad(Object eventView)
  163. {
  164. if (firstFlag)
  165. {
  166. this.DataHistoryView = (DataHistoryView)eventView;
  167. this.DataHistoryView.wfTimeFrom.Value = DateTime.Today;
  168. this.DataHistoryView.wfTimeTo.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59, 999);
  169. //this.DataHistoryView.MyDrawGraphicsControl.PointCollections=new PointCollection(new Point[] {})
  170. firstFlag = false;
  171. }
  172. }
  173. private void OnUnLoad()
  174. {
  175. GC.Collect(); // This should pick up the control removed at a previous MouseDown
  176. GC.WaitForPendingFinalizers(); // Doesn't help either
  177. GC.Collect();
  178. GC.WaitForPendingFinalizers(); // Doesn't help either
  179. }
  180. private void OnParameterCheck(object obj)
  181. {
  182. startTime = DateTime.Now;
  183. ParameterNode node = obj as ParameterNode;
  184. if (!RefreshTreeStatusToChild(node))
  185. {
  186. node.Selected = !node.Selected;
  187. }
  188. else
  189. {
  190. RefreshTreeStatusToParent(node);
  191. }
  192. Keys.Clear();
  193. for (int i = 0; i < ParameterNodes.Count; i++)
  194. {
  195. CalKeys(ParameterNodes[i]);
  196. }
  197. OldKeyDataCollection.Clear();
  198. OldKeyDataCollection = DeepCopyJson(KeyDataObservableCollection);
  199. KeyDataObservableCollection.Clear();
  200. for (int i = 0; i < Keys.Count; i++)
  201. {
  202. if (i == 10)
  203. {
  204. break;
  205. }
  206. KeyDataObservableCollection.Add(new KeyData() { Key = Keys[i], Color = solidColorBrushes[i], UniqueId = i });
  207. }
  208. //Compare(OldKeyDataCollection, KeyDataObservableCollection);
  209. //KeyDataObservableCollection = DeepCopyJson(OldKeyDataCollection);
  210. }
  211. public void Compare(ObservableCollection<KeyData> olddata, ObservableCollection<KeyData> newdata)
  212. {
  213. if (newdata != null)
  214. {
  215. for (int i = 0; i < newdata.Count; i++)
  216. {
  217. var lists = olddata.ToList().Find(t => t.Key == newdata[i].Key);
  218. if (lists == null)
  219. {
  220. olddata.Add(new KeyData() { Key = newdata[i].Key, Color = solidColorBrushes[i], UniqueId = olddata.Count + 1 });
  221. }
  222. }
  223. for (int i = 0; i < olddata.Count; i++)
  224. {
  225. var lists = newdata.ToList().Find(t => t.Key == olddata[i].Key);
  226. if (lists == null)
  227. {
  228. olddata.Remove(olddata[i]);
  229. }
  230. }
  231. }
  232. }
  233. public static T DeepCopyJson<T>(T obj)
  234. {
  235. // 序列化
  236. string json = JsonConvert.SerializeObject(obj);
  237. // 反序列化
  238. return JsonConvert.DeserializeObject<T>(json);
  239. }
  240. private void OnStartRealTime(object obj)
  241. {
  242. if (Keys.Count > 10)
  243. {
  244. ((System.Windows.Controls.CheckBox)obj).IsChecked = false;
  245. timer.Stop();
  246. WPFMessageBox.ShowWarning("最多显示10个数据");
  247. return;
  248. }
  249. currentTime = DateTime.Now;
  250. timer.Start();
  251. }
  252. private void OnStopRealTime()
  253. {
  254. timer.Stop();
  255. }
  256. public async void OnStart()
  257. {
  258. if (Keys.Count > 10)
  259. {
  260. WPFMessageBox.ShowWarning("最多显示10个数据");
  261. return;
  262. }
  263. TimeSpan sp = this.DataHistoryView.wfTimeTo.Value.Subtract(this.DataHistoryView.wfTimeFrom.Value);
  264. if (sp.TotalHours > 24)
  265. {
  266. WPFMessageBox.ShowWarning("数据差不能超过24小时");
  267. return;
  268. }
  269. this.DataHistoryView.MyDrawGraphicsControl.ClearPlotPoints();
  270. //Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
  271. await Task.Run(() =>
  272. {
  273. var result = GetData(Keys.Distinct().ToList(), this.DataHistoryView.wfTimeFrom.Value, this.DataHistoryView.wfTimeTo.Value);
  274. DataHistoryView.Dispatcher.Invoke(new Action(() =>
  275. {
  276. if (result == null)
  277. {
  278. return;
  279. }
  280. List<PointCollection> cls = new List<PointCollection>();
  281. for (int i = 0; i < Keys.Count; i++)
  282. {
  283. PointCollection points = new PointCollection();
  284. int k = 1;
  285. result[Keys[i]].ForEach(point =>
  286. {
  287. points.Add(new Point() { X = point.dateTime.ToOADate(), Y = point.value });
  288. k += 1;
  289. });
  290. cls.Add(points);
  291. }
  292. this.DataHistoryView.MyDrawGraphicsControl.PointCollections = cls;
  293. this.DataHistoryView.MyDrawGraphicsControl.FitControl();
  294. this.DataHistoryView.MyDrawGraphicsControl.YPoints.Clear();
  295. if (IsShowStep)
  296. {
  297. var item = QueryDataClient.Instance.Service.GetHistorySteps(this.DataHistoryView.wfTimeFrom.Value, this.DataHistoryView.wfTimeTo.Value);
  298. if (item != null)
  299. {
  300. var pmList = new List<string>();
  301. if (IsPMAChecked)
  302. {
  303. pmList.Add("PMA");
  304. }
  305. if (IsPMBChecked)
  306. {
  307. pmList.Add("PMB");
  308. }
  309. if (IsPMCChecked)
  310. {
  311. pmList.Add("PMC");
  312. }
  313. if (IsPMDChecked)
  314. {
  315. pmList.Add("PMD");
  316. }
  317. item.ForEach(x =>
  318. {
  319. if (pmList.Contains(x.RecipeId))
  320. {
  321. this.DataHistoryView.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")}" });
  322. }
  323. });
  324. }
  325. }
  326. }));
  327. });
  328. }
  329. private void CloseAll(ObservableCollection<ParameterNode> parameterNodes)
  330. {
  331. foreach (var item in parameterNodes)
  332. {
  333. item.Selected = false;
  334. if (item.ChildNodes.Count > 0)
  335. {
  336. CloseAll(item.ChildNodes);
  337. }
  338. }
  339. }
  340. private void OnClear()
  341. {
  342. this.DataHistoryView.MyDrawGraphicsControl.ClearPlotPoints();
  343. this.DataHistoryView.MyDrawGraphicsControl.YPoints = new List<Venus_Core.StepItem>();
  344. KeyDataObservableCollection.Clear();
  345. CloseAll(ParameterNodes);
  346. Keys.Clear();
  347. this.DataHistoryView.MyDrawGraphicsControl.InitPens();
  348. }
  349. private void OnExport()
  350. {
  351. Task.Run(() =>
  352. {
  353. try
  354. {
  355. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  356. dlg.DefaultExt = ".xls"; // Default file extension
  357. dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  358. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  359. if (result != true) // Process open file dialog box results
  360. return;
  361. System.Data.DataSet ds = new System.Data.DataSet();
  362. ds.Tables.Add(new System.Data.DataTable("Data"));
  363. //var item = ProcessData;
  364. var result2 = GetData(Keys.Distinct().ToList(), this.DataHistoryView.wfTimeFrom.Value, this.DataHistoryView.wfTimeTo.Value);
  365. int columnIndex = 0;
  366. int rowIndex = 0;
  367. ds.Tables[0].Columns.Add($"Time");
  368. foreach (var item in result2)
  369. {
  370. rowIndex = 0;
  371. if (item.Value.Count == 0)
  372. {
  373. continue;
  374. }
  375. ds.Tables[0].Columns.Add(item.Key);
  376. item.Value.ForEach(x =>
  377. {
  378. if (columnIndex == 0)
  379. {
  380. var row = ds.Tables[0].NewRow();
  381. row[0] = x.dateTime;
  382. row[columnIndex+1] = x.value;
  383. ds.Tables[0].Rows.Add(row);
  384. }
  385. else
  386. {
  387. ds.Tables[0].Rows[rowIndex][columnIndex+1]= x.value;
  388. }
  389. rowIndex += 1;
  390. });
  391. columnIndex += 1;
  392. }
  393. ds.WriteXml(dlg.FileName);
  394. }
  395. catch (Exception ex)
  396. {
  397. WPFMessageBox.ShowError($"导出系统日志发生错误{ex.Message}");
  398. }
  399. });
  400. }
  401. #endregion
  402. #region 私有方法
  403. private bool RefreshTreeStatusToChild(ParameterNode node)
  404. {
  405. if (node.ChildNodes.Count > 0)
  406. {
  407. for (int i = 0; i < node.ChildNodes.Count; i++)
  408. {
  409. ParameterNode n = node.ChildNodes[i];
  410. n.Selected = node.Selected;
  411. if (!RefreshTreeStatusToChild(n))
  412. {
  413. //uncheck left node
  414. for (int j = i; j < node.ChildNodes.Count; j++)
  415. {
  416. node.ChildNodes[j].Selected = !node.Selected;
  417. }
  418. //node.Selected = !node.Selected;
  419. return false;
  420. }
  421. }
  422. }
  423. //else
  424. //{
  425. // if (node.Selected == true)
  426. // {
  427. // keys.Add(node.Name);
  428. // }
  429. // else
  430. // {
  431. // keys.Remove(node.Name);
  432. // }
  433. //}
  434. return true;
  435. }
  436. private void RefreshTreeStatusToParent(ParameterNode node)
  437. {
  438. if (node.ParentNode != null)
  439. {
  440. if (node.Selected)
  441. {
  442. bool flag = true;
  443. for (int i = 0; i < node.ParentNode.ChildNodes.Count; i++)
  444. {
  445. if (!node.ParentNode.ChildNodes[i].Selected)
  446. {
  447. flag = false; //as least one child is unselected
  448. break;
  449. }
  450. }
  451. if (flag)
  452. node.ParentNode.Selected = true;
  453. }
  454. else
  455. {
  456. node.ParentNode.Selected = false;
  457. }
  458. RefreshTreeStatusToParent(node.ParentNode);
  459. }
  460. }
  461. private Dictionary<string, List<HistoryDataItem>> GetData(List<string> keys, DateTime from, DateTime to)
  462. {
  463. string sql = "";
  464. if (from.ToString("yyyyMMdd") == to.ToString("yyyyMMdd"))
  465. {
  466. sql += "select time AS InternalTimeStamp";
  467. foreach (var dataId in keys)
  468. {
  469. sql += "," + string.Format("\"{0}\"", dataId);
  470. }
  471. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc",
  472. from.ToString("yyyyMMdd") + "." + "Data", from.Ticks, to.Ticks);
  473. }
  474. else
  475. {
  476. sql += "select time AS InternalTimeStamp";
  477. foreach (var dataId in keys)
  478. {
  479. sql += "," + string.Format("\"{0}\"", dataId);
  480. }
  481. sql += string.Format(" from \"{0}\" where time > {1}",
  482. from.ToString("yyyyMMdd") + "." + "Data", from.Ticks);
  483. sql += " UNION ";
  484. sql += "select time AS InternalTimeStamp";
  485. foreach (var dataId in keys)
  486. {
  487. sql += "," + string.Format("\"{0}\"", dataId);
  488. }
  489. sql += string.Format(" from \"{0}\" where time < {1}",
  490. to.ToString("yyyyMMdd") + "." + "Data", to.Ticks);
  491. }
  492. DataTable dataTable = QueryDataClient.Instance.Service.QueryData(sql);
  493. Dictionary<string, List<HistoryDataItem>> historyData = new Dictionary<string, List<HistoryDataItem>>();
  494. if (dataTable == null || dataTable.Rows.Count == 0)
  495. return null;
  496. DateTime dt = new DateTime();
  497. Dictionary<int, string> colName = new Dictionary<int, string>();
  498. for (int colNo = 0; colNo < dataTable.Columns.Count; colNo++)
  499. {
  500. colName.Add(colNo, dataTable.Columns[colNo].ColumnName);
  501. historyData[dataTable.Columns[colNo].ColumnName] = new List<HistoryDataItem>();
  502. }
  503. for (int rowNo = 0; rowNo < dataTable.Rows.Count; rowNo++)
  504. {
  505. PointCollection points = new PointCollection();
  506. var row = dataTable.Rows[rowNo];
  507. for (int i = 0; i < dataTable.Columns.Count; i++)
  508. {
  509. HistoryDataItem data = new HistoryDataItem();
  510. if (i == 0)
  511. {
  512. long ticks = (long)row[i];
  513. dt = new DateTime(ticks);
  514. continue;
  515. }
  516. else
  517. {
  518. string dataId = colName[i];
  519. if (row[i] is DBNull || row[i] == null)
  520. {
  521. data.dateTime = dt;
  522. data.dbName = colName[i];
  523. data.value = 0;
  524. }
  525. else if (row[i] is bool)
  526. {
  527. data.dateTime = dt;
  528. data.dbName = colName[i];
  529. data.value = (bool)row[i] ? 1 : 0;
  530. }
  531. else
  532. {
  533. data.dateTime = dt;
  534. data.dbName = colName[i];
  535. data.value = float.Parse(row[i].ToString());
  536. }
  537. }
  538. historyData[data.dbName].Add(data);
  539. }
  540. }
  541. foreach (var item in historyData)
  542. {
  543. item.Value.Sort((x, y) => DateTime.Compare(x.dateTime, y.dateTime));
  544. }
  545. return historyData;
  546. }
  547. private void CalKeys(ParameterNode parameterNode)
  548. {
  549. if (parameterNode.ChildNodes.Count > 0)
  550. {
  551. foreach (var item in parameterNode.ChildNodes)
  552. {
  553. CalKeys(item);
  554. }
  555. }
  556. else
  557. {
  558. if (parameterNode.Selected == true)
  559. {
  560. Keys.Add(parameterNode.Name);
  561. }
  562. }
  563. }
  564. private void Timer_Tick(object sender, EventArgs e)
  565. {
  566. if (!m_IsEnter)
  567. {
  568. return;
  569. }
  570. if (Keys.Count > 10)
  571. {
  572. WPFMessageBox.ShowWarning("最多显示10个数据");
  573. timer.Stop();
  574. return;
  575. }
  576. this.DataHistoryView.MyDrawGraphicsControl.ClearPlotPoints();
  577. var result = GetData(Keys.Distinct().ToList(), currentTime.AddMinutes(-1), DateTime.Now);
  578. if (result == null)
  579. {
  580. return;
  581. }
  582. List<PointCollection> cls = new List<PointCollection>();
  583. for (int i = 0; i < Keys.Count; i++)
  584. {
  585. PointCollection points = new PointCollection();
  586. int k = 1;
  587. result[Keys[i]].ForEach(point =>
  588. {
  589. points.Add(new Point() { X = point.dateTime.ToOADate(), Y = point.value });
  590. k += 1;
  591. });
  592. cls.Add(points);
  593. }
  594. this.DataHistoryView.MyDrawGraphicsControl.PointCollections = cls;
  595. //if (this.DataHistoryView.MyDrawGraphicsControl.IsHorizontalNavigationEnabled == false && this.DataHistoryView.MyDrawGraphicsControl.IsVerticalNavigationEnabled == false)
  596. //{
  597. // this.DataHistoryView.MyDrawGraphicsControl.FitControlWithoutDrawing();
  598. //}
  599. //DateTime dateTimeNow = DateTime.Now;
  600. this.DataHistoryView.MyDrawGraphicsControl.YPoints.Clear();
  601. if (IsShowStep)
  602. {
  603. var item = QueryDataClient.Instance.Service.GetHistorySteps(startTime, DateTime.Now);
  604. if (item.Count > 0)
  605. {
  606. var pmList = new List<string>();
  607. if (IsPMAChecked)
  608. {
  609. pmList.Add("PMA");
  610. }
  611. if (IsPMBChecked)
  612. {
  613. pmList.Add("PMB");
  614. }
  615. if (IsPMCChecked)
  616. {
  617. pmList.Add("PMC");
  618. }
  619. if (IsPMDChecked)
  620. {
  621. pmList.Add("PMD");
  622. }
  623. item.ForEach(x =>
  624. {
  625. if (pmList.Contains(x.RecipeId))
  626. {
  627. this.DataHistoryView.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")}" });
  628. }
  629. });
  630. }
  631. }
  632. else
  633. {
  634. this.DataHistoryView.MyDrawGraphicsControl.YPoints.Clear();
  635. }
  636. }
  637. public void ColorChanged()
  638. {
  639. for (int i = 0; i < KeyDataObservableCollection.Count(); i++)
  640. {
  641. var _color = KeyDataObservableCollection[i].Color.Color;
  642. this.DataHistoryView.MyDrawGraphicsControl.m_PenCollencteions[i] = new System.Drawing.Pen(System.Drawing.Color.FromArgb(_color.A, _color.R, _color.G, _color.B), 2);
  643. }
  644. }
  645. public void EnterExitView(bool isEnter)
  646. {
  647. if (isEnter)
  648. {
  649. m_IsEnter = true;
  650. }
  651. else
  652. {
  653. m_IsEnter = false;
  654. }
  655. }
  656. #endregion
  657. }
  658. public class QueryIndexer
  659. {
  660. public DateTime TimeToken { get; set; }
  661. public List<string> DataList { get; set; }
  662. public string Module { get; set; }
  663. }
  664. public class KeyData : BindableBase
  665. {
  666. public string Key { get; set; }
  667. public SolidColorBrush _Color;
  668. public SolidColorBrush Color
  669. {
  670. get { return _Color; }
  671. set { SetProperty(ref _Color, value); }
  672. }
  673. public int UniqueId { get; set; }
  674. }
  675. }