ProcessHistoryView.xaml.cs 8.0 KB

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