| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 | 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{    /// <summary>    /// DataLogView.xaml 的交互逻辑    /// </summary>    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<RecipeItem> 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<bool> 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<bool> 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<string, int> colIndex = new Dictionary<string, int>();                Dictionary<DateTime, int> rowIndex = new Dictionary<DateTime, int>();                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;                }            }        }    }}
 |