using Caliburn.Micro; using Caliburn.Micro.Core; using MECF.Framework.Common.CommonData; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; using FurnaceUI.Models; using FurnaceUI.Views.Recipes; namespace FurnaceUI.Views.DataLog { public class BatchDetailViewModel : FurnaceUIViewModelBase { public List BoatWafers { get; set; } = new List(); public ObservableCollection BatchDetailItems { get; set; } = new ObservableCollection(); private SolidColorBrush _DefaultdBk = new SolidColorBrush(Colors.White); private SolidColorBrush _PBk = new SolidColorBrush(Colors.SkyBlue); private SolidColorBrush _SDBk = new SolidColorBrush(Colors.White); private SolidColorBrush _FDBk = new SolidColorBrush(Colors.Yellow); private SolidColorBrush _M1Bk = new SolidColorBrush(Colors.Pink); private SolidColorBrush _M2Bk = new SolidColorBrush(Colors.Pink); private SolidColorBrush _XDBk = new SolidColorBrush(Colors.White); private SolidColorBrush _TBk = new SolidColorBrush(Colors.DarkGreen); private string _batchId; public string BatchId { get => _batchId; set { _batchId = value; NotifyOfPropertyChange(nameof(BatchId)); } } private int _productionCount; public int ProductionCount { get => _productionCount; set { _productionCount = value; NotifyOfPropertyChange(nameof(ProductionCount)); } } private int _monitorCount; public int MonitorCount { get => _monitorCount; set { _monitorCount = value; NotifyOfPropertyChange(nameof(MonitorCount)); } } private int _dummyCount; public int DummyCount { get => _dummyCount; set { _dummyCount = value; NotifyOfPropertyChange(nameof(DummyCount)); } } private int _extraDummyCount; public int ExtraDummyCount { get => _extraDummyCount; set { _extraDummyCount = value; NotifyOfPropertyChange(nameof(ExtraDummyCount)); } } private int _etcCount; public int EtcCount { get => _etcCount; set { _etcCount = value; NotifyOfPropertyChange(nameof(EtcCount)); } } private int _total; public int Total { get => _total; set { _total = value; NotifyOfPropertyChange(nameof(Total)); } } public DateTime StartTime { get; set; } public DateTime EndTime { get; set; } private int _cassetteSelectIndex; public int CassetteSelectIndex { get => _cassetteSelectIndex; set { _cassetteSelectIndex = value; NotifyOfPropertyChange(nameof(CassetteSelectIndex)); } } public BatchDetailViewModel() { } public BatchDetailViewModel(DateTime startTime, DateTime endTime, string batchId, List layoutData, int iSlotCount, List waferData) { StartTime = startTime; EndTime = endTime; BatchId = batchId; Total = iSlotCount; for (int i = 0; i < iSlotCount; i++) { BoatWaferItem item = new BoatWaferItem() { Slot = i + 1, Description = $"{layoutData[i]}" }; BoatWafers.Add(item); } for (int i = 0; i < iSlotCount; i++) { string waferType = BoatWafers[i].Description.Split('-').ToList()[0]; switch (waferType) { case "P": BoatWafers[i].BkColor = _PBk; break; case "M1": BoatWafers[i].BkColor = _M1Bk; break; case "M2": BoatWafers[i].BkColor = _M2Bk; break; case "SD": BoatWafers[i].BkColor = _SDBk; break; case "FD": BoatWafers[i].BkColor = _FDBk; break; default: BoatWafers[i].BkColor = _DefaultdBk; break; } var description = BoatWafers[i].Description; description = description.Substring(description.IndexOf('-') + 1); BoatWafers[i].Description = description; } BatchDetailParser(waferData); } private void BatchDetailParser(List waferData) { ProductionCount = 0; MonitorCount = 0; DummyCount = 0; ExtraDummyCount = 0; EtcCount = 0; for (int i = 0; i < waferData.Count; i++) { if (string.IsNullOrEmpty(waferData[i])) continue; var temp = waferData[i].Split(':').ToList(); var wafertype = temp[0]; var stockername = temp[1].Split('.')[0]; var lotid = temp.Count > 2 ? temp[2] : ""; switch (wafertype) { case "P": ProductionCount++; break; case "M": MonitorCount++; break; case "SD": DummyCount++; break; case "ED": ExtraDummyCount++; break; } BatchDetailItem detail = BatchDetailItems.Where(x => x.StockerName == stockername).FirstOrDefault(); if (detail == null) { BatchDetailItem item = new BatchDetailItem(); item.WaferType = wafertype; item.StockerName = stockername; item.LotId = lotid; item.WaferCount = 1; BatchDetailItems.Add(item); } else { BatchDetailItems.Where(x => x.StockerName == stockername).FirstOrDefault().WaferCount++; } } EtcCount = Total - ProductionCount - MonitorCount - DummyCount - ExtraDummyCount; } public void CassetteDetail() { if (CassetteSelectIndex != -1 && BatchDetailItems.Count > 0) { var windowManager = IoC.Get(); CassetteDetailViewModel cassetteDetailViewModel = new CassetteDetailViewModel(StartTime, EndTime, BatchDetailItems[CassetteSelectIndex].LotId); (windowManager as WindowManager)?.ShowDialogWithTitle(cassetteDetailViewModel, null, "Cassette Detail"); } } public void CloseCmd() { ((Window)GetView()).Close(); } } public class BatchDetailItem : NotifiableItem { private string _waferType; public string WaferType { get => _waferType; set { _waferType = value; InvokePropertyChanged(nameof(WaferType)); } } private string _stockerName; public string StockerName { get => _stockerName; set { _stockerName = value; InvokePropertyChanged(nameof(StockerName)); } } private string _lotId; public string LotId { get => _lotId; set { _lotId = value; InvokePropertyChanged(nameof(LotId)); } } private int _waferCount; public int WaferCount { get => _waferCount; set { _waferCount = value; InvokePropertyChanged(nameof(WaferCount)); } } } }