KeplerProcessHistoryView.xaml.cs 8.1 KB

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