| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 | using System;using System.Collections.Generic;using System.Linq;using Aitex.Core.RT.Log;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using ExcelLibrary.SpreadSheet;using PunkHPX8_MainPages.ViewModels;//using Xceed.Wpf.DataGrid;using System.IO;using System.Collections.ObjectModel;using Aitex.Core.UI.View.Smart;using System.Drawing;using LiveCharts.Wpf;namespace PunkHPX8_MainPages.Views{    /// <summary>    /// ProcessHistoryView.xaml 的交互逻辑    /// </summary>    public partial class ProcessHistoryView : UserControl    {        public ProcessHistoryView()        {            InitializeComponent();            this.DataContext = new ProcessHistoryViewModel();        }        private ProcessHistoryViewModel _viewModel;        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            {                _viewModel = (ProcessHistoryViewModel)DataContext;                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.WriteExeption(ex.Message, ex);            }        }        private void OnChangeLineColor(object sender, RoutedEventArgs e)        {            var btn = (Button)sender;            if (btn != null)            {                int dataId = (int)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 };                    System.Drawing.Color _newColor = System.Drawing.Color.FromArgb(newColor.A, newColor.R, newColor.G, newColor.B);                    _viewModel = (ProcessHistoryViewModel)DataContext;                    var item = _viewModel.PdKeyDataCollection.ToList().Find(t => t.UniqueId == dataId);                    item.Color = new SolidColorBrush(newColor);                     _viewModel.OnSearchData();                }            }        }        private void buttonLotDetailsExport_Click(object sender, System.Windows.RoutedEventArgs e)        {            try            {                RecipeItem log = (dataGrid_RecipeList.SelectedItem) as RecipeItem;                if (log == null)                {                    MessageBox.Show("没有数据,先从列表中选择一个批次");                    return;                }                _viewModel = (ProcessHistoryViewModel)DataContext;                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.Replace(" ","").Replace("/", ""));                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<string, int> rowIndex = new Dictionary<string, int>();                int colCount = 0;                int rowCount = 0;                foreach (var item in _viewModel.ProcessData)                {                     if (!rowIndex.ContainsKey(item.dateTime.ToString("G")))                    {                        rowCount++;                        rowIndex[item.dateTime.ToString("G")] = rowCount;                        worksheet.Cells[rowCount, 0] = new Cell(item.dateTime.ToString("G"));                    }                    if (!colIndex.ContainsKey(item.dbName))                    {                        colCount++;                        colIndex[item.dbName] = colCount;                        worksheet.Cells[0, colCount] = new Cell(item.dbName);                    }                    worksheet.Cells[rowIndex[item.dateTime.ToString("G")], colIndex[item.dbName]] = new Cell(item.value);                }                workbook.Worksheets.Add(worksheet);                workbook.Save(dlg.FileName);            }            catch (Exception ex)            {                                LOG.WriteExeption(ex.Message, ex);            }        }    }}
 |