프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / DB / SPPID_DB.cs @ 69b7387a

이력 | 보기 | 이력해설 | 다운로드 (14.8 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 e88aae98 gaqhf
        public static DataTable GetSPPIDAttribute()
303 23eb98bf gaqhf
        {
304
            List<string> attributes = new List<string>();
305 2e1e3c12 gaqhf
            SPPID_DBInfo dbInfo = SPPID_DBInfo.GetInstance();
306 e88aae98 gaqhf
            DataTable dt = null;
307 23eb98bf gaqhf
            try
308
            {
309
                if (dbInfo.DBType == "ORACLE")
310
                {
311
                    string connString = string.Format(oConnString, dbInfo.ServerIP, dbInfo.Port, dbInfo.Service);
312
                    connString = "Data Source=" + connString + ";User Id=" + dbInfo.DBUser + ";Password=" + dbInfo.DBPassword;
313
314
                    using (OracleConnection conn = new OracleConnection(connString))
315
                    {
316
                        conn.Open();
317
                        if (conn.State == System.Data.ConnectionState.Open)
318
                        {
319 e88aae98 gaqhf
                            string sQuery = string.Format(CultureInfo.CurrentCulture,
320
                                @"SELECT DISTINCT(ATTR.displayname), ATTR.name FROM {0}.itemattributions ATTR
321
                                ORDER BY ATTR.displayname ASC", dbInfo.PlantPIDDic);
322
                            using (OracleCommand cmd = new OracleCommand(sQuery, conn))
323
                            using (OracleDataAdapter adapter = new OracleDataAdapter())
324 23eb98bf gaqhf
                            {
325 e88aae98 gaqhf
                                adapter.SelectCommand = cmd;
326
                                dt = new DataTable();
327
                                adapter.Fill(dt);
328 23eb98bf gaqhf
                            }
329
                        }
330
                    }
331
                }
332
                else
333
                {
334
335
                }
336
            }
337
            catch (Exception ex)
338
            {
339 289e9573 gaqhf
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
340 23eb98bf gaqhf
            }
341
342 e88aae98 gaqhf
            return dt;
343 23eb98bf gaqhf
        }
344
    }
345
}
클립보드 이미지 추가 (최대 크기: 500 MB)