using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using SystemX.Net.XAdaptor.PC; using SystemX.Net.Platform.Common.ExtensionMethods; using static SystemX.Net.XAdaptor.PC.O2Sensor.NgCode.DBSchemaMap; using static SystemX.Net.Platform.Common.Util.LogMessage; namespace SystemX.Net.XAdaptor.PC.O2Sensor.NgCode { public class NGHistDBFinder { string SET_NG_HIST_TABLE_NAME = "HIST_TestNgResult"; //Name - ProcNo - TestID Dictionary> dicHistInfo; XAdaptorPC refPCAdaptor; public NGHistDBFinder(XAdaptorPC refAdaptor) { refPCAdaptor = refAdaptor; dicHistInfo = new Dictionary>(); dicHistInfo.Add(eHistProcTableList.HIST_ProdLoad, new Tuple(180, "PL")); dicHistInfo.Add(eHistProcTableList.HIST_CapDeassy, new Tuple(180, "CDA")); dicHistInfo.Add(eHistProcTableList.HIST_PreHeating, new Tuple(190, "PH")); dicHistInfo.Add(eHistProcTableList.HIST_PreMeas, new Tuple(190, "PM")); dicHistInfo.Add(eHistProcTableList.HIST_Leak, new Tuple(200, "LK")); dicHistInfo.Add(eHistProcTableList.HIST_LaserTrim, new Tuple(210, "LT")); dicHistInfo.Add(eHistProcTableList.HIST_LaserTrimVision, new Tuple(220, "LTV")); dicHistInfo.Add(eHistProcTableList.HIST_IsoRes, new Tuple(220, "IR")); dicHistInfo.Add(eHistProcTableList.HIST_CapAssy, new Tuple(230, "CA")); dicHistInfo.Add(eHistProcTableList.HIST_Function, new Tuple(240, "FT")); dicHistInfo.Add(eHistProcTableList.HIST_OutSealPress, new Tuple(250, "OSP")); dicHistInfo.Add(eHistProcTableList.HIST_PinVision, new Tuple(260, "PV")); dicHistInfo.Add(eHistProcTableList.HIST_PinLVDT, new Tuple(260, "LVDT")); } public Dictionary FindHistory(string strMESID, string strPalletID, bool bFristFailScan = false) { Dictionary dicResult = new Dictionary(); string strQuery = $"SELECT * FROM {SET_NG_HIST_TABLE_NAME.ToString()} WHERE No IN (SELECT No FROM {SET_NG_HIST_TABLE_NAME.ToString()} WHERE " + $"{eHistTableCommonCols.ProdID} = '{strMESID}' AND {eHistTableCommonCols.PalletID} = '{strPalletID}') " + $"ORDER BY {eHistTableCommonCols.ProcNo.ToString()};"; DataSet dsResult = null; try { dsResult = refPCAdaptor.WaitSystemQuery(strQuery); DataRow dr = null; foreach (eHistProcTableList tableName in Enum.GetValues(typeof(eHistProcTableList))) { int iProcNo = dicHistInfo[tableName].Item1; string strTestID = dicHistInfo[tableName].Item2; bool bNgRowFind = false; dr = null; foreach (var item in dsResult.Tables[0].Rows) { dr = item as DataRow; int iIndex = dsResult.Tables[0].Rows.IndexOf(dr); string strGetProcNo = dsResult.Tables[0].Rows[iIndex][eHistTableCommonCols.ProcNo.ToString()].ToString().Trim(); string strGetTestID = dsResult.Tables[0].Rows[iIndex][eHistTableCommonCols.TestID.ToString()].ToString().Trim(); if (strGetProcNo == iProcNo.ToString() && strGetTestID == strTestID) { bNgRowFind = true; break; } } if (bNgRowFind) { dicResult.Add(tableName, dr); //이력 존재시 NG if (bFristFailScan) break; } else { dicResult.Add(tableName, null); //이력 미 존재시 PASS } } } catch (Exception ex) { MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"NgCode - NGHistDBFinder - FindHistory()\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG); } finally { } return dicResult; } public Tuple FindNGHistory(string strMESID, string strPalletID) { Tuple pairResult = null; Dictionary dicResult = FindHistory(strMESID, strPalletID, true); try { foreach (eHistProcTableList procTbl in Enum.GetValues(typeof(eHistProcTableList))) { DataRow dtRow = dicResult[procTbl]; if (dtRow == null) { if (pairResult == null) pairResult = new Tuple(procTbl, null, true); } else { pairResult = new Tuple(procTbl, dtRow, false); break; } } } catch (Exception ex) { MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"NgCode - NGHistDBFinder - FindNGHistory()\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG); } finally { } return pairResult; } public List GetOnloadedPalletIDs(string strMESID) { string strQuery = $"SELECT PalletID FROM {eHistAllTableList.HIST_ProdLoad.ToString()} WHERE {eHistTableCommonCols.ProdID} = '{strMESID}' ORDER BY {eHistTableCommonCols.UpdateDT.ToString()} DESC"; DataSet dtSet = refPCAdaptor.WaitSystemQuery(strQuery); List vstrPalletID = (from dtResult in dtSet.Tables[0].AsEnumerable() let strResult = dtResult[eHistTableCommonCols.PalletID.ToString()].ToString().Trim() select strResult).ToList(); return vstrPalletID; } public List GetNGCodeHistory(string strMESID) { List vstrNGCodes = null; try { string strQuery = $"SELECT TOP 100 NGCode FROM {eHistAllTableList.HIST_ProdUnload.ToString()} WHERE {eHistTableCommonCols.ProdID} = '{strMESID}' ORDER BY {eHistTableCommonCols.UpdateDT.ToString()} DESC"; DataSet dtSet = refPCAdaptor.WaitSystemQuery(strQuery); vstrNGCodes = (from dtResult in dtSet.Tables[0].AsEnumerable() let strResult = dtResult[eHist_ProdUnload.NGCode.ToString()].ToString().Trim() select strResult).ToList(); } catch (Exception ex) { MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"NgCode - NGHistDBFinder - GetNGCodeHistory()\r\n" + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG); } finally { } return vstrNGCodes; } string SearchRecentResultQuery(string strTable, string strMESID) { string strQuery = $"SELECT * FROM {strTable}"; return strQuery; } public string GetCurrentPalletID(string strMESID) { string strColPalletID = "PalletID"; string strProdLoadState = "STAT_ProdLoad"; string strQuery = $"SELECT {strColPalletID} FROM {strProdLoadState} WHERE {eStat_ProdLoad.ProdID} = '{strMESID}'"; DataSet dsResult = refPCAdaptor.WaitSystemQuery(QueryProcessList); List vstrPalletID = (from dtResult in dsResult.Tables[0].AsEnumerable() where dtResult[strColPalletID].ToString().Trim() == strMESID let strResult = dtResult[strColPalletID].ToString().Trim() select strResult).ToList(); if(vstrPalletID.Count <= 0) return string.Empty; return vstrPalletID[0]; } public DataTable GetProcessList() { DataSet dsResult = refPCAdaptor.WaitSystemQuery(QueryProcessList); return dsResult.Tables[0]; } string QueryProcessList = $"SELECT * FROM {DBSchemaMap.ProcessListTableName}"; } }