hytos / DTI_PID / SPPIDConverter / DB / SPPID_DB.cs @ 289e9573
이력 | 보기 | 이력해설 | 다운로드 (19.9 KB)
1 | 23eb98bf | gaqhf | 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 | |||
11 | b8e2644e | gaqhf | namespace Converter.SPPID.DB |
12 | 23eb98bf | gaqhf | { |
13 | 2e1e3c12 | gaqhf | public class SPPID_DB |
14 | 23eb98bf | gaqhf | { |
15 | private const string oConnString = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST ={0}" + @")(PORT = {1}))(CONNECT_DATA = (SERVICE_NAME = {2})))"; |
||
16 | |||
17 | fab4f207 | gaqhf | public static bool CheckAndSetSPPIDInfo(SPPID_DBInfo dbInfo) |
18 | 23eb98bf | gaqhf | { |
19 | bool bResult = false; |
||
20 | try |
||
21 | { |
||
22 | if (dbInfo.DBType == "ORACLE") |
||
23 | { |
||
24 | string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
||
25 | connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
||
26 | |||
27 | using (OracleConnection conn = new OracleConnection(connString)) |
||
28 | { |
||
29 | conn.Open(); |
||
30 | if (conn.State == System.Data.ConnectionState.Open) |
||
31 | { |
||
32 | using (OracleCommand cmd = new OracleCommand()) |
||
33 | { |
||
34 | cmd.Connection = conn; |
||
35 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT NAME, PATH FROM {0}.T_ROOTITEM", dbInfo.Site); |
||
36 | |||
37 | using (OracleDataReader reader = cmd.ExecuteReader()) |
||
38 | { |
||
39 | while (reader.Read()) |
||
40 | { |
||
41 | dbInfo.Plant = reader["NAME"].ToString(); |
||
42 | dbInfo.PlantPath = reader["PATH"].ToString(); |
||
43 | } |
||
44 | |||
45 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, @"SELECT SP_SCHEMA_TYPE, USERNAME |
||
46 | FROM {0}.T_DB_DATA DB_DATA |
||
47 | INNER JOIN {0}.T_ROOTITEM ROOTITEM ON DB_DATA.SP_ROOTITEMID = ROOTITEM.SP_ID |
||
48 | WHERE ROOTITEM.NAME = '{1}'", dbInfo.Site, dbInfo.Plant); |
||
49 | |||
50 | |||
51 | using (OracleDataAdapter adapter = new OracleDataAdapter()) |
||
52 | { |
||
53 | DataTable dt = new DataTable(); |
||
54 | adapter.SelectCommand = cmd; |
||
55 | adapter.Fill(dt); |
||
56 | |||
57 | foreach (DataRow row in dt.Rows) |
||
58 | { |
||
59 | string sType = row["SP_SCHEMA_TYPE"].ToString(); |
||
60 | switch (sType) |
||
61 | { |
||
62 | case "SPPIDDATA_DICTIONARY": |
||
63 | dbInfo.PlantPIDDic = row["USERNAME"].ToString(); |
||
64 | break; |
||
65 | case "DATA_DICTIONARY": |
||
66 | dbInfo.PlantDic = row["USERNAME"].ToString(); |
||
67 | break; |
||
68 | case "SPAPLANT": |
||
69 | dbInfo.Plant = row["USERNAME"].ToString(); |
||
70 | break; |
||
71 | case "SPPID": |
||
72 | dbInfo.PlantPID = row["USERNAME"].ToString(); |
||
73 | break; |
||
74 | default: |
||
75 | break; |
||
76 | } |
||
77 | } |
||
78 | bResult = true; |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | else |
||
86 | { |
||
87 | |||
88 | } |
||
89 | } |
||
90 | catch (Exception ex) |
||
91 | { |
||
92 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
93 | 23eb98bf | gaqhf | } |
94 | |||
95 | return bResult; |
||
96 | } |
||
97 | |||
98 | fab4f207 | gaqhf | public static bool SetPlantDBSetting(SPPID_DBInfo dbInfo) |
99 | 23eb98bf | gaqhf | { |
100 | bool bResult = false; |
||
101 | try |
||
102 | { |
||
103 | if (dbInfo.DBType == "ORACLE") |
||
104 | { |
||
105 | string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
||
106 | connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
||
107 | |||
108 | using (OracleConnection conn = new OracleConnection(connString)) |
||
109 | { |
||
110 | conn.Open(); |
||
111 | if (conn.State == System.Data.ConnectionState.Open) |
||
112 | { |
||
113 | using (OracleCommand cmd = new OracleCommand()) |
||
114 | { |
||
115 | cmd.Connection = conn; |
||
116 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, @"SELECT SP_SCHEMA_TYPE, USERNAME |
||
117 | FROM {0}.T_DB_DATA DB_DATA |
||
118 | INNER JOIN {0}.T_ROOTITEM ROOTITEM ON DB_DATA.SP_ROOTITEMID = ROOTITEM.SP_ID |
||
119 | WHERE ROOTITEM.NAME = '{1}'", dbInfo.Site, dbInfo.SelectedPlant); |
||
120 | using (OracleDataAdapter adapter = new OracleDataAdapter()) |
||
121 | { |
||
122 | DataTable dt = new DataTable(); |
||
123 | adapter.SelectCommand = cmd; |
||
124 | adapter.Fill(dt); |
||
125 | |||
126 | foreach (DataRow row in dt.Rows) |
||
127 | { |
||
128 | string sType = row["SP_SCHEMA_TYPE"].ToString(); |
||
129 | switch (sType) |
||
130 | { |
||
131 | case "SPPIDDATA_DICTIONARY": |
||
132 | dbInfo.PlantPIDDic = row["USERNAME"].ToString(); |
||
133 | break; |
||
134 | case "DATA_DICTIONARY": |
||
135 | dbInfo.PlantDic = row["USERNAME"].ToString(); |
||
136 | break; |
||
137 | case "SPAPLANT": |
||
138 | dbInfo.Plant = row["USERNAME"].ToString(); |
||
139 | break; |
||
140 | case "SPPID": |
||
141 | dbInfo.PlantPID = row["USERNAME"].ToString(); |
||
142 | break; |
||
143 | default: |
||
144 | break; |
||
145 | } |
||
146 | bResult = true; |
||
147 | } |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | else |
||
154 | { |
||
155 | |||
156 | } |
||
157 | } |
||
158 | catch (Exception ex) |
||
159 | { |
||
160 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
161 | 23eb98bf | gaqhf | } |
162 | |||
163 | return bResult; |
||
164 | } |
||
165 | |||
166 | fab4f207 | gaqhf | public static List<string> GetPlantList(SPPID_DBInfo dbInfo) |
167 | 23eb98bf | gaqhf | { |
168 | List<string> plantList = new List<string>(); |
||
169 | try |
||
170 | { |
||
171 | if (dbInfo.DBType == "ORACLE") |
||
172 | { |
||
173 | string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
||
174 | connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
||
175 | |||
176 | using (OracleConnection conn = new OracleConnection(connString)) |
||
177 | { |
||
178 | conn.Open(); |
||
179 | if (conn.State == System.Data.ConnectionState.Open) |
||
180 | { |
||
181 | using (OracleCommand cmd = new OracleCommand()) |
||
182 | { |
||
183 | cmd.Connection = conn; |
||
184 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT NAME, PATH FROM {0}.T_ROOTITEM", dbInfo.Site); |
||
185 | |||
186 | using (OracleDataReader reader = cmd.ExecuteReader()) |
||
187 | { |
||
188 | while (reader.Read()) |
||
189 | { |
||
190 | plantList.Add(reader["NAME"].ToString()); |
||
191 | } |
||
192 | } |
||
193 | } |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | else |
||
198 | { |
||
199 | |||
200 | } |
||
201 | } |
||
202 | catch (Exception ex) |
||
203 | { |
||
204 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
205 | 23eb98bf | gaqhf | } |
206 | |||
207 | return plantList; |
||
208 | } |
||
209 | |||
210 | public static DataTable GetUnitTree() |
||
211 | { |
||
212 | DataTable dt = new DataTable(); |
||
213 | try |
||
214 | { |
||
215 | 2e1e3c12 | gaqhf | SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
216 | 23eb98bf | gaqhf | |
217 | if (dbInfo.DBType == "ORACLE") |
||
218 | { |
||
219 | string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
||
220 | connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
||
221 | |||
222 | using (OracleConnection conn = new OracleConnection(connString)) |
||
223 | { |
||
224 | conn.Open(); |
||
225 | if (conn.State == System.Data.ConnectionState.Open) |
||
226 | { |
||
227 | string sQuery = string.Format(CultureInfo.CurrentCulture, |
||
228 | @"SELECT SP_ID, PARENTID, NAME |
||
229 | FROM {0}.T_PLANTGROUP |
||
230 | START WITH PARENTID='-1' |
||
231 | CONNECT BY PRIOR SP_ID=PARENTID", dbInfo.Plant); |
||
232 | |||
233 | using (OracleCommand cmd = new OracleCommand(sQuery, conn)) |
||
234 | using (OracleDataAdapter adapter = new OracleDataAdapter()) |
||
235 | { |
||
236 | adapter.SelectCommand = cmd; |
||
237 | adapter.Fill(dt); |
||
238 | } |
||
239 | } |
||
240 | } |
||
241 | } |
||
242 | else |
||
243 | { |
||
244 | |||
245 | } |
||
246 | } |
||
247 | catch (Exception ex) |
||
248 | { |
||
249 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
250 | 23eb98bf | gaqhf | } |
251 | |||
252 | return dt; |
||
253 | } |
||
254 | |||
255 | public static string GetPlantPID_T_OPTIONSETTING_Value(string name) |
||
256 | { |
||
257 | string TemplatePath = string.Empty; |
||
258 | 2e1e3c12 | gaqhf | SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
259 | 23eb98bf | gaqhf | try |
260 | { |
||
261 | if (dbInfo.DBType == "ORACLE") |
||
262 | { |
||
263 | string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
||
264 | connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
||
265 | |||
266 | using (OracleConnection conn = new OracleConnection(connString)) |
||
267 | { |
||
268 | conn.Open(); |
||
269 | if (conn.State == System.Data.ConnectionState.Open) |
||
270 | { |
||
271 | using (OracleCommand cmd = new OracleCommand()) |
||
272 | { |
||
273 | cmd.Connection = conn; |
||
274 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT VALUE FROM {0}.T_OPTIONSETTING WHERE NAME = '{1}'", dbInfo.PlantPID, name); |
||
275 | |||
276 | using (OracleDataReader reader = cmd.ExecuteReader()) |
||
277 | { |
||
278 | while (reader.Read()) |
||
279 | { |
||
280 | TemplatePath = reader["VALUE"].ToString(); |
||
281 | break; |
||
282 | } |
||
283 | } |
||
284 | } |
||
285 | } |
||
286 | } |
||
287 | } |
||
288 | else |
||
289 | { |
||
290 | |||
291 | } |
||
292 | |||
293 | } |
||
294 | catch (Exception ex) |
||
295 | { |
||
296 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
297 | 23eb98bf | gaqhf | } |
298 | |||
299 | return TemplatePath; |
||
300 | } |
||
301 | |||
302 | public static List<string> GetSPPIDAttribute() |
||
303 | { |
||
304 | List<string> attributes = new List<string>(); |
||
305 | 2e1e3c12 | gaqhf | SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
306 | 23eb98bf | gaqhf | try |
307 | { |
||
308 | if (dbInfo.DBType == "ORACLE") |
||
309 | { |
||
310 | string connString = string.Format(oConnString, 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 | using (OracleCommand cmd = new OracleCommand()) |
||
319 | { |
||
320 | cmd.Connection = conn; |
||
321 | |||
322 | // 정리 필요 |
||
323 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM {0}.{1}", dbInfo.PlantPID, "T_EQUIPMENT"); |
||
324 | using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)) |
||
325 | { |
||
326 | DataTable dt = reader.GetSchemaTable(); |
||
327 | foreach (DataRow row in dt.Rows) |
||
328 | attributes.Add(row["ColumnName"].ToString()); |
||
329 | } |
||
330 | |||
331 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM {0}.{1}", dbInfo.PlantPID, "T_NOZZLE"); |
||
332 | using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)) |
||
333 | { |
||
334 | DataTable dt = reader.GetSchemaTable(); |
||
335 | foreach (DataRow row in dt.Rows) |
||
336 | attributes.Add(row["ColumnName"].ToString()); |
||
337 | } |
||
338 | |||
339 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM {0}.{1}", dbInfo.PlantPID, "T_PIPINGCOMP"); |
||
340 | using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)) |
||
341 | { |
||
342 | DataTable dt = reader.GetSchemaTable(); |
||
343 | foreach (DataRow row in dt.Rows) |
||
344 | attributes.Add(row["ColumnName"].ToString()); |
||
345 | } |
||
346 | |||
347 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM {0}.{1}", dbInfo.PlantPID, "T_PIPERUN"); |
||
348 | using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)) |
||
349 | { |
||
350 | |||
351 | DataTable dt = reader.GetSchemaTable(); |
||
352 | foreach (DataRow row in dt.Rows) |
||
353 | attributes.Add(row["ColumnName"].ToString()); |
||
354 | } |
||
355 | |||
356 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM {0}.{1}", dbInfo.PlantPID, "T_INSTRUMENT"); |
||
357 | using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)) |
||
358 | { |
||
359 | DataTable dt = reader.GetSchemaTable(); |
||
360 | foreach (DataRow row in dt.Rows) |
||
361 | attributes.Add(row["ColumnName"].ToString()); |
||
362 | } |
||
363 | |||
364 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM {0}.{1}", dbInfo.PlantPID, "T_INLINECOMP"); |
||
365 | using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)) |
||
366 | { |
||
367 | DataTable dt = reader.GetSchemaTable(); |
||
368 | foreach (DataRow row in dt.Rows) |
||
369 | attributes.Add(row["ColumnName"].ToString()); |
||
370 | } |
||
371 | |||
372 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM {0}.{1}", dbInfo.PlantPID, "T_VESSEL"); |
||
373 | using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)) |
||
374 | { |
||
375 | DataTable dt = reader.GetSchemaTable(); |
||
376 | foreach (DataRow row in dt.Rows) |
||
377 | attributes.Add(row["ColumnName"].ToString()); |
||
378 | } |
||
379 | |||
380 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM {0}.{1}", dbInfo.PlantPID, "T_EXCHANGER"); |
||
381 | using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)) |
||
382 | { |
||
383 | DataTable dt = reader.GetSchemaTable(); |
||
384 | foreach (DataRow row in dt.Rows) |
||
385 | attributes.Add(row["ColumnName"].ToString()); |
||
386 | } |
||
387 | |||
388 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM {0}.{1}", dbInfo.PlantPID, "T_MECHANICAL"); |
||
389 | using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)) |
||
390 | { |
||
391 | DataTable dt = reader.GetSchemaTable(); |
||
392 | foreach (DataRow row in dt.Rows) |
||
393 | attributes.Add(row["ColumnName"].ToString()); |
||
394 | } |
||
395 | |||
396 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM {0}.{1}", dbInfo.PlantPID, "T_EQUIPCOMPONENT"); |
||
397 | using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)) |
||
398 | { |
||
399 | DataTable dt = reader.GetSchemaTable(); |
||
400 | foreach (DataRow row in dt.Rows) |
||
401 | attributes.Add(row["ColumnName"].ToString()); |
||
402 | } |
||
403 | |||
404 | } |
||
405 | } |
||
406 | } |
||
407 | } |
||
408 | else |
||
409 | { |
||
410 | |||
411 | } |
||
412 | } |
||
413 | catch (Exception ex) |
||
414 | { |
||
415 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
416 | 23eb98bf | gaqhf | } |
417 | |||
418 | |||
419 | |||
420 | return attributes.Distinct().ToList(); |
||
421 | } |
||
422 | } |
||
423 | } |