ProcessHistoryView.xaml.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.UI.MVVM;
  3. using Aitex.Core.UI.View.Smart;
  4. using ExcelLibrary.SpreadSheet;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.ComponentModel;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. namespace VirgoUI.Client.Models.History.ProcessHistory
  14. {
  15. /// <summary>
  16. /// DataLogView.xaml 的交互逻辑
  17. /// </summary>
  18. public partial class ProcessHistoryView : UserControl
  19. {
  20. private ProcessHistoryViewModel _viewModel;
  21. public ProcessHistoryView()
  22. {
  23. InitializeComponent();
  24. }
  25. private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
  26. {
  27. RecipeItem item = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
  28. _viewModel = (ProcessHistoryViewModel)DataContext;
  29. _viewModel.UpdateData(item);
  30. ButtonExportData.IsEnabled = item != null;
  31. ButtonExportList.IsEnabled = item != null;
  32. }
  33. private void buttonLotListExport_Click(object sender, System.Windows.RoutedEventArgs e)
  34. {
  35. try
  36. {
  37. ObservableCollection<RecipeItem> DataRecipeList = _viewModel.Recipes;
  38. if (DataRecipeList == null || DataRecipeList.Count == 0) return;
  39. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  40. dlg.DefaultExt = ".xls"; // Default file extension
  41. dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  42. dlg.FileName = string.Format("RecipeList{0}", _viewModel.StartDateTime.ToString("yyyyMMdd"));
  43. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  44. if (result != true) // Process open file dialog box results
  45. return;
  46. if (File.Exists(dlg.FileName))
  47. {
  48. File.Delete(dlg.FileName);
  49. }
  50. Workbook workbook = new Workbook();
  51. Worksheet worksheet = new Worksheet(_viewModel.StartDateTime.ToString("yyyyMMdd"));
  52. int col = 0;
  53. worksheet.Cells[0, col++] = new Cell("Start");
  54. worksheet.Cells[0, col++] = new Cell("End");
  55. worksheet.Cells[0, col++] = new Cell("Chamber");
  56. worksheet.Cells[0, col++] = new Cell("Guid");
  57. worksheet.Cells[0, col++] = new Cell("WaferID");
  58. worksheet.Cells[0, col++] = new Cell("Recipe");
  59. worksheet.Cells[0, col++] = new Cell("Status");
  60. for (int i = 0; i < DataRecipeList.Count; i++)
  61. {
  62. int colCount = 0;
  63. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].StartTime);
  64. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].EndTime);
  65. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Chamber);
  66. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Guid);
  67. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].RecipeRunGuid);
  68. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Recipe);
  69. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Status);
  70. }
  71. workbook.Worksheets.Add(worksheet);
  72. workbook.Save(dlg.FileName);
  73. }
  74. catch (Exception ex)
  75. {
  76. LOG.Error(ex.Message, ex);
  77. }
  78. }
  79. private void buttonLotDetailsExport_Click(object sender, System.Windows.RoutedEventArgs e)
  80. {
  81. try
  82. {
  83. RecipeItem log = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
  84. if (log == null)
  85. {
  86. MessageBox.Show("没有数据,先从列表中选择一个批次");
  87. return;
  88. }
  89. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  90. dlg.DefaultExt = ".xls"; // Default file extension
  91. dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  92. dlg.FileName = string.Format("{0}-{1}", _viewModel.StartDateTime.ToString("yyyyMMdd"), log.Recipe);
  93. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  94. if (result != true) // Process open file dialog box results
  95. return;
  96. if (File.Exists(dlg.FileName))
  97. {
  98. File.Delete(dlg.FileName);
  99. }
  100. Workbook workbook = new Workbook();
  101. Worksheet worksheet = new Worksheet(log.Recipe);
  102. Dictionary<string, int> colIndex = new Dictionary<string, int>();
  103. Dictionary<DateTime, int> rowIndex = new Dictionary<DateTime, int>();
  104. int colCount = 0;
  105. int rowCount = 0;
  106. foreach (var item in _viewModel.ProcessData)
  107. {
  108. if (!rowIndex.ContainsKey(item.dateTime))
  109. {
  110. rowCount++;
  111. rowIndex[item.dateTime] = rowCount;
  112. worksheet.Cells[rowCount, 0] = new Cell(item.dateTime);
  113. }
  114. if (!colIndex.ContainsKey(item.dbName))
  115. {
  116. colCount++;
  117. colIndex[item.dbName] = colCount;
  118. worksheet.Cells[0, colCount] = new Cell(item.dbName);
  119. }
  120. worksheet.Cells[rowIndex[item.dateTime], colIndex[item.dbName]] = new Cell(item.value);
  121. }
  122. workbook.Worksheets.Add(worksheet);
  123. workbook.Save(dlg.FileName);
  124. }
  125. catch (Exception ex)
  126. {
  127. LOG.Error(ex.Message, ex);
  128. }
  129. }
  130. private void OnChangeDrawingItemVisibility(object sender, System.Windows.RoutedEventArgs e)
  131. {
  132. var checkbox = (CheckBox)sender;
  133. if (checkbox != null && checkbox.IsChecked.HasValue)
  134. {
  135. string dataId = (string)checkbox.Tag;
  136. var line = _viewModel.ProcessChartData.RenderableSeries.ToList().Find((o) => ((SmartDataLine)o).UniqueId == dataId);
  137. if (line != null)
  138. {
  139. line.IsVisible = checkbox.IsChecked.Value;
  140. //vm.InvokePropertyChanged("ReflectionDataSeries");
  141. }
  142. }
  143. }
  144. private void OnChangeLineColor(object sender, System.Windows.RoutedEventArgs e)
  145. {
  146. var btn = (Button)sender;
  147. if (btn != null)
  148. {
  149. string dataId = (string)btn.Tag;
  150. var dlg = new System.Windows.Forms.ColorDialog();
  151. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  152. {
  153. var newColor = new System.Windows.Media.Color() { A = dlg.Color.A, B = dlg.Color.B, G = dlg.Color.G, R = dlg.Color.R };
  154. var line = _viewModel.ProcessChartData.RenderableSeries.ToList().Find((o) => ((SmartDataLine)o).UniqueId == dataId);
  155. if (line != null) line.Stroke = newColor;
  156. }
  157. }
  158. }
  159. }
  160. }