using Aitex.Core.RT.Log;
using Aitex.Core.UI.MVVM;
using Aitex.Core.UI.View.Smart;
using ExcelLibrary.SpreadSheet;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace VirgoUI.Client.Models.History.ProcessHistory
{
///
/// DataLogView.xaml 的交互逻辑
///
public partial class ProcessHistoryView : UserControl
{
private ProcessHistoryViewModel _viewModel;
public ProcessHistoryView()
{
InitializeComponent();
}
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
RecipeItem item = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
_viewModel = (ProcessHistoryViewModel)DataContext;
_viewModel.UpdateData(item);
ButtonExportData.IsEnabled = item != null;
ButtonExportList.IsEnabled = item != null;
}
private void buttonLotListExport_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
ObservableCollection DataRecipeList = _viewModel.Recipes;
if (DataRecipeList == null || DataRecipeList.Count == 0) return;
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.DefaultExt = ".xls"; // Default file extension
dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
dlg.FileName = string.Format("RecipeList{0}", _viewModel.StartDateTime.ToString("yyyyMMdd"));
Nullable result = dlg.ShowDialog();// Show open file dialog box
if (result != true) // Process open file dialog box results
return;
if (File.Exists(dlg.FileName))
{
File.Delete(dlg.FileName);
}
Workbook workbook = new Workbook();
Worksheet worksheet = new Worksheet(_viewModel.StartDateTime.ToString("yyyyMMdd"));
int col = 0;
worksheet.Cells[0, col++] = new Cell("Start");
worksheet.Cells[0, col++] = new Cell("End");
worksheet.Cells[0, col++] = new Cell("Chamber");
worksheet.Cells[0, col++] = new Cell("Guid");
worksheet.Cells[0, col++] = new Cell("WaferID");
worksheet.Cells[0, col++] = new Cell("Recipe");
worksheet.Cells[0, col++] = new Cell("Status");
for (int i = 0; i < DataRecipeList.Count; i++)
{
int colCount = 0;
worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].StartTime);
worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].EndTime);
worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Chamber);
worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Guid);
worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].RecipeRunGuid);
worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Recipe);
worksheet.Cells[i + 1, colCount++] = new Cell(DataRecipeList[i].Status);
}
workbook.Worksheets.Add(worksheet);
workbook.Save(dlg.FileName);
}
catch (Exception ex)
{
LOG.Error(ex.Message, ex);
}
}
private void buttonLotDetailsExport_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
RecipeItem log = (dataGrid_RecipeList.SelectedItem) as RecipeItem;
if (log == null)
{
MessageBox.Show("没有数据,先从列表中选择一个批次");
return;
}
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.DefaultExt = ".xls"; // Default file extension
dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
dlg.FileName = string.Format("{0}-{1}", _viewModel.StartDateTime.ToString("yyyyMMdd"), log.Recipe);
Nullable result = dlg.ShowDialog();// Show open file dialog box
if (result != true) // Process open file dialog box results
return;
if (File.Exists(dlg.FileName))
{
File.Delete(dlg.FileName);
}
Workbook workbook = new Workbook();
Worksheet worksheet = new Worksheet(log.Recipe);
Dictionary colIndex = new Dictionary();
Dictionary rowIndex = new Dictionary();
int colCount = 0;
int rowCount = 0;
foreach (var item in _viewModel.ProcessData)
{
if (!rowIndex.ContainsKey(item.dateTime))
{
rowCount++;
rowIndex[item.dateTime] = rowCount;
worksheet.Cells[rowCount, 0] = new Cell(item.dateTime);
}
if (!colIndex.ContainsKey(item.dbName))
{
colCount++;
colIndex[item.dbName] = colCount;
worksheet.Cells[0, colCount] = new Cell(item.dbName);
}
worksheet.Cells[rowIndex[item.dateTime], colIndex[item.dbName]] = new Cell(item.value);
}
workbook.Worksheets.Add(worksheet);
workbook.Save(dlg.FileName);
}
catch (Exception ex)
{
LOG.Error(ex.Message, ex);
}
}
private void OnChangeDrawingItemVisibility(object sender, System.Windows.RoutedEventArgs e)
{
var checkbox = (CheckBox)sender;
if (checkbox != null && checkbox.IsChecked.HasValue)
{
string dataId = (string)checkbox.Tag;
var line = _viewModel.ProcessChartData.RenderableSeries.ToList().Find((o) => ((SmartDataLine)o).UniqueId == dataId);
if (line != null)
{
line.IsVisible = checkbox.IsChecked.Value;
//vm.InvokePropertyChanged("ReflectionDataSeries");
}
}
}
private void OnChangeLineColor(object sender, System.Windows.RoutedEventArgs e)
{
var btn = (Button)sender;
if (btn != null)
{
string dataId = (string)btn.Tag;
var dlg = new System.Windows.Forms.ColorDialog();
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var newColor = new System.Windows.Media.Color() { A = dlg.Color.A, B = dlg.Color.B, G = dlg.Color.G, R = dlg.Color.R };
var line = _viewModel.ProcessChartData.RenderableSeries.ToList().Find((o) => ((SmartDataLine)o).UniqueId == dataId);
if (line != null) line.Stroke = newColor;
}
}
}
}
}