WaferHistory2ViewModel.cs 16 KB

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