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(QueryLots); BatchDetailCommand = new BaseCommand(BatchDetail); ProcessDetailCommand = new BaseCommand(ProcessDetail); ProcessExportCommand = new BaseCommand(ProcessExport); ExportProcessTableCommand = new BaseCommand(ExportProcessTable); ProcessJobInfoCommand = new BaseCommand(ProcessJobInfo); // DisplayGraphCommand = new BaseCommand(DisplayGraph); InitTime(); } public ObservableCollection ProcessHistoryLots { get; set; } = new ObservableCollection(); 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 layoutData = ProcessHistoryLots[ProcessHistoryLotSelectIndex].LayoutData.Split(',').ToList(); List waferData = ProcessHistoryLots[ProcessHistoryLotSelectIndex].WaferData.Split(',').ToList(); var windowManager = IoC.Get(); BatchDetailViewModel batchDetailViewModel = new BatchDetailViewModel(startTime, endTime, batchID, layoutData, layoutData.Count, waferData); (windowManager as WindowManager)?.ShowDialogWithTitle(batchDetailViewModel, null, "Batch Detail"); } else { var windowManager = IoC.Get(); BatchDetailViewModel batchDetailViewModel = new BatchDetailViewModel(); (windowManager as WindowManager)?.ShowDialogWithTitle(batchDetailViewModel, null, "Batch Detail"); } } public void SelectDate(string SelectType) { var windowManager = Caliburn.Micro.Core.IoC.Get(); 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(); var param = ProcessHistoryLots.Where(x => x.IsChecked).ToList(); object processDetailViewModel = new ProcessDetailViewModel(param); (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(processDetailViewModel, null, "Process Detail"); //} } void ProcessJobInfo(object o) { var windowManager = IoC.Get(); 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 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(); var param = ProcessHistoryLots.Where(x => x.IsChecked).ToList(); object processExportViewModel = new ProcessExportAllViewModel(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)); } } } }