프로젝트

일반

사용자정보

개정판 8847ea67

ID8847ea67e8e1f07b684ed75ed66457fe8fa32003
상위 2062c36a
하위 6ea71950

gaqhf 이(가) 5년 이상 전에 추가함

dev issue #1203 : MSSQL 설정 창 추가 및 데이터 구조 변경

Change-Id: I7f310aba7b221ea99c3e5b8070fb89c7a85460e3

차이점 보기:

DTI_PID/SPPIDConverter/DB/Project_DB.cs
6 6
using System.Globalization;
7 7
using System.Data.SQLite;
8 8
using System.Data;
9
using System.Data.SqlClient;
9 10
using Newtonsoft.Json;
10 11

  
11 12
namespace Converter.BaseModel
......
27 28
        const string Symbol_TABLE = "Symbol";
28 29
        const string OPCRelations_TABLE = "OPCRelations";
29 30

  
30
        public static bool ConnTestAndCreateTable()
31
        private static SqlConnection GetSqlConnection()
31 32
        {
32
            bool result = false;
33 33
            Project_Info projectInfo = Project_Info.GetInstance();
34
            SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", projectInfo.DBFilePath));
34
            SqlConnection connection = null;
35 35
            try
36 36
            {
37
                connection = new SqlConnection(string.Format(CultureInfo.CurrentCulture,
38
                    @"Data Source = {0},{1}; Initial Catalog = {2}; User ID = {3}; Password = {4};",
39
                    projectInfo.ServerIP,
40
                    projectInfo.Port,
41
                    System.IO.Path.GetFileName(projectInfo.DefaultPath),
42
                    projectInfo.DBUser,
43
                    projectInfo.DBPassword));
44

  
37 45
                connection.Open();
38
                if (connection.State == ConnectionState.Open)
39
                {
40
                    CreateTable(connection);
41
                    result = true;
42
                }
43
                connection.Close();
44 46
            }
45 47
            catch (Exception ex)
46 48
            {
47

  
48
            }
49
            finally
50
            {
51 49
                connection.Dispose();
50
                connection = null;
52 51
            }
53 52

  
54
            return result;
53
            return connection;
55 54
        }
56 55

  
57
        public static bool SaveSPPID_DB_INFO(string jsonString)
56
        public static bool ConnTestAndCreateTable()
58 57
        {
58
            bool result = false;
59 59
            Project_Info projectInfo = Project_Info.GetInstance();
60
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
60
            if (projectInfo.DBType == ID2DB_Type.SQLite)
61 61
            {
62

  
63
                try
62
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", projectInfo.DBFilePath)))
64 63
                {
65
                    connection.Open();
66
                    using (SQLiteCommand cmd = connection.CreateCommand())
64
                    try
67 65
                    {
68
                        cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_DB_INFO_TABLE);
69
                        cmd.ExecuteNonQuery();
66
                        connection.Open();
67
                        if (connection.State == ConnectionState.Open)
68
                        {
69
                            using (SQLiteCommand cmd = connection.CreateCommand())
70
                            {
71
                                cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'";
72
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
73
                                using (DataTable dt = new DataTable())
74
                                {
75
                                    dt.Load(dr);
76

  
77
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0)
78
                                    {
79
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT)", SPPID_DB_INFO_TABLE);
80
                                        cmd.ExecuteNonQuery();
81
                                    }
82
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0)
83
                                    {
84
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT, SettingType TEXT)", SPPID_SETTING_TABLE);
85
                                        cmd.ExecuteNonQuery();
86
                                    }
87
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0)
88
                                    {
89
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT, SPPID_SYMBOL_PATH TEXT, LEADERLINE BOOLEAN)", SPPID_SYMBOL_MAPPING_TABLE);
90
                                        cmd.ExecuteNonQuery();
91
                                    }
92
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
93
                                    {
94
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, SPPID_ATTRIBUTE TEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE);
95
                                        cmd.ExecuteNonQuery();
96
                                    }
97
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0)
98
                                    {
99
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BOOLEAN)", SPPID_LABEL_INFO_TABLE);
100
                                        cmd.ExecuteNonQuery();
101
                                    }
102
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DRAWING_INFO)).Length == 0)
103
                                    {
104
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID Text PRIMARY KEY, PATH TEXT, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT)", SPPID_DRAWING_INFO);
105
                                        cmd.ExecuteNonQuery();
106
                                    }
107
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_OPC_INFO)).Length == 0)
108
                                    {
109
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_OPC_UID TEXT PRIMARY KEY, SPPID_OPC_MODELITEM_ID TEXT, ID2_DRAWING_UID TEXT, ATTRIBUTES TEXT, PAIRED BOOL)", SPPID_OPC_INFO);
110
                                        cmd.ExecuteNonQuery();
111
                                    }
112
                                }
113

  
114
                                #region Check Column 업데이트시 예비용
115
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
116
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
117
                                using (DataTable dt = new DataTable())
118
                                {
119
                                    dt.Load(dr);
120
                                    if (!dt.Columns.Contains("LEADERLINE"))
121
                                    {
122
                                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN LEADERLINE BOOLEAN", SPPID_SYMBOL_MAPPING_TABLE);
123
                                        cmd.ExecuteNonQuery();
124
                                    }
125
                                }
126

  
127
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
128
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
129
                                using (DataTable dt = new DataTable())
130
                                {
131
                                    dt.Load(dr);
132
                                    if (!dt.Columns.Contains("SettingType"))
133
                                    {
134
                                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN SettingType Text", SPPID_SETTING_TABLE);
135
                                        cmd.ExecuteNonQuery();
136
                                    }
137
                                }
70 138

  
71
                        cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString)", SPPID_DB_INFO_TABLE);
72
                        cmd.Parameters.AddWithValue("@jsonString", jsonString);
73
                        cmd.ExecuteNonQuery();
139
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO);
140
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
141
                                using (DataTable dt = new DataTable())
142
                                {
143
                                    dt.Load(dr);
144
                                    if (dt.Columns.Contains("DOCUMENT"))
145
                                    {
146
                                        cmd.CommandText = string.Format("DROP TABLE {0}", SPPID_DRAWING_INFO);
147
                                        cmd.ExecuteNonQuery();
148

  
149
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID Text PRIMARY KEY, PATH TEXT, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT)", SPPID_DRAWING_INFO);
150
                                        cmd.ExecuteNonQuery();
151
                                    }
152
                                }
153
                                #endregion
154
                            }
155
                            result = true;
156
                        }
157
                        connection.Close();
158
                    }
159
                    catch (Exception ex)
160
                    {
161

  
162
                    }
163
                    finally
164
                    {
165
                        connection.Dispose();
74 166
                    }
75
                    connection.Close();
76
                }
77
                catch (Exception ex)
78
                {
79
                    return false;
80
                }
81
                finally
82
                {
83
                    connection.Dispose();
84 167
                }
85 168
            }
86

  
87
            return true;
88
        }
89

  
90
        public static DataTable SelectSPPID_DB_INFO()
91
        {
92
            DataTable dt = new DataTable();
93
            Project_Info projectInfo = Project_Info.GetInstance();
94
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
169
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
95 170
            {
96
                try
171
                using (SqlConnection connection = GetSqlConnection())
97 172
                {
98
                    connection.Open();
99
                    using (SQLiteCommand cmd = connection.CreateCommand())
173
                    try
100 174
                    {
101
                        cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DB_INFO_TABLE);
102
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
103
                            dt.Load(dr);
175
                        if (connection != null && connection.State == ConnectionState.Open)
176
                        {
177
                            using (SqlCommand cmd = connection.CreateCommand())
178
                            {
179
                                cmd.CommandText = "SELECT TABLE_NAME AS NAME FROM INFORMATION_SCHEMA.TABLES";
180
                                using (SqlDataReader dr = cmd.ExecuteReader())
181
                                using (DataTable dt = new DataTable())
182
                                {
183
                                    dt.Load(dr);
184

  
185
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0)
186
                                    {
187
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString varchar(255))", SPPID_DB_INFO_TABLE);
188
                                        cmd.ExecuteNonQuery();
189
                                    }
190
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0)
191
                                    {
192
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString varchar(255), SettingType varchar(255))", SPPID_SETTING_TABLE);
193
                                        cmd.ExecuteNonQuery();
194
                                    }
195
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0)
196
                                    {
197
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, NAME varchar(255), SPPID_SYMBOL_PATH varchar(255), LEADERLINE BIT)", SPPID_SYMBOL_MAPPING_TABLE);
198
                                        cmd.ExecuteNonQuery();
199
                                    }
200
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
201
                                    {
202
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, SPPID_ATTRIBUTE varchar(255))", SPPID_ATTRIBUTE_MAPPING_TABLE);
203
                                        cmd.ExecuteNonQuery();
204
                                    }
205
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0)
206
                                    {
207
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BIT)", SPPID_LABEL_INFO_TABLE);
208
                                        cmd.ExecuteNonQuery();
209
                                    }
210
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DRAWING_INFO)).Length == 0)
211
                                    {
212
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID varchar(255) PRIMARY KEY, PATH varchar(255), DRAWINGNUMBER varchar(255), DRAWINGNAME varchar(255))", SPPID_DRAWING_INFO);
213
                                        cmd.ExecuteNonQuery();
214
                                    }
215
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_OPC_INFO)).Length == 0)
216
                                    {
217
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_OPC_UID varchar(255) PRIMARY KEY, SPPID_OPC_MODELITEM_ID varchar(255), ID2_DRAWING_UID varchar(255), ATTRIBUTES varchar(255), PAIRED BIT)", SPPID_OPC_INFO);
218
                                        cmd.ExecuteNonQuery();
219
                                    }
220
                                }
221

  
222
                                #region Check Column 업데이트시 예비용
223
                                #endregion
224
                            }
225
                            result = true;
226
                        }
104 227
                    }
105
                    connection.Close();
106
                }
107
                catch (Exception ex)
108
                {
228
                    catch (Exception ex)
229
                    {
109 230

  
110
                }
111
                finally
112
                {
113
                    connection.Dispose();
231
                    }
232
                    finally
233
                    {
234
                        if (connection != null)
235
                            connection.Dispose();
236
                    }
114 237
                }
115 238
            }
116 239

  
117
            return dt;
240
            return result;
118 241
        }
119 242

  
120
        public static bool SaveETCSetting(Dictionary<string,string> dicSetting)
243
        public static bool SaveSPPID_DB_INFO(string jsonString)
121 244
        {
122 245
            Project_Info projectInfo = Project_Info.GetInstance();
123
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
246
            if (projectInfo.DBType == ID2DB_Type.SQLite)
124 247
            {
125

  
126
                try
248
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
127 249
                {
128
                    connection.Open();
129
                    using (SQLiteCommand cmd = connection.CreateCommand())
130
                    {
131
                        cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_SETTING_TABLE);
132
                        cmd.ExecuteNonQuery();
133 250

  
134
                        foreach (var item in dicSetting)
251
                    try
252
                    {
253
                        connection.Open();
254
                        using (SQLiteCommand cmd = connection.CreateCommand())
135 255
                        {
136
                            cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString, @SettingType)", SPPID_SETTING_TABLE);
137
                            cmd.Parameters.AddWithValue("@jsonString", item.Value);
138
                            cmd.Parameters.AddWithValue("@SettingType", item.Key);
256
                            cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_DB_INFO_TABLE);
257
                            cmd.ExecuteNonQuery();
258

  
259
                            cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString)", SPPID_DB_INFO_TABLE);
260
                            cmd.Parameters.AddWithValue("@jsonString", jsonString);
139 261
                            cmd.ExecuteNonQuery();
140 262
                        }
263
                        connection.Close();
264
                    }
265
                    catch (Exception ex)
266
                    {
267
                        return false;
268
                    }
269
                    finally
270
                    {
271
                        connection.Dispose();
141 272
                    }
142
                    connection.Close();
143
                }
144
                catch (Exception ex)
145
                {
146
                    return false;
147 273
                }
148
                finally
274
            }
275
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
276
            {
277
                using (SqlConnection connection = GetSqlConnection())
149 278
                {
150
                    connection.Dispose();
279
                    try
280
                    {
281
                        if (connection != null && connection.State == ConnectionState.Open)
282
                        {
283

  
284
                        }
285
                    }
286
                    catch (Exception ex)
287
                    {
288

  
289
                    }
290
                    finally
291
                    {
292
                        if (connection != null)
293
                            connection.Dispose();
294
                    }
151 295
                }
152 296
            }
153 297

  
298

  
154 299
            return true;
155 300
        }
156 301

  
157
        public static DataTable SelectSetting()
302
        public static DataTable SelectSPPID_DB_INFO()
158 303
        {
159 304
            DataTable dt = new DataTable();
160 305
            Project_Info projectInfo = Project_Info.GetInstance();
161
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
306
            if (projectInfo.DBType == ID2DB_Type.SQLite)
162 307
            {
163
                try
308
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
164 309
                {
165
                    connection.Open();
166
                    using (SQLiteCommand cmd = connection.CreateCommand())
310
                    try
167 311
                    {
168
                        cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
169
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
170
                            dt.Load(dr);
312
                        connection.Open();
313
                        using (SQLiteCommand cmd = connection.CreateCommand())
314
                        {
315
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DB_INFO_TABLE);
316
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
317
                                dt.Load(dr);
318
                        }
319
                        connection.Close();
171 320
                    }
172
                    connection.Close();
173
                }
174
                catch (Exception ex)
175
                {
321
                    catch (Exception ex)
322
                    {
176 323

  
324
                    }
325
                    finally
326
                    {
327
                        connection.Dispose();
328
                    }
177 329
                }
178
                finally
330
            }
331
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
332
            {
333
                using (SqlConnection connection = GetSqlConnection())
179 334
                {
180
                    connection.Dispose();
335
                    try
336
                    {
337
                        if (connection != null && connection.State == ConnectionState.Open)
338
                        {
339

  
340
                        }
341
                    }
342
                    catch (Exception ex)
343
                    {
344

  
345
                    }
346
                    finally
347
                    {
348
                        if (connection != null)
349
                            connection.Dispose();
350
                    }
181 351
                }
182 352
            }
183 353

  
184 354
            return dt;
185 355
        }
186 356

  
187
        private static void CreateTable(SQLiteConnection connection)
357
        public static bool SaveETCSetting(Dictionary<string,string> dicSetting)
188 358
        {
189
            using (SQLiteCommand cmd = connection.CreateCommand())
359
            Project_Info projectInfo = Project_Info.GetInstance();
360
            if (projectInfo.DBType == ID2DB_Type.SQLite)
190 361
            {
191
                cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'";
192
                using (SQLiteDataReader dr = cmd.ExecuteReader())
193
                using (DataTable dt = new DataTable())
362
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
194 363
                {
195
                    dt.Load(dr);
196 364

  
197
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0)
198
                    {
199
                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT)", SPPID_DB_INFO_TABLE);
200
                        cmd.ExecuteNonQuery();
201
                    }
202
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0)
365
                    try
203 366
                    {
204
                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT, SettingType TEXT)", SPPID_SETTING_TABLE);
205
                        cmd.ExecuteNonQuery();
367
                        connection.Open();
368
                        using (SQLiteCommand cmd = connection.CreateCommand())
369
                        {
370
                            cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_SETTING_TABLE);
371
                            cmd.ExecuteNonQuery();
372

  
373
                            foreach (var item in dicSetting)
374
                            {
375
                                cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString, @SettingType)", SPPID_SETTING_TABLE);
376
                                cmd.Parameters.AddWithValue("@jsonString", item.Value);
377
                                cmd.Parameters.AddWithValue("@SettingType", item.Key);
378
                                cmd.ExecuteNonQuery();
379
                            }
380
                        }
381
                        connection.Close();
206 382
                    }
207
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0)
383
                    catch (Exception ex)
208 384
                    {
209
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT, SPPID_SYMBOL_PATH TEXT, LEADERLINE BOOLEAN)", SPPID_SYMBOL_MAPPING_TABLE);
210
                        cmd.ExecuteNonQuery();
385
                        return false;
211 386
                    }
212
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
387
                    finally
213 388
                    {
214
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, SPPID_ATTRIBUTE TEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE);
215
                        cmd.ExecuteNonQuery();
389
                        connection.Dispose();
216 390
                    }
217
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0)
391
                }
392
            }
393
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
394
            {
395
                using (SqlConnection connection = GetSqlConnection())
396
                {
397
                    try
218 398
                    {
219
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BOOLEAN)", SPPID_LABEL_INFO_TABLE);
220
                        cmd.ExecuteNonQuery();
399
                        if (connection != null && connection.State == ConnectionState.Open)
400
                        {
401

  
402
                        }
221 403
                    }
222
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DRAWING_INFO)).Length == 0)
404
                    catch (Exception ex)
223 405
                    {
224
                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID Text PRIMARY KEY, PATH TEXT, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT)", SPPID_DRAWING_INFO);
225
                        cmd.ExecuteNonQuery();
406

  
226 407
                    }
227
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_OPC_INFO)).Length == 0)
408
                    finally
228 409
                    {
229
                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_OPC_UID TEXT PRIMARY KEY, SPPID_OPC_MODELITEM_ID TEXT, ID2_DRAWING_UID TEXT, ATTRIBUTES TEXT, PAIRED BOOL)", SPPID_OPC_INFO);
230
                        cmd.ExecuteNonQuery();
410
                        if (connection != null)
411
                            connection.Dispose();
231 412
                    }
232 413
                }
414
            }
233 415

  
234
                #region Check Column 업데이트시 예비용
235
                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
236
                using (SQLiteDataReader dr = cmd.ExecuteReader())
237
                using (DataTable dt = new DataTable())
416
            return true;
417
        }
418

  
419
        public static DataTable SelectSetting()
420
        {
421
            DataTable dt = new DataTable();
422
            Project_Info projectInfo = Project_Info.GetInstance();
423
            if (projectInfo.DBType == ID2DB_Type.SQLite)
424
            {
425
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
238 426
                {
239
                    dt.Load(dr);
240
                    if (!dt.Columns.Contains("LEADERLINE"))
427
                    try
241 428
                    {
242
                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN LEADERLINE BOOLEAN", SPPID_SYMBOL_MAPPING_TABLE);
243
                        cmd.ExecuteNonQuery();
429
                        connection.Open();
430
                        using (SQLiteCommand cmd = connection.CreateCommand())
431
                        {
432
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
433
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
434
                                dt.Load(dr);
435
                        }
436
                        connection.Close();
244 437
                    }
245
                }
438
                    catch (Exception ex)
439
                    {
246 440

  
247
                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
248
                using (SQLiteDataReader dr = cmd.ExecuteReader())
249
                using (DataTable dt = new DataTable())
250
                {
251
                    dt.Load(dr);
252
                    if (!dt.Columns.Contains("SettingType"))
441
                    }
442
                    finally
253 443
                    {
254
                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN SettingType Text", SPPID_SETTING_TABLE);
255
                        cmd.ExecuteNonQuery();
444
                        connection.Dispose();
256 445
                    }
257 446
                }
258

  
259
                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO);
260
                using (SQLiteDataReader dr = cmd.ExecuteReader())
261
                using (DataTable dt = new DataTable())
447
            }
448
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
449
            {
450
                using (SqlConnection connection = GetSqlConnection())
262 451
                {
263
                    dt.Load(dr);
264
                    if (dt.Columns.Contains("DOCUMENT"))
452
                    try
453
                    {
454
                        if (connection != null && connection.State == ConnectionState.Open)
455
                        {
456

  
457
                        }
458
                    }
459
                    catch (Exception ex)
265 460
                    {
266
                        cmd.CommandText = string.Format("DROP TABLE {0}", SPPID_DRAWING_INFO);
267
                        cmd.ExecuteNonQuery();
268 461

  
269
                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID Text PRIMARY KEY, PATH TEXT, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT)", SPPID_DRAWING_INFO);
270
                        cmd.ExecuteNonQuery();
462
                    }
463
                    finally
464
                    {
465
                        if (connection != null)
466
                            connection.Dispose();
271 467
                    }
272 468
                }
273
                #endregion
274 469
            }
470

  
471
            return dt;
275 472
        }
276 473

  
277 474
        public static DataTable SelectProjectSymbol()
278 475
        {
279 476
            DataTable dt = new DataTable();
280 477
            Project_Info projectInfo = Project_Info.GetInstance();
281
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
478
            if (projectInfo.DBType == ID2DB_Type.SQLite)
282 479
            {
283
                try
480
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
284 481
                {
285
                    connection.Open();
286
                    using (SQLiteCommand cmd = connection.CreateCommand())
482
                    try
287 483
                    {
288
                        cmd.CommandText = string.Format(@"
484
                        connection.Open();
485
                        using (SQLiteCommand cmd = connection.CreateCommand())
486
                        {
487
                            cmd.CommandText = string.Format(@"
289 488
                            SELECT s.UID, s.Name, st.Type, sp.SPPID_SYMBOL_PATH, sp.LEADERLINE FROM {1} as st, {0} as s 
290 489
                                LEFT OUTER JOIN {2} as sp 
291 490
                                    ON s.UID = SP.UID 
292 491
                            WHERE s.SymbolType_UID = st.UID 
293 492
                            ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
294
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
295
                            dt.Load(dr);
493
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
494
                                dt.Load(dr);
296 495

  
297
                        DataTable dtClone = dt.Clone();
298
                        dtClone.Columns["UID"].DataType = typeof(string);
299
                        foreach (DataRow row in dt.Rows)
300
                        {
301
                            dtClone.ImportRow(row);
496
                            DataTable dtClone = dt.Clone();
497
                            dtClone.Columns["UID"].DataType = typeof(string);
498
                            foreach (DataRow row in dt.Rows)
499
                            {
500
                                dtClone.ImportRow(row);
501
                            }
502
                            dt.Dispose();
503
                            dt = dtClone;
302 504
                        }
303
                        dt.Dispose();
304
                        dt = dtClone;
505
                        connection.Close();
305 506
                    }
306
                    connection.Close();
307
                }
308
                catch (Exception ex)
309
                {
507
                    catch (Exception ex)
508
                    {
310 509

  
510
                    }
511
                    finally
512
                    {
513
                        connection.Dispose();
514
                    }
311 515
                }
312
                finally
516
            }
517
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
518
            {
519
                using (SqlConnection connection = GetSqlConnection())
313 520
                {
314
                    connection.Dispose();
521
                    try
522
                    {
523
                        if (connection != null && connection.State == ConnectionState.Open)
524
                        {
525

  
526
                        }
527
                    }
528
                    catch (Exception ex)
529
                    {
530

  
531
                    }
532
                    finally
533
                    {
534
                        if (connection != null)
535
                            connection.Dispose();
536
                    }
315 537
                }
316 538
            }
317 539

  
......
327 549
            result.Columns.Add("SPPID_SYMBOL_PATH");
328 550
            
329 551
            Project_Info projectInfo = Project_Info.GetInstance();
330
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
331
            using (DataTable dt = new DataTable())
552
            if (projectInfo.DBType == ID2DB_Type.SQLite)
332 553
            {
333
                try
554
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
555
                using (DataTable dt = new DataTable())
334 556
                {
335
                    connection.Open();
336
                    using (SQLiteCommand cmd = connection.CreateCommand())
557
                    try
337 558
                    {
338
                        cmd.CommandText = string.Format(@"
559
                        connection.Open();
560
                        using (SQLiteCommand cmd = connection.CreateCommand())
561
                        {
562
                            cmd.CommandText = string.Format(@"
339 563
                            SELECT AdditionalSymbol FROM Symbol");
340
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
341
                            dt.Load(dr);
342
                        List<string> childList = new List<string>();
343
                        foreach (DataRow row in dt.Rows)
344
                        { 
345
                            if (row["AdditionalSymbol"] != null && !DBNull.Value.Equals(row["AdditionalSymbol"]) && !string.IsNullOrEmpty((string)row["AdditionalSymbol"]))
564
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
565
                                dt.Load(dr);
566
                            List<string> childList = new List<string>();
567
                            foreach (DataRow row in dt.Rows)
346 568
                            {
347
                                string[] array = row["AdditionalSymbol"].ToString().Split(new char[] { '/' });
348
                                foreach (var childString in array)
569
                                if (row["AdditionalSymbol"] != null && !DBNull.Value.Equals(row["AdditionalSymbol"]) && !string.IsNullOrEmpty((string)row["AdditionalSymbol"]))
349 570
                                {
350
                                    childList.Add(childString.Split(new char[] { ',' })[2]);
571
                                    string[] array = row["AdditionalSymbol"].ToString().Split(new char[] { '/' });
572
                                    foreach (var childString in array)
573
                                    {
574
                                        childList.Add(childString.Split(new char[] { ',' })[2]);
575
                                    }
351 576
                                }
352
                            }
353 577

  
354
                        }
578
                            }
355 579

  
356
                        dt.Clear();
357
                        cmd.Reset();
358
                        cmd.CommandText = string.Format(@"
580
                            dt.Clear();
581
                            cmd.Reset();
582
                            cmd.CommandText = string.Format(@"
359 583
                            SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
360
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
361
                            dt.Load(dr);
362

  
363
                        childList = childList.Distinct().ToList();
364
                        foreach (var child in childList)
365
                        {
366
                            string mappingPath = string.Empty;
367
                            DataRow[] rows = dt.Select(string.Format("UID = '{0}'", child));
368
                            if (rows.Length == 1)
369
                                mappingPath = !DBNull.Value.Equals(rows[0]["SPPID_SYMBOL_PATH"]) ? (string)rows[0]["SPPID_SYMBOL_PATH"] : null;
584
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
585
                                dt.Load(dr);
370 586

  
371
                            DataRow newRow = result.NewRow();
372
                            newRow["UID"] = child;
373
                            newRow["Name"] = child;
374
                            newRow["Type"] = "Child Symbol";
375
                            newRow["SPPID_SYMBOL_PATH"] = mappingPath;
376
                            result.Rows.Add(newRow);
587
                            childList = childList.Distinct().ToList();
588
                            foreach (var child in childList)
589
                            {
590
                                string mappingPath = string.Empty;
591
                                DataRow[] rows = dt.Select(string.Format("UID = '{0}'", child));
592
                                if (rows.Length == 1)
593
                                    mappingPath = !DBNull.Value.Equals(rows[0]["SPPID_SYMBOL_PATH"]) ? (string)rows[0]["SPPID_SYMBOL_PATH"] : null;
594

  
595
                                DataRow newRow = result.NewRow();
596
                                newRow["UID"] = child;
597
                                newRow["Name"] = child;
598
                                newRow["Type"] = "Child Symbol";
599
                                newRow["SPPID_SYMBOL_PATH"] = mappingPath;
600
                                result.Rows.Add(newRow);
601
                            }
377 602
                        }
603
                        connection.Close();
378 604
                    }
379
                    connection.Close();
380
                }
381
                catch (Exception ex)
382
                {
605
                    catch (Exception ex)
606
                    {
383 607

  
608
                    }
609
                    finally
610
                    {
611
                        connection.Dispose();
612
                    }
384 613
                }
385
                finally
614
            }
615
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
616
            {
617
                using (SqlConnection connection = GetSqlConnection())
386 618
                {
387
                    connection.Dispose();
619
                    try
620
                    {
621
                        if (connection != null && connection.State == ConnectionState.Open)
622
                        {
623

  
624
                        }
625
                    }
626
                    catch (Exception ex)
627
                    {
628

  
629
                    }
630
                    finally
631
                    {
632
                        if (connection != null)
633
                            connection.Dispose();
634
                    }
388 635
                }
389 636
            }
390

  
391 637
            return result;
392 638
        }
393 639

  
......
395 641
        {
396 642
            DataTable dt = new DataTable();
397 643
            Project_Info projectInfo = Project_Info.GetInstance();
398
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
644
            if (projectInfo.DBType == ID2DB_Type.SQLite)
399 645
            {
400
                try
646
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
401 647
                {
402
                    connection.Open();
403
                    using (SQLiteCommand cmd = connection.CreateCommand())
648
                    try
404 649
                    {
405
                        cmd.CommandText = string.Format(@"
650
                        connection.Open();
651
                        using (SQLiteCommand cmd = connection.CreateCommand())
652
                        {
653
                            cmd.CommandText = string.Format(@"
406 654
                            SELECT l.UID, l.Name, sp.SPPID_SYMBOL_PATH FROM {0} as l 
407 655
                                LEFT OUTER JOIN {1} as sp 
408 656
                                    ON l.UID = SP.UID ;", LineTypes_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
409
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
410
                            dt.Load(dr);
657
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
658
                                dt.Load(dr);
659
                        }
660
                        connection.Close();
411 661
                    }
412
                    connection.Close();
413
                }
414
                catch (Exception ex)
415
                {
662
                    catch (Exception ex)
663
                    {
416 664

  
665
                    }
666
                    finally
667
                    {
668
                        connection.Dispose();
669
                    }
417 670
                }
418
                finally
671
            }
672
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
673
            {
674
                using (SqlConnection connection = GetSqlConnection())
419 675
                {
420
                    connection.Dispose();
676
                    try
677
                    {
678
                        if (connection != null && connection.State == ConnectionState.Open)
679
                        {
680

  
681
                        }
682
                    }
683
                    catch (Exception ex)
684
                    {
685

  
686
                    }
687
                    finally
688
                    {
689
                        if (connection != null)
690
                            connection.Dispose();
691
                    }
421 692
                }
422 693
            }
423 694

  
......
428 699
        {
429 700
            DataTable dt = new DataTable();
430 701
            Project_Info projectInfo = Project_Info.GetInstance();
431
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
702
            if (projectInfo.DBType == ID2DB_Type.SQLite)
432 703
            {
433
                try
704
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
434 705
                {
435
                    connection.Open();
436
                    using (SQLiteCommand cmd = connection.CreateCommand())
706
                    try
437 707
                    {
438
                        cmd.CommandText = string.Format(@"
708
                        connection.Open();
709
                        using (SQLiteCommand cmd = connection.CreateCommand())
710
                        {
711
                            cmd.CommandText = string.Format(@"
439 712
                            SELECT lp.UID, lp.DisplayName, sp.SPPID_SYMBOL_PATH, spa.SPPID_ATTRIBUTE
440 713
                            FROM {0} as lp 
441 714
                                 LEFT OUTER JOIN {1} as sp 
442 715
                                      ON lp.UID = sp.UID
443 716
                                 LEFT OUTER JOIN {2} as spa 
444 717
                                      ON lp.UID = spa.UID;", LineProperties_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE);
445
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
446
                            dt.Load(dr);
718
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
719
                                dt.Load(dr);
720
                        }
721
                        connection.Close();
447 722
                    }
448
                    connection.Close();
449
                }
450
                catch (Exception ex)
451
                {
723
                    catch (Exception ex)
724
                    {
452 725

  
726
                    }
727
                    finally
728
                    {
729
                        connection.Dispose();
730
                    }
453 731
                }
454
                finally
732
            }
733
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
734
            {
735
                using (SqlConnection connection = GetSqlConnection())
455 736
                {
456
                    connection.Dispose();
737
                    try
738
                    {
739
                        if (connection != null && connection.State == ConnectionState.Open)
740
                        {
741

  
742
                        }
743
                    }
744
                    catch (Exception ex)
745
                    {
746

  
747
                    }
748
                    finally
749
                    {
750
                        if (connection != null)
751
                            connection.Dispose();
752
                    }
457 753
                }
458 754
            }
459 755

  
......
464 760
        {
465 761
            DataTable dt = new DataTable();
466 762
            Project_Info projectInfo = Project_Info.GetInstance();
467
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
763
            if (projectInfo.DBType == ID2DB_Type.SQLite)
468 764
            {
469
                try
765
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
470 766
                {
471
                    connection.Open();
472
                    using (SQLiteCommand cmd = connection.CreateCommand())
767
                    try
473 768
                    {
474
                        cmd.CommandText = string.Format(@"
769
                        connection.Open();
770
                        using (SQLiteCommand cmd = connection.CreateCommand())
771
                        {
772
                            cmd.CommandText = string.Format(@"
475 773
                            SELECT sa.UID, sa.DisplayAttribute, st.TYPE, spa.SPPID_ATTRIBUTE, sp.SPPID_SYMBOL_PATH, spl.LOCATION, spl.LEADERLINE, sa.Property
476 774
                            FROM {1} as sa, {0} as st 
477 775
                                 LEFT OUTER JOIN {2} as sp 
......
481 779
                                LEFT OUTER JOIN {4} as spl 
482 780
                                     ON sa.UID = spl.UID
483 781
                            WHERE sa.SymbolType_UID = st.UID AND (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE, SPPID_LABEL_INFO_TABLE);
484
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
485
                            dt.Load(dr);
782
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
783
                                dt.Load(dr);
784
                        }
785
                        connection.Close();
486 786
                    }
487
                    connection.Close();
488
                }
489
                catch (Exception ex)
490
                {
787
                    catch (Exception ex)
788
                    {
491 789

  
492
                }
493
                finally
790
                    }
791
                    finally
792
                    {
793
                        connection.Dispose();
794
                    }
795
                }
796
            }
797
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
798
            {
799
                using (SqlConnection connection = GetSqlConnection())
494 800
                {
495
                    connection.Dispose();
801
                    try
802
                    {
803
                        if (connection != null && connection.State == ConnectionState.Open)
804
                        {
805

  
806
                        }
807
                    }
808
                    catch (Exception ex)
809
                    {
810

  
811
                    }
812
                    finally
813
                    {
814
                        if (connection != null)
815
                            connection.Dispose();
816
                    }
496 817
                }
497 818
            }
498 819

  
820

  
499 821
            return dt;
500 822
        }
501 823

  
......
503 825
        {
504 826
            DataTable dt = new DataTable();
505 827
            Project_Info projectInfo = Project_Info.GetInstance();
506
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
828
            if (projectInfo.DBType == ID2DB_Type.SQLite)
507 829
            {
508
                try
830
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
509 831
                {
510
                    connection.Open();
511
                    using (SQLiteCommand cmd = connection.CreateCommand())
832
                    try
512 833
                    {
513
                        cmd.CommandText = @"SELECT * FROM Symbol";
514
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
515
                            dt.Load(dr);
834
                        connection.Open();
835
                        using (SQLiteCommand cmd = connection.CreateCommand())
836
                        {
837
                            cmd.CommandText = @"SELECT * FROM Symbol";
838
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
839
                                dt.Load(dr);
840
                        }
841
                        connection.Close();
516 842
                    }
517
                    connection.Close();
518
                }
519
                catch (Exception ex)
520
                {
843
                    catch (Exception ex)
844
                    {
521 845

  
846
                    }
847
                    finally
848
                    {
849
                        connection.Dispose();
850
                    }
522 851
                }
523
                finally
852
            }
853
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
854
            {
855
                using (SqlConnection connection = GetSqlConnection())
524 856
                {
525
                    connection.Dispose();
857
                    try
858
                    {
859
                        if (connection != null && connection.State == ConnectionState.Open)
860
                        {
861

  
862
                        }
863
                    }
864
                    catch (Exception ex)
865
                    {
866

  
867
                    }
868
                    finally
869
                    {
870
                        if (connection != null)
871
                            connection.Dispose();
872
                    }
526 873
                }
527 874
            }
528 875

  
......
533 880
        {
534 881
            DataTable dt = new DataTable();
535 882
            Project_Info projectInfo = Project_Info.GetInstance();
536
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
883
            if (projectInfo.DBType == ID2DB_Type.SQLite)
537 884
            {
538
                try
885
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
539 886
                {
540
                    connection.Open();
541
                    using (SQLiteCommand cmd = connection.CreateCommand())
887
                    try
542 888
                    {
543
                        cmd.CommandText = string.Format("SELECT * FROM {0}", OPCRelations_TABLE);
544
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
545
                            dt.Load(dr);
889
                        connection.Open();
890
                        using (SQLiteCommand cmd = connection.CreateCommand())
891
                        {
892
                            cmd.CommandText = string.Format("SELECT * FROM {0}", OPCRelations_TABLE);
893
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
894
                                dt.Load(dr);
895
                        }
896
                        connection.Close();
546 897
                    }
547
                    connection.Close();
548
                }
549
                catch (Exception ex)
550
                {
898
                    catch (Exception ex)
899
                    {
551 900

  
901
                    }
902
                    finally
903
                    {
904
                        connection.Dispose();
905
                    }
552 906
                }
553
                finally
907
            }
908
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
909
            {
910
                using (SqlConnection connection = GetSqlConnection())
554 911
                {
555
                    connection.Dispose();
912
                    try
913
                    {
914
                        if (connection != null && connection.State == ConnectionState.Open)
915
                        {
916

  
917
                        }
918
                    }
919
                    catch (Exception ex)
920
                    {
921

  
922
                    }
923
                    finally
924
                    {
925
                        if (connection != null)
926
                            connection.Dispose();
927
                    }
556 928
                }
557 929
            }
558 930

  
......
563 935
        {
564 936
            DataTable dt = new DataTable();
565 937
            Project_Info projectInfo = Project_Info.GetInstance();
566
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
938
            if (projectInfo.DBType == ID2DB_Type.SQLite)
567 939
            {
568
                try
940
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
569 941
                {
570
                    connection.Open();
571
                    using (SQLiteCommand cmd = connection.CreateCommand())
942
                    try
572 943
                    {
573
                        cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings");
574
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
575
                            dt.Load(dr);
944
                        connection.Open();
945
                        using (SQLiteCommand cmd = connection.CreateCommand())
946
                        {
947
                            cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings");
948
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
949
                                dt.Load(dr);
950
                        }
951
                        connection.Close();
576 952
                    }
577
                    connection.Close();
578
                }
579
                catch (Exception ex)
580
                {
953
                    catch (Exception ex)
954
                    {
581 955

  
956
                    }
957
                    finally
958
                    {
959
                        connection.Dispose();
960
                    }
582 961
                }
583
                finally
962
            }
963
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
964
            {
965
                using (SqlConnection connection = GetSqlConnection())
584 966
                {
585
                    connection.Dispose();
967
                    try
968
                    {
969
                        if (connection != null && connection.State == ConnectionState.Open)
970
                        {
971

  
972
                        }
973
                    }
974
                    catch (Exception ex)
975
                    {
976

  
977
                    }
978
                    finally
979
                    {
980
                        if (connection != null)
981
                            connection.Dispose();
982
                    }
586 983
                }
587 984
            }
588 985

  
......
593 990
        {
594 991
            DataTable dt = new DataTable();
595 992
            Project_Info projectInfo = Project_Info.GetInstance();
596
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
993
            if (projectInfo.DBType == ID2DB_Type.SQLite)
597 994
            {
598
                try
995
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
599 996
                {
600
                    connection.Open();
601
                    using (SQLiteCommand cmd = connection.CreateCommand())
997
                    try
602 998
                    {
603
                        cmd.CommandText = string.Format("SELECT * FROM {0} WHERE SPPID_OPC_MODELITEM_ID IS NOT NULL AND PAIRED = False", SPPID_OPC_INFO);
604
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
605
                            dt.Load(dr);
999
                        connection.Open();
1000
                        using (SQLiteCommand cmd = connection.CreateCommand())
1001
                        {
1002
                            cmd.CommandText = string.Format("SELECT * FROM {0} WHERE SPPID_OPC_MODELITEM_ID IS NOT NULL AND PAIRED = False", SPPID_OPC_INFO);
1003
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1004
                                dt.Load(dr);
1005
                        }
1006
                        connection.Close();
606 1007
                    }
607
                    connection.Close();
608
                }
609
                catch (Exception ex)
610
                {
1008
                    catch (Exception ex)
1009
                    {
611 1010

  
1011
                    }
1012
                    finally
1013
                    {
1014
                        connection.Dispose();
1015
                    }
612 1016
                }
613
                finally
1017
            }
1018
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1019
            {
1020
                using (SqlConnection connection = GetSqlConnection())
614 1021
                {
615
                    connection.Dispose();
1022
                    try
1023
                    {
1024
                        if (connection != null && connection.State == ConnectionState.Open)
1025
                        {
1026

  
1027
                        }
1028
                    }
1029
                    catch (Exception ex)
1030
                    {
1031

  
1032
                    }
1033
                    finally
1034
                    {
1035
                        if (connection != null)
1036
                            connection.Dispose();
1037
                    }
616 1038
                }
617 1039
            }
618 1040

  
......
623 1045
        {
624 1046
            DataTable dt = new DataTable();
625 1047
            Project_Info projectInfo = Project_Info.GetInstance();
626
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1048
            if (projectInfo.DBType == ID2DB_Type.SQLite)
627 1049
            {
628
                try
1050
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
629 1051
                {
630
                    connection.Open();
631
                    using (SQLiteCommand cmd = connection.CreateCommand())
1052
                    try
632 1053
                    {
633
                        cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE);
634
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
635
                            dt.Load(dr);
1054
                        connection.Open();
1055
                        using (SQLiteCommand cmd = connection.CreateCommand())
1056
                        {
1057
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE);
1058
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1059
                                dt.Load(dr);
1060
                        }
1061
                        connection.Close();
636 1062
                    }
637
                    connection.Close();
638
                }
639
                catch (Exception ex)
640
                {
1063
                    catch (Exception ex)
1064
                    {
641 1065

  
1066
                    }
1067
                    finally
1068
                    {
1069
                        connection.Dispose();
1070
                    }
642 1071
                }
643
                finally
1072
            }
1073
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1074
            {
1075
                using (SqlConnection connection = GetSqlConnection())
644 1076
                {
645
                    connection.Dispose();
1077
                    try
1078
                    {
1079
                        if (connection != null && connection.State == ConnectionState.Open)
1080
                        {
1081

  
1082
                        }
1083
                    }
1084
                    catch (Exception ex)
1085
                    {
1086

  
1087
                    }
1088
                    finally
1089
                    {
1090
                        if (connection != null)
1091
                            connection.Dispose();
1092
                    }
646 1093
                }
647 1094
            }
648 1095

  
......
653 1100
        {
654 1101
            DataTable dt = new DataTable();
655 1102
            Project_Info projectInfo = Project_Info.GetInstance();
656
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1103
            if (projectInfo.DBType == ID2DB_Type.SQLite)
657 1104
            {
658
                try
1105
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
659 1106
                {
660
                    connection.Open();
661
                    using (SQLiteCommand cmd = connection.CreateCommand())
1107
                    try
662 1108
                    {
663
                        cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO);
664
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
665
                            dt.Load(dr);
1109
                        connection.Open();
1110
                        using (SQLiteCommand cmd = connection.CreateCommand())
1111
                        {
1112
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO);
1113
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1114
                                dt.Load(dr);
1115
                        }
1116
                        connection.Close();
666 1117
                    }
667
                    connection.Close();
668
                }
669
                catch (Exception ex)
670
                {
1118
                    catch (Exception ex)
1119
                    {
671 1120

  
1121
                    }
1122
                    finally
1123
                    {
1124
                        connection.Dispose();
1125
                    }
672 1126
                }
673
                finally
1127
            }
1128
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1129
            {
1130
                using (SqlConnection connection = GetSqlConnection())
674 1131
                {
675
                    connection.Dispose();
1132
                    try
1133
                    {
1134
                        if (connection != null && connection.State == ConnectionState.Open)
1135
                        {
1136

  
1137
                        }
1138
                    }
1139
                    catch (Exception ex)
1140
                    {
1141

  
1142
                    }
1143
                    finally
1144
                    {
1145
                        if (connection != null)
1146
                            connection.Dispose();
1147
                    }
676 1148
                }
677 1149
            }
678 1150

  
......
682 1154
        public static bool InsertSymbolMapping(List<Tuple<string, string, string, bool>> datas)
683 1155
        {
684 1156
            Project_Info projectInfo = Project_Info.GetInstance();
685
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1157
            if (projectInfo.DBType == ID2DB_Type.SQLite)
686 1158
            {
687
                try
1159
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
688 1160
                {
689
                    connection.Open();
690
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
1161
                    try
691 1162
                    {
692
                        try
1163
                        connection.Open();
1164
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
693 1165
                        {
694
                            using (SQLiteCommand cmd = connection.CreateCommand())
1166
                            try
695 1167
                            {
696
                                foreach (var item in datas)
1168
                                using (SQLiteCommand cmd = connection.CreateCommand())
697 1169
                                {
698
                                    cmd.Parameters.Clear();
699
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE);
700
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
701
                                    cmd.Parameters.AddWithValue("@NAME", item.Item2);
702
                                    cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3);
703
                                    cmd.Parameters.AddWithValue("@LEADERLINE", item.Item4);
704
                                    cmd.ExecuteNonQuery();
1170
                                    foreach (var item in datas)
1171
                                    {
1172
                                        cmd.Parameters.Clear();
1173
                                        cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE);
1174
                                        cmd.Parameters.AddWithValue("@UID", item.Item1);
1175
                                        cmd.Parameters.AddWithValue("@NAME", item.Item2);
1176
                                        cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3);
1177
                                        cmd.Parameters.AddWithValue("@LEADERLINE", item.Item4);
1178
                                        cmd.ExecuteNonQuery();
1179
                                    }
705 1180
                                }
1181
                                transaction.Commit();
1182
                                connection.Close();
1183
                            }
1184
                            catch (Exception ex)
1185
                            {
1186
                                transaction.Rollback();
1187
                            }
1188
                            finally
1189
                            {
1190
                                transaction.Dispose();
706 1191
                            }
707
                            transaction.Commit();
708
                            connection.Close();
709
                        }
710
                        catch (Exception ex)
711
                        {
... 이 차이점은 표시할 수 있는 최대 줄수를 초과해서 이 차이점은 잘렸습니다.

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)