using Aitex.Core.UI.Control; using Aitex.Core.Util; using Caliburn.Micro.Core; using DocumentFormat.OpenXml.Drawing; using DocumentFormat.OpenXml.Drawing.Diagrams; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.Jobs; using MECF.Framework.Common.Utilities; using MECF.Framework.UI.Client.CenterViews.Editors.Recipe; using MECF.Framework.UI.Client.ClientBase; using OpenSEMI.ClientBase.Command; using SciChart.Core.Extensions; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics.Eventing.Reader; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace MECF.Framework.UI.Client.CenterViews.DataLogs.ProcessHistory { public class ProcessDetailV2ViewModel : ModuleUiViewModelBase { #region [Subscription("Rt.Status")] public string RtStatus { get; set; } [Subscription("PM1.Status")] public string PM1Status { get; set; } private int _upperSDNum = 0; public int UpperSDNum { get => _upperSDNum; set { _upperSDNum = value; NotifyOfPropertyChange(nameof(UpperSDNum)); } } private int _productNum = 0; public int ProductNum { get => _productNum; set { _productNum = value; NotifyOfPropertyChange(nameof(ProductNum)); } } private int _monitorNum1 = 0; public int MonitorNum1 { get => _monitorNum1; set { _monitorNum1 = value; NotifyOfPropertyChange(nameof(MonitorNum1)); } } private int _monitorNum2 = 0; public int MonitorNum2 { get => _monitorNum2; set { _monitorNum2 = value; NotifyOfPropertyChange(nameof(MonitorNum2)); } } private int _lowerSDNum = 0; public int LowerSDNum { get => _lowerSDNum; set { _lowerSDNum = value; NotifyOfPropertyChange(nameof(LowerSDNum)); } } private int _selectItemIndex = 0; public int SelectItemIndex { get => _selectItemIndex; set { _selectItemIndex = value; NotifyOfPropertyChange(nameof(SelectItemIndex)); } } private int _tableCount = 0; public int TableCount { get => _tableCount; set { _tableCount = value; NotifyOfPropertyChange(nameof(TableCount)); } } private List _boatMapWafers = new List(); public List BoatMapWafers { get => _boatMapWafers; set { _boatMapWafers = value; NotifyOfPropertyChange(nameof(BoatMapWafers)); } } private ProcessDetailV2ViewData _viewData; public ProcessDetailV2ViewData ViewData { get => _viewData; set { _viewData = value; NotifyOfPropertyChange(nameof(ViewData)); } } private RecipeDataBase _layoutRecipe = new RecipeDataBase(); public RecipeDataBase LayoutRecipe { get { return _layoutRecipe; } set { _layoutRecipe = value; this.NotifyOfPropertyChange(nameof(LayoutRecipe)); } } private RecipeDataBase _processRecipe = new RecipeDataBase(); public RecipeDataBase ProcessRecipe { get { return _processRecipe; } set { _processRecipe = value; this.NotifyOfPropertyChange(nameof(ProcessRecipe)); } } private ProcessHistoryLot _pJInfo = new ProcessHistoryLot(); public ProcessHistoryLot PJInfo { get { return _pJInfo; } set { _pJInfo = value; this.NotifyOfPropertyChange(nameof(PJInfo)); } } private readonly RecipeProvider _recipeProvider = new RecipeProvider(); private RecipeFormatBuilder _columnBuilder = new RecipeFormatBuilder(); private string _processPrefix = "Furnace\\Process"; private string _layoutPrefix = "Furnace\\Layout"; public ICommand AlarmInformationCommand { get; set; } public ICommand EventLoggingCommand { get; set; } public ICommand PMCTraceLoggingCommand { get; set; } public ICommand VPCommand { get; set; } #endregion public ProcessDetailV2ViewModel() { AlarmInformationCommand = new BaseCommand(AlarmInformationMethod); EventLoggingCommand = new BaseCommand(EventLoggingMethod); PMCTraceLoggingCommand = new BaseCommand(PMCTraceLoggingMethod); VPCommand = new BaseCommand(VPMethod); } private void AlarmInformationMethod(object e) { // } private void EventLoggingMethod(object e) { } private void PMCTraceLoggingMethod(object e) { } private void VPMethod(object e) { } protected override void OnViewLoaded(object _view) { base.OnViewLoaded(_view); ViewData = new ProcessDetailV2ViewData(); LoadLayoutInfo(PJInfo.LayoutName); LoadProcessData(); if (string.IsNullOrEmpty(PJInfo.LayoutName)) { ViewData.ProcessStartTime = ViewData.PJobStartTime; ViewData.ProcessEndTime = ViewData.PJobEndTime; } } private void LoadProcessData() { var pjStartNoEnd = PJInfo.StartTime != DateTime.MinValue && PJInfo.EndTime == DateTime.MinValue; var pjStartAndEnd = PJInfo.StartTime != DateTime.MinValue && PJInfo.EndTime != DateTime.MinValue; var hasLayoutRecipe = !string.IsNullOrEmpty(PJInfo.LayoutName); string sql = $"SELECT * FROM process_data where (pj_id ='{PJInfo.PjId}')"; if (string.IsNullOrEmpty(PJInfo.PjId)) { sql = $"SELECT * FROM process_data where (recipe_name ='{PJInfo.RecipeName}' and process_begin_time >= '{PJInfo.StartTime:yyyy/MM/dd HH:mm:ss.fff}' and process_end_time <= '{PJInfo.EndTime:yyyy/MM/dd HH:mm:ss.fff}') order by process_begin_time DESC;"; } DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql); string processDataStatus = ""; if (dbData != null && dbData.Rows.Count > 0) { ViewData.ProcessStartTime = dbData.Rows[0]["process_begin_time"].ToString(); ViewData.ProcessEndTime = dbData.Rows[0]["process_end_time"].ToString(); processDataStatus = dbData.Rows[0]["process_status"].ToString(); } if (pjStartNoEnd) { ViewData.IsSettingUp = true; ViewData.IsProcessComplete = false; ViewData.IsProcessing = false; } if (!string.IsNullOrEmpty(ViewData.ProcessStartTime) && string.IsNullOrEmpty(ViewData.ProcessEndTime)) { ViewData.IsSettingUp = false; ViewData.IsProcessComplete = false; ViewData.IsProcessing = true; } if (pjStartAndEnd) { ViewData.IsSettingUp = false; ViewData.IsProcessComplete = true; ViewData.IsProcessing = false; } if (PJInfo.Form == ProcessEndResultEnum.Abort.ToDescription()) { ViewData.ProcessEndResult = ProcessEndResultEnum.Abort.ToDescription(); return; } if (PJInfo.Form == ProcessEndResultEnum.Normal.ToDescription() && !string.IsNullOrEmpty(processDataStatus) && processDataStatus == ProcessEndResultEnum.Succeed.ToDescription()) { ViewData.ProcessEndResult = ProcessEndResultEnum.NORMALEND.ToDescription(); return; } if (pjStartNoEnd || (PJInfo.Form == ProcessEndResultEnum.Normal.ToDescription() && string.IsNullOrEmpty(processDataStatus))) { ViewData.ProcessEndResult = ProcessEndResultEnum.NONE.ToDescription(); return; } } protected override void InvokeAfterUpdateProperty(Dictionary data) { // RefreshCassetteDataTask(); } private void RefreshCassetteDataTask() { var wafers = ModuleManager.ModuleInfos[ModuleName.PM1.ToString()].WaferManager.Wafers; } private void LoadLayoutInfo(string layoutName) { ViewData.PJobStartTime = PJInfo.StartTime.ToString("yyyy/MM/dd HH:mm:ss.fff"); ViewData.PJobEndTime = PJInfo.EndTime.ToString("yyyy/MM/dd HH:mm:ss.fff"); if (string.IsNullOrEmpty(layoutName)) { return; } _columnBuilder.Build("Layout"); LayoutRecipe.PrefixPath = _layoutPrefix; var recipeContent = _recipeProvider.LoadRecipe(LayoutRecipe.PrefixPath, layoutName); //if (string.IsNullOrEmpty(recipeContent)) //{ // System.Windows.MessageBox.Show($"{layoutName} is empty, please confirm the file is valid."); // return; //} // LayoutRecipe.InitData(LayoutRecipe.PrefixPath, layoutName, recipeContent, _columnBuilder.Configs, "PM1"); var waferNumberAll = (int)QueryDataClient.Instance.Service.GetConfig("Boat.SlotCount"); var cassetteSlotCount = (int)QueryDataClient.Instance.Service.GetConfig("System.CassetteSlotCount"); List listWafers = QueryDataClient.Instance.Service.GetLayoutRecipeContent(recipeContent, waferNumberAll.ToString(), cassetteSlotCount.ToString()); BoatMapWafers = listWafers; if (null != BoatMapWafers && BoatMapWafers.Count > 0) { var data = ComputSD(BoatMapWafers); ComputWafer(listWafers); } } private void ComputWafer(List listWafers) { UpperSDNum = listWafers.Where(x => x == "SD").Count(); LowerSDNum = listWafers.Where(x => x == "FD").Count(); ProductNum = listWafers.Where(x => x.StartsWith("P")).Count(); MonitorNum1 = listWafers.Where(x => x == "M1").Count(); MonitorNum2 = listWafers.Where(x => x == "M2").Count(); } private Tuple ComputSD(List dataSource) { List otherSlot = dataSource.Where(a => a != "SD" && !string.IsNullOrEmpty(a)).ToList().Distinct().ToList(); if (dataSource == null || dataSource.Count == 0) { return new Tuple(0, 0); } List minList = new List(); for (int i = 0; i < dataSource.Count; i++) { var item = dataSource[i]; if (otherSlot.Contains(item) && !string.IsNullOrEmpty(item)) { break; } if (string.IsNullOrEmpty(item)) { continue; } minList.Add(i); } dataSource.Reverse(); List maxList = new List(); for (int i = 0; i < dataSource.Count; i++) { var item = dataSource[i]; if (otherSlot.Contains(item) && !string.IsNullOrEmpty(item)) { break; } if (string.IsNullOrEmpty(item)) { continue; } maxList.Add(i); } return new Tuple(minList.Count(), maxList.Count()); } public enum ProcessEndResultEnum { [Description("NORMAL END")] NORMALEND, [Description("ABNORMAL END")] ABNORMALEND, [Description("NONE")] NONE, [Description("Recipe Abort")] Abort, [Description("Normal")] Normal, [Description("Succeed")] Succeed, } public class ProcessDetailV2ViewData : PropertyChangedBase { private string _processEndResult; public string ProcessEndResult { get => _processEndResult; set { _processEndResult = value; NotifyOfPropertyChange(nameof(ProcessEndResult)); } } private string _pJobStartTime = ""; public string PJobStartTime { get => _pJobStartTime; set { _pJobStartTime = value; NotifyOfPropertyChange(nameof(PJobStartTime)); } } public string PJobEndTime { get => _pJobEndTime; set { _pJobEndTime = value; NotifyOfPropertyChange(nameof(PJobEndTime)); } } private string _pJobEndTime = ""; public string ExecREcipeThinckess { get => _execREcipeThinckess; set { _execREcipeThinckess = value; NotifyOfPropertyChange(nameof(ExecREcipeThinckess)); } } private string _execREcipeThinckess = ""; public string ProcessStartTime { get => _processStartTime; set { _processStartTime = value; NotifyOfPropertyChange(nameof(ProcessStartTime)); } } private string _processStartTime = ""; public string ProcessEndTime { get => _processEndTime; set { _processEndTime = value; NotifyOfPropertyChange(nameof(ProcessEndTime)); } } private string _processEndTime = ""; public string CJobId { get => _cJobId; set { _cJobId = value; NotifyOfPropertyChange(nameof(CJobId)); } } private string _cJobId = ""; private List _pCarrierIdList = new List(); public List PCarrierIdList { get => _pCarrierIdList; set { _pCarrierIdList = value; NotifyOfPropertyChange(nameof(PCarrierIdList)); } } private bool _isSettingUp = false; public bool IsSettingUp { get => _isSettingUp; set { _isSettingUp = value; NotifyOfPropertyChange(nameof(IsSettingUp)); } } private bool _isProcessing = false; public bool IsProcessing { get => _isProcessing; set { _isProcessing = value; NotifyOfPropertyChange(nameof(IsProcessing)); } } private bool _isProcessComplete = false; public bool IsProcessComplete { get => _isProcessComplete; set { _isProcessComplete = value; NotifyOfPropertyChange(nameof(IsProcessComplete)); } } } } }