WaferHistoryViewModel.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Windows;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Sorter.Common;
  7. using MECF.Framework.Common.CommonData;
  8. using VirgoUI.Client.Models.Sys;
  9. using MECF.Framework.Common.DataCenter;
  10. using OpenSEMI.ClientBase;
  11. namespace VirgoUI.Client.Models.DataLog.WaferHistory
  12. {
  13. public class WaferHistoryViewModel : BaseModel
  14. {
  15. public DateTime BeginDate { get; set; }
  16. public DateTime UIBeginTime { get; set; }
  17. public DateTime EndDate { get; set; }
  18. public DateTime UIEndTime { get; set; }
  19. public ObservableCollection<HistoryProcessData> ProcessData { get; set; }
  20. public ObservableCollection<HistoryCarrierData> CarrierData { get; set; }
  21. public WaferHistoryViewModel()
  22. {
  23. this.DisplayName = "Wafer History";
  24. this.ProcessData = new ObservableCollection<HistoryProcessData>();
  25. this.CarrierData = new ObservableCollection<HistoryCarrierData>();
  26. var now = DateTime.Now;
  27. EndDate = now;
  28. BeginDate = now;
  29. UIBeginTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0);
  30. UIEndTime = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999);
  31. }
  32. public void Query()
  33. {
  34. this.UpdateProcessData(BeginTime, EndTime);
  35. this.UpdateCarrierData(BeginTime, EndTime);
  36. }
  37. public void UpdateProcessData(DateTime begin, DateTime end)
  38. {
  39. try
  40. {
  41. string sql = string.Format(
  42. "SELECT * FROM \"process_data\" where \"process_begin_time\" >= '{0}' and \"process_begin_time\" <= '{1}' order by \"process_begin_time\" ASC;",
  43. begin.ToString("yyyy/MM/dd HH:mm:ss.fff"), end.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  44. List<HistoryProcessData> result = QueryDataClient.Instance.Service. QueryDBProcess(sql);
  45. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  46. {
  47. ProcessData = new ObservableCollection<HistoryProcessData>();
  48. if (result != null)
  49. {
  50. foreach (HistoryProcessData ev in result)
  51. {
  52. ProcessData.Add(ev);
  53. }
  54. }
  55. NotifyOfPropertyChange("ProcessData");
  56. }));
  57. }
  58. catch (Exception e)
  59. {
  60. LOG.Write(e);
  61. }
  62. }
  63. public void UpdateCarrierData(DateTime begin, DateTime end)
  64. {
  65. try
  66. {
  67. string sql = string.Format(
  68. "SELECT * FROM \"carrier_data\" where \"load_time\" >= '{0}' and \"load_time\" <= '{1}' order by \"load_time\" ASC;",
  69. begin.ToString("yyyy/MM/dd HH:mm:ss.fff"), end.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  70. List<HistoryCarrierData> result = QueryDataClient.Instance.Service.QueryDBCarrier(sql);
  71. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  72. {
  73. CarrierData = new ObservableCollection<HistoryCarrierData>();
  74. if (result != null)
  75. {
  76. foreach (HistoryCarrierData ev in result)
  77. {
  78. CarrierData.Add(ev);
  79. }
  80. }
  81. NotifyOfPropertyChange("CarrierData");
  82. }));
  83. }
  84. catch (Exception e)
  85. {
  86. LOG.Write(e);
  87. }
  88. }
  89. private HistoryCarrierData selectedHistoryProcessData;
  90. public HistoryCarrierData SelectedHistoryProcessData
  91. {
  92. get { return this.selectedHistoryProcessData; }
  93. set
  94. {
  95. this.selectedHistoryProcessData = value;
  96. }
  97. }
  98. private HistoryCarrierData selectedHistoryCarrierData;
  99. public HistoryCarrierData SelectedHistoryCarrierData
  100. {
  101. get { return this.selectedHistoryCarrierData; }
  102. set
  103. {
  104. this.selectedHistoryCarrierData = value;
  105. }
  106. }
  107. private DateTime BeginTime
  108. {
  109. get
  110. {
  111. return new DateTime(BeginDate.Year, BeginDate.Month, BeginDate.Day,
  112. UIBeginTime.Hour, UIBeginTime.Minute, UIBeginTime.Second);
  113. }
  114. }
  115. private DateTime EndTime
  116. {
  117. get
  118. {
  119. return new DateTime(EndDate.Year, EndDate.Month, EndDate.Day,
  120. UIEndTime.Hour, UIEndTime.Minute, UIEndTime.Second, 999);
  121. }
  122. }
  123. }
  124. }