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