| | 1 | | using Microsoft.Data.SqlClient; |
| | 2 | | using ReportingServices.Shared.Models.PlanningReport; |
| | 3 | | using ReportingServices.Shared.Models.ProductionReport; |
| | 4 | | using System.Data; |
| | 5 | |
|
| | 6 | | namespace ReportingServices.Shared.Repositories |
| | 7 | | { |
| | 8 | | public class ScrapeDatabaseRepository : IScrapeDatabaseRepository |
| | 9 | | { |
| | 10 | | private SqlConnection _connection; |
| | 11 | | private readonly string _connectionString; |
| | 12 | |
|
| 0 | 13 | | public ScrapeDatabaseRepository() |
| 0 | 14 | | { |
| 0 | 15 | | _connectionString = "Server=MESSV01EC.EC.LOCAL\\PROD1,53959;Database=LSL2SQL;User Id=srpadmin;Password=0okm9 |
| 0 | 16 | | } |
| | 17 | |
|
| | 18 | | public void OpenConnection() |
| 0 | 19 | | { |
| 0 | 20 | | if (_connection == null) |
| 0 | 21 | | _connection = new SqlConnection(_connectionString); |
| | 22 | |
|
| 0 | 23 | | if (_connection.State != ConnectionState.Open) |
| 0 | 24 | | _connection.Open(); |
| 0 | 25 | | } |
| | 26 | |
|
| | 27 | | public void CloseConnection() |
| 0 | 28 | | { |
| 0 | 29 | | if (_connection.State != ConnectionState.Closed) |
| 0 | 30 | | _connection.Close(); |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | public int GetNumberOfPartChanges(string startDate, string endDate) |
| 0 | 34 | | { |
| 0 | 35 | | int result = 0; |
| | 36 | |
|
| 0 | 37 | | OpenConnection(); |
| | 38 | |
|
| 0 | 39 | | SqlCommand cmd = _connection.CreateCommand(); |
| | 40 | |
|
| 0 | 41 | | string query = "SELECT COUNT(*) FROM " + |
| 0 | 42 | | "(SELECT REACTOR, COUNT(PROD_SPEC_ID) - 1 AS PCHANGE FROM " + |
| 0 | 43 | | "(SELECT REACTOR, PROD_SPEC_ID, COUNT(WO) AS PSN_COUNT FROM RDS WHERE DATE_OUT BETWEEN @start |
| 0 | 44 | | "GROUP BY REACTOR) AS l WHERE PCHANGE > 0"; |
| | 45 | |
|
| 0 | 46 | | cmd.CommandText = query; |
| 0 | 47 | | cmd.Parameters.AddWithValue("@startDate", startDate); |
| 0 | 48 | | cmd.Parameters.AddWithValue("@endDate", endDate); |
| | 49 | |
|
| 0 | 50 | | using (SqlDataReader reader = cmd.ExecuteReader()) |
| 0 | 51 | | { |
| 0 | 52 | | reader.Read(); |
| | 53 | |
|
| 0 | 54 | | result = int.Parse(reader[0].ToString()); |
| 0 | 55 | | } |
| | 56 | |
|
| 0 | 57 | | cmd.Dispose(); |
| | 58 | |
|
| 0 | 59 | | CloseConnection(); |
| | 60 | |
|
| 0 | 61 | | return result; |
| 0 | 62 | | } |
| | 63 | |
|
| | 64 | | public List<ScrapByDay> GetScrapByDay(List<ReactorOutsByRDS> outs) |
| 0 | 65 | | { |
| 0 | 66 | | List<ScrapByDay> scrap = new(); |
| 0 | 67 | | string rdsNumbers = ""; |
| | 68 | |
|
| 0 | 69 | | foreach (ReactorOutsByRDS rout in outs) |
| 0 | 70 | | rdsNumbers = rdsNumbers + "'" + rout.RDS_NO + "', "; |
| | 71 | |
|
| 0 | 72 | | rdsNumbers = rdsNumbers.Substring(0, rdsNumbers.Length - 2); |
| | 73 | |
|
| 0 | 74 | | OpenConnection(); |
| | 75 | |
|
| 0 | 76 | | SqlCommand cmd = _connection.CreateCommand(); |
| | 77 | |
|
| 0 | 78 | | string query = "SELECT " + |
| 0 | 79 | | " DATE_OUT," + |
| 0 | 80 | | " SUM(CUST_TOT_REJ) AS TOT_REJ_CUST," + |
| 0 | 81 | | " SUM(LSL_TOT_REJ) AS TOT_REJ_MANU," + |
| 0 | 82 | | " SUM(TW_PROD) AS TW_PROD " + |
| 0 | 83 | | "FROM RDS " + |
| 0 | 84 | | "WHERE SEQ IN (" + rdsNumbers + ") " + |
| 0 | 85 | | "GROUP BY DATE_OUT " + |
| 0 | 86 | | "ORDER BY 1 DESC"; |
| | 87 | |
|
| 0 | 88 | | cmd.CommandText = query; |
| | 89 | |
|
| 0 | 90 | | using (SqlDataReader reader = cmd.ExecuteReader()) |
| 0 | 91 | | { |
| 0 | 92 | | while (reader.Read() && reader[0].ToString() != "1/1/1900 12:00:00 AM") |
| 0 | 93 | | scrap.Add(new ScrapByDay |
| 0 | 94 | | { |
| 0 | 95 | | StartDate = reader[0].ToString(), |
| 0 | 96 | | TW_PROD = int.Parse(reader[3].ToString()), |
| 0 | 97 | | TOT_REJ_CUST = int.Parse(reader[1].ToString()), |
| 0 | 98 | | TOT_REJ_MANU = int.Parse(reader[2].ToString()), |
| 0 | 99 | | TOT_REJ_WFRS = |
| 0 | 100 | | int.Parse(reader[1].ToString()) + int.Parse(reader[2].ToString()) |
| 0 | 101 | | }); |
| 0 | 102 | | } |
| | 103 | |
|
| 0 | 104 | | cmd.Dispose(); |
| | 105 | |
|
| 0 | 106 | | CloseConnection(); |
| | 107 | |
|
| 0 | 108 | | return scrap; |
| 0 | 109 | | } |
| | 110 | |
|
| | 111 | | public List<ReactorPSNWORuns> GetReactorPSNWORuns(string startDate, string endDate) |
| 0 | 112 | | { |
| 0 | 113 | | List<ReactorPSNWORuns> weeklyPartChanges = new(); |
| | 114 | |
|
| 0 | 115 | | OpenConnection(); |
| | 116 | |
|
| 0 | 117 | | SqlCommand cmd = _connection.CreateCommand(); |
| | 118 | |
|
| 0 | 119 | | string query = "SELECT REACTOR, PROD_SPEC_ID, COUNT(WO) FROM RDS " + |
| 0 | 120 | | "WHERE DATE_OUT BETWEEN @startDate AND @endDate " + |
| 0 | 121 | | "GROUP BY REACTOR, PROD_SPEC_ID " + |
| 0 | 122 | | "ORDER BY 1"; |
| | 123 | |
|
| 0 | 124 | | cmd.CommandText = query; |
| 0 | 125 | | cmd.Parameters.AddWithValue("@startDate", startDate); |
| 0 | 126 | | cmd.Parameters.AddWithValue("@endDate", endDate); |
| | 127 | |
|
| 0 | 128 | | using (SqlDataReader reader = cmd.ExecuteReader()) |
| 0 | 129 | | { |
| 0 | 130 | | while (reader.Read()) |
| 0 | 131 | | weeklyPartChanges.Add(new ReactorPSNWORuns |
| 0 | 132 | | { |
| 0 | 133 | | REACTOR = reader[0].ToString(), |
| 0 | 134 | | PSN = reader[1].ToString(), |
| 0 | 135 | | WO_COUNT = int.Parse(reader[2].ToString()) |
| 0 | 136 | | }); |
| 0 | 137 | | } |
| | 138 | |
|
| 0 | 139 | | cmd.Dispose(); |
| | 140 | |
|
| 0 | 141 | | CloseConnection(); |
| | 142 | |
|
| 0 | 143 | | return weeklyPartChanges; |
| 0 | 144 | | } |
| | 145 | |
|
| | 146 | | public QuarterlyTargets GetQuarterlyTargets() |
| 0 | 147 | | { |
| 0 | 148 | | Dictionary<string, float> targets = new(); |
| | 149 | |
|
| 0 | 150 | | OpenConnection(); |
| | 151 | |
|
| 0 | 152 | | SqlCommand cmd = _connection.CreateCommand(); |
| | 153 | |
|
| 0 | 154 | | string query = "SELECT THRU_TARGET, THRU_QTY, THRU_PCNT FROM FISCAL_QTR_TARGETS " + |
| 0 | 155 | | " WHERE THRU_GROUP = 'TOT' " + |
| 0 | 156 | | " AND FISCAL_YR = " + |
| 0 | 157 | | " (SELECT FISCAL_YR FROM FISCAL_QTR " + |
| 0 | 158 | | " WHERE START_DT < SYSDATETIME() " + |
| 0 | 159 | | " AND END_DT > SYSDATETIME()) " + |
| 0 | 160 | | " AND FISCAL_QTR = " + |
| 0 | 161 | | " (SELECT FISCAL_QTR FROM FISCAL_QTR " + |
| 0 | 162 | | " WHERE START_DT < SYSDATETIME() " + |
| 0 | 163 | | " AND END_DT > SYSDATETIME()) " + |
| 0 | 164 | | "UNION " + |
| 0 | 165 | | "SELECT 'PlanWorkingDays' As THRU_TARGET," + |
| 0 | 166 | | " PLAN_WORKING_DAYS AS THRU_QTY," + |
| 0 | 167 | | " NULL AS THRU_PCNT" + |
| 0 | 168 | | " FROM FISCAL_QTR " + |
| 0 | 169 | | " WHERE SYSDATETIME() BETWEEN START_DT AND END_DT"; |
| | 170 | |
|
| 0 | 171 | | cmd.CommandText = query; |
| | 172 | |
|
| 0 | 173 | | using (SqlDataReader reader = cmd.ExecuteReader()) |
| 0 | 174 | | { |
| 0 | 175 | | while(reader.Read()) |
| 0 | 176 | | { |
| 0 | 177 | | if (reader[0].ToString().ToUpper() == "YIELD") |
| 0 | 178 | | targets.Add(reader[0].ToString(), float.Parse(reader[2].ToString())); |
| 0 | 179 | | else if (!string.IsNullOrEmpty(reader[1].ToString())) |
| 0 | 180 | | targets.Add(reader[0].ToString(), int.Parse(reader[1].ToString())); |
| 0 | 181 | | } |
| 0 | 182 | | } |
| | 183 | |
|
| 0 | 184 | | cmd.Dispose(); |
| | 185 | |
|
| 0 | 186 | | CloseConnection(); |
| | 187 | |
|
| 0 | 188 | | QuarterlyTargets quarterlyTargets = new() |
| 0 | 189 | | { |
| 0 | 190 | | Reactor_Outs = (int)targets["Reactor_Outs"], |
| 0 | 191 | | Yield_Outs = (int)targets["Yield_Outs"], |
| 0 | 192 | | IFX_Scrap = (int)targets["IFX_Scrap"], |
| 0 | 193 | | Yield = targets["Yield"], |
| 0 | 194 | | PlanWorkingDays = (int)targets["PlanWorkingDays"] |
| 0 | 195 | | }; |
| | 196 | |
|
| 0 | 197 | | return quarterlyTargets; |
| 0 | 198 | | } |
| | 199 | |
|
| | 200 | | public List<Reactor> GetReactors() |
| 0 | 201 | | { |
| 0 | 202 | | List<Reactor> reactors = new(); |
| | 203 | |
|
| 0 | 204 | | OpenConnection(); |
| | 205 | |
|
| 0 | 206 | | SqlCommand cmd = _connection.CreateCommand(); |
| | 207 | |
|
| 0 | 208 | | string query = "SELECT " + |
| 0 | 209 | | " REACT_NO, REACT_TYPE, SUSC_POCKET_SIZE, CASE WHEN ACTIVE_LL_DISABLED <> '' THEN 'TRUE' EL |
| 0 | 210 | | " FROM REACTOR " + |
| 0 | 211 | | " WHERE REACT_ASSIGNMENT IS NOT NULL " + |
| 0 | 212 | | " AND REACT_ASSIGNMENT <> 'Out of Service' " + |
| 0 | 213 | | " AND REACT_ASSIGNMENT<> ''"; |
| | 214 | |
|
| 0 | 215 | | cmd.CommandText = query; |
| | 216 | |
|
| 0 | 217 | | using (SqlDataReader reader = cmd.ExecuteReader()) |
| 0 | 218 | | { |
| 0 | 219 | | while (reader.Read()) |
| 0 | 220 | | reactors.Add(new Reactor |
| 0 | 221 | | { |
| 0 | 222 | | ReactorNumber = int.Parse(reader[0].ToString()), |
| 0 | 223 | | Type = reader[1].ToString(), |
| 0 | 224 | | PocketSize = reader[2].ToString(), |
| 0 | 225 | | HasDisabledLoadlock = bool.Parse(reader[3].ToString()) |
| 0 | 226 | | }); |
| 0 | 227 | | } |
| | 228 | |
|
| 0 | 229 | | cmd.Dispose(); |
| | 230 | |
|
| 0 | 231 | | CloseConnection(); |
| | 232 | |
|
| 0 | 233 | | return reactors; |
| 0 | 234 | | } |
| | 235 | |
|
| | 236 | | public List<RDS> GetRDSForLastDay(string date) |
| 0 | 237 | | { |
| 0 | 238 | | List<RDS> rdsList = new(); |
| | 239 | |
|
| 0 | 240 | | OpenConnection(); |
| | 241 | |
|
| 0 | 242 | | SqlCommand cmd = _connection.CreateCommand(); |
| | 243 | |
|
| 0 | 244 | | string query = "SELECT rds.REACTOR, rds.REACTOR_TYPE, rds.DATE_OUT, " + |
| 0 | 245 | | "CASE WHEN lay.UL_TEMP IS NULL THEN '1000' ELSE lay.UL_TEMP END, psn.LAYER_TYPE FROM RDS " + |
| 0 | 246 | | "INNER JOIN RDS_LAYER lay ON lay.RDS_NO = SEQ " + |
| 0 | 247 | | "INNER JOIN PROD_SPEC psn ON rds.PROD_SPEC_ID = psn.SEQ " + |
| 0 | 248 | | "WHERE DATE_OUT >= @date"; |
| | 249 | |
|
| 0 | 250 | | cmd.CommandText = query; |
| 0 | 251 | | cmd.Parameters.AddWithValue("@date", date); |
| | 252 | |
|
| 0 | 253 | | using (SqlDataReader reader = cmd.ExecuteReader()) |
| 0 | 254 | | { |
| 0 | 255 | | while (reader.Read()) |
| 0 | 256 | | rdsList.Add(new RDS |
| 0 | 257 | | { |
| 0 | 258 | | Reactor = int.Parse(reader[0].ToString()), |
| 0 | 259 | | ReactorType = reader[1].ToString(), |
| 0 | 260 | | DateOut = DateTime.Parse(reader[2].ToString()), |
| 0 | 261 | | UnloadTemp = int.Parse(reader[3].ToString()), |
| 0 | 262 | | LayerType = reader[4].ToString() |
| 0 | 263 | | }); |
| 0 | 264 | | } |
| | 265 | |
|
| 0 | 266 | | cmd.Dispose(); |
| | 267 | |
|
| 0 | 268 | | CloseConnection(); |
| | 269 | |
|
| 0 | 270 | | return rdsList; |
| 0 | 271 | | } |
| | 272 | | } |
| | 273 | | } |