hytos / DTI_PID / SPPIDConverter / DB / SPPID_DB.cs @ dfb9a03c
이력 | 보기 | 이력해설 | 다운로드 (44.4 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
using System.Data; |
7 |
using System.Globalization; |
8 |
using System.IO; |
9 |
using Oracle.ManagedDataAccess.Client; |
10 |
using System.Data.SqlClient; |
11 |
|
12 |
namespace Converter.SPPID.DB |
13 |
{ |
14 |
public class SPPID_DB |
15 |
{ |
16 |
private const string oracleConnString = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST ={0}" + @")(PORT = {1}))(CONNECT_DATA = (SERVICE_NAME = {2})))"; |
17 |
private const string sqlConnString = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST ={0}" + @")(PORT = {1}))(CONNECT_DATA = (SERVICE_NAME = {2})))"; |
18 |
|
19 |
public static bool CheckAndSetSPPIDInfo(SPPID_DBInfo dbInfo) |
20 |
{ |
21 |
bool bResult = false; |
22 |
try |
23 |
{ |
24 |
if (dbInfo.DBType == "ORACLE") |
25 |
{ |
26 |
string connString = string.Format(oracleConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
27 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
28 |
|
29 |
using (OracleConnection conn = new OracleConnection(connString)) |
30 |
{ |
31 |
conn.Open(); |
32 |
if (conn.State == System.Data.ConnectionState.Open) |
33 |
{ |
34 |
using (OracleCommand cmd = new OracleCommand()) |
35 |
{ |
36 |
cmd.Connection = conn; |
37 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT NAME, PATH FROM {0}.T_ROOTITEM", dbInfo.Site); |
38 |
|
39 |
using (OracleDataReader reader = cmd.ExecuteReader()) |
40 |
{ |
41 |
while (reader.Read()) |
42 |
{ |
43 |
dbInfo.Plant = reader["NAME"].ToString(); |
44 |
dbInfo.PlantPath = reader["PATH"].ToString(); |
45 |
} |
46 |
|
47 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, @"SELECT SP_SCHEMA_TYPE, USERNAME |
48 |
FROM {0}.T_DB_DATA DB_DATA |
49 |
INNER JOIN {0}.T_ROOTITEM ROOTITEM ON DB_DATA.SP_ROOTITEMID = ROOTITEM.SP_ID |
50 |
WHERE ROOTITEM.NAME = '{1}'", dbInfo.Site, dbInfo.Plant); |
51 |
|
52 |
|
53 |
using (OracleDataAdapter adapter = new OracleDataAdapter()) |
54 |
{ |
55 |
DataTable dt = new DataTable(); |
56 |
adapter.SelectCommand = cmd; |
57 |
adapter.Fill(dt); |
58 |
|
59 |
foreach (DataRow row in dt.Rows) |
60 |
{ |
61 |
string sType = row["SP_SCHEMA_TYPE"].ToString(); |
62 |
switch (sType) |
63 |
{ |
64 |
case "SPPIDDATA_DICTIONARY": |
65 |
dbInfo.PlantPIDDic = row["USERNAME"].ToString(); |
66 |
break; |
67 |
case "DATA_DICTIONARY": |
68 |
dbInfo.PlantDic = row["USERNAME"].ToString(); |
69 |
break; |
70 |
case "SPAPLANT": |
71 |
dbInfo.Plant = row["USERNAME"].ToString(); |
72 |
break; |
73 |
case "SPPID": |
74 |
dbInfo.PlantPID = row["USERNAME"].ToString(); |
75 |
break; |
76 |
default: |
77 |
break; |
78 |
} |
79 |
} |
80 |
bResult = true; |
81 |
} |
82 |
} |
83 |
} |
84 |
} |
85 |
} |
86 |
} |
87 |
else if (dbInfo.DBType == "SQLSERVER") |
88 |
{ |
89 |
|
90 |
} |
91 |
} |
92 |
catch (Exception ex) |
93 |
{ |
94 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
95 |
} |
96 |
|
97 |
return bResult; |
98 |
} |
99 |
public static bool SetPlantDBSetting(SPPID_DBInfo dbInfo) |
100 |
{ |
101 |
bool bResult = false; |
102 |
try |
103 |
{ |
104 |
if (dbInfo.DBType == "ORACLE") |
105 |
{ |
106 |
string connString = string.Format(oracleConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
107 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
108 |
|
109 |
using (OracleConnection conn = new OracleConnection(connString)) |
110 |
{ |
111 |
conn.Open(); |
112 |
if (conn.State == System.Data.ConnectionState.Open) |
113 |
{ |
114 |
using (OracleCommand cmd = new OracleCommand()) |
115 |
{ |
116 |
cmd.Connection = conn; |
117 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, @"SELECT SP_SCHEMA_TYPE, USERNAME |
118 |
FROM {0}.T_DB_DATA DB_DATA |
119 |
INNER JOIN {0}.T_ROOTITEM ROOTITEM ON DB_DATA.SP_ROOTITEMID = ROOTITEM.SP_ID |
120 |
WHERE ROOTITEM.NAME = '{1}'", dbInfo.Site, dbInfo.SelectedPlant); |
121 |
using (OracleDataAdapter adapter = new OracleDataAdapter()) |
122 |
{ |
123 |
DataTable dt = new DataTable(); |
124 |
adapter.SelectCommand = cmd; |
125 |
adapter.Fill(dt); |
126 |
|
127 |
foreach (DataRow row in dt.Rows) |
128 |
{ |
129 |
string sType = row["SP_SCHEMA_TYPE"].ToString(); |
130 |
switch (sType) |
131 |
{ |
132 |
case "SPPIDDATA_DICTIONARY": |
133 |
dbInfo.PlantPIDDic = row["USERNAME"].ToString(); |
134 |
break; |
135 |
case "DATA_DICTIONARY": |
136 |
dbInfo.PlantDic = row["USERNAME"].ToString(); |
137 |
break; |
138 |
case "SPAPLANT": |
139 |
dbInfo.Plant = row["USERNAME"].ToString(); |
140 |
break; |
141 |
case "SPPID": |
142 |
dbInfo.PlantPID = row["USERNAME"].ToString(); |
143 |
break; |
144 |
default: |
145 |
break; |
146 |
} |
147 |
bResult = true; |
148 |
} |
149 |
} |
150 |
|
151 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT PATH FROM {0}.T_ROOTITEM WHERE NAME = '{1}'", dbInfo.Site, dbInfo.Plant); |
152 |
using (OracleDataReader reader = cmd.ExecuteReader()) |
153 |
{ |
154 |
while (reader.Read()) |
155 |
{ |
156 |
dbInfo.PlantPath = reader["PATH"].ToString(); |
157 |
} |
158 |
} |
159 |
} |
160 |
} |
161 |
} |
162 |
} |
163 |
else if (dbInfo.DBType == "SQLSERVER") |
164 |
{ |
165 |
string connString = string.Format("server = {0}; uid = {1}; pwd = {2}; database = {3};", dbInfo.Service, dbInfo.DBUser, dbInfo.DBPassword, dbInfo.SQLSERVER_DBNAME); |
166 |
using (SqlConnection conn = new SqlConnection(connString)) |
167 |
{ |
168 |
conn.Open(); |
169 |
if (conn.State == ConnectionState.Open) |
170 |
{ |
171 |
using (SqlCommand cmd = new SqlCommand()) |
172 |
{ |
173 |
cmd.Connection = conn; |
174 |
|
175 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, @"SELECT SP_SCHEMA_TYPE, USERNAME, DATA_BASE |
176 |
FROM {0}.T_DB_DATA DB_DATA |
177 |
INNER JOIN {0}.T_ROOTITEM ROOTITEM ON DB_DATA.SP_ROOTITEMID = ROOTITEM.SP_ID |
178 |
WHERE ROOTITEM.NAME = '{1}'", dbInfo.Site, dbInfo.SelectedPlant); |
179 |
using (SqlDataAdapter adapter = new SqlDataAdapter()) |
180 |
{ |
181 |
DataTable dt = new DataTable(); |
182 |
adapter.SelectCommand = cmd; |
183 |
adapter.Fill(dt); |
184 |
foreach (DataColumn item in dt.Columns) |
185 |
item.ColumnName = item.ColumnName.ToUpper(); |
186 |
|
187 |
foreach (DataRow row in dt.Rows) |
188 |
{ |
189 |
string sType = row["SP_SCHEMA_TYPE"].ToString(); |
190 |
switch (sType) |
191 |
{ |
192 |
case "SPPIDDATA_DICTIONARY": |
193 |
dbInfo.PlantPIDDic = row["USERNAME"].ToString(); |
194 |
dbInfo.PlantPIDDic_DataBase = row["DATA_BASE"].ToString(); |
195 |
break; |
196 |
case "DATA_DICTIONARY": |
197 |
dbInfo.PlantDic = row["USERNAME"].ToString(); |
198 |
dbInfo.PlantDic_DataBase = row["DATA_BASE"].ToString(); |
199 |
break; |
200 |
case "SPAPLANT": |
201 |
dbInfo.Plant = row["USERNAME"].ToString(); |
202 |
dbInfo.Plant_DataBase = row["DATA_BASE"].ToString(); |
203 |
break; |
204 |
case "SPPID": |
205 |
dbInfo.PlantPID = row["USERNAME"].ToString(); |
206 |
dbInfo.PlantPID_DataBase = row["DATA_BASE"].ToString(); |
207 |
break; |
208 |
default: |
209 |
break; |
210 |
} |
211 |
bResult = true; |
212 |
} |
213 |
} |
214 |
|
215 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT PATH FROM {0}.T_ROOTITEM WHERE NAME = '{1}'", dbInfo.Site, dbInfo.SelectedPlant); |
216 |
using (SqlDataReader reader = cmd.ExecuteReader()) |
217 |
{ |
218 |
while (reader.Read()) |
219 |
{ |
220 |
dbInfo.PlantPath = reader["PATH"].ToString(); |
221 |
} |
222 |
} |
223 |
} |
224 |
} |
225 |
} |
226 |
} |
227 |
} |
228 |
catch (Exception ex) |
229 |
{ |
230 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
231 |
} |
232 |
|
233 |
return bResult; |
234 |
} |
235 |
public static List<string> GetPlantList(SPPID_DBInfo dbInfo) |
236 |
{ |
237 |
List<string> plantList = new List<string>(); |
238 |
try |
239 |
{ |
240 |
if (dbInfo.DBType == "ORACLE") |
241 |
{ |
242 |
string connString = string.Format(oracleConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
243 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
244 |
|
245 |
using (OracleConnection conn = new OracleConnection(connString)) |
246 |
{ |
247 |
conn.Open(); |
248 |
if (conn.State == System.Data.ConnectionState.Open) |
249 |
{ |
250 |
using (OracleCommand cmd = new OracleCommand()) |
251 |
{ |
252 |
cmd.Connection = conn; |
253 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT NAME, PATH FROM {0}.T_ROOTITEM", dbInfo.Site); |
254 |
|
255 |
using (OracleDataReader reader = cmd.ExecuteReader()) |
256 |
{ |
257 |
while (reader.Read()) |
258 |
{ |
259 |
plantList.Add(reader["NAME"].ToString()); |
260 |
} |
261 |
} |
262 |
} |
263 |
} |
264 |
} |
265 |
} |
266 |
else if (dbInfo.DBType == "SQLSERVER") |
267 |
{ |
268 |
string connString = string.Format("server = {0}; uid = {1}; pwd = {2}; database = {3};", dbInfo.Service, dbInfo.DBUser, dbInfo.DBPassword, dbInfo.SQLSERVER_DBNAME); |
269 |
using (SqlConnection conn = new SqlConnection(connString)) |
270 |
{ |
271 |
conn.Open(); |
272 |
if (conn.State == ConnectionState.Open) |
273 |
{ |
274 |
using (SqlCommand cmd = new SqlCommand()) |
275 |
{ |
276 |
cmd.Connection = conn; |
277 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT NAME, PATH FROM {0}.T_ROOTITEM", dbInfo.Site); |
278 |
|
279 |
using (SqlDataReader reader = cmd.ExecuteReader()) |
280 |
{ |
281 |
while (reader.Read()) |
282 |
{ |
283 |
plantList.Add(reader["NAME"].ToString()); |
284 |
} |
285 |
} |
286 |
} |
287 |
|
288 |
} |
289 |
} |
290 |
} |
291 |
} |
292 |
catch (Exception ex) |
293 |
{ |
294 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
295 |
} |
296 |
|
297 |
return plantList; |
298 |
} |
299 |
|
300 |
public static DataTable GetSPPIDCodeList() |
301 |
{ |
302 |
List<string> attributes = new List<string>(); |
303 |
SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
304 |
DataTable dt = null; |
305 |
string connString = string.Empty; |
306 |
try |
307 |
{ |
308 |
if (dbInfo.DBType == "ORACLE") |
309 |
{ |
310 |
connString = string.Format(oracleConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
311 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
312 |
|
313 |
using (OracleConnection conn = new OracleConnection(connString)) |
314 |
{ |
315 |
conn.Open(); |
316 |
if (conn.State == System.Data.ConnectionState.Open) |
317 |
{ |
318 |
string sQuery = string.Format(CultureInfo.CurrentCulture, |
319 |
@"SELECT attribute_name, attribute_datatype FROM {0}.attributes WHERE attribute_codelisted = 'T'" |
320 |
, dbInfo.PlantPIDDic); |
321 |
using (OracleCommand cmd = new OracleCommand(sQuery, conn)) |
322 |
using (OracleDataAdapter adapter = new OracleDataAdapter()) |
323 |
{ |
324 |
adapter.SelectCommand = cmd; |
325 |
dt = new DataTable(); |
326 |
adapter.Fill(dt); |
327 |
foreach (DataColumn item in dt.Columns) |
328 |
item.ColumnName = item.ColumnName.ToUpper(); |
329 |
} |
330 |
} |
331 |
} |
332 |
} |
333 |
else if (dbInfo.DBType == "SQLSERVER") |
334 |
{ |
335 |
connString = string.Format("server = {0}; uid = {1}; pwd = {2}; database = {3};", dbInfo.Service, dbInfo.DBUser, dbInfo.DBPassword, dbInfo.PlantPIDDic_DataBase); |
336 |
using (SqlConnection conn = new SqlConnection(connString)) |
337 |
{ |
338 |
conn.Open(); |
339 |
if (conn.State == ConnectionState.Open) |
340 |
{ |
341 |
string sQuery = string.Format(CultureInfo.CurrentCulture, |
342 |
@"SELECT attribute_name, attribute_datatype FROM {0}.attributes WHERE attribute_codelisted = 'T'" |
343 |
, dbInfo.PlantPIDDic); |
344 |
using (SqlCommand cmd = new SqlCommand(sQuery, conn)) |
345 |
using (SqlDataAdapter adapter = new SqlDataAdapter()) |
346 |
{ |
347 |
adapter.SelectCommand = cmd; |
348 |
dt = new DataTable(); |
349 |
adapter.Fill(dt); |
350 |
foreach (DataColumn item in dt.Columns) |
351 |
item.ColumnName = item.ColumnName.ToUpper(); |
352 |
} |
353 |
} |
354 |
} |
355 |
} |
356 |
|
357 |
} |
358 |
catch (Exception ex) |
359 |
{ |
360 |
System.Windows.Forms.MessageBox.Show("Connection String : " + connString + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); |
361 |
} |
362 |
|
363 |
return dt; |
364 |
} |
365 |
public static DataTable GetSPPIDAttribute() |
366 |
{ |
367 |
List<string> attributes = new List<string>(); |
368 |
SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
369 |
DataTable dt = null; |
370 |
string connString = string.Empty; |
371 |
try |
372 |
{ |
373 |
if (dbInfo.DBType == "ORACLE") |
374 |
{ |
375 |
connString = string.Format(oracleConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
376 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
377 |
|
378 |
using (OracleConnection conn = new OracleConnection(connString)) |
379 |
{ |
380 |
conn.Open(); |
381 |
if (conn.State == System.Data.ConnectionState.Open) |
382 |
{ |
383 |
string sQuery = string.Format(CultureInfo.CurrentCulture, |
384 |
@"SELECT ITEM.description ItemType ,ATTR.displayname, ATTR.name FROM {0}.itemattributions ATTR |
385 |
LEFT OUTER JOIN {0}.item ITEM |
386 |
ON ITEM.ID = ATTR.ITEMID |
387 |
ORDER BY ATTR.displayname ASC", dbInfo.PlantPIDDic); |
388 |
//string sQuery = string.Format(CultureInfo.CurrentCulture, |
389 |
// @"SELECT DISTINCT(ATTR.displayname), ATTR.name FROM {0}.itemattributions ATTR |
390 |
// ORDER BY ATTR.displayname ASC", dbInfo.PlantPIDDic); |
391 |
using (OracleCommand cmd = new OracleCommand(sQuery, conn)) |
392 |
using (OracleDataAdapter adapter = new OracleDataAdapter()) |
393 |
{ |
394 |
adapter.SelectCommand = cmd; |
395 |
dt = new DataTable(); |
396 |
adapter.Fill(dt); |
397 |
foreach (DataColumn item in dt.Columns) |
398 |
item.ColumnName = item.ColumnName.ToUpper(); |
399 |
} |
400 |
} |
401 |
} |
402 |
} |
403 |
else if (dbInfo.DBType == "SQLSERVER") |
404 |
{ |
405 |
connString = string.Format("server = {0}; uid = {1}; pwd = {2}; database = {3};", dbInfo.Service, dbInfo.DBUser, dbInfo.DBPassword, dbInfo.PlantPIDDic_DataBase); |
406 |
using (SqlConnection conn = new SqlConnection(connString)) |
407 |
{ |
408 |
conn.Open(); |
409 |
if (conn.State == ConnectionState.Open) |
410 |
{ |
411 |
string sQuery = string.Format(CultureInfo.CurrentCulture, |
412 |
@"SELECT ITEM.description ItemType ,ATTR.displayname, ATTR.name FROM {0}.itemattributions ATTR |
413 |
LEFT OUTER JOIN {0}.item ITEM |
414 |
ON ITEM.ID = ATTR.ITEMID |
415 |
ORDER BY ATTR.displayname ASC", dbInfo.PlantPIDDic); |
416 |
//string sQuery = string.Format(CultureInfo.CurrentCulture, |
417 |
// @"SELECT DISTINCT(ATTR.displayname), ATTR.name FROM {0}.itemattributions ATTR |
418 |
// ORDER BY ATTR.displayname ASC", dbInfo.PlantPIDDic); |
419 |
using (SqlCommand cmd = new SqlCommand(sQuery, conn)) |
420 |
using (SqlDataAdapter adapter = new SqlDataAdapter()) |
421 |
{ |
422 |
adapter.SelectCommand = cmd; |
423 |
dt = new DataTable(); |
424 |
adapter.Fill(dt); |
425 |
foreach (DataColumn item in dt.Columns) |
426 |
item.ColumnName = item.ColumnName.ToUpper(); |
427 |
} |
428 |
} |
429 |
} |
430 |
} |
431 |
|
432 |
} |
433 |
catch (Exception ex) |
434 |
{ |
435 |
System.Windows.Forms.MessageBox.Show("Connection String : " + connString + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); |
436 |
} |
437 |
|
438 |
return dt; |
439 |
} |
440 |
public static DataTable GetFluidSystemInfo(string operFluidCode) |
441 |
{ |
442 |
List<string> attributes = new List<string>(); |
443 |
SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
444 |
DataTable dt = null; |
445 |
try |
446 |
{ |
447 |
if (dbInfo.DBType == "ORACLE") |
448 |
{ |
449 |
string connString = string.Format(oracleConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
450 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
451 |
|
452 |
using (OracleConnection conn = new OracleConnection(connString)) |
453 |
{ |
454 |
conn.Open(); |
455 |
if (conn.State == System.Data.ConnectionState.Open) |
456 |
{ |
457 |
string sQuery = string.Format(CultureInfo.CurrentCulture, |
458 |
@"SELECT * FROM {0}.CODELISTS OUTATTR |
459 |
WHERE OUTATTR.codelist_index = |
460 |
(SELECT attr.codelist_constraint FROM {0}.CODELISTS ATTR WHERE ATTR.CODELIST_TEXT = '{1}' AND ATTR.CODELIST_NUMBER = 19) AND OUTATTR.CODELIST_NUMBER = 20", dbInfo.PlantPIDDic, operFluidCode); |
461 |
using (OracleCommand cmd = new OracleCommand(sQuery, conn)) |
462 |
using (OracleDataAdapter adapter = new OracleDataAdapter()) |
463 |
{ |
464 |
adapter.SelectCommand = cmd; |
465 |
dt = new DataTable(); |
466 |
adapter.Fill(dt); |
467 |
foreach (DataColumn item in dt.Columns) |
468 |
item.ColumnName = item.ColumnName.ToUpper(); |
469 |
} |
470 |
} |
471 |
} |
472 |
} |
473 |
else if (dbInfo.DBType == "SQLSERVER") |
474 |
{ |
475 |
string connString = string.Format("server = {0}; uid = {1}; pwd = {2}; database = {3};", dbInfo.Service, dbInfo.DBUser, dbInfo.DBPassword, dbInfo.PlantPIDDic_DataBase); |
476 |
using (SqlConnection conn = new SqlConnection(connString)) |
477 |
{ |
478 |
conn.Open(); |
479 |
if (conn.State == ConnectionState.Open) |
480 |
{ |
481 |
string sQuery = string.Format(CultureInfo.CurrentCulture, |
482 |
@"SELECT * FROM {0}.CODELISTS OUTATTR |
483 |
WHERE OUTATTR.codelist_index = |
484 |
(SELECT attr.codelist_constraint FROM {0}.CODELISTS ATTR WHERE ATTR.CODELIST_TEXT = '{1}' AND ATTR.CODELIST_NUMBER = 19) AND OUTATTR.CODELIST_NUMBER = 20", dbInfo.PlantPIDDic, operFluidCode); |
485 |
using (SqlCommand cmd = new SqlCommand(sQuery, conn)) |
486 |
using (SqlDataAdapter adapter = new SqlDataAdapter()) |
487 |
{ |
488 |
adapter.SelectCommand = cmd; |
489 |
dt = new DataTable(); |
490 |
adapter.Fill(dt); |
491 |
foreach (DataColumn item in dt.Columns) |
492 |
item.ColumnName = item.ColumnName.ToUpper(); |
493 |
} |
494 |
} |
495 |
} |
496 |
} |
497 |
} |
498 |
catch (Exception ex) |
499 |
{ |
500 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
501 |
} |
502 |
|
503 |
return dt; |
504 |
} |
505 |
|
506 |
|
507 |
public static DataTable GetPipeRunProperties(bool isBrief = false, bool isCase = false) |
508 |
{ |
509 |
SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
510 |
DataTable dt = null; |
511 |
try |
512 |
{ |
513 |
if (dbInfo.DBType == "ORACLE") |
514 |
{ |
515 |
string connString = string.Format(oracleConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
516 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
517 |
|
518 |
using (OracleConnection conn = new OracleConnection(connString)) |
519 |
{ |
520 |
conn.Open(); |
521 |
if (conn.State == System.Data.ConnectionState.Open) |
522 |
{ |
523 |
string sQuery = string.Empty; |
524 |
if (isBrief) |
525 |
{ |
526 |
sQuery = string.Format(CultureInfo.CurrentCulture, |
527 |
@"SELECT ia.DISPLAYNAME, ia.NAME, ea.DATATYPE, ea.TABLENAME |
528 |
FROM {0}.ITEMATTRIBUTIONS ia |
529 |
INNER JOIN {0}.ITEM I |
530 |
ON i.ID = ia.ITEMID |
531 |
LEFT JOIN |
532 |
(SELECT sa.ATTRIBUTEID |
533 |
, sv.ITEMTYPE |
534 |
, sl.NAME AS LAYOUTNAME |
535 |
, sl.APPUSAGE AS LAYOUTAPPUSAGE |
536 |
, sa.COLUMNNAME |
537 |
, sv.DEFAULTFILTER |
538 |
, sv.DEFAULTLAYOUT |
539 |
FROM {0}.SPTPATTRIBUTES sa |
540 |
INNER JOIN {0}.SPTPLAYOUTS sl |
541 |
ON sl.ID = sa.SPTPLAYOUTS_ID |
542 |
INNER JOIN {0}.SPTPVIEWS sv |
543 |
ON sl.SPTPVIEWS_ID = sv.ID |
544 |
) sp |
545 |
ON ia.ID = sp.ATTRIBUTEID |
546 |
LEFT JOIN |
547 |
(SELECT ua.ID |
548 |
, e.ENTITY_NUMBER |
549 |
, e.ENTITY_NAME AS TABLENAME |
550 |
, ca.CODELIST_TEXT |
551 |
, ca.CODELIST_SORT_VALUE |
552 |
, a.ATTRIBUTE_DATATYPE AS DATATYPE |
553 |
FROM {0}.ENTITIES e |
554 |
INNER JOIN {0}.UNIQUEATTS ua |
555 |
ON ua.ENTITY_NUMBER = e.ENTITY_NUMBER |
556 |
INNER join {0}.CODELISTS ca |
557 |
ON ua.CATEGORY = ca.CODELIST_INDEX |
558 |
and ca.CODELIST_NUMBER = 55 |
559 |
INNER JOIN {0}.ATTRIBUTES a |
560 |
ON a.ATTRIBUTE_NUMBER = ua.ATTRIBUTE_NUMBER |
561 |
and ua.CATEGORY <> 100 |
562 |
) ea |
563 |
ON ea.ID = ia.ATTRIBUTIONID |
564 |
WHERE 1 = 1 |
565 |
AND((i.NAME = 'PipeRun' AND sp.LAYOUTAPPUSAGE IN(1, 3)) OR i.NAME = 'PlantItem') |
566 |
AND sp.DEFAULTLAYOUT = 279 |
567 |
ORDER BY ia.DISPLAYNAME", dbInfo.PlantPIDDic); |
568 |
} |
569 |
else |
570 |
{ |
571 |
sQuery = string.Format(CultureInfo.CurrentCulture, |
572 |
@"SELECT DISTINCT ia.DISPLAYNAME, ia.NAME, ea.DATATYPE, ea.TABLENAME |
573 |
FROM {0}.ITEMATTRIBUTIONS ia |
574 |
INNER JOIN {0}.ITEM I |
575 |
ON i.ID = ia.ITEMID |
576 |
LEFT JOIN |
577 |
(SELECT ua.ID |
578 |
, e.ENTITY_NUMBER |
579 |
, e.ENTITY_NAME |
580 |
, e.ENTITY_NAME AS TABLENAME |
581 |
, ca.CODELIST_TEXT |
582 |
, ca.CODELIST_SORT_VALUE |
583 |
, a.ATTRIBUTE_DATATYPE AS DATATYPE |
584 |
, a.ATTRIBUTE_NAME |
585 |
, ua.DISPLAY |
586 |
FROM {0}.ENTITIES e |
587 |
INNER JOIN {0}.UNIQUEATTS ua |
588 |
ON ua.ENTITY_NUMBER = e.ENTITY_NUMBER |
589 |
INNER JOIN {0}.ATTRIBUTES a |
590 |
ON a.ATTRIBUTE_NUMBER = ua.ATTRIBUTE_NUMBER |
591 |
LEFT join {0}.CODELISTS ca |
592 |
ON ua.CATEGORY = ca.CODELIST_INDEX |
593 |
and ca.CODELIST_NUMBER = 55 |
594 |
) ea |
595 |
ON ea.ID = ia.ATTRIBUTIONID |
596 |
WHERE 1 = 1 |
597 |
AND ia.NAME NOT LIKE('Case.%') |
598 |
AND ea.ENTITY_NAME NOT IN('T_PlantItemGroup') |
599 |
and instr(ia.NAME, 'SP_RoomID') = 0 |
600 |
and(ia.DISPLAYNAME not like 'Parent%' or ia.DISPLAYNAME = 'Parent Item') |
601 |
AND ia.DISPLAYNAME not like 'PartOfPlant%' |
602 |
AND ia.DISPLAYNAME not like '%Design Basis UID%' |
603 |
AND ia.NAME not like 'Room.%' |
604 |
AND ia.NAME not like '%HydraulicCircuit.%' |
605 |
AND (ia.NAME = 'ContractPackage.ItemTag' or ia.NAME not like '%Package.%') |
606 |
AND ia.NAME not like '%System.%' |
607 |
AND ia.NAME not like '%TestSystem.%' |
608 |
AND ia.NAME not like '%InstrLoop.%' |
609 |
AND ia.NAME not like '%DuctRun.%' |
610 |
AND ia.NAME not like '%InlineComp.PipeRun.%' |
611 |
AND ia.NAME not like '%PartOfPlantItem.%' |
612 |
AND ia.NAME not like '%SafetyClass.%' |
613 |
AND ia.NAME not in ('PipingPoint1.Description', 'PipingPoint2.Description', 'PipingPoint3.Description', 'PipingPoint4.Description') |
614 |
AND not(ia.NAME not like 'PipingPoint%' and ia.DISPLAYNAME like 'End %' ) |
615 |
AND ia.DISPLAYNAME not like 'J_%' |
616 |
AND (ia.DISPLAYNAME not like 'Loop %' or ia.DISPLAYNAME in ('Loop ItemTag', 'Loop Tag', 'Loop No')) |
617 |
AND not(i.NAME in ('PlantItem', 'ModelItem') and(ia.DISPLAYNAME like 'Pipe %' or ia.DISPLAYNAME like 'Sig%' or ia.DISPLAYNAME like 'Sys %' or ia.DISPLAYNAME like 'System %')) |
618 |
AND not(i.NAME = 'Status' and (ia.DISPLAYNAME like 'Duct Hold %' or ia.DISPLAYNAME like 'Duct Parent %' or ia.DISPLAYNAME like 'Inline Comp %' or ia.DISPLAYNAME like 'Inline Comp %' |
619 |
OR ia.DISPLAYNAME like 'Pipe Hold %' or ia.DISPLAYNAME like 'Pipe Parent %' or ia.DISPLAYNAME like 'Signal Run %' )) |
620 |
AND ea.ATTRIBUTE_NAME <> 'UpdateCount' |
621 |
AND ea.DISPLAY = 'T' |
622 |
AND not(i.NAME<> 'PipeRun' and ea.ATTRIBUTE_NAME = 'aabbcc_code') |
623 |
AND not(i.NAME = 'PipeRun' and ea.ATTRIBUTE_NAME = 'SP_ID') |
624 |
AND i.NAME IN('PipeRun', 'PlantItem','ModelItem', 'Representation', 'Case','CaseProcess', 'CaseControl', 'Status') |
625 |
{1} order by TRIM(ia.DISPLAYNAME)", dbInfo.PlantPIDDic, isCase ? "" : " AND ea.ENTITY_NAME NOT IN ('T_Case', 'T_CaseProcess', 'T_CaseControl', 'T_Status') "); |
626 |
} |
627 |
using (OracleCommand cmd = new OracleCommand(sQuery, conn)) |
628 |
using (OracleDataAdapter adapter = new OracleDataAdapter()) |
629 |
{ |
630 |
adapter.SelectCommand = cmd; |
631 |
dt = new DataTable(); |
632 |
adapter.Fill(dt); |
633 |
foreach (DataColumn item in dt.Columns) |
634 |
item.ColumnName = item.ColumnName.ToUpper(); |
635 |
} |
636 |
} |
637 |
} |
638 |
} |
639 |
else if (dbInfo.DBType == "SQLSERVER") |
640 |
{ |
641 |
string connString = string.Format("server = {0}; uid = {1}; pwd = {2}; database = {3};", dbInfo.Service, dbInfo.DBUser, dbInfo.DBPassword, dbInfo.PlantPIDDic_DataBase); |
642 |
using (SqlConnection conn = new SqlConnection(connString)) |
643 |
{ |
644 |
conn.Open(); |
645 |
if (conn.State == ConnectionState.Open) |
646 |
{ |
647 |
string sQuery = string.Empty; |
648 |
if (isBrief) |
649 |
{ |
650 |
sQuery = string.Format(CultureInfo.CurrentCulture, |
651 |
@"SELECT ia.DISPLAYNAME, ia.NAME, ea.DATATYPE, ea.TABLENAME |
652 |
FROM {0}.ITEMATTRIBUTIONS ia |
653 |
INNER JOIN {0}.ITEM I |
654 |
ON i.ID = ia.ITEMID |
655 |
LEFT JOIN |
656 |
(SELECT sa.ATTRIBUTEID |
657 |
, sv.ITEMTYPE |
658 |
, sl.NAME AS LAYOUTNAME |
659 |
, sl.APPUSAGE AS LAYOUTAPPUSAGE |
660 |
, sa.COLUMNNAME |
661 |
, sv.DEFAULTFILTER |
662 |
, sv.DEFAULTLAYOUT |
663 |
FROM {0}.SPTPATTRIBUTES sa |
664 |
INNER JOIN {0}.SPTPLAYOUTS sl |
665 |
ON sl.ID = sa.SPTPLAYOUTS_ID |
666 |
INNER JOIN {0}.SPTPVIEWS sv |
667 |
ON sl.SPTPVIEWS_ID = sv.ID |
668 |
) sp |
669 |
ON ia.ID = sp.ATTRIBUTEID |
670 |
LEFT JOIN |
671 |
(SELECT ua.ID |
672 |
, e.ENTITY_NUMBER |
673 |
, e.ENTITY_NAME AS TABLENAME |
674 |
, ca.CODELIST_TEXT |
675 |
, ca.CODELIST_SORT_VALUE |
676 |
, a.ATTRIBUTE_DATATYPE AS DATATYPE |
677 |
FROM {0}.ENTITIES e |
678 |
INNER JOIN {0}.UNIQUEATTS ua |
679 |
ON ua.ENTITY_NUMBER = e.ENTITY_NUMBER |
680 |
INNER join {0}.CODELISTS ca |
681 |
ON ua.CATEGORY = ca.CODELIST_INDEX |
682 |
and ca.CODELIST_NUMBER = 55 |
683 |
INNER JOIN {0}.ATTRIBUTES a |
684 |
ON a.ATTRIBUTE_NUMBER = ua.ATTRIBUTE_NUMBER |
685 |
and ua.CATEGORY <> 100 |
686 |
) ea |
687 |
ON ea.ID = ia.ATTRIBUTIONID |
688 |
WHERE 1 = 1 |
689 |
AND((i.NAME = 'PipeRun' AND sp.LAYOUTAPPUSAGE IN(1, 3)) OR i.NAME = 'PlantItem') |
690 |
AND sp.DEFAULTLAYOUT = 279 |
691 |
ORDER BY ia.DISPLAYNAME", dbInfo.PlantPIDDic); |
692 |
} |
693 |
else |
694 |
{ |
695 |
sQuery = string.Format(CultureInfo.CurrentCulture, |
696 |
@"SELECT DISTINCT ia.DISPLAYNAME, ia.NAME, ea.DATATYPE, ea.TABLENAME |
697 |
FROM {0}.ITEMATTRIBUTIONS ia |
698 |
INNER JOIN {0}.ITEM I |
699 |
ON i.ID = ia.ITEMID |
700 |
LEFT JOIN |
701 |
(SELECT ua.ID |
702 |
, e.ENTITY_NUMBER |
703 |
, e.ENTITY_NAME |
704 |
, e.ENTITY_NAME AS TABLENAME |
705 |
, ca.CODELIST_TEXT |
706 |
, ca.CODELIST_SORT_VALUE |
707 |
, a.ATTRIBUTE_DATATYPE AS DATATYPE |
708 |
, a.ATTRIBUTE_NAME |
709 |
, ua.DISPLAY |
710 |
FROM {0}.ENTITIES e |
711 |
INNER JOIN {0}.UNIQUEATTS ua |
712 |
ON ua.ENTITY_NUMBER = e.ENTITY_NUMBER |
713 |
INNER JOIN {0}.ATTRIBUTES a |
714 |
ON a.ATTRIBUTE_NUMBER = ua.ATTRIBUTE_NUMBER |
715 |
LEFT join {0}.CODELISTS ca |
716 |
ON ua.CATEGORY = ca.CODELIST_INDEX |
717 |
and ca.CODELIST_NUMBER = 55 |
718 |
) ea |
719 |
ON ea.ID = ia.ATTRIBUTIONID |
720 |
WHERE 1 = 1 |
721 |
AND ia.NAME NOT LIKE('Case.%') |
722 |
AND ea.ENTITY_NAME NOT IN('T_PlantItemGroup') |
723 |
AND (ia.NAME not like 'SP_RoomID%' ) |
724 |
AND (ia.DISPLAYNAME not like 'Parent%' or ia.DISPLAYNAME = 'Parent Item') |
725 |
AND ia.DISPLAYNAME not like 'PartOfPlant%' |
726 |
AND ia.DISPLAYNAME not like '%Design Basis UID%' |
727 |
AND ia.NAME not like 'Room.%' |
728 |
AND ia.NAME not like '%HydraulicCircuit.%' |
729 |
AND(ia.NAME = 'ContractPackage.ItemTag' or ia.NAME not like '%Package.%') |
730 |
AND ia.NAME not like '%System.%' |
731 |
AND ia.NAME not like '%TestSystem.%' |
732 |
AND ia.NAME not like '%InstrLoop.%' |
733 |
AND ia.NAME not like '%DuctRun.%' |
734 |
AND ia.NAME not like '%InlineComp.PipeRun.%' |
735 |
AND ia.NAME not like '%PartOfPlantItem.%' |
736 |
AND ia.NAME not like '%SafetyClass.%' |
737 |
AND ia.NAME not in ('PipingPoint1.Description', 'PipingPoint2.Description', 'PipingPoint3.Description', 'PipingPoint4.Description') |
738 |
AND not(ia.NAME not like 'PipingPoint%' and ia.DISPLAYNAME like 'End %' ) |
739 |
AND ia.DISPLAYNAME not like 'J_%' |
740 |
AND (ia.DISPLAYNAME not like 'Loop %' or ia.DISPLAYNAME in ('Loop ItemTag', 'Loop Tag', 'Loop No')) |
741 |
and not(i.NAME in ('PlantItem', 'ModelItem') and(ia.DISPLAYNAME like 'Pipe %' or ia.DISPLAYNAME like 'Sig%' or ia.DISPLAYNAME like 'Sys %' or ia.DISPLAYNAME like 'System %')) |
742 |
AND not(i.NAME = 'Status' and (ia.DISPLAYNAME like 'Duct Hold %' or ia.DISPLAYNAME like 'Duct Parent %' or ia.DISPLAYNAME like 'Inline Comp %' or ia.DISPLAYNAME like 'Inline Comp %' |
743 |
OR ia.DISPLAYNAME like 'Pipe Hold %' or ia.DISPLAYNAME like 'Pipe Parent %' or ia.DISPLAYNAME like 'Signal Run %' )) |
744 |
AND ea.ATTRIBUTE_NAME <> 'UpdateCount' |
745 |
AND ea.DISPLAY = 'T' |
746 |
AND not(i.NAME<> 'PipeRun' and ea.ATTRIBUTE_NAME = 'aabbcc_code') |
747 |
AND not(i.NAME = 'PipeRun' and ea.ATTRIBUTE_NAME = 'SP_ID') |
748 |
AND i.NAME IN('PipeRun', 'PlantItem','ModelItem', 'Representation', 'Case','CaseProcess', 'CaseControl', 'Status') |
749 |
{1} order by ia.DISPLAYNAME", dbInfo.PlantPIDDic, isCase ? "" : " AND ea.ENTITY_NAME NOT IN ('T_Case', 'T_CaseProcess', 'T_CaseControl', 'T_Status') "); |
750 |
} |
751 |
using (SqlCommand cmd = new SqlCommand(sQuery, conn)) |
752 |
using (SqlDataAdapter adapter = new SqlDataAdapter()) |
753 |
{ |
754 |
adapter.SelectCommand = cmd; |
755 |
dt = new DataTable(); |
756 |
adapter.Fill(dt); |
757 |
foreach (DataColumn item in dt.Columns) |
758 |
item.ColumnName = item.ColumnName.ToUpper(); |
759 |
} |
760 |
} |
761 |
} |
762 |
} |
763 |
if (dt != null && dt.Rows.Count > 0) |
764 |
{ |
765 |
DataRow dr = dt.NewRow(); |
766 |
dt.Rows.InsertAt(dr, 0); |
767 |
} |
768 |
} |
769 |
catch (Exception ex) |
770 |
{ |
771 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
772 |
} |
773 |
|
774 |
return dt; |
775 |
} |
776 |
} |
777 |
} |