public List <MQCItemSummary> GetMQCItemSummaries(PeriodProduction period, string site, string process) { DateTime from = new DateTime(); DateTime to = new DateTime(); DateTimeControl.ReturnDateTimePeriodProduction(period, ref from, ref to); string date = from.ToString("yyyy-MM-dd"); string time = from.ToString("HH:mm:ss"); List <MQCItemSummary> qCItemSummaries = new List <MQCItemSummary>(); try { LoadDataMQC dataMQC = new LoadDataMQC(); List <MQCDataItems> mQCDataItems = dataMQC.listMQCDataItemsbySite(from, to, site, process); //Nhom theo san pham var ListMQCbyProduct = mQCDataItems .GroupBy(u => u.lot) .Select(grp => grp.ToList()) .ToList(); foreach (var qCDataItems in ListMQCbyProduct) { MQCItemSummary itemSummary = new MQCItemSummary(); itemSummary.product = qCDataItems[0].model; itemSummary.defectItems = new List <DefectItem>(); var ListItemsData = qCDataItems .GroupBy(u => u.item) .Select(grp => grp.ToList()) .ToList(); var ListItemsDate = qCDataItems .GroupBy(u => u.inspectdate) .ToList(); foreach (var itemDate in ListItemsDate) { var ListItemsTime = qCDataItems .GroupBy(u => u.inspecttime) .ToList(); if (ListItemsDate.Count() == 1) { itemSummary.Time_from = "[" + ListItemsDate[0].Key.ToString("dd-MM-yy") + "] " + ListItemsTime.Min(d => d.Key).ToString(); itemSummary.Time_To = "[" + ListItemsDate[0].Key.ToString("dd-MM-yy") + "] " + ListItemsTime.Max(d => d.Key).ToString(); } else if (ListItemsDate.Count() == 2) { itemSummary.Time_from = "[" + ListItemsDate[0].Key.ToString("dd-MM-yy") + "] " + ListItemsTime.Min(d => d.Key).ToString(); itemSummary.Time_To = "[" + ListItemsDate[1].Key.ToString("dd-MM-yy") + "] " + ListItemsTime.Max(d => d.Key).ToString(); } } //Khi thay doi ngay can phai chinh lai thoi gian foreach (var itemData in ListItemsData) { DefectItem item = new DefectItem(); item.DefectCode = itemData[0].item; itemSummary.Lot = itemData[0].lot; item.Quantity = itemData.Select(d => d.data).Sum(); if (itemData[0].remark == "OP") { itemSummary.OutputQty += item.Quantity; } else if (itemData[0].remark == "NG") { LoadDefectMapping defectMapping = new LoadDefectMapping(); NGItemsMapping nGItemsMapping = defectMapping.GetNGMapping(site, process, item.DefectCode); item.DefectSFT = nGItemsMapping.NGCode_SFT; item.DefectSFTName = nGItemsMapping.NGCodeName_SFT; itemSummary.defectItems.Add(item); itemSummary.NGQty += item.Quantity; } } itemSummary.QuantityTotal = itemSummary.OutputQty + itemSummary.NGQty; itemSummary.DefectRate = (itemSummary.QuantityTotal != 0) ? (itemSummary.NGQty / itemSummary.QuantityTotal) : 0; qCItemSummaries.Add(itemSummary); } } catch (Exception ex) { Log.Logfile.Output(Log.StatusLog.Error, "GetMQCItemSummaries(DateTime from, DateTime to, string site, string process)", ex.Message); } return(qCItemSummaries); }
public List <MQCItemSummary> GetMQCItemSummaries(PeriodProduction period, string site, string process) { DateTime from = new DateTime(); DateTime to = new DateTime(); DateTimeControl.ReturnDateTimePeriodProduction(period, ref from, ref to); List <MQCItemSummary> qCItemSummaries = new List <MQCItemSummary>(); try { LoadDataMQC dataMQC = new LoadDataMQC(); List <MQCDataItems> mQCDataItems = dataMQC.listMQCDataItemsbySite(from, to, site, process); //Nhom theo san pham var ListMQCbyProduct = mQCDataItems .OrderBy(d => d.line) .GroupBy(u => u.lot) .Select(grp => grp.ToList()) .ToList(); foreach (var qCDataItems in ListMQCbyProduct) { MQCItemSummary itemSummary = new MQCItemSummary(); itemSummary.product = qCDataItems[0].model; itemSummary.defectItems = new List <DefectItem>(); var ListItemsData = qCDataItems .GroupBy(u => u.item) .Select(grp => grp.ToList()) .ToList(); itemSummary.Time_from = dataMQC.GetMinTimeProductionOfProduct(itemSummary.product, from, to).Substring(0, 16); itemSummary.Time_To = dataMQC.GetMaxTimeProductionOfProduct(itemSummary.product, from, to).Substring(0, 16); //Khi thay doi ngay can phai chinh lai thoi gian foreach (var itemData in ListItemsData) { itemSummary.product = itemData[0].model; itemSummary.Line = itemData[0].line; itemSummary.Lot = itemData[0].lot; if (itemData[0].remark == "OP") { itemSummary.OutputQty = itemData.Select(d => d.data).Sum(); } else if (itemData[0].remark == "NG") { DefectItem item = new DefectItem(); item.DefectCode = itemData[0].item; item.Quantity = itemData.Select(d => d.data).Sum(); LoadDefectMapping defectMapping = new LoadDefectMapping(); NGItemsMapping nGItemsMapping = defectMapping.GetNGMapping(site, process, item.DefectCode); item.DefectSFT = nGItemsMapping.NGCode_SFT; item.DefectSFTName = nGItemsMapping.NGCodeName_SFT; itemSummary.defectItems.Add(item); itemSummary.NGQty += item.Quantity; } else if (itemData[0].remark == "RW") { DefectItem item = new DefectItem(); item.DefectCode = itemData[0].item; item.Quantity = itemData.Select(d => d.data).Sum(); itemSummary.ReworkQty += item.Quantity; } } itemSummary.QuantityTotal = itemSummary.OutputQty + itemSummary.NGQty /*+ itemSummary.ReworkQty*/; itemSummary.DefectRate = (itemSummary.QuantityTotal != 0) ? (itemSummary.NGQty / itemSummary.QuantityTotal) : 0; itemSummary.ReworkRate = (itemSummary.QuantityTotal != 0) ? (itemSummary.ReworkQty / itemSummary.QuantityTotal) : 0; qCItemSummaries.Add(itemSummary); } } catch (Exception ex) { SystemLog.Output(SystemLog.MSG_TYPE.Err, "GetMQCItemSummaries(DateTime from, DateTime to, string site, string process)", ex.Message); } return(qCItemSummaries); }