[성현모] CPXV2 Init

This commit is contained in:
SHM
2024-06-26 10:30:00 +09:00
parent cdf12248c5
commit 5958993b6a
588 changed files with 698420 additions and 0 deletions

View File

@ -0,0 +1,165 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SystemX.Net.XAdaptor.PC.O2Sensor.NgCode
{
public static class DBSchemaMap
{
public const string ProcessListTableName = "INFO_PROCESS";
public const string TableName_NGCode = "INFO_NGCode";
public const string TableName_DetailData = "HIST_TestResultDatail";
public enum eHistAllTableList
{
HIST_ProdLoad = 0,
HIST_CapDeassy,
HIST_PreHeating,
HIST_PreMeas,
HIST_Leak,
HIST_LaserTrim,
HIST_LaserTrimVision,
HIST_IsoRes,
HIST_CapAssy,
HIST_Function,
HIST_OutSealPress,
HIST_PinVision,
HIST_PinLVDT,
HIST_ProdUnload
}
public enum eHistProcTableList
{
HIST_ProdLoad = 0,
HIST_CapDeassy,
HIST_PreHeating,
HIST_PreMeas,
HIST_Leak,
HIST_LaserTrim,
HIST_LaserTrimVision,
HIST_IsoRes,
HIST_CapAssy,
HIST_Function,
HIST_OutSealPress,
HIST_PinVision,
HIST_PinLVDT
}
public enum eHistTableCommonCols
{
No,
LogAccessKey,
ProcNo,
PalletNumber,
PalletID,
PIndex,
ProdNo,
ProdID,
TestID,
Result,
Status,
UpdateDT
}
public enum eHistTableCols
{
No,
ProcNo,
PalletNumber,
PalletID,
PIndex,
ProdNo,
ProdID,
TestID,
LogDataPath,
LogData,
Status,
UpdateDT
}
public enum eHistDetailTableCols
{
No,
LogAccessKey,
STEP,
POSITION,
MO,
FNC_NAME,
MIN_VALUE,
MEASURE_VALUE,
MAX_VALUE,
DIM,
CHECK_RETURN,
SPENT_TIME,
INFO,
UpdateDT
}
public enum eStat_ProdLoad
{
No,
PalletID,
Index,
ProdNo,
ProdID,
SensorType,
Status
}
public enum eHist_ProdUnload
{
No,
PalletID,
Index,
ProdNo,
ProdID,
Status,
NGCode,
Result,
UpdateDT
}
public enum eHist_LeakTest
{
No,
LogAccessKey,
ProcNo,
PalletNumber,
PalletID,
PIndex,
ProdNo,
ProdID,
SensorType,
Status,
TestID,
Result,
UpdateDT,
Val_Min,
Val_Max,
Val_Meas
}
public enum eNGCodeTable
{
NGCode,
Description,
ProcNo,
TestID,
StepNo,
Type,
ReworkType,
CustomCode,
Status,
UpdateDT
}
public enum eReworkType
{
Retest,
M_Rework,
Rework,
Scrap,
Unknown,
}
}
}

View File

@ -0,0 +1,607 @@
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 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 NGCodeFinder
{
public enum eNGFlag
{
NG,
ERROR
}
public enum eNGDataType
{
CP,
LEAK,
CHECK
}
public enum eJudgeType
{
MIN,
MAX,
CHECK
}
public string UnsortedNGTitle { get; set; } = "Unknown";
DataTable NGCodeTable { get; set; }
XAdaptorPC refPCAdaptor;
public NGCodeFinder(XAdaptorPC refAdaptor)
{
refPCAdaptor = refAdaptor;
NGCodeTable = GetNGCodeTable();
}
public void InitialNgCodeTable()
{
NGCodeTable = GetNGCodeTable();
}
private DataTable GetNGCodeTable()
{
DataTable dtResult = null;
string strQuery = $"SELECT * FROM {DBSchemaMap.TableName_NGCode};";
DataSet dtSetResult = refPCAdaptor.WaitSystemQuery(strQuery);
if(((dtSetResult != null) ? dtSetResult.Tables.Cast<DataTable>().Any(table => table.Rows.Count != 0) : false))
dtResult = dtSetResult.Tables[0];
return dtResult;
}
public Dictionary<string, string> GetNGCodeDictionary(DataRow dtNGRow)
{
Dictionary<string, string> dicNg = new Dictionary<string, string>();
bool bDisplayMessage = true;
try
{
if (dtNGRow == null)
{
dicNg.Add("NTH", "-");
bDisplayMessage = false;
throw new Exception("-");
}
string strProcNo = dtNGRow[eHistTableCommonCols.ProcNo.ToString()].ToString().Trim();
string strTestID = dtNGRow[eHistTableCommonCols.TestID.ToString()].ToString().Trim();
string strResult = "";
try
{
strResult = dtNGRow[eHistTableCommonCols.Result.ToString()].ToString().Trim();
}
catch (Exception ex)
{
strResult = "0";
}
if (strResult == "1" || strResult == "True")
{
dicNg.Add("PASS", "-");
bDisplayMessage = false;
throw new Exception("-");
}
string strUnknwonCode = GetUnknownNGCode(strProcNo, strTestID);
List<DataRow> vdtNGCodeRow = GetNGCodeList(strProcNo, strTestID);
if (vdtNGCodeRow == null ? true : vdtNGCodeRow.Count <= 0)
{
dicNg.Add(strUnknwonCode, "-");
bDisplayMessage = false;
throw new Exception("-");
}
string strLogAccessKey = "";
List<DataRow> vdtDetailRow = null;
List<DataRow> vdtHISTRow = null;
//LogAccessKey Exist - PC/DEVICE
//Not exist - PLC
try
{
strLogAccessKey = dtNGRow[eHistTableCommonCols.LogAccessKey.ToString()]?.ToString().Trim();
vdtDetailRow = GetNGDetailRow(GetNGDetailData(strProcNo, strLogAccessKey));
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
DataRow dtNGDetailRow = null;
DataRow dtNGHISTRow = null;
DataRow dtNGCodeRow = null;
if (vdtDetailRow != null && vdtDetailRow.Count > 0)
dtNGDetailRow = vdtDetailRow[0];
/*
if (vdtNGCodeRow[0][eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.CP.ToString())
dtNGCodeRow = GetNGCodeRowCPLog(vdtNGCodeRow, dtNGDetailRow);
else if (vdtNGCodeRow[0][eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.LEAK.ToString())
dtNGCodeRow = GeNGCodeRowLeakLog(vdtNGCodeRow, dtNGRow);
else
{
List<DataRow> vdtFoundRow = vdtNGCodeRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if (vdtFoundRow.Count > 0)
dtNGCodeRow = vdtFoundRow[0];
else
{
dicNg.Add(strUnknwonCode, "-");
bDisplayMessage = false;
throw new Exception("-");
}
}
*/
if (vdtNGCodeRow.Where(x => x[eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.CP.ToString()).ToList().Count > 0)
dtNGCodeRow = GetNGCodeRowCPLog(vdtNGCodeRow, dtNGDetailRow);
else if (vdtNGCodeRow.Where(x => x[eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.LEAK.ToString()).ToList().Count > 0)
{
vdtHISTRow = GetNGHistRow(GetNGHistData(eHistAllTableList.HIST_Leak, strLogAccessKey));
if (vdtHISTRow != null && vdtHISTRow.Count > 0)
dtNGHISTRow = vdtHISTRow[0];
dtNGCodeRow = GeNGCodeRowLeakLog(vdtNGCodeRow, dtNGHISTRow);
}
if(dtNGCodeRow == null)
{
List<DataRow> vdtFoundRow = vdtNGCodeRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if (vdtFoundRow.Count > 0)
dtNGCodeRow = vdtFoundRow[0];
else
{
dicNg.Add(strUnknwonCode, "-");
bDisplayMessage = false;
throw new Exception("-");
}
}
if(dtNGCodeRow != null)
dicNg.Add(dtNGCodeRow[eNGCodeTable.NGCode.ToString()].ToString().Trim(), dtNGCodeRow[eNGCodeTable.Status.ToString()].ToString().Trim());
}
catch (Exception ex)
{
if (bDisplayMessage)
{
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
@"NgCode<Exception> - NGCodeFinder - GetNGCodeDictionary()\r\n" +
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
}
}
finally { }
return dicNg;
}
public string GetNGCode(DataRow dtNGRow)
{
if (dtNGRow == null)
return "NTH";
string strProcNo = dtNGRow[eHistTableCommonCols.ProcNo.ToString()].ToString().Trim();
string strTestID = dtNGRow[eHistTableCommonCols.TestID.ToString()].ToString().Trim();
string strResult = "";
try
{
strResult = dtNGRow[eHistTableCommonCols.Result.ToString()].ToString().Trim();
}
catch (Exception ex)
{
strResult = "0";
}
if (strResult == "1" || strResult == "True")
return "PASS";
string strUnknwonCode = GetUnknownNGCode(strProcNo, strTestID);
List<DataRow> vdtNGCodeRow = GetNGCodeList(strProcNo, strTestID);
if (vdtNGCodeRow == null ? true : vdtNGCodeRow.Count <= 0)
return strUnknwonCode;
string strLogAccessKey = "";
List<DataRow> vdtDetailRow = null;
List<DataRow> vdtHISTRow = null;
//LogAccessKey Exist - PC/DEVICE
//Not exist - PLC
try
{
strLogAccessKey = dtNGRow[eHistTableCommonCols.LogAccessKey.ToString()]?.ToString().Trim();
vdtDetailRow = GetNGDetailRow(GetNGDetailData(strProcNo, strLogAccessKey));
}
catch (Exception ex)
{
}
DataRow dtNGDetailRow = null;
DataRow dtNGHISTRow = null;
DataRow dtNGCodeRow = null;
bool bUnknownState = false;
try
{
if (vdtDetailRow != null && vdtDetailRow.Count > 0)
dtNGDetailRow = vdtDetailRow[0];
/*
if (vdtNGCodeRow[0][eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.CP.ToString())
dtNGCodeRow = GetNGCodeRowCPLog(vdtNGCodeRow, dtNGDetailRow);
else if (vdtNGCodeRow[0][eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.LEAK.ToString())
dtNGCodeRow = GeNGCodeRowLeakLog(vdtNGCodeRow, dtNGRow);
else
{
List<DataRow> vdtFoundRow = vdtNGCodeRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if (vdtFoundRow.Count > 0)
dtNGCodeRow = vdtFoundRow[0];
else
bUnknownState = true;
}
*/
if (vdtNGCodeRow.Where(x => x[eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.CP.ToString()).ToList().Count > 0)
dtNGCodeRow = GetNGCodeRowCPLog(vdtNGCodeRow, dtNGDetailRow);
else if (vdtNGCodeRow.Where(x => x[eNGCodeTable.CustomCode.ToString()].ToString().Trim() == eNGDataType.LEAK.ToString()).ToList().Count > 0)
{
vdtHISTRow = GetNGHistRow(GetNGHistData (eHistAllTableList.HIST_Leak, strLogAccessKey));
if (vdtHISTRow != null && vdtHISTRow.Count > 0)
dtNGHISTRow = vdtHISTRow[0];
dtNGCodeRow = GeNGCodeRowLeakLog(vdtNGCodeRow, dtNGHISTRow);
}
if(dtNGCodeRow == null)
{
List<DataRow> vdtFoundRow = vdtNGCodeRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if (vdtFoundRow.Count > 0)
dtNGCodeRow = vdtFoundRow[0];
else
bUnknownState = true;
}
}
catch (Exception ex)
{
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
@"NgCode<Exception> - NGCodeFinder - GetNGCode()\r\n" +
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
}
finally { }
if (bUnknownState)
return strUnknwonCode;
else
{
if (dtNGCodeRow != null)
return dtNGCodeRow[eNGCodeTable.NGCode.ToString()].ToString().Trim();
else
return strUnknwonCode;
//return dtNGCodeRow[eNGCodeTable.NGCode.ToString()].ToString().Trim();
}
}
public List<DataRow> GetNGCodeList(string strProcNo, string strTestID)
{
List<DataRow> vdtRows = null;
try
{
if (!(NGCodeTable == null))
{
/*
vdtRows = (from dtRow in NGCodeTable.AsEnumerable()
where dtRow[eNGCodeTable.ProcNo.ToString()].ToString().Trim() == strProcNo
select dtRow).ToList();
*/
vdtRows = (from dtRow in NGCodeTable.AsEnumerable()
where dtRow[eNGCodeTable.ProcNo.ToString()].ToString().Trim() == strProcNo
&& dtRow[eNGCodeTable.TestID.ToString()].ToString().Trim() == strTestID
select dtRow).ToList();
}
}
catch (Exception ex)
{
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
@"NgCode<Exception> - NGCodeFinder - GetNGCodeList()\r\n" +
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
}
finally { }
return vdtRows;
}
public DataTable GetNGDetailData(string strProcNum, string strKeyCode)
{
DataTable dtResult = null;
string strQuery = $"SELECT * FROM {TableName_DetailData}" + "_" + strProcNum + " WHERE " +
$"No IN(SELECT No FROM {TableName_DetailData}" + "_" + strProcNum + " WHERE LogAccessKey = '" + strKeyCode +
$"') ORDER BY {eHistDetailTableCols.STEP.ToString()} ASC;";
DataSet dtSet = refPCAdaptor.WaitSystemQuery(strQuery);
if (dtSet.Tables.Count > 0)
dtResult = dtSet.Tables[0];
return dtResult;
}
public List<DataRow> GetNGDetailRow(DataTable dtResult)
{
if(dtResult == null)
return null;
List<DataRow> vRows = null;
try
{
List<string> vstrNGFlags = Enum.GetNames(typeof(eNGFlag)).ToList();
vRows = (from unitRow in dtResult.AsEnumerable() where vstrNGFlags.Contains(unitRow[eHistDetailTableCols.CHECK_RETURN.ToString()].ToString().Trim()) select unitRow).ToList();
vRows = vRows.OrderBy(x => Convert.ToInt32(x[eHistDetailTableCols.STEP.ToString()].ToString().Trim())).Reverse().ToList();
}
catch (Exception ex)
{
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
@"NgCode<Exception> - NGCodeFinder - GetNGDetailRow()\r\n" +
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
}
finally { }
return vRows;
}
public DataTable GetNGHistData(eHistAllTableList setTable, string strKeyCode)
{
DataTable dtResult = null;
string strQuery = $"SELECT * FROM {setTable.ToString()} WHERE " +
$"No IN(SELECT No FROM {setTable.ToString()} WHERE LogAccessKey = '" + strKeyCode +
$"') ORDER BY No DESC;";
DataSet dtSet = refPCAdaptor.WaitSystemQuery(strQuery);
if (dtSet.Tables.Count > 0)
dtResult = dtSet.Tables[0];
return dtResult;
}
public List<DataRow> GetNGHistRow(DataTable dtResult)
{
if (dtResult == null)
return null;
string strNgResult = "0";
List<DataRow> vRows = null;
try
{
vRows = (from unitRow in dtResult.AsEnumerable() where strNgResult == (unitRow[eHistTableCommonCols.Result.ToString()].ToString().Trim()) select unitRow).ToList();
vRows = vRows.OrderBy(x => Convert.ToInt32(x[eHistDetailTableCols.STEP.ToString()].ToString().Trim())).Reverse().ToList();
}
catch (Exception ex)
{
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
@"NgCode<Exception> - NGCodeFinder - GetNGHistRow()\r\n" +
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
}
finally { }
return vRows;
}
DataRow GeNGCodeRowLeakLog(List<DataRow> vdtRstRow, DataRow dtDetailNGRow)
{
List<DataRow> vFoundRow = null;
double dMVal = double.NaN;
double dMin = double.NaN;
double dMax = double.NaN;
if(dtDetailNGRow == null)
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if(vFoundRow.Count > 0)
return vFoundRow[0];
else
return null;
}
double.TryParse(dtDetailNGRow[eHist_LeakTest.Val_Meas.ToString()].ToString().Trim(), out dMVal);
double.TryParse(dtDetailNGRow[eHist_LeakTest.Val_Min.ToString()].ToString().Trim(), out dMin);
double.TryParse(dtDetailNGRow[eHist_LeakTest.Val_Max.ToString()].ToString().Trim(), out dMax);
if (double.IsNaN(dMVal) ||
double.IsNaN(dMin) ||
double.IsNaN(dMax))
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if(vFoundRow.Count > 0)
return vFoundRow[0];
}
if(dMVal < dMin)
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.MIN.ToString()).ToList();
if(vFoundRow.Count > 0)
return vFoundRow[0];
else
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if (vFoundRow.Count > 0)
return vFoundRow[0];
}
}
else if(dMVal > dMax)
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.MAX.ToString()).ToList();
if(vFoundRow.Count > 0)
return vFoundRow[0];
else
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if (vFoundRow.Count > 0)
return vFoundRow[0];
}
}
else
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if (vFoundRow.Count > 0)
return vFoundRow[0];
}
return null;
}
DataRow GetNGCodeRowCPLog(List<DataRow> vdtRstRow, DataRow dtDetailNGRow)
{
List<DataRow> vFoundRow = null;
double dMVal = double.NaN;
double dMin = double.NaN;
double dMax = double.NaN;
if(dtDetailNGRow == null)
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if(vFoundRow.Count > 0)
return vFoundRow[0];
else
return null;
}
double.TryParse(dtDetailNGRow[eHistDetailTableCols.MEASURE_VALUE.ToString()].ToString().Trim(), out dMVal);
double.TryParse(dtDetailNGRow[eHistDetailTableCols.MIN_VALUE.ToString()].ToString().Trim(), out dMin);
double.TryParse(dtDetailNGRow[eHistDetailTableCols.MAX_VALUE.ToString()].ToString().Trim(), out dMax);
int iGetStep = 0;
int.TryParse(dtDetailNGRow[eHistDetailTableCols.STEP.ToString()].ToString().Trim(), out iGetStep);
if (double.IsNaN(dMVal) ||
double.IsNaN(dMin) ||
double.IsNaN(dMax))
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if(vFoundRow.Count > 0)
return vFoundRow[0];
}
else if(dMVal < dMin)
{
vFoundRow = vdtRstRow.Where(x => (x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.MIN.ToString()) &&
(x[eNGCodeTable.StepNo.ToString()].ToString().Trim() == iGetStep.ToString())).ToList();
if(vFoundRow.Count > 0)
return vFoundRow[0];
else
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if (vFoundRow.Count > 0)
return vFoundRow[0];
}
}
else if(dMVal > dMax)
{
vFoundRow = vdtRstRow.Where(x => (x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.MAX.ToString()) &&
(x[eNGCodeTable.StepNo.ToString()].ToString().Trim() == iGetStep.ToString())).ToList();
if (vFoundRow.Count > 0)
return vFoundRow[0];
else
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if (vFoundRow.Count > 0)
return vFoundRow[0];
}
}
else
{
vFoundRow = vdtRstRow.Where(x => x[eNGCodeTable.Type.ToString()].ToString().Trim() == eJudgeType.CHECK.ToString()).ToList();
if (vFoundRow.Count > 0)
return vFoundRow[0];
}
return null;
}
string GetUnknownNGCode(string strProcNo, string strTestID)
{
string strNGCodeResult = UnsortedNGTitle + ":" + strProcNo + "-" + strTestID;
return strNGCodeResult;
}
public eReworkType GetReworkType(string strNGCode)
{
List<DataRow> vdtRstRow = (from dtNGRow in NGCodeTable.AsEnumerable() where dtNGRow[eNGCodeTable.NGCode.ToString()].ToString().Trim() == strNGCode select dtNGRow).ToList();
eReworkType R_Type = eReworkType.Unknown;
if(vdtRstRow.Count == 0)
return R_Type;
string strRType = "";
try
{
strRType = vdtRstRow[0][eNGCodeTable.ReworkType.ToString()].ToString().Trim();
}
catch (Exception ex)
{
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
@"NgCode<Exception> - NGCodeFinder - GetReworkType()\r\n" +
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
}
finally { }
if (!Enum.TryParse(strRType, out R_Type))
return R_Type;
return R_Type;
}
}
}

View File

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
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 NGCodeMgr
{
public bool CONNECT { internal set; get; }
NGCodeFinder NGCodeFinder { get; set; }
NGHistDBFinder HistFinder { get; set; }
XAdaptorPC refPCAdaptor;
public NGCodeMgr(XAdaptorPC refAdaptor)
{
refPCAdaptor = refAdaptor;
CreateInstances();
}
bool CreateInstances()
{
try
{
HistFinder = new NGHistDBFinder(refPCAdaptor);
NGCodeFinder = new NGCodeFinder(refPCAdaptor);
NGCodeFinder.InitialNgCodeTable();
}
catch (Exception ex)
{
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"Error during initiating NG Code Manager Instance: " + ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
return false;
}
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") + @"Recv NgTable.", ConsoleColor.White, LogMessageLevel.DEBUG);
return true;
}
public List<string> GetNGCodeHistory(string strProductID)
{
return HistFinder.GetNGCodeHistory(strProductID);
}
public Dictionary<eHistProcTableList, DataRow> GetProcResult(string strProductID, string strPalletID, bool bFirstNgFind)
{
return HistFinder.FindHistory(strProductID, strPalletID, bFirstNgFind);
}
public Tuple<eHistProcTableList, DataRow, bool> GetNGProcess(string strProductID, string strPalletID)
{
return HistFinder.FindNGHistory(strProductID, strPalletID);
}
public Dictionary<string, string> GetNGCodeDictionary(eHistProcTableList proc, DataRow dtRow)
{
Dictionary<string, string> dicNgCode = null;
dicNgCode = NGCodeFinder.GetNGCodeDictionary(dtRow);
return dicNgCode;
}
public string GetNGCode(eHistProcTableList proc, DataRow dtRow)
{
string strNGCode = string.Empty;
strNGCode = NGCodeFinder .GetNGCode(dtRow);
return strNGCode;
}
public eReworkType GetReworkType(string strNGCode)
{
return NGCodeFinder.GetReworkType(strNGCode);
}
}
}

View File

@ -0,0 +1,212 @@
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<eHistProcTableList, Tuple<int, string>> dicHistInfo;
XAdaptorPC refPCAdaptor;
public NGHistDBFinder(XAdaptorPC refAdaptor)
{
refPCAdaptor = refAdaptor;
dicHistInfo = new Dictionary<eHistProcTableList, Tuple<int, string>>();
dicHistInfo.Add(eHistProcTableList.HIST_ProdLoad, new Tuple<int, string>(180, "PL"));
dicHistInfo.Add(eHistProcTableList.HIST_CapDeassy, new Tuple<int, string>(180, "CDA"));
dicHistInfo.Add(eHistProcTableList.HIST_PreHeating, new Tuple<int, string>(190, "PH"));
dicHistInfo.Add(eHistProcTableList.HIST_PreMeas, new Tuple<int, string>(190, "PM"));
dicHistInfo.Add(eHistProcTableList.HIST_Leak, new Tuple<int, string>(200, "LK"));
dicHistInfo.Add(eHistProcTableList.HIST_LaserTrim, new Tuple<int, string>(210, "LT"));
dicHistInfo.Add(eHistProcTableList.HIST_LaserTrimVision, new Tuple<int, string>(220, "LTV"));
dicHistInfo.Add(eHistProcTableList.HIST_IsoRes, new Tuple<int, string>(220, "IR"));
dicHistInfo.Add(eHistProcTableList.HIST_CapAssy, new Tuple<int, string>(230, "CA"));
dicHistInfo.Add(eHistProcTableList.HIST_Function, new Tuple<int, string>(240, "FT"));
dicHistInfo.Add(eHistProcTableList.HIST_OutSealPress, new Tuple<int, string>(250, "OSP"));
dicHistInfo.Add(eHistProcTableList.HIST_PinVision, new Tuple<int, string>(260, "PV"));
dicHistInfo.Add(eHistProcTableList.HIST_PinLVDT, new Tuple<int, string>(260, "LVDT"));
}
public Dictionary<eHistProcTableList, DataRow> FindHistory(string strMESID, string strPalletID, bool bFristFailScan = false)
{
Dictionary<eHistProcTableList, DataRow> dicResult = new Dictionary<eHistProcTableList, DataRow>();
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<Exception> - NGHistDBFinder - FindHistory()\r\n" +
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
}
finally { }
return dicResult;
}
public Tuple<eHistProcTableList, DataRow, bool> FindNGHistory(string strMESID, string strPalletID)
{
Tuple<eHistProcTableList, DataRow, bool> pairResult = null;
Dictionary<eHistProcTableList, DataRow> 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<eHistProcTableList, DataRow, bool>(procTbl, null, true);
}
else
{
pairResult = new Tuple<eHistProcTableList, DataRow, bool>(procTbl, dtRow, false);
break;
}
}
}
catch (Exception ex)
{
MessageOutput.ConsoleWrite(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss>>") +
@"NgCode<Exception> - NGHistDBFinder - FindNGHistory()\r\n" +
ex.Message, ConsoleColor.Yellow, LogMessageLevel.DEBUG);
}
finally { }
return pairResult;
}
public List<string> 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<string> vstrPalletID = (from dtResult in dtSet.Tables[0].AsEnumerable()
let strResult = dtResult[eHistTableCommonCols.PalletID.ToString()].ToString().Trim()
select strResult).ToList();
return vstrPalletID;
}
public List<string> GetNGCodeHistory(string strMESID)
{
List<string> 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<Exception> - 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<string> 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}";
}
}