WaferHistoryViewModel.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Data;
  4. using System.Windows;
  5. using Aitex.Core.RT.Log;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.Utilities;
  8. using MECF.Framework.UI.Client.ClientBase;
  9. using OpenSEMI.ClientBase;
  10. using SciChart.Charting.Model.DataSeries;
  11. using SciChart.Charting.Visuals.Annotations;
  12. using SciChart.Charting.Visuals.RenderableSeries;
  13. using SciChart.Data.Model;
  14. namespace MECF.Framework.UI.Client.CenterViews.DataLogs.WaferHistory
  15. {
  16. public class WaferHistoryDetail
  17. {
  18. public string Guid { get; set; }
  19. public string CreateTime { get; set; }
  20. public string DeleteTime { get; set; }
  21. public string LoadPort { get; set; }
  22. public string Slot { get; set; }
  23. public string CarrierID { get; set; }
  24. public string LotID { get; set; }
  25. public string WaferID { get; set; }
  26. public string Status { get; set; }
  27. public string LotId { get; set; }
  28. public string SequenceName { get; set; }
  29. public string NotchAngle { get; set; }
  30. }
  31. public class WaferMovement
  32. {
  33. public string Time { get; set; }
  34. public string Station { get; set; }
  35. public string Slot { get; set; }
  36. public string Status { get; set; }
  37. public string WaferID { get; set; }
  38. }
  39. public class WaferHistoryViewModel : BaseModel
  40. {
  41. public bool IsPermission { get => this.Permission == 3; }
  42. public DateTime BeginDate { get; set; }
  43. public DateTime StartDateTime { get; set; }
  44. public DateTime EndDateTime { get; set; }
  45. public DateTime UIEndTime { get; set; }
  46. public ObservableCollection<WaferHistoryDetail> Wafers { get; set; }
  47. public ObservableCollection<WaferMovement> Movements { get; set; }
  48. public ObservableCollection<string> SourceLP { get; set; }
  49. public string SelectedValueLP { get; set; }
  50. public WaferHistoryViewModel()
  51. {
  52. this.DisplayName = "Wafer History";
  53. var now = DateTime.Now;
  54. this.StartDateTime = now;
  55. this.BeginDate = now;
  56. this.StartDateTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0);
  57. this.EndDateTime = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999);
  58. this.Wafers = new ObservableCollection<WaferHistoryDetail>();
  59. this.Movements = new ObservableCollection<WaferMovement>();
  60. SourceLP = new ObservableCollection<string>(new[] { "LP1", "LP2", "LP3" });
  61. }
  62. protected override void OnInitialize()
  63. {
  64. base.OnInitialize();
  65. this.YLabelProvider = new YAxisLabelProvider();
  66. this.RenderableSeries = new ObservableCollection<IRenderableSeries>();
  67. this.RenderableSeries.Add(new FastLineRenderableSeries() { DataSeries = new XyDataSeries<int, int>() });
  68. this.Annotations = new AnnotationCollection();
  69. }
  70. private WaferHistoryView view;
  71. public void Query(string loadport, string waferid, string lotid, string carrierid, string sequencename, string processchamber, string processrecipe)
  72. {
  73. try
  74. {
  75. this.StartDateTime = this.view.wfTimeFrom.Value;
  76. this.EndDateTime = this.view.wfTimeTo.Value;
  77. if (StartDateTime > EndDateTime)
  78. {
  79. MessageBox.Show("Time range invalid, start time should be early than end time");
  80. return;
  81. }
  82. string sql = string.Format(
  83. "SELECT * FROM \"wafer_data\",\"carrier_data\" where \"create_time\" >= '{0}' and \"create_time\" <= '{1}' and \"wafer_data\".\"carrier_data_guid\"=\"carrier_data\".\"guid\"",
  84. StartDateTime.ToString("yyyy/MM/dd HH:mm:ss.fff"), EndDateTime.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  85. if (!string.IsNullOrWhiteSpace(loadport))
  86. {
  87. sql += " and (FALSE ";
  88. var loadPorts = loadport.Split(',');
  89. for (int i = 0; i < loadPorts.Length; i++)
  90. {
  91. sql += $" OR \"create_station\"='{loadPorts[i]}'";
  92. }
  93. sql += " )";
  94. }
  95. if (!string.IsNullOrWhiteSpace(waferid))
  96. sql += $" and lower(\"wafer_id\") like '%{waferid.ToLower()}%'";
  97. if (!string.IsNullOrWhiteSpace(lotid))
  98. sql += $" and lower(\"wafer_data\".\"lot_id\") like '%{lotid.ToLower()}%'";
  99. if (!string.IsNullOrWhiteSpace(carrierid))
  100. sql += $" and lower(\"rfid\") like '%{carrierid.ToLower()}%'";
  101. sql += " order by \"create_time\" ASC, \"create_station\" ASC,\"create_slot\" ASC";
  102. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  103. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  104. {
  105. Wafers.Clear();
  106. try
  107. {
  108. if (dbData == null || dbData.Rows.Count == 0)
  109. return;
  110. for (int i = 0; i < dbData.Rows.Count; i++)
  111. {
  112. WaferHistoryDetail item = new WaferHistoryDetail();
  113. item.Guid = dbData.Rows[i]["guid"].ToString();
  114. item.LoadPort = dbData.Rows[i]["create_station"].ToString();
  115. item.Slot = dbData.Rows[i]["create_slot"].ToString();
  116. item.CarrierID = dbData.Rows[i]["rfid"].ToString();
  117. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  118. item.WaferID = dbData.Rows[i]["wafer_id"].ToString();
  119. item.Status = dbData.Rows[i]["process_status"].ToString();
  120. if (!dbData.Rows[i]["create_time"].Equals(DBNull.Value))
  121. item.CreateTime = ((DateTime)dbData.Rows[i]["create_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  122. if (!dbData.Rows[i]["delete_time"].Equals(DBNull.Value))
  123. item.DeleteTime = ((DateTime)dbData.Rows[i]["delete_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  124. Wafers.Add(item);
  125. }
  126. }
  127. catch (Exception ex)
  128. {
  129. LOG.Write(ex);
  130. }
  131. }));
  132. }
  133. catch (Exception e)
  134. {
  135. LOG.Write(e);
  136. }
  137. }
  138. public void WaferHistoryChanged(WaferHistoryDetail detail)
  139. {
  140. try
  141. {
  142. if (detail == null)
  143. {
  144. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  145. {
  146. Movements.Clear();
  147. }));
  148. return;
  149. }
  150. string sql = string.Format(
  151. "SELECT * FROM \"wafer_move_history\" where \"wafer_data_guid\" = '{0}' order by \"arrive_time\" ASC;",
  152. detail.Guid);
  153. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  154. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  155. {
  156. Movements.Clear();
  157. if (dbData == null || dbData.Rows.Count == 0)
  158. return;
  159. for (int i = 0; i < dbData.Rows.Count; i++)
  160. {
  161. WaferMovement item = new WaferMovement();
  162. item.Station = dbData.Rows[i]["station"].ToString();
  163. item.Slot = dbData.Rows[i]["slot"].ToString();
  164. item.Status = dbData.Rows[i]["status"].ToString();
  165. item.WaferID = detail.WaferID;
  166. if (!dbData.Rows[i]["arrive_time"].Equals(DBNull.Value))
  167. item.Time = ((DateTime)dbData.Rows[i]["arrive_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  168. Movements.Add(item);
  169. }
  170. }));
  171. }
  172. catch (Exception e)
  173. {
  174. LOG.Write(e);
  175. }
  176. }
  177. public void Export()
  178. {
  179. try
  180. {
  181. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  182. dlg.DefaultExt = ".xlsx"; // Default file extension
  183. dlg.FileName = $"{DisplayName}_{DateTime.Now:yyyyMMdd_HHmmss}";
  184. dlg.Filter = "Excel数据表格文件(*.xlsx)|*.xlsx"; // Filter files by extension
  185. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  186. if (result == true) // Process open file dialog box results
  187. {
  188. System.Data.DataSet ds = new System.Data.DataSet();
  189. ds.Tables.Add(new System.Data.DataTable("系统运行日志"));
  190. ds.Tables[0].Columns.Add("CreateTime");
  191. ds.Tables[0].Columns.Add("DeleteTime");
  192. ds.Tables[0].Columns.Add("LoadPort");
  193. ds.Tables[0].Columns.Add("Slot");
  194. ds.Tables[0].Columns.Add("CarrierID");
  195. ds.Tables[0].Columns.Add("LotID");
  196. ds.Tables[0].Columns.Add("WaferID");
  197. ds.Tables[0].Columns.Add("Status");
  198. foreach (var item in Wafers)
  199. {
  200. var row = ds.Tables[0].NewRow();
  201. row[0] = item.CreateTime;
  202. row[1] = item.DeleteTime;
  203. row[2] = item.LoadPort;
  204. row[3] = item.Slot;
  205. row[4] = item.CarrierID;
  206. row[5] = item.LotID;
  207. row[6] = item.WaferID;
  208. row[7] = item.Status;
  209. ds.Tables[0].Rows.Add(row);
  210. }
  211. if (!ExcelHelper.ExportToExcel(dlg.FileName, ds, out string reason))
  212. {
  213. MessageBox.Show($"Export failed, {reason}", "Export", MessageBoxButton.OK, MessageBoxImage.Warning);
  214. return;
  215. }
  216. MessageBox.Show($"Export succeed, file save as {dlg.FileName}", "Export", MessageBoxButton.OK, MessageBoxImage.Information);
  217. }
  218. }
  219. catch (Exception ex)
  220. {
  221. LOG.Write(ex);
  222. MessageBox.Show("导出系统日志发生错误", "导出失败", MessageBoxButton.OK, MessageBoxImage.Warning);
  223. }
  224. }
  225. public void ExportMove()
  226. {
  227. try
  228. {
  229. if (Movements.Count == 0)
  230. {
  231. DialogBox.ShowDialog(DialogButton.OK, DialogType.INFO, "No wafer move history to export.");
  232. return;
  233. }
  234. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  235. dlg.DefaultExt = ".xlsx"; // Default file extension
  236. dlg.FileName = $"Wafer_Move_History_{DateTime.Now:yyyyMMdd_HHmmss}";
  237. dlg.Filter = "Excel数据表格文件(*.xlsx)|*.xlsx"; // Filter files by extension
  238. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  239. if (result == true) // Process open file dialog box results
  240. {
  241. System.Data.DataSet ds = new System.Data.DataSet();
  242. ds.Tables.Add(new System.Data.DataTable("系统运行日志"));
  243. ds.Tables[0].Columns.Add("Time");
  244. ds.Tables[0].Columns.Add("Station");
  245. ds.Tables[0].Columns.Add("Slot");
  246. ds.Tables[0].Columns.Add("Status");
  247. ds.Tables[0].Columns.Add("WaferId");
  248. foreach (var item in Movements)
  249. {
  250. var row = ds.Tables[0].NewRow();
  251. row[0] = item.Time;
  252. row[1] = item.Station;
  253. row[2] = item.Slot;
  254. row[3] = item.Status;
  255. row[4] = item.WaferID;
  256. ds.Tables[0].Rows.Add(row);
  257. }
  258. if (!ExcelHelper.ExportToExcel(dlg.FileName, ds, out string reason))
  259. {
  260. MessageBox.Show($"Export failed, {reason}", "Export", MessageBoxButton.OK, MessageBoxImage.Warning);
  261. return;
  262. }
  263. MessageBox.Show($"Export succeed, file save as {dlg.FileName}", "Export", MessageBoxButton.OK, MessageBoxImage.Information);
  264. }
  265. }
  266. catch (Exception ex)
  267. {
  268. LOG.Write(ex);
  269. MessageBox.Show($"导出系统日志发生错误", "导出失败", MessageBoxButton.OK, MessageBoxImage.Warning);
  270. }
  271. }
  272. #region scichart
  273. public ObservableCollection<IRenderableSeries> RenderableSeries
  274. {
  275. get;
  276. set;
  277. }
  278. private AnnotationCollection _annotations = new AnnotationCollection();
  279. public AnnotationCollection Annotations
  280. {
  281. get { return _annotations; }
  282. set { _annotations = value; }
  283. }
  284. private IRange _TimeRange;
  285. public IRange TimeRange
  286. {
  287. get { return _TimeRange; }
  288. set
  289. {
  290. _TimeRange = value;
  291. NotifyOfPropertyChange("TimeRange");
  292. }
  293. }
  294. private IRange _YTimeRange;
  295. public IRange YTimeRange
  296. {
  297. get { return _YTimeRange; }
  298. set { _YTimeRange = value; }
  299. }
  300. public YAxisLabelProvider YLabelProvider { get; set; }
  301. public void AppendData()
  302. {
  303. (this.RenderableSeries[0].DataSeries as XyDataSeries<int, int>).Clear();
  304. for (var index = 1; index <= 8; index++)
  305. {
  306. (this.RenderableSeries[0].DataSeries as XyDataSeries<int, int>).Append(index * 5, index);
  307. this.Annotations.Add(new LineArrowAnnotation() { X1 = index * 5, Y1 = index, X2 = index * 5, Y2 = index + 2, });
  308. }
  309. }
  310. protected override void OnViewLoaded(object _view)
  311. {
  312. base.OnViewLoaded(_view);
  313. this.view = (WaferHistoryView)_view;
  314. this.view.wfTimeFrom.Value = this.StartDateTime;
  315. this.view.wfTimeTo.Value = this.EndDateTime;
  316. this.AppendData();
  317. }
  318. #endregion
  319. }
  320. }