ProcessHistoryView.xaml.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Aitex.Core.RT.Log;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using ExcelLibrary.SpreadSheet;
  17. using Venus_MainPages.ViewModels;
  18. //using Xceed.Wpf.DataGrid;
  19. using System.IO;
  20. using static Venus_MainPages.ViewModels.ProcessHistoryViewModel;
  21. using System.Collections.ObjectModel;
  22. namespace Venus_MainPages.Views
  23. {
  24. /// <summary>
  25. /// ProcessHistoryView.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class ProcessHistoryView : UserControl
  28. {
  29. public ProcessHistoryView()
  30. {
  31. InitializeComponent();
  32. }
  33. private ProcessHistoryViewModel _viewModel;
  34. private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
  35. {
  36. RecipeItem item = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
  37. _viewModel = (ProcessHistoryViewModel)DataContext;
  38. _viewModel.UpdateData(item);
  39. ButtonExportData.IsEnabled = item != null;
  40. ButtonExportList.IsEnabled = item != null;
  41. }
  42. private void buttonLotListExport_Click(object sender, System.Windows.RoutedEventArgs e)
  43. {
  44. try
  45. {
  46. ObservableCollection<RecipeItem> DataRecipeList = _viewModel.Recipes;
  47. if (DataRecipeList == null || DataRecipeList.Count == 0) return;
  48. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  49. dlg.DefaultExt = ".xls"; // Default file extension
  50. dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  51. dlg.FileName = string.Format("RecipeList{0}", _viewModel.StartDateTime.ToString("yyyyMMdd"));
  52. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  53. if (result != true) // Process open file dialog box results
  54. return;
  55. if (File.Exists(dlg.FileName))
  56. {
  57. File.Delete(dlg.FileName);
  58. }
  59. Workbook workbook = new Workbook();
  60. Worksheet worksheet = new Worksheet(_viewModel.StartDateTime.ToString("yyyyMMdd"));
  61. int col = 0;
  62. worksheet.Cells[0, col++] = new Cell("Start");
  63. worksheet.Cells[0, col++] = new Cell("End");
  64. worksheet.Cells[0, col++] = new Cell("Chamber");
  65. worksheet.Cells[0, col++] = new Cell("Guid");
  66. worksheet.Cells[0, col++] = new Cell("WaferID");
  67. worksheet.Cells[0, col++] = new Cell("Recipe");
  68. worksheet.Cells[0, col++] = new Cell("Status");
  69. for (int i = 0; i < DataRecipeList.Count; i++)
  70. {
  71. int colCount = 0;
  72. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].StartTime);
  73. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].EndTime);
  74. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Chamber);
  75. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Guid);
  76. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].RecipeRunGuid);
  77. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Recipe);
  78. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Status);
  79. }
  80. workbook.Worksheets.Add(worksheet);
  81. workbook.Save(dlg.FileName);
  82. }
  83. catch (Exception ex)
  84. {
  85. LOG.WriteExeption(ex.Message, ex);
  86. }
  87. }
  88. private void buttonLotDetailsExport_Click(object sender, System.Windows.RoutedEventArgs e)
  89. {
  90. try
  91. {
  92. RecipeItem log = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
  93. if (log == null)
  94. {
  95. MessageBox.Show("没有数据,先从列表中选择一个批次");
  96. return;
  97. }
  98. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  99. dlg.DefaultExt = ".xls"; // Default file extension
  100. dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  101. dlg.FileName = string.Format("{0}-{1}", _viewModel.StartDateTime.ToString("yyyyMMdd"), log.Recipe);
  102. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  103. if (result != true) // Process open file dialog box results
  104. return;
  105. if (File.Exists(dlg.FileName))
  106. {
  107. File.Delete(dlg.FileName);
  108. }
  109. Workbook workbook = new Workbook();
  110. Worksheet worksheet = new Worksheet(log.Recipe);
  111. Dictionary<string, int> colIndex = new Dictionary<string, int>();
  112. Dictionary<DateTime, int> rowIndex = new Dictionary<DateTime, int>();
  113. int colCount = 0;
  114. int rowCount = 0;
  115. foreach (var item in _viewModel.ProcessData)
  116. {
  117. if (!rowIndex.ContainsKey(item.dateTime))
  118. {
  119. rowCount++;
  120. rowIndex[item.dateTime] = rowCount;
  121. worksheet.Cells[rowCount, 0] = new Cell(item.dateTime);
  122. }
  123. if (!colIndex.ContainsKey(item.dbName))
  124. {
  125. colCount++;
  126. colIndex[item.dbName] = colCount;
  127. worksheet.Cells[0, colCount] = new Cell(item.dbName);
  128. }
  129. worksheet.Cells[rowIndex[item.dateTime], colIndex[item.dbName]] = new Cell(item.value);
  130. }
  131. workbook.Worksheets.Add(worksheet);
  132. workbook.Save(dlg.FileName);
  133. }
  134. catch (Exception ex)
  135. {
  136. LOG.WriteExeption(ex.Message, ex);
  137. }
  138. }
  139. }
  140. }