123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- 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 Aitex.Triton160.Common;
- using Aitex.Triton160.UI.ViewModel;
- using DataAnalysisControl.Core;
- using Aitex.Core.Util;
- using ExcelLibrary.SpreadSheet;
- using Triton160.UI.ViewModel;
- namespace Aitex.Triton160.UI.Views
- {
- /// <summary>
- /// Interaction logic for DataLogView.xaml
- /// </summary>
- public partial class DataLogView : UserControl
- {
- private DataLogViewModel _viewModel;
- private DateTime BeginTime
- {
- get
- {
- var BeginDate = dateBegin.SelectedDate.HasValue ? dateBegin.SelectedDate.Value : DateTime.Now;
- return new DateTime(BeginDate.Year, BeginDate.Month, BeginDate.Day,
- timeBegin.Value.Value.Hour, timeBegin.Value.Value.Minute, timeBegin.Value.Value.Second);
- }
- }
- private DateTime EndTime
- {
- get
- {
- var EndDate = dateEnd.SelectedDate.HasValue ? dateEnd.SelectedDate.Value : DateTime.Now;
- return new DateTime(EndDate.Year, EndDate.Month, EndDate.Day,
- timeEnd.Value.Value.Hour, timeEnd.Value.Value.Minute, timeEnd.Value.Value.Second, 999);
- }
- }
- public DataLogView()
- {
- InitializeComponent();
-
- _viewModel = new DataLogViewModel();
- DataContext = _viewModel;
- var now = DateTime.Now;
- dateBegin.DisplayDate = now - new TimeSpan(1, 0, 0, 0);
- dateEnd.DisplayDate = now;
- dateBegin.SelectedDate = now;
- dateEnd.SelectedDate = now;
- timeBegin.Value = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0);
- timeEnd.Value = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999);
- dataGrid_LotList.CanUserAddRows = false;
-
- _viewModel.UpdateRecipeList(BeginTime, EndTime);
- IsVisibleChanged += DataLogView_IsVisibleChanged;
- }
- void DataLogView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- if (!IsLoaded)
- return;
- if (IsVisible)
- _viewModel.UpdateRecipeList(BeginTime, EndTime);
- }
- private void buttonQuery_Click(object sender, RoutedEventArgs e)
- {
- _viewModel.UpdateDataLogList(BeginTime, EndTime, recipeName.Text,LotTextBox.BarcodeText.Trim());
- List<DataLogItem> DataLogList = _viewModel.DataLogList;
- ButtonExportList.IsEnabled = DataLogList != null && DataLogList.Count > 0;
- }
- private void dateBegin_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!IsLoaded)
- return;
- _viewModel.UpdateRecipeList(BeginTime, EndTime);
- }
- private void timeBegin_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
- {
- if (!IsLoaded)
- return;
- _viewModel.UpdateRecipeList(BeginTime, EndTime);
- }
- private void dateEnd_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!IsLoaded)
- return;
- _viewModel.UpdateRecipeList(BeginTime, EndTime);
- }
- private void timeEnd_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
- {
- if (!IsLoaded)
- return;
- _viewModel.UpdateRecipeList(BeginTime, EndTime);
- }
- private void dataGrid_DataLogList_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- DataLogItem log = (dataGrid_LotList.SelectedItem) as DataLogItem;
- _viewModel.UpdateData(log );
- ButtonExportData.IsEnabled = log != null ;
-
- }
- private void buttonLotListExport_Click(object sender, RoutedEventArgs e)
- {
- List<DataLogItem> DataLogList = _viewModel.DataLogList;
- if (DataLogList == null ||DataLogList.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("LotList{0}", BeginTime.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(BeginTime.ToString("yyyyMMdd"));
- int col = 0;
- worksheet.Cells[0, col++] = new Cell(Aitex.Triton160.UI.Properties.Resources.LotName);
- worksheet.Cells[0, col++] = new Cell(Aitex.Triton160.UI.Properties.Resources.RecipeName);
- worksheet.Cells[0, col++] = new Cell(Aitex.Triton160.UI.Properties.Resources.ProcessBeginTime);
- worksheet.Cells[0, col++] = new Cell(Aitex.Triton160.UI.Properties.Resources.ProcessEndTime);
- worksheet.Cells[0, col++] = new Cell(Aitex.Triton160.UI.Properties.Resources.RecipeResult);
- for (int i=0; i<DataLogList.Count;i++)
- {
- int colCount = 0;
- worksheet.Cells[i+1, colCount++] = new Cell(DataLogList[i].LotName);
- worksheet.Cells[i+1, colCount++] = new Cell(DataLogList[i].RecipeName);
- worksheet.Cells[i+1, colCount++] = new Cell(DataLogList[i].ProcessBeginTime);
- worksheet.Cells[i+1, colCount++] = new Cell(DataLogList[i].ProcessEndTime);
- worksheet.Cells[i+1, colCount++] = new Cell(DataLogList[i].RecipeResult);
- }
- workbook.Worksheets.Add(worksheet);
- workbook.Save(dlg.FileName);
- }
- private void buttonLotDetailsExport_Click(object sender, RoutedEventArgs e)
- {
- DataLogItem log = (dataGrid_LotList.SelectedItem) as DataLogItem;
- if (log == null)
- {
- MessageBox.Show(Aitex.Triton160.UI.Properties.Resources.NoDataSelectedPleaseSelectLotFromTheLotList);
- 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}", log.DataLogName);
- 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.DataLogName);
- 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);
- }
- }
- }
|