123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- using Aitex.Core.RT.Log;
- using Aitex.Sorter.Common;
- using Caliburn.Micro;
- using Caliburn.Micro.Core;
- using MECF.Framework.Common.CommonData;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.Utilities;
- using MECF.Framework.UI.Client.CenterViews.DataLogs.Event;
- using MECF.Framework.UI.Client.ClientBase;
- using OpenSEMI.ClientBase;
- using OpenSEMI.ClientBase.Command;
- using SciChart.Charting.Common.Extensions;
- using SciChart.Core.Extensions;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics.Eventing.Reader;
- using System.Linq;
- using System.Windows.Forms;
- using System.Windows.Input;
- namespace MECF.Framework.UI.Client.CenterViews.DataLogs.ProcessHistory
- {
- public class ProcessHistoryTwoViewModel : UiViewModelBase
- {
- public ProcessHistoryTwoViewModel()
- {
- QueryCommand = new BaseCommand<object>(QueryLots);
- BatchDetailCommand = new BaseCommand<object>(BatchDetail);
- ProcessDetailCommand = new BaseCommand<object>(ProcessDetail);
- ProcessExportCommand = new BaseCommand<object>(ProcessExport);
- ExportProcessTableCommand = new BaseCommand<object>(ExportProcessTable);
- ProcessJobInfoCommand = new BaseCommand<object>(ProcessJobInfo);
- // DisplayGraphCommand = new BaseCommand<object>(DisplayGraph);
- InitTime();
- }
- public ObservableCollection<ProcessHistoryLot> ProcessHistoryLots { get; set; } = new ObservableCollection<ProcessHistoryLot>();
- private int _processHistoryLotSelectIndex;
- public int ProcessHistoryLotSelectIndex
- {
- get => _processHistoryLotSelectIndex;
- set
- {
- _processHistoryLotSelectIndex = value;
- NotifyOfPropertyChange(nameof(ProcessHistoryLotSelectIndex));
- }
- }
- private DateTime _searchBeginTime;
- public DateTime SearchBeginTime
- {
- get { return _searchBeginTime; }
- set
- {
- _searchBeginTime = value;
- NotifyOfPropertyChange("SearchBeginTime");
- }
- }
- private DateTime _searchEndTime;
- public DateTime SearchEndTime
- {
- get { return _searchEndTime; }
- set
- {
- _searchEndTime = value;
- NotifyOfPropertyChange("SearchEndTime");
- }
- }
- private string keyWord;
- public string KeyWord
- {
- get { return keyWord; }
- set
- {
- keyWord = value;
- NotifyOfPropertyChange("KeyWord");
- }
- }
- private ProcessHistoryTwoView view;
- public ICommand QueryCommand { get; set; }
- public ICommand BatchDetailCommand { get; set; }
- public ICommand ProcessDetailCommand { get; set; }
- public ICommand ProcessExportCommand { get; set; }
- public ICommand ExportProcessTableCommand { get; set; }
- public ICommand ProcessJobInfoCommand { get; set; }
- // public ICommand DisplayGraphCommand { get; set; }
- protected override void OnViewLoaded(object _view)
- {
- base.OnViewLoaded(_view);
- this.view = (ProcessHistoryTwoView)_view;
- this.view.wfTimeFrom.Content = this.SearchBeginTime;
- this.view.wfTimeTo.Content = this.SearchEndTime;
- QueryLots(new object());
- if (ProcessHistoryLots != null && ProcessHistoryLots.FirstOrDefault() != null)
- {
- ProcessHistoryLots.FirstOrDefault().IsChecked = true;
- }
- }
- void InitTime()
- {
- SearchBeginTime = DateTime.Now.Date;
- SearchEndTime = DateTime.Now.Date.AddDays(1).Date;
- }
- void QueryLots(object e)
- {
- this.SearchBeginTime = Convert.ToDateTime(this.view.wfTimeFrom.Content);
- this.SearchEndTime = Convert.ToDateTime(this.view.wfTimeTo.Content);
- if (SearchBeginTime > SearchEndTime)
- {
- MessageBox.Show("Time range invalid, start time should be early than end time");
- return;
- }
- ProcessHistoryLots.Clear();
- QueryLot(SearchBeginTime, SearchEndTime, KeyWord);//.OrderByDescending(lot => lot.StartTime).ToArray();
- }
- void BatchDetail(object o)
- {
- if (ProcessHistoryLotSelectIndex != -1 && ProcessHistoryLots.Count > 0)
- {
- DateTime startTime = ProcessHistoryLots[ProcessHistoryLotSelectIndex].StartTime;
- DateTime endTime = ProcessHistoryLots[ProcessHistoryLotSelectIndex].EndTime;
- var batchID = ProcessHistoryLots[ProcessHistoryLotSelectIndex].BatchID;
- List<string> layoutData = ProcessHistoryLots[ProcessHistoryLotSelectIndex].LayoutData.Split(',').ToList();
- List<string> waferData = ProcessHistoryLots[ProcessHistoryLotSelectIndex].WaferData.Split(',').ToList();
- var windowManager = IoC.Get<IWindowManager>();
- BatchDetailViewModel batchDetailViewModel = new BatchDetailViewModel(startTime, endTime, batchID, layoutData, layoutData.Count, waferData);
- (windowManager as WindowManager)?.ShowDialogWithTitle(batchDetailViewModel, null, "Batch Detail");
- }
- else
- {
- var windowManager = IoC.Get<IWindowManager>();
- BatchDetailViewModel batchDetailViewModel = new BatchDetailViewModel();
- (windowManager as WindowManager)?.ShowDialogWithTitle(batchDetailViewModel, null, "Batch Detail");
- }
- }
- public void SelectDate(string SelectType)
- {
- var windowManager = Caliburn.Micro.Core.IoC.Get<Caliburn.Micro.IWindowManager>();
- if (SelectType == "Start")
- {
- this.SearchBeginTime = Convert.ToDateTime(this.view.wfTimeFrom.Content);
- SelectDateViewModel selectdateViewModel = new SelectDateViewModel(SearchBeginTime);
- var result = (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(selectdateViewModel, null, "Start Time");
- if (result == true)
- {
- this.view.wfTimeFrom.Content = selectdateViewModel.SearchDate;
- }
- }
- else
- {
- this.SearchEndTime = Convert.ToDateTime(this.view.wfTimeTo.Content);
- SelectDateViewModel selectdateViewModel = new SelectDateViewModel(SearchEndTime);
- var result = (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(selectdateViewModel, null, "End Time");
- if (result == true)
- {
- this.view.wfTimeTo.Content = selectdateViewModel.SearchDate;
- }
- }
- }
- void ProcessDetail(object o)
- {
- //if (ProcessHistoryLots.Count > 0)
- //{
- var windowManager = IoC.Get<IWindowManager>();
- var param = ProcessHistoryLots.Where(x => x.IsChecked).ToList();
- object processDetailViewModel = new ProcessDetailViewModel<double>(param);
- (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(processDetailViewModel, null, "Process Detail");
- //}
- }
- void ProcessJobInfo(object o)
- {
- var windowManager = IoC.Get<IWindowManager>();
- var param = ProcessHistoryLots.Where(x => x.IsChecked).FirstOrDefault();
- ProcessDetailV2ViewModel processDetailViewModel = new ProcessDetailV2ViewModel();
- processDetailViewModel.PJInfo = param;
- processDetailViewModel.TableCount = ProcessHistoryLots.Count;
- processDetailViewModel.SelectItemIndex = ProcessHistoryLots.IndexOf(param) + 1;
- (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(processDetailViewModel, null, "ProcessJob Info");
- }
- void ExportProcessTable(object o)
- {
- try
- {
- if (ProcessHistoryLots == null || ProcessHistoryLots.Count == 0)
- {
- MessageBox.Show($"Table is null");
- }
- Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
- dlg.DefaultExt = ".xlsx"; // Default file extension
- dlg.FileName = $"Process_{SearchBeginTime.ToString("yyyy_MM_dd_HH_mm_ss")}~{SearchEndTime.ToString("yyyy_MM_dd_HH_mm_ss")}";
- dlg.Filter = "Excel数据表格文件(*.xlsx)|*.xlsx"; // Filter files by extension
- Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
- if (result == true) // Process open file dialog box results
- {
- System.Data.DataSet ds = new System.Data.DataSet();
- SaveStepsToTable(ds);
- if (!ExcelHelper.ExportToExcel(dlg.FileName, ds, out string reason, true, false))
- {
- MessageBox.Show($"Export failed, {reason}");
- return;
- }
- MessageBox.Show($"Export succeed, file save as {dlg.FileName}");
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show("导出 Process Table发生错误", "导出失败");
- }
- }
- private void SaveStepsToTable(System.Data.DataSet ds)
- {
- ds.Tables.Add(new System.Data.DataTable("Process"));
- ds.Tables[0].Columns.Add("StartTime");
- ds.Tables[0].Columns.Add("EndTime");
- ds.Tables[0].Columns.Add("BatchId");
- ds.Tables[0].Columns.Add("JobName");
- ds.Tables[0].Columns.Add("RecipeName");
- ds.Tables[0].Columns.Add("LayoutName");
- ds.Tables[0].Columns.Add("Form");
- ds.Tables[0].Columns.Add("Wafer");
- foreach (var item in ProcessHistoryLots)
- {
- var row = ds.Tables[0].NewRow();
- row["BatchId"] = item.BatchID + " ";
- row["JobName"] = item.JobName;
- row["RecipeName"] = item.RecipeName;
- row["Form"] = item.Form;
- row["StartTime"] = item.StartTime;
- row["EndTime"] = item.EndTime;
- row["Wafer"] = item.WaferCount;
- row["LayoutName"] = item.LayoutName;
- ds.Tables[0].Rows.Add(row);
- }
- }
- public void SelectChangedHandle(object obj)
- {
- if (obj != null && obj is ProcessHistoryLot)
- {
- var item = obj as ProcessHistoryLot;
- item.IsChecked = true;
- }
- }
- void ProcessExport(object o)
- {
- var windowManager = IoC.Get<IWindowManager>();
- var param = ProcessHistoryLots.Where(x => x.IsChecked).ToList();
- object processExportViewModel = new ProcessExportAllViewModel<double>(param);
- (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(processExportViewModel, null, "Process Export");
- }
- //void DisplayGraph(object o)
- //{
- // ClientApp.Instance.SwitchPage("DataLog", "DataHistory", null);
- //}
- public void QueryLot(DateTime from, DateTime to, string key)
- {
- string sql = $"SELECT * FROM \"pj_data\" where \"start_time\" >= '{from:yyyy/MM/dd HH:mm:ss.fff}' and \"start_time\" <= '{to:yyyy/MM/dd HH:mm:ss.fff}' order by \"start_time\" DESC;";
- if (!string.IsNullOrWhiteSpace(key)) sql += string.Format(" and lower(\"batch_id\")='{0}' ", key.ToLower());
- DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
- if (dbData != null && dbData.Rows.Count > 0)
- {
- for (int i = 0; i < dbData.Rows.Count; i++)
- {
- ProcessHistoryLot item = new ProcessHistoryLot();
- item.PjId = dbData.Rows[i]["guid"].ToString();
- item.BatchID = dbData.Rows[i]["batch_id"].ToString();
- item.JobName = dbData.Rows[i]["job_name"].ToString();
- item.RecipeName = dbData.Rows[i]["recipe_name"].ToString();
- item.LayoutName = dbData.Rows[i]["layout_name"].ToString();
- item.LayoutData = dbData.Rows[i]["layout_data"].ToString();
- item.WaferData = dbData.Rows[i]["wafer_data"].ToString();
- item.Form = dbData.Rows[i]["form"].ToString();
- if (!dbData.Rows[i]["total_wafer_count"].Equals(DBNull.Value))
- {
- item.WaferCount = (int)dbData.Rows[i]["total_wafer_count"];
- }
- if (!dbData.Rows[i]["start_time"].Equals(DBNull.Value))
- {
- item.StartTime = (DateTime)dbData.Rows[i]["start_time"];
- }
- if (!dbData.Rows[i]["end_time"].Equals(DBNull.Value))
- {
- item.EndTime = (DateTime)dbData.Rows[i]["end_time"];
- }
- ProcessHistoryLots.Add(item);
- }
- }
- }
- }
- public class ProcessHistoryLot : NotifiableItem
- {
- private bool _IsChecked;
- public bool IsChecked
- {
- get => _IsChecked;
- set
- {
- _IsChecked = value;
- InvokePropertyChanged(nameof(IsChecked));
- }
- }
- private string _pjId;
- public string PjId
- {
- get => _pjId;
- set
- {
- _pjId = value;
- InvokePropertyChanged(nameof(PjId));
- }
- }
- private string _batchID;
- public string BatchID
- {
- get => _batchID;
- set
- {
- _batchID = value;
- InvokePropertyChanged(nameof(BatchID));
- }
- }
- private string _jobName;
- public string JobName
- {
- get => _jobName;
- set
- {
- _jobName = value;
- InvokePropertyChanged(nameof(JobName));
- }
- }
- private string _recipeName;
- public string RecipeName
- {
- get => _recipeName;
- set
- {
- _recipeName = value;
- InvokePropertyChanged(nameof(RecipeName));
- }
- }
- private string _layoutName;
- public string LayoutName
- {
- get => _layoutName;
- set
- {
- _layoutName = value;
- InvokePropertyChanged(nameof(LayoutName));
- }
- }
- private string _layoutData;
- public string LayoutData
- {
- get => _layoutData;
- set
- {
- _layoutData = value;
- InvokePropertyChanged(nameof(LayoutData));
- }
- }
- private string _waferData;
- public string WaferData
- {
- get => _waferData;
- set
- {
- _waferData = value;
- InvokePropertyChanged(nameof(WaferData));
- }
- }
- private string _form;
- public string Form
- {
- get => _form;
- set
- {
- _form = value;
- InvokePropertyChanged(nameof(Form));
- }
- }
- private DateTime _startTime;
- public DateTime StartTime
- {
- get => _startTime;
- set
- {
- _startTime = value;
- InvokePropertyChanged(nameof(StartTime));
- }
- }
- private DateTime _endTime;
- public DateTime EndTime
- {
- get => _endTime;
- set
- {
- _endTime = value;
- InvokePropertyChanged(nameof(EndTime));
- }
- }
- private int _waferCount;
- public int WaferCount
- {
- get => _waferCount;
- set
- {
- _waferCount = value;
- InvokePropertyChanged(nameof(WaferCount));
- }
- }
- }
- }
|