ProcessHistoryView.xaml.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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("Start");
  68. // worksheet.Cells[0, col++] = new Cell("End");
  69. // worksheet.Cells[0, col++] = new Cell("Chamber");
  70. // worksheet.Cells[0, col++] = new Cell("Guid");
  71. // worksheet.Cells[0, col++] = new Cell("WaferID");
  72. // worksheet.Cells[0, col++] = new Cell("Recipe");
  73. // worksheet.Cells[0, col++] = new Cell("Status");
  74. // for (int i = 0; i < DataRecipeList.Count; i++)
  75. // {
  76. // int colCount = 0;
  77. // worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].StartTime);
  78. // worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].EndTime);
  79. // worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Chamber);
  80. // worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Guid);
  81. // worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].RecipeRunGuid);
  82. // worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Recipe);
  83. // worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Status);
  84. // }
  85. // workbook.Worksheets.Add(worksheet);
  86. // workbook.Save(dlg.FileName);
  87. // }
  88. // catch (Exception ex)
  89. // {
  90. // LOG.WriteExeption(ex.Message, ex);
  91. // }
  92. //}
  93. private void OnChangeLineColor(object sender, RoutedEventArgs e)
  94. {
  95. var btn = (Button)sender;
  96. if (btn != null)
  97. {
  98. int dataId = (int)btn.Tag;
  99. var dlg = new System.Windows.Forms.ColorDialog();
  100. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  101. {
  102. var newColor = new System.Windows.Media.Color() { A = dlg.Color.A, B = dlg.Color.B, G = dlg.Color.G, R = dlg.Color.R };
  103. System.Drawing.Color _newColor = System.Drawing.Color.FromArgb(newColor.A, newColor.R, newColor.G, newColor.B);
  104. _viewModel = (ProcessHistoryViewModel)DataContext;
  105. var item = _viewModel.PdKeyDataCollection.ToList().Find(t => t.UniqueId == dataId);
  106. item.Color = new SolidColorBrush(newColor);
  107. _viewModel.ColorChanged();
  108. }
  109. }
  110. }
  111. //private void buttonLotDetailsExport_Click(object sender, System.Windows.RoutedEventArgs e)
  112. //{
  113. // try
  114. // {
  115. // RecipeItem log = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
  116. // if (log == null)
  117. // {
  118. // MessageBox.Show("没有数据,先从列表中选择一个批次");
  119. // return;
  120. // }
  121. // _viewModel = (ProcessHistoryViewModel)DataContext;
  122. // Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  123. // dlg.DefaultExt = ".xls"; // Default file extension
  124. // dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  125. // dlg.FileName = string.Format("{0}-{1}", _viewModel.StartDateTime.ToString("yyyyMMdd"), log.Recipe.Replace(" ","").Replace("/", ""));
  126. // Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  127. // if (result != true) // Process open file dialog box results
  128. // return;
  129. // if (File.Exists(dlg.FileName))
  130. // {
  131. // File.Delete(dlg.FileName);
  132. // }
  133. // Workbook workbook = new Workbook();
  134. // Worksheet worksheet = new Worksheet(log.Recipe);
  135. // Dictionary<string, int> colIndex = new Dictionary<string, int>();
  136. // Dictionary<string, int> rowIndex = new Dictionary<string, int>();
  137. // int colCount = 0;
  138. // int rowCount = 0;
  139. // foreach (var item in _viewModel.ProcessData)
  140. // {
  141. // if (!rowIndex.ContainsKey(item.dateTime.ToString("G")))
  142. // {
  143. // rowCount++;
  144. // rowIndex[item.dateTime.ToString("G")] = rowCount;
  145. // worksheet.Cells[rowCount, 0] = new Cell(item.dateTime.ToString("G"));
  146. // }
  147. // if (!colIndex.ContainsKey(item.dbName))
  148. // {
  149. // colCount++;
  150. // colIndex[item.dbName] = colCount;
  151. // worksheet.Cells[0, colCount] = new Cell(item.dbName);
  152. // }
  153. // worksheet.Cells[rowIndex[item.dateTime.ToString("G")], colIndex[item.dbName]] = new Cell(item.value);
  154. // }
  155. // workbook.Worksheets.Add(worksheet);
  156. // workbook.Save(dlg.FileName);
  157. // }
  158. // catch (Exception ex)
  159. // {
  160. // LOG.WriteExeption(ex.Message, ex);
  161. // }
  162. //}
  163. }
  164. }