123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using Aitex.Core.RT.Log;
- using Aitex.Core.UI.ControlDataContext;
- using Aitex.Core.Utilities;
- using Aitex.Sorter.Common;
- using VirgoUI.Client.Models.Sys;
- using MECF.Framework.Common.DataCenter;
- using OpenSEMI.ClientBase;
- using ExcelLibrary.SpreadSheet;
- using MECF.Framework.Common.CommonData;
- namespace VirgoUI.Client.Models.DataLog.ProcessHistory
- {
- public class ProcessHistoryViewModel : BaseModel
- {
- public DateTime BeginDate { get; set; }
- public DateTime UIBeginTime { get; set; }
- public DateTime EndDate { get; set; }
- public DateTime UIEndTime { get; set; }
- public bool EnableExportList { get; set; }
- public bool EnableExportData { get; set; }
- public ObservableCollection<HistoryProcessData> ProcessList { get; set; }
- private HistoryProcessData selectedProcessData;
- public HistoryProcessData SelectedProcessData
- {
- get { return this.selectedProcessData; }
- set
- {
- this.selectedProcessData = value;
- this.UpdateData(this.selectedProcessData);
- if (this.selectedProcessData != null)
- {
- this.EnableExportData = true;
- this.NotifyOfPropertyChange("EnableExportData");
- }
- else
- {
- this.EnableExportData = false;
- this.NotifyOfPropertyChange("EnableExportData");
- }
- }
- }
- public ProcessDataChartDataItem ProcessChartData { get; set; }
- public List<HistoryDataItem> ProcessData { get; set; }
- public ProcessHistoryViewModel()
- {
- DisplayName = "Process History";
- ProcessChartData = new ProcessDataChartDataItem(60000);
- this.EnableExportData = false;
- this.EnableExportList = false;
- this.NotifyOfPropertyChange("EnableExportData");
- this.NotifyOfPropertyChange("EnableExportList");
- }
- protected override void OnInitialize()
- {
- base.OnInitialize();
- var now = DateTime.Now;
- EndDate = now;
- BeginDate = now;
- UIBeginTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0);
- UIEndTime = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999);
- }
- protected override void OnActivate()
- {
- base.OnActivate();
- }
- public void UpdateRecipeList(DateTime from, DateTime to)
- {
- //ObservableCollection<string> lst = new ObservableCollection<string>();
- //List<string> result = Triton160UiSystem.Instance.WCF.Query.GetHistoryRecipeList(from, to);
- //if (result != null)
- // result.ForEach(lst.Add);
- //RecipeList = lst;
- //InvokePropertyChanged("RecipeList");
- }
-
- public void UpdateProcessList(DateTime begin, DateTime end)
- {
- try
- {
- string sql = string.Format(
- "SELECT * FROM \"process_data\" where \"process_begin_time\" >= '{0}' and \"process_begin_time\" <= '{1}' order by \"process_begin_time\" ASC;",
- begin.ToString("yyyy/MM/dd HH:mm:ss.fff"), end.ToString("yyyy/MM/dd HH:mm:ss.fff"));
- List<HistoryProcessData> result = QueryDataClient.Instance.Service.QueryDBProcess(sql);
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- this.ProcessList = new ObservableCollection<HistoryProcessData>();
- if (result != null)
- {
- foreach (HistoryProcessData ev in result)
- {
- this.ProcessList.Add(ev);
- }
- }
- if (this.ProcessList.Count>0)
- {
- this.EnableExportList = true;
- this.NotifyOfPropertyChange("EnableExportList");
- }
- else
- {
- this.EnableExportList = false;
- this.NotifyOfPropertyChange("EnableExportList");
- }
- NotifyOfPropertyChange("ProcessList");
- }));
- }
- catch (Exception e)
- {
- LOG.Write(e);
- }
- }
- public void UpdateData(HistoryProcessData dataLog)
- {
- if (dataLog == null)
- {
- ProcessChartData.ClearData();
- return;
- }
- List<string> keys = new List<string>();
- //Application.Current.Dispatcher.Invoke(new Action(() =>
- //{
- // Dictionary<string, Tuple<string, string, bool>> dicItems = GetDataElements(CultureSupported.English);
- // keys = dicItems.Keys.ToList();
- // ProcessChartData.UpdateColumns(dicItems);
- //}));
- ProcessData = QueryDataClient.Instance.Service.GetHistoryData(keys, dataLog.Guid , "Data");
- Application.Current.Dispatcher.Invoke(new Action(() =>
- {
- ProcessChartData.SetInfo(dataLog.RecipeName);
- ProcessChartData.UpdateData(ProcessData);
- }));
- }
- public void ExportLotList()
- {
- ObservableCollection<HistoryProcessData> DataLogList = this.ProcessList;
- 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("RecipeName");
- worksheet.Cells[0, col++] = new Cell("ProcessBeginTime");
- worksheet.Cells[0, col++] = new Cell("ProcessEndTime");
- worksheet.Cells[0, col++] = new Cell("RecipeResult");
- for (int i = 0; i < DataLogList.Count; i++)
- {
- int colCount = 0;
- worksheet.Cells[i + 1, colCount++] = new Cell(DataLogList[i].RecipeName);
- worksheet.Cells[i + 1, colCount++] = new Cell(DataLogList[i].StartTime);
- worksheet.Cells[i + 1, colCount++] = new Cell(DataLogList[i].EndTime);
- worksheet.Cells[i + 1, colCount++] = new Cell(DataLogList[i].Result);
- }
- workbook.Worksheets.Add(worksheet);
- workbook.Save(dlg.FileName);
- }
- public void ExportLotDetails()
- {
- if (this.SelectedProcessData == null)
- return;
- HistoryProcessData log = this.SelectedProcessData;
- if (log == null)
- {
- MessageBox.Show("No Data Selected, Please Select Lot From The Lot List");
- 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.RecipeName);
- 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.RecipeName);
- 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 this.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);
- }
- public void Query()
- {
- this.UpdateProcessList(BeginTime, EndTime);
- }
- private DateTime BeginTime
- {
- get
- {
- return new DateTime(BeginDate.Year, BeginDate.Month, BeginDate.Day,
- UIBeginTime.Hour, UIBeginTime.Minute, UIBeginTime.Second);
- }
- }
- private DateTime EndTime
- {
- get
- {
- return new DateTime(EndDate.Year, EndDate.Month, EndDate.Day,
- UIEndTime.Hour, UIEndTime.Minute, UIEndTime.Second, 999);
- }
- }
- }
- }
|