using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Text.Json; using System.Text.RegularExpressions; namespace Adaptation.FileHandlers.TIBCO.Transport; public class Job { public string AutomationMode { get; } public string BasicType { get; } public string Equipment { get; } public string JobName { get; } public string LotName { get; } public string PackageName { get; } public string ProcessSpecName { get; } public string ProcessType { get; } public string ProductName { get; } public string Qty { get; } public string RecipeName { get; } public string StateModel { get; } // public bool IsAreaSi { get; } public DateTime DateTime { get; } public List Items { get; } public Job(string lsl2SQLConnectionString, string mid) { Items = new List(); if (string.IsNullOrEmpty(mid) || mid[0] != '{' || mid[mid.Length - 1] != '}' || !mid.Contains("\"Si\"")) IsAreaSi = false; else { string psn; int rds = 0; string lotName; string reactor; string basicType; const string hyphen = "-"; Input input = JsonSerializer.Deserialize(mid); IsAreaSi = input.Area == "Si"; if (input.MID is null) input.MID = string.Empty; if (!long.TryParse(input.Sequence, out long sequence)) DateTime = DateTime.Now; else DateTime = new DateTime(sequence); string[] segments = Regex.Split(input.MID, @"[^0-9']"); if (segments.Length < 3 || (segments.Length > 1 && !int.TryParse(segments[1], out rds))) { psn = string.Empty; reactor = string.Empty; } else if (rds is < 100000 or > 100000000) { psn = string.Empty; reactor = string.Empty; } else { psn = segments[2]; reactor = segments[0]; } AutomationMode = string.Concat(DateTime.Ticks, ".", input.MesEntity); Equipment = input.MesEntity; JobName = DateTime.Ticks.ToString(); if (rds is < 100000 or > 100000000) { basicType = hyphen; lotName = input.MID; } else { lotName = rds.ToString(); string json = GetRunJson(lsl2SQLConnectionString, rds); if (string.IsNullOrEmpty(json)) basicType = hyphen; else { Run[] runs; try { runs = JsonSerializer.Deserialize(json); } catch (Exception) { runs = Array.Empty(); } if (!runs.Any()) basicType = hyphen; else { if (string.IsNullOrEmpty(reactor)) reactor = runs[0].REACTOR.ToString(); if (string.IsNullOrEmpty(psn)) psn = runs[0].PS_NO; string loadLockSide = runs[0].LOAD_LOCK_SIDE; string loadLockSideFull = loadLockSide switch { "L" => "Left", "R" => "Right", _ => loadLockSide, }; basicType = $"{loadLockSideFull} - {runs[0].REACTOR_TYPE}"; } } } BasicType = basicType; LotName = lotName; PackageName = hyphen; //WAFER_ID WaferLot ProcessSpecName = hyphen; //WAFER_POS PocketNumber ProcessType = reactor; ProductName = psn; Qty = "1"; RecipeName = input.Recipe; StateModel = input.EquipmentType; Items.Add(new Item { Name = "0", Type = "NA", Number = (0 + 1).ToString(), Qty = "1", CarrierName = hyphen }); } } private static string GetRunJson(string lsl2SQLConnectionString, int rds) { string result; object scalar = null; StringBuilder sql = new(); _ = sql.Append(" SELECT "). Append(" RDS_NO, "). Append(" WO_NO, "). Append(" WO_STEP, "). Append(" CASS_NO, "). Append(" REACTOR, "). Append(" VER_WFR_CNT, "). Append(" LOAD_WFR_CNT, "). Append(" ENTER_BY, "). Append(" ENTER_DTM, "). Append(" VER_SIG, "). Append(" VER_SIG_DTM, "). Append(" PRE_SIG, "). Append(" PRE_SIG_DTM, "). Append(" LOAD_SIG, "). Append(" LOAD_SIG_DTM, "). Append(" WFR_SIG, "). Append(" WFR_SIG_DTM, "). Append(" UNLOAD_SIG, "). Append(" UNLOAD_SIG_DTM, "). Append(" POST_SIG, "). Append(" POST_SIG_DTM, "). Append(" FINAL_SIG, "). Append(" FINAL_SIG_DTM, "). Append(" SCHED_DT, "). Append(" REACT_IDLE_TIME, "). Append(" SHIFT, "). Append(" LOAD_LOCK_SIDE, "). Append(" ADE_READ, "). Append(" INJECTORS, "). Append(" TUBE_ID, "). Append(" TUBE_GRADE, "). Append(" SUSCEPTOR_ID, "). Append(" SUPP_INST, "). Append(" SUPP_ENTRY_ID, "). Append(" SUPP_ENTRY_DTM, "). Append(" SUPP_SIG, "). Append(" SUPP_SIG_DTM, "). Append(" REACT_ACT_ESC_DTM, "). Append(" SCHED_WFR_QTY, "). Append(" CURR_WFR_CNT, "). Append(" CURR_WFR_CNT_REJ, "). Append(" CUST_NAME, "). Append(" CUST_NO, "). Append(" LOT_NO, "). Append(" PART_NO, "). Append(" PS_NO, "). Append(" REACTOR_TYPE, "). Append(" RECIPE_NAME, "). Append(" RECIPE_NO, "). Append(" SPEC_TYPE, "). Append(" WFR_UNLOAD_DAYS, "). Append(" WFR_UNLOAD_NIGHTS, "). Append(" WFR_UNLOAD_QTY, "). Append(" CASS_ID_SAP, "). Append(" REACT_TOOL_ID "). Append(" FROM [LSL2SQL].[dbo].[REACT_RUN] "). Append(" WHERE RDS_NO = '").Append(rds).Append("' "). Append(" FOR JSON PATH "); try { using SqlConnection sqlConnection = new(lsl2SQLConnectionString); sqlConnection.Open(); using (SqlCommand sqlCommand = new(sql.ToString(), sqlConnection)) scalar = sqlCommand.ExecuteScalar(); sqlConnection.Close(); } catch (Exception) { } if (scalar is null) result = string.Empty; else result = scalar.ToString(); return result; } }