ProcessHistoryView.xaml.cs 7.7 KB

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