hytos / DTI_PID / SPPIDConverter / DB / SPPID_DB.cs @ ebe81079
이력 | 보기 | 이력해설 | 다운로드 (15.4 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 | 224535bb | gaqhf | |
150 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT PATH FROM {0}.T_ROOTITEM WHERE NAME = '{1}'", dbInfo.Site, dbInfo.Plant); |
||
151 | using (OracleDataReader reader = cmd.ExecuteReader()) |
||
152 | { |
||
153 | while (reader.Read()) |
||
154 | { |
||
155 | dbInfo.PlantPath = reader["PATH"].ToString(); |
||
156 | } |
||
157 | } |
||
158 | 23eb98bf | gaqhf | } |
159 | } |
||
160 | } |
||
161 | } |
||
162 | else |
||
163 | { |
||
164 | |||
165 | } |
||
166 | } |
||
167 | catch (Exception ex) |
||
168 | { |
||
169 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
170 | 23eb98bf | gaqhf | } |
171 | |||
172 | return bResult; |
||
173 | } |
||
174 | |||
175 | fab4f207 | gaqhf | public static List<string> GetPlantList(SPPID_DBInfo dbInfo) |
176 | 23eb98bf | gaqhf | { |
177 | List<string> plantList = new List<string>(); |
||
178 | try |
||
179 | { |
||
180 | if (dbInfo.DBType == "ORACLE") |
||
181 | { |
||
182 | string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
||
183 | connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
||
184 | |||
185 | using (OracleConnection conn = new OracleConnection(connString)) |
||
186 | { |
||
187 | conn.Open(); |
||
188 | if (conn.State == System.Data.ConnectionState.Open) |
||
189 | { |
||
190 | using (OracleCommand cmd = new OracleCommand()) |
||
191 | { |
||
192 | cmd.Connection = conn; |
||
193 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT NAME, PATH FROM {0}.T_ROOTITEM", dbInfo.Site); |
||
194 | |||
195 | using (OracleDataReader reader = cmd.ExecuteReader()) |
||
196 | { |
||
197 | while (reader.Read()) |
||
198 | { |
||
199 | plantList.Add(reader["NAME"].ToString()); |
||
200 | } |
||
201 | } |
||
202 | } |
||
203 | } |
||
204 | } |
||
205 | } |
||
206 | else |
||
207 | { |
||
208 | |||
209 | } |
||
210 | } |
||
211 | catch (Exception ex) |
||
212 | { |
||
213 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
214 | 23eb98bf | gaqhf | } |
215 | |||
216 | return plantList; |
||
217 | } |
||
218 | |||
219 | public static DataTable GetUnitTree() |
||
220 | { |
||
221 | DataTable dt = new DataTable(); |
||
222 | try |
||
223 | { |
||
224 | 2e1e3c12 | gaqhf | SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
225 | 23eb98bf | gaqhf | |
226 | if (dbInfo.DBType == "ORACLE") |
||
227 | { |
||
228 | string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
||
229 | connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
||
230 | |||
231 | using (OracleConnection conn = new OracleConnection(connString)) |
||
232 | { |
||
233 | conn.Open(); |
||
234 | if (conn.State == System.Data.ConnectionState.Open) |
||
235 | { |
||
236 | string sQuery = string.Format(CultureInfo.CurrentCulture, |
||
237 | @"SELECT SP_ID, PARENTID, NAME |
||
238 | FROM {0}.T_PLANTGROUP |
||
239 | START WITH PARENTID='-1' |
||
240 | CONNECT BY PRIOR SP_ID=PARENTID", dbInfo.Plant); |
||
241 | |||
242 | using (OracleCommand cmd = new OracleCommand(sQuery, conn)) |
||
243 | using (OracleDataAdapter adapter = new OracleDataAdapter()) |
||
244 | { |
||
245 | adapter.SelectCommand = cmd; |
||
246 | adapter.Fill(dt); |
||
247 | } |
||
248 | } |
||
249 | } |
||
250 | } |
||
251 | else |
||
252 | { |
||
253 | |||
254 | } |
||
255 | } |
||
256 | catch (Exception ex) |
||
257 | { |
||
258 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
259 | 23eb98bf | gaqhf | } |
260 | |||
261 | return dt; |
||
262 | } |
||
263 | |||
264 | public static string GetPlantPID_T_OPTIONSETTING_Value(string name) |
||
265 | { |
||
266 | string TemplatePath = string.Empty; |
||
267 | 2e1e3c12 | gaqhf | SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
268 | 23eb98bf | gaqhf | try |
269 | { |
||
270 | if (dbInfo.DBType == "ORACLE") |
||
271 | { |
||
272 | string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
||
273 | connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
||
274 | |||
275 | using (OracleConnection conn = new OracleConnection(connString)) |
||
276 | { |
||
277 | conn.Open(); |
||
278 | if (conn.State == System.Data.ConnectionState.Open) |
||
279 | { |
||
280 | using (OracleCommand cmd = new OracleCommand()) |
||
281 | { |
||
282 | cmd.Connection = conn; |
||
283 | cmd.CommandText = string.Format(CultureInfo.CurrentCulture, "SELECT VALUE FROM {0}.T_OPTIONSETTING WHERE NAME = '{1}'", dbInfo.PlantPID, name); |
||
284 | |||
285 | using (OracleDataReader reader = cmd.ExecuteReader()) |
||
286 | { |
||
287 | while (reader.Read()) |
||
288 | { |
||
289 | TemplatePath = reader["VALUE"].ToString(); |
||
290 | break; |
||
291 | } |
||
292 | } |
||
293 | } |
||
294 | } |
||
295 | } |
||
296 | } |
||
297 | else |
||
298 | { |
||
299 | |||
300 | } |
||
301 | |||
302 | } |
||
303 | catch (Exception ex) |
||
304 | { |
||
305 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
306 | 23eb98bf | gaqhf | } |
307 | |||
308 | return TemplatePath; |
||
309 | } |
||
310 | |||
311 | e88aae98 | gaqhf | public static DataTable GetSPPIDAttribute() |
312 | 23eb98bf | gaqhf | { |
313 | List<string> attributes = new List<string>(); |
||
314 | 2e1e3c12 | gaqhf | SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance(); |
315 | e88aae98 | gaqhf | DataTable dt = null; |
316 | 23eb98bf | gaqhf | try |
317 | { |
||
318 | if (dbInfo.DBType == "ORACLE") |
||
319 | { |
||
320 | string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service); |
||
321 | connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword; |
||
322 | |||
323 | using (OracleConnection conn = new OracleConnection(connString)) |
||
324 | { |
||
325 | conn.Open(); |
||
326 | if (conn.State == System.Data.ConnectionState.Open) |
||
327 | { |
||
328 | e88aae98 | gaqhf | string sQuery = string.Format(CultureInfo.CurrentCulture, |
329 | @"SELECT DISTINCT(ATTR.displayname), ATTR.name FROM {0}.itemattributions ATTR |
||
330 | ORDER BY ATTR.displayname ASC", dbInfo.PlantPIDDic); |
||
331 | using (OracleCommand cmd = new OracleCommand(sQuery, conn)) |
||
332 | using (OracleDataAdapter adapter = new OracleDataAdapter()) |
||
333 | 23eb98bf | gaqhf | { |
334 | e88aae98 | gaqhf | adapter.SelectCommand = cmd; |
335 | dt = new DataTable(); |
||
336 | adapter.Fill(dt); |
||
337 | 23eb98bf | gaqhf | } |
338 | } |
||
339 | } |
||
340 | } |
||
341 | else |
||
342 | { |
||
343 | |||
344 | } |
||
345 | } |
||
346 | catch (Exception ex) |
||
347 | { |
||
348 | 289e9573 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
349 | 23eb98bf | gaqhf | } |
350 | |||
351 | e88aae98 | gaqhf | return dt; |
352 | 23eb98bf | gaqhf | } |
353 | } |
||
354 | } |