ProcessHistoryView.xaml.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.UI.MVVM;
  3. using Aitex.Core.UI.View.Smart;
  4. using ExcelLibrary.SpreadSheet;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.ComponentModel;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. namespace VirgoUI.Client.Models.History.ProcessHistory
  14. {
  15. /// <summary>
  16. /// DataLogView.xaml 的交互逻辑
  17. /// </summary>
  18. public partial class ProcessHistoryView : UserControl
  19. {
  20. private ProcessHistoryViewModel _viewModel;
  21. public ProcessHistoryView()
  22. {
  23. InitializeComponent();
  24. }
  25. private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
  26. {
  27. RecipeItem item = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
  28. _viewModel = (ProcessHistoryViewModel)DataContext;
  29. _viewModel.UpdateData(item);
  30. ButtonExportData.IsEnabled = item != null;
  31. ButtonExportList.IsEnabled = item != null;
  32. }
  33. private void buttonLotListExport_Click(object sender, System.Windows.RoutedEventArgs e)
  34. {
  35. try
  36. {
  37. ObservableCollection<RecipeItem> DataRecipeList = _viewModel.Recipes;
  38. if (DataRecipeList == null || DataRecipeList.Count == 0) return;
  39. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  40. dlg.DefaultExt = ".xls"; // Default file extension
  41. //dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
  42. dlg.Filter = "Excel(*.xls)|*.xls"; // Filter files by extension
  43. dlg.FileName = string.Format("RecipeList{0}", _viewModel.StartDateTime.ToString("yyyyMMdd"));
  44. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  45. if (result != true) // Process open file dialog box results
  46. return;
  47. if (File.Exists(dlg.FileName))
  48. {
  49. File.Delete(dlg.FileName);
  50. }
  51. Workbook workbook = new Workbook();
  52. Worksheet worksheet = new Worksheet(_viewModel.StartDateTime.ToString("yyyyMMdd"));
  53. int col = 0;
  54. worksheet.Cells[0, col++] = new Cell("LotID");
  55. worksheet.Cells[0, col++] = new Cell("SlotID");
  56. worksheet.Cells[0, col++] = new Cell("Start");
  57. worksheet.Cells[0, col++] = new Cell("End");
  58. worksheet.Cells[0, col++] = new Cell("Chamber");
  59. //worksheet.Cells[0, col++] = new Cell("Guid");
  60. //worksheet.Cells[0, col++] = new Cell("WaferID");
  61. worksheet.Cells[0, col++] = new Cell("Recipe");
  62. worksheet.Cells[0, col++] = new Cell("Status");
  63. for (int i = 0; i < DataRecipeList.Count; i++)
  64. {
  65. int colCount = 0;
  66. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].LotID);
  67. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].SlotID);
  68. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].StartTime);
  69. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].EndTime);
  70. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Chamber);
  71. //worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Guid);
  72. //worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].RecipeRunGuid);
  73. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Recipe);
  74. worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Status);
  75. }
  76. workbook.Worksheets.Add(worksheet);
  77. workbook.Save(dlg.FileName);
  78. }
  79. catch (Exception ex)
  80. {
  81. LOG.Error(ex.Message, ex);
  82. }
  83. }
  84. private void buttonLotDetailsExport_Click(object sender, System.Windows.RoutedEventArgs e)
  85. {
  86. try
  87. {
  88. RecipeItem log = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
  89. if (log == null)
  90. {
  91. MessageBox.Show("No choice data");
  92. return;
  93. }
  94. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  95. dlg.DefaultExt = ".xls"; // Default file extension
  96. dlg.Filter = "Excel(*.xls)|*.xls"; // Filter files by extension
  97. dlg.FileName = string.Format("{0}-{1}", _viewModel.StartDateTime.ToString("yyyyMMdd"), log.Recipe);
  98. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  99. if (result != true) // Process open file dialog box results
  100. return;
  101. if (File.Exists(dlg.FileName))
  102. {
  103. File.Delete(dlg.FileName);
  104. }
  105. Workbook workbook = new Workbook();
  106. Worksheet worksheet = new Worksheet(log.Recipe);
  107. Dictionary<string, int> colIndex = new Dictionary<string, int>();
  108. Dictionary<DateTime, int> rowIndex = new Dictionary<DateTime, int>();
  109. int colCount = 0;
  110. int rowCount = 0;
  111. foreach (var item in _viewModel.ProcessData)
  112. {
  113. var selectItems = _viewModel.ProcessChartData.RenderableSeries.Where(p => p is SmartDataLine && ((SmartDataLine)p).DisplayName == item.dbName);
  114. if (selectItems != null && selectItems.Count() > 0)
  115. {
  116. var selectItem = selectItems.ToList()[0] as SmartDataLine;
  117. if (selectItem != null && !selectItem.IsVisible)
  118. continue;
  119. }
  120. if (!rowIndex.ContainsKey(item.dateTime))
  121. {
  122. rowCount++;
  123. rowIndex[item.dateTime] = rowCount;
  124. worksheet.Cells[rowCount, 0] = new Cell(item.dateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
  125. }
  126. if (!colIndex.ContainsKey(item.dbName))
  127. {
  128. colCount++;
  129. colIndex[item.dbName] = colCount;
  130. worksheet.Cells[0, colCount] = new Cell(item.dbName);
  131. }
  132. worksheet.Cells[rowIndex[item.dateTime], colIndex[item.dbName]] = new Cell(item.value);
  133. }
  134. workbook.Worksheets.Add(worksheet);
  135. workbook.Save(dlg.FileName);
  136. }
  137. catch (Exception ex)
  138. {
  139. LOG.Error(ex.Message, ex);
  140. }
  141. }
  142. private void OnChangeDrawingItemVisibility(object sender, System.Windows.RoutedEventArgs e)
  143. {
  144. var checkbox = (CheckBox)sender;
  145. if (checkbox != null && checkbox.IsChecked.HasValue)
  146. {
  147. string dataId = (string)checkbox.Tag;
  148. var line = _viewModel.ProcessChartData.RenderableSeries.ToList().Find((o) => ((SmartDataLine)o).UniqueId == dataId);
  149. if (line != null)
  150. {
  151. line.IsVisible = checkbox.IsChecked.Value;
  152. //vm.InvokePropertyChanged("ReflectionDataSeries");
  153. }
  154. }
  155. }
  156. private void OnChangeLineColor(object sender, System.Windows.RoutedEventArgs e)
  157. {
  158. var btn = (Button)sender;
  159. if (btn != null)
  160. {
  161. string dataId = (string)btn.Tag;
  162. var dlg = new System.Windows.Forms.ColorDialog();
  163. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  164. {
  165. var newColor = new System.Windows.Media.Color() { A = dlg.Color.A, B = dlg.Color.B, G = dlg.Color.G, R = dlg.Color.R };
  166. var line = _viewModel.ProcessChartData.RenderableSeries.ToList().Find((o) => ((SmartDataLine)o).UniqueId == dataId);
  167. if (line != null) line.Stroke = newColor;
  168. }
  169. }
  170. }
  171. }
  172. }