hytos / DTI_PID / SPPIDConverter / DB / SPPID_DB.cs @ 518c7651
이력 | 보기 | 이력해설 | 다운로드 (14.2 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 |
|
11 |
namespace Converter.SPPID.DB |
12 |
{ |
13 |
public class SPPID_DB |
14 |
{ |
15 |
private const string oConnString = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST ={0}" + @")(PORT = {1}))(CONNECT_DATA = (SERVICE_NAME = {2})))"; |
16 |
|
17 |
public static bool CheckAndSetSPPIDInfo(SPPID_DBInfo dbInfo) |
18 |
{ |
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 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
93 |
} |
94 |
|
95 |
return bResult; |
96 |
} |
97 |
public static bool SetPlantDBSetting(SPPID_DBInfo dbInfo) |
98 |
{ |
99 |
bool bResult = false; |
100 |
try |
101 |
{ |
102 |
if (dbInfo.DBType == "ORACLE") |
103 |
{ |
104 |
string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
105 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
106 |
|
107 |
using (OracleConnection conn = new OracleConnection(connString)) |
108 |
{ |
109 |
conn.Open(); |
110 |
if (conn.State == System.Data.ConnectionState.Open) |
111 |
{ |
112 |
using (OracleCommand cmd = new OracleCommand()) |
113 |
{ |
114 |
cmd.Connection = conn; |
115 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, @"SELECT SP_SCHEMA_TYPE, USERNAME |
116 |
FROM {0}.T_DB_DATA DB_DATA |
117 |
INNER JOIN {0}.T_ROOTITEM ROOTITEM ON DB_DATA.SP_ROOTITEMID = ROOTITEM.SP_ID |
118 |
WHERE ROOTITEM.NAME = '{1}'", dbInfo.Site, dbInfo.SelectedPlant); |
119 |
using (OracleDataAdapter adapter = new OracleDataAdapter()) |
120 |
{ |
121 |
DataTable dt = new DataTable(); |
122 |
adapter.SelectCommand = cmd; |
123 |
adapter.Fill(dt); |
124 |
|
125 |
foreach (DataRow row in dt.Rows) |
126 |
{ |
127 |
string sType = row["SP_SCHEMA_TYPE"].ToString(); |
128 |
switch (sType) |
129 |
{ |
130 |
case "SPPIDDATA_DICTIONARY": |
131 |
dbInfo.PlantPIDDic = row["USERNAME"].ToString(); |
132 |
break; |
133 |
case "DATA_DICTIONARY": |
134 |
dbInfo.PlantDic = row["USERNAME"].ToString(); |
135 |
break; |
136 |
case "SPAPLANT": |
137 |
dbInfo.Plant = row["USERNAME"].ToString(); |
138 |
break; |
139 |
case "SPPID": |
140 |
dbInfo.PlantPID = row["USERNAME"].ToString(); |
141 |
break; |
142 |
default: |
143 |
break; |
144 |
} |
145 |
bResult = true; |
146 |
} |
147 |
} |
148 |
|
149 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT PATH FROM {0}.T_ROOTITEM WHERE NAME = '{1}'", dbInfo.Site, dbInfo.Plant); |
150 |
using (OracleDataReader reader = cmd.ExecuteReader()) |
151 |
{ |
152 |
while (reader.Read()) |
153 |
{ |
154 |
dbInfo.PlantPath = reader["PATH"].ToString(); |
155 |
} |
156 |
} |
157 |
} |
158 |
} |
159 |
} |
160 |
} |
161 |
else |
162 |
{ |
163 |
|
164 |
} |
165 |
} |
166 |
catch (Exception ex) |
167 |
{ |
168 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
169 |
} |
170 |
|
171 |
return bResult; |
172 |
} |
173 |
public static List<string> GetPlantList(SPPID_DBInfo dbInfo) |
174 |
{ |
175 |
List<string> plantList = new List<string>(); |
176 |
try |
177 |
{ |
178 |
if (dbInfo.DBType == "ORACLE") |
179 |
{ |
180 |
string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
181 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
182 |
|
183 |
using (OracleConnection conn = new OracleConnection(connString)) |
184 |
{ |
185 |
conn.Open(); |
186 |
if (conn.State == System.Data.ConnectionState.Open) |
187 |
{ |
188 |
using (OracleCommand cmd = new OracleCommand()) |
189 |
{ |
190 |
cmd.Connection = conn; |
191 |
cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT NAME, PATH FROM {0}.T_ROOTITEM", dbInfo.Site); |
192 |
|
193 |
using (OracleDataReader reader = cmd.ExecuteReader()) |
194 |
{ |
195 |
while (reader.Read()) |
196 |
{ |
197 |
plantList.Add(reader["NAME"].ToString()); |
198 |
} |
199 |
} |
200 |
} |
201 |
} |
202 |
} |
203 |
} |
204 |
else |
205 |
{ |
206 |
|
207 |
} |
208 |
} |
209 |
catch (Exception ex) |
210 |
{ |
211 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
212 |
} |
213 |
|
214 |
return plantList; |
215 |
} |
216 |
|
217 |
public static DataTable GetSPPIDAttribute() |
218 |
{ |
219 |
List<string> attributes = new List<string>(); |
220 |
SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
221 |
DataTable dt = null; |
222 |
try |
223 |
{ |
224 |
if (dbInfo.DBType == "ORACLE") |
225 |
{ |
226 |
string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
227 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
228 |
|
229 |
using (OracleConnection conn = new OracleConnection(connString)) |
230 |
{ |
231 |
conn.Open(); |
232 |
if (conn.State == System.Data.ConnectionState.Open) |
233 |
{ |
234 |
string sQuery = string.Format(CultureInfo.CurrentCulture, |
235 |
@"SELECT ITEM.description ItemType ,ATTR.displayname, ATTR.name FROM {0}.itemattributions ATTR |
236 |
LEFT OUTER JOIN {0}.item ITEM |
237 |
ON ITEM.ID = ATTR.ITEMID |
238 |
ORDER BY ATTR.displayname ASC", dbInfo.PlantPIDDic); |
239 |
//string sQuery = string.Format(CultureInfo.CurrentCulture, |
240 |
// @"SELECT DISTINCT(ATTR.displayname), ATTR.name FROM {0}.itemattributions ATTR |
241 |
// ORDER BY ATTR.displayname ASC", dbInfo.PlantPIDDic); |
242 |
using (OracleCommand cmd = new OracleCommand(sQuery, conn)) |
243 |
using (OracleDataAdapter adapter = new OracleDataAdapter()) |
244 |
{ |
245 |
adapter.SelectCommand = cmd; |
246 |
dt = new DataTable(); |
247 |
adapter.Fill(dt); |
248 |
} |
249 |
} |
250 |
} |
251 |
} |
252 |
else |
253 |
{ |
254 |
|
255 |
} |
256 |
} |
257 |
catch (Exception ex) |
258 |
{ |
259 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
260 |
} |
261 |
|
262 |
return dt; |
263 |
} |
264 |
public static DataTable GetFluidSystemInfo(string operFluidCode) |
265 |
{ |
266 |
List<string> attributes = new List<string>(); |
267 |
SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
268 |
DataTable dt = null; |
269 |
try |
270 |
{ |
271 |
if (dbInfo.DBType == "ORACLE") |
272 |
{ |
273 |
string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
274 |
connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
275 |
|
276 |
using (OracleConnection conn = new OracleConnection(connString)) |
277 |
{ |
278 |
conn.Open(); |
279 |
if (conn.State == System.Data.ConnectionState.Open) |
280 |
{ |
281 |
string sQuery = string.Format(CultureInfo.CurrentCulture, |
282 |
@"SELECT * FROM {0}.CODELISTS OUTATTR |
283 |
WHERE OUTATTR.codelist_index = |
284 |
(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); |
285 |
using (OracleCommand cmd = new OracleCommand(sQuery, conn)) |
286 |
using (OracleDataAdapter adapter = new OracleDataAdapter()) |
287 |
{ |
288 |
adapter.SelectCommand = cmd; |
289 |
dt = new DataTable(); |
290 |
adapter.Fill(dt); |
291 |
} |
292 |
} |
293 |
} |
294 |
} |
295 |
else |
296 |
{ |
297 |
|
298 |
} |
299 |
} |
300 |
catch (Exception ex) |
301 |
{ |
302 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
303 |
} |
304 |
|
305 |
return dt; |
306 |
} |
307 |
} |
308 |
} |