ProcessHistoryView.xaml.cs 6.4 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. this.DataContext = new ProcessHistoryViewModel();
  33. }
  34. private ProcessHistoryViewModel _viewModel;
  35. private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
  36. {
  37. RecipeItem item = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
  38. _viewModel = (ProcessHistoryViewModel)DataContext;
  39. _viewModel.UpdateData(item);
  40. ButtonExportData.IsEnabled = item != null;
  41. ButtonExportList.IsEnabled = item != null;
  42. }
  43. private void buttonLotListExport_Click(object sender, System.Windows.RoutedEventArgs e)
  44. {
  45. try
  46. {
  47. ObservableCollection<RecipeItem> DataRecipeList = _viewModel.Recipes;
  48. if (DataRecipeList == null || DataRecipeList.Count == 0) return;
  49. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  50. dlg.DefaultExt = ".xls"; // Default file extension
  51. dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  52. dlg.FileName = string.Format("RecipeList{0}", _viewModel.StartDateTime.ToString("yyyyMMdd"));
  53. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  54. if (result != true) // Process open file dialog box results
  55. return;
  56. if (File.Exists(dlg.FileName))
  57. {
  58. File.Delete(dlg.FileName);
  59. }
  60. Workbook workbook = new Workbook();
  61. Worksheet worksheet = new Worksheet(_viewModel.StartDateTime.ToString("yyyyMMdd"));
  62. int col = 0;
  63. worksheet.Cells[0, col++] = new Cell("Start");
  64. worksheet.Cells[0, col++] = new Cell("End");
  65. worksheet.Cells[0, col++] = new Cell("Chamber");
  66. worksheet.Cells[0, col++] = new Cell("Guid");
  67. worksheet.Cells[0, col++] = new Cell("WaferID");
  68. worksheet.Cells[0, col++] = new Cell("Recipe");
  69. worksheet.Cells[0, col++] = new Cell("Status");
  70. for (int i = 0; i < DataRecipeList.Count; i++)
  71. {
  72. int colCount = 0;
  73. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].StartTime);
  74. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].EndTime);
  75. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Chamber);
  76. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Guid);
  77. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].RecipeRunGuid);
  78. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Recipe);
  79. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Status);
  80. }
  81. workbook.Worksheets.Add(worksheet);
  82. workbook.Save(dlg.FileName);
  83. }
  84. catch (Exception ex)
  85. {
  86. LOG.WriteExeption(ex.Message, ex);
  87. }
  88. }
  89. private void buttonLotDetailsExport_Click(object sender, System.Windows.RoutedEventArgs e)
  90. {
  91. try
  92. {
  93. RecipeItem log = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
  94. if (log == null)
  95. {
  96. MessageBox.Show("没有数据,先从列表中选择一个批次");
  97. return;
  98. }
  99. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  100. dlg.DefaultExt = ".xls"; // Default file extension
  101. dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  102. dlg.FileName = string.Format("{0}-{1}", _viewModel.StartDateTime.ToString("yyyyMMdd"), log.Recipe);
  103. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  104. if (result != true) // Process open file dialog box results
  105. return;
  106. if (File.Exists(dlg.FileName))
  107. {
  108. File.Delete(dlg.FileName);
  109. }
  110. Workbook workbook = new Workbook();
  111. Worksheet worksheet = new Worksheet(log.Recipe);
  112. Dictionary<string, int> colIndex = new Dictionary<string, int>();
  113. Dictionary<DateTime, int> rowIndex = new Dictionary<DateTime, int>();
  114. int colCount = 0;
  115. int rowCount = 0;
  116. foreach (var item in _viewModel.ProcessData)
  117. {
  118. if (!rowIndex.ContainsKey(item.dateTime))
  119. {
  120. rowCount++;
  121. rowIndex[item.dateTime] = rowCount;
  122. worksheet.Cells[rowCount, 0] = new Cell(item.dateTime);
  123. }
  124. if (!colIndex.ContainsKey(item.dbName))
  125. {
  126. colCount++;
  127. colIndex[item.dbName] = colCount;
  128. worksheet.Cells[0, colCount] = new Cell(item.dbName);
  129. }
  130. worksheet.Cells[rowIndex[item.dateTime], colIndex[item.dbName]] = new Cell(item.value);
  131. }
  132. workbook.Worksheets.Add(worksheet);
  133. workbook.Save(dlg.FileName);
  134. }
  135. catch (Exception ex)
  136. {
  137. LOG.WriteExeption(ex.Message, ex);
  138. }
  139. }
  140. }
  141. }